]> git.sesse.net Git - mlt/blobdiff - src/modules/normalize/filter_volume.c
Move rotoscoping filter into plusgpl module.
[mlt] / src / modules / normalize / filter_volume.c
index b9060ccab6e8e1151bdd2a7bad2b13cf35677bee..8b0ccd6059dde0db3ca81ad380eb30af33474441 100644 (file)
@@ -100,7 +100,7 @@ static inline double get_smoothed_data( double *buf, int count )
                        j++;
                }
        }
-       smoothed /= j;
+       if (j) smoothed /= j;
 //     fprintf( stderr, "smoothed over %d values, result %f\n", j, smoothed );
 
        return smoothed;
@@ -171,9 +171,6 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
        // Get the properties from the filter
        mlt_properties filter_props = MLT_FILTER_PROPERTIES( this );
 
-       // Get the properties of the a frame
-       mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
-
        // Get the frame's filter instance properties
        mlt_properties instance_props = mlt_frame_unique_properties( frame, MLT_FILTER_SERVICE( this ) );
 
@@ -293,7 +290,6 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
 
 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 {
-       mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
        mlt_properties filter_props = MLT_FILTER_PROPERTIES( this );
        mlt_properties instance_props = mlt_frame_unique_properties( frame, MLT_FILTER_SERVICE( this ) );
 
@@ -323,12 +319,6 @@ 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 );
-                               mlt_position time = mlt_frame_get_position( frame );
-                               double position = ( double )( time - in ) / ( double )( out - in + 1 );
-
                                double end = -1;
                                char *p = mlt_properties_get( filter_props, "end" );
                                if ( strcmp( p, "" ) != 0 )
@@ -344,7 +334,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
                                        end = fabs( end );
 
                                if ( end != -1 )
-                                       gain += ( end - gain ) * position;
+                                       gain += ( end - gain ) * mlt_filter_get_progress( this, frame );
                        }
                }
        }
@@ -423,12 +413,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 );
-                       mlt_position time = mlt_frame_get_position( frame );
-                       double position = ( double )( time - in ) / ( double )( out - in + 1 );
-                       amplitude *= position;
+                       amplitude *= mlt_filter_get_progress( this, frame );
                }
                mlt_properties_set_int( instance_props, "normalise", 1 );
                mlt_properties_set_double( instance_props, "amplitude", amplitude );
@@ -460,7 +445,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 
 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 );
+       mlt_filter this = calloc( 1, sizeof( struct mlt_filter_s ) );
        if ( this != NULL && mlt_filter_init( this, NULL ) == 0 )
        {
                mlt_properties properties = MLT_FILTER_PROPERTIES( this );