@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
27 lines (26 loc) • 642 B
JavaScript
import { AGen } from "./agen.js";
const add = (step, start, clamp) => new Add(step, start, clamp);
class Add extends AGen {
constructor(_step = 1, _start = 0, _clamp) {
super(0);
this._step = _step;
this._start = _start;
this._clamp = _clamp;
this.reset();
}
copy() {
return new Add(this._step, this._start, this._clamp);
}
reset() {
this._val = this._start - this._step;
return this;
}
next() {
let v = this._val + this._step;
return this._val = this._clamp !== void 0 ? this._start < this._clamp ? Math.min(v, this._clamp) : Math.max(v, this._clamp) : v;
}
}
export {
Add,
add
};