rnd-20000807-1-src
[rocksndiamonds.git] / src / sound.c
index 928a955c61dfdaadfb52de3cbac2fecd145e271a..d2cdbc724d0e9d781aa664bd7d03d8f60e199b4c 100644 (file)
@@ -715,16 +715,30 @@ boolean LoadSound(struct SoundInfo *snd_info)
 {
   char filename[256];
   char *sound_ext = "wav";
+#ifndef USE_SDL_LIBRARY
 #ifndef MSDOS
   byte sound_header_buffer[WAV_HEADER_SIZE];
   char chunk[CHUNK_ID_LEN + 1];
   int chunk_length, dummy;
   FILE *file;
   int i;
+#endif
 #endif
 
   sprintf(filename, "%s/%s/%s.%s",
-         options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext);
+         options.ro_base_directory, SOUNDS_DIRECTORY,
+         snd_info->name, sound_ext);
+
+#ifdef USE_SDL_LIBRARY
+
+  snd_info->mix_chunk = Mix_LoadWAV(filename);
+  if (snd_info->mix_chunk == NULL)
+  {
+    Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename);
+    return FALSE;
+  }
+
+#else /* !USE_SDL_LIBRARY */
 
 #ifndef MSDOS
 
@@ -788,12 +802,13 @@ boolean LoadSound(struct SoundInfo *snd_info)
   if (!snd_info->sample_ptr)
   {
     Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename);
-    return(FALSE);
+    return FALSE;
   }
 
 #endif /* MSDOS */
+#endif /* !USE_SDL_LIBRARY */
 
-  return(TRUE);
+  return TRUE;
 }
 
 void PlaySound(int nr)
@@ -836,6 +851,14 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
   snd_ctrl.data_ptr    = Sound[nr].data_ptr;
   snd_ctrl.data_len    = Sound[nr].data_len;
 
+#ifdef USE_SDL_LIBRARY
+
+  Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+  Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+
+  Mix_PlayChannel(-1, Sound[nr].mix_chunk, (loop ? -1 : 0));
+
+#else
 #ifndef MSDOS
   if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0)
   {
@@ -846,6 +869,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
 #else
   sound_handler(snd_ctrl);
 #endif
+#endif
 }
 
 void FadeSound(int nr)
@@ -886,6 +910,20 @@ void StopSoundExt(int nr, int method)
     snd_ctrl.stop_sound = TRUE;
   }
 
+#ifdef USE_SDL_LIBRARY
+
+  if (SSND_FADING(method))
+  {
+    Mix_FadeOutChannel(-1, 1000);
+    Mix_FadeOutMusic(1000);
+  }
+  else
+  {
+    Mix_HaltChannel(-1);
+    Mix_HaltMusic();
+  }
+
+#else
 #ifndef MSDOS
   if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0)
   {
@@ -896,6 +934,7 @@ void StopSoundExt(int nr, int method)
 #else
   sound_handler(snd_ctrl);
 #endif
+#endif
 }
 
 void FreeSounds(int num_sounds)