Skip to content

Commit

Permalink
emscripten: don't replace the AudioContext if the SDL node has <1 cha…
Browse files Browse the repository at this point in the history
…nnels
  • Loading branch information
AliceLR committed Aug 15, 2020
1 parent 49fbd76 commit aab52a6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions arch/emscripten/web/res/mzxrun_loader.js
Expand Up @@ -33,17 +33,21 @@
if(!swapSdlContext || sdl.audioContext.state !== "suspended")
return;

// Replace the forever-locked context that SDL2 creates in favor
// of the unlocked one we created earlier.
sdl.audioContext = audioCtx;

// Fetch some data from the original script processor node and create
// a new one.
let node = sdl.audio.scriptProcessorNode;
let buffer = node.bufferSize;
let channels = node.channelCount;
let audioProcessFunc = node.onaudioprocess;

// If any of the values is obviously invalid, abort.
if(typeof(channels) !== "number" || channels < 1)
return;

// Replace the forever-locked context that SDL2 creates in favor
// of the unlocked one we created earlier.
sdl.audioContext = audioCtx;

sdl.audio.scriptProcessorNode =
sdl.audioContext.createScriptProcessor(buffer, 0, channels);

Expand Down

0 comments on commit aab52a6

Please sign in to comment.