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

◆ processBlock() [1/2]

void fl::SoundLevelMeter::processBlock ( const int16_t * samples,
size_t count )

Process a block of int16 PCM samples.

Definition at line 96 of file audio.cpp.

96 {
97 // 1) compute block power → dBFS
98 double sum_sq = 0.0;
99 for (size_t i = 0; i < count; ++i) {
100 double s = samples[i] / 32768.0; // normalize to ±1
101 sum_sq += s * s;
102 }
103 double p = sum_sq / count; // mean power
104 double dbfs = 10.0 * log10(p + 1e-12);
105 current_dbfs_ = dbfs;
106
107 // 2) update global floor (with optional smoothing)
108 if (dbfs < dbfs_floor_global_) {
109 if (smoothing_alpha_ <= 0.0) {
110 dbfs_floor_global_ = dbfs;
111 } else {
114 }
116 }
117
118 // 3) estimate SPL
119 current_spl_ = dbfs + offset_;
120}
double dbfs_floor_global_
Definition audio.h:93
double current_dbfs_
Definition audio.h:95
double smoothing_alpha_
Definition audio.h:92
double spl_floor_
Definition audio.h:91
double current_spl_
Definition audio.h:96
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
Definition noise.cpp:30

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

Referenced by processBlock().

+ Here is the caller graph for this function: