X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fsound.c;h=185b1822d9bbe3213a927ba37c803a671897107a;hb=1150bdce04915bf329bd816307fb2507eba80e15;hp=1ab2b8c5f7c748cb732a56ced661cf349c30d02e;hpb=2a66260e017880b41a1ffb93f7de12e4d4d83f0f;p=rocksndiamonds.git diff --git a/src/sound.c b/src/sound.c index 1ab2b8c5..185b1822 100644 --- a/src/sound.c +++ b/src/sound.c @@ -23,37 +23,38 @@ static struct SoundControl emptySoundControl = -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL }; -#if !defined(MSDOS) && !defined(WIN32) +#if defined(PLATFORM_UNIX) static int stereo_volume[PSND_MAX_LEFT2RIGHT+1]; static char premix_first_buffer[SND_BLOCKSIZE]; #ifdef VOXWARE static char premix_left_buffer[SND_BLOCKSIZE]; static char premix_right_buffer[SND_BLOCKSIZE]; static int premix_last_buffer[SND_BLOCKSIZE]; -#endif /* VOXWARE */ +#endif static unsigned char playing_buffer[SND_BLOCKSIZE]; -#endif /* !MSDOS && !WIN32 */ +#endif /* forward declaration of internal functions */ #ifdef VOXWARE static void SoundServer_InsertNewSound(struct SoundControl); -#endif - -#if !defined(VOXWARE) && !defined(MSDOS) && !defined(WIN32) +#else +#if defined(PLATFORM_UNIX) 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 -#ifdef MSDOS +#if defined(PLATFORM_MSDOS) static void SoundServer_InsertNewSound(struct SoundControl); static void SoundServer_StopSound(int); static void SoundServer_StopAllSounds(); #endif +#if defined(PLATFORM_UNIX) int OpenAudio(char *audio_device_name) { int audio_fd; @@ -69,21 +70,48 @@ int OpenAudio(char *audio_device_name) 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; +} +#endif /* PLATFORM_UNIX */ + void SoundServer() { int i; -#if !defined(MSDOS) && !defined(WIN32) +#if defined(PLATFORM_UNIX) struct SoundControl snd_ctrl; fd_set sound_fdset; - close(sound_pipe[1]); /* no writing into pipe needed */ + close(sysinfo.audio_process_pipe[1]); /* no writing into pipe needed */ #endif for(i=0;i= 0) + (sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { @@ -168,12 +197,13 @@ void SoundServer() /* (with stereo the effective buffer size will shrink to 256) */ fragment_size = 0x00020009; - if (ioctl(sound_device, SNDCTL_DSP_SETFRAGMENT, &fragment_size) < 0) + if (ioctl(sysinfo.audio_fd, 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 */ - if (ioctl(sound_device, SNDCTL_DSP_STEREO, &stereo) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) { #ifdef DEBUG static boolean reported = FALSE; @@ -187,12 +217,13 @@ void SoundServer() stereo = FALSE; } - if (ioctl(sound_device, SNDCTL_DSP_SPEED, &sample_rate) < 0) + if (ioctl(sysinfo.audio_fd, 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 */ - if (ioctl(sound_device, SNDCTL_DSP_GETBLKSIZE, &fragment_size) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size) + < 0) Error(ERR_EXIT_SOUND_SERVER, "cannot get fragment size of /dev/dsp - no sounds"); @@ -203,9 +234,10 @@ void SoundServer() SoundServer_InsertNewSound(snd_ctrl); while(playing_sounds && - select(sound_pipe[0]+1,&sound_fdset,NULL,NULL,&delay)<1) + select(sysinfo.audio_process_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { - FD_SET(sound_pipe[0], &sound_fdset); + FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset); /* first clear the last premixing buffer */ memset(premix_last_buffer,0,fragment_size*sizeof(int)); @@ -302,12 +334,12 @@ void SoundServer() } /* finally play the sound fragment */ - write(sound_device,playing_buffer,fragment_size); + write(sysinfo.audio_fd, playing_buffer,fragment_size); } /* if no sounds playing, free device for other sound programs */ if (!playing_sounds) - close(sound_device); + close(sysinfo.audio_fd); } } @@ -322,14 +354,15 @@ void SoundServer() int wait_percent = 90; /* wait 90% of the real playing time */ int i; - if ((sound_device = OpenAudio(sound_device_name)) >= 0) + if ((sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0) { playing_sounds = 1; while(playing_sounds && - select(sound_pipe[0]+1,&sound_fdset,NULL,NULL,&delay)<1) + select(sysinfo.audio_process_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { - FD_SET(sound_pipe[0], &sound_fdset); + FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset); /* get pointer and size of the actual sound sample */ sample_ptr = snd_ctrl.data_ptr + snd_ctrl.playingpos; @@ -356,12 +389,12 @@ void SoundServer() playing_sounds = 0; /* finally play the sound fragment */ - write(sound_device,playing_buffer,sample_size); + write(sysinfo.audio_fd,playing_buffer,sample_size); delay.tv_sec = 0; delay.tv_usec = ((sample_size*10*wait_percent)/(sample_rate))*1000; } - close(sound_device); + close(sysinfo.audio_fd); } } @@ -369,11 +402,11 @@ void SoundServer() } -#endif /* !MSDOS && !WIN32 */ +#endif /* PLATFORM_UNIX */ } -#ifdef MSDOS +#if defined(PLATFORM_MSDOS) static void sound_handler(struct SoundControl snd_ctrl) { int i; @@ -424,9 +457,9 @@ static void sound_handler(struct SoundControl snd_ctrl) if (snd_ctrl.active) SoundServer_InsertNewSound(snd_ctrl); } -#endif /* MSDOS */ +#endif /* PLATFORM_MSDOS */ -#ifndef WIN32 +#if !defined(PLATFORM_WIN32) static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl) { int i, k; @@ -438,7 +471,7 @@ static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl) for(i=0;iname, sound_ext); -#ifdef USE_SDL_LIBRARY +#if defined(TARGET_SDL) snd_info->mix_chunk = Mix_LoadWAV(filename); if (snd_info->mix_chunk == NULL) @@ -764,9 +799,9 @@ boolean LoadSound(struct SoundInfo *snd_info) return FALSE; } -#else /* !USE_SDL_LIBRARY */ +#else /* !TARGET_SDL */ -#ifndef MSDOS +#if !defined(PLATFORM_MSDOS) if ((file = fopen(filename, "r")) == NULL) { @@ -822,7 +857,7 @@ boolean LoadSound(struct SoundInfo *snd_info) for (i=0; idata_len; i++) snd_info->data_ptr[i] = snd_info->data_ptr[i] ^ 0x80; -#else /* MSDOS */ +#else /* PLATFORM_MSDOS */ snd_info->sample_ptr = load_sample(filename); if (!snd_info->sample_ptr) @@ -831,8 +866,8 @@ boolean LoadSound(struct SoundInfo *snd_info) return FALSE; } -#endif /* MSDOS */ -#endif /* !USE_SDL_LIBRARY */ +#endif /* PLATFORM_MSDOS */ +#endif /* !TARGET_SDL */ return TRUE; } @@ -856,7 +891,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) { struct SoundControl snd_ctrl = emptySoundControl; - if (sound_status==SOUND_OFF || !setup.sound) + if (!sysinfo.audio_available || !setup.sound) return; if (volume