From 1b5459fe2b79c808b9f78b9c0042826f9f7fc207 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 17 Apr 2008 11:12:22 -0500 Subject: [PATCH] Don't waste time deinterleaving peaks. --- Timeline/Audio_File.C | 12 +++++++----- Timeline/Region.C | 20 +++++++++++--------- Timeline/Waveform.C | 8 ++++---- Timeline/Waveform.H | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Timeline/Audio_File.C b/Timeline/Audio_File.C index d821666..322c173 100644 --- a/Timeline/Audio_File.C +++ b/Timeline/Audio_File.C @@ -77,11 +77,13 @@ Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, P *pbuf = new Peak[ *peaks * *channels ]; - /* 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 ]; + 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 ]; */ return true; } diff --git a/Timeline/Region.C b/Timeline/Region.C index 0826b52..defe688 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -626,16 +626,18 @@ Region::draw ( void ) int ch = (h() - Fl::box_dh( box() )) / channels; + + /* scale it */ + for ( int j = peaks * channels; j--; ) + { + pbuf[ j ].min *= _scale; + pbuf[ j ].max *= _scale; + } + + for ( int i = 0; i < channels; ++i ) { - Peak *pb = pbuf + (peaks * i); - - /* scale it */ - for ( int j = peaks; j--; ) - { - pb[ j ].min *= _scale; - pb[ j ].max *= _scale; - } +// Peak *pb = pbuf + (peaks * i); /* int fw = timeline->ts_to_x( fade.length ); */ @@ -651,7 +653,7 @@ Region::draw ( void ) (y() + Fl::box_dy( box() )) + (i * ch), W, ch, - pb, peaks, + pbuf + i, peaks, channels, selected() ? fl_invert_color( _color ) : _color ); } diff --git a/Timeline/Waveform.C b/Timeline/Waveform.C index 1b0f439..6c3f51c 100644 --- a/Timeline/Waveform.C +++ b/Timeline/Waveform.C @@ -43,7 +43,7 @@ bool Waveform::logarithmic = true; /** draw a portion of /clip/'s waveform. coordinates are the portion to draw */ void Waveform::draw ( int X, int Y, int W, int H, - Peak *pbuf, int peaks, + Peak *pbuf, int peaks, int skip, Fl_Color color ) { fl_push_clip( X, Y, W, H ); @@ -62,7 +62,7 @@ Waveform::draw ( int X, int Y, int W, int H, if ( Waveform::fill ) { j = start; - for ( int x = X; x < X + W; ++x, ++j ) + for ( int x = X; x < X + W; ++x, j += skip ) { const Peak p = pbuf[ j ]; @@ -106,7 +106,7 @@ Waveform::draw ( int X, int Y, int W, int H, fl_begin_line(); j = start; - for ( int x = X; x < X + W; ++x, ++j ) + for ( int x = X; x < X + W; ++x, j += skip ) { const Peak p = pbuf[ j ]; @@ -118,7 +118,7 @@ Waveform::draw ( int X, int Y, int W, int H, fl_begin_line(); j = start; - for ( int x = X; x < X + W; ++x, ++j ) + for ( int x = X; x < X + W; ++x, j += skip ) { const Peak p = pbuf[ j ]; diff --git a/Timeline/Waveform.H b/Timeline/Waveform.H index f4ab3ee..2abe731 100644 --- a/Timeline/Waveform.H +++ b/Timeline/Waveform.H @@ -36,7 +36,7 @@ public: static bool logarithmic; static void draw ( int X, int Y, int W, int H, - Peak *pbuf, int peaks, + Peak *pbuf, int peaks, int skip, Fl_Color color ); };