Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-09 13:28:23 +0000
committerStijn Buys <ingar@osirion.org>2010-11-09 13:28:23 +0000
commit7c024e9101a63be34a2c97ef0dc18deaa1afb175 (patch)
treedc604d5578efa98ba8164c5492ce20f2848f646a /src/audio
parentfdcff7183b035a27ff960f347b9975ab8e67a3cd (diff)
prevent error message spam if the audio subsystem can not initialize itself
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio.cc42
-rw-r--r--src/audio/audio.h3
-rw-r--r--src/audio/buffers.cc9
3 files changed, 42 insertions, 12 deletions
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 <string.h>
+#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) {