# Chorus

> A chorus device: a rate or a note value, a depth, a delay, one to eight voices and a mix, a panel that draws the sweep of each voice, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type ChorusState,
  chorusDevice,
} from "@/components/audio-ui/devices/chorus/device";
import { createChorusEngine } from "@/components/audio-ui/devices/chorus/engine";
import { ChorusPanel } from "@/components/audio-ui/devices/chorus/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useDeviceSignal } from "@/hooks/use-device-signal";
import { useMasterBus } from "@/hooks/use-master-bus";
import { useDemoSound } from "@/hooks/use-demo-source";

const MASTER_VOLUME = 0.7;

/**
 * A chorus you can plug in: its state, a panel that draws the sweep of its
 * delay and an engine that plays it, each its own file and none knowing the
 * others. Play the loop and turn the rate and the depth.
 */
export function BlockChorus() {
  const [state, setState] = useState<ChorusState>(() =>
    chorusDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createChorusEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, chorusDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <ChorusPanel
        onValueChange={setState}
        signal={signal}
        tempo={tempo}
        value={state}
      />
    </div>
  );
}
```

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](/docs/devices): a state, a panel, an engine and tools, each its own file.

## Installation

**CLI**

```bash
npx 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`.

**Manual**

**1. Install the packages:**

```bash
npm install @ui-sdk/core@0.1.0-beta.14 @ui-sdk/react@0.1.0-beta.14
```

**2. Add the pieces you want. All of them, or only the state and the panel if your engine is elsewhere:**

```bash
npx shadcn@latest add @audio-ui/chorus-device @audio-ui/chorus-panel @audio-ui/chorus-engine
```

**3. Copy and paste the demo that wires them, if you want it.**

```tsx title="components/examples/block-chorus.tsx"
import { useState } from "react";
import {
  type ChorusState,
  chorusDevice,
} from "@/components/audio-ui/devices/chorus/device";
import { createChorusEngine } from "@/components/audio-ui/devices/chorus/engine";
import { ChorusPanel } from "@/components/audio-ui/devices/chorus/panel";
import { useDeviceLoop } from "@/hooks/use-device-loop";
import { useDeviceSignal } from "@/hooks/use-device-signal";
import { useMasterBus } from "@/hooks/use-master-bus";
import { useDemoSound } from "@/hooks/use-demo-source";

const MASTER_VOLUME = 0.7;

/**
 * A chorus you can plug in: its state, a panel that draws the sweep of its
 * delay and an engine that plays it, each its own file and none knowing the
 * others. Play the loop and turn the rate and the depth.
 */
export function BlockChorus() {
  const [state, setState] = useState<ChorusState>(() =>
    chorusDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createChorusEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, chorusDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <ChorusPanel
        onValueChange={setState}
        signal={signal}
        tempo={tempo}
        value={state}
      />
    </div>
  );
}
```

**Agent**

Paste this prompt to your agent. It does the rest: it installs the skill, adds the component and wires it to your audio.

```text
Install the audio/ui skill with `npx skills add ouestlabs/audio-ui`, then follow it to add the chorus from audio/ui to my project and wire it to my audio code. Read the docs at https://www.audio-ui.dev/llms.txt first.
```

To let the agent read the docs live, connect the [MCP server](/docs/mcp). More in [Agent Skill](/docs/agents).

## Controls

| Control | Range | Default | What it does |
| --- | --- | --- | --- |
| On | On or off | On | Turns the device on. Off, the signal passes through unchanged. |
| Rate | 0.05 Hz to 8.00 Hz | 0.80 Hz | How fast the oscillator sweeps the delay. |
| Sync | On or off | Off | Takes the rate from a note value and the tempo of the host. See [Tempo sync](/docs/devices#tempo-sync). |
| Note | 1/32 triplet, 1/32, 1/32 dotted, 1/16 triplet, 1/16, 1/16 dotted, 1/8 triplet, 1/8, 1/8 dotted, 1/4 triplet, 1/4, 1/4 dotted, 1/2 triplet, 1/2, 1/2 dotted, 1/1 triplet, 1/1, 1/1 dotted | 1/4 | The note value of one cycle of the oscillator. |
| Depth | 0 % to 100 % | 40 % | How far the oscillator moves the delay. |
| Delay | 5 ms to 40 ms | 18 ms | The delay the sweep is centred on. |
| Voices | 1 to 8 | 1 | How many delays are read, 1 to 8, their oscillators spread evenly around the cycle. However many there are, they play as loud as one. A new count or a new delay with more than one voice waits for the knob to rest, then fades in. |
| Mix | 0 % to 100 % | 50 % | The balance of the delayed signal and the dry one. |

## 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.

```tsx
import { 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](/docs/devices#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.
