[gcompris] core sdl_mixer backend.



commit f5faf19558c1e7883e33403839c6e8e8a0d38a83
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Tue Oct 23 01:06:18 2012 +0200

    core sdl_mixer backend.
    
    Implemented gc_sound_fx_close() to support the play and interrupt mode.
    Strange that it was not implemented before. It will for sure improve our
    windows version on the audio side.

 src/gcompris/sdlplayer.c     |   14 ++++++++++----
 src/gcompris/soundutil_sdl.c |    1 +
 src/gcompris/soundutil_sdl.h |    1 +
 3 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/src/gcompris/sdlplayer.c b/src/gcompris/sdlplayer.c
index d346fc3..6e15a0a 100644
--- a/src/gcompris/sdlplayer.c
+++ b/src/gcompris/sdlplayer.c
@@ -51,6 +51,7 @@ int len=4096, bits=0, which=0;
 #define AUDIO_BUFFERS 2048
 
 static gboolean sound_closed = FALSE;
+static int _channel_fx = -1;
 
 /******************************************************************************/
 /* some simple exit and error routines                                        */
@@ -139,10 +140,14 @@ int sdlplayer_music(char *filename, int volume)
   return(0);
 }
 
+void sdl_player_fx_cancel() {
+  if ( _channel_fx != -1)
+    Mix_HaltChannel(_channel_fx);
+}
+
 int sdlplayer_fx(char *filename, int volume)
 {
   Mix_Chunk *sample;
-  static int channel;
 
   g_warning("sdlplayer %s\n", filename);
 
@@ -154,11 +159,11 @@ int sdlplayer_fx(char *filename, int volume)
 
   Mix_VolumeChunk(sample, MIX_MAX_VOLUME);
 
-  if((channel=Mix_PlayChannel(-1, sample, 0))==-1) {
-    return(cleanExit("Mix_LoadChannel(0x%p,1)",channel));
+  if((_channel_fx = Mix_PlayChannel(-1, sample, 0))==-1) {
+    return(cleanExit("Mix_LoadChannel(0x%p,1)", _channel_fx));
   }
 
-  while(Mix_Playing(channel))
+  while( Mix_Playing( _channel_fx ) )
     {
       SDL_Delay(50);
     }
@@ -166,6 +171,7 @@ int sdlplayer_fx(char *filename, int volume)
   // free the sample
   // Mix_Chunk *sample;
   Mix_FreeChunk(sample);
+  _channel_fx = -1;
 
   g_warning("sdlplayer complete playing of %s\n", filename);
 
diff --git a/src/gcompris/soundutil_sdl.c b/src/gcompris/soundutil_sdl.c
index 9719e46..534853b 100644
--- a/src/gcompris/soundutil_sdl.c
+++ b/src/gcompris/soundutil_sdl.c
@@ -116,6 +116,7 @@ gc_sound_bg_close()
 void
 gc_sound_fx_close()
 {
+   sdl_player_fx_cancel();
 }
 
 void
diff --git a/src/gcompris/soundutil_sdl.h b/src/gcompris/soundutil_sdl.h
index 9f0286a..f7025ea 100644
--- a/src/gcompris/soundutil_sdl.h
+++ b/src/gcompris/soundutil_sdl.h
@@ -47,6 +47,7 @@ void	 sdlplayer_resume_music();
 void	 sdlplayer_halt_fx();
 void	 sdlplayer_resume_fx();
 int	 sdlplayer_fx(char *filename, int volume);
+void	 sdl_player_fx_cancel();
 
 gchar *gc_sound_alphabet(gchar *chars);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]