# Phaser

> A phaser device: a phaser, classic or flanger mode, a rate or a note value, a depth, a centre frequency, a delay, the classic phaser's stages, a feedback and a mix, a panel that draws the sweep, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type PhaserState,
  phaserDevice,
} from "@/components/audio-ui/devices/phaser/device";
import { createPhaserEngine } from "@/components/audio-ui/devices/phaser/engine";
import { PhaserPanel } from "@/components/audio-ui/devices/phaser/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 phaser and flanger you can plug in: its state, a panel that draws the sweep and an engine that plays it, each its own file. Play the loop, switch the mode and turn the rate and the feedback.
 */
export function BlockPhaser() {
  const [state, setState] = useState<PhaserState>(() =>
    phaserDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createPhaserEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, phaserDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <PhaserPanel
        onValueChange={setState}
        signal={signal}
        tempo={tempo}
        value={state}
      />
    </div>
  );
}
```

Sweeps notches through the sound with a slow oscillator. In Phaser mode it is a chain of four all-pass filters around a centre frequency. In Classic mode it is 2 to 12 first-order all-pass stages, as analog phasers have. In Flanger mode it is a very short delay. 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/phaser
```

It installs the device's state, its engine and its panel to `components/audio-ui/devices/phaser/`. The demo above, which wires them to a loop, is `@audio-ui/block-phaser`.

**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/phaser-device @audio-ui/phaser-panel @audio-ui/phaser-engine
```

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

```tsx title="components/examples/block-phaser.tsx"
import { useState } from "react";
import {
  type PhaserState,
  phaserDevice,
} from "@/components/audio-ui/devices/phaser/device";
import { createPhaserEngine } from "@/components/audio-ui/devices/phaser/engine";
import { PhaserPanel } from "@/components/audio-ui/devices/phaser/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 phaser and flanger you can plug in: its state, a panel that draws the sweep and an engine that plays it, each its own file. Play the loop, switch the mode and turn the rate and the feedback.
 */
export function BlockPhaser() {
  const [state, setState] = useState<PhaserState>(() =>
    phaserDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine, tempo } = useDeviceLoop({
    create: createPhaserEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, phaserDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <PhaserPanel
        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 phaser 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. |
| Mode | Phaser, Classic, Flanger | Phaser | Phaser sweeps four second-order all-pass filters, an octave range either side of the centre. Classic sweeps first-order stages in a straight line around the centre, from the centre less the depth's share of it to the centre plus as much, so its notches spend longer in the highs. Flanger sweeps the delay. It is picked in the title bar, and the controls the mode does not use are drawn off. |
| Rate | 0.05 Hz to 10.00 Hz | 0.40 Hz | How fast the oscillator sweeps. |
| 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 % | 60 % | How far the oscillator moves the filters or the delay. For Classic, the share of the centre the sweep goes either side of it. |
| Center | 200 Hz to 8 kHz | 1.2 kHz | The frequency the phaser sweeps around. |
| Delay | 0.5 ms to 10 ms | 3 ms | The delay the flanger sweeps around. |
| Stages | 2 to 12 | 4 | How many first-order stages the classic phaser has, 2 to 12: half as many notches. A new count waits for the knob to rest, then fades in. |
| Feedback | 0 % to 90 % | 40 % | How much of the output goes back in, which deepens the notches. |
| Mix | 0 % to 100 % | 50 % | The balance of the processed signal and the dry one. |

## Panel

The panel draws what the oscillator does over two seconds, and picks the mode in its title bar. `phaserSweep(state)` is what it draws, and `phaserSettings(state)` gives the numbers that go on the nodes.

```tsx
import { PhaserPanel } from "@/components/audio-ui/devices/phaser/panel";
import { phaserDevice } from "@/components/audio-ui/devices/phaser/device";

const [state, setState] = useState(() => phaserDevice.defaults());

<PhaserPanel onValueChange={setState} value={state} />;
```

## Engine

Create it, connect it and update it as for any device: see [The engine](/docs/devices#the-engine).

The phaser and flanger paths are always built and the mode crossfades them, so switching does not click. One oscillator moves the filters, in cents, and the delay, in seconds. The flanger's sweep is kept inside its delay so the time never goes negative.

The classic phaser runs on the audio thread: the kernel of `@audio/effect-phaser` in an `AudioWorklet` loaded from a blob (`PHASER_WORKLET` is its source), 128 frames at a time, with its own oscillator. A worklet cannot import, so the device carries the kernel as published (`PHASER_KERNELS`, in its `kernels.ts`). The worklet is fed only while Classic plays. Until it has loaded, and in a context with no worklets, Classic plays the phaser: `ready` resolves once it is in the graph.
