/* * CINELERRA * Copyright (C) 2016-2020 William Morrow * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #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; }