Hi,

at the osg branch, the directional sound and doppler effects should work since two days.

It seems that (at least) on windows there is a bug within OpenAL calculating the Doppler effect. Either there is no Doppler Effect (like I have) or it is totally wrong (as aerotro has with the same executable than I have). Eventually it affects the performance of flightgear.

The enclosed patch switches of the Doppler calculation of OpenAL and adds a own Doppler calculation. The patch is not designed for cvs (now). I first need the feedback, if all windows builds or even other OS are affected.

With this patch Doppler effect should be ok at every OS. I hope, that the performance issue is solved with that, too (or is independent from the sound former sound patch).



Now that the Doppler effect works here I got aware of some bugs:
- the effect is wrong, if the aircraft changes its orientation (pitch and heading) - the sound is switched off for one frame if the fly-by view jumps to a new eyepoint (and often some 3d models are loaded at this time this frame can be noticeable long)
- the same happens, if you change the view
- if you move (rotate) the eye-point in an external view you hear Doppler effects

I will try to make a patch for this within the next days.

Maik
Index: sound/sample_openal.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.cxx,v
retrieving revision 1.27
diff -u -p -r1.27 sample_openal.cxx
--- sound/sample_openal.cxx     21 Jun 2007 21:46:21 -0000      1.27
+++ sound/sample_openal.cxx     24 Jun 2007 00:06:53 -0000
@@ -75,6 +75,10 @@ SGSoundSample::SGSoundSample() :
     reference_dist(500.0),
     max_dist(3000.),
     loop(AL_FALSE),
+#ifndef USE_OPEN_AL_DOPPLER
+    doppler_pitch_factor(1),
+    doppler_volume_factor(1),
+#endif
     playing(false)
 {
 }
@@ -273,7 +277,7 @@ SGSoundSample::set_pitch( double p ) {
     if ( p > 2.0 ) { p = 2.0; }
     pitch = p;
     if (playing) {
-        alSourcef( source, AL_PITCH, pitch );
+        alSourcef( source, AL_PITCH, pitch * doppler_pitch_factor );
         print_openal_error("set_pitch");
     }
 }
@@ -282,7 +286,7 @@ void
 SGSoundSample::set_volume( double v ) {
     volume = v;
     if (playing) {
-        alSourcef( source, AL_GAIN, volume );
+        alSourcef( source, AL_GAIN, volume * doppler_volume_factor );
         print_openal_error("set_volume");
     }
 }
@@ -354,9 +358,35 @@ SGSoundSample::set_source_vel( ALfloat *
     source_vel[0] = vel[0];
     source_vel[1] = vel[1];
     source_vel[2] = vel[2];
+#ifdef USE_OPEN_AL_DOPPLER
     if (playing) {
         alSourcefv( source, AL_VELOCITY, source_vel );
     }
+#else
+    double doppler, msv, mfp;
+    sgVec3 final_pos;
+    sgAddVec3( final_pos, source_pos, offset_pos );
+    msv = sgLengthVec3(source_vel);
+    mfp = sgLengthVec3(final_pos);
+    if (mfp > 1e-6)
+        doppler = (msv < 339) ? (340 - 
+            sgScalarProductVec3( source_vel, final_pos ) / mfp) / (340 - msv) 
+            : 0;
+    else
+        doppler = 1;
+    if (doppler > 0.1) {
+        doppler_pitch_factor = doppler;
+        doppler_volume_factor = 1;
+    }
+    else {
+        doppler_pitch_factor = 0.1;
+        doppler_volume_factor = (doppler > 0) ? doppler * 10 : 0;
+    }
+    if (playing) {
+        alSourcef( source, AL_GAIN, volume * doppler_volume_factor );
+        alSourcef( source, AL_PITCH, pitch * doppler_pitch_factor );
+    }
+#endif
 }
 
 void
Index: sound/sample_openal.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.hxx,v
retrieving revision 1.17
diff -u -p -r1.17 sample_openal.hxx
--- sound/sample_openal.hxx     8 Mar 2006 18:16:09 -0000       1.17
+++ sound/sample_openal.hxx     24 Jun 2007 00:06:54 -0000
@@ -90,6 +90,10 @@ private:
 
     double pitch;
     double volume;
+#ifndef USE_OPEN_AL_DOPPLER
+    double doppler_pitch_factor;
+    double doppler_volume_factor;
+#endif
     double reference_dist;
     double max_dist;
     ALboolean loop;
-------------------------------------------------------------------------
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