From 6138b266a4a6d8c7ca668cbd2de4aa4f2ee4da59 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sat, 6 Jun 2009 15:59:48 +0300 Subject: [PATCH] Stereo plugin --- filter.ttl | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- lv2filter.c | 141 +++++++++++++++++++++++++----- lv2filter.h | 3 + lv2plugin.c | 10 ++- manifest.ttl | 6 ++ ui | 10 ++- 6 files changed, 425 insertions(+), 25 deletions(-) diff --git a/filter.ttl b/filter.ttl index f9a5fba..128fc20 100644 --- a/filter.ttl +++ b/filter.ttl @@ -19,7 +19,7 @@ foaf:homepage ; foaf:mbox ; ]; - doap:name "4-band parametric filter"; + doap:name "4-band parametric filter (Mono)"; doap:license ; uiext:ui ; @@ -272,3 +272,281 @@ lv2:portProperty epp:hasStrictBounds; ue:unit ue:db; ]. + + + a lv2:Plugin; + a lv2:FilterPlugin; + doap:maintainer [ + foaf:name "Nedko Arnaudov"; + foaf:homepage ; + foaf:mbox ; + ]; + doap:name "4-band parametric filter (Stereo)"; + doap:license ; + + uiext:ui ; + + lv2:port [ + a lv2:InputPort, lv2:AudioPort; + lv2:datatype lv2:float; + lv2:index 0; + lv2:symbol "in_left"; + lv2:name "left audio input"; + ], + + [ + a lv2:InputPort, lv2:AudioPort; + lv2:datatype lv2:float; + lv2:index 1; + lv2:symbol "in_right"; + lv2:name "Right audio input"; + ], + + [ + a lv2:OutputPort, lv2:AudioPort; + lv2:datatype lv2:float; + lv2:index 2; + lv2:symbol "out_left"; + lv2:name "Left audio output"; + ], + + [ + a lv2:OutputPort, lv2:AudioPort; + lv2:datatype lv2:float; + lv2:index 3; + lv2:symbol "out_right"; + lv2:name "Right audio output"; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 4; + lv2:symbol "active"; + lv2:name "Active"; + lv2:default 0.0; + lv2:minimum 0.0; + lv2:maximum 1.0; + lv2:portProperty lv2:toggled; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 5; + lv2:symbol "gain"; + lv2:name "Gain"; + lv2:default 0.0; + lv2:minimum -20.0; + lv2:maximum 20.0; + lv2:portProperty epp:hasStrictBounds; + ue:unit ue:db; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 6; + lv2:symbol "active1"; + lv2:name "Active1"; + lv2:default 0.0; + lv2:minimum 0.0; + lv2:maximum 1.0; + lv2:portProperty lv2:toggled; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 7; + lv2:symbol "freq1"; + lv2:name "Frequency 1"; + lv2:default 200.0; + lv2:minimum 20.0; + lv2:maximum 2000.0; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ue:unit ue:hz; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 8; + lv2:symbol "bandwidth1"; + lv2:name "Bandwidth 1"; + lv2:default 1.0; + lv2:minimum 0.125; + lv2:maximum 8.0; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 9; + lv2:symbol "gain1"; + lv2:name "Gain 1"; + lv2:default 0.0; + lv2:minimum -20.0; + lv2:maximum 20.0; + lv2:portProperty epp:hasStrictBounds; + ue:unit ue:db; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 10; + lv2:symbol "active2"; + lv2:name "Active 2"; + lv2:default 0.0; + lv2:minimum 0.0; + lv2:maximum 1.0; + lv2:portProperty lv2:toggled; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 11; + lv2:symbol "frequency2"; + lv2:name "Frequency 2"; + lv2:default 400; + lv2:minimum 40; + lv2:maximum 4000; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ue:unit ue:hz; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 12; + lv2:symbol "bandwidth2"; + lv2:name "Bandwidth 2"; + lv2:default 1.0; + lv2:minimum 0.125; + lv2:maximum 8.0; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 13; + lv2:symbol "gain2"; + lv2:name "Gain 2"; + lv2:default 0.0; + lv2:minimum -20.0; + lv2:maximum 20.0; + lv2:portProperty epp:hasStrictBounds; + ue:unit ue:db; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 14; + lv2:symbol "active3"; + lv2:name "Active 3"; + lv2:default 0.0; + lv2:minimum 0.0; + lv2:maximum 1.0; + lv2:portProperty lv2:toggled; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 15; + lv2:symbol "frequency3"; + lv2:name "Frequency 3"; + lv2:default 1000; + lv2:minimum 100; + lv2:maximum 10000; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ue:unit ue:hz; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 16; + lv2:symbol "bandwidth3"; + lv2:name "Bandwidth 3"; + lv2:default 1.0; + lv2:minimum 0.125; + lv2:maximum 8.0; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 17; + lv2:symbol "gain3"; + lv2:name "Gain 3"; + lv2:default 0.0; + lv2:minimum -20.0; + lv2:maximum 20.0; + lv2:portProperty epp:hasStrictBounds; + ue:unit ue:db; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 18; + lv2:symbol "active4"; + lv2:name "Active 4"; + lv2:default 0.0; + lv2:minimum 0.0; + lv2:maximum 1.0; + lv2:portProperty lv2:toggled; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 19; + lv2:symbol "frequency4"; + lv2:name "Frequency 4"; + lv2:default 2000; + lv2:minimum 200; + lv2:maximum 20000; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ue:unit ue:hz; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 20; + lv2:symbol "bandwidth4"; + lv2:name "Bandwidth 4"; + lv2:default 1.0; + lv2:minimum 0.125; + lv2:maximum 8.0; + lv2:portProperty epp:hasStrictBounds; + lv2:portProperty epp:logarithmic; + ], + + [ + a lv2:InputPort; + a lv2:ControlPort; + lv2:index 21; + lv2:symbol "gain4"; + lv2:name "Gain 4"; + lv2:default 0.0; + lv2:minimum -20.0; + lv2:maximum 20.0; + lv2:portProperty epp:hasStrictBounds; + ue:unit ue:db; + ]. diff --git a/lv2filter.c b/lv2filter.c index f9ba38b..dcfe30d 100644 --- a/lv2filter.c +++ b/lv2filter.c @@ -33,16 +33,28 @@ #define BANDS_COUNT 4 -#define LV2_PORT_AUDIO_IN 0 -#define LV2_PORT_AUDIO_OUT 1 -#define LV2_PORTS_COUNT (2 + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) +#define LV2_PORT_MONO_AUDIO_IN 0 +#define LV2_PORT_MONO_AUDIO_OUT 1 +#define LV2_MONO_AUDIO_PORT_COUNT 2 +#define LV2_PORTS_COUNT_MONO (LV2_MONO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) + +#define LV2_PORT_LEFT_AUDIO_IN 0 +#define LV2_PORT_RIGHT_AUDIO_IN 1 +#define LV2_PORT_LEFT_AUDIO_OUT 2 +#define LV2_PORT_RIGHT_AUDIO_OUT 3 +#define LV2_STEREO_AUDIO_PORT_COUNT 4 +#define LV2_PORTS_COUNT_STEREO (LV2_STEREO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT) struct lv2filter { + bool stereo; filter_handle filter; + filter_handle filter_right; char * bundle_path; const float * audio_in; + const float * audio_in_right; float * audio_out; + float * audio_out_right; const LV2_Feature * const * host_features; }; @@ -57,6 +69,7 @@ lv2filter_instantiate( const LV2_Feature * const * feature_ptr_ptr; LOG_DEBUG("lv2filter_create_plugin_instance() called."); + LOG_DEBUG("uri = \"%s\"", descriptor->URI); LOG_DEBUG("sample_rate = %f", sample_rate); LOG_DEBUG("bundle_path = \"%s\"", bundle_path); @@ -73,7 +86,21 @@ lv2filter_instantiate( { goto fail; } - + + if (strcmp(descriptor->URI, LV2FILTER_STEREO_URI) == 0) + { + lv2filter_ptr->stereo = true; + } + else if (strcmp(descriptor->URI, LV2FILTER_MONO_URI) == 0) + { + lv2filter_ptr->stereo = false; + } + else + { + assert(false); + goto fail_free_instance; + } + lv2filter_ptr->host_features = host_features; lv2filter_ptr->bundle_path = strdup(bundle_path); @@ -87,8 +114,19 @@ lv2filter_instantiate( goto fail_free_bundle_path; } + if (lv2filter_ptr->stereo) + { + if (!filter_create(sample_rate, BANDS_COUNT, &lv2filter_ptr->filter_right)) + { + goto fail_destroy_filter; + } + } + return (LV2_Handle)lv2filter_ptr; +fail_destroy_filter: + filter_destroy(lv2filter_ptr->filter); + fail_free_bundle_path: free(lv2filter_ptr->bundle_path); @@ -111,10 +149,19 @@ lv2filter_run( { LOG_DEBUG("lv2filter_run"); filter_run( - lv2filter_ptr->filter, + lv2filter_ptr->filter, lv2filter_ptr->audio_in, lv2filter_ptr->audio_out, samples_count); + + if (lv2filter_ptr->stereo) + { + filter_run( + lv2filter_ptr->filter_right, + lv2filter_ptr->audio_in_right, + lv2filter_ptr->audio_out_right, + samples_count); + } } void @@ -122,6 +169,12 @@ lv2filter_cleanup( LV2_Handle instance) { filter_destroy(lv2filter_ptr->filter); + + if (lv2filter_ptr->stereo) + { + filter_destroy(lv2filter_ptr->filter_right); + } + free(lv2filter_ptr->bundle_path); free(lv2filter_ptr); } @@ -134,32 +187,78 @@ lv2filter_connect_port( { LOG_DEBUG("lv2filter_connect_port %u %p", (unsigned int)port, data_location); - if (port >= LV2_PORTS_COUNT) + if (lv2filter_ptr->stereo) { - assert(0); - return; - } + if (port >= LV2_PORTS_COUNT_STEREO) + { + assert(0); + return; + } - if (port == LV2_PORT_AUDIO_IN) - { - lv2filter_ptr->audio_in = data_location; - } - else if (port == LV2_PORT_AUDIO_OUT) - { - lv2filter_ptr->audio_out = data_location; + if (port == LV2_PORT_LEFT_AUDIO_IN) + { + lv2filter_ptr->audio_in = data_location; + } + else if (port == LV2_PORT_LEFT_AUDIO_OUT) + { + lv2filter_ptr->audio_out = data_location; + } + else if (port == LV2_PORT_RIGHT_AUDIO_IN) + { + lv2filter_ptr->audio_in_right = data_location; + } + else if (port == LV2_PORT_RIGHT_AUDIO_OUT) + { + lv2filter_ptr->audio_out_right = data_location; + } + else + { + assert(port >= LV2_STEREO_AUDIO_PORT_COUNT); + port -= LV2_STEREO_AUDIO_PORT_COUNT; + if (port < GLOBAL_PARAMETERS_COUNT) + { + filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); + filter_connect_global_parameter(lv2filter_ptr->filter_right, port, data_location); + } + else + { + assert(port >= GLOBAL_PARAMETERS_COUNT); + port -= GLOBAL_PARAMETERS_COUNT; + + filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); + filter_connect_band_parameter(lv2filter_ptr->filter_right, port / BANDS_COUNT, port % BANDS_COUNT, data_location); + } + } } else { - port -= 2; - if (port < GLOBAL_PARAMETERS_COUNT) + if (port >= LV2_PORTS_COUNT_MONO) + { + assert(0); + return; + } + + if (port == LV2_PORT_MONO_AUDIO_IN) + { + lv2filter_ptr->audio_in = data_location; + } + else if (port == LV2_PORT_MONO_AUDIO_OUT) { - filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); + lv2filter_ptr->audio_out = data_location; } else { - port -= GLOBAL_PARAMETERS_COUNT; + port -= LV2_MONO_AUDIO_PORT_COUNT; + if (port < GLOBAL_PARAMETERS_COUNT) + { + filter_connect_global_parameter(lv2filter_ptr->filter, port, data_location); + } + else + { + port -= GLOBAL_PARAMETERS_COUNT; - filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); + filter_connect_band_parameter(lv2filter_ptr->filter, port / BANDS_COUNT, port % BANDS_COUNT, data_location); + } } } } diff --git a/lv2filter.h b/lv2filter.h index 028cb77..1dc4977 100644 --- a/lv2filter.h +++ b/lv2filter.h @@ -21,6 +21,9 @@ #ifndef LV2FILTER_H__6EC1E456_7DD7_4536_B8D3_F23BE4583A23__INCLUDED #define LV2FILTER_H__6EC1E456_7DD7_4536_B8D3_F23BE4583A23__INCLUDED +#define LV2FILTER_MONO_URI "http://nedko.aranaudov.org/soft/filter/1/mono" +#define LV2FILTER_STEREO_URI "http://nedko.aranaudov.org/soft/filter/1/stereo" + LV2_Handle lv2filter_instantiate( const LV2_Descriptor * descriptor, diff --git a/lv2plugin.c b/lv2plugin.c index df73426..6e34067 100644 --- a/lv2plugin.c +++ b/lv2plugin.c @@ -28,7 +28,15 @@ static LV2_Descriptor g_lv2_plugins[] = { { - .URI = "http://nedko.aranaudov.org/soft/filter/1/mono", + .URI = LV2FILTER_MONO_URI, + .instantiate = lv2filter_instantiate, + .connect_port = lv2filter_connect_port, + .run = lv2filter_run, + .cleanup = lv2filter_cleanup, + .extension_data = lv2filter_extension_data + }, + { + .URI = LV2FILTER_STEREO_URI, .instantiate = lv2filter_instantiate, .connect_port = lv2filter_connect_port, .run = lv2filter_run, diff --git a/manifest.ttl b/manifest.ttl index de6bbcc..0f4a814 100644 --- a/manifest.ttl +++ b/manifest.ttl @@ -6,3 +6,9 @@ a lv2:FilterPlugin; lv2:binary ; rdfs:seeAlso . + + + a lv2:Plugin; + a lv2:FilterPlugin; + lv2:binary ; + rdfs:seeAlso . diff --git a/ui b/ui index a4f406b..912ab28 100755 --- a/ui +++ b/ui @@ -699,6 +699,13 @@ class filter_ui(dssi_ui): def __init__(self, argv): dssi_ui.__init__(self, argv) + if self.plugin_uri == "http://nedko.aranaudov.org/soft/filter/1/mono": + self.port_base = 2 + elif self.plugin_uri == "http://nedko.aranaudov.org/soft/filter/1/stereo": + self.port_base = 4 + else: + return + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) #self.window.set_size_request(600, 400) self.window.set_title("%s (4-band parametric filter)" % self.human_id) @@ -743,8 +750,7 @@ class filter_ui(dssi_ui): freq_min = [ 20.0, 40.0, 100.0, 200.0] freq_max = [2000.0, 4000.0, 10000.0, 20000.0] - self.port_base = 2 - port_index = self.port_base + port_index = 2 for i in [0, 1, 2, 3]: band_frame = gtk.Frame("Band %d" % (i + 1)) -- 2.11.4.GIT