]> git.sesse.net Git - mlt/commitdiff
Add filter channelswap.
authorDan Dennedy <dan@dennedy.org>
Mon, 16 Aug 2010 00:53:02 +0000 (17:53 -0700)
committerDan Dennedy <dan@dennedy.org>
Mon, 16 Aug 2010 00:53:02 +0000 (17:53 -0700)
It is a permutation of channelcopy that can be used from channelcopy as
well by setting swap=1.

src/modules/core/factory.c
src/modules/core/filter_channelcopy.c

index 2be9dc03fd9844dafb574823554792a19d00ef52..05df3f083bfe0c04ab80213bdc2655a4f966b1ac 100644 (file)
@@ -57,7 +57,8 @@ MLT_REPOSITORY
        MLT_REGISTER( filter_type, "audioconvert", filter_audioconvert_init );
        MLT_REGISTER( filter_type, "brightness", filter_brightness_init );
        MLT_REGISTER( filter_type, "channelcopy", filter_channelcopy_init );
-       MLT_REGISTER( filter_type, "crop", filter_crop_init );
+    MLT_REGISTER( filter_type, "channelswap", filter_channelcopy_init );
+    MLT_REGISTER( filter_type, "crop", filter_crop_init );
        MLT_REGISTER( filter_type, "data_feed", filter_data_feed_init );
        MLT_REGISTER( filter_type, "data_show", filter_data_show_init );
        MLT_REGISTER( filter_type, "gamma", filter_gamma_init );
index 6e31998fc4d6a8fc254e5f3113ecd442ac2959a6..02730495057e9b5f22125846748bd3910bb953b7 100644 (file)
@@ -39,6 +39,7 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
 
        int from = mlt_properties_get_int( properties, "channelcopy.from" );
        int to = mlt_properties_get_int( properties, "channelcopy.to" );
+       int swap = mlt_properties_get_int( properties, "channelcopy.swap" );
 
        // Get the producer's audio
        mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
@@ -50,23 +51,57 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
                {
                        int16_t *f = (int16_t*) *buffer + from;
                        int16_t *t = (int16_t*) *buffer + to;
+                       int16_t x;
                        int i;
-                       for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
-                               *t = *f;
+
+                       if ( swap )
+                               for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+                               {
+                                       x = *t;
+                                       *t = *f;
+                                       *f = x;
+                               }
+                       else
+                               for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+                                       *t = *f;
                        break;
                }
                case mlt_audio_s32:
                {
                        int32_t *f = (int32_t*) *buffer + from * *samples;
                        int32_t *t = (int32_t*) *buffer + to * *samples;
-                       memcpy( t, f, *samples * sizeof(int32_t) );
+
+                       if ( swap )
+                       {
+                               int32_t *x = malloc( *samples * sizeof(int32_t) );
+                               memcpy( x, t, *samples * sizeof(int32_t) );
+                               memcpy( t, f, *samples * sizeof(int32_t) );
+                               memcpy( f, x, *samples * sizeof(int32_t) );
+                               free( x );
+                       }
+                       else
+                       {
+                               memcpy( t, f, *samples * sizeof(int32_t) );
+                       }
                        break;
                }
                case mlt_audio_float:
                {
                        float *f = (float*) *buffer + from * *samples;
                        float *t = (float*) *buffer + to * *samples;
-                       memcpy( t, f, *samples * sizeof(float) );
+
+                       if ( swap )
+                       {
+                               float *x = malloc( *samples * sizeof(float) );
+                               memcpy( x, t, *samples * sizeof(float) );
+                               memcpy( t, f, *samples * sizeof(float) );
+                               memcpy( f, x, *samples * sizeof(float) );
+                               free( x );
+                       }
+                       else
+                       {
+                               memcpy( t, f, *samples * sizeof(float) );
+                       }
                        break;
                }
                default:
@@ -88,6 +123,7 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
        // Propogate the parameters
        mlt_properties_set_int( frame_props, "channelcopy.to", mlt_properties_get_int( properties, "to" ) );
        mlt_properties_set_int( frame_props, "channelcopy.from", mlt_properties_get_int( properties, "from" ) );
+       mlt_properties_set_int( frame_props, "channelcopy.swap", mlt_properties_get_int( properties, "swap" ) );
 
        // Override the get_audio method
        mlt_frame_push_audio( frame, this );
@@ -109,6 +145,8 @@ mlt_filter filter_channelcopy_init( mlt_profile profile, mlt_service_type type,
                        mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "to", atoi( arg ) );
                else
                        mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "to", 1 );
+               if ( strcmp(id, "channelswap") == 0 )
+                       mlt_properties_set_int( MLT_FILTER_PROPERTIES( this ), "swap", 1 );
        }
        return this;
 }