1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Copyright (C) 2006,2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
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; version 2 of the License
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *****************************************************************************/
29 #include "lv2filter.h"
31 #define LOG_LEVEL LOG_LEVEL_ERROR
36 #define LV2_PORT_MONO_AUDIO_IN 0
37 #define LV2_PORT_MONO_AUDIO_OUT 1
38 #define LV2_MONO_AUDIO_PORT_COUNT 2
39 #define LV2_PORTS_COUNT_MONO (LV2_MONO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT)
41 #define LV2_PORT_LEFT_AUDIO_IN 0
42 #define LV2_PORT_RIGHT_AUDIO_IN 1
43 #define LV2_PORT_LEFT_AUDIO_OUT 2
44 #define LV2_PORT_RIGHT_AUDIO_OUT 3
45 #define LV2_STEREO_AUDIO_PORT_COUNT 4
46 #define LV2_PORTS_COUNT_STEREO (LV2_STEREO_AUDIO_PORT_COUNT + GLOBAL_PARAMETERS_COUNT + BANDS_COUNT * BAND_PARAMETERS_COUNT)
52 filter_handle filter_right
;
54 const float * audio_in
;
55 const float * audio_in_right
;
57 float * audio_out_right
;
58 const LV2_Feature
* const * host_features
;
62 lv2filter_instantiate(
63 const LV2_Descriptor
* descriptor
,
65 const char * bundle_path
,
66 const LV2_Feature
* const * host_features
)
68 struct lv2filter
* lv2filter_ptr
;
69 const LV2_Feature
* const * feature_ptr_ptr
;
71 LOG_DEBUG("lv2filter_create_plugin_instance() called.");
72 LOG_DEBUG("uri = \"%s\"", descriptor
->URI
);
73 LOG_DEBUG("sample_rate = %f", sample_rate
);
74 LOG_DEBUG("bundle_path = \"%s\"", bundle_path
);
76 feature_ptr_ptr
= host_features
;
77 while (*feature_ptr_ptr
)
79 LOG_DEBUG("Host feature <%s> detected", (*feature_ptr_ptr
)->URI
);
84 lv2filter_ptr
= malloc(sizeof(struct lv2filter
));
85 if (lv2filter_ptr
== NULL
)
90 if (strcmp(descriptor
->URI
, LV2FILTER_STEREO_URI
) == 0)
92 lv2filter_ptr
->stereo
= true;
94 else if (strcmp(descriptor
->URI
, LV2FILTER_MONO_URI
) == 0)
96 lv2filter_ptr
->stereo
= false;
101 goto fail_free_instance
;
104 lv2filter_ptr
->host_features
= host_features
;
106 lv2filter_ptr
->bundle_path
= strdup(bundle_path
);
107 if (lv2filter_ptr
->bundle_path
== NULL
)
109 goto fail_free_instance
;
112 if (!filter_create(sample_rate
, BANDS_COUNT
, &lv2filter_ptr
->filter
))
114 goto fail_free_bundle_path
;
117 if (lv2filter_ptr
->stereo
)
119 if (!filter_create(sample_rate
, BANDS_COUNT
, &lv2filter_ptr
->filter_right
))
121 goto fail_destroy_filter
;
125 return (LV2_Handle
)lv2filter_ptr
;
128 filter_destroy(lv2filter_ptr
->filter
);
130 fail_free_bundle_path
:
131 free(lv2filter_ptr
->bundle_path
);
140 #define lv2filter_ptr ((struct lv2filter *)instance)
142 /* The run() callback. This is the function that gets called by the host
143 when it wants to run the plugin. The parameter is the number of sample
144 frames to process. */
148 uint32_t samples_count
)
150 LOG_DEBUG("lv2filter_run");
152 lv2filter_ptr
->filter
,
153 lv2filter_ptr
->audio_in
,
154 lv2filter_ptr
->audio_out
,
157 if (lv2filter_ptr
->stereo
)
160 lv2filter_ptr
->filter_right
,
161 lv2filter_ptr
->audio_in_right
,
162 lv2filter_ptr
->audio_out_right
,
171 filter_destroy(lv2filter_ptr
->filter
);
173 if (lv2filter_ptr
->stereo
)
175 filter_destroy(lv2filter_ptr
->filter_right
);
178 free(lv2filter_ptr
->bundle_path
);
183 lv2filter_connect_port(
186 void * data_location
)
188 LOG_DEBUG("lv2filter_connect_port %u %p", (unsigned int)port
, data_location
);
190 if (lv2filter_ptr
->stereo
)
192 if (port
>= LV2_PORTS_COUNT_STEREO
)
198 if (port
== LV2_PORT_LEFT_AUDIO_IN
)
200 lv2filter_ptr
->audio_in
= data_location
;
202 else if (port
== LV2_PORT_LEFT_AUDIO_OUT
)
204 lv2filter_ptr
->audio_out
= data_location
;
206 else if (port
== LV2_PORT_RIGHT_AUDIO_IN
)
208 lv2filter_ptr
->audio_in_right
= data_location
;
210 else if (port
== LV2_PORT_RIGHT_AUDIO_OUT
)
212 lv2filter_ptr
->audio_out_right
= data_location
;
216 assert(port
>= LV2_STEREO_AUDIO_PORT_COUNT
);
217 port
-= LV2_STEREO_AUDIO_PORT_COUNT
;
218 if (port
< GLOBAL_PARAMETERS_COUNT
)
220 filter_connect_global_parameter(lv2filter_ptr
->filter
, port
, data_location
);
221 filter_connect_global_parameter(lv2filter_ptr
->filter_right
, port
, data_location
);
225 assert(port
>= GLOBAL_PARAMETERS_COUNT
);
226 port
-= GLOBAL_PARAMETERS_COUNT
;
228 filter_connect_band_parameter(lv2filter_ptr
->filter
, port
/ BANDS_COUNT
, port
% BANDS_COUNT
, data_location
);
229 filter_connect_band_parameter(lv2filter_ptr
->filter_right
, port
/ BANDS_COUNT
, port
% BANDS_COUNT
, data_location
);
235 if (port
>= LV2_PORTS_COUNT_MONO
)
241 if (port
== LV2_PORT_MONO_AUDIO_IN
)
243 lv2filter_ptr
->audio_in
= data_location
;
245 else if (port
== LV2_PORT_MONO_AUDIO_OUT
)
247 lv2filter_ptr
->audio_out
= data_location
;
251 port
-= LV2_MONO_AUDIO_PORT_COUNT
;
252 if (port
< GLOBAL_PARAMETERS_COUNT
)
254 filter_connect_global_parameter(lv2filter_ptr
->filter
, port
, data_location
);
258 port
-= GLOBAL_PARAMETERS_COUNT
;
260 filter_connect_band_parameter(lv2filter_ptr
->filter
, port
/ BANDS_COUNT
, port
% BANDS_COUNT
, data_location
);
267 lv2filter_extension_data(