Skip to content

Compressor

mzuelch edited this page Jan 24, 2026 · 1 revision

plugin_id: compressor · UI: Kompression · Source: plugins/compressor.py

Envelope-based hard-knee compressor (peak detector) with configurable attack/release smoothing. For stereo/multi-channel signals the detector uses the peak across channels to preserve balance.

Parameters

Parameter Type Default Range Meaning
threshold_db float -18.0 (typ.) -60..0 dBFS Threshold in dBFS.
ratio float 2.0 ≥ 1.0 Compression ratio above threshold.
attack_ms float 10.0 ≥ 0 ms Attack time constant (faster gain reduction).
release_ms float 100.0 ≥ 0 ms Release time constant (slower return to unity).

Algorithm

  1. Detector (per-sample, linear domain):
det[i] = max_c |x[i,c]|
  1. Envelope follower with attack/release in linear domain:
a = exp(-1 / (fs * attack_s))
r = exp(-1 / (fs * release_s))

env[i] = coeff * env[i-1] + (1 - coeff) * det[i]
coeff = a   if det[i] > env[i-1]     # rising → attack
coeff = r   otherwise                 # falling → release
  1. Hard-knee gain computer (dB domain):
env_db = 20*log10(max(env, eps))
over   = env_db - threshold_db

out_db  = env_db                      if over <= 0
out_db  = threshold_db + over/ratio   if over > 0
gain_db = out_db - env_db
gain    = 10^(gain_db/20)
y[i,c]  = x[i,c] * gain[i]

Implementation notes

  • Attack/release of 0 ms makes the envelope track immediately (coeff = 0).
  • No soft knee; for gentler behavior use a lower ratio and/or higher threshold.
  • The same gain is applied to all channels (stereo-safe).

References

  • D. Giannoulis, M. Massberg, J. D. Reiss, “Digital Dynamic Range Compressor Design—A Tutorial and Analysis,” Journal of the Audio Engineering Society, 60(6), pp. 399–408, 2012.

Clone this wiki locally