diff options
-rw-r--r-- | src/library_sdl.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 79468af8..55e9aa49 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1595,13 +1595,17 @@ var LibrarySDL = { var curtime = SDL.audioContext['currentTime']; if (curtime > SDL.audio.nextPlayTime && SDL.audio.nextPlayTime != 0) { console.log('warning: Audio callback had starved sending audio by ' + (curtime - SDL.audio.nextPlayTime) + ' seconds.'); - // Immediately queue up an extra buffer to force the sound feeding to be ahead by one sample block: - Browser.safeSetTimeout(SDL.audio.caller, 1); } var playtime = Math.max(curtime, SDL.audio.nextPlayTime); SDL.audio.soundSource[SDL.audio.nextSoundSource]['start'](playtime); - SDL.audio.nextPlayTime = playtime + SDL.audio.soundSource[SDL.audio.nextSoundSource]['buffer']['duration']; + var buffer_duration = SDL.audio.soundSource[SDL.audio.nextSoundSource]['buffer']['duration']; + SDL.audio.nextPlayTime = playtime + buffer_duration; SDL.audio.nextSoundSource = (SDL.audio.nextSoundSource + 1) % 4; + // Make sure we are always more than one sample block ahead of the current time to avoid starving. + if (curtime + buffer_duration + buffer_duration >= SDL.audio.nextPlayTime) { + // Immediately queue up an extra buffer to force the sound feeding to be ahead by more than one sample block: + Browser.safeSetTimeout(SDL.audio.caller, 1); + } } catch(e) { console.log('Web Audio API error playing back audio: ' + e.toString()); } |