X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fsound.c;h=51a75c88dbe5e6a9d7d5f9d1d63e462cd7cc4ff7;hp=340ec942b8ebc30d25e62107bdf02a28e30498c5;hb=3ae3dff29ac1a6022b1e5af414ba2c99391148c8;hpb=50c422d96b6da2c0412b6bd3763e9d1a029a6014 diff --git a/src/sound.c b/src/sound.c index 340ec942..51a75c88 100644 --- a/src/sound.c +++ b/src/sound.c @@ -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); } @@ -498,6 +526,7 @@ void SoundServer_FadeSound(int nr) } */ +#ifdef MSDOS static void SoundServer_StopSound(int nr) { int i; @@ -540,6 +569,7 @@ static void SoundServer_StopAllSounds() close(sound_device); #endif } +#endif /* MSDOS */ #ifdef HPUX_AUDIO static void HPUX_Audio_Control() @@ -564,6 +594,8 @@ static void HPUX_Audio_Control() } #endif /* HPUX_AUDIO */ +#ifndef VOXWARE +#ifndef MSDOS /* these two are stolen from "sox"... :) */ /* @@ -667,6 +699,8 @@ 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 ***/