From 7d239fe4ac7af88c7a4c11c6355adae18fbf9171 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 28 Apr 2004 03:57:13 +0000 Subject: [PATCH] Expose the ability to specify how the sound volume fades relative to distance from the listener. This let's us configure "interior" cockpit sounds versus "exterior" engine type sounds. --- simgear/sound/sample_openal.cxx | 12 ++++++++++-- simgear/sound/sample_openal.hxx | 21 +++++++++++++++++++++ simgear/sound/xmlsound.cxx | 9 ++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 6d3739dc..d2242d3c 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -66,6 +66,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file, data(NULL), pitch(1.0), volume(1.0), + reference_dist(500.0), + max_dist(3000.), loop(AL_FALSE) { SGPath samplepath( path ); @@ -131,8 +133,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file, alSourcei( source, AL_LOOPING, loop ); alSourcei( source, AL_SOURCE_RELATIVE, AL_TRUE ); - alSourcef( source, AL_REFERENCE_DISTANCE, 500.0f ); - alSourcef( source, AL_MAX_DISTANCE, 3000.0f ); + alSourcef( source, AL_REFERENCE_DISTANCE, reference_dist ); + alSourcef( source, AL_MAX_DISTANCE, max_dist ); } @@ -141,6 +143,8 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) : data(NULL), pitch(1.0), volume(1.0), + reference_dist(500.0), + max_dist(3000.), loop(AL_FALSE) { SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); @@ -176,6 +180,10 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) : alSourcefv( source, AL_POSITION, source_pos ); alSourcefv( source, AL_VELOCITY, source_vel ); alSourcei( source, AL_LOOPING, loop ); + + alSourcei( source, AL_SOURCE_RELATIVE, AL_TRUE ); + alSourcef( source, AL_REFERENCE_DISTANCE, reference_dist ); + alSourcef( source, AL_MAX_DISTANCE, max_dist ); } diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 90d4baeb..e0488979 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -81,6 +81,8 @@ private: double pitch; double volume; + double reference_dist; + double max_dist; ALboolean loop; public: @@ -210,6 +212,25 @@ public: alSourcefv( source, AL_VELOCITY, source_vel ); } + + /** + * Set reference distance of sound (the distance where the gain + * will be half.) + */ + inline void set_reference_dist( ALfloat dist ) { + reference_dist = dist; + alSourcef( source, AL_REFERENCE_DISTANCE, reference_dist ); + } + + + /** + * Set maximume distance of sound (the distance where the sound is + * no longer audible. + */ + inline void set_max_dist( ALfloat dist ) { + max_dist = dist; + alSourcef( source, AL_MAX_DISTANCE, max_dist ); + } }; diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 79d441e7..5708486b 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -180,7 +180,11 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr, } - + float reference_dist = node->getDoubleValue("reference-dist", 500.0); + float max_dist = node->getDoubleValue("max-dist", 3000.0); + SG_LOG(SG_GENERAL,SG_ALERT, "ref-dist = " << reference_dist ); + SG_LOG(SG_GENERAL,SG_ALERT, "max-dist = " << max_dist ); + // // set pitch properties // @@ -241,10 +245,13 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr, _sample = new SGSoundSample( path.c_str(), node->getStringValue("path", ""), true ); + _mgr->add( _sample, _name ); } _sample->set_volume(v); + _sample->set_reference_dist( reference_dist ); + _sample->set_max_dist( max_dist ); _sample->set_pitch(p); } -- 2.39.5