| 134 | } |
| 135 | |
| 136 | void VUMeter::updateLevels(const MeterValues& latestValues) |
| 137 | { |
| 138 | float rawRmsCh0 = 0.0f, rawRmsCh1 = 0.0f, rawPeakCh0 = 0.0f, rawPeakCh1 = 0.0f; |
| 139 | const bool isGlobal = (mBandIndex == -1); |
| 140 | |
| 141 | if (mIsInput) |
| 142 | { |
| 143 | if (isGlobal) |
| 144 | { |
| 145 | rawRmsCh0 = latestValues.inputRMS_L; |
| 146 | rawRmsCh1 = latestValues.inputRMS_R; |
| 147 | rawPeakCh0 = latestValues.inputPeak_L; |
| 148 | rawPeakCh1 = latestValues.inputPeak_R; |
| 149 | } |
| 150 | else if (juce::isPositiveAndBelow(mBandIndex, 4)) |
| 151 | { |
| 152 | rawRmsCh0 = latestValues.bandInputRMS_L[mBandIndex]; |
| 153 | rawRmsCh1 = latestValues.bandInputRMS_R[mBandIndex]; |
| 154 | rawPeakCh0 = latestValues.bandInputPeak_L[mBandIndex]; |
| 155 | rawPeakCh1 = latestValues.bandInputPeak_R[mBandIndex]; |
| 156 | } |
| 157 | } |
| 158 | else // Output |
| 159 | { |
| 160 | if (isGlobal) |
| 161 | { |
| 162 | rawRmsCh0 = latestValues.outputRMS_L; |
| 163 | rawRmsCh1 = latestValues.outputRMS_R; |
| 164 | rawPeakCh0 = latestValues.outputPeak_L; |
| 165 | rawPeakCh1 = latestValues.outputPeak_R; |
| 166 | } |
| 167 | else if (juce::isPositiveAndBelow(mBandIndex, 4)) |
| 168 | { |
| 169 | rawRmsCh0 = latestValues.bandOutputRMS_L[mBandIndex]; |
| 170 | rawRmsCh1 = latestValues.bandOutputRMS_R[mBandIndex]; |
| 171 | rawPeakCh0 = latestValues.bandOutputPeak_L[mBandIndex]; |
| 172 | rawPeakCh1 = latestValues.bandOutputPeak_R[mBandIndex]; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // --- The rest of the function remains identical --- |
| 177 | |
| 178 | // 2. Convert from linear gain to normalized dB for UI display. |
| 179 | float updatedRmsCh0 = dBToNormalizedGain(rawRmsCh0); |
| 180 | float updatedRmsCh1 = dBToNormalizedGain(rawRmsCh1); |
| 181 | float updatedPeakCh0 = dBToNormalizedGain(rawPeakCh0); |
| 182 | float updatedPeakCh1 = dBToNormalizedGain(rawPeakCh1); |
| 183 | |
| 184 | // 3. Apply smoothing to RMS for a more stable visual. |
| 185 | auto applySmoothing = [](float current, float target) |
| 186 | { |
| 187 | if (target > current) |
| 188 | return target; // Fast attack |
| 189 | return current + 0.1f * (target - current); // Slow release |
| 190 | }; |
| 191 | |
| 192 | mRmsCh0Level = applySmoothing(mRmsCh0Level, updatedRmsCh0); |
| 193 | mRmsCh1Level = applySmoothing(mRmsCh1Level, updatedRmsCh1); |
no test coverage detected