FastLED 3.10.8
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 157 of file audio.cpp.hpp.

157 {
158 if (count == 0) {
159 return;
160 }
161
162 // 1) compute block power → dBFS
163 double sum_sq = 0.0;
164 for (fl::size i = 0; i < count; ++i) {
165 double s = samples[i] / 32768.0; // normalize to ±1
166 sum_sq += s * s;
167 }
168 double p = sum_sq / count; // mean power
169 double dbfs = 10.0 * log10(p + 1e-12);
170 mCurrentDbfs = dbfs;
171
172 // 2) update global floor (with optional smoothing)
173 if (dbfs < mDbfsFloorGlobal) {
175 mDbfsFloorGlobal = dbfs;
176 } else {
179 }
181 }
182
183 // 3) estimate SPL
184 mCurrentSpl = dbfs + mOffset;
185}
#define FL_INFINITY_DOUBLE
Definition math.h:50
double log10(double value) FL_NO_EXCEPT
Definition math.h:433

References FL_INFINITY_DOUBLE, fl::FL_NO_EXCEPT, 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: