Add support for audio orientation: direction and cone definition. This currently only works for internal view and tower view because those set the listener position correctly.

This commit is contained in:
ehofman
2004-09-08 11:15:57 +00:00
parent 9e3822ceaf
commit 88c0dbf661
3 changed files with 51 additions and 0 deletions
+10
View File
@@ -83,6 +83,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
inner = outer = 360.0; outergain = 0.0;
// clear errors from elsewhere?
alGetError();
@@ -128,6 +129,10 @@ SGSoundSample::SGSoundSample( const char *path, const char *file,
alSourcef( source, AL_PITCH, pitch );
alSourcef( source, AL_GAIN, volume );
alSourcefv( source, AL_POSITION, source_pos );
alSourcefv( source, AL_DIRECTION, direction );
alSourcef( source, AL_CONE_INNER_ANGLE, inner );
alSourcef( source, AL_CONE_OUTER_ANGLE, outer );
alSourcef( source, AL_CONE_OUTER_GAIN, outergain);
alSourcefv( source, AL_VELOCITY, source_vel );
alSourcei( source, AL_LOOPING, loop );
@@ -154,6 +159,7 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq,
source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
offset_pos[0] = 0.0; offset_pos[1] = 0.0; offset_pos[2] = 0.0;
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
inner = outer = 360.0; outergain = 0.0;
// clear errors from elsewhere?
alGetError();
@@ -192,6 +198,10 @@ SGSoundSample::SGSoundSample( unsigned char *_data, int len, int _freq,
alSourcef( source, AL_PITCH, pitch );
alSourcef( source, AL_GAIN, volume );
alSourcefv( source, AL_POSITION, source_pos );
alSourcefv( source, AL_DIRECTION, direction );
alSourcef( source, AL_CONE_INNER_ANGLE, inner );
alSourcef( source, AL_CONE_OUTER_ANGLE, outer );
alSourcef( source, AL_CONE_OUTER_GAIN, outergain );
alSourcefv( source, AL_VELOCITY, source_vel );
alSourcei( source, AL_LOOPING, loop );
+21
View File
@@ -74,6 +74,10 @@ private:
// A constant offset to be applied to the final source_pos
ALfloat offset_pos[3];
// The orientation of the sound (direction and cut-off angles)
ALfloat direction[3];
ALfloat inner, outer, outergain;
// Velocity of the source sound.
ALfloat source_vel[3];
@@ -237,6 +241,23 @@ public:
alSourcefv( source, AL_POSITION, final_pos );
}
/**
* Set the orientation of the sound source, both for direction
* and audio cut-off angles.
*/
inline void set_orientation( ALfloat *dir, ALfloat inner_angle=360.0,
ALfloat outer_angle=360.0,
ALfloat outer_gain=0.0)
{
inner = inner_angle;
outer = outer_angle;
outergain = outer_gain;
alSourcefv( source, AL_DIRECTION, dir);
alSourcef( source, AL_CONE_INNER_ANGLE, inner );
alSourcef( source, AL_CONE_OUTER_ANGLE, outer );
alSourcef( source, AL_CONE_OUTER_GAIN, outergain );
}
/**
* Set velocity of sound source (uses same coordinate system as opengl)
*/
+20
View File
@@ -247,6 +247,25 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr,
offset_pos[2] = pos->getDoubleValue("z", 0.0);
}
//
// Orientation
//
sgVec3 dir;
float inner, outer, outer_gain;
sgSetVec3( dir, 0.0, 0.0, 0.0 );
inner = outer = 360.0;
outer_gain = 0.0;
pos = node->getChild("orientation");
if ( pos != NULL ) {
dir[0] = pos->getDoubleValue("x", 0.0);
dir[1] = pos->getDoubleValue("y", 0.0);
dir[2] = pos->getDoubleValue("z", 0.0);
inner = pos->getDoubleValue("inner-angle", 360.0);
outer = pos->getDoubleValue("outer-angle", 360.0);
outer_gain = pos->getDoubleValue("outer-gain", 0.0);
}
//
// Initialize the sample
//
@@ -260,6 +279,7 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGSoundMgr *sndmgr,
}
_sample->set_offset_pos( offset_pos );
_sample->set_orientation(dir, inner, outer, outer_gain);
_sample->set_volume(v);
_sample->set_reference_dist( reference_dist );
_sample->set_max_dist( max_dist );