From 9814d34ac62f9155e3ef75a8fd9ccbfdc056be97 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 1 May 2008 02:13:58 -0500 Subject: [PATCH] Make region normalization possible again. --- Timeline/Peaks.C | 28 ++++++++++------------------ Timeline/Peaks.H | 5 ++++- Timeline/Region.C | 7 ++++++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Timeline/Peaks.C b/Timeline/Peaks.C index 45de37a..31ffddd 100644 --- a/Timeline/Peaks.C +++ b/Timeline/Peaks.C @@ -331,27 +331,19 @@ Peaks::make_peaks ( int chunksize ) /** return normalization factor for range of samples from /start/ to /end/ (uses known peak data if possible */ -/* float */ -/* Peaks::normalization_factor( float fpp, nframes_t start, nframes_t end ) const */ -/* { */ -/* float s; */ +float +//Peaks::normalization_factor( float fpp, nframes_t start, nframes_t end ) const +Peak::normalization_factor( void ) const +{ + float s; -/* // fill_buffer( fpp, start, end ); */ + s = 1.0f / fabs( this->max ); -/* /\* if ( end - start < _peaks->chunksize * 4 ) *\/ */ -/* /\* fill_buffer( _clip->length() / 4, start, end ); *\/ */ -/* /\* else *\/ */ -/* /\* fill_buffer( _clip->length(), start, end ); *\/ */ + if ( s * this->min < -1.0 ) + s = 1.0f / fabs( this->min ); -/* Peak p = peak( start, end ); */ - -/* s = 1.0f / fabs( p.max ); */ - -/* if ( s * p.min < -1.0 ) */ -/* s = 1.0f / fabs( p.min ); */ - -/* return s; */ -/* } */ + return s; +} diff --git a/Timeline/Peaks.H b/Timeline/Peaks.H index ed0281f..1cf79f1 100644 --- a/Timeline/Peaks.H +++ b/Timeline/Peaks.H @@ -26,6 +26,9 @@ struct Peak { float min; float max; + + float normalization_factor ( void ) const; + }; class Audio_File; @@ -94,7 +97,7 @@ public: void downsample ( Peak *peaks, int s, int e, float *mhi, float *mlo ) const; void read ( int X, float *hi, float *lo ) const; bool open ( void ); - float normalization_factor( float fpp, nframes_t start, nframes_t end ) const; +// float normalization_factor( float fpp, nframes_t start, nframes_t end ) ; bool current ( void ) const; bool make_peaks ( int chunksize ); diff --git a/Timeline/Region.C b/Timeline/Region.C index e2b908f..0f80e5a 100644 --- a/Timeline/Region.C +++ b/Timeline/Region.C @@ -742,8 +742,13 @@ Region::normalize ( void ) printf( "normalize: start=%lu end=%lu\n", _r->start, _r->end ); /* FIXME: figure out a way to do this via the peak server */ -/* _scale = _clip->peaks( 0 )->normalization_factor( timeline->fpp(), _r->start, _r->end ); */ + int peaks, channels; + Peak *pbuf; + + if ( _clip->read_peaks( length(), _r->start, _r->end, &peaks, &pbuf, &channels ) && + peaks ) + _scale = pbuf->normalization_factor(); }