]> git.mxchange.org Git - simgear.git/commitdiff
Add support for audio orientation: direction and cone definition. This currently...
authorehofman <ehofman>
Wed, 8 Sep 2004 11:15:57 +0000 (11:15 +0000)
committerehofman <ehofman>
Wed, 8 Sep 2004 11:15:57 +0000 (11:15 +0000)
simgear/sound/sample_openal.cxx
simgear/sound/sample_openal.hxx
simgear/sound/xmlsound.cxx

index ffedaab4269c12858321c1b3689eacbb72b0d9d3..ef6db1d8feaae001a0f936ad7a4a5f66b03e40f1 100644 (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 );
 
index 8646e60d8e484512f2b61366b88404e520ded0dd..3686edd5b68989c73f38a58959dd2df52c0f1cf9 100644 (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)
      */
index 4e866b85e7f0c76320cc7a9277aef9f585e71f56..9d8dfdbc78fa5298ba18e37c69ce1f4a0459aa9e 100644 (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 );