Difuse the onceEnded mechanism

This commit is contained in:
jeromew 2025-12-04 13:17:20 +00:00
parent e01621d0cc
commit 46291bf85c
3 changed files with 11 additions and 10 deletions

View file

@ -324,10 +324,10 @@ export function getVibratoOscillator(param, value, t) {
gain.gain.value = vibmod * 100; gain.gain.value = vibmod * 100;
vibratoOscillator.connect(gain); vibratoOscillator.connect(gain);
gain.connect(param); gain.connect(param);
vibratoOscillator.onended = () => { onceEnded(vibratoOscillator, () => {
gain.disconnect(param); gain.disconnect(param);
vibratoOscillator.disconnect(gain); vibratoOscillator.disconnect(gain);
}; });
vibratoOscillator.start(t); vibratoOscillator.start(t);
return vibratoOscillator; return vibratoOscillator;
} }

View file

@ -1,4 +1,4 @@
import { drywet } from './helpers.mjs'; import { drywet, onceEnded } from './helpers.mjs';
import { getAudioContext } from './audioContext.mjs'; import { getAudioContext } from './audioContext.mjs';
let noiseCache = {}; let noiseCache = {};
@ -65,7 +65,7 @@ export function getNoiseOscillator(type = 'white', t, density = 0.02) {
export function getNoiseMix(inputNode, wet, t) { export function getNoiseMix(inputNode, wet, t) {
const noiseOscillator = getNoiseOscillator('pink', t); const noiseOscillator = getNoiseOscillator('pink', t);
const noiseMix = drywet(inputNode, noiseOscillator.node, wet); const noiseMix = drywet(inputNode, noiseOscillator.node, wet);
noiseOscillator.node.onended = () => noiseMix.onended(); onceEnded(noiseOscillator.node, () => noiseMix.onended());
return { return {
node: noiseMix.node, node: noiseMix.node,
stop: (time) => noiseOscillator?.stop(time), stop: (time) => noiseOscillator?.stop(time),

View file

@ -1,5 +1,6 @@
import { clamp } from './util.mjs'; import { clamp } from './util.mjs';
import { registerSound, soundMap } from './superdough.mjs'; import { registerSound, soundMap } from './superdough.mjs';
import { onceEnded } from './helpers.mjs';
import { getAudioContext } from './audioContext.mjs'; import { getAudioContext } from './audioContext.mjs';
import { import {
applyFM, applyFM,
@ -110,7 +111,7 @@ export function registerSynthSounds() {
const mix = gainNode(mixGain); const mix = gainNode(mixGain);
o.onended = () => { onceEnded(o, () => {
o.disconnect(); o.disconnect();
g.disconnect(); g.disconnect();
sat.disconnect(); sat.disconnect();
@ -118,7 +119,7 @@ export function registerSynthSounds() {
noiseGain.disconnect(); noiseGain.disconnect();
mix.disconnect(); mix.disconnect();
onended(); onended();
}; });
const node = o.connect(sat).connect(g).connect(mix); const node = o.connect(sat).connect(g).connect(mix);
noise.node.connect(noiseGain).connect(mix); noise.node.connect(noiseGain).connect(mix);
@ -384,11 +385,11 @@ export function registerSynthSounds() {
const { duration } = value; const { duration } = value;
o.onended = () => { onceEnded(o, () => {
o.disconnect(); o.disconnect();
g.disconnect(); g.disconnect();
onended(); onended();
}; });
const envGain = gainNode(1); const envGain = gainNode(1);
let node = o.connect(g).connect(envGain); let node = o.connect(g).connect(envGain);
@ -489,11 +490,11 @@ export function getOscillator(s, t, value, onended) {
noiseMix = getNoiseMix(o, noise, t); noiseMix = getNoiseMix(o, noise, t);
} }
o.onended = () => { onceEnded(o, () => {
noiseMix || o.disconnect(); noiseMix || o.disconnect();
noiseMix?.node.disconnect(); noiseMix?.node.disconnect();
onended(); onended();
}; });
o.start(t); o.start(t);
return { return {