diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-17 14:19:18 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-17 14:19:18 +0000 |
commit | ae65ef53fc8b70ebee3b43bb06ecd091aaae2a26 (patch) | |
tree | d8a2a253314e0bab54edc9ee829aee819a7860bd /src/audio | |
parent | eb075660e7cb61b138c2da337115c59857f89e17 (diff) |
engine sounds
Diffstat (limited to 'src/audio')
-rw-r--r-- | src/audio/audio.cc | 41 | ||||
-rw-r--r-- | src/audio/audio.h | 13 | ||||
-rw-r--r-- | src/audio/sources.cc | 26 | ||||
-rw-r--r-- | src/audio/sources.h | 4 |
4 files changed, 84 insertions, 0 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc index 1895d21..ff0918d 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -91,4 +91,45 @@ void play(const char *name) } } +void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch, float gain) +{ + 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); +} + +void loop( size_t source_index, const char *name, float pitch, float gain) +{ + if (!audio_context) + return; + + ALuint source = Sources::source(source_index); + Buffers::bind(source, Buffers::load(std::string(name))); + + alSourcef(source, AL_PITCH, pitch); + alSourcef(source, AL_GAIN, gain); + + alSourcei(source, AL_LOOPING, AL_TRUE); + alSourceRewind(source); + alSourcePlay(source); +} + +void update_listener(math::Vector3f const &location, math::Axis const &axis, float speed) +{ + alListenerfv(AL_POSITION, location.ptr()); + + math::Vector3f velocity(axis.forward()); + velocity = velocity * speed; + //alListenerfv(AL_VELOCITY, velocity.ptr()); + + ALfloat orientation[6]; + for (size_t i =0; i <3; i++) { + orientation[i] = axis.forward()[i]; + orientation[i+3] = axis.up()[i]; + } + alListenerfv(AL_ORIENTATION, orientation); +} + } diff --git a/src/audio/audio.h b/src/audio/audio.h index bf97a4a..629ae88 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -7,6 +7,8 @@ #ifndef __INCLUDED_AUDIO_AUDIO_H__ #define __INCLUDED_AUDIO_AUDIO_H__ +#include <iostream> + #ifdef _WIN32 #include <windows.h> #endif @@ -14,6 +16,9 @@ #include "AL/al.h" #include "AL/alc.h" +#include "math/vector3f.h" +#include "math/axis.h" + /// functions to handle audio namespace audio { @@ -30,6 +35,14 @@ void load(const char *name); /// play a previously loaded audio sample void play(const char *name); +/// 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); + +/// 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); + +/// update listener parameters +void update_listener(math::Vector3f const &location, math::Axis const &axis, float speed); } #endif // __INCLUDED_AUDIO_AUDIO_H__ diff --git a/src/audio/sources.cc b/src/audio/sources.cc index 2c67304..3a6b3fc 100644 --- a/src/audio/sources.cc +++ b/src/audio/sources.cc @@ -53,4 +53,30 @@ void Sources::clear() } +size_t Sources::get() +{ + for (size_t i= MAXUISOURCES; i < MAXSOURCES; i++) { + if (source_available[i]) { + source_available[i] = false; + alSourcef(sources[i], AL_PITCH, 1.0); + alSourcef(sources[i], AL_GAIN, 1.0); + //con_debug << "reserved source " << i << std::endl; + return i; + } + } + return 0; +} + +void Sources::remove(size_t index) +{ + if ( (index < MAXUISOURCES ) || (MAXSOURCES <= index)) + return; + + source_available[index] = true; + alSourcef(sources[index], AL_GAIN, 0); + alSourceRewind(sources[index]); + + //con_debug << "removed source " << index << std::endl; +} + } diff --git a/src/audio/sources.h b/src/audio/sources.h index 302d5d5..078c424 100644 --- a/src/audio/sources.h +++ b/src/audio/sources.h @@ -27,6 +27,10 @@ public: static inline bool available(size_t index) { return source_available[index]; } static inline ALuint source(size_t index) { return sources[index]; } + + static size_t get(); + static void remove(size_t index); + private: static void clear(); |