FastLED 3.10.8
Loading...
Searching...
No Matches

◆ calculateMakeupGain()

float fl::audio::SpectralEqualizer::calculateMakeupGain ( span< const float > inputBins,
span< const float > outputBins ) const
private

Calculate makeup gain to maintain target level.

Parameters
inputBinsInput frequency bins
outputBinsOutput frequency bins (after EQ)
Returns
Makeup gain multiplier

Definition at line 183 of file spectral_equalizer.cpp.hpp.

183 {
184 // Calculate average levels
185 float inputAvg = 0.0f;
186 float outputAvg = 0.0f;
187
188 for (size i = 0; i < mConfig.numBands; ++i) {
189 inputAvg += inputBins[i];
190 outputAvg += outputBins[i];
191 }
192
193 inputAvg /= static_cast<float>(mConfig.numBands);
194 outputAvg /= static_cast<float>(mConfig.numBands);
195
196 // Avoid division by zero
197 if (outputAvg < 0.001f) {
198 return 1.0f;
199 }
200
201 // Calculate makeup gain to bring output to target level
202 // Target is relative to input average
203 float targetLevel = inputAvg * mConfig.makeupGainTarget;
204 float makeupGain = targetLevel / outputAvg;
205
206 // Clamp to reasonable range (0.1 to 10.0)
207 if (makeupGain < 0.1f) {
208 makeupGain = 0.1f;
209 }
210 if (makeupGain > 10.0f) {
211 makeupGain = 10.0f;
212 }
213
214 return makeupGain;
215}
SpectralEqualizerConfig mConfig

References fl::FL_NO_EXCEPT, and mConfig.

Referenced by apply().

+ Here is the caller graph for this function: