From 7c024e9101a63be34a2c97ef0dc18deaa1afb175 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 9 Nov 2010 13:28:23 +0000 Subject: prevent error message spam if the audio subsystem can not initialize itself --- src/audio/audio.cc | 42 +++++++++++++++++++++++++++++++----------- src/audio/audio.h | 3 +++ src/audio/buffers.cc | 9 ++++++++- 3 files changed, 42 insertions(+), 12 deletions(-) (limited to 'src/audio') diff --git a/src/audio/audio.cc b/src/audio/audio.cc index 46d3a67..d7f85d9 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -15,11 +15,19 @@ namespace audio ALCdevice *audio_device = 0; ALCcontext *audio_context = 0; +bool audio_initialized = false; + +bool initialized() +{ + return audio_initialized; +} void init() { con_print << "^BInitializing audio..." << std::endl; + audio_initialized = false; + // open the default audio device audio_device = alcOpenDevice(0); @@ -54,19 +62,28 @@ void init() // console sound load("ui/console"); + + audio_initialized = true; } void reset() { - con_print << "^BInitializing audio..." << std::endl; - - Sources::shutdown(); - Buffers::shutdown(); - Buffers::init(); - Sources::init(); + if (audio_initialized) { + con_print << "^BResetting audio..." << std::endl; - load("ui/nosnd"); - load("ui/console"); + Sources::shutdown(); + Buffers::shutdown(); + } + + if (!audio_initialized) { + init(); + } else { + Buffers::init(); + Sources::init(); + + load("ui/nosnd"); + load("ui/console"); + } } void load(const char *name) @@ -78,9 +95,10 @@ void shutdown() { con_print << "^BShutting down audio..." << std::endl; - Sources::shutdown(); - - Buffers::shutdown(); + if (audio_initialized) { + Sources::shutdown(); + Buffers::shutdown(); + } if (audio_context) { alcMakeContextCurrent(0); @@ -92,6 +110,8 @@ void shutdown() alcCloseDevice(audio_device); audio_device = 0; } + + audio_initialized = false; } size_t play(const char *name) diff --git a/src/audio/audio.h b/src/audio/audio.h index ad9a024..073fb67 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -62,6 +62,9 @@ void update_listener(math::Vector3f const &location, math::Axis const &axis, mat /// return true is a source is playing bool is_playing(const size_t source_index); +/// return true if audio is initialized +bool initialized(); + } #endif // __INCLUDED_AUDIO_AUDIO_H__ diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc index 7bf7eb1..4349e8f 100644 --- a/src/audio/buffers.cc +++ b/src/audio/buffers.cc @@ -1,11 +1,12 @@ /* - audio/buffers.h + audio/buffers.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include +#include "audio/audio.h" #include "audio/buffers.h" #include "audio/pcm.h" #include "audio/wav.h" @@ -59,6 +60,12 @@ size_t Buffers::load(std::string name) if (it != registry.end()) return (*it).second; + // check if the audio subsystem has been initialized + if (!initialized()) { + registry[name] = 0; + return 0; + } + // load wav file PCM *pcm = Wav::load(name); if (!pcm) { -- cgit v1.2.3