X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fsound.c;fp=src%2Fsound.c;h=9d49c7dcac1982084a9f508f5d833b5bea36c4c3;hp=628dc047c11c66d9c9eecada841222e335873f01;hb=10c48f0b3b2cf27451ddf355a3f72ee5c169eae4;hpb=ab9b68feafe2cf6012533e5ad0581e6b9d423959 diff --git a/src/sound.c b/src/sound.c index 628dc047..9d49c7dc 100644 --- a/src/sound.c +++ b/src/sound.c @@ -55,10 +55,14 @@ static void SoundServer_StopAllSounds(); #endif #if defined(PLATFORM_UNIX) -int OpenAudio(char *audio_device_name) +int OpenAudioDevice(char *audio_device_name) { int audio_fd; + /* check if desired audio device is accessible */ + if (access(sound_device_name, W_OK) != 0) + return -1; + /* try to open audio device in non-blocking mode */ if ((audio_fd = open(audio_device_name, O_WRONLY | O_NONBLOCK)) < 0) return audio_fd; @@ -70,36 +74,42 @@ int OpenAudio(char *audio_device_name) return audio_fd; } -int CheckAudio(char *audio_device_name) +void UnixOpenAudio(struct AudioSystemInfo *audio) { + static char *audio_device_name[] = + { + DEV_DSP, + DEV_AUDIO + }; int audio_fd; + int i; - if (access(audio_device_name, W_OK) != 0) - { - Error(ERR_WARN, "cannot access audio device - no sound"); - return SOUND_OFF; - } + /* look for available audio devices, starting with preferred ones */ + for (i=0; i= 0) + break; - if ((audio_fd = OpenAudio(sound_device_name)) < 0) + if (audio_fd < 0) { Error(ERR_WARN, "cannot open audio device - no sound"); - return SOUND_OFF; + return; } close(audio_fd); - return SOUND_AVAILABLE; -} - -void UnixInitAudio(struct AudioSystemInfo *audio) -{ - if (!(audio->sound_available = CheckAudio(sound_device_name))) - return; + audio->sound_available = TRUE; #ifdef VOXWARE audio->loops_available = TRUE; #endif } + +void UnixCloseAudio(struct AudioSystemInfo *audio) +{ + if (audio->device_fd) + close(audio->device_fd); +} + #endif /* PLATFORM_UNIX */ void SoundServer() @@ -194,7 +204,7 @@ void SoundServer() #endif if (playing_sounds || - (audio.device_fd = OpenAudio(sound_device_name)) >= 0) + (audio.device_fd = OpenAudioDevice(sound_device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { @@ -357,7 +367,7 @@ void SoundServer() int wait_percent = 90; /* wait 90% of the real playing time */ int i; - if ((audio.device_fd = OpenAudio(sound_device_name)) >= 0) + if ((audio.device_fd = OpenAudioDevice(sound_device_name)) >= 0) { playing_sounds = 1;