aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_sdl.js51
-rwxr-xr-xtests/runner.py9
-rw-r--r--tests/sdl_audio_mix.c83
-rw-r--r--tests/sounds/pluck.oggbin0 -> 69092 bytes
-rw-r--r--tests/sounds/the_entertainer.oggbin0 -> 557640 bytes
5 files changed, 120 insertions, 23 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 5033b27e..3dbb9a33 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1235,6 +1235,7 @@ var LibrarySDL = {
Mix_Init: function(flags) {
if (!flags) return 0;
+ SDL.channelMinimumNumber = 0;
return 8; /* MIX_INIT_OGG */
},
Mix_Quit: function(){},
@@ -1317,7 +1318,9 @@ var LibrarySDL = {
Mix_FreeChunk: function(id) {
SDL.audios[id] = null;
},
-
+ Mix_ReserveChannels: function(num) {
+ SDL.channelMinimumNumber = num;
+ },
Mix_PlayChannel: function(channel, id, loops) {
// TODO: handle loops
@@ -1330,8 +1333,8 @@ var LibrarySDL = {
// If the user asks us to allocate a channel automatically, get the first
// free one.
if (channel == -1) {
- channel = 0;
- for (var i = 0; i < SDL.numChannels; i++) {
+ channel = SDL.channelMinimumNumber;
+ for (var i = SDL.channelMinimumNumber; i < SDL.numChannels; i++) {
if (!SDL.channels[i].audio) {
channel = i;
break;
@@ -1403,6 +1406,7 @@ var LibrarySDL = {
audio.play();
}
audio.volume = channelInfo.volume;
+ audio.paused = false;
return channel;
},
Mix_PlayChannelTimed: 'Mix_PlayChannel', // XXX ignore Timing
@@ -1493,44 +1497,45 @@ var LibrarySDL = {
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_38.html#SEC38
// "Note: Does not check if the channel has been paused."
- Mix_Playing: function(id) {
- if (id === -1) {
+ Mix_Playing: function(channel) {
+ if (channel === -1) {
var count = 0;
- for (var i = 0; i < SDL.audios.length; i++) {
- count += SDL.Mix_Playing(i);
+ for (var i = 0; i < SDL.channels.length; i++) {
+ count += _Mix_Playing(i);
}
return count;
}
- var info = SDL.audios[id];
+ var info = SDL.channels[channel];
if (info && info.audio && !info.audio.paused) {
return 1;
}
return 0;
},
- Mix_Pause: function(id) {
- if (id === -1) {
- for (var i = 0; i<SDL.audios.length;i++) {
- SDL.Mix_Pause(i);
+ Mix_Pause: function(channel) {
+ if (channel === -1) {
+ for (var i = 0; i<SDL.channels.length;i++) {
+ _Mix_Pause(i);
}
return;
}
- var info = SDL.audios[id];
+ var info = SDL.channels[channel];
if (info && info.audio) {
info.audio.pause();
+ info.audio.paused = true;
}
},
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_39.html#SEC39
- Mix_Paused: function(id) {
- if (id === -1) {
+ Mix_Paused: function(channel) {
+ if (channel === -1) {
var pausedCount = 0;
- for (var i = 0; i<SDL.audios.length;i++) {
- pausedCount += SDL.Mix_Paused(i);
+ for (var i = 0; i<SDL.channels.length;i++) {
+ pausedCount += _Mix_Paused(i);
}
return pausedCount;
}
- var info = SDL.audios[id];
+ var info = SDL.channels[channel];
if (info && info.audio && info.audio.paused) {
return 1;
}
@@ -1542,14 +1547,14 @@ var LibrarySDL = {
},
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_33.html#SEC33
- Mix_Resume: function(id) {
- if (id === -1) {
- for (var i = 0; i<SDL.audios.length;i++) {
- SDL.Mix_Resume(i);
+ Mix_Resume: function(channel) {
+ if (channel === -1) {
+ for (var i = 0; i<SDL.channels.length;i++) {
+ _Mix_Resume(i);
}
return;
}
- var info = SDL.audios[id];
+ var info = SDL.channels[channel];
if (info && info.audio) {
info.audio.play();
}
diff --git a/tests/runner.py b/tests/runner.py
index eb0f8e7b..d46ca369 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10779,6 +10779,15 @@ elif 'browser' in str(sys.argv):
Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]']).communicate()
self.run_browser('page.html', '', '/report_result?1')
+ def test_sdl_audio_mix(self):
+ shutil.copyfile(path_from_root('tests', 'sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg'))
+ shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg'))
+ open(os.path.join(self.get_dir(), 'sdl_audio_mix.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix.c')).read()))
+
+ # use closure to check for a possible bug with closure minifying away newer Audio() attributes
+ Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '-o', 'page.html']).communicate()
+ self.run_browser('page.html', '', '/report_result?1')
+
def test_sdl_audio_quickload(self):
open(os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_quickload.c')).read()))
diff --git a/tests/sdl_audio_mix.c b/tests/sdl_audio_mix.c
new file mode 100644
index 00000000..e3431e0c
--- /dev/null
+++ b/tests/sdl_audio_mix.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_mixer.h>
+#include <assert.h>
+#include <emscripten.h>
+
+static Mix_Chunk *sound = NULL;
+static Mix_Music *music = NULL;
+
+static int soundChannel = 0;
+
+void one_iter();
+void one_iter() {
+ static int frames = 0;
+ frames++;
+
+ switch( frames ) {
+ case 1:
+ soundChannel = Mix_PlayChannel(-1, sound, 0);
+ printf("channel = %d", soundChannel);
+ assert(soundChannel != -1 && soundChannel != 0);
+ break;
+ case 2:
+ printf("channel %d is playing = %d", soundChannel, Mix_Playing(soundChannel));
+ assert(Mix_Playing(soundChannel));
+ break;
+ case 30:
+ Mix_Pause(soundChannel);
+ Mix_PlayMusic(music, 1);
+ break;
+ case 31:
+ assert(Mix_Paused(soundChannel));
+ assert(Mix_PlayingMusic());
+ break;
+ case 60:
+ Mix_Resume(soundChannel);
+ Mix_PauseMusic();
+ break;
+ case 61:
+ assert(Mix_Playing(soundChannel));
+ assert(Mix_PausedMusic());
+ break;
+ case 90:
+ Mix_ResumeMusic();
+ break;
+ case 91:
+ assert(Mix_PlayingMusic());
+ break;
+ case 120:
+ Mix_HaltChannel(soundChannel);
+ Mix_HaltMusic();
+ break;
+ };
+}
+
+
+int main(int argc, char **argv) {
+ SDL_Init(SDL_INIT_AUDIO);
+ Mix_Init(MIX_INIT_OGG);
+
+ // This reserves channel 0 for other purposes.
+ // We are just going to verify that we are not
+ // allocated channel 0 when we call Mix_PlayChannel(-1, ...)
+ Mix_ReserveChannels(1);
+
+ int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
+ assert(ret == 0);
+
+ sound = Mix_LoadWAV("sound.ogg");
+ assert(sound);
+ music = Mix_LoadMUS("music.ogg");
+ assert(music);
+
+ emscripten_set_main_loop(one_iter, 30, 0);
+
+ // force a quit
+ while(Mix_Init(0))
+ Mix_Quit();
+ Mix_CloseAudio();
+
+ return 0;
+}
+
diff --git a/tests/sounds/pluck.ogg b/tests/sounds/pluck.ogg
new file mode 100644
index 00000000..20f7b854
--- /dev/null
+++ b/tests/sounds/pluck.ogg
Binary files differ
diff --git a/tests/sounds/the_entertainer.ogg b/tests/sounds/the_entertainer.ogg
new file mode 100644
index 00000000..249e74f7
--- /dev/null
+++ b/tests/sounds/the_entertainer.ogg
Binary files differ