Hi,

please find enclosed a patch enabling directional sound for the osg-branch.

In principle the same can be done in the plib branch, but there is a bug within the eye-position reported by viewer.cxx and I am not sure about the easiest way to get the listener-pos, listener-up and listener-look-at vectors.

Please commit.

(The aircrafts having definitions for directional sound will probably not work as expected. There was an error regarding defining the sound direction and now the sound use the same base as the 3D-model-animations.)


Regards,
Maik


Index: sound/sample_openal.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.cxx,v
retrieving revision 1.26
diff -u -p -r1.26 sample_openal.cxx
--- sound/sample_openal.cxx     8 Mar 2006 18:16:09 -0000       1.26
+++ sound/sample_openal.cxx     20 Jun 2007 21:11:08 -0000
@@ -338,6 +338,9 @@ SGSoundSample::set_orientation( ALfloat 
     inner = inner_angle;
     outer = outer_angle;
     outergain = outer_gain;
+    direction[0] = dir[0];
+    direction[1] = dir[1];
+    direction[2] = dir[2];
     if (playing) {
         alSourcefv( source, AL_DIRECTION, dir);
         alSourcef( source, AL_CONE_INNER_ANGLE, inner );
Index: sound/xmlsound.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/xmlsound.cxx,v
retrieving revision 1.19
diff -u -p -r1.19 xmlsound.cxx
--- sound/xmlsound.cxx  30 Jul 2006 21:02:36 -0000      1.19
+++ sound/xmlsound.cxx  20 Jun 2007 21:11:11 -0000
@@ -237,7 +237,7 @@ SGXmlSound::init(SGPropertyNode *root, S
    SGPropertyNode_ptr pos = node->getChild("position");
    if ( pos != NULL ) {
        offset_pos[0] = pos->getDoubleValue("x", 0.0);
-       offset_pos[1] = pos->getDoubleValue("y", 0.0);
+       offset_pos[1] = - pos->getDoubleValue("y", 0.0);
        offset_pos[2] = pos->getDoubleValue("z", 0.0);
    }
 
@@ -252,7 +252,7 @@ SGXmlSound::init(SGPropertyNode *root, S
    pos = node->getChild("orientation");
    if ( pos != NULL ) {
       dir[0] = pos->getDoubleValue("x", 0.0);
-      dir[1] = pos->getDoubleValue("y", 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);
Index: README.xmlsound
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/Docs/README.xmlsound,v
retrieving revision 1.3
diff -u -p -r1.3 README.xmlsound
--- README.xmlsound     30 Oct 2005 09:50:54 -0000      1.3
+++ README.xmlsound     20 Jun 2007 21:29:18 -0000
@@ -196,9 +196,11 @@ Configuration description:
 
    <position>
         Specify the position of the sounds source relative to the
-        pilot's ears.  The coordinate system used is a right hand
-        coordinate system where -X = left, +X = right, -Y = down, +Y =
-        up, -Z = forward, +Z = aft.  Distances are in meters.
+        aircraft center.  The coordinate system used is a right hand
+        coordinate system where +Y = left, -Y = right, -Z = down, +Z =
+        up, -X = forward, +X = aft.  Distances are in meters.
+        The volume calculation due to distance and orientation of the
+        sounds source ONLY work on mono samples!
 
      <x>
         X dimension offset
@@ -214,16 +216,17 @@ Configuration description:
         Specify the orientation of the sounds source.
 
         The zero vector is default, indicating that a Source is not 
directional.
-        Specifying a non-zero vector will make the Source directional.
+        Specifying a non-zero vector will make the Source directional in
+        the X,Y,Z direction
 
      <x>
-        X dimension angle (0.0 - 360.0)
+        X dimension
 
      <y>
-        Y dimension angle (0.0 - 360.0)
+        Y dimension
 
      <z>
-        Z dimension angle (0.0 - 360.0)
+        Z dimension
 
      <inner-cone>
         The inner edge of the audio cone in degrees (0.0 - 360.0).
Index: Main/main.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Main/main.cxx,v
retrieving revision 1.238
diff -u -p -r1.238 main.cxx
--- Main/main.cxx       21 May 2007 17:50:02 -0000      1.238
+++ Main/main.cxx       20 Jun 2007 21:27:20 -0000
@@ -546,10 +546,29 @@ static void fgMainLoop( void ) {
 #ifdef ENABLE_AUDIO_SUPPORT
     // Right now we make a simplifying assumption that the primary
     // aircraft is the source of all sounds and that all sounds are
-    // positioned relative to the current view position.
+    // positioned in the aircraft base
 
     static sgVec3 last_pos_offset;
 
+    //get the orientations
+    const SGQuatd view_or = current_view->getViewOrientation();
+    SGQuatd surf_or = SGQuatd::fromLonLatDeg(
+        current_view->getLongitude_deg(),current_view->getLatitude_deg());
+    SGQuatd model_or = SGQuatd::fromYawPitchRollDeg(
+        globals->get_aircraft_model()->get3DModel()->getHeadingDeg(),
+        globals->get_aircraft_model()->get3DModel()->getPitchDeg(),
+        globals->get_aircraft_model()->get3DModel()->getRollDeg());
+
+    //get the up and at vector in the aircraft base 
+    SGVec3d sgv_up = model_or.rotateBack(
+        surf_or.rotateBack(view_or.rotate(SGVec3d(0,-1,0))));
+    sgVec3 up;
+    sgSetVec3(up,sgv_up[0],sgv_up[1],sgv_up[2]);
+    SGVec3d sgv_at = model_or.rotateBack(
+        surf_or.rotateBack(view_or.rotate(SGVec3d(0,0,1))));
+    sgVec3 at;
+    sgSetVec3(at,sgv_at[0],sgv_at[1],sgv_at[2]);
+
     // get the location data for the primary FDM (now hardcoded to ac model)...
     SGLocation *acmodel_loc = NULL;
     acmodel_loc = (SGLocation *)globals->
@@ -558,13 +577,26 @@ static void fgMainLoop( void ) {
     // set positional offset for sources
     sgdVec3 dsource_pos_offset;
     sgdSubVec3( dsource_pos_offset,
-                view_location->get_absolute_view_pos(),
+                (double*) &current_view->get_view_pos(),
                 acmodel_loc->get_absolute_view_pos() );
-    // cout << "pos all = " << source_pos_offset[0] << " " << 
source_pos_offset[1] << " " << source_pos_offset[2] << endl;
+    SGVec3d sgv_dsource_pos_offset = model_or.rotateBack(
+        surf_or.rotateBack(SGVec3d(dsource_pos_offset[0],
+        dsource_pos_offset[1],dsource_pos_offset[2])));
+
+    //sgv_dsource_pos_offset = model_or.rotateBack(sgv_dsource_pos_offset);
     sgVec3 source_pos_offset;
-    sgSetVec3(source_pos_offset, dsource_pos_offset);
+    sgSetVec3(source_pos_offset, sgv_dsource_pos_offset[0],
+        sgv_dsource_pos_offset[1], sgv_dsource_pos_offset[2]);
+
     globals->get_soundmgr()->set_source_pos_all( source_pos_offset );
 
+    float ori[6];
+    for(int i=0;i<3;i++) {
+        ori[i] = sgv_at[i];
+        ori[i+3] = sgv_up[i];
+    }
+    globals->get_soundmgr()->set_listener_orientation( ori );
+
     // set the velocity
     sgVec3 source_vel;
     sgSubVec3( source_vel, source_pos_offset, last_pos_offset );
@@ -573,11 +605,9 @@ static void fgMainLoop( void ) {
     // cout << "vel = " << source_vel[0] << " " << source_vel[1] << " " << 
source_vel[2] << endl;
     globals->get_soundmgr()->set_source_vel_all( source_vel );
 
-    // Right now we make a simplifying assumption that the listener is
-    // always positioned at the origin.
+    // The listener is always positioned at the origin.
     sgVec3 listener_pos;
     sgSetVec3( listener_pos, 0.0, 0.0, 0.0 );
-    // cout << "listener = " << listener_pos[0] << " " << listener_pos[1] << " 
" << listener_pos[2] << endl;
     globals->get_soundmgr()->set_listener_pos( listener_pos );
 #endif
 
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to