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 29 of file fx_audio.h.

29 {
30 assert(length == 512);
31 // 1) block peak
32 float peak = 0.0f;
33 for (size_t i = 0; i < length; ++i) {
34 float v = fl::abs(samples[i]) * (1.0f/32768.0f);
35 peak = fl::max(peak, v);
36 }
37
38 // 2) time delta
39 float dt = static_cast<float>(length) / mSampleRate;
40
41 // 3) update mCurrentLevel with attack/decay
42 if (peak > mCurrentLevel) {
43 float riseFactor = 1.0f - fl::exp(-mAttackRate * dt);
44 mCurrentLevel += (peak - mCurrentLevel) * riseFactor;
45 } else {
46 float decayFactor = fl::exp(-mDecayRate * dt);
47 mCurrentLevel *= decayFactor;
48 }
49
50 // 4) output inertia: smooth mSmoothedOutput → mCurrentLevel
51 float outFactor = 1.0f - fl::exp(-mOutputRate * dt);
53
54 return mSmoothedOutput;
55 }
float mSmoothedOutput
Definition fx_audio.h:63
float mOutputRate
Definition fx_audio.h:60
float mAttackRate
Definition fx_audio.h:58
float mDecayRate
Definition fx_audio.h:59
float mCurrentLevel
Definition fx_audio.h:62
float mSampleRate
Definition fx_audio.h:61
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT

References fl::abs(), fl::exp(), length(), mAttackRate, fl::max(), mCurrentLevel, mDecayRate, mOutputRate, mSampleRate, and mSmoothedOutput.

+ Here is the call graph for this function: