From 886b16d6fd906c1a1f917679bed0eb4011e42371 Mon Sep 17 00:00:00 2001 From: Jade Rowland Date: Thu, 23 Nov 2023 14:07:32 -0500 Subject: [PATCH] fixed panic function --- packages/superdough/superdough.mjs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index a1b81edd..2eb4a64f 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -36,15 +36,6 @@ export const getAudioContext = () => { } return audioContext; }; -// outputs: Map -const outputs = new Map(); - -export const panic = () => { - outputs.forEach((output) => { - return output.gain.linearRampToValueAtTime(0, getAudioContext().currentTime + 0.01); - }); - outputs.clear(); -}; let workletsLoading; @@ -92,13 +83,16 @@ export async function initAudioOnFirstClick(options) { let delays = {}; const maxfeedback = 0.98; -let channelMerger; +let channelMerger, destinationGain; + // input: AudioNode, channels: ?Array export const connectToDestination = (input, channels = [0, 1]) => { const ctx = getAudioContext(); if (channelMerger == null) { channelMerger = new ChannelMergerNode(ctx, { numberOfInputs: ctx.destination.channelCount }); - channelMerger.connect(ctx.destination); + destinationGain = new GainNode(ctx); + channelMerger.connect(destinationGain); + destinationGain.connect(ctx.destination); } //This upmix can be removed if correct channel counts are set throughout the app, // and then strudel could theoretically support surround sound audio files @@ -114,6 +108,11 @@ export const connectToDestination = (input, channels = [0, 1]) => { }); }; +export const panic = () => { + destinationGain.gain.linearRampToValueAtTime(0, getAudioContext().currentTime + 0.01); + destinationGain = null; +}; + function getDelay(orbit, delaytime, delayfeedback, t) { if (delayfeedback > maxfeedback) { //logger(`delayfeedback was clamped to ${maxfeedback} to save your ears`);