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

◆ computePinkNoiseGains()

void fl::audio::computePinkNoiseGains ( const float * binCenters,
int numBins,
float * out )
inline

Compute pink noise compensation gains for all bins.

Normalizes so the geometric mean of all gains ≈ 1.0.

Parameters
binCentersArray of bin center frequencies (Hz)
numBinsNumber of bins
outOutput array of gains (length numBins)

Definition at line 295 of file mic_response_data.h.

295 {
296 if (numBins <= 0) return;
297
298 // Compute geometric mean of bin centers for f_ref
299 float logSum = 0.0f;
300 int validCount = 0;
301 for (int i = 0; i < numBins; ++i) {
302 if (binCenters[i] > 0.0f) {
303 logSum += fl::logf(binCenters[i]);
304 ++validCount;
305 }
306 }
307 float f_ref = (validCount > 0)
308 ? fl::expf(logSum / static_cast<float>(validCount))
309 : 1000.0f;
310
311 // Compute raw gains
312 for (int i = 0; i < numBins; ++i) {
313 out[i] = computePinkNoiseGain(binCenters[i], f_ref);
314 }
315
316 // Cap individual gains to prevent extreme boosting of high-frequency bins
317 static constexpr float kMaxPinkNoiseGain = 3.0f;
318 for (int i = 0; i < numBins; ++i) {
319 if (out[i] > kMaxPinkNoiseGain) {
320 out[i] = kMaxPinkNoiseGain;
321 }
322 }
323
324 // Normalize so geometric mean of output gains = 1.0
325 float outLogSum = 0.0f;
326 for (int i = 0; i < numBins; ++i) {
327 if (out[i] > 0.0f) {
328 outLogSum += fl::logf(out[i]);
329 }
330 }
331 float geoMean = fl::expf(outLogSum / static_cast<float>(numBins));
332 if (geoMean > 0.001f) {
333 for (int i = 0; i < numBins; ++i) {
334 out[i] /= geoMean;
335 }
336 }
337}
float computePinkNoiseGain(float freq_hz, float f_ref) FL_NO_EXCEPT
Compute pink noise compensation gain for a single frequency.
float logf(float value) FL_NO_EXCEPT
Definition math.h:426
float expf(float value) FL_NO_EXCEPT
Definition math.h:406

References computePinkNoiseGain(), fl::expf(), fl::FL_NO_EXCEPT, and fl::logf().

Referenced by fl::audio::Reactive::begin(), and fl::audio::detector::EqualizerDetector::recomputePinkNoiseGains().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: