# useDemoSource

> The sound a device plays: the one chosen in its session, such as from a preview's bar, else the one that shows best what the device does. It tells the session its default, so a bar can offer the choice only where there is one. Outside a session it is always the default.

```bash
npx shadcn@latest add @audio-ui/use-demo-source
```

```ts
import { useDemoSource, useDemoSound } from "@/hooks/use-demo-source";
```

- Files: `hooks/use-demo-source.ts`
- Depends on: `demo-sound`, `use-audio-session`, `use-device-loop`, `use-play-switch`, `web-audio`; npm: nothing
- Used by: `block-auto-pan`, `block-bass-enhancer`, `block-binaural-panner`, `block-channel-eq`, `block-chorus`, `block-compander`, `block-compressor`, `block-deesser`, `block-delay`, `block-device-chain`, `block-distortion`, `block-ducker`, `block-equalizer`, `block-exciter`, `block-expander`, `block-filter`, `block-frequency-shifter`, `block-gate`, `block-graphic-eq`, `block-limiter`, `block-lofi`, `block-mid-side`, `block-multiband`, `block-overdrive`, `block-phaser`, `block-redux`, `block-reverb`, `block-rotary`, `block-saturator`, `block-stutter`, `block-tilt-eq`, `block-transient`, `block-unlimiter`, `block-utility`, `block-vibe`, `block-wah`

| Export | Kind | What it is |
| --- | --- | --- |
| `useDemoSource` | function | The sound a device plays: the one chosen in its session, such as from a preview's bar, else `fallback`, the one that shows best what the device does. |
| `useDemoSound` | function | The demo sound a device plays (`useDemoSource`), rendered for the page's context, with the kick that goes with it as a sidechain key when `key` is set: the `sound` of `useDeviceLoop`. |

## Usage

The sound a device plays: the one chosen in its [session](/docs/hooks/use-audio-session), such as from a preview's bar, else `fallback`, the one that shows best what the device does. It tells the session its fallback, so a bar offers the choice only where there is one.

```tsx
import { useDemoSource } from "@/hooks/use-demo-source";

const name = useDemoSource("groove"); // one of DEMO_SOURCES
```

The sounds are [`demo-sound`](/docs/lib/demo-sound)'s, made in code. Outside a session it is always `fallback`.

`useDemoSound(fallback, { key })` renders that sound for the page's context, with the kick that goes with it when `key` is set: the `sound` of [`useDeviceLoop`](/docs/hooks/use-device-loop). It renders once the session's play switch is on, so no audio context is made before a press, and is `null` until then.

```tsx
import { useDemoSound } from "@/hooks/use-demo-source";

const sound = useDemoSound("groove");
```
