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.
This commit is contained in:
curt
2004-04-28 03:57:13 +00:00
parent edd92caba1
commit 7d239fe4ac
3 changed files with 39 additions and 3 deletions

View File

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

View File

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

View File

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