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),
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 );
}

View File

@ -52,6 +52,7 @@
# include <AL/alut.h>
#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 );
/**

View File

@ -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 );
}
}

View File

@ -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 );
}