Audio UI
Keeps the sound under a ceiling. The input gain pushes the level against it, and what goes over is held down. It is the lookahead brickwall limiter of audio.js, which can hold true peaks. 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/limiter
It installs the device's state, its engine and its panel to components/audio-ui/devices/limiter/. The demo above, which wires them to a loop, is @audio-ui/block-limiter.
Controls
Controls · 6
Panel
The panel draws the transfer curve against the straight line of a clean sound. Drag the handle up and down for the ceiling and across for the input gain.
Copy to Clipboardimport { LimiterPanel } from "@/components/audio-ui/devices/limiter/panel"; import { limiterDevice } from "@/components/audio-ui/devices/limiter/device"; const [state, setState] = useState(() => limiterDevice.defaults()); <LimiterPanel 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
The limiter is the processor of @audio/dynamics-limiter's manifest as published, in an AudioWorklet. Until the worklet is ready, the signal passes at the input gain. The ceiling and the release change as it plays. A new look-ahead or true peak, which set its delay, builds it again: at most every 50 ms, the new one first playing the last 100 ms of sound, then taking over in a 30 ms fade. engine.reduction reads the gain it takes off, measured from its output against its input as late.
Its latency is the look-ahead, plus 96 samples with True peak on, and the device declares it, so a host that compensates latency keeps it in time. Measured on noise pushed 20 dB over the ceiling:
| True peak | Samples | Between the samples |
|---|---|---|
| Off | at the ceiling | up to 1.5 dB over it |
| On | at the ceiling | at it, read at 8 points a sample; 0.02 dB over, read at the 4 of BS.1770 |