rnd-20020312-1-src
[rocksndiamonds.git] / src / libgame / sound.c
index 757a7bd5d8aff67305563fa72a5970534f891c2b..f0aa106ac273ec0d73096f1b402778aeaa54d518 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-* (c) 1994-2000 Artsoft Entertainment                      *
+* (c) 1994-2001 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
@@ -117,6 +117,7 @@ static boolean TestAudioDevices(void)
   return TRUE;
 }
 
+#if !defined(TARGET_SDL)
 static boolean ForkAudioProcess(void)
 {
   if (pipe(audio.soundserver_pipe) < 0)
@@ -143,6 +144,7 @@ static boolean ForkAudioProcess(void)
 
   return TRUE;
 }
+#endif
 
 void UnixOpenAudio(void)
 {
@@ -179,6 +181,9 @@ void InitPlaylist(void)
 
 void StartSoundserver(void)
 {
+  if (!audio.sound_available)
+    return;
+
 #if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)
   if (!ForkAudioProcess())
     audio.sound_available = FALSE;
@@ -871,6 +876,9 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music)
   int i;
 #endif
 
+  if (!audio.sound_available)
+    return FALSE;
+
   num_sounds++;
   Sound = checked_realloc(Sound, num_sounds * sizeof(struct SampleInfo));
 
@@ -998,6 +1006,9 @@ int LoadMusic(void)
   int num_wav_music = 0;
   int num_mod_music = 0;
 
+  if (!audio.sound_available)
+    return 0;
+
   if ((dir = opendir(music_directory)) == NULL)
   {
     Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
@@ -1054,8 +1065,8 @@ void PlayMusic(int nr)
 #if defined(TARGET_SDL)
   if (audio.mods_available)    /* play MOD music */
   {
-    Mix_VolumeMusic(SOUND_MAX_VOLUME);
     Mix_PlayMusic(Mod[nr].mix_music, -1);
+    Mix_VolumeMusic(SOUND_MAX_VOLUME); /* must be _after_ Mix_PlayMusic()! */
   }
   else                         /* play WAV music loop */
   {
@@ -1126,6 +1137,9 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
 void FadeMusic(void)
 {
 #if defined(TARGET_SDL)
+  if (!audio.sound_available)
+    return;
+
   if (audio.mods_available)
     Mix_FadeOutMusic(SOUND_FADING_INTERVAL);
   else
@@ -1142,6 +1156,7 @@ void FadeSound(int nr)
 
 void FadeSounds()
 {
+  FadeMusic();
   StopSoundExt(-1, SSND_FADE_ALL_SOUNDS);
 }