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

◆ update()

void fl::audio::detector::EnergyAnalyzer::update ( shared_ptr< Context > context)
overridevirtual

Implements fl::audio::Detector.

Definition at line 23 of file energy_analyzer.cpp.hpp.

23 {
24 // Get RMS directly from Sample (no fft::FFT needed)
25 mCurrentRMS = context->getRMS();
26 u32 timestamp = context->getTimestamp();
27
28 // Update peak tracking
29 updatePeak(mCurrentRMS, timestamp);
30
31 // Update average and history
33
34 // Update min/max
35 if (mCurrentRMS > 0.001f) { // Ignore near-silence
38 }
39
40 // Compute normalized 0-1 RMS using adaptive range tracking.
41 // AttackDecayFilter: instant attack (0.001s), slow decay (2.0s).
42 const float dt = computeAudioDt(context->getPCM().size(), context->getSampleRate());
43 float runningMax = mRunningMaxFilter.update(mCurrentRMS, dt);
44 // Ensure running max doesn't decay below a minimum threshold
45 if (runningMax < 1.0f) {
46 runningMax = 1.0f;
47 }
48 mNormalizedRMS = fl::min(1.0f, mCurrentRMS / runningMax);
49}
AttackDecayFilter< float > mRunningMaxFilter
void updatePeak(float energy, u32 timestamp)
float computeAudioDt(fl::size pcmSize, int sampleRate) FL_NOEXCEPT
Compute the time delta (in seconds) for an audio buffer.
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75

References EnergyAnalyzer(), fl::audio::computeAudioDt(), fl::max(), mCurrentRMS, fl::min(), mMaxEnergy, mMinEnergy, mNormalizedRMS, mRunningMaxFilter, update(), updateAverage(), and updatePeak().

Referenced by ~EnergyAnalyzer(), and update().

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