rnd-20000806-1-src
[rocksndiamonds.git] / src / sound.c
index 7839902a50d21f24c7d2080035c3047cc11d6d6d..e89a153fd665db256c4306e1c231632227e83446 100644 (file)
@@ -715,18 +715,31 @@ 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.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
 
   if ((file = fopen(filename, "r")) == NULL)
@@ -789,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)
@@ -816,6 +830,17 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop)
 {
   struct SoundControl snd_ctrl = emptySoundControl;
 
+#ifdef USE_SDL_LIBRARY
+  Mix_PlayChannel(-1, Sound[nr].mix_chunk, 0);
+
+  /*
+  Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+  Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+  */
+
+  return;
+#endif
+
   if (sound_status==SOUND_OFF || !setup.sound)
     return;
 
@@ -873,6 +898,11 @@ void StopSoundExt(int nr, int method)
 {
   struct SoundControl snd_ctrl = emptySoundControl;
 
+#ifdef USE_SDL_LIBRARY
+  Mix_HaltMusic();
+  return;
+#endif
+
   if (sound_status==SOUND_OFF)
     return;