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>2008-08-08 22:17:29 +0000
committerStijn Buys <ingar@osirion.org>2008-08-08 22:17:29 +0000
commit56b0856541446cbafee4eed9ef0ee9fb69af565a (patch)
tree8cec133fb9b0a02fc2f415c26b69fcd4c6db1ef9 /src/audio
parentf540e8dac10de8ff443692e78404b1508dde9d1e (diff)
improved truster indicator, impulse engine sounds
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio.cc74
-rw-r--r--src/audio/audio.h12
2 files changed, 69 insertions, 17 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 50d15c8..81a260c 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -81,19 +81,19 @@ void shutdown()
}
}
-void play(const char *name)
+size_t play(const char *name)
{
if (!audio_context)
- return;
+ return 0;
- size_t buffer = Buffers::load(std::string(name));
+ size_t buffer_index = Buffers::load(std::string(name));
for (size_t i = 0; i < MAXUISOURCES; i++) {
ALint srcstate = 0;
ALuint source = Sources::source(i);
alGetSourcei(source , AL_SOURCE_STATE , &srcstate);
if (srcstate != AL_PLAYING) {
- Buffers::bind(source, buffer);
+ Buffers::bind(source, buffer_index);
alSourcef(source, AL_PITCH, 1.0);
alSourcef(source, AL_GAIN, 1.0);
alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
@@ -101,30 +101,49 @@ void play(const char *name)
alSourcefv(source, AL_POSITION, location);
alSourceRewind(source);
alSourcePlay(source);
- return;
+ return buffer_index;
}
}
+
+ return 0;
}
-void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch, float gain)
+size_t play(size_t source_index, size_t buffer_index, float pitch, float gain)
{
- if (!audio_context)
- return;
+ if (!audio_context || !buffer_index)
+ return 0;
ALuint source = Sources::source(source_index);
- alSourcefv(source, AL_POSITION, location.ptr());
- //alSourcefv(source, AL_VELOCITY, velocity.ptr());
+ ALint srcstate = 0;
+ alGetSourcei(source , AL_SOURCE_STATE , &srcstate);
+ if (srcstate == AL_PLAYING) {
+ alSourceStop(source);
+ }
+ Buffers::bind(source, buffer_index);
+ alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcef(source, AL_PITCH, pitch);
alSourcef(source, AL_GAIN, gain);
+
+ alSourcei(source, AL_LOOPING, AL_FALSE);
+ alSourceRewind(source);
+ alSourcePlay(source);
+
+ return buffer_index;
}
-void loop( size_t source_index, const char *name, float pitch, float gain)
+size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain)
{
- if (!audio_context)
- return;
+ if (!audio_context || !buffer_index)
+ return 0;
ALuint source = Sources::source(source_index);
- Buffers::bind(source, Buffers::load(std::string(name)));
+ ALint srcstate = 0;
+ alGetSourcei(source , AL_SOURCE_STATE , &srcstate);
+ if (srcstate == AL_PLAYING) {
+ alSourceStop(source);
+ }
+
+ Buffers::bind(source, buffer_index);
//alSourcef(source, AL_REFERENCE_DISTANCE, 2.0f); // might be the cause of cracks in the sound
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
@@ -134,6 +153,20 @@ void loop( size_t source_index, const char *name, float pitch, float gain)
alSourcei(source, AL_LOOPING, AL_TRUE);
alSourceRewind(source);
alSourcePlay(source);
+
+ return buffer_index;
+}
+
+size_t loop(size_t source_index, const char *name, float pitch, float gain)
+{
+ if (!audio_context)
+ return 0;
+
+ size_t buffer_index = Buffers::load(std::string(name));
+ if (buffer_index)
+ loop(source_index, buffer_index, pitch, gain);
+
+ return buffer_index;
}
void update_listener(math::Vector3f const &location, math::Axis const &axis, math::Vector3f const & velocity)
@@ -151,5 +184,18 @@ void update_listener(math::Vector3f const &location, math::Axis const &axis, mat
alListenerfv(AL_ORIENTATION, orientation);
//alListenerfv(AL_VELOCITY, velocity.ptr());
}
+
+
+void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch, float gain)
+{
+ if (!audio_context)
+ return;
+
+ ALuint source = Sources::source(source_index);
+ alSourcefv(source, AL_POSITION, location.ptr());
+ //alSourcefv(source, AL_VELOCITY, velocity.ptr());
+ alSourcef(source, AL_PITCH, pitch);
+ alSourcef(source, AL_GAIN, gain);
+}
}
diff --git a/src/audio/audio.h b/src/audio/audio.h
index a3d4010..c0479d3 100644
--- a/src/audio/audio.h
+++ b/src/audio/audio.h
@@ -32,11 +32,17 @@ void shutdown();
/// load an audio sample
void load(const char *name);
-/// play a previously loaded audio sample
-void play(const char *name);
+/// play a previously loaded audio sample on the ui channel
+size_t play(const char *name);
+
+/// playe a sound from a specific buffer on a specific source
+size_t play(size_t source_index, size_t buffer_index, float pitch=1.0f, float gain=1.0f);
/// play a looping sound on a specified source
-void loop( size_t source_index, const char *name, float pitch=1.0f, float gain=1.0f);
+size_t loop( size_t source_index, const char *name, float pitch=1.0f, float gain=1.0f);
+
+/// play a looping sound from a specified buffer on a specified source
+size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain);
/// update source parameters
void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch=1.0f, float gain=1.0f);