2 * filter_ladspa.c -- filter audio through LADSPA plugins
3 * Copyright (C) 2004-2005 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 <framework/mlt_filter.h>
22 #include <framework/mlt_frame.h>
26 #include <sys/types.h>
32 #include "jack_rack.h"
34 #define BUFFER_LEN 10000
36 static jack_rack_t* initialise_jack_rack( mlt_properties properties, int channels )
38 jack_rack_t *jackrack = NULL;
39 char *resource = mlt_properties_get( properties, "resource" );
40 if ( !resource && mlt_properties_get( properties, "src" ) )
41 resource = mlt_properties_get( properties, "src" );
43 // Propogate these for the Jack processing callback
44 mlt_properties_set_int( properties, "channels", channels );
49 // Create JackRack without Jack client name so that it only uses LADSPA
50 jackrack = jack_rack_new( NULL, channels );
51 mlt_properties_set_data( properties, "jackrack", jackrack, 0,
52 (mlt_destructor) jack_rack_destroy, NULL );
53 jack_rack_open_file( jackrack, resource );
62 static int ladspa_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
64 // Get the filter service
65 mlt_filter filter = mlt_frame_pop_audio( frame );
67 // Get the filter properties
68 mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
70 // Get the producer's audio
71 *format = mlt_audio_float;
72 mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
74 // Initialise LADSPA if needed
75 jack_rack_t *jackrack = mlt_properties_get_data( filter_properties, "jackrack", NULL );
76 if ( jackrack == NULL )
78 sample_rate = *frequency; // global inside jack_rack
79 jackrack = initialise_jack_rack( filter_properties, *channels );
82 // Get the filter-specific properties
83 LADSPA_Data **input_buffers = mlt_pool_alloc( sizeof( LADSPA_Data* ) * *channels );
84 LADSPA_Data **output_buffers = mlt_pool_alloc( sizeof( LADSPA_Data* ) * *channels );
87 for ( i = 0; i < *channels; i++ )
89 input_buffers[i] = (LADSPA_Data*) *buffer + i * *samples;
90 output_buffers[i] = (LADSPA_Data*) *buffer + i * *samples;
93 // Do LADSPA processing
94 int error = jackrack && process_ladspa( jackrack->procinfo, *samples, input_buffers, output_buffers );
96 mlt_pool_release( input_buffers );
97 mlt_pool_release( output_buffers );
103 /** Filter processing.
106 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
108 if ( mlt_frame_is_test_audio( frame ) == 0 )
110 mlt_frame_push_audio( frame, this );
111 mlt_frame_push_audio( frame, ladspa_get_audio );
117 /** Constructor for the filter.
120 mlt_filter filter_ladspa_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
122 mlt_filter this = mlt_filter_new( );
125 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
126 this->process = filter_process;
127 mlt_properties_set( properties, "resource", arg );