@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
29 lines (28 loc) • 512 B
JavaScript
import { AGen } from "./agen.js";
const alt = (n = 1) => new Alt(n, -n);
const altT = (a, b) => new Alt(a, b);
const altB = (x = true) => new Alt(x, !x);
class Alt extends AGen {
constructor(_a, _b) {
super(_b);
this._a = _a;
this._b = _b;
}
_flip = true;
copy() {
return new Alt(this._a, this._b);
}
reset() {
this._flip = true;
return this;
}
next() {
return this._val = (this._flip = !this._flip) ? this._b : this._a;
}
}
export {
Alt,
alt,
altB,
altT
};