From 72a203d18b5f2355d50f046ad3919fc690d1063c Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 16 Apr 2008 13:08:00 -0500 Subject: [PATCH] Fix a number of errors turned up by valgrind. Import new captures. --- Timeline/Audio_File.C | 5 +++++ Timeline/Audio_File.H | 4 +--- Timeline/Audio_File_SF.C | 6 +++--- Timeline/Peaks.C | 19 ++++++++++--------- Timeline/Record_DS.C | 11 +++++++++++ Timeline/Region.C | 5 +++++ Timeline/Waveform.C | 6 +++--- Timeline/dsp.C | 4 ---- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Timeline/Audio_File.C b/Timeline/Audio_File.C index 36e29bc..18539e3 100644 --- a/Timeline/Audio_File.C +++ b/Timeline/Audio_File.C @@ -22,6 +22,11 @@ map Audio_File::_open_files; +Audio_File::~Audio_File ( ) +{ + _open_files[ string( _filename ) ] = NULL; +} + /** attmpet to open any supported filetype */ Audio_File * Audio_File::from_file ( const char * filename ) diff --git a/Timeline/Audio_File.H b/Timeline/Audio_File.H index 77e940b..d065c9f 100644 --- a/Timeline/Audio_File.H +++ b/Timeline/Audio_File.H @@ -53,9 +53,7 @@ public: _length = _channels = 0; } - virtual ~Audio_File ( ) - { - } + virtual ~Audio_File ( ); static Audio_File *from_file ( const char *filename ); diff --git a/Timeline/Audio_File_SF.C b/Timeline/Audio_File_SF.C index 02c05cc..0c271a5 100644 --- a/Timeline/Audio_File_SF.C +++ b/Timeline/Audio_File_SF.C @@ -163,7 +163,7 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len ) for ( int i = channel; i < rlen * _channels; i += _channels ) *(buf++) = tmp[ i ]; - delete tmp; + delete[] tmp; } _current_read += rlen; @@ -177,13 +177,13 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end { assert( end > start ); - open(); +// open(); seek( start ); nframes_t len = read( buf, channel, end - start ); - close(); +// close(); return len; } diff --git a/Timeline/Peaks.C b/Timeline/Peaks.C index 8573b05..5378ffe 100644 --- a/Timeline/Peaks.C +++ b/Timeline/Peaks.C @@ -90,7 +90,7 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize } /* get chunk size of peak file */ - int pfchunksize; + int pfchunksize = 0; fread( &pfchunksize, sizeof( int ), 1, fp ); int channels = _clip->channels(); @@ -108,8 +108,7 @@ Peaks::read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize /* locate to start position */ fseek( fp, (s * channels / pfchunksize) * sizeof( Peak ), SEEK_CUR ); - size_t len; - + size_t len = 0; int i; for ( i = 0; i < npeaks; ++i ) @@ -195,12 +194,12 @@ Peaks::read_source_peaks ( Peak *peaks, int npeaks, int chunksize ) const int Peaks::read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, int chunksize ) const { - _clip->open(); +// _clip->open(); _clip->seek( s ); int i = read_source_peaks( peaks, npeaks, chunksize ); - _clip->close(); +// _clip->close(); return i; } @@ -318,14 +317,16 @@ Peaks::make_peaks ( int chunksize ) if ( current() ) return true; - if ( ! _clip->open() ) - return false; + _clip->seek( 0 ); + +/* if ( ! _clip->open() ) */ +/* return false; */ FILE *fp = fopen( peakname( filename ), "w" ); if ( fp == NULL ) { - _clip->close(); +// _clip->close(); return false; } @@ -343,7 +344,7 @@ Peaks::make_peaks ( int chunksize ) } while ( len ); - _clip->close(); +// _clip->close(); fclose( fp ); diff --git a/Timeline/Record_DS.C b/Timeline/Record_DS.C index 4e2cd1d..fed14e7 100644 --- a/Timeline/Record_DS.C +++ b/Timeline/Record_DS.C @@ -165,9 +165,20 @@ Record_DS::stop ( nframes_t frame ) shutdown(); /* FIXME: flush buffers here? */ + + char *name = strdup( _af->name() ); delete _af; _af = NULL; + Audio_File *af = Audio_File::from_file( name ); + + if ( ! af ) + printf( "impossible!\n" ); + + new Region( af, track(), _frame ); + + track()->redraw(); + _recording = false; printf( "recording finished\n" ); diff --git a/Timeline/Region.C b/Timeline/Region.C index a168483..28f103f 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -144,6 +144,9 @@ Region::Region ( Audio_File *c, Track *t, nframes_t o ) int sum = 0; const char *s = rindex( _clip->name(), '/' ); + if ( ! s ) + s = _clip->name(); + for ( int i = strlen( s ); i--; ) sum += s[ i ]; @@ -714,6 +717,8 @@ Region::Fade::apply ( sample_t *buf, Region::Fade::fade_dir_e dir, long start, n nframes_t n = e - i; + assert( i + n <= nframes ); + if ( dir == Fade::Out ) { fi = 1.0f - fi; diff --git a/Timeline/Waveform.C b/Timeline/Waveform.C index c279d8b..6535be9 100644 --- a/Timeline/Waveform.C +++ b/Timeline/Waveform.C @@ -60,7 +60,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 ) { const Peak p = pbuf[ j ]; @@ -104,7 +104,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 ) { const Peak p = pbuf[ j ]; @@ -116,7 +116,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 ) { const Peak p = pbuf[ j ]; diff --git a/Timeline/dsp.C b/Timeline/dsp.C index 0d48be2..6f4129e 100644 --- a/Timeline/dsp.C +++ b/Timeline/dsp.C @@ -55,8 +55,6 @@ buffer_mix_with_gain ( sample_t *dst, sample_t *src, nframes_t nframes, float g void buffer_interleave_one_channel ( sample_t *dst, sample_t *src, int channel, int channels, nframes_t nframes ) { - nframes *= channels; - dst += channel; while ( nframes-- ) @@ -69,8 +67,6 @@ buffer_interleave_one_channel ( sample_t *dst, sample_t *src, int channel, int c void buffer_interleave_one_channel_and_mix ( sample_t *dst, sample_t *src, int channel, int channels, nframes_t nframes ) { - nframes *= channels; - dst += channel; while ( nframes-- )