UNPKG

@thi.ng/dsp

Version:

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

66 lines (65 loc) 1.23 kB
import { AProc } from "./aproc.js"; function serial(...procs) { const [a, b, c, d] = procs; switch (procs.length) { case 2: return new Serial2(a, b); case 3: return new Serial3(a, b, c); case 4: return new Serial4(a, b, c, d); default: return new Serial(procs); } } class Serial2 extends AProc { constructor(_a, _b) { super(null); this._a = _a; this._b = _b; } next(x) { return this._val = this._b.next(this._a.next(x)); } } class Serial3 extends AProc { constructor(_a, _b, _c) { super(null); this._a = _a; this._b = _b; this._c = _c; } next(x) { return this._val = this._c.next(this._b.next(this._a.next(x))); } } class Serial4 extends AProc { constructor(_a, _b, _c, _d) { super(null); this._a = _a; this._b = _b; this._c = _c; this._d = _d; } next(x) { return this._val = this._d.next( this._c.next(this._b.next(this._a.next(x))) ); } } class Serial extends AProc { constructor(_procs) { super(null); this._procs = _procs; } next(x) { return this._val = this._procs.reduce((x2, p) => p.next(x2), x); } } export { Serial, Serial2, Serial3, Serial4, serial };