@maruaudio/dsp/dynamics/envelope-follower tracks the level of a signal with a branching one-pole detector: s = c·s + (1 − c)·t, where t is |x| (peak) or x² (RMS) and c is the attack coefficient when t rises above the state, the release coefficient otherwise. Coefficients are exp(−1 / (seconds · rate)), rounded to f32, as is the detector state. RMS mode returns sqrt(s). The leaf also exports a standalone mean-square window for compressor detectors.
const state = initEnvelopeFollower(48000)
setEnvelopeFollowerAttack(state, 0.005)
const level = envelopeFollowerTick(state, x)Parameters
| Setter | Range the setter enforces | Default | Unit |
|---|---|---|---|
setEnvelopeFollowerMode | ≥ 1 is ENVELOPE_MODE_RMS, anything else ENVELOPE_MODE_PEAK | Peak | mode |
setEnvelopeFollowerAttack | 0.0001 to 2 | 0.01 | s |
setEnvelopeFollowerRelease | 0.001 to 10 | 0.1 | s |
envelopeTimeCoefficient(seconds, rate) clamps seconds to 0.0001 to 10 and the rate to 8000 to 384000 Hz. rmsWindowCoefficient clamps seconds to 0.0005 to 0.2; rmsMeanSquareTick(state, x, c) returns the new f32 mean square and leaves the square root to the caller.
Lifecycle
initEnvelopeFollower(sampleRate) → setters → envelopeFollowerTick → resetEnvelopeFollower, which zeroes the detector and keeps the settings. prepareEnvelopeFollowerSampleRate re-derives both coefficients from the stored times without allocating. The mean-square helpers are stateless; the caller owns their state.
When to use it
A control signal from an audio input: ducking, an auto-wah, a gate or meter detector. Use the separate mean-square window when the averaging interval must be independent of the attack and release.
Limits
- Mono sample tick. In RMS mode the same coefficients both average the square and shape the envelope; the standalone window separates those.
- Clamps are the kernel node's conditional clamp, not
@maru/math-range. audio-kernelskeeps the PCM16 render entries and node-parameter ABI.