From bb0b511122dc6b47d2000d8497d16f99e24a4610 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 17 Feb 2008 17:29:09 -0600 Subject: [PATCH] Make make_peaks use Clip to access source. --- Peaks.C | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/Peaks.C b/Peaks.C index 7189d0b..ddf2c46 100644 --- a/Peaks.C +++ b/Peaks.C @@ -247,50 +247,29 @@ Peaks::make_peaks ( const char *filename, int chunksize ) if ( current( filename ) ) return true; - SNDFILE *in; - SF_INFO si; - - memset( &si, 0, sizeof( si ) ); - - in = sf_open( filename, SFM_READ, &si ); + if ( ! _clip->open() ) + return false; FILE *fp = fopen( peakname( filename ), "w" ); if ( fp == NULL ) { - sf_close( in ); - /* return fals */ + _clip->close(); return false; } /* write chunksize first */ fwrite( &chunksize, sizeof( int ), 1, fp ); - float *fbuf = new float[ chunksize ]; - size_t len; do { - /* read in a buffer */ - len = sf_read_float( in, fbuf, chunksize ); - Peak p; - p.max = -1.0; - p.min = 1.0; - - for ( int i = 0; i < len; ++i ) - { - if ( fbuf[i] > p.max ) - p.max = fbuf[i]; - if ( fbuf[i] < p.min ) - p.min = fbuf[i]; - } - + len = clip_read_peaks( &p, 1, chunksize ); fwrite( &p, sizeof( Peak ), 1, fp ); } - while ( len == chunksize ); + while ( len ); + + _clip->close(); fclose( fp ); - sf_close( in ); - - delete fbuf; }