X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fsound.c;fp=src%2Fsound.c;h=1ab2b8c5f7c748cb732a56ced661cf349c30d02e;hp=6db2f63329a54bab3a1575982463ac276abd13ec;hb=2a66260e017880b41a1ffb93f7de12e4d4d83f0f;hpb=386a99d41a627e9d96aac8247a6ef7754817de9c diff --git a/src/sound.c b/src/sound.c index 6db2f633..1ab2b8c5 100644 --- a/src/sound.c +++ b/src/sound.c @@ -54,6 +54,21 @@ 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; +} + void SoundServer() { int i; @@ -144,7 +159,8 @@ void SoundServer() int sample_rate = 22050; #endif - if (playing_sounds || (sound_device=open(sound_device_name,O_WRONLY))>=0) + if (playing_sounds || + (sound_device = OpenAudio(sound_device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { @@ -306,7 +322,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;