FastLED 3.9.15
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 294 of file mic_response_data.h.

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

References computePinkNoiseGain(), fl::expf(), 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: