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

◆ operator()()

float MaxFadeTracker::operator() ( const int16_t * samples,
size_t length )
inline

Process one 512-sample block; returns [0…1] with inertia.

Definition at line 30 of file fx_audio.h.

30 {
31 assert(length == 512);
32 // 1) block peak
33 float peak = 0.0f;
34 for (size_t i = 0; i < length; ++i) {
35 float v = ABS(samples[i]) * (1.0f/32768.0f);
36 peak = MAX(peak, v);
37 }
38
39 // 2) time delta
40 float dt = static_cast<float>(length) / sampleRate_;
41
42 // 3) update currentLevel_ with attack/decay
43 if (peak > currentLevel_) {
44 float riseFactor = 1.0f - exp(-attackRate_ * dt);
45 currentLevel_ += (peak - currentLevel_) * riseFactor;
46 } else {
47 float decayFactor = exp(-decayRate_ * dt);
48 currentLevel_ *= decayFactor;
49 }
50
51 // 4) output inertia: smooth smoothedOutput_ → currentLevel_
52 float outFactor = 1.0f - exp(-outputRate_ * dt);
54
55 return smoothedOutput_;
56 }
float sampleRate_
Definition fx_audio.h:62
float outputRate_
Definition fx_audio.h:61
float currentLevel_
Definition fx_audio.h:63
float decayRate_
Definition fx_audio.h:60
float smoothedOutput_
Definition fx_audio.h:64
float attackRate_
Definition fx_audio.h:59
UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
#define ABS(x)
Definition math_macros.h:19
#define MAX(a, b)
Definition math_macros.h:11

References ABS, attackRate_, currentLevel_, decayRate_, length(), MAX, outputRate_, sampleRate_, and smoothedOutput_.

+ Here is the call graph for this function: