+ 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_us()) {
+ return;
+ }
+
+ const float load = (float) elapsed_time_us() / (float)m_max_time_us;
+ if (load > m_dsp_load || load > 1.0) {
+ m_dsp_load = load;
+ } else {
+ const float alpha = 0.2f * (m_max_time_us * 1e-6f);
+ m_dsp_load = std::min (1.f, m_dsp_load);
+ m_dsp_load += alpha * (load - m_dsp_load) + 1e-12;
+ }
+ }