From 4b08dd8447e24216ae1caa4a317362f7f0103867 Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 13 Dec 2025 15:20:51 -0600 Subject: [PATCH] Unify lfo functions --- packages/superdough/helpers.mjs | 53 ++++++++++++++++-------------- packages/superdough/superdough.mjs | 2 +- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index b13f4049..7b9becdf 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -109,36 +109,39 @@ export function getEnvelope(audioContext, properties = {}) { return getWorklet(audioContext, 'envelope-processor', properties); } -export function getLfo(audioContext, begin, end, properties = {}) { - const { shape = 0, ...props } = properties; - const { dcoffset = -0.5, depth = 1 } = properties; +export function getLfo(audioContext, properties = {}) { + const { + shape = 0, + begin = 0, + end = 0, + time, + depth = 1, + dcoffset = -0.5, + frequency = 1, + skew = 0.5, + phaseoffset = 0, + curve = 1, + min, + max, + ...props + } = properties; + const lfoprops = { - frequency: 1, - depth, - skew: 0.5, - phaseoffset: 0, - time: begin, begin, end, - shape: getModulationShapeInput(shape), + time: time ?? begin, + depth, dcoffset, - min: dcoffset * depth, - max: dcoffset * depth + depth, - curve: 1, - ...props, - }; - - return getWorklet(audioContext, 'lfo-processor', lfoprops); -} - -export function getCustomLfo(audioContext, properties = {}) { - // Default / process certain params - const { shape = 0, ...props } = properties; - const lfoprops = { + frequency, + skew, + phaseoffset, + curve, shape: getModulationShapeInput(shape), - dcoffset: -0.5, + min: min ?? dcoffset * depth, + max: max ?? dcoffset * depth + depth, ...props, }; + return getWorklet(audioContext, 'lfo-processor', lfoprops); } @@ -177,7 +180,9 @@ export function getParamLfo(audioContext, param, start, end, lfoValues) { } let lfo; if (depth) { - lfo = getLfo(audioContext, start, end, { + lfo = getLfo(audioContext, { + begin: start, + end, depth, dcoffset, ...getLfoInputs, diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index ba84d691..5ea04f89 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -457,7 +457,7 @@ function connectLFO(idx, params, nodeTracker) { min, max, }; - const lfoNode = getCustomLfo(getAudioContext(), modParams); + const lfoNode = getLfo(getAudioContext(), modParams); nodeTracker[`lfo${idx}`] = [lfoNode]; targetParams.forEach((t) => lfoNode.connect(t)); return lfoNode;