dynamics.h
The rest of the dynamics family.
#include <sonore/dynamics.h>- 4types
- Guides: Getting started, MIDI and MPE
On this page
Design notes
dsp.h has a Compressor, effects.h a Limiter and a NoiseGate, and for a long time that was all: every "make it punchier" or "tame the esses" was written from scratch, and a hand-written gain computer is where a knee comes out discontinuous or a release runs the wrong way. These are the other standard gain computers, each built on the same EnvFollower the compressor uses, so a plugin that pairs two of them gets one detector behaviour rather than two.
The knee maths follows Giannoulis, Massberg & Reiss, "Digital Dynamic Range Compressor Design -- A Tutorial and Analysis" (JAES 2012): a quadratic that meets the hard curve with matching slope at both ends of the knee, so there is no corner for a level sitting exactly on the threshold to buzz against.
Included by dsp.h.
Types 4
Downward expander: below the threshold, every dB the input drops the output drops by ratio dB. A gate is the limiting case (ratio -> infinity) and the NoiseGate in effects.h is the better tool for that; this is for the gentle 1.5:1 -- 3:1 that pushes a drum room's bleed down without ever slamming shut.
range caps the attenuation. A 2:1 expander with no range would take a -80 dB fade to -140 dB; with a 40 dB range it stops where the noise floor would have been anyway, and a reverb tail gets quieter without vanishing.
Upward compression: below the threshold the signal is BROUGHT UP, by (1 - 1/ratio) dB per dB it sits under. Where a downward compressor makes the loud parts quieter, this makes the quiet parts louder -- the move behind "bring up the room" and behind most "loudness" processors, and the thing a parallel compressor is approximating with a mix knob.
maxGain matters more here than range does on the expander. Uncapped, a 4:1 upward compressor lifts a -100 dB noise floor by 75 dB, which is how a fade-out ends in a roar. The default 20 dB cap is where broadcast tools stop.
Attack and sustain as two independent controls, with no threshold.
The trick, from the SPL Transient Designer: two envelope followers that differ only in ATTACK time disagree exactly while a transient is arriving (the fast one is already up, the slow one still climbing), and two that differ only in RELEASE disagree exactly while a note is dying (the slow one is still up, the fast one already down). Each difference, in dB, is a detector for one thing and nothing else, and it needs no threshold because it is a RATIO -- a quiet hit and a loud hit produce the same difference.
attack and sustain run -1..+1: +1 applies the full detected difference as gain (a hit gets louder by however much it out-ran the slow follower), -1 applies it inverted (the hit is pulled down to the slow follower's level), 0 does nothing. Both are capped at +/-24 dB, because a difference detector on a signal that starts from digital silence is unbounded.
Sibilance control: a compressor whose detector hears only one band.
Two ways to apply the gain, and they are different tools. WIDEBAND ducks the whole signal while an "s" is loud -- transparent on speech, because an "s" carries little else, and it is what the classic hardware does. SPLIT ducks only the band above the crossover, leaving the body of the voice untouched, which is what you want on a vocal that is being de-essed hard.
The detector is a bandpass a third of an octave wide around frequency, so a bright guitar strum a fifth below it does not trip the compressor.