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
Copy to Clipboardpnpm 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
| Model | Package | Detector | Character |
|---|---|---|---|
| Smooth | @audio/dynamics-compressor | peak | The default. The gain reduction is smoothed in decibels, so the attack and the release hold at any depth of compression. |
| VCA | @audio/dynamics-vca | peak | Clean and precise, with a near-hard knee. |
| FET | @audio/dynamics-fet | peak | Very fast, made for short attacks and high ratios. |
| Opto | @audio/dynamics-opto | RMS | A 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-varimu | RMS, of its own output | A 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.
Copy to Clipboardimport { 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.
Copy to Clipboardengine.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:
| Model | Above the curve | Why |
|---|---|---|
| Smooth | under 0.1 dB | Its gain reduction is smoothed in decibels, after the curve |
| Opto | about 2.3 dB | It follows the RMS level, 3 dB under a sine's peak |
| Vari-Mu | about 1.5 dB | It follows the RMS level of its own output |
| VCA, FET | 4.4 dB at 100 Hz to 5.6 dB at 1 kHz | Their detectors follow the waveform itself, so the gain comes back between its peaks |