diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index 96cf3f67..a591df0f 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -343,41 +343,41 @@ function getDelay(orbit, delaytime, delayfeedback, t, channels) { return delays[orbit]; } -export function getLfo(audioContext, begin, end, properties = {}) { - const { shape = 0, ...props } = properties; - const { dcoffset = -0.5, depth = 1 } = properties; - return getWorklet(audioContext, 'lfo-processor', { - frequency: 1, - depth, - skew: 0, - phaseoffset: 0, - time: begin, - begin, - end, - shape: getModulationShapeInput(shape), - dcoffset, - min: dcoffset - depth * 0.5, - max: dcoffset + depth * 0.5, - curve: 1, - ...props, - }); -} - -// export function getLfo(audioContext, time, end, properties = {}) { +// export function getLfo(audioContext, begin, end, properties = {}) { +// const { shape = 0, ...props } = properties; +// const { dcoffset = -0.5, depth = 1 } = properties; // return getWorklet(audioContext, 'lfo-processor', { // frequency: 1, -// depth: 1, +// depth, // skew: 0, // phaseoffset: 0, -// time, -// begin: time, +// time: begin, +// begin, // end, -// shape: 1, -// dcoffset: -0.5, -// ...properties, +// shape: getModulationShapeInput(shape), +// dcoffset, +// min: dcoffset - depth * 0.5, +// max: dcoffset + depth * 0.5, +// curve: 1, +// ...props, // }); // } +export function getLfo(audioContext, time, end, properties = {}) { + return getWorklet(audioContext, 'lfo-processor', { + frequency: 1, + depth: 1, + skew: 0, + phaseoffset: 0, + time, + begin: time, + end, + shape: 1, + dcoffset: -0.5, + ...properties, + }); +} + export function getSyncedLfo(audioContext, time, end, cps, cycle, properties = {}) { const frequency = cycle / cps; diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index b4b36f6c..25dae03c 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -81,7 +81,70 @@ function getParamValue(block, param) { } return param[0]; } -const waveShapeNames = Object.keys(waveshapes); +// const waveShapeNames = Object.keys(waveshapes); +// class LFOProcessor extends AudioWorkletProcessor { +// static get parameterDescriptors() { +// return [ +// { name: 'time', defaultValue: 0 }, +// { name: 'end', defaultValue: 0 }, +// { name: 'frequency', defaultValue: 0.5 }, +// { name: 'skew', defaultValue: 0.5 }, +// { name: 'depth', defaultValue: 1 }, +// { name: 'phaseoffset', defaultValue: 0 }, +// { name: 'shape', defaultValue: 0 }, +// { name: 'dcoffset', defaultValue: 0 }, +// ]; +// } + +// constructor() { +// super(); +// this.phase; +// } + +// incrementPhase(dt) { +// this.phase += dt; +// if (this.phase > 1.0) { +// this.phase = this.phase - 1; +// } +// } + +// process(inputs, outputs, parameters) { +// // eslint-disable-next-line no-undef +// if (currentTime >= parameters.end[0]) { +// return false; +// } + +// const output = outputs[0]; +// const frequency = parameters['frequency'][0]; + +// const time = parameters['time'][0]; +// const depth = parameters['depth'][0]; +// const skew = parameters['skew'][0]; +// const phaseoffset = parameters['phaseoffset'][0]; + +// const dcoffset = parameters['dcoffset'][0]; +// const shape = waveShapeNames[parameters['shape'][0]]; + +// const blockSize = output[0].length ?? 0; + +// if (this.phase == null) { +// this.phase = _mod(time * frequency + phaseoffset, 1); +// } +// // eslint-disable-next-line no-undef +// const dt = frequency / sampleRate; +// for (let n = 0; n < blockSize; n++) { +// for (let i = 0; i < output.length; i++) { +// const modval = (waveshapes[shape](this.phase, skew) + dcoffset) * depth; +// output[i][n] = modval; +// } +// this.incrementPhase(dt); +// } + +// return true; +// } +// } +// registerProcessor('lfo-processor', LFOProcessor); +// const waveShapeNames = Object.keys(waveshapes); class LFOProcessor extends AudioWorkletProcessor { static get parameterDescriptors() { return [