From: Tim Mayberry Date: Mon, 14 Sep 2015 11:04:27 +0000 (+1000) Subject: Use ARDOUR::DSPLoadCalculator in DummyBackend X-Git-Tag: 4.3~358 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=faa38a0d29b9cd3887cd980f2084536c16b1f9b1;p=ardour.git Use ARDOUR::DSPLoadCalculator in DummyBackend --- diff --git a/libs/backends/dummy/dummy_audiobackend.cc b/libs/backends/dummy/dummy_audiobackend.cc index 7c45ad8186..f43d512513 100644 --- a/libs/backends/dummy/dummy_audiobackend.cc +++ b/libs/backends/dummy/dummy_audiobackend.cc @@ -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)); diff --git a/libs/backends/dummy/dummy_audiobackend.h b/libs/backends/dummy/dummy_audiobackend.h index 29baa235c1..b235d101ff 100644 --- a/libs/backends/dummy/dummy_audiobackend.h +++ b/libs/backends/dummy/dummy_audiobackend.h @@ -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;