From: Holger Schemel Date: Tue, 28 Nov 2000 23:39:18 +0000 (+0100) Subject: rnd-20001129-2-src X-Git-Tag: 2.0.0^2~26 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=10c48f0b3b2cf27451ddf355a3f72ee5c169eae4;p=rocksndiamonds.git rnd-20001129-2-src --- diff --git a/src/init.c b/src/init.c index 040270a1..851eaa5e 100644 --- a/src/init.c +++ b/src/init.c @@ -142,7 +142,7 @@ void InitSound() { int i; - audio = InitAudio(); + OpenAudio(&audio); for(i=0; iformat, color_r, color_g, color_b)); } -inline boolean SDLInitAudio(void) +inline boolean SDLOpenAudio(void) { if (SDL_Init(SDL_INIT_AUDIO) < 0) { @@ -203,4 +203,12 @@ inline boolean SDLInitAudio(void) return TRUE; } +inline void SDLCloseAudio(void) +{ + Mix_HaltMusic(); + Mix_HaltChannel(-1); + + Mix_CloseAudio(); +} + #endif /* TARGET_SDL */ diff --git a/src/sdl.h b/src/sdl.h index bfe4b4ad..cd503c1d 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -303,6 +303,7 @@ inline void SDLCopyArea(SDL_Surface *, SDL_Surface *, inline void SDLFillRectangle(SDL_Surface *, int, int, int, int, unsigned int); inline void SDLDrawSimpleLine(SDL_Surface *, int, int, int, int, unsigned int); -inline boolean SDLInitAudio(void); +inline boolean SDLOpenAudio(void); +inline void SDLCloseAudio(void); #endif /* SDL_H */ 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; diff --git a/src/sound.h b/src/sound.h index a4f9d878..c03fdaf1 100644 --- a/src/sound.h +++ b/src/sound.h @@ -90,8 +90,9 @@ extern void ioctl(long, long, void *); #define SND_PATH "./sounds" #endif -#define DEV_AUDIO "/dev/audio" #define DEV_DSP "/dev/dsp" +#define DEV_AUDIO "/dev/audio" +#define DEV_AUDIOCTL "/dev/audioCtl" #ifdef VOXWARE #define SOUND_DEVICE DEV_DSP @@ -99,15 +100,6 @@ extern void ioctl(long, long, void *); #define SOUND_DEVICE DEV_AUDIO #endif -#define SOUND_OFF 0 -#define SOUND_AVAILABLE 1 - -#ifdef NO_SOUNDS -#define SOUND_STATUS SOUND_OFF -#else -#define SOUND_STATUS SOUND_AVAILABLE -#endif - struct SoundHeader_SUN { unsigned long magic; @@ -161,9 +153,8 @@ struct SoundControl }; /* general sound functions */ -int OpenAudio(char *); -int CheckAudio(char *); -void UnixInitAudio(struct AudioSystemInfo *); +void UnixOpenAudio(struct AudioSystemInfo *); +void UnixCloseAudio(struct AudioSystemInfo *); /* sound server functions */ void SoundServer(void); diff --git a/src/system.c b/src/system.c index cdf66b33..37ca4841 100644 --- a/src/system.c +++ b/src/system.c @@ -234,33 +234,45 @@ inline void ChangeVideoModeIfNeeded(void) /* audio functions */ /* ========================================================================= */ -inline struct AudioSystemInfo InitAudio(void) +inline boolean OpenAudio(struct AudioSystemInfo *audio) { - struct AudioSystemInfo audio; - - audio.sound_available = FALSE; - audio.loops_available = FALSE; - audio.soundserver_pipe[0] = audio.soundserver_pipe[1] = 0; - audio.soundserver_pid = 0; - audio.device_fd = 0; + audio->sound_available = FALSE; + audio->loops_available = FALSE; + audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0; + audio->soundserver_pid = 0; + audio->device_fd = 0; #if defined(TARGET_SDL) - if (SDLInitAudio()) + if (SDLOpenAudio()) { - audio.sound_available = TRUE; - audio.loops_available = TRUE; + audio->sound_available = TRUE; + audio->loops_available = TRUE; } #elif defined(PLATFORM_MSDOS) - if (MSDOSInitAudio()) + if (MSDOSOpenAudio()) { - audio.sound_available = TRUE; - audio.loops_available = TRUE; + audio->sound_available = TRUE; + audio->loops_available = TRUE; } #elif defined(PLATFORM_UNIX) - UnixInitAudio(&audio); + UnixOpenAudio(audio); +#endif + + return audio->sound_available; +} + +inline void CloseAudio(struct AudioSystemInfo *audio) +{ +#if defined(TARGET_SDL) + SDLCloseAudio(); +#elif defined(PLATFORM_MSDOS) + MSDOSCloseAudio(); +#elif defined(PLATFORM_UNIX) + UnixCloseAudio(audio); #endif - return audio; + audio->sound_available = FALSE; + audio->loops_available = FALSE; } diff --git a/src/system.h b/src/system.h index feaf5ae6..fdfb4a6a 100644 --- a/src/system.h +++ b/src/system.h @@ -73,7 +73,8 @@ inline boolean PointerInWindow(DrawWindow); inline boolean SetVideoMode(void); inline void ChangeVideoModeIfNeeded(void); -inline struct AudioSystemInfo InitAudio(void); +inline boolean OpenAudio(struct AudioSystemInfo *); +inline void CloseAudio(struct AudioSystemInfo *); inline void InitEventFilter(EventFilter); inline boolean PendingEvent(void);