# Saturator

> A saturator device: four curves, a drive, a mix and an output, a panel that draws the transfer curve, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type SaturatorState,
  saturatorDevice,
} from "@/components/audio-ui/devices/saturator/device";
import { createSaturatorEngine } from "@/components/audio-ui/devices/saturator/engine";
import { SaturatorPanel } from "@/components/audio-ui/devices/saturator/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 saturator you can plug in: its state, a panel that draws its transfer
 * curve and an engine that plays it, each its own file and none knowing the
 * others. Play the loop, pick a curve and turn the drive: the curve bends as
 * the sound does.
 */
export function BlockSaturator() {
  const [state, setState] = useState<SaturatorState>(() =>
    saturatorDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createSaturatorEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, saturatorDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <SaturatorPanel onValueChange={setState} signal={signal} value={state} />
    </div>
  );
}
```

Adds warmth or dirt. The drive pushes the signal into one of four curves: a soft clip, a hard clip, a wavefold or an asymmetric tube. 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/saturator
```

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

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

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

```tsx title="components/examples/block-saturator.tsx"
import { useState } from "react";
import {
  type SaturatorState,
  saturatorDevice,
} from "@/components/audio-ui/devices/saturator/device";
import { createSaturatorEngine } from "@/components/audio-ui/devices/saturator/engine";
import { SaturatorPanel } from "@/components/audio-ui/devices/saturator/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 saturator you can plug in: its state, a panel that draws its transfer
 * curve and an engine that plays it, each its own file and none knowing the
 * others. Play the loop, pick a curve and turn the drive: the curve bends as
 * the sound does.
 */
export function BlockSaturator() {
  const [state, setState] = useState<SaturatorState>(() =>
    saturatorDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createSaturatorEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, saturatorDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <SaturatorPanel onValueChange={setState} signal={signal} 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 saturator 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. |
| Curve | Soft, Hard, Fold, Tube | Soft | The shape of the saturation. |
| Drive | 0 dB to 36 dB | 9 dB | How hard the signal is pushed into the curve. |
| Mix | 0 % to 100 % | 100 % | The balance of the saturated signal and the clean one. |
| Output | -24 dB to 12 dB | -3 dB | The level of the output. |

## Panel

The panel draws the transfer curve against the straight line of a clean sound. `saturate(curve, input)` is one curve and `saturatorCurve(state)` is the whole transfer curve with the mix and the output.

```tsx
import { SaturatorPanel } from "@/components/audio-ui/devices/saturator/panel";
import { saturatorDevice } from "@/components/audio-ui/devices/saturator/device";

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

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

## Engine

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

The drive is a gain before the table of the curve, so turning it never rebuilds the table. Only picking another curve does. The shaper oversamples 4x to keep the clip from aliasing, which is the [latency](/docs/devices#latency) of the device.
