@maruaudio/dsp/dynamics/lookahead-limiter is a true-peak lookahead brickwall limiter adapted from Synthlet's @synthlet/lookahead-limiter (MIT; notices in `). Per sample: input drive, a 4× polyphase true-peak detector (48-tap Hann sinc), the gain ceiling / peak`, a sliding-minimum hold, a two-pole release and a boxcar attack over the lookahead, applied to the input delayed by lookahead plus 6 samples, then an arithmetic ceiling backstop. A linked stereo wrapper shares one gain.
const state = initLookaheadLimiterNode(48000, 2) // lookahead in ms
setLookaheadLimiterThreshold(state, -1)
const y = lookaheadLimiterNodeTick(state, x)Parameters
| Setter | Range the setter enforces | Default | Unit |
|---|---|---|---|
initLookaheadLimiterNode(rate, lookaheadMs) | 0.5 to 5 ms, at least 1 sample; fixes latency | — | ms |
setLookaheadLimiterThreshold | −24 to 0 (the ceiling) | −1 | dB |
setLookaheadLimiterRelease | 10 to 1000; time constant max(0.1, ms/3.3579) ms | 168 | ms |
setLookaheadLimiterInputGain | −12 to +24 (drive) | 0 | dB |
setStereoLookaheadLimiterParameters(state, gainDb, ceilingDb, releaseMs) sets both lanes.
Lifecycle
initLookaheadLimiterNode allocates the rings, deque, boxcar and delay → setters → lookaheadLimiterNodeTick → resetLookaheadLimiterNode, which clears every history and keeps the settings. The detect, gain and delay stages are exported separately, so one gain can protect several aligned lanes. prepareLookaheadLimiterNodeSampleRate re-derives lookahead, latency and release within the init capacity and clears history; size the state for the highest rate. The stereo tick is stereoLookaheadLimiterTick (outputLeft, outputRight).
When to use it
The last stage of a master or bus, where peaks must stay under a ceiling and a few milliseconds of latency are acceptable.
Limits
- Latency is
lookaheadLimiterLatencySamples(ms, rate): lookahead samples plus 6. - Release state and output are f32. The stereo detector takes the larger lane peak, not a sum, and replaces NaN and infinite input with 0.