Optimize waveform drawing some.

This commit is contained in:
Jonathan Moore Liles 2008-04-17 11:46:44 -05:00
parent e86123de78
commit ed9a1aaf5b
2 changed files with 13 additions and 21 deletions

View File

@ -124,21 +124,19 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize
/* get the peak for each channel */ /* get the peak for each channel */
for ( int j = 0; j < channels; ++j ) for ( int j = 0; j < channels; ++j )
{ {
Peak &p = pk[ j ]; Peak *p = &pk[ j ];
p.min = 0; p->min = 0;
p.max = 0; p->max = 0;
const Peak *pb = pbuf + j; const Peak *pb = pbuf + j;
for ( int k = len * channels; k--; pb += channels ) for ( int k = len * channels; k--; pb += channels )
{ {
const Peak pp = *pb; if ( pb->max > p->max )
p->max = pb->max;
if ( pp.max > p.max ) if ( pb->min < p->min )
p.max = pp.max; p->min = pb->min;
if ( pp.min < p.min )
p.min = pp.min;
} }
} }

View File

@ -82,8 +82,8 @@ Waveform::draw ( int X, int Y, int W, int H,
else else
fl_color( color ); fl_color( color );
const int ty = mid + (halfheight * p.min); const int ty = mid + ( halfheight * p.min );
const int by = mid + (halfheight * p.max ); const int by = mid + ( halfheight * p.max );
fl_line( x, ty, x, by ); fl_line( x, ty, x, by );
/* if ( outline ) */ /* if ( outline ) */
@ -96,6 +96,8 @@ Waveform::draw ( int X, int Y, int W, int H,
} }
} }
const int ty = Y + halfheight;
if ( Waveform::outline ) if ( Waveform::outline )
{ {
@ -107,11 +109,7 @@ Waveform::draw ( int X, int Y, int W, int H,
j = start; j = start;
for ( int x = X; x < X + W; ++x, j += skip ) for ( int x = X; x < X + W; ++x, j += skip )
{ fl_vertex( x, ty + ( halfheight * pbuf[ j ].min ) );
const Peak p = pbuf[ j ];
fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.min ));
}
fl_end_line(); fl_end_line();
@ -119,11 +117,7 @@ Waveform::draw ( int X, int Y, int W, int H,
j = start; j = start;
for ( int x = X; x < X + W; ++x, j += skip ) for ( int x = X; x < X + W; ++x, j += skip )
{ fl_vertex( x, ty + ( halfheight * pbuf[ j ].max ) );
const Peak p = pbuf[ j ];
fl_vertex( x, Y + (H / 2) + ((float)H / 2 * p.max ));
}
fl_end_line(); fl_end_line();