From 099288545e8d55a38c6a855f73126187b045a525 Mon Sep 17 00:00:00 2001 From: Aria Date: Thu, 4 Dec 2025 22:12:54 -0600 Subject: [PATCH] Working version --- packages/superdough/helpers.mjs | 5 +++-- packages/superdough/superdough.mjs | 16 +++++++++++----- packages/superdough/worklets-common.mjs | 1 - packages/superdough/worklets.mjs | 5 +++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index 88f2f7d8f..8b0f53cc6 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -566,8 +566,9 @@ export const getDistortionAlgorithm = (algo) => { return distortionAlgorithms[name]; }; -export const getDistortion = (distort, postgain, algorithm) => { - return getWorklet(getAudioContext(), 'distort-processor', { distort, postgain }, { processorOptions: { algorithm } }); +export const getDistortion = (fullParams) => { + const { algorithm, ...params } = fullParams; + return getPooledWorklet(getAudioContext(), 'distort-processor', params, {}, { algorithm }); }; export const getFrequencyFromValue = (value, defaultNote = 36) => { diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index c3708d275..affecf48e 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -539,7 +539,10 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) } const chain = []; // audio nodes that will be connected to each other sequentially chain.push(sourceNode); - stretch !== undefined && chain.push(getPooledWorklet(ac, 'phase-vocoder-processor', { pitchFactor: stretch })); + stretch !== undefined && + chain.push( + getPooledWorklet(ac, 'phase-vocoder-processor', { pitchFactor: stretch, begin: t, end: endWithRelease }), + ); // gain stage chain.push(gainNode(gain)); @@ -652,10 +655,13 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) } // effects - coarse !== undefined && chain.push(getPooledWorklet(ac, 'coarse-processor', { coarse })); - crush !== undefined && chain.push(getPooledWorklet(ac, 'crush-processor', { crush })); - shape !== undefined && chain.push(getPooledWorklet(ac, 'shape-processor', { shape, postgain: shapevol })); - distort !== undefined && chain.push(getDistortion(distort, distortvol, distorttype)); + coarse !== undefined && + chain.push(getPooledWorklet(ac, 'coarse-processor', { coarse, begin: t, end: endWithRelease })); + crush !== undefined && chain.push(getPooledWorklet(ac, 'crush-processor', { crush, begin: t, end: endWithRelease })); + shape !== undefined && + chain.push(getPooledWorklet(ac, 'shape-processor', { shape, postgain: shapevol, begin: t, end: endWithRelease })); + distort !== undefined && + chain.push(getDistortion({ distort, postgain: distortvol, algorithm: distorttype, begin: t, end: endWithRelease })); if (tremolosync != null) { tremolo = cps * tremolosync; diff --git a/packages/superdough/worklets-common.mjs b/packages/superdough/worklets-common.mjs index 00a5c44ff..704b50f27 100644 --- a/packages/superdough/worklets-common.mjs +++ b/packages/superdough/worklets-common.mjs @@ -41,7 +41,6 @@ export const makeReusable = (Base) => this.handlePortMessage(type, payload, e); } }; - this.initialize(); } initialize(_options) { diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index 44cc03dbd..9a59e14ec 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -476,7 +476,7 @@ function genHannWindow(length) { class PhaseVocoderProcessor extends OLAProcessor { static get parameterDescriptors() { - return [{ name: 'pitchFactor', defaultValue: 1.0 }]; + return [...super.parameterDescriptors, { name: 'pitchFactor', defaultValue: 1.0 }]; } constructor(options) { @@ -488,7 +488,8 @@ class PhaseVocoderProcessor extends OLAProcessor { this.invfftSize = 1 / this.fftSize; } - initialize(_options) { + initialize(options) { + super.initialize(options); this.timeCursor = 0; this.hannWindow = genHannWindow(this.fftSize); // prepare FFT and pre-allocate buffers