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 32 of file fx.h.

32 {
33 assert(length == 512);
34 // 1) block peak
35 float peak = 0.0f;
36 for (size_t i = 0; i < length; ++i) {
37 float v = std::abs(samples[i]) * (1.0f/32768.0f);
38 peak = std::max(peak, v);
39 }
40
41 // 2) time delta
42 float dt = static_cast<float>(length) / sampleRate_;
43
44 // 3) update currentLevel_ with attack/decay
45 if (peak > currentLevel_) {
46 float riseFactor = 1.0f - std::exp(-attackRate_ * dt);
47 currentLevel_ += (peak - currentLevel_) * riseFactor;
48 } else {
49 float decayFactor = std::exp(-decayRate_ * dt);
50 currentLevel_ *= decayFactor;
51 }
52
53 // 4) output inertia: smooth smoothedOutput_ → currentLevel_
54 float outFactor = 1.0f - std::exp(-outputRate_ * dt);
56
57 return smoothedOutput_;
58 }
float sampleRate_
Definition fx.h:64
float outputRate_
Definition fx.h:63
float currentLevel_
Definition fx.h:65
float decayRate_
Definition fx.h:62
float smoothedOutput_
Definition fx.h:66
float attackRate_
Definition fx.h:61
UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)

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

+ Here is the call graph for this function: