diff options
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r-- | src/library_sdl.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 75544765..aa7ab532 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -694,6 +694,11 @@ var LibrarySDL = { Module['canvas'].addEventListener(event, SDL.receiveEvent, true); }); Browser.setCanvasSize(width, height, true); + // Free the old surface first. + if (SDL.screen) { + SDL.freeSurface(SDL.screen); + SDL.screen = null; + } SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen'); if (!SDL.addedResizeListener) { SDL.addedResizeListener = true; @@ -1155,9 +1160,6 @@ var LibrarySDL = { SDL_OpenAudio: function(desired, obtained) { SDL.allocateChannels(32); - // FIXME: Assumes 16-bit audio - assert(obtained === 0, 'Cannot return obtained SDL audio params'); - SDL.audio = { freq: {{{ makeGetValue('desired', 'SDL.structs.AudioSpec.freq', 'i32', 0, 1) }}}, format: {{{ makeGetValue('desired', 'SDL.structs.AudioSpec.format', 'i16', 0, 1) }}}, @@ -1169,6 +1171,16 @@ var LibrarySDL = { timer: null }; + if (obtained) { + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.freq', 'SDL.audio.freq', 'i32') }}}; // no good way for us to know if the browser can really handle this + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.format', 33151, 'i16') }}}; // float, signed, 32-bit + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.channels', 'SDL.audio.channels', 'i8') }}}; + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.silence', makeGetValue('desired', 'SDL.structs.AudioSpec.silence', 'i8', 0, 1), 'i8') }}}; // unclear if browsers can provide this + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.samples', 'SDL.audio.samples', 'i16') }}}; + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.callback', 'SDL.audio.callback', '*') }}}; + {{{ makeSetValue('obtained', 'SDL.structs.AudioSpec.userdata', 'SDL.audio.userdata', '*') }}}; + } + var totalSamples = SDL.audio.samples*SDL.audio.channels; SDL.audio.bufferSize = totalSamples*2; // hardcoded 16-bit audio SDL.audio.buffer = _malloc(SDL.audio.bufferSize); @@ -1197,7 +1209,7 @@ var LibrarySDL = { SDL_PauseAudio: function(pauseOn) { if (SDL.audio.paused !== pauseOn) { - SDL.audio.timer = pauseOn ? SDL.audio.timer && clearInterval(SDL.audio.timer) : setInterval(SDL.audio.caller, 1/35); + SDL.audio.timer = pauseOn ? SDL.audio.timer && clearInterval(SDL.audio.timer) : Browser.safeSetInterval(SDL.audio.caller, 1/35); } SDL.audio.paused = pauseOn; }, @@ -1349,6 +1361,9 @@ var LibrarySDL = { channelInfo.audio = audio = audio.cloneNode(true); audio.numChannels = info.audio.numChannels; audio.frequency = info.audio.frequency; + + // TODO: handle N loops. Behavior matches Mix_PlayMusic + audio.loop = loops != 0; if (SDL.channelFinished) { audio['onended'] = function() { // TODO: cache these Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel); @@ -1450,7 +1465,7 @@ var LibrarySDL = { loops = Math.max(loops, 1); var audio = SDL.audios[id].audio; if (!audio) return 0; - audio.loop = loops != 1; // TODO: handle N loops for finite N + audio.loop = loops != 0; // TODO: handle N loops for finite N if (SDL.audios[id].buffer) { audio["mozWriteAudio"](SDL.audios[id].buffer); } else { |