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

◆ update()

float fl::audio::SilenceEnvelope::update ( bool isSilent,
float currentValue,
float dt )

Definition at line 14 of file silence_envelope.cpp.hpp.

14 {
15 if (!isSilent) {
16 // Pass-through during audio; cache for decay if silence starts next frame.
17 mCurrent = currentValue;
18 return mCurrent;
19 }
20
21 // During silence — exponential decay toward target with time constant tau.
22 // alpha = 1 - exp(-dt/tau) gives a proper first-order response independent
23 // of dt. At dt=tau, alpha ≈ 0.632; at dt=3*tau, we've crossed 95% of the way.
24 if (mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f) {
25 // No decay time or zero dt → snap to target immediately.
26 mCurrent = mConfig.targetValue;
27 return mCurrent;
28 }
29 const float alpha = 1.0f - fl::expf(-dt / mConfig.decayTauSeconds);
30 mCurrent = mCurrent + (mConfig.targetValue - mCurrent) * alpha;
31 return mCurrent;
32}
static bool isSilent
float expf(float value) FL_NOEXCEPT
Definition math.h:398

References fl::expf(), FL_NOEXCEPT, isSilent, mConfig, and mCurrent.

+ Here is the call graph for this function: