Use ARDOUR::DSPLoadCalculator in DummyBackend
authorTim Mayberry <mojofunk@gmail.com>
Mon, 14 Sep 2015 11:04:27 +0000 (21:04 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Wed, 16 Sep 2015 01:22:17 +0000 (11:22 +1000)
libs/backends/dummy/dummy_audiobackend.cc
libs/backends/dummy/dummy_audiobackend.h

index 7c45ad818687116c62cd56b3223df116f3e6f830..f43d51251368292917d21a0ef2bb9e73ed1eec91 100644 (file)
@@ -447,6 +447,8 @@ DummyAudioBackend::_start (bool /*for_latency_measurement*/)
        engine.sample_rate_change (_samplerate);
        engine.buffer_size_change (_samples_per_period);
 
+       _dsp_load_calc.set_max_time (_samplerate, _samples_per_period);
+
        if (engine.reestablish_ports ()) {
                PBD::error << _("DummyAudioBackend: Could not re-establish ports.") << endmsg;
                stop ();
@@ -1213,7 +1215,7 @@ DummyAudioBackend::main_process_thread ()
        manager.registration_callback();
        manager.graph_order_callback();
 
-       int64_t clock1, clock2;
+       int64_t clock1;
        clock1 = -1;
        while (_running) {
 
@@ -1264,35 +1266,12 @@ DummyAudioBackend::main_process_thread ()
                }
 
                if (!_freewheel) {
-                       const int64_t nominal_time = 1e6 * _samples_per_period / _samplerate;
-                       clock2 = _x_get_monotonic_usec();
-                       bool timers_ok = true;
-
-                       /* querying the performance counter can fail occasionally (-1).
-                        * Also on some multi-core systems, timers are CPU specific and not
-                        * synchronized. We assume they differ more than a few milliseconds
-                        * (4 * nominal cycle time) and simply ignore cases where the
-                        * execution switches cores.
-                        */
-                       if (clock1 < 0 || clock2 < 0 || (clock1 > clock2) || (clock2 - clock1) > 4 * nominal_time) {
-                               clock1 = 0;
-                               clock2 = nominal_time;
-                               timers_ok = false;
-                       }
-
-                       const int64_t elapsed_time = clock2 - clock1;
-
-                       if (timers_ok)
-                       { // low pass filter
-                               const float load = elapsed_time / (float) nominal_time;
-                               if (load > _dsp_load) {
-                                       _dsp_load = load;
-                               } else {
-                                       const float a = .2 * _samples_per_period / _samplerate;
-                                       _dsp_load = _dsp_load + a * (load - _dsp_load) + 1e-12;
-                               }
-                       }
+                       _dsp_load_calc.set_start_timestamp_us (clock1);
+                       _dsp_load_calc.set_stop_timestamp_us (_x_get_monotonic_usec());
+                       _dsp_load = _dsp_load_calc.get_dsp_load ();
 
+                       const int64_t elapsed_time = _dsp_load_calc.elapsed_time_us ();
+                       const int64_t nominal_time = _dsp_load_calc.get_max_time_us ();
                        if (elapsed_time < nominal_time) {
                                const int64_t sleepy = _speedup * (nominal_time - elapsed_time);
                                Glib::usleep (std::max ((int64_t) 100, sleepy));
index 29baa235c11885647aa842948d444223ac2dc45b..b235d101ffb9657c2c96945aa857c8042683c444 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "ardour/types.h"
 #include "ardour/audio_backend.h"
+#include "ardour/dsp_load_calculator.h"
 
 namespace ARDOUR {
 
@@ -401,6 +402,7 @@ class DummyAudioBackend : public AudioBackend {
                float  _samplerate;
                size_t _samples_per_period;
                float  _dsp_load;
+               DSPLoadCalculator _dsp_load_calc;
                static size_t _max_buffer_size;
 
                uint32_t _n_inputs;