@thi.ng/dsp
Version:
Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils
16 lines (15 loc) • 423 B
JavaScript
import { mix as _mix } from "@thi.ng/math/mix";
import { fract } from "@thi.ng/math/prec";
const wavetable = (table, interpolate = _mix) => {
const n = table.length;
const n1 = n - 1;
return (phase, freq, amp = 1, dc = 0) => {
phase = fract(phase * freq) * n;
let i = phase | 0;
let j = i < n1 ? i + 1 : 0;
return dc + amp * interpolate(table[i], table[j], phase - i);
};
};
export {
wavetable
};