Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio.cc19
-rw-r--r--src/audio/audio.h3
-rw-r--r--src/audio/buffers.cc8
-rw-r--r--src/audio/buffers.h1
-rw-r--r--src/audio/sources.cc15
-rw-r--r--src/audio/sources.h1
6 files changed, 41 insertions, 6 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 81a260c..ca30590 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -18,13 +18,13 @@ ALCcontext *audio_context = 0;
void init()
{
- con_print << "^BInitializing audio...";
+ con_print << "^BInitializing audio..." << std::endl;
// open the default audio device
audio_device = alcOpenDevice(0);
if (!audio_device) {
- con_warn << "Could not initialize audio!";
+ con_warn << "Could not initialize audio!" << std::endl;
return;
}
@@ -34,7 +34,7 @@ void init()
if (!audio_context) {
alcCloseDevice(audio_device);
audio_device = 0;
- con_warn << "Could not create audio context!";
+ con_warn << "Could not create audio context!" << std::endl;
return;
}
@@ -56,6 +56,17 @@ void init()
load("ui/console");
}
+void reset()
+{
+ con_print << "^BReloading audio..." << std::endl;
+
+ Sources::reset();
+ Buffers::reset();
+
+ load("ui/nosnd");
+ load("ui/console");
+}
+
void load (const char *name)
{
Buffers::load(std::string(name));
@@ -63,7 +74,7 @@ void load (const char *name)
void shutdown()
{
- con_print << "^BShutting down audio...";
+ con_print << "^BShutting down audio..." << std::endl;
Sources::shutdown();
diff --git a/src/audio/audio.h b/src/audio/audio.h
index c0479d3..930edaf 100644
--- a/src/audio/audio.h
+++ b/src/audio/audio.h
@@ -29,6 +29,9 @@ void init();
/// shut down the audio subsystem
void shutdown();
+/// reload audio
+void reset();
+
/// load an audio sample
void load(const char *name);
diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc
index af14cb1..33c4dbf 100644
--- a/src/audio/buffers.cc
+++ b/src/audio/buffers.cc
@@ -25,7 +25,7 @@ void Buffers::init()
alGenBuffers(MAXBUFFERS, buffers);
if ((error = alGetError()) != AL_NO_ERROR) {
- con_warn << "Error " << std::hex << error << " initializing OpenAL buffers!" << std::endl;
+ con_warn << "Error " << error << " initializing OpenAL buffers!" << std::endl;
return;
}
}
@@ -44,6 +44,12 @@ void Buffers::clear()
index = 0;
}
+void Buffers::reset()
+{
+ shutdown();
+ init();
+}
+
size_t Buffers::load(std::string name)
{
// check if it is already loaded
diff --git a/src/audio/buffers.h b/src/audio/buffers.h
index cc7a6c8..462afff 100644
--- a/src/audio/buffers.h
+++ b/src/audio/buffers.h
@@ -23,6 +23,7 @@ class Buffers {
public:
static void init();
static void shutdown();
+ static void reset();
/// find previously loaded PCM data
static size_t find(std::string name);
diff --git a/src/audio/sources.cc b/src/audio/sources.cc
index 584f366..01fbafb 100644
--- a/src/audio/sources.cc
+++ b/src/audio/sources.cc
@@ -23,7 +23,7 @@ void Sources::init()
alGenSources(MAXSOURCES, sources);
if ((error = alGetError()) != AL_NO_ERROR) {
- con_warn << "Error " << std::hex << error << " initializing OpenAL sources!" << std::endl;
+ con_warn << "Error " << error << " initializing OpenAL sources!" << std::endl;
return;
}
@@ -55,6 +55,19 @@ void Sources::clear()
}
+void Sources::reset()
+{
+ for (size_t index= 0; index < MAXSOURCES; index++) {
+ source_available[index] = true;
+ alSourceRewind(sources[index]);
+ }
+
+ // reserve ui sound sources
+ for (size_t i=0; i < MAXUISOURCES; i++) {
+ source_available[i] = false;
+ }
+}
+
size_t Sources::get()
{
for (size_t i= MAXUISOURCES; i < MAXSOURCES; i++) {
diff --git a/src/audio/sources.h b/src/audio/sources.h
index 078c424..f01e7a4 100644
--- a/src/audio/sources.h
+++ b/src/audio/sources.h
@@ -23,6 +23,7 @@ class Sources {
public:
static void init();
static void shutdown();
+ static void reset();
static inline bool available(size_t index) { return source_available[index]; }