Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-14 20:40:20 +0000
committerStijn Buys <ingar@osirion.org>2008-07-14 20:40:20 +0000
commit28d7a4cd5b4bc3df5d034ed9472231d91710a6b6 (patch)
tree18c0d5df6c0a4b3f406869c86f5fe2f3b63ca299
parentf9dad976adca728a5996450334dcabf57fef2443 (diff)
failed attempt at multiple simultanious sounds
-rw-r--r--src/audio/audio.cc23
-rw-r--r--src/audio/buffers.cc11
-rw-r--r--src/audio/buffers.h3
-rw-r--r--src/audio/sources.cc17
-rw-r--r--src/audio/sources.h9
5 files changed, 46 insertions, 17 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 729f3d2..8880780 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -71,12 +71,25 @@ void shutdown()
void play(const char *name)
{
- Buffers::load(std::string(name));
+ if (!audio_context)
+ return;
- if (Sources::available(0)) {
- alSourceRewind(Sources::ui());
- Buffers::bind(Sources::ui(), std::string(name));
- alSourcePlay(Sources::ui());
+ size_t buffer = Buffers::load(std::string(name));
+
+ ALint state;
+ for (size_t i = 0; i < MAXUISOURCES; i++) {
+ ALuint source = Sources::source(i);
+ alGetSourcei(source , AL_SOURCE_STATE , &state);
+ if (state != AL_PLAYING) {
+ //alSourceRewind(Sources::source(i));
+ Buffers::bind(source, buffer);
+ alSourcef(source, AL_PITCH, 1.0);
+ alSourcef(source, AL_GAIN, 1.0);
+ alSourcePlay(source);
+
+ } else {
+ con_debug << "source " << Sources::source(i) << " playing!" << std::endl;
+ }
}
}
diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc
index 5ea1b05..dd83000 100644
--- a/src/audio/buffers.cc
+++ b/src/audio/buffers.cc
@@ -99,15 +99,18 @@ size_t Buffers::find(std::string name)
return id;
}
-void Buffers::bind(ALuint source, std::string name)
+void Buffers::bind(ALuint source, size_t id)
{
int error;
- size_t id = find(name);
alSourcei(source, AL_BUFFER, buffers[id]);
if ((error = alGetError()) != AL_NO_ERROR) {
- con_warn << "Error " << std::hex << error << " binding " << name
- << " source " << source << " buffer " << buffers[id] << std::endl;
+ con_warn << "Error " << std::hex << error << " binding buffer " << buffers[id] << " to source " << source << std::endl;
}
}
+void Buffers::bind(ALuint source, std::string name)
+{
+ bind(source, find(name));
+}
+
}
diff --git a/src/audio/buffers.h b/src/audio/buffers.h
index 53137e9..cc7a6c8 100644
--- a/src/audio/buffers.h
+++ b/src/audio/buffers.h
@@ -33,6 +33,9 @@ public:
/// bind a buffer to a source
static void bind(ALuint source, std::string name);
+ /// bind a specific buffer to a source
+ static void bind(ALuint source, size_t id);
+
private:
static void clear();
diff --git a/src/audio/sources.cc b/src/audio/sources.cc
index 209bc94..dd736e7 100644
--- a/src/audio/sources.cc
+++ b/src/audio/sources.cc
@@ -24,7 +24,16 @@ void Sources::init()
con_warn << "Error " << std::hex << error << " initializing OpenAL sources!" << std::endl;
return;
}
- source_available[0] = true;
+
+ // all sources are available for use
+ for (size_t i=MAXUISOURCES; i < MAXSOURCES; i++) {
+ source_available[i] = true;
+ }
+
+ // reserve ui sound sources
+ for (size_t i=0; i < MAXUISOURCES; i++) {
+ source_available[i] = false;
+ }
}
void Sources::shutdown()
@@ -36,7 +45,11 @@ void Sources::shutdown()
void Sources::clear()
{
memset(sources,0, sizeof(sources));
- memset(source_available, 0 , sizeof(source_available));
+
+ // all sources are available for use
+ for (size_t i=0; i < MAXSOURCES; i++) {
+ source_available[i] = false;
+ }
}
diff --git a/src/audio/sources.h b/src/audio/sources.h
index 08a2a41..302d5d5 100644
--- a/src/audio/sources.h
+++ b/src/audio/sources.h
@@ -16,6 +16,7 @@
namespace audio {
const size_t MAXSOURCES = 32;
+const size_t MAXUISOURCES = 4;
/// OpenAL sources wrapper class
class Sources {
@@ -23,13 +24,9 @@ public:
static void init();
static void shutdown();
- static bool available(size_t index) { return source_available[index]; }
-
- static ALuint source(size_t index) { return sources[index]; }
-
- /// the sources for user interface sounds
- static inline ALuint ui() { return sources[0]; }
+ static inline bool available(size_t index) { return source_available[index]; }
+ static inline ALuint source(size_t index) { return sources[index]; }
private:
static void clear();