From 89d426470b264038192d7ee183864363244c8969 Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 22 Jul 2007 13:33:23 +0000 Subject: [PATCH] Maik JUSTUS: Doppler fixes (add option to turn off Doppler for sounds that shouldn't be affected -- marker beep, ATIS messages, etc.) mf: this is the first part of the original patch. It is supposed to contain fixes that are not caused by OpenAL bugs, and thus aren't meant to be reverted later. The second part will contain a temprary workaround for OpenAL bugs. Unfortunately, I had to do the split myself as the contributor refused to do it. --- simgear/sound/sample_openal.cxx | 31 +++++++++++++++++++++---------- simgear/sound/sample_openal.hxx | 8 +++++--- simgear/sound/soundmgr_openal.cxx | 2 +- simgear/sound/xmlsound.cxx | 3 ++- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 2eb4910d..ec494392 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -75,12 +75,13 @@ SGSoundSample::SGSoundSample() : reference_dist(500.0), max_dist(3000.), loop(AL_FALSE), - playing(false) + playing(false), + no_Doppler_effect(true) { } // constructor -SGSoundSample::SGSoundSample( const char *path, const char *file) : +SGSoundSample::SGSoundSample( const char *path, const char *file , bool _no_Doppler_effect ) : buffer(0), source(0), pitch(1.0), @@ -88,8 +89,9 @@ SGSoundSample::SGSoundSample( const char *path, const char *file) : reference_dist(500.0), max_dist(3000.), loop(AL_FALSE), - playing(false) -{ + playing(false), + no_Doppler_effect(_no_Doppler_effect) + { SGPath samplepath( path ); if ( strlen(file) ) { samplepath.append( file ); @@ -145,7 +147,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file) : } // constructor -SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) : +SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq , bool _no_Doppler_effect ) : buffer(0), source(0), pitch(1.0), @@ -153,7 +155,8 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) : reference_dist(500.0), max_dist(3000.), loop(AL_FALSE), - playing(false) + playing(false), + no_Doppler_effect(_no_Doppler_effect) { SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); @@ -313,6 +316,7 @@ SGSoundSample::set_source_pos( ALfloat *pos ) { sgAddVec3( final_pos, source_pos, offset_pos ); alSourcefv( source, AL_POSITION, final_pos ); + print_openal_error("set_source_pos"); } } @@ -327,6 +331,7 @@ SGSoundSample::set_offset_pos( ALfloat *pos ) { sgAddVec3( final_pos, source_pos, offset_pos ); alSourcefv( source, AL_POSITION, final_pos ); + print_openal_error("set_offset_pos"); } } @@ -350,10 +355,16 @@ SGSoundSample::set_orientation( ALfloat *dir, ALfloat inner_angle, } void -SGSoundSample::set_source_vel( ALfloat *vel ) { - source_vel[0] = vel[0]; - source_vel[1] = vel[1]; - source_vel[2] = vel[2]; +SGSoundSample::set_source_vel( ALfloat *vel , ALfloat *listener_vel ) { + if (no_Doppler_effect) { + source_vel[0] = listener_vel[0]; + source_vel[1] = listener_vel[1]; + source_vel[2] = listener_vel[2]; + } else { + source_vel[0] = vel[0]; + source_vel[1] = vel[1]; + source_vel[2] = vel[2]; + } if (playing) { alSourcefv( source, AL_VELOCITY, source_vel ); } diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 41780783..b1559801 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -52,6 +52,7 @@ # include #endif + SG_USING_STD(string); /** @@ -96,6 +97,7 @@ private: bool playing; bool bind_source(); + bool no_Doppler_effect; public: @@ -112,7 +114,7 @@ public: should usually be true unless you want to manipulate the data later.) */ - SGSoundSample( const char *path, const char *file ); + SGSoundSample( const char *path, const char *file , bool no_Doppler_effect = true ); /** * Constructor. @@ -123,7 +125,7 @@ public: should usually be true unless you want to manipulate the data later.) */ - SGSoundSample( unsigned char *_data, int len, int _freq ); + SGSoundSample( unsigned char *_data, int len, int _freq , bool no_Doppler_effect = true ); ~SGSoundSample(); @@ -208,7 +210,7 @@ public: /** * Set velocity of sound source (uses same coordinate system as opengl) */ - void set_source_vel( ALfloat *vel ); + void set_source_vel( ALfloat *vel , ALfloat *listener_vel ); /** diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index d29b7fb1..0a85fcce 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -345,6 +345,6 @@ void SGSoundMgr::set_source_vel_all( ALfloat *vel ) { sample_map_iterator sample_end = samples.end(); for ( ; sample_current != sample_end; ++sample_current ) { SGSoundSample *sample = sample_current->second; - sample->set_source_vel( vel ); + sample->set_source_vel( vel , listener_vel ); } } diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 078dffd7..1dfe62ab 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -272,7 +272,8 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr, // "alSource". The semantics of what is going on here seems // confused and needs to be thought through more carefully. _sample = new SGSoundSample( path.c_str(), - node->getStringValue("path", "") ); + node->getStringValue("path", ""), + false ); _mgr->add( _sample, _name ); } -- 2.39.5