UNPKG

@thi.ng/dsp

Version:

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

49 lines (48 loc) 830 B
import { TAU } from "@thi.ng/math/api"; import { AGen } from "./agen.js"; class SinCos extends AGen { constructor(_freq, _amp = 1) { super([0, _amp]); this._freq = _freq; this._amp = _amp; this.calcCoeffs(); } _f; _s; _c; copy() { return new SinCos(this._freq, this._amp); } reset() { this.calcCoeffs(); return this; } next() { this._val = [this._s, this._c]; this._s += this._f * this._c; this._c -= this._f * this._s; return this._val; } freq() { return this._freq; } setFreq(freq) { this._freq = freq; this.calcCoeffs(); } amp() { return this._amp; } setAmp(amp) { this._amp = amp; this.calcCoeffs(); } calcCoeffs() { this._f = TAU * this._freq; this._s = 0; this._c = this._amp; } } export { SinCos };