Audio UI
Bends the sound into one of four curves. The more the drive, the more the peaks round off, or fold back. 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/distortion
It installs the device's state, its engine and its panel to components/audio-ui/devices/distortion/. The demo above, which wires them to a loop, is @audio-ui/block-distortion.
Controls
Controls · 6
Panel
The panel draws the transfer curve, the output for each input, against the straight line of a clean sound, and picks the curve with buttons drawn from each. distortionShape(curve, input) is a curve at an input after the drive, and distortionCurve(state) is the whole curve with the mix and the output.
Copy to Clipboardimport { DistortionPanel } from "@/components/audio-ui/devices/distortion/panel"; import { distortionDevice } from "@/components/audio-ui/devices/distortion/device"; const [state, setState] = useState(() => distortionDevice.defaults()); <DistortionPanel onValueChange={setState} value={state} />;
Engine
Create it, connect it and update it as for any device: see The engine.
The drive is a gain before the table of the curve, so turning it never changes the table; only picking another curve does. The tables are written by the curves of @audio/effect-distortion (distortionTable(curve)) over the whole range of the drive, so a fold keeps folding at full drive. The shaper oversamples 4x to keep the curve from aliasing, which is the latency of the device.