From 2a66260e017880b41a1ffb93f7de12e4d4d83f0f Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 4 Nov 2000 17:59:10 +0100 Subject: [PATCH] rnd-20001104-1-src --- CHANGES | 6 +++++- src/init.c | 2 +- src/sound.c | 20 ++++++++++++++++++-- src/sound.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index bb830209..c8ad050d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ +Version 1.5.0 +------------- + - SDL!!! + - trying to open already busy audio device does not block the game -Release Version 1.3.5 [?? SEP 1999] +Release Version 1.4.0 [27 OCT 1999] ----------------------------------- - new Boulderdash elements for better game emulation - new cool medium-sized crystal font diff --git a/src/init.c b/src/init.c index 4d3a034d..941881f3 100644 --- a/src/init.c +++ b/src/init.c @@ -193,7 +193,7 @@ void InitSound() return; } - if ((sound_device = open(sound_device_name,O_WRONLY))<0) + if ((sound_device = OpenAudio(sound_device_name)) < 0) { Error(ERR_WARN, "cannot open sound device - no sounds"); sound_status = SOUND_OFF; 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; diff --git a/src/sound.h b/src/sound.h index dada0e89..6eb0dad2 100644 --- a/src/sound.h +++ b/src/sound.h @@ -160,6 +160,7 @@ struct SoundControl }; /* start sound server */ +int OpenAudio(char *); void SoundServer(void); /* client functions */ -- 2.34.1