rnd-20020407-4-src
[rocksndiamonds.git] / src / libgame / sound.c
index 220dfde6ded3f5265e5492d1de81ed2e6a50f8dd..92c2253c81acad8581b67d82c9dec25e0f16bca5 100644 (file)
@@ -135,7 +135,7 @@ static boolean ForkAudioProcess(void)
     return FALSE;
   }
 
-  if (audio.soundserver_pid == 0)      /* we are child */
+  if (audio.soundserver_pid == 0)      /* we are child process */
   {
     SoundServer();
 
@@ -168,7 +168,7 @@ void UnixCloseAudio(void)
   if (audio.device_fd)
     close(audio.device_fd);
 
-  if (audio.soundserver_pid)
+  if (audio.soundserver_pid > 0)       /* we are parent process */
     kill(audio.soundserver_pid, SIGTERM);
 }
 #endif /* PLATFORM_UNIX */
@@ -1080,21 +1080,10 @@ int LoadMusic(void)
   {
     char *filename = dir_entry->d_name;
 
-    if (strlen(filename) > 4 &&
-       strcmp(&filename[strlen(filename) - 4], ".wav") == 0)
-    {
-      if (LoadSoundExt(filename, TRUE))
-       num_wav_music++;
-    }
-    else if (strlen(filename) > 4 &&
-            (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 ||
-             strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 ||
-             strncmp(filename, "mod.", 4) == 0 ||
-             strncmp(filename, "MOD.", 4) == 0))
-    {
-      if (LoadMod(filename))
-       num_mod_music++;
-    }
+    if (FileIsSound(filename) && LoadSoundExt(filename, TRUE))
+      num_wav_music++;
+    else if (FileIsMusic(filename) && LoadMod(filename))
+      num_mod_music++;
   }
 
   closedir(dir);
@@ -1180,6 +1169,9 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
   Mix_Volume(-1, SOUND_MAX_VOLUME);
   Mix_PlayChannel(-1, Sound[nr].mix_chunk, (loop ? -1 : 0));
 #elif defined(PLATFORM_UNIX)
+  if (audio.soundserver_pid == 0)      /* we are child process */
+    return;
+
   if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
   {
     Error(ERR_WARN, "cannot pipe to child process -- no sounds");
@@ -1285,6 +1277,9 @@ void StopSoundExt(int nr, int method)
 
 #else
 #if !defined(PLATFORM_MSDOS)
+  if (audio.soundserver_pid == 0)      /* we are child process */
+    return;
+
   if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0)
   {
     Error(ERR_WARN, "cannot pipe to child process -- no sounds");