rnd-20001125-3-src
[rocksndiamonds.git] / src / sound.c
index 6db2f63329a54bab3a1575982463ac276abd13ec..d302b0e7a9036b6c8c5d2ecbcd277e81d0c93929 100644 (file)
@@ -54,6 +54,47 @@ static void SoundServer_StopSound(int);
 static void SoundServer_StopAllSounds();
 #endif
 
+int OpenAudio(char *audio_device_name)
+{
+  int audio_fd;
+
+  /* try to open audio device in non-blocking mode */
+  if ((audio_fd = open(audio_device_name, O_WRONLY | O_NONBLOCK)) < 0)
+    return audio_fd;
+
+  /* re-open audio device in blocking mode */
+  close(audio_fd);
+  audio_fd = open(audio_device_name, O_WRONLY);
+
+  return audio_fd;
+}
+
+int CheckAudio(char *audio_device_name)
+{
+  int audio_fd;
+
+  if (access(audio_device_name, W_OK) != 0)
+  {
+    Error(ERR_WARN, "cannot access audio device - no sound");
+    return SOUND_OFF;
+  }
+
+  if ((audio_fd = OpenAudio(sound_device_name)) < 0)
+  {
+    Error(ERR_WARN, "cannot open audio device - no sound");
+    return SOUND_OFF;
+  }
+
+  close(audio_fd);
+
+  return SOUND_AVAILABLE;
+}
+
+boolean UnixInitAudio(void)
+{
+  return TRUE;
+}
+
 void SoundServer()
 {
   int i;
@@ -144,7 +185,8 @@ void SoundServer()
       int sample_rate = 22050;
 #endif
 
-      if (playing_sounds || (sound_device=open(sound_device_name,O_WRONLY))>=0)
+      if (playing_sounds ||
+         (sound_device = OpenAudio(sound_device_name)) >= 0)
       {
        if (!playing_sounds)    /* we just opened the audio device */
        {
@@ -306,7 +348,7 @@ void SoundServer()
       int wait_percent = 90;   /* wait 90% of the real playing time */
       int i;
 
-      if ((sound_device=open(sound_device_name,O_WRONLY))>=0)
+      if ((sound_device = OpenAudio(sound_device_name)) >= 0)
       {
        playing_sounds = 1;
 
@@ -725,7 +767,7 @@ boolean LoadSound(struct SoundInfo *snd_info)
 {
   char filename[256];
   char *sound_ext = "wav";
-#ifndef USE_SDL_LIBRARY
+#ifndef TARGET_SDL
 #ifndef MSDOS
   byte sound_header_buffer[WAV_HEADER_SIZE];
   char chunk[CHUNK_ID_LEN + 1];
@@ -739,7 +781,7 @@ boolean LoadSound(struct SoundInfo *snd_info)
          options.ro_base_directory, SOUNDS_DIRECTORY,
          snd_info->name, sound_ext);
 
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
 
   snd_info->mix_chunk = Mix_LoadWAV(filename);
   if (snd_info->mix_chunk == NULL)
@@ -748,7 +790,7 @@ boolean LoadSound(struct SoundInfo *snd_info)
     return FALSE;
   }
 
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
 
 #ifndef MSDOS
 
@@ -816,7 +858,7 @@ boolean LoadSound(struct SoundInfo *snd_info)
   }
 
 #endif /* MSDOS */
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 
   return TRUE;
 }
@@ -861,7 +903,7 @@ 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
+#ifdef TARGET_SDL
 
   Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
   Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
@@ -920,7 +962,7 @@ void StopSoundExt(int nr, int method)
     snd_ctrl.stop_sound = TRUE;
   }
 
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
 
   if (SSND_FADING(method))
   {