Fix webAudioTimeout connecting the wrong AudioContext after export

This commit is contained in:
Tijmen Zwaan
2026-08-13 19:26:52 +02:00
parent 75f58bc875
commit c5b42b5555
2 changed files with 6 additions and 3 deletions
+3
View File
@@ -19,6 +19,9 @@ export const setAudioContext = (context) => {
// Existing nodes in the node pool contain references to the previous AudioContext,
// so all the nodes in the pool must be cleared when we set a new AudioContext.
clearNodePool();
if (audioContext && audioContext.state !== 'closed') {
audioContext.close();
}
audioContext = context;
return audioContext;
};
+3 -3
View File
@@ -6,8 +6,8 @@ import { clamp, nanFallback, midiToFreq, noteToMidi } from './util.mjs';
export const noises = ['pink', 'white', 'brown', 'crackle'];
export function gainNode(value) {
const node = getAudioContext().createGain();
export function gainNode(value, audioContext = getAudioContext()) {
const node = audioContext.createGain();
node.gain.value = value;
return node;
}
@@ -374,7 +374,7 @@ export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
// Certain browsers requires audio nodes to be connected in order for their onended events
// to fire, so we _mute it_ and then connect it to the destination
const zeroGain = gainNode(0);
const zeroGain = gainNode(0, audioContext);
zeroGain.connect(audioContext.destination);
constantNode.connect(zeroGain);