diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index 236a147c..889ca18b 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -215,11 +215,16 @@ export function applyFM(param, value, begin) { fmwave: fmWaveform = 'sine', duration, } = value; + let modulator; + let stop = () => {}; if (fmModulationIndex) { const ac = getAudioContext(); const envGain = ac.createGain(); - const { node: modulator, stop } = fm(param, fmHarmonicity, fmModulationIndex, fmWaveform); + const fmmod = fm(param, fmHarmonicity, fmModulationIndex, fmWaveform); + + modulator = fmmod.node; + stop = fmmod.stop; if (![fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity].find((v) => v !== undefined)) { // no envelope by default modulator.connect(param); @@ -242,4 +247,5 @@ export function applyFM(param, value, begin) { envGain.connect(param); } } + return { stop }; } diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index 1ec74f97..b828645c 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -208,7 +208,7 @@ export function getOscillator(s, t, value) { // pitch envelope getPitchEnvelope(o.detune, value, t, t + duration); - applyFM(o.frequency, value, t); + const fmModulator = applyFM(o.frequency, value, t); let noiseMix; if (noise) { @@ -218,9 +218,9 @@ export function getOscillator(s, t, value) { return { node: noiseMix?.node || o, stop: (time) => { + fmModulator.stop(time); vibratoOscillator?.stop(time); noiseMix?.stop(time); - // stopFm?.(time); o.stop(time); }, triggerRelease: (time) => {