13
0

Use same algorithm as CA and ALSA backends in DSPLoadCalculation

Stop using an averaging of the values until we can establish whether it is
really necessary.
This commit is contained in:
Tim Mayberry 2015-09-11 23:07:01 +10:00
parent cf88bbc472
commit f5e7aa11f9
2 changed files with 8 additions and 64 deletions

View File

@ -23,8 +23,6 @@
#include <cassert>
#include <algorithm>
#include <pbd/ringbuffer.h>
#include "ardour/libardour_visibility.h"
namespace ARDOUR {
@ -36,8 +34,6 @@ public:
, m_start_timestamp_us(0)
, m_stop_timestamp_us(0)
, m_dsp_load(0)
, m_value_history (max_value_history())
, m_num_values(0)
{
}
@ -45,17 +41,8 @@ public:
void set_max_time_us(uint64_t max_time_us) {
assert(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();
}
int64_t get_max_time_us() const { return m_max_time_us; }
void set_start_timestamp_us(int64_t start_timestamp_us)
@ -85,9 +72,8 @@ public:
}
return m_dsp_load;
}
private: // methods
static uint32_t max_value_history () { return 16; }
private: // methods
int64_t max_timer_error () { return 4 * m_max_time_us; }
private: // data
@ -95,8 +81,6 @@ private: // data
int64_t m_start_timestamp_us;
int64_t m_stop_timestamp_us;
float m_dsp_load;
RingBuffer<float> m_value_history;
uint32_t m_num_values;
};
} // namespace ARDOUR

View File

@ -23,10 +23,6 @@ namespace ARDOUR {
void
DSPLoadCalculator::set_stop_timestamp_us(int64_t stop_timestamp_us)
{
// We could only bother with calculations if a certain amount of time
// has passed, or the Raw DSP value is > X% different than last calc
// which would mean consistent overhead for small values of m_max_time_us
m_stop_timestamp_us = stop_timestamp_us;
/* querying the performance counter can fail occasionally (-1).
@ -41,52 +37,16 @@ DSPLoadCalculator::set_stop_timestamp_us(int64_t stop_timestamp_us)
return;
}
float load = 0;
if (elapsed_time_us() > m_max_time_us) {
load = 1.0f;
m_dsp_load = 1.0f;
} else {
load = elapsed_time_us() / (float)m_max_time_us;
}
assert(m_value_history.write_space() >= 1);
// push raw load value onto history
m_value_history.write(&load, 1);
// if load is under 80% use an average of past values
if (elapsed_time_us() < ((m_max_time_us * 80) / 100)) {
RingBuffer<float>::rw_vector vec;
m_value_history.get_read_vector(&vec);
uint32_t values_read = 0;
float dsp_accumulator = 0.0f;
// iterate through the read vectors accumulating the dsp load
for (unsigned int i = 0; i < vec.len[0]; ++i) {
dsp_accumulator += vec.buf[0][i];
values_read++;
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;
}
for (unsigned int i = 0; i < vec.len[1]; ++i) {
dsp_accumulator += vec.buf[1][i];
values_read++;
}
load = dsp_accumulator / (float)values_read;
const float alpha = 0.2f * (m_max_time_us * 1e-6f);
m_dsp_load = m_dsp_load + alpha * (load - m_dsp_load) + 1e-12;
} else {
// Use raw load value otherwise 100% may never be indicated because of
// averaging/LPF etc
m_dsp_load = load;
}
if (m_value_history.read_space() >= m_num_values) {
// "remove" the oldest value
m_value_history.increment_read_idx(1);
}
}