import type { IReset } from "@thi.ng/api" ; import { TAU } from "@thi.ng/math/api" ; import { AGen } from "./agen.js" ; remarks param freq param amp export class SinCos extends AGen < number [ ] > implements IReset { protected _f ! : number ; protected _s ! : number ; protected _c ! : number ; constructor ( protected _freq , protected _amp = 1 ) { super ( [ 0 , _amp ] ) ; this . calcCoeffs ( ) ; } 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 ( ) ; } protected calcCoeffs ( ) { this . _f = TAU * this . _freq ; this . _s = 0 ; this . _c = this . _amp ; } }