]> git.mxchange.org Git - flightgear.git/commitdiff
- Fixed mk-viii sound sample loader: missing "/".
authorThorsten Brehm <brehm@patagonia.southamerica>
Thu, 30 Sep 2010 21:18:13 +0000 (23:18 +0200)
committerThorsten Brehm <brehm@patagonia.southamerica>
Thu, 30 Sep 2010 21:18:13 +0000 (23:18 +0200)
- Fixed triggering of debug assertion "altitude_callout_voice != NULL" when
  altitude callouts were delayed by higher priority warnings.
- Fixed performance bug: MK_VIII::IOHandler::TerrainClearanceFilter::update
  sucked CPU time (top #12 in profiler), due to complex "moving average"
  calculation on a queue of hundreds/thousands of altitude samples.
  Also, pausing the sim caused this queue to grow excessively (by one sample
  per update loop) => resuming the sim after pausing it for a long time
  resulted in the TerrainClearanceFilter sucking even more CPU time...
  => Number of altitude samples is now limited to 5 samples/sim-time-second
  (still more than enough to calculate a stable average).

src/Instrumentation/mk_viii.cxx
src/Instrumentation/mk_viii.hxx

index 65c22fe493ce7d369b67dc9a7dc6b2fca672261c..25e0f24917a1892e421cc8ce02a8808647a77281 100755 (executable)
@@ -987,6 +987,11 @@ MK_VIII::IOHandler::TerrainClearanceFilter::update (double agl)
   // [PILOT] page 20 specifies that the terrain clearance is equal to
   // 75% of the radio altitude, averaged over the previous 15 seconds.
 
+  // no updates when simulation is paused (dt=0.0), and add 5 samples/second only 
+  if (globals->get_sim_time_sec() - last_update < 0.2)
+      return value;
+  last_update = globals->get_sim_time_sec();
+
   samples_type::iterator iter;
 
   // remove samples older than 15 seconds
@@ -1000,8 +1005,10 @@ MK_VIII::IOHandler::TerrainClearanceFilter::update (double agl)
   double new_value = 0;
   if (samples.size() > 0)
     {
+      // time consuming loop => queue limited to 75 samples
+      // (= 15seconds * 5samples/second)
       for (iter = samples.begin(); iter != samples.end(); iter++)
-       new_value += (*iter).value;
+        new_value += (*iter).value;
       new_value /= samples.size();
     }
   new_value *= 0.75;
@@ -1017,6 +1024,7 @@ MK_VIII::IOHandler::TerrainClearanceFilter::reset ()
 {
   samples.clear();
   value = 0;
+  last_update = -1.0;
 }
 
 MK_VIII::IOHandler::IOHandler (MK_VIII *device)
@@ -2272,7 +2280,7 @@ MK_VIII::VoicePlayer::get_sample (const char *name)
   SGSoundSample *sample = _sgr->find(refname.str());
   if (! sample)
     {
-      string filename = "Sounds/mk-viii" + string(name) + ".wav";
+      string filename = "Sounds/mk-viii/" + string(name) + ".wav";
       try
        {
          sample = new SGSoundSample(filename.c_str(), SGPath());
@@ -2868,6 +2876,7 @@ MK_VIII::AlertHandler::update ()
        {
          assert(altitude_callout_voice != NULL);
          mk->voice_player.play(altitude_callout_voice);
+         altitude_callout_voice = NULL;
        }
     }
   else if (select_voice_alerts(ALERT_MODE4_TOO_LOW_GEAR))
@@ -2955,7 +2964,6 @@ MK_VIII::AlertHandler::update ()
 
   old_alerts = voice_alerts;
   repeated_alerts = 0;
-  altitude_callout_voice = NULL;
 }
 
 void
@@ -2975,6 +2983,8 @@ MK_VIII::AlertHandler::unset_alerts (unsigned int _alerts)
 {
   alerts &= ~_alerts;
   repeated_alerts &= ~_alerts;
+  if (_alerts & ALERT_MODE6_ALTITUDE_CALLOUT)
+    altitude_callout_voice = NULL;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -3738,7 +3748,7 @@ MK_VIII::Mode4Handler::get_bias (double initial_bias, double min_agl)
       initial_bias = 0.0;
     while ((mk_data(radio_altitude).get() < min_agl - min_agl * initial_bias)&&
            (initial_bias < 1.0))
-    initial_bias += 0.2;
+      initial_bias += 0.2;
   }
 
   return initial_bias;
@@ -4835,7 +4845,7 @@ MK_VIII::TCFHandler::update ()
                  new_bias = 0.0;
                while ((*reference < initial_value - initial_value * new_bias)&&
                       (new_bias < 1.0))
-               new_bias += 0.2;
+                 new_bias += 0.2;
              }
 
              if (new_bias > bias)
index fe9f564fabebecd766bcc1d3c320a5af0fa35f73..594094cf88b68f20504c9bdf6cc0b8c6bc8182a3 100755 (executable)
@@ -1,4 +1,4 @@
-// mk_viii.cxx -- Honeywell MK VIII EGPWS emulation
+// mk_viii.hxx -- Honeywell MK VIII EGPWS emulation
 //
 // Written by Jean-Yves Lefort, started September 2005.
 //
@@ -635,6 +635,7 @@ public:
       typedef deque< Sample<double> > samples_type;
       samples_type             samples;
       double                   value;
+      double                   last_update;
 
     public:
       inline TerrainClearanceFilter ()