- memleak fix and menu fix from MatzeB
[supertux.git] / src / sound.cpp
index 340d019..0098cb0 100644 (file)
 #include "setup.h"
 
 /*global variable*/
-bool use_sound;           /* handle sound on/off menu and command-line option */
-bool use_music;           /* handle music on/off menu and command-line option */
-bool audio_device;        /* != 0: available and initialized */
-int current_music;
+bool use_sound = true;    /* handle sound on/off menu and command-line option */
+bool use_music = true;    /* handle music on/off menu and command-line option */
+bool audio_device = true; /* != 0: available and initialized */
 
 char * soundfilenames[NUM_SOUNDS] = {
                                        "/sounds/jump.wav",
@@ -47,15 +46,14 @@ char * soundfilenames[NUM_SOUNDS] = {
                                        "/sounds/shoot.wav",
                                        "/sounds/lifeup.wav",
                                        "/sounds/stomp.wav",
-                                       "/sounds/kick.wav"
+                                       "/sounds/kick.wav",
+                                       "/sounds/explode.wav"
                                     };
 
 
 #include <SDL_mixer.h>
 
 Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * herring_song = 0;
-Mix_Music * current_song = 0;
 
 /* --- OPEN THE AUDIO DEVICE --- */
 
@@ -102,7 +100,6 @@ Mix_Chunk * load_sound(const std::string& file)
 
   snd = Mix_LoadWAV(file.c_str());
 
-  /* printf message and abort if there is an initialized audio device */
   if ((snd == NULL) && audio_device)
     st_abort("Can't load", file);
 
@@ -115,17 +112,10 @@ Mix_Chunk * load_sound(const std::string& file)
 Mix_Music * load_song(const std::string& file)
 {
   if(!audio_device)
-    return 0;
+    return (Mix_Music*) ~0;
   
-  Mix_Music * sng;
-
-  sng = Mix_LoadMUS(file.c_str());
-
-  /* printf message and abort if there is an initialized audio device */
-  if (sng == NULL)
-    st_abort("Can't load", file);
-  return (sng);
+  Mix_Music* song = Mix_LoadMUS(file.c_str());
+  return song;
 }
 
 
@@ -160,48 +150,8 @@ void free_chunk(Mix_Chunk *chunk)
 {
   if (chunk != NULL)
     {
-      DEBUG_MSG( __PRETTY_FUNCTION__ );
       Mix_FreeChunk( chunk );
       chunk = NULL;
     }
 }
 
-void halt_music(void)
-{
-  if (!use_music || !audio_device)
-    return;
-
-  Mix_HaltMusic();
-  current_song = 0;
-}
-
-
-void play_music(Mix_Music *music)
-{
-  if (!audio_device)
-    return;
-
-  if (use_music && Mix_PlayMusic(music, -1) < 0)
-    st_abort("Couldn't play music: ", Mix_GetError());
-
-  current_song = music;
-}
-
-
-void free_music(Mix_Music *music)
-{
-  Mix_FreeMusic( music );
-}
-
-void enable_music(bool enable)
-{
-  if(!audio_device)
-    return;
-  
-  use_music = enable;
-  if(!use_music)
-    Mix_HaltMusic();
-  else
-    Mix_PlayMusic(current_song, -1);
-}
-