Audio UI
Thickens the sound with a short delay that a slow oscillator sweeps up and down, or up to eight of them, swept in turn. 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/chorus
It installs the device's state, its engine and its panel to components/audio-ui/devices/chorus/. The demo above, which wires them to a loop, is @audio-ui/block-chorus.
Controls
Controls · 8
Panel
The panel draws the delay time of each voice over two seconds as its oscillator moves it. chorusSweep(state, tempo, voice) is what it draws for a voice. With Sync on, it draws the oscillator at the rate it really has.
Copy to Clipboardimport { ChorusPanel } from "@/components/audio-ui/devices/chorus/panel"; import { chorusDevice } from "@/components/audio-ui/devices/chorus/device"; const [state, setState] = useState(() => chorusDevice.defaults()); <ChorusPanel onValueChange={setState} value={state} />;
Engine
Create it, connect it and update it as for any device: see The engine.
One voice is a delay node: the output of the oscillator, scaled by the depth, is added to its time. The sweep is kept inside the delay, so the time never goes negative.
Two to eight voices run on the audio thread: the kernel of @audio/effect-chorus in an AudioWorklet loaded from a blob (CHORUS_WORKLET is its source), 128 frames at a time, its depth the same sweep as a share of the delay. The kernel averages its voices, and on a full sound they hardly correlate, so the worklet raises them by the square root of their count. A worklet cannot import, so the device carries the kernel as published (CHORUS_KERNELS, in its kernels.ts). The worklet is fed only while more than one voice plays. Until it has loaded, and in a context with no worklets, the chorus plays one voice: ready resolves once it is in the graph.