rnd-19990205-1
[rocksndiamonds.git] / src / sound.c
index d39a98612efdccc61df92dcf136e0e87f3392a0d..51a75c88dbe5e6a9d7d5f9d1d63e462cd7cc4ff7 100644 (file)
@@ -39,9 +39,11 @@ static unsigned char playing_buffer[SND_BLOCKSIZE];
 static void SoundServer_InsertNewSound(struct SoundControl);
 #endif
 #ifndef VOXWARE
+#ifndef MSDOS
 static unsigned char linear_to_ulaw(int);
 static int ulaw_to_linear(unsigned char);
 #endif
+#endif
 #ifdef HPUX_AUDIO
 static void HPUX_Audio_Control();
 #endif
@@ -132,7 +134,10 @@ void SoundServer()
       long sample_size;
       static long max_sample_size = 0;
       static long fragment_size = 0;
-      boolean stereo;
+      /* Even if the stereo flag is used as being boolean, it must be
+        defined as an integer, else 'ioctl()' will fail! */
+      int stereo = TRUE;
+      int sample_rate = 8000;
 
       if (playing_sounds || (sound_device=open(sound_device_name,O_WRONLY))>=0)
       {
@@ -141,12 +146,35 @@ void SoundServer()
          /* 2 buffers / 512 bytes, giving 1/16 second resolution */
          /* (with stereo the effective buffer size will shrink to 256) */
          fragment_size = 0x00020009;
-         ioctl(sound_device, SNDCTL_DSP_SETFRAGMENT, &fragment_size);
+
+         if (ioctl(sound_device, SNDCTL_DSP_SETFRAGMENT, &fragment_size) < 0)
+           Error(ERR_EXIT_SOUND_SERVER,
+                 "cannot set fragment size of /dev/dsp - no sounds");
+
          /* try if we can use stereo sound */
-         stereo = TRUE;
-         ioctl(sound_device, SNDCTL_DSP_STEREO, &stereo);
+         if (ioctl(sound_device, SNDCTL_DSP_STEREO, &stereo) < 0)
+         {
+#ifdef DEBUG
+           static boolean reported = FALSE;
+
+           if (!reported)
+           {
+             Error(ERR_RETURN, "cannot get stereo sound on /dev/dsp");
+             reported = TRUE;
+           }
+#endif
+           stereo = FALSE;
+         }
+
+         if (ioctl(sound_device, SNDCTL_DSP_SPEED, &sample_rate) < 0)
+           Error(ERR_EXIT_SOUND_SERVER,
+                 "cannot set sample rate of /dev/dsp - no sounds");
+
          /* get the real fragmentation size; this should return 512 */
-         ioctl(sound_device, SNDCTL_DSP_GETBLKSIZE, &fragment_size);
+         if (ioctl(sound_device, SNDCTL_DSP_GETBLKSIZE, &fragment_size) < 0)
+           Error(ERR_EXIT_SOUND_SERVER,
+                 "cannot get fragment size of /dev/dsp - no sounds");
+
          max_sample_size = fragment_size / (stereo ? 2 : 1);
        }
 
@@ -567,6 +595,7 @@ static void HPUX_Audio_Control()
 #endif /* HPUX_AUDIO */
 
 #ifndef VOXWARE
+#ifndef MSDOS
 /* these two are stolen from "sox"... :) */
 
 /*
@@ -670,6 +699,7 @@ static int ulaw_to_linear(unsigned char ulawbyte)
 
   return(sample);
 }
+#endif /* !MSDOS */
 #endif /* !VOXWARE */
 
 /*** THE STUFF ABOVE IS ONLY USED BY THE SOUND SERVER CHILD PROCESS ***/