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.
This commit is contained in:
mfranz 2007-07-22 13:33:23 +00:00
parent 23c7a1b5b7
commit 89d426470b
4 changed files with 29 additions and 15 deletions

View File

@ -75,12 +75,13 @@ SGSoundSample::SGSoundSample() :
reference_dist(500.0), reference_dist(500.0),
max_dist(3000.), max_dist(3000.),
loop(AL_FALSE), loop(AL_FALSE),
playing(false) playing(false),
no_Doppler_effect(true)
{ {
} }
// constructor // constructor
SGSoundSample::SGSoundSample( const char *path, const char *file) : SGSoundSample::SGSoundSample( const char *path, const char *file , bool _no_Doppler_effect ) :
buffer(0), buffer(0),
source(0), source(0),
pitch(1.0), pitch(1.0),
@ -88,8 +89,9 @@ SGSoundSample::SGSoundSample( const char *path, const char *file) :
reference_dist(500.0), reference_dist(500.0),
max_dist(3000.), max_dist(3000.),
loop(AL_FALSE), loop(AL_FALSE),
playing(false) playing(false),
{ no_Doppler_effect(_no_Doppler_effect)
{
SGPath samplepath( path ); SGPath samplepath( path );
if ( strlen(file) ) { if ( strlen(file) ) {
samplepath.append( file ); samplepath.append( file );
@ -145,7 +147,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file) :
} }
// constructor // 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), buffer(0),
source(0), source(0),
pitch(1.0), pitch(1.0),
@ -153,7 +155,8 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq ) :
reference_dist(500.0), reference_dist(500.0),
max_dist(3000.), max_dist(3000.),
loop(AL_FALSE), loop(AL_FALSE),
playing(false) playing(false),
no_Doppler_effect(_no_Doppler_effect)
{ {
SG_LOG( SG_GENERAL, SG_DEBUG, "In memory sounds sample" ); 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 ); sgAddVec3( final_pos, source_pos, offset_pos );
alSourcefv( source, AL_POSITION, final_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 ); sgAddVec3( final_pos, source_pos, offset_pos );
alSourcefv( source, AL_POSITION, final_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 void
SGSoundSample::set_source_vel( ALfloat *vel ) { SGSoundSample::set_source_vel( ALfloat *vel , ALfloat *listener_vel ) {
source_vel[0] = vel[0]; if (no_Doppler_effect) {
source_vel[1] = vel[1]; source_vel[0] = listener_vel[0];
source_vel[2] = vel[2]; 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) { if (playing) {
alSourcefv( source, AL_VELOCITY, source_vel ); alSourcefv( source, AL_VELOCITY, source_vel );
} }

View File

@ -52,6 +52,7 @@
# include <AL/alut.h> # include <AL/alut.h>
#endif #endif
SG_USING_STD(string); SG_USING_STD(string);
/** /**
@ -96,6 +97,7 @@ private:
bool playing; bool playing;
bool bind_source(); bool bind_source();
bool no_Doppler_effect;
public: public:
@ -112,7 +114,7 @@ public:
should usually be true unless you want to manipulate the data should usually be true unless you want to manipulate the data
later.) later.)
*/ */
SGSoundSample( const char *path, const char *file ); SGSoundSample( const char *path, const char *file , bool no_Doppler_effect = true );
/** /**
* Constructor. * Constructor.
@ -123,7 +125,7 @@ public:
should usually be true unless you want to manipulate the data should usually be true unless you want to manipulate the data
later.) later.)
*/ */
SGSoundSample( unsigned char *_data, int len, int _freq ); SGSoundSample( unsigned char *_data, int len, int _freq , bool no_Doppler_effect = true );
~SGSoundSample(); ~SGSoundSample();
@ -208,7 +210,7 @@ public:
/** /**
* Set velocity of sound source (uses same coordinate system as opengl) * 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 );
/** /**

View File

@ -345,6 +345,6 @@ void SGSoundMgr::set_source_vel_all( ALfloat *vel ) {
sample_map_iterator sample_end = samples.end(); sample_map_iterator sample_end = samples.end();
for ( ; sample_current != sample_end; ++sample_current ) { for ( ; sample_current != sample_end; ++sample_current ) {
SGSoundSample *sample = sample_current->second; SGSoundSample *sample = sample_current->second;
sample->set_source_vel( vel ); sample->set_source_vel( vel , listener_vel );
} }
} }

View File

@ -272,7 +272,8 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr,
// "alSource". The semantics of what is going on here seems // "alSource". The semantics of what is going on here seems
// confused and needs to be thought through more carefully. // confused and needs to be thought through more carefully.
_sample = new SGSoundSample( path.c_str(), _sample = new SGSoundSample( path.c_str(),
node->getStringValue("path", "") ); node->getStringValue("path", ""),
false );
_mgr->add( _sample, _name ); _mgr->add( _sample, _name );
} }