FastLED 3.9.15
Loading...
Searching...
No Matches

◆ processBlock() [1/2]

void fl::audio::SoundLevelMeter::processBlock ( const fl::i16 * samples,
fl::size count )

Process a block of int16 PCM samples.

Definition at line 152 of file audio.cpp.hpp.

152 {
153 // 1) compute block power → dBFS
154 double sum_sq = 0.0;
155 for (fl::size i = 0; i < count; ++i) {
156 double s = samples[i] / 32768.0; // normalize to ±1
157 sum_sq += s * s;
158 }
159 double p = sum_sq / count; // mean power
160 double dbfs = 10.0 * log10(p + 1e-12);
161 mCurrentDbfs = dbfs;
162
163 // 2) update global floor (with optional smoothing)
164 if (dbfs < mDbfsFloorGlobal) {
165 if (mSmoothingAlpha <= 0.0) {
166 mDbfsFloorGlobal = dbfs;
167 } else {
170 }
172 }
173
174 // 3) estimate SPL
175 mCurrentSpl = dbfs + mOffset;
176}
double log10(double value) FL_NOEXCEPT
Definition math.h:425

References fl::log10(), mCurrentDbfs, mCurrentSpl, mDbfsFloorGlobal, mOffset, mSmoothingAlpha, and mSplFloor.

Referenced by processBlock().

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