Audio UI
Shapes the attack and the sustain of a sound, at any level. A drum gains click or loses it, and a pluck rings longer or shorter. There is no threshold, so a quiet hit and a loud one are shaped alike. It runs on the transient shaper of audio.js. 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/transient
It installs the device's state, its engine and its panel to components/audio-ui/devices/transient/. The demo above, which wires them to a loop, is @audio-ui/block-transient.
Controls
Controls · 4
Panel
The panel is a square with the sustain across and the attack up, and one handle to drag to both at once. The centre is a sound left as it is.
Copy to Clipboardimport { TransientPanel } from "@/components/audio-ui/devices/transient/panel"; import { transientDevice } from "@/components/audio-ui/devices/transient/device"; const [state, setState] = useState(() => transientDevice.defaults()); <TransientPanel onValueChange={setState} value={state} />;
Engine
Create it, connect it and update it as for any device: see The engine.
The browser has no such node. The shaper is the processor of @audio/dynamics-transient-shaper's manifest as published, in an AudioWorklet. It tells the attack by how far the level rises over a copy of it 50 times slower, and moves the gain in a line between the attack's and the sustain's. Only the shape of the envelope counts, not its level. Until it is ready the signal passes unchanged. Its attack and sustain change as it plays.
Measured in Chrome on a decaying tone, +9 on the attack raises the first peak by 8.9 dB at -6 dB and at -26 dB, -9 lowers it by 7.3 to 8.4 dB, and the sustain moves the tail by 8.7 to 9.0 dB, from 60 Hz to 2 kHz. A sustain turned up raises the first peak too, by about 1.5 dB: its gain blends with the attack's in a line.