applied patch from Duong-Khang NGUYEN <neoneurone@users.sf.net>, which
[supertux.git] / src / sound.c
index 69c980b..1decace 100644 (file)
@@ -10,8 +10,6 @@
   April 22, 2000 - July 15, 2002
 */
 
-#ifndef NOSOUND
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -20,8 +18,6 @@
 #include <SDL.h>
 #include <SDL_image.h>
 
-#include <SDL_mixer.h>
-
 #ifdef LINUX
 #include <pwd.h>
 #include <sys/types.h>
 #include "sound.h"
 #include "setup.h"
 
+#ifndef NOSOUND
+
+/* --- OPEN THE AUDIO DEVICE --- */
+
+int open_audio (int frequency, Uint16 format, int channels, int chunksize)
+{
+  if (use_sound) {
+    return Mix_OpenAudio( frequency, format, channels, chunksize );
+  }
+  else {
+    // let the user think that the audio device was correctly opened
+    // and keep the compiler happy :-D
+    return 0;
+  }
+}
+
 
 /* --- LOAD A SOUND --- */
 
 Mix_Chunk * load_sound(char * file)
 {
   Mix_Chunk * snd;
-  
+
   if (use_sound)
   {
     snd = Mix_LoadWAV(file);
-  
+
     if (snd == NULL)
       st_abort("Can't load", file);
   }
@@ -54,14 +66,6 @@ Mix_Chunk * load_sound(char * file)
 }
 
 
-/* --- PLAY A SOUND --- */
-
-void playsound(Mix_Chunk * snd)
-{
-  Mix_PlayChannel(-1, snd, 0);
-}
-
-
 /* --- LOAD A SONG --- */
 
 Mix_Music * load_song(char * file)
@@ -81,4 +85,85 @@ Mix_Music * load_song(char * file)
   return (sng);
 }
 
+
+/* --- PLAY A SOUND --- */
+
+ void play_sound(Mix_Chunk * snd)
+ {
+  // this won't call the function if the user has disabled sound
+  if (use_sound) {
+    Mix_PlayChannel(-1, snd, 0);
+  }
+}
+
+
+void free_chunk(Mix_Chunk *chunk)
+{
+  if (use_sound) {
+    DEBUG_MSG( __PRETTY_FUNCTION__ );
+    Mix_FreeChunk( chunk );
+  }
+}
+
+int playing_music(void)
+{
+  if (use_sound) {
+    return Mix_PlayingMusic();
+  }
+  else {
+    /* we are in --disable-sound we can't be playing music */
+    return 0;
+  }
+}
+
+
+int halt_music(void)
+{
+  if (use_sound) {
+    return Mix_HaltMusic();
+  }
+  else {
+    return 0;
+  }
+}
+
+
+int play_music(Mix_Music *music, int loops)
+{
+  if (use_sound) {
+    DEBUG_MSG(__PRETTY_FUNCTION__);
+    return Mix_PlayMusic(music, loops);
+  }
+  else {
+    /* return error since you're trying to play music in --disable-sound mode */
+    return -1;
+  }
+}
+
+
+void free_music(Mix_Music *music)
+{
+  if (use_sound) {
+    DEBUG_MSG(__PRETTY_FUNCTION__);
+    Mix_FreeMusic( music );
+  }
+}
+
+#else
+
+int open_audio (int frequency, int format, int channels, int chunksize)
+{
+  return -1;
+}
+
+void* load_sound(void* file) { return NULL; }
+void play_sound(void * snd) {}
+void* load_song(void* file) { return NULL; }
+
+int playing_music() { return 0; }
+void halt_music() {}
+int play_music(int *music, int loops) { return 0;}
+void free_music(int *music) {}
+void free_chunk(int *chunk) {}
+
 #endif