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