# oversampling

> What a waveshaper that oversamples costs in time, and a delay that holds a dry path back by it, so a distortion mixed with its dry sound does not comb. Measured in Chrome.

```bash
npx shadcn@latest add @audio-ui/oversampling
```

```ts
import { oversamplingSeconds, oversamplingDelay, createOversamplingDelay } from "@/lib/oversampling";
```

- Files: `lib/oversampling.ts`
- Depends on: nothing; npm: nothing
- Used by: `distortion-device`, `distortion-engine`, `limiter-device`, `overdrive-device`, `overdrive-engine`, `saturator-device`, `saturator-engine`, `vibe-device`, `wave-shaper-device`, `wave-shaper-engine`

| Export | Kind | What it is |
| --- | --- | --- |
| `oversamplingSeconds` | function | The delay in seconds a `WaveShaperNode` adds when it oversamples at `amount`, at a sample rate. |
| `oversamplingDelay` | function | The delay in seconds a `WaveShaperNode` adds when it oversamples at `amount`, in a context. |
| `createOversamplingDelay` | function | A delay node that holds a dry path back by the oversampling of a shaper. |

## Usage

Waveshaping without aliasing, and the latency it costs: a `WaveShaperNode` oversampled 2x or 4x delays the sound a little, so a dry path mixed beside it has to wait as long.

```ts
import { createOversamplingDelay, oversamplingSeconds } from "@/lib/oversampling";

shaper.oversample = "4x";
const dryDelay = createOversamplingDelay(ctx, "4x"); // the dry path waits as long as the shaper
const latency = oversamplingSeconds("4x", ctx.sampleRate); // what a device declares
```

The saturator, overdrive and wave shaper use it.
