2 * filter_channelcopy.c -- copy one audio channel to another
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "filter_channelcopy.h"
23 #include <framework/mlt_frame.h>
27 #define __USE_ISOC99 1
33 static int filter_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
35 // Get the properties of the a frame
36 mlt_properties properties = mlt_frame_properties( frame );
38 int from = mlt_properties_get_int( properties, "channelcopy.from" );
39 int to = mlt_properties_get_int( properties, "channelcopy.to" );
41 // Restore the original get_audio
42 frame->get_audio = mlt_properties_get_data( properties, "channelcopy.get_audio", NULL );
44 // Get the producer's audio
45 mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
47 // Duplicate channels as necessary
49 int size = *channels * *samples * 2;
50 int16_t *new_buffer = mlt_pool_alloc( size );
52 mlt_properties_set_data( properties, "audio", new_buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
54 // Duplicate the existing channels
55 for ( i = 0; i < *samples; i++ )
57 for ( j = 0; j < *channels; j++ )
59 new_buffer[ ( i * *channels ) + j ] = (*buffer)[ ( i * *channels ) + ( j == to ? from : j ) ];
67 /** Filter processing.
70 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
72 mlt_properties properties = mlt_filter_properties( this );
73 mlt_properties frame_props = mlt_frame_properties( frame );
75 // Propogate the parameters
76 mlt_properties_set_int( frame_props, "channelcopy.to", mlt_properties_get_int( properties, "to" ) );
77 mlt_properties_set_int( frame_props, "channelcopy.from", mlt_properties_get_int( properties, "from" ) );
79 // Backup the original get_audio (it's still needed)
80 mlt_properties_set_data( frame_props, "channelcopy.get_audio", frame->get_audio, 0, NULL, NULL );
82 // Override the get_audio method
83 frame->get_audio = filter_get_audio;
88 /** Constructor for the filter.
91 mlt_filter filter_channelcopy_init( char *arg )
93 mlt_filter this = mlt_filter_new( );
96 this->process = filter_process;
98 mlt_properties_set_int( mlt_filter_properties( this ), "to", atoi( arg ) );
100 mlt_properties_set_int( mlt_filter_properties( this ), "to", 1 );