diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2013-06-17 10:18:35 +0300 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-24 16:56:45 -0700 |
commit | cc19844b5117539c197f19564c04f104df8d9ee8 (patch) | |
tree | 7098736cd69f2ffe5bbcfe88de91be28b09a6253 | |
parent | ce9057fc48ce6c7fda32b5029f8001e3a2c77685 (diff) |
Adjust SDL Web Audio API backend to make it work on Firefox nightly. Note that this path is still disabled for Firefox, since Mozilla Audio Data API gives better sound quality.
-rw-r--r-- | src/library_sdl.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index e8c4b6b8..f06fade7 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1579,10 +1579,10 @@ var LibrarySDL = { // Allocate new sound buffer to be played. var source = SDL.audioContext['createBufferSource'](); if (SDL.audio.soundSource[SDL.audio.nextSoundSource]) { - SDL.audio.soundSource[SDL.audio.nextSoundSource]['disconnect'](); + SDL.audio.soundSource[SDL.audio.nextSoundSource]['disconnect'](); // Explicitly disconnect old source, since we know it shouldn't be running anymore. } SDL.audio.soundSource[SDL.audio.nextSoundSource] = source; - source.buffer = SDL.audioContext['createBuffer'](SDL.audio.channels,sizeSamplesPerChannel,SDL.audio.freq); + var soundBuffer = SDL.audioContext['createBuffer'](SDL.audio.channels,sizeSamplesPerChannel,SDL.audio.freq); SDL.audio.soundSource[SDL.audio.nextSoundSource]['connect'](SDL.audioContext['destination']); // The input audio data is interleaved across the channels, i.e. [L, R, L, R, L, R, ...] and is either 8-bit or 16-bit as @@ -1590,7 +1590,7 @@ var LibrarySDL = { // so perform a buffer conversion for the data. var numChannels = SDL.audio.channels; for(var i = 0; i < numChannels; ++i) { - var channelData = SDL.audio.soundSource[SDL.audio.nextSoundSource]['buffer']['getChannelData'](i); + var channelData = soundBuffer['getChannelData'](i); if (channelData.length != sizeSamplesPerChannel) { throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + sizeSamplesPerChannel + ' samples!'; } @@ -1605,6 +1605,8 @@ var LibrarySDL = { } } } + // Workaround https://bugzilla.mozilla.org/show_bug.cgi?id=883675 by setting the buffer only after filling. The order is important here! + source['buffer'] = soundBuffer; // Schedule the generated sample buffer to be played out at the correct time right after the previously scheduled // sample buffer has finished. |