From 08e18a0cb47d862aaa42909fe92e554350dfe302 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 11 Sep 2015 23:26:31 +1000 Subject: Move implementation for DSPLoadCalculator back into header It can be inline now that it is much simpler --- libs/ardour/ardour/dsp_load_calculator.h | 33 ++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'libs/ardour/ardour/dsp_load_calculator.h') diff --git a/libs/ardour/ardour/dsp_load_calculator.h b/libs/ardour/ardour/dsp_load_calculator.h index 42386e2cb0..1da9786d36 100644 --- a/libs/ardour/ardour/dsp_load_calculator.h +++ b/libs/ardour/ardour/dsp_load_calculator.h @@ -23,11 +23,9 @@ #include #include -#include "ardour/libardour_visibility.h" - namespace ARDOUR { -class LIBARDOUR_API DSPLoadCalculator { +class DSPLoadCalculator { public: DSPLoadCalculator() : m_max_time_us(0) @@ -50,7 +48,34 @@ public: m_start_timestamp_us = start_timestamp_us; } - void set_stop_timestamp_us(int64_t stop_timestamp_us); + void set_stop_timestamp_us(int64_t stop_timestamp_us) + { + m_stop_timestamp_us = stop_timestamp_us; + + /* 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 (m_start_timestamp_us < 0 || m_stop_timestamp_us < 0 || + m_start_timestamp_us > m_stop_timestamp_us || + elapsed_time_us() > max_timer_error()) { + return; + } + + if (elapsed_time_us() > m_max_time_us) { + m_dsp_load = 1.0f; + } else { + const float load = elapsed_time_us() / (float)m_max_time_us; + if (load > m_dsp_load) { + m_dsp_load = load; + } else { + const float alpha = 0.2f * (m_max_time_us * 1e-6f); + m_dsp_load = m_dsp_load + alpha * (load - m_dsp_load) + 1e-12; + } + } + } int64_t elapsed_time_us() { -- cgit v1.2.3