1 #include <stdlib.h>
2 #include <string.h>
3 #ifndef WIN32
4 #include "config.h"
5 #endif
6
7 #ifdef ENABLE_NLS
8 #include <libintl.h>
9 #endif
10
11 #define _ISOC9X_SOURCE 1
12 #define _ISOC99_SOURCE 1
13 #define __USE_ISOC99 1
14 #define __USE_ISOC9X 1
15
16 #include <math.h>
17
18 #include "ladspa.h"
19
20 #ifdef WIN32
21 #define _WINDOWS_DLL_EXPORT_ __declspec(dllexport)
22 int bIsFirstTime = 1;
23 static void __attribute__((constructor)) swh_init(); // forward declaration
24 #else
25 #define _WINDOWS_DLL_EXPORT_
26 #endif
27
28 #line 9 "bandpass_a_iir_1893.xml"
29
30 #include "config.h"
31 #include "util/iir.h"
32
33 #define BANDPASS_A_IIR_CENTER 0
34 #define BANDPASS_A_IIR_WIDTH 1
35 #define BANDPASS_A_IIR_INPUT 2
36 #define BANDPASS_A_IIR_OUTPUT 3
37
38 static LADSPA_Descriptor *bandpass_a_iirDescriptor = NULL;
39
40 typedef struct {
41 LADSPA_Data *center;
42 LADSPA_Data *width;
43 LADSPA_Data *input;
44 LADSPA_Data *output;
45 iir_stage_t* gt;
46 iirf_t* iirf;
47 long sample_rate;
48 LADSPA_Data run_adding_gain;
49 } Bandpass_a_iir;
50
51 _WINDOWS_DLL_EXPORT_
ladspa_descriptor(unsigned long index)52 const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
53
54 #ifdef WIN32
55 if (bIsFirstTime) {
56 swh_init();
57 bIsFirstTime = 0;
58 }
59 #endif
60 switch (index) {
61 case 0:
62 return bandpass_a_iirDescriptor;
63 default:
64 return NULL;
65 }
66 }
67
activateBandpass_a_iir(LADSPA_Handle instance)68 static void activateBandpass_a_iir(LADSPA_Handle instance) {
69 Bandpass_a_iir *plugin_data = (Bandpass_a_iir *)instance;
70 iir_stage_t*gt = plugin_data->gt;
71 iirf_t*iirf = plugin_data->iirf;
72 long sample_rate = plugin_data->sample_rate;
73 #line 33 "bandpass_a_iir_1893.xml"
74
75 gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2);
76 iirf = init_iirf_t(gt);
77 calc_2polebandpass(iirf, gt, *(plugin_data->center), *(plugin_data->width), sample_rate);
78 plugin_data->gt = gt;
79 plugin_data->iirf = iirf;
80 plugin_data->sample_rate = sample_rate;
81
82 }
83
cleanupBandpass_a_iir(LADSPA_Handle instance)84 static void cleanupBandpass_a_iir(LADSPA_Handle instance) {
85 #line 39 "bandpass_a_iir_1893.xml"
86 Bandpass_a_iir *plugin_data = (Bandpass_a_iir *)instance;
87 free_iirf_t(plugin_data->iirf, plugin_data->gt);
88 free_iir_stage(plugin_data->gt);
89 free(instance);
90 }
91
connectPortBandpass_a_iir(LADSPA_Handle instance,unsigned long port,LADSPA_Data * data)92 static void connectPortBandpass_a_iir(
93 LADSPA_Handle instance,
94 unsigned long port,
95 LADSPA_Data *data) {
96 Bandpass_a_iir *plugin;
97
98 plugin = (Bandpass_a_iir *)instance;
99 switch (port) {
100 case BANDPASS_A_IIR_CENTER:
101 plugin->center = data;
102 break;
103 case BANDPASS_A_IIR_WIDTH:
104 plugin->width = data;
105 break;
106 case BANDPASS_A_IIR_INPUT:
107 plugin->input = data;
108 break;
109 case BANDPASS_A_IIR_OUTPUT:
110 plugin->output = data;
111 break;
112 }
113 }
114
instantiateBandpass_a_iir(const LADSPA_Descriptor * descriptor,unsigned long s_rate)115 static LADSPA_Handle instantiateBandpass_a_iir(
116 const LADSPA_Descriptor *descriptor,
117 unsigned long s_rate) {
118 Bandpass_a_iir *plugin_data = (Bandpass_a_iir *)calloc(1, sizeof(Bandpass_a_iir));
119 iir_stage_t*gt = NULL;
120 iirf_t*iirf = NULL;
121 long sample_rate;
122
123 #line 22 "bandpass_a_iir_1893.xml"
124 sample_rate = s_rate;
125
126 plugin_data->gt = gt;
127 plugin_data->iirf = iirf;
128 plugin_data->sample_rate = sample_rate;
129
130 return (LADSPA_Handle)plugin_data;
131 }
132
133 #undef buffer_write
134 #undef RUN_ADDING
135 #undef RUN_REPLACING
136
137 #define buffer_write(b, v) (b = v)
138 #define RUN_ADDING 0
139 #define RUN_REPLACING 1
140
runBandpass_a_iir(LADSPA_Handle instance,unsigned long sample_count)141 static void runBandpass_a_iir(LADSPA_Handle instance, unsigned long sample_count) {
142 Bandpass_a_iir *plugin_data = (Bandpass_a_iir *)instance;
143 LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
144
145 /* Center Frequency (Hz) (float value) */
146 const LADSPA_Data center = *(plugin_data->center);
147
148 /* Bandwidth (Hz) (float value) */
149 const LADSPA_Data width = *(plugin_data->width);
150
151 /* Input (array of floats of length sample_count) */
152 const LADSPA_Data * const input = plugin_data->input;
153
154 /* Output (array of floats of length sample_count) */
155 LADSPA_Data * const output = plugin_data->output;
156 iir_stage_t* gt = plugin_data->gt;
157 iirf_t* iirf = plugin_data->iirf;
158 long sample_rate = plugin_data->sample_rate;
159
160 #line 25 "bandpass_a_iir_1893.xml"
161 calc_2polebandpass(iirf, gt, center, width, sample_rate);
162 iir_process_buffer_1s_5(iirf, gt, input, output, sample_count,0);
163
164 // Unused variable
165 (void)(run_adding_gain);
166 }
167 #undef buffer_write
168 #undef RUN_ADDING
169 #undef RUN_REPLACING
170
171 #define buffer_write(b, v) (b += (v) * run_adding_gain)
172 #define RUN_ADDING 1
173 #define RUN_REPLACING 0
174
setRunAddingGainBandpass_a_iir(LADSPA_Handle instance,LADSPA_Data gain)175 static void setRunAddingGainBandpass_a_iir(LADSPA_Handle instance, LADSPA_Data gain) {
176 ((Bandpass_a_iir *)instance)->run_adding_gain = gain;
177 }
178
runAddingBandpass_a_iir(LADSPA_Handle instance,unsigned long sample_count)179 static void runAddingBandpass_a_iir(LADSPA_Handle instance, unsigned long sample_count) {
180 Bandpass_a_iir *plugin_data = (Bandpass_a_iir *)instance;
181 LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
182
183 /* Center Frequency (Hz) (float value) */
184 const LADSPA_Data center = *(plugin_data->center);
185
186 /* Bandwidth (Hz) (float value) */
187 const LADSPA_Data width = *(plugin_data->width);
188
189 /* Input (array of floats of length sample_count) */
190 const LADSPA_Data * const input = plugin_data->input;
191
192 /* Output (array of floats of length sample_count) */
193 LADSPA_Data * const output = plugin_data->output;
194 iir_stage_t* gt = plugin_data->gt;
195 iirf_t* iirf = plugin_data->iirf;
196 long sample_rate = plugin_data->sample_rate;
197
198 #line 25 "bandpass_a_iir_1893.xml"
199 calc_2polebandpass(iirf, gt, center, width, sample_rate);
200 iir_process_buffer_1s_5(iirf, gt, input, output, sample_count,0);
201
202 // Unused variable
203 (void)(run_adding_gain);
204 }
205
swh_init()206 static void __attribute__((constructor)) swh_init() {
207 char **port_names;
208 LADSPA_PortDescriptor *port_descriptors;
209 LADSPA_PortRangeHint *port_range_hints;
210
211 #ifdef ENABLE_NLS
212 #define D_(s) dgettext(PACKAGE, s)
213 bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
214 #else
215 #define D_(s) (s)
216 #endif
217
218
219 bandpass_a_iirDescriptor =
220 (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
221
222 if (bandpass_a_iirDescriptor) {
223 bandpass_a_iirDescriptor->UniqueID = 1893;
224 bandpass_a_iirDescriptor->Label = "bandpass_a_iir";
225 bandpass_a_iirDescriptor->Properties =
226 LADSPA_PROPERTY_HARD_RT_CAPABLE;
227 bandpass_a_iirDescriptor->Name =
228 D_("Glame Bandpass Analog Filter");
229 bandpass_a_iirDescriptor->Maker =
230 "Alexander Ehlert <mag@glame.de>";
231 bandpass_a_iirDescriptor->Copyright =
232 "GPL";
233 bandpass_a_iirDescriptor->PortCount = 4;
234
235 port_descriptors = (LADSPA_PortDescriptor *)calloc(4,
236 sizeof(LADSPA_PortDescriptor));
237 bandpass_a_iirDescriptor->PortDescriptors =
238 (const LADSPA_PortDescriptor *)port_descriptors;
239
240 port_range_hints = (LADSPA_PortRangeHint *)calloc(4,
241 sizeof(LADSPA_PortRangeHint));
242 bandpass_a_iirDescriptor->PortRangeHints =
243 (const LADSPA_PortRangeHint *)port_range_hints;
244
245 port_names = (char **)calloc(4, sizeof(char*));
246 bandpass_a_iirDescriptor->PortNames =
247 (const char **)port_names;
248
249 /* Parameters for Center Frequency (Hz) */
250 port_descriptors[BANDPASS_A_IIR_CENTER] =
251 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
252 port_names[BANDPASS_A_IIR_CENTER] =
253 D_("Center Frequency (Hz)");
254 port_range_hints[BANDPASS_A_IIR_CENTER].HintDescriptor =
255 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_LOGARITHMIC;
256 port_range_hints[BANDPASS_A_IIR_CENTER].LowerBound = 0.0001;
257 port_range_hints[BANDPASS_A_IIR_CENTER].UpperBound = 0.45;
258
259 /* Parameters for Bandwidth (Hz) */
260 port_descriptors[BANDPASS_A_IIR_WIDTH] =
261 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
262 port_names[BANDPASS_A_IIR_WIDTH] =
263 D_("Bandwidth (Hz)");
264 port_range_hints[BANDPASS_A_IIR_WIDTH].HintDescriptor =
265 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_LOGARITHMIC;
266 port_range_hints[BANDPASS_A_IIR_WIDTH].LowerBound = 0.0001;
267 port_range_hints[BANDPASS_A_IIR_WIDTH].UpperBound = 0.45;
268
269 /* Parameters for Input */
270 port_descriptors[BANDPASS_A_IIR_INPUT] =
271 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
272 port_names[BANDPASS_A_IIR_INPUT] =
273 D_("Input");
274 port_range_hints[BANDPASS_A_IIR_INPUT].HintDescriptor = 0;
275
276 /* Parameters for Output */
277 port_descriptors[BANDPASS_A_IIR_OUTPUT] =
278 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
279 port_names[BANDPASS_A_IIR_OUTPUT] =
280 D_("Output");
281 port_range_hints[BANDPASS_A_IIR_OUTPUT].HintDescriptor = 0;
282
283 bandpass_a_iirDescriptor->activate = activateBandpass_a_iir;
284 bandpass_a_iirDescriptor->cleanup = cleanupBandpass_a_iir;
285 bandpass_a_iirDescriptor->connect_port = connectPortBandpass_a_iir;
286 bandpass_a_iirDescriptor->deactivate = NULL;
287 bandpass_a_iirDescriptor->instantiate = instantiateBandpass_a_iir;
288 bandpass_a_iirDescriptor->run = runBandpass_a_iir;
289 bandpass_a_iirDescriptor->run_adding = runAddingBandpass_a_iir;
290 bandpass_a_iirDescriptor->set_run_adding_gain = setRunAddingGainBandpass_a_iir;
291 }
292 }
293
swh_fini()294 static void __attribute__((destructor)) swh_fini() {
295 if (bandpass_a_iirDescriptor) {
296 free((LADSPA_PortDescriptor *)bandpass_a_iirDescriptor->PortDescriptors);
297 free((char **)bandpass_a_iirDescriptor->PortNames);
298 free((LADSPA_PortRangeHint *)bandpass_a_iirDescriptor->PortRangeHints);
299 free(bandpass_a_iirDescriptor);
300 }
301 bandpass_a_iirDescriptor = NULL;
302
303 }
304