From e86123de78d47b567f1245f4dd24ea9107796daa Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 17 Apr 2008 11:30:20 -0500 Subject: [PATCH] Improve peak reading efficiency. --- Timeline/Audio_File.C | 10 +--------- Timeline/Peaks.C | 14 +++++++++----- Timeline/Region.C | 3 --- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Timeline/Audio_File.C b/Timeline/Audio_File.C index 322c173..5f7005d 100644 --- a/Timeline/Audio_File.C +++ b/Timeline/Audio_File.C @@ -75,15 +75,7 @@ Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, P *channels = this->channels(); - *pbuf = new Peak[ *peaks * *channels ]; - - memcpy( *pbuf, pk.peakbuf(), *peaks * *channels * sizeof( Peak ) ); - -/* /\* deintereave peaks *\/ */ -/* int k = 0; */ -/* for ( int i = 0; i < *channels; i++ ) */ -/* for ( int j = i; j < *peaks * *channels; j += *channels ) */ -/* (*pbuf)[ k++ ] = pk.peakbuf()[ j ]; */ + *pbuf = pk.peakbuf(); return true; } diff --git a/Timeline/Peaks.C b/Timeline/Peaks.C index b43e848..841e916 100644 --- a/Timeline/Peaks.C +++ b/Timeline/Peaks.C @@ -129,12 +129,16 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize p.min = 0; p.max = 0; - for ( int k = j; k < len * channels; k += channels ) + const Peak *pb = pbuf + j; + + for ( int k = len * channels; k--; pb += channels ) { - if ( pbuf[ k ].max > p.max ) - p.max = pbuf[ k ].max; - if ( pbuf[ k ].min < p.min ) - p.min = pbuf[ k ].min; + const Peak pp = *pb; + + if ( pp.max > p.max ) + p.max = pp.max; + if ( pp.min < p.min ) + p.min = pp.min; } } diff --git a/Timeline/Region.C b/Timeline/Region.C index defe688..068ede8 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -656,9 +656,6 @@ Region::draw ( void ) pbuf + i, peaks, channels, selected() ? fl_invert_color( _color ) : _color ); } - - delete[] pbuf; - } timeline->draw_measure_lines( rx, Y, rw, H, _box_color );