Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

@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

SetterRange the setter enforcesDefaultUnit
setEnvelopeFollowerMode≥ 1 is ENVELOPE_MODE_RMS, anything else ENVELOPE_MODE_PEAKPeakmode
setEnvelopeFollowerAttack0.0001 to 20.01s
setEnvelopeFollowerRelease0.001 to 100.1s

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-kernels keeps the PCM16 render entries and node-parameter ABI.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Parameters

ParameterTypeSetter
Mode modefloatsetEnvelopeFollowerMode
Envelope follower attack envelopeFollowerAttackfloatsetEnvelopeFollowerAttack
Envelope follower release envelopeFollowerReleasefloatsetEnvelopeFollowerRelease

Dependencies

None: this node imports no other node.

Dependents

Used by