From 159cb4d2f916401329593cf7aaec1e6fc68d91ac Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 7 Nov 2014 12:17:15 +0100 Subject: [PATCH] another hack for windows timers, DSP load calculation --- libs/backends/dummy/dummy_audiobackend.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/backends/dummy/dummy_audiobackend.cc b/libs/backends/dummy/dummy_audiobackend.cc index a128e56437..7c2f101ae7 100644 --- a/libs/backends/dummy/dummy_audiobackend.cc +++ b/libs/backends/dummy/dummy_audiobackend.cc @@ -1167,17 +1167,24 @@ DummyAudioBackend::main_process_thread () } if (!_freewheeling) { + const int64_t nomial_time = 1e6 * _samples_per_period / _samplerate; clock2 = _x_get_monotonic_usec(); #ifdef PLATFORM_WINDOWS - // querying the performance counter can fail occasionally - if (clock1 < 0 || clock2 < 0) { + bool win_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 * nomial_time) { clock2 = clock1 = 0; + win_timers_ok = false; } #endif const int64_t elapsed_time = clock2 - clock1; - const int64_t nomial_time = 1e6 * _samples_per_period / _samplerate; #ifdef PLATFORM_WINDOWS - if (clock1 >= 0 && clock2 >= 0) + if (win_timers_ok) #endif { // low pass filter _dsp_load = _dsp_load + .05 * ((elapsed_time / (float) nomial_time) - _dsp_load) + 1e-12; @@ -1192,6 +1199,8 @@ DummyAudioBackend::main_process_thread () _dsp_load = 1.0f; Glib::usleep (100); // don't hog cpu } + + /* beginning of netx cycle */ clock1 = _x_get_monotonic_usec(); bool connections_changed = false;