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 84 of file audio.cpp.

84 {
85 // 1) compute block power → dBFS
86 double sum_sq = 0.0;
87 for (size_t i = 0; i < count; ++i) {
88 double s = samples[i] / 32768.0; // normalize to ±1
89 sum_sq += s * s;
90 }
91 double p = sum_sq / count; // mean power
92 double dbfs = 10.0 * log10(p + 1e-12);
93 current_dbfs_ = dbfs;
94
95 // 2) update global floor (with optional smoothing)
96 if (dbfs < dbfs_floor_global_) {
97 if (smoothing_alpha_ <= 0.0) {
98 dbfs_floor_global_ = dbfs;
99 } else {
102 }
104 }
105
106 // 3) estimate SPL
107 current_spl_ = dbfs + offset_;
108}
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: