pnpm dlx shadcn@latest add @audio-ui/oversampling
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.
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 declaresThe saturator, overdrive and wave shaper use it.