X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fnormalize%2Ffilter_volume.c;h=3bc747ced4d46b811bb23707e284d55c009bbf80;hb=f4963a6aa07644399b273b5d2b1f9299c9047414;hp=c4822d1d9c51f1aadce015a31cd800f241fd2450;hpb=f00476101550ec7d8e863f6516aa83bc1b524570;p=melted diff --git a/src/modules/normalize/filter_volume.c b/src/modules/normalize/filter_volume.c index c4822d1..3bc747c 100644 --- a/src/modules/normalize/filter_volume.c +++ b/src/modules/normalize/filter_volume.c @@ -18,8 +18,7 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "filter_volume.h" - +#include #include #include @@ -31,7 +30,7 @@ #define MAX_CHANNELS 6 #define EPSILON 0.00001 -/* The normalise functions come from the normalize utility: +/* The following normalise functions come from the normalize utility: Copyright (C) 1999--2002 Chris Vaill */ #define samp_width 16 @@ -186,9 +185,6 @@ static int filter_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format if ( mlt_properties_get( properties, "volume.limiter" ) != NULL ) limiter_level = mlt_properties_get_double( properties, "volume.limiter" ); - // Restore the original get_audio - frame->get_audio = mlt_properties_get_data( properties, "volume.get_audio", NULL ); - // Get the producer's audio mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples ); // fprintf( stderr, "filter_volume: frequency %d\n", *frequency ); @@ -232,18 +228,22 @@ static int filter_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format gain = max_gain; // Initialise filter's previous gain value to prevent an inadvertant jump from 0 - if ( mlt_properties_get( filter_props, "previous_gain" ) == NULL ) - mlt_properties_set_double( filter_props, "previous_gain", gain ); + mlt_position last_position = mlt_properties_get_position( filter_props, "_last_position" ); + mlt_position current_position = mlt_frame_get_position( frame ); + if ( mlt_properties_get( filter_props, "_previous_gain" ) == NULL + || current_position != last_position + 1 ) + mlt_properties_set_double( filter_props, "_previous_gain", gain ); // Start the gain out at the previous - double previous_gain = mlt_properties_get_double( filter_props, "previous_gain" ); + double previous_gain = mlt_properties_get_double( filter_props, "_previous_gain" ); // Determine ramp increment double gain_step = ( gain - previous_gain ) / *samples; // fprintf( stderr, "filter_volume: previous gain %f current gain %f step %f\n", previous_gain, gain, gain_step ); // Save the current gain for the next iteration - mlt_properties_set_double( filter_props, "previous_gain", gain ); + mlt_properties_set_double( filter_props, "_previous_gain", gain ); + mlt_properties_set_position( filter_props, "_last_position", current_position ); // Ramp from the previous gain to the current gain = previous_gain; @@ -311,7 +311,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) // If there is an end adjust gain to the range if ( mlt_properties_get( filter_props, "end" ) != NULL ) - { + { // Determine the time position of this frame in the transition duration mlt_position in = mlt_filter_get_in( this ); mlt_position out = mlt_filter_get_out( this ); @@ -435,11 +435,8 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) // Put a filter reference onto the frame mlt_properties_set_data( properties, "filter_volume", this, 0, NULL, NULL ); - // Backup the original get_audio (it's still needed) - mlt_properties_set_data( properties, "volume.get_audio", frame->get_audio, 0, NULL, NULL ); - // Override the get_audio method - frame->get_audio = filter_get_audio; + mlt_frame_push_audio( frame, filter_get_audio ); return frame; } @@ -447,7 +444,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) /** Constructor for the filter. */ -mlt_filter filter_volume_init( char *arg ) +mlt_filter filter_volume_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); if ( this != NULL && mlt_filter_init( this, NULL ) == 0 )