]> git.mxchange.org Git - flightgear.git/commitdiff
Erik Hofman:
authorcurt <curt>
Sun, 25 Aug 2002 23:27:00 +0000 (23:27 +0000)
committercurt <curt>
Sun, 25 Aug 2002 23:27:00 +0000 (23:27 +0000)
I removed some pending random code and I also fixed a
small cosmetic glitch where dt_play was cleared before it was printed.

Curt: Erik changed the sound update intervale and I further I tweaked it.
The issue is that if we put too much into the sound buffer, then we can't react
quick enough to sounds like tire squeek that need to be synced with the visuals
and the action.  We put too little into the sound buffer and we risk the
audio dropping out for moment if a frame takes longer to draw than the amount
of audio in the buffer.

src/Main/main.cxx
src/Sound/fg_sound.cxx
src/Sound/fg_sound.hxx

index 52a488382549abc97d748cdbf9dfdefb00f601b4..2e1df4a6890aa9b3133e9a9f75487ebe3ab42f01 100644 (file)
@@ -861,6 +861,11 @@ static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
 static void fgMainLoop( void ) {
 
     // Update the elapsed time.
+    static bool first_time = true;
+    if ( first_time ) {
+        last_time_stamp.stamp();
+        first_time = false;
+    }
     current_time_stamp.stamp();
     delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
     last_time_stamp = current_time_stamp;
@@ -1082,8 +1087,17 @@ static void fgMainLoop( void ) {
 #ifdef ENABLE_AUDIO_SUPPORT
     if ( fgGetBool("/sim/sound/audible")
            && globals->get_soundmgr()->is_working() ) {
-       globals->get_fx()->update(1); // FIXME: use dt
-       globals->get_soundmgr()->update(1); // FIXME: use dt
+        static double dt = 0.0;
+        static double sound_update_rate = 0.05;
+
+        dt += delta_time_sec;
+
+       // Updating four times a second should be enough
+        if ( dt >= sound_update_rate ) {
+           globals->get_fx()->update( dt );
+           globals->get_soundmgr()->update( dt );
+            dt = 0.0;
+        }
     }
 #endif
 
index ccd8075e014218b934bcb364db21e6027191286e..28ebafb708e195814335c886d671db41d2f2d397 100644 (file)
@@ -136,8 +136,6 @@ FGSound::init(SGPropertyNode *node)
          volume.intern = &_dt_play;
       else if (!strcmp(intern_str, "dt_stop"))
          volume.intern = &_dt_stop;
-      else if (!strcmp(intern_str, "random"))
-         volume.intern = &_random;
 
       if ((volume.factor = kids[i]->getDoubleValue("factor", 1.0)) != 0.0)
          if (volume.factor < 0.0) {
@@ -271,16 +269,16 @@ FGSound::update (double dt)
       )
    {
 
-      _active = false;
-      _dt_stop += dt;
-      _dt_play = 0.0;
-
       if (_sample->is_playing()) {
          SG_LOG(SG_GENERAL, SG_INFO, "Stopping audio after " << _dt_play
                                       << " sec: " << _name );
          _sample->stop( _mgr->get_scheduler() );
       }
 
+      _active = false;
+      _dt_stop += dt;
+      _dt_play = 0.0;
+
       return;
 
    }
@@ -302,7 +300,7 @@ FGSound::update (double dt)
    }
 
    //
-   // Update playtime, cache the current value and feed the random number
+   // Update playing time and cache the current value.
    //
     _dt_play += dt;
    _prev_value = curr_value;
index fb871d2cbfaeb9fdf15130ce6f6a890b495810cb..f6c21b80bcb9d58ffaef2308fab59312f4e4be3c 100644 (file)
@@ -81,7 +81,6 @@ private:
   string _name;
   int _mode;
   double _prev_value;
-  double _random;
   double _dt_play;
   double _dt_stop;