UNPKG

@thi.ng/dsp

Version:

Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils

42 lines (41 loc) 777 B
import { PI, QUARTER_PI } from "@thi.ng/math/api"; import { clamp05 } from "@thi.ng/math/interval"; import { AProc } from "./aproc.js"; const allpass = (freq) => new AllPass1(freq); class AllPass1 extends AProc { _freq; _coeff; _z1; constructor(freq) { super(0); this.setFreq(freq); this.reset(); } reset() { this._z1 = 0; return this; } next(x) { const { _coeff, _z1 } = this; x -= _z1 * _coeff; this._z1 = x; return x * _coeff + _z1; } low(x) { return (x + this.next(x)) * 0.5; } high(x) { return (x - this.next(x)) * 0.5; } freq() { return this._freq; } setFreq(freq) { this._freq = clamp05(freq); this._coeff = Math.tan(freq * PI - QUARTER_PI); } } export { AllPass1, allpass };