FastLED 3.9.15
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 189 of file spectral_equalizer.cpp.hpp.

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

References mConfig.

Referenced by apply().

+ Here is the caller graph for this function: