diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-09-10 11:44:39 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-09-10 12:12:56 +1000 |
commit | 8625362cac6fbec43f953e684c54eba46ad213c0 (patch) | |
tree | c494d872a6856c8d13fa9c6ee3aeb2b7b35535e9 /libs/ardour/ardour/dsp_load_calculator.h | |
parent | 09caf8336f4ec681668a940e7df00ec18b3fd836 (diff) |
Add DSPLoadCalculator class to libardour
This is similar to the class in the PortaudioBackend but uses an average of the
values if raw load is under 80%
Diffstat (limited to 'libs/ardour/ardour/dsp_load_calculator.h')
-rw-r--r-- | libs/ardour/ardour/dsp_load_calculator.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/libs/ardour/ardour/dsp_load_calculator.h b/libs/ardour/ardour/dsp_load_calculator.h new file mode 100644 index 0000000000..911f1e3f14 --- /dev/null +++ b/libs/ardour/ardour/dsp_load_calculator.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef ARDOUR_DSP_LOAD_CALCULATOR_H +#define ARDOUR_DSP_LOAD_CALCULATOR_H + +#include <stdint.h> +#include <cassert> +#include <algorithm> + +#include <pbd/ringbuffer.h> + +namespace ARDOUR { + +class DSPLoadCalculator { +public: + DSPLoadCalculator() + : m_max_time_us(0) + , m_start_timestamp_us(0) + , m_stop_timestamp_us(0) + , m_dsp_load(0) + , m_value_history (max_value_history()) + , m_num_values(0) + { + + } + + void set_max_time_us(uint64_t max_time_us) { + assert(m_max_time_us != 0); + m_max_time_us = max_time_us; + + // Use average of last 1/4 second of values so responsiveness + // remains consistent independent of max time + uint32_t max_dsp_samples_per_qtr_second = (250000 / m_max_time_us); + m_num_values = + std::min(max_value_history() - 1, max_dsp_samples_per_qtr_second); + + m_value_history.reset(); + } + + + uint64_t get_max_time_us() const { return m_max_time_us; } + + void set_start_timestamp_us(uint64_t start_timestamp_us) + { + m_start_timestamp_us = start_timestamp_us; + } + + void set_stop_timestamp_us(uint64_t stop_timestamp_us); + + uint64_t elapsed_time_us() + { + return m_stop_timestamp_us - m_start_timestamp_us; + } + + /** + * @return a decimal value between 0.0 and 1.0 representing the percentage + * of time spent between start and stop in proportion to the max expected time + * in microseconds(us). + */ + float get_dsp_load() const + { + if (m_dsp_load > m_max_time_us) { + return 1.0f; + } + if (m_dsp_load < 0.0f) { + return 0.0f; + } + return m_dsp_load; + } +private: // methods + static uint32_t max_value_history () { return 16; } + +private: // data + uint64_t m_max_time_us; + uint64_t m_start_timestamp_us; + uint64_t m_stop_timestamp_us; + float m_dsp_load; + RingBuffer<float> m_value_history; + uint32_t m_num_values; +}; + +} // namespace ARDOUR + +#endif // ARDOUR_DSP_LOAD_CALCULATOR_H |