diff --git a/packages/superdough/helpers.mjs b/packages/superdough/helpers.mjs index 0b696df9..6fe1e5b7 100644 --- a/packages/superdough/helpers.mjs +++ b/packages/superdough/helpers.mjs @@ -324,10 +324,10 @@ export function getVibratoOscillator(param, value, t) { gain.gain.value = vibmod * 100; vibratoOscillator.connect(gain); gain.connect(param); - vibratoOscillator.onended = () => { + onceEnded(vibratoOscillator, () => { gain.disconnect(param); vibratoOscillator.disconnect(gain); - }; + }); vibratoOscillator.start(t); return vibratoOscillator; } diff --git a/packages/superdough/noise.mjs b/packages/superdough/noise.mjs index 3e41515d..da60e87a 100644 --- a/packages/superdough/noise.mjs +++ b/packages/superdough/noise.mjs @@ -1,4 +1,4 @@ -import { drywet } from './helpers.mjs'; +import { drywet, onceEnded } from './helpers.mjs'; import { getAudioContext } from './audioContext.mjs'; let noiseCache = {}; @@ -65,7 +65,7 @@ export function getNoiseOscillator(type = 'white', t, density = 0.02) { export function getNoiseMix(inputNode, wet, t) { const noiseOscillator = getNoiseOscillator('pink', t); const noiseMix = drywet(inputNode, noiseOscillator.node, wet); - noiseOscillator.node.onended = () => noiseMix.onended(); + onceEnded(noiseOscillator.node, () => noiseMix.onended()); return { node: noiseMix.node, stop: (time) => noiseOscillator?.stop(time), diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index b0235446..a2d3aeca 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -1,5 +1,6 @@ import { clamp } from './util.mjs'; import { registerSound, soundMap } from './superdough.mjs'; +import { onceEnded } from './helpers.mjs'; import { getAudioContext } from './audioContext.mjs'; import { applyFM, @@ -110,7 +111,7 @@ export function registerSynthSounds() { const mix = gainNode(mixGain); - o.onended = () => { + onceEnded(o, () => { o.disconnect(); g.disconnect(); sat.disconnect(); @@ -118,7 +119,7 @@ export function registerSynthSounds() { noiseGain.disconnect(); mix.disconnect(); onended(); - }; + }); const node = o.connect(sat).connect(g).connect(mix); noise.node.connect(noiseGain).connect(mix); @@ -384,11 +385,11 @@ export function registerSynthSounds() { const { duration } = value; - o.onended = () => { + onceEnded(o, () => { o.disconnect(); g.disconnect(); onended(); - }; + }); const envGain = gainNode(1); let node = o.connect(g).connect(envGain); @@ -489,11 +490,11 @@ export function getOscillator(s, t, value, onended) { noiseMix = getNoiseMix(o, noise, t); } - o.onended = () => { + onceEnded(o, () => { noiseMix || o.disconnect(); noiseMix?.node.disconnect(); onended(); - }; + }); o.start(t); return {