]> git.mxchange.org Git - flightgear.git/commitdiff
Erik Hofman:
authorcurt <curt>
Sat, 28 Sep 2002 12:16:37 +0000 (12:16 +0000)
committercurt <curt>
Sat, 28 Sep 2002 12:16:37 +0000 (12:16 +0000)
For sounds that play while a value is in transit, use time rather than
the number of frames to judge when to halt the sound because it will be much
more reliable on high performance systems. It currently waits 10 ms.
before stopping the sound, but you might want to fiddle it a little by
changing MAX_TRANSIT_TIME defined int fg_sound.hxx

src/Sound/fg_sound.cxx
src/Sound/fg_sound.hxx

index 28ebafb708e195814335c886d671db41d2f2d397..bcd95d824dbfc6495f943ae618d348c328f8c1a0 100644 (file)
@@ -70,7 +70,8 @@ FGSound::FGSound()
     _mode(FGSound::ONCE),
     _prev_value(0),
     _dt_play(0.0),
-    _dt_stop(0.0)
+    _dt_stop(0.0),
+    _stopping(0.0)
 {
 }
 
@@ -270,12 +271,19 @@ FGSound::update (double dt)
    {
 
       if (_sample->is_playing()) {
-         SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
-                                      << " sec: " << _name );
-         _sample->stop( _mgr->get_scheduler() );
+
+         if ((_mode != FGSound::IN_TRANSIT) || (_stopping < MAX_TRANSIT_TIME)) {
+
+            _active = false;
+            _sample->stop( _mgr->get_scheduler() );
+
+            SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
+                                        << " sec: " << _name );
+
+         } else
+            _stopping += dt;
       }
 
-      _active = false;
       _dt_stop += dt;
       _dt_play = 0.0;
 
index f6c21b80bcb9d58ffaef2308fab59312f4e4be3c..e3c0cda4618a123f0cadafa59467a2405b1d7ca5 100644 (file)
@@ -33,6 +33,9 @@
 
 #include "soundmgr.hxx"
 
+static const double MAX_TRANSIT_TIME = 0.01;   // 10 ms.
+
+
 /**
  * Class for handling one sound event.
  *
@@ -56,7 +59,6 @@ protected:
   enum { ONCE=0, LOOPED, IN_TRANSIT };
   enum { LEVEL=0, INVERTED, FLIPFLOP };
 
-
   // Sound properties
   typedef struct {
         SGPropertyNode * prop;
@@ -83,6 +85,8 @@ private:
   double _prev_value;
   double _dt_play;
   double _dt_stop;
+  double _stopping;    // time after the sound should have stopped.
+                       // This is usefull for lost packets in in-trasit mode.
 
   vector<_snd_prop> _volume;
   vector<_snd_prop> _pitch;