# Limiter

> A limiter device: input gain, ceiling, release and true peak, a panel that draws its transfer curve with a handle on the ceiling, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type LimiterState,
  limiterDevice,
} from "@/components/audio-ui/devices/limiter/device";
import { createLimiterEngine } from "@/components/audio-ui/devices/limiter/engine";
import { LimiterPanel } from "@/components/audio-ui/devices/limiter/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 limiter you can plug in: its state, a panel that draws its transfer curve with a handle on the ceiling and an engine that plays it, each its own file. Play the loop, push the gain and pull the ceiling down.
 */
export function BlockLimiter() {
  const [state, setState] = useState<LimiterState>(() =>
    limiterDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createLimiterEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, limiterDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <LimiterPanel onValueChange={setState} signal={signal} value={state} />
    </div>
  );
}
```

Keeps the sound under a ceiling. The input gain pushes the level against it, and what goes over is held down. It is the lookahead brickwall limiter of [audio.js](https://audio.js.org), which can hold true peaks. 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/limiter
```

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

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

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

```tsx title="components/examples/block-limiter.tsx"
import { useState } from "react";
import {
  type LimiterState,
  limiterDevice,
} from "@/components/audio-ui/devices/limiter/device";
import { createLimiterEngine } from "@/components/audio-ui/devices/limiter/engine";
import { LimiterPanel } from "@/components/audio-ui/devices/limiter/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 limiter you can plug in: its state, a panel that draws its transfer curve with a handle on the ceiling and an engine that plays it, each its own file. Play the loop, push the gain and pull the ceiling down.
 */
export function BlockLimiter() {
  const [state, setState] = useState<LimiterState>(() =>
    limiterDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createLimiterEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, limiterDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <LimiterPanel 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 limiter 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. |
| Gain | 0 dB to 24 dB | 0 dB | Pushes the level of the input against the ceiling. |
| Ceiling | -24 dB to 0 dB | -1 dB | The level the output should not go over. |
| Release | 10 ms to 1000 ms | 100 ms | How fast the gain comes back after a peak. |
| Look-ahead | 0.1 ms to 20 ms | 5 ms | How far ahead the limiter sees a peak coming: how long it takes to bring the gain down into it, and how late the sound comes out. |
| True peak | On or off | Off | Keeps the waveform rebuilt between the samples under the ceiling too, not only the samples. It adds 96 samples of latency. |

## Panel

The panel draws the transfer curve against the straight line of a clean sound. Drag the handle up and down for the ceiling and across for the input gain.

```tsx
import { LimiterPanel } from "@/components/audio-ui/devices/limiter/panel";
import { limiterDevice } from "@/components/audio-ui/devices/limiter/device";

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

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

## Engine

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

```ts
engine.reduction; // dB being taken off, read per frame
```

The limiter is the processor of `@audio/dynamics-limiter`'s manifest as published, in an `AudioWorklet`. Until the worklet is ready, the signal passes at the input gain. The ceiling and the release change as it plays. A new look-ahead or true peak, which set its delay, builds it again: at most every 50 ms, the new one first playing the last 100 ms of sound, then taking over in a 30 ms fade. `engine.reduction` reads the gain it takes off, measured from its output against its input as late.

Its latency is the look-ahead, plus 96 samples with True peak on, and the device declares it, so a host that compensates latency keeps it in time. Measured on noise pushed 20 dB over the ceiling:

| True peak | Samples | Between the samples |
| --- | --- | --- |
| Off | at the ceiling | up to 1.5 dB over it |
| On | at the ceiling | at it, read at 8 points a sample; 0.02 dB over, read at the 4 of BS.1770 |
