From 88c0dbf6611221d3846593624387398828c435e8 Mon Sep 17 00:00:00 2001 From: ehofman Date: Wed, 8 Sep 2004 11:15:57 +0000 Subject: [PATCH] Add support for audio orientation: direction and cone definition. This currently only works for internal view and tower view because those set the listener position correctly. --- simgear/sound/sample_openal.cxx | 10 ++++++++++ simgear/sound/sample_openal.hxx | 21 +++++++++++++++++++++ simgear/sound/xmlsound.cxx | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index ffedaab4..ef6db1d8 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -83,6 +83,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file, source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0; offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0; source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0; + inner = outer = 360.0; outergain = 0.0; // clear errors from elsewhere? alGetError(); @@ -128,6 +129,10 @@ SGSoundSample::SGSoundSample( const char *path, const char *file, alSourcef( source, AL_PITCH, pitch ); alSourcef( source, AL_GAIN, volume ); alSourcefv( source, AL_POSITION, source_pos ); + alSourcefv( source, AL_DIRECTION, direction ); + alSourcef( source, AL_CONE_INNER_ANGLE, inner ); + alSourcef( source, AL_CONE_OUTER_ANGLE, outer ); + alSourcef( source, AL_CONE_OUTER_GAIN, outergain); alSourcefv( source, AL_VELOCITY, source_vel ); alSourcei( source, AL_LOOPING, loop ); @@ -154,6 +159,7 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq, source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0; offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0; source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0; + inner = outer = 360.0; outergain = 0.0; // clear errors from elsewhere? alGetError(); @@ -192,6 +198,10 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq, alSourcef( source, AL_PITCH, pitch ); alSourcef( source, AL_GAIN, volume ); alSourcefv( source, AL_POSITION, source_pos ); + alSourcefv( source, AL_DIRECTION, direction ); + alSourcef( source, AL_CONE_INNER_ANGLE, inner ); + alSourcef( source, AL_CONE_OUTER_ANGLE, outer ); + alSourcef( source, AL_CONE_OUTER_GAIN, outergain ); alSourcefv( source, AL_VELOCITY, source_vel ); alSourcei( source, AL_LOOPING, loop ); diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 8646e60d..3686edd5 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -74,6 +74,10 @@ private: // A constant offset to be applied to the final source_pos ALfloat offset_pos[3]; + // The orientation of the sound (direction and cut-off angles) + ALfloat direction[3]; + ALfloat inner, outer, outergain; + // Velocity of the source sound. ALfloat source_vel[3]; @@ -237,6 +241,23 @@ public: alSourcefv( source, AL_POSITION, final_pos ); } + /** + * Set the orientation of the sound source, both for direction + * and audio cut-off angles. + */ + inline void set_orientation( ALfloat *dir, ALfloat inner_angle=360.0, + ALfloat outer_angle=360.0, + ALfloat outer_gain=0.0) + { + inner = inner_angle; + outer = outer_angle; + outergain = outer_gain; + alSourcefv( source, AL_DIRECTION, dir); + alSourcef( source, AL_CONE_INNER_ANGLE, inner ); + alSourcef( source, AL_CONE_OUTER_ANGLE, outer ); + alSourcef( source, AL_CONE_OUTER_GAIN, outergain ); + } + /** * Set velocity of sound source (uses same coordinate system as opengl) */ diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 4e866b85..9d8dfdbc 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -247,6 +247,25 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr, offset_pos[2] = pos->getDoubleValue("z", 0.0); } + // + // Orientation + // + sgVec3 dir; + float inner, outer, outer_gain; + sgSetVec3( dir, 0.0, 0.0, 0.0 ); + inner = outer = 360.0; + outer_gain = 0.0; + pos = node->getChild("orientation"); + if ( pos != NULL ) { + dir[0] = pos->getDoubleValue("x", 0.0); + dir[1] = pos->getDoubleValue("y", 0.0); + dir[2] = pos->getDoubleValue("z", 0.0); + inner = pos->getDoubleValue("inner-angle", 360.0); + outer = pos->getDoubleValue("outer-angle", 360.0); + outer_gain = pos->getDoubleValue("outer-gain", 0.0); + } + + // // Initialize the sample // @@ -260,6 +279,7 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr, } _sample->set_offset_pos( offset_pos ); + _sample->set_orientation(dir, inner, outer, outer_gain); _sample->set_volume(v); _sample->set_reference_dist( reference_dist ); _sample->set_max_dist( max_dist ); -- 2.39.5