2 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef ARDOUR_DSP_LOAD_CALCULATOR_H
20 #define ARDOUR_DSP_LOAD_CALCULATOR_H
26 #include <pbd/ringbuffer.h>
28 #include "ardour/libardour_visibility.h"
32 class LIBARDOUR_API DSPLoadCalculator {
36 , m_start_timestamp_us(0)
37 , m_stop_timestamp_us(0)
39 , m_value_history (max_value_history())
45 void set_max_time_us(uint64_t max_time_us) {
46 assert(max_time_us != 0);
47 m_max_time_us = max_time_us;
49 // Use average of last 1/4 second of values so responsiveness
50 // remains consistent independent of max time
51 uint32_t max_dsp_samples_per_qtr_second = (250000 / m_max_time_us);
53 std::min(max_value_history() - 1, max_dsp_samples_per_qtr_second);
55 m_value_history.reset();
59 int64_t get_max_time_us() const { return m_max_time_us; }
61 void set_start_timestamp_us(int64_t start_timestamp_us)
63 m_start_timestamp_us = start_timestamp_us;
66 void set_stop_timestamp_us(int64_t stop_timestamp_us);
68 int64_t elapsed_time_us()
70 return m_stop_timestamp_us - m_start_timestamp_us;
74 * @return a decimal value between 0.0 and 1.0 representing the percentage
75 * of time spent between start and stop in proportion to the max expected time
76 * in microseconds(us).
78 float get_dsp_load() const
80 if (m_dsp_load > m_max_time_us) {
83 if (m_dsp_load < 0.0f) {
89 static uint32_t max_value_history () { return 16; }
92 int64_t m_max_time_us;
93 int64_t m_start_timestamp_us;
94 int64_t m_stop_timestamp_us;
96 RingBuffer<float> m_value_history;
97 uint32_t m_num_values;
100 } // namespace ARDOUR
102 #endif // ARDOUR_DSP_LOAD_CALCULATOR_H