# dsp

> The audio.js processors the registry's devices are built on, from @audio-ui/engine: compressor and expander models, the gain curves of dynamics, filter circuits, reverbs and biquad shelves, under one dependency.

```bash
npm install @audio-ui/engine
```

```ts
import { highshelf, lowshelf, magnitude, compandStream, compressorGain, /* … */ } from "@audio-ui/engine/dsp";
```

- audio.js: [`@audio/biquad`](https://audio.js.org/modules/biquad/), [`@audio/dynamics-compand`](https://audio.js.org/modules/dynamics-compand/), [`@audio/dynamics-compressor`](https://audio.js.org/modules/dynamics-compressor/), [`@audio/dynamics-deesser`](https://audio.js.org/modules/dynamics-deesser/), [`@audio/dynamics-expander`](https://audio.js.org/modules/dynamics-expander/), [`@audio/dynamics-fet`](https://audio.js.org/modules/dynamics-fet/), [`@audio/dynamics-limiter`](https://audio.js.org/modules/dynamics-limiter/), [`@audio/dynamics-opto`](https://audio.js.org/modules/dynamics-opto/), [`@audio/dynamics-unlimit`](https://audio.js.org/modules/dynamics-unlimit/), [`@audio/dynamics-varimu`](https://audio.js.org/modules/dynamics-varimu/), [`@audio/dynamics-vca`](https://audio.js.org/modules/dynamics-vca/), [`@audio/effect-distortion`](https://audio.js.org/modules/effect-distortion/), [`@audio/filter-diode-ladder`](https://audio.js.org/modules/filter-diode-ladder/), [`@audio/filter-korg35`](https://audio.js.org/modules/filter-korg35/), [`@audio/filter-moog-ladder`](https://audio.js.org/modules/filter-moog-ladder/), [`@audio/filter-oberheim`](https://audio.js.org/modules/filter-oberheim/), [`@audio/reverb-dattorro`](https://audio.js.org/modules/reverb-dattorro/), [`@audio/reverb-fdn`](https://audio.js.org/modules/reverb-fdn/), [`@audio/reverb-freeverb`](https://audio.js.org/modules/reverb-freeverb/), [`@audio/reverb-schroeder`](https://audio.js.org/modules/reverb-schroeder/), [`@audio/reverb-spring`](https://audio.js.org/modules/reverb-spring/)

| Export | Kind | What it is |
| --- | --- | --- |
| `highshelf` | function | High-shelf. |
| `lowshelf` | function | Low-shelf. |
| `magnitude` | function | |H(f)| of one section at frequency `f` — analysis/plotting. |
| `compandStream` | function | { write, flush } streaming primitive underlying the default export's streaming form. |
| `compressorGain` | function | Soft-knee downward compression curve. |
| `compressor` | const | The smooth compressor's manifest: an AudioWorklet processor's parameters and state, as its package publishes them. |
| `deesser` | const | The de-esser's manifest: its processor's parameters and latency. |
| `expanderGain` | function | Soft-knee downward expansion curve. |
| `upwardExpanderGain` | function | Soft-knee upward expansion curve — the above-threshold complement of expanderGain. |
| `expander` | const | The expander's manifest: its processor's parameters and modes. |
| `fet` | const | The FET compressor model's manifest. |
| `limiterLatency` | function | Samples the output trails the input by: the lookahead, and 96 with `truePeak`. |
| `opto` | const | The opto compressor model's manifest. |
| `unlimitDeficitGain` | function | adaptive (default) pure mapping: transient deficit (crestTarget − peak-held transientness) → target lift (dB), gated by onset presence. |
| `unlimitGain` | function | adaptive:false pure mapping: transientness (fast-over-slow envelope gap, dB) → target lift (dB), before ballistic smoothing. |
| `unlimit` | const | The de-limiter's manifest: its processor's parameters. |
| `varimu` | const | The vari-mu compressor model's manifest. |
| `vca` | const | The VCA compressor model's manifest. |
| `distortion` | function | Mutates `data` in place and returns the same reference. |
| `diodeLadder` | function | The diode ladder filter, run over a buffer in place. |
| `korg35` | function | The Korg35 filter, run over a buffer in place. |
| `moogLadder` | function | The Moog ladder filter, two or four poles, run over a buffer in place. |
| `oberheim` | function | The Oberheim SEM state-variable filter, run over a buffer in place. |
| `dattorro` | function | Process in place. |
| `fdn` | function | Process in place. |
| `freeverb` | function | Process in place. |
| `schroeder` | function | Process a mono buffer in place; returns the same array. |
| `spring` | function | Process a mono buffer in place; returns the same array. |

## Usage

A device describes its parameters itself, and takes the processors it is made of from here: the models a compressor offers, the gain curve a panel draws, the circuits of a filter, the reverbs a room is rendered with. They are the audio.js atoms' own, under the names the devices use, so a project depends on `@audio-ui/engine` and not on each atom:

```ts
import { compressorGain, moogLadder } from "@audio-ui/engine/dsp";

// At -10 dB in, a -20 dB threshold, 4:1 and a 6 dB knee: -7.5 dB of gain.
compressorGain(-10, -20, 4, 6);
```

| What | Exports |
| --- | --- |
| Dynamics models, each the manifest of an `AudioWorklet` processor | `compressor`, `fet`, `opto`, `varimu`, `vca`, `deesser`, `expander`, `unlimit` |
| Gain curves, for a panel's transfer curve | `compressorGain`, `expanderGain`, `upwardExpanderGain`, `unlimitGain`, `unlimitDeficitGain`, `compandStream` |
| Filter circuits | `moogLadder`, `diodeLadder`, `korg35`, `oberheim` |
| Reverbs | `dattorro`, `fdn`, `freeverb`, `schroeder`, `spring` |
| Shaping and filters | `distortion`, `lowshelf`, `highshelf`, `magnitude`, `limiterLatency` |

A device's engine runs the same atoms in an `AudioWorklet` through [`kernels`](/docs/engine/kernels).
