| 146 | } |
| 147 | |
| 148 | float AutoGain::computeTargetGain() { |
| 149 | const float peakEnv = mPeakEnvelope.value(); |
| 150 | |
| 151 | // Avoid division by very small numbers |
| 152 | if (peakEnv < 1.0f) { |
| 153 | return mConfig.maxGain; // Signal is essentially silent |
| 154 | } |
| 155 | |
| 156 | return mConfig.targetRMSLevel / peakEnv; |
| 157 | } |
| 158 | |
| 159 | float AutoGain::updatePIController(float targetGain, float dt) { |
| 160 | const float error = targetGain - mLastGain; |