|
FastLED 3.9.15
|
AutoGain implements adaptive gain control using a PI (proportional-integral) controller with slow peak envelope tracking, inspired by WLED Sound Reactive.
The algorithm:
This design adapts to source-level differences (mic sensitivity, line-in voltage) without tracking musical dynamics, preventing cross-band coupling.
Usage:
Definition at line 85 of file auto_gain.h.
#include <auto_gain.h>
Collaboration diagram for fl::audio::AutoGain:Classes | |
| struct | Stats |
| Get current statistics (for monitoring/debugging) More... | |
Public Member Functions | |
| AutoGain () FL_NOEXCEPT | |
| AutoGain (const AutoGainConfig &config) | |
| ~AutoGain () FL_NOEXCEPT | |
| void | configure (const AutoGainConfig &config) |
| Configure the auto gain controller. | |
| float | getGain () const |
| Get current gain multiplier. | |
| const Stats & | getStats () const |
| Sample | process (const Sample &sample) |
| Process audio sample with automatic gain adjustment. | |
| void | reset () |
| Reset internal state. | |
| void | setSampleRate (int sampleRate) |
| Set sample rate for dt computation. | |
Private Member Functions | |
| void | applyGain (const vector< i16 > &input, float gain, vector< i16 > &output) |
| Apply gain to audio samples. | |
| float | computeTargetGain () |
| Compute target gain from peak envelope. | |
| void | resolvePreset () |
| Resolve preset enum into concrete PI tuning parameters. | |
| float | updatePIController (float targetGain, float dt) |
| Update PI controller toward target gain. | |
Private Attributes | |
| AutoGainConfig | mConfig |
| float | mGainFollowFastTau = 0.38f |
| float | mGainFollowSlowTau = 12.3f |
| float | mIntegrator = 0.0f |
| PI integrator state. | |
| float | mKi = 1.7f |
| float | mKp = 0.6f |
| float | mLastGain = 1.0f |
| Last smoothed gain output. | |
| vector< i16 > | mOutputBuffer |
| Working buffer (reused to avoid allocations) | |
| float | mPeakDecayTau = 3.3f |
| AttackDecayFilter< float > | mPeakEnvelope {0.01f, 3.3f, 0.0f} |
| Peak envelope tracker: fast attack (10ms), slow decay (preset-dependent) | |
| int | mSampleRate = 44100 |
| Stats | mStats |