Skip to content

Commit 9440047

Browse files
committed
Remove the use of Web Audio API ScriptProcessorNode for queueing buffers. It doesn't improve in practice, generates a new set of compatibility bugs and is limited to one sampling frequency only (which the browser either matches or doesn't match at random). Keep the code simple and use a unified path for SDL audio in all audio frequencies.
1 parent df164a7 commit 9440047

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

src/library_sdl.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,27 +2269,11 @@ var LibrarySDL = {
22692269
SDL.audio.numAudioTimersPending = 0;
22702270
SDL.audio.timer = undefined;
22712271
}
2272-
if (SDL.audio.scriptProcessorNode !== undefined) {
2273-
SDL.audio.scriptProcessorNode['disconnect']();
2274-
SDL.audio.scriptProcessorNode = undefined;
2275-
}
2276-
} else if (!SDL.audio.timer && !SDL.audio.scriptProcessorNode) {
2277-
// If we are using the same sampling frequency as the native sampling rate of the Web Audio graph is using, we can feed our buffers via
2278-
// Web Audio ScriptProcessorNode, which is a pull-mode API that calls back to our code to get audio data.
2279-
if (SDL.audioContext !== undefined && SDL.audio.freq == SDL.audioContext['sampleRate'] && typeof SDL.audioContext['createScriptProcessor'] !== 'undefined') {
2280-
var sizeSamplesPerChannel = SDL.audio.bufferSize / SDL.audio.bytesPerSample / SDL.audio.channels; // How many samples per a single channel fit in the cb buffer?
2281-
SDL.audio.scriptProcessorNode = SDL.audioContext['createScriptProcessor'](sizeSamplesPerChannel, 0, SDL.audio.channels);
2282-
SDL.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
2283-
Runtime.dynCall('viii', SDL.audio.callback, [SDL.audio.userdata, SDL.audio.buffer, SDL.audio.bufferSize]);
2284-
SDL.fillWebAudioBufferFromHeap(SDL.audio.buffer, sizeSamplesPerChannel, e['outputBuffer']);
2285-
}
2286-
SDL.audio.scriptProcessorNode['connect'](SDL.audioContext['destination']);
2287-
} else { // If we are using a different sampling rate, must manually queue audio data to the graph via timers.
2288-
// Start the audio playback timer callback loop.
2289-
SDL.audio.numAudioTimersPending = 1;
2290-
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, 1);
2291-
SDL.audio.startTime = Date.now() / 1000.0; // Only used for Mozilla Audio Data API. Not needed for Web Audio API.
2292-
}
2272+
} else if (!SDL.audio.timer) {
2273+
// Start the audio playback timer callback loop.
2274+
SDL.audio.numAudioTimersPending = 1;
2275+
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, 1);
2276+
SDL.audio.startTime = Date.now() / 1000.0; // Only used for Mozilla Audio Data API. Not needed for Web Audio API.
22932277
}
22942278
SDL.audio.paused = pauseOn;
22952279
},

0 commit comments

Comments
 (0)