audioJS

@audio/saturate-waveshaper

Status calibrated

npm1.1.3licenseMIT

Waveshaper — normalized tanh or custom curve, oversampled

Overview

Install
Updated
Family
saturate, 5 packages under it
Tags
shape
import waveshaper from '@audio/saturate-waveshaper'

Applies a memoryless transfer function to every sample — normalized tanh(drive·x) by default, or your own curve function. Oversampled (windowed-sinc up → shape → windowed-sinc down) so harmonics pushed above Nyquist by the nonlinearity fold back as inaudible energy instead of audible aliasing, not a naive per-sample waveshaper.

waveshaper(data, { drive: 4, fs: 44100 })
waveshaper(data, { curve: x => x - x ** 3 / 3, fs: 44100 })  // custom transfer
Param Default
drive 2 pre-gain into the tanh curve (ignored when curve is set)
curve x => tanh(drive·x)/tanh(drive) custom (x: number) => number transfer function, applied at the oversampled rate
fs 44100 sample rate
oversample 4 oversample factor; 1 disables oversampling (naive, aliased)
mix 1 0..1 — wet/dry blend

Mutates data in place and returns it (same array reference, not a copy). mix: 0 is an exact passthrough — verified bit-close (<1e-6) in the family test suite.

Use when: you need a specific custom transfer curve, or a clean tanh baseline without a particular harmonic-symmetry signature.
Not for: a specific circuit-modeled color — use tube (even harmonics), transistor (odd harmonics), or tape (HF-rolled tanh) for those.


Part of the @audio/saturate family.

MIT © audiojs