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

◆ processBlock() [1/2]

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

Process a block of int16 PCM samples.

Definition at line 102 of file audio.cpp.

102 {
103 // 1) compute block power → dBFS
104 double sum_sq = 0.0;
105 for (fl::size i = 0; i < count; ++i) {
106 double s = samples[i] / 32768.0; // normalize to ±1
107 sum_sq += s * s;
108 }
109 double p = sum_sq / count; // mean power
110 double dbfs = 10.0 * log10(p + 1e-12);
111 current_dbfs_ = dbfs;
112
113 // 2) update global floor (with optional smoothing)
114 if (dbfs < dbfs_floor_global_) {
115 if (smoothing_alpha_ <= 0.0) {
116 dbfs_floor_global_ = dbfs;
117 } else {
120 }
122 }
123
124 // 3) estimate SPL
125 current_spl_ = dbfs + offset_;
126}
double dbfs_floor_global_
Definition audio.h:95
double current_dbfs_
Definition audio.h:97
double smoothing_alpha_
Definition audio.h:94
double spl_floor_
Definition audio.h:93
double current_spl_
Definition audio.h:98

References current_dbfs_, current_spl_, dbfs_floor_global_, offset_, smoothing_alpha_, and spl_floor_.

Referenced by processBlock().

+ Here is the caller graph for this function: