aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-05 14:25:18 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-03-05 14:25:18 -0800
commitdaed1bdade84f5aa3c18d87dbad1858998e5d7c1 (patch)
tree9b7d4f8321d44e79ed8b7f88d2dc0e492105a82d
parentdf26b7eebaa8d5745bbbc64bf09024099099a82c (diff)
parent2e9cb244f45c8dfe6bbd4b1f779c15b0d73a0f74 (diff)
Merge branch 'sd-audio' of github.com:michaeljbishop/emscripten into michaeljbishop-sd-audio
-rw-r--r--src/library_sdl.js56
-rw-r--r--tests/sdl_audio.c20
2 files changed, 72 insertions, 4 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 96ae6fa2..30735a0b 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1463,10 +1463,66 @@ var LibrarySDL = {
return (SDL.music.audio && !SDL.music.audio.paused) ? 1 : 0;
},
+ // 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) {
+ var count = 0;
+ for (var i = 0; i < SDL.audios.length; i++)
+ count += SDL.Mix_Playing(i);
+ return count;
+ }
+ var info = SDL.audios[id];
+ 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);
+ return;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio)
+ info.audio.pause();
+ },
+
+ // http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_39.html#SEC39
+ Mix_Paused: function(id) {
+ if (id === -1) {
+ var pausedCount = 0;
+ for (var i = 0; i<SDL.audios.length;i++)
+ pausedCount += SDL.Mix_Paused(i);
+ return pausedCount;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio && info.audio.paused) {
+ return 1;
+ }
+ return 0;
+ },
+
Mix_PausedMusic: function() {
return (SDL.music.audio && SDL.music.audio.paused) ? 1 : 0;
},
+ // 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);
+ return;
+ }
+ var info = SDL.audios[id];
+ if (info && info.audio)
+ {
+ info.audio.play();
+ }
+ },
+
// SDL TTF
TTF_Init: function() { return 0 },
diff --git a/tests/sdl_audio.c b/tests/sdl_audio.c
index 938df3c4..ce3bf5a9 100644
--- a/tests/sdl_audio.c
+++ b/tests/sdl_audio.c
@@ -6,13 +6,14 @@
Mix_Chunk *sound, *sound2;
-void play2();
+int play2();
-void play() {
+int play() {
int channel = Mix_PlayChannel(-1, sound, 1);
assert(channel == 0);
emscripten_run_script("setTimeout(Module['_play2'], 500)");
+ return channel;
}
void done(int channel) {
@@ -22,11 +23,12 @@ void done(int channel) {
REPORT_RESULT();
}
-void play2() {
+int play2() {
Mix_ChannelFinished(done);
int channel2 = Mix_PlayChannel(-1, sound2, 1);
assert(channel2 == 1);
+ return channel2;
}
int main(int argc, char **argv) {
@@ -40,7 +42,17 @@ int main(int argc, char **argv) {
sound2 = Mix_LoadWAV("sound2.wav");
assert(sound);
- play();
+ int channel = play();
+ printf( "Pausing Channel %d", channel );
+ Mix_Pause(channel);
+ int paused = Mix_Paused(channel);
+ printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
+ assert(paused);
+ Mix_Resume(channel);
+ paused = Mix_Paused(channel);
+ printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
+ assert(paused == 0);
+
if (argc == 12121) play2(); // keep it alive
emscripten_run_script("element = document.createElement('input');"