LabDAW

Compressor

A compressor device: five models, threshold, ratio, attack, release, knee, make-up and mix, a panel that draws its transfer curve, a Web Audio engine and tools for agents.

Audio UI

Brings loud parts down. Above the threshold, the level rises by one decibel for every ratio decibels in. Its model is one of five from audio.js, each with its own detector and timing. To duck one sound by another, use the Ducker. It is a device: a state, a panel, an engine and tools, each its own file.

Installation

pnpm dlx shadcn@latest add @audio-ui/compressor

It installs the device's state, its engine and its panel to components/audio-ui/devices/compressor/. The demo above, which wires them to a loop, is @audio-ui/block-compressor.

Controls

Controls · 9

Models

ModelPackageDetectorCharacter
Smooth@audio/dynamics-compressorpeakThe default. The gain reduction is smoothed in decibels, so the attack and the release hold at any depth of compression.
VCA@audio/dynamics-vcapeakClean and precise, with a near-hard knee.
FET@audio/dynamics-fetpeakVery fast, made for short attacks and high ratios.
Opto@audio/dynamics-optoRMSA wide soft knee, and a release that slows the longer it has been reducing. It has no Release of its own.
Vari-Mu@audio/dynamics-varimuRMS, of its own outputA very soft knee, and a ratio that rises as it is pushed. It has no Ratio of its own.

Every model takes the knobs as they are set. The model runs in an AudioWorklet, the processor of its package's manifest as published, and Make-up goes on after it. Every value changes as it plays, smoothed by the package, so a knob turned is heard as it goes; a new model takes over in a 30 ms fade, after first playing the last 100 ms of sound, so it starts where the old one was.

Panel

The panel draws the transfer curve the state plays: the threshold, the dashed unity line, and a dot that rides the curve at the level going in. Pass signal, the device's live sound from useDeviceSignal, to show the dot. Below the threshold the curve sits above unity by the make-up gain. The model is picked in its title bar.

import { CompressorPanel } from "@/components/audio-ui/devices/compressor/panel";
import { compressorDevice } from "@/components/audio-ui/devices/compressor/device";

const [state, setState] = useState(() => compressorDevice.defaults());

<CompressorPanel onValueChange={setState} value={state} />;

Engine

Create it, connect it and update it as for any device: see The engine.

engine.reduction; // dB being taken off, read per frame

What goes on each node comes from compressorSettings(state). The models have no look-ahead, so the device adds no latency. Until their worklet is ready, the signal passes unchanged. engine.reduction reads the gain the model takes off, measured from its output against its input about every 10 ms.

How close the curve is

The curve is the static curve: the level once the gain has settled on a steady level. It is measured from the model itself, its processor run on a steady level until it settles (modelCurve), so the vari-mu, which follows its own output, draws what it plays. Below the threshold it is exact.

A real detector follows a signal with an attack and a release, so what you hear sits above the curve, by how much depending on the detector. Measured on a sine with its peak 12 dB over the threshold, at the defaults:

ModelAbove the curveWhy
Smoothunder 0.1 dBIts gain reduction is smoothed in decibels, after the curve
Optoabout 2.3 dBIt follows the RMS level, 3 dB under a sine's peak
Vari-Muabout 1.5 dBIt follows the RMS level of its own output
VCA, FET4.4 dB at 100 Hz to 5.6 dB at 1 kHzTheir detectors follow the waveform itself, so the gain comes back between its peaks
Built by Ouest Labs, the source code is available on GitHub.
RSS