#include "meterhistory.h" #include #include MeterHistory::MeterHistory() { size = 0; channels = 0; current_peak = 0; samples = 0; values = 0; } MeterHistory::~MeterHistory() { init(0, 0); } void MeterHistory::init(int chs, int sz) { if( size != sz ) { delete [] samples; samples = 0; size = 0; } if( !samples && sz > 0 ) { samples = new int64_t[size = sz]; for( int i=0; i 0 ) { current_peak = new int[channels = chs]; for( int i=0; i= size ) peak_idx = 0; current_peak[ch] = peak_idx; } double MeterHistory::get_peak(int ch, int idx) { return idx>=0 ? values[ch][idx] : 0; } int MeterHistory::get_nearest(int64_t pos, int64_t tolerance) { int result = -1; if( size > 0 ) { int64_t best = tolerance; for( int i=0; i= tolerance || diff >= best ) continue; best = diff; result = i; } } return result; }