Audio UI
Cuts the sound between hits. Above the threshold the signal passes, and below it the signal is turned down to the floor. It is the gate of audio.js, which closes only under a lower threshold than the one it opens at. A key connected to the sidechain, such as a kick, opens and closes it in place of the sound: it is only listened to, never heard. 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/gate
It installs the device's state, its engine and its panel to components/audio-ui/devices/gate/. The demo above, which wires them to a loop, is @audio-ui/block-gate.
Controls
Controls · 8
Panel
The panel draws the transfer curve against the straight line of a clean sound, with a handle on the threshold.
Copy to Clipboardimport { GatePanel } from "@/components/audio-ui/devices/gate/panel"; import { gateDevice } from "@/components/audio-ui/devices/gate/device"; const [state, setState] = useState(() => gateDevice.defaults()); <GatePanel onValueChange={setState} value={state} />;
Engine
Create it, connect it and update it as for any device: see The engine.
The browser has no gate node. The engine is the processor of @audio/dynamics-gate's manifest as published, in an AudioWorklet with two inputs, the sound and the key, with its own look-ahead. With nothing on engine.sidechain, it follows the sound itself. Until the worklet is ready the gate stays open. The threshold, the hysteresis, the floor, the attack, the hold and the release change as it plays. A new look-ahead 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. gateSettings(state) gives the numbers the engine puts on it.