From a60a97bf8deb9d17381dcaf59d63e56b6608d37f Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Sat, 10 Sep 2011 23:03:11 -0700 Subject: [PATCH] Only compute rms if normalise. --- src/modules/sox/filter_sox.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/modules/sox/filter_sox.c b/src/modules/sox/filter_sox.c index cc73d1f0..32860586 100644 --- a/src/modules/sox/filter_sox.c +++ b/src/modules/sox/filter_sox.c @@ -263,30 +263,27 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f st_sample_t *p = input_buffer; st_size_t isamp = *samples; st_size_t osamp = *samples; - double rms = 0; int j = *samples + 1; char *normalise = mlt_properties_get( filter_properties, "normalise" ); double normalised_gain = 1.0; - // Convert from interleaved - while( --j ) - { - // Compute rms amplitude while we are accessing each sample - rms += ( double )*p * ( double )*p; - p ++; - } - if ( normalise ) { int window = mlt_properties_get_int( filter_properties, "window" ); double *smooth_buffer = mlt_properties_get_data( filter_properties, "smooth_buffer", NULL ); double max_gain = mlt_properties_get_double( filter_properties, "max_gain" ); - + double rms = 0; + // Default the maximum gain factor to 20dBFS if ( max_gain == 0 ) max_gain = 10.0; - // Compute final rms amplitude + // Compute rms amplitude + while( --j ) + { + rms += ( double )*p * ( double )*p; + p ++; + } rms = sqrt( rms / *samples / ST_SSIZE_MIN / ST_SSIZE_MIN ); // The smoothing buffer prevents radical shifts in the gain level -- 2.39.5