Build with this node

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

Ask Studio

@maruaudio/dsp/dynamics/peak-compressor is a feed-forward compressor that reads the instantaneous peak level of each sample. The level in dB (20·log10|x|, floored at −240 dB below 1e−12) goes through a quadratic soft-knee gain computer; the gain reduction in dB is smoothed by a branching one-pole (attack while it rises, release while it falls) and rounded to f32; the output is x·10^((makeup − reduction)/20).

const state = initCompressorNode(48000)
setCompressorRatio(state, 4)
const y = compressorNodeTick(state, x)

Parameters

SetterRange the setter enforcesDefaultUnit
setCompressorThreshold−60 to 0−24dB
setCompressorRatio1 to 2012ratio
setCompressorKnee0 to 40 (full width)30dB
setCompressorAttack0 to 1; 0 is instantaneous0.003s
setCompressorRelease0 to 1; 0 is instantaneous0.25s
setCompressorMakeup−24 to +240dB

compressorGainReductionDb(level, threshold, ratio, knee) is exported and re-clamps its arguments to the same ranges.

Lifecycle

initCompressorNode(sampleRate) → setters → compressorNodeTick → resetCompressorNode, which zeroes the gain reduction and keeps the settings. prepareCompressorNodeSampleRate re-derives both coefficients from the stored times without allocating; the coefficient clamps the rate to 8 to 384 kHz.

When to use it

Evening out a guitar, bass or vocal line where each peak should be caught as it arrives. @maru/dynamics-keyed-compressor adds a sidechain, RMS detection, hold and auto-release.

Limits

  • Mono, sample tick, no lookahead or sidechain input.
  • Each tick calls log and pow (through dbToGain).
  • Clamps are the kernel node's conditional clamp, not @maru/math-range.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Parameters

ParameterTypeSetter
Compressor threshold compressorThresholdfloatsetCompressorThreshold
Compressor ratio compressorRatiofloatsetCompressorRatio
Compressor knee compressorKneefloatsetCompressorKnee
Compressor attack compressorAttackfloatsetCompressorAttack
Compressor release compressorReleasefloatsetCompressorRelease
Compressor makeup compressorMakeupfloatsetCompressorMakeup

Ports

  • In ininput · audio · mono
  • Out outoutput · audio · mono

One sample per compressorNodeTick call.

Dependencies

Dependents

No other node imports this one.

Used by