@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
29 lines (28 loc) • 618 B
JavaScript
import { QUARTER_PI } from "@thi.ng/math/api";
import { clamp11 } from "@thi.ng/math/interval";
import { AProc } from "./aproc.js";
import { __ensureGenN } from "./internal/ensure.js";
const pan = (pos) => new Pan(pos);
class Pan extends AProc {
_pos;
constructor(pos = 0) {
super([0, 0]);
this.pos = pos;
}
get pos() {
return this._pos.deref();
}
set pos(pos) {
this._pos = __ensureGenN(pos, clamp11);
}
next(x) {
const pos = this._pos.next() * QUARTER_PI;
const s = x * Math.sin(pos);
const c = x * Math.cos(pos);
return [c - s, s + c];
}
}
export {
Pan,
pan
};