X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fsound.c;h=d302b0e7a9036b6c8c5d2ecbcd277e81d0c93929;hb=a8b2caa1d373c84c1b3fc2f615370c2a319051ca;hp=7839902a50d21f24c7d2080035c3047cc11d6d6d;hpb=0c27626bae90cb1eeea4939de0130a49b9aac507;p=rocksndiamonds.git diff --git a/src/sound.c b/src/sound.c index 7839902a..d302b0e7 100644 --- a/src/sound.c +++ b/src/sound.c @@ -23,7 +23,7 @@ static struct SoundControl emptySoundControl = -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL }; -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) static int stereo_volume[PSND_MAX_LEFT2RIGHT+1]; static char premix_first_buffer[SND_BLOCKSIZE]; #ifdef VOXWARE @@ -32,31 +32,73 @@ static char premix_right_buffer[SND_BLOCKSIZE]; static int premix_last_buffer[SND_BLOCKSIZE]; #endif /* VOXWARE */ static unsigned char playing_buffer[SND_BLOCKSIZE]; -#endif /* MSDOS */ +#endif /* !MSDOS && !WIN32 */ /* forward declaration of internal functions */ #ifdef VOXWARE static void SoundServer_InsertNewSound(struct SoundControl); #endif -#ifndef VOXWARE -#ifndef MSDOS + +#if !defined(VOXWARE) && !defined(MSDOS) && !defined(WIN32) 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 static void SoundServer_InsertNewSound(struct SoundControl); 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; -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) struct SoundControl snd_ctrl; fd_set sound_fdset; @@ -67,7 +109,7 @@ void SoundServer() playlist[i] = emptySoundControl; playing_sounds = 0; -#ifndef MSDOS +#if !defined(MSDOS) && !defined(WIN32) stereo_volume[PSND_MAX_LEFT2RIGHT] = 0; for(i=0;i=0) + if (playing_sounds || + (sound_device = OpenAudio(sound_device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { @@ -301,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; @@ -347,7 +394,9 @@ void SoundServer() #endif /* !VOXWARE */ } -#endif /* !MSDOS */ + +#endif /* !MSDOS && !WIN32 */ + } #ifdef MSDOS @@ -403,6 +452,7 @@ static void sound_handler(struct SoundControl snd_ctrl) } #endif /* MSDOS */ +#ifndef WIN32 static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl) { int i, k; @@ -511,6 +561,7 @@ static void SoundServer_InsertNewSound(struct SoundControl snd_ctrl) } } } +#endif /* !WIN32 */ /* void SoundServer_FadeSound(int nr) @@ -526,6 +577,7 @@ void SoundServer_FadeSound(int nr) } */ +#ifndef WIN32 #ifdef MSDOS static void SoundServer_StopSound(int nr) { @@ -570,6 +622,7 @@ static void SoundServer_StopAllSounds() #endif } #endif /* MSDOS */ +#endif /* !WIN32 */ #ifdef HPUX_AUDIO static void HPUX_Audio_Control() @@ -594,8 +647,8 @@ static void HPUX_Audio_Control() } #endif /* HPUX_AUDIO */ -#ifndef VOXWARE -#ifndef MSDOS +#if !defined(VOXWARE) && !defined(MSDOS) && !defined(WIN32) + /* these two are stolen from "sox"... :) */ /* @@ -699,8 +752,7 @@ static int ulaw_to_linear(unsigned char ulawbyte) return(sample); } -#endif /* !MSDOS */ -#endif /* !VOXWARE */ +#endif /* !VOXWARE && !MSDOS && !WIN32 */ /*** THE STUFF ABOVE IS ONLY USED BY THE SOUND SERVER CHILD PROCESS ***/ @@ -715,18 +767,31 @@ boolean LoadSound(struct SoundInfo *snd_info) { char filename[256]; char *sound_ext = "wav"; +#ifndef TARGET_SDL #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 TARGET_SDL + + 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 /* !TARGET_SDL */ + #ifndef MSDOS if ((file = fopen(filename, "r")) == NULL) @@ -789,12 +854,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 /* !TARGET_SDL */ - return(TRUE); + return TRUE; } void PlaySound(int nr) @@ -837,6 +903,14 @@ 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 TARGET_SDL + + Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4); + Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4); + + Mix_PlayChannel(-1, Sound[nr].mix_chunk, (loop ? -1 : 0)); + +#else #ifndef MSDOS if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0) { @@ -847,6 +921,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) #else sound_handler(snd_ctrl); #endif +#endif } void FadeSound(int nr) @@ -887,6 +962,20 @@ void StopSoundExt(int nr, int method) snd_ctrl.stop_sound = TRUE; } +#ifdef TARGET_SDL + + if (SSND_FADING(method)) + { + Mix_FadeOutChannel(-1, 1000); + Mix_FadeOutMusic(1000); + } + else + { + Mix_HaltChannel(-1); + Mix_HaltMusic(); + } + +#else #ifndef MSDOS if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0) { @@ -897,6 +986,7 @@ void StopSoundExt(int nr, int method) #else sound_handler(snd_ctrl); #endif +#endif } void FreeSounds(int num_sounds)