# Transient shaper

> A transient shaper device: attack and sustain, each up or down by 12 dB, a panel with one handle for both, a Web Audio engine and tools for agents.

```tsx
import { useState } from "react";
import {
  type TransientState,
  transientDevice,
} from "@/components/audio-ui/devices/transient/device";
import { createTransientEngine } from "@/components/audio-ui/devices/transient/engine";
import { TransientPanel } from "@/components/audio-ui/devices/transient/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 transient shaper you can plug in: its state, a panel with a handle for
 * the attack and the sustain and an engine that plays it, each its own file
 * and none knowing the others. Play the loop and drag the handle: up for more
 * click, down to soften it, left to shorten what rings.
 */
export function BlockTransient() {
  const [state, setState] = useState<TransientState>(() =>
    transientDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createTransientEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, transientDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <TransientPanel onValueChange={setState} signal={signal} value={state} />
    </div>
  );
}
```

Shapes the attack and the sustain of a sound, at any level. A drum gains click or loses it, and a pluck rings longer or shorter. There is no threshold, so a quiet hit and a loud one are shaped alike. It runs on the transient shaper of [audio.js](https://audio.js.org). 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/transient
```

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

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

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

```tsx title="components/examples/block-transient.tsx"
import { useState } from "react";
import {
  type TransientState,
  transientDevice,
} from "@/components/audio-ui/devices/transient/device";
import { createTransientEngine } from "@/components/audio-ui/devices/transient/engine";
import { TransientPanel } from "@/components/audio-ui/devices/transient/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 transient shaper you can plug in: its state, a panel with a handle for
 * the attack and the sustain and an engine that plays it, each its own file
 * and none knowing the others. Play the loop and drag the handle: up for more
 * click, down to soften it, left to shorten what rings.
 */
export function BlockTransient() {
  const [state, setState] = useState<TransientState>(() =>
    transientDevice.defaults()
  );
  const master = useMasterBus(MASTER_VOLUME);
  const sound = useDemoSound("groove");
  const { engine } = useDeviceLoop({
    create: createTransientEngine,
    destination: master,
    sound,
    state,
  });
  const signal = useDeviceSignal(engine, transientDevice);
  return (
    <div className="rounded-xl h-full w-full min-w-0">
      <TransientPanel 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 transient 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. |
| Attack | -12 dB to 12 dB | 6 dB | Turns the start of a hit up or down. |
| Sustain | -12 dB to 12 dB | 0 dB | Turns what rings after the hit up or down. |
| Output | -12 dB to 12 dB | 0 dB | The level of the output. |

## Panel

The panel is a square with the sustain across and the attack up, and one handle to drag to both at once. The centre is a sound left as it is.

```tsx
import { TransientPanel } from "@/components/audio-ui/devices/transient/panel";
import { transientDevice } from "@/components/audio-ui/devices/transient/device";

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

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

## Engine

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

The browser has no such node. The shaper is the processor of `@audio/dynamics-transient-shaper`'s manifest as published, in an `AudioWorklet`. It tells the attack by how far the level rises over a copy of it 50 times slower, and moves the gain in a line between the attack's and the sustain's. Only the shape of the envelope counts, not its level. Until it is ready the signal passes unchanged. Its attack and sustain change as it plays.

Measured in Chrome on a decaying tone, +9 on the attack raises the first peak by 8.9 dB at -6 dB and at -26 dB, -9 lowers it by 7.3 to 8.4 dB, and the sustain moves the tail by 8.7 to 9.0 dB, from 60 Hz to 2 kHz. A sustain turned up raises the first peak too, by about 1.5 dB: its gain blends with the attack's in a line.
