import type { IReset } from "@thi.ng/api" ; import { PI , QUARTER_PI } from "@thi.ng/math/api" ; import { clamp05 } from "@thi.ng/math/interval" ; import { AProc } from "./aproc.js" ; param freq export const allpass = ( freq ) => new AllPass1 ( freq ) ; export class AllPass1 extends AProc < number , number > implements IReset { protected _freq ! : number ; protected _coeff ! : number ; protected _z1 ! : number ; 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 ) ; } }