1 /*                                                     -*- linux-c -*-
2     Copyright (C) 2004 Tom Szilagyi
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18     $Id: tap_eqbw.c,v 1.6 2009/08/17 11:16:19 tszilagyi Exp $
19 */
20 
21 
22 /* This plugin is identical to TAP Equalizer (2141), but it has
23  * separate user controls for setting the bandwidth of every filter.
24  */
25 
26 #include <stdlib.h>
27 #include <string.h>
28 #include <math.h>
29 
30 #include "ladspa.h"
31 #include "tap_utils.h"
32 
33 /* The Unique ID of the plugin */
34 #define ID_MONO        2151
35 
36 
37 /* Default bandwidth of EQ filters in octaves */
38 #define BWIDTH        1.0f
39 
40 
41 /* Port numbers */
42 
43 #define EQ_CH0G                     0
44 #define EQ_CH1G                     1
45 #define EQ_CH2G                     2
46 #define EQ_CH3G                     3
47 #define EQ_CH4G                     4
48 #define EQ_CH5G                     5
49 #define EQ_CH6G                     6
50 #define EQ_CH7G                     7
51 
52 #define EQ_CH0F                     8
53 #define EQ_CH1F                     9
54 #define EQ_CH2F                     10
55 #define EQ_CH3F                     11
56 #define EQ_CH4F                     12
57 #define EQ_CH5F                     13
58 #define EQ_CH6F                     14
59 #define EQ_CH7F                     15
60 
61 #define EQ_CH0B                     16
62 #define EQ_CH1B                     17
63 #define EQ_CH2B                     18
64 #define EQ_CH3B                     19
65 #define EQ_CH4B                     20
66 #define EQ_CH5B                     21
67 #define EQ_CH6B                     22
68 #define EQ_CH7B                     23
69 
70 #define EQ_INPUT                    24
71 #define EQ_OUTPUT                   25
72 
73 
74 /* Total number of ports */
75 #define PORTCOUNT_MONO  26
76 
77 
78 static LADSPA_Descriptor *eqDescriptor = NULL;
79 
80 typedef struct {
81 	LADSPA_Data *ch0f;
82 	LADSPA_Data *ch0g;
83 	LADSPA_Data *ch0b;
84 	LADSPA_Data *ch1f;
85 	LADSPA_Data *ch1g;
86 	LADSPA_Data *ch1b;
87 	LADSPA_Data *ch2f;
88 	LADSPA_Data *ch2g;
89 	LADSPA_Data *ch2b;
90 	LADSPA_Data *ch3f;
91 	LADSPA_Data *ch3g;
92 	LADSPA_Data *ch3b;
93 	LADSPA_Data *ch4f;
94 	LADSPA_Data *ch4g;
95 	LADSPA_Data *ch4b;
96 	LADSPA_Data *ch5f;
97 	LADSPA_Data *ch5g;
98 	LADSPA_Data *ch5b;
99 	LADSPA_Data *ch6f;
100 	LADSPA_Data *ch6g;
101 	LADSPA_Data *ch6b;
102 	LADSPA_Data *ch7f;
103 	LADSPA_Data *ch7g;
104 	LADSPA_Data *ch7b;
105 	LADSPA_Data *input;
106 	LADSPA_Data *output;
107 	biquad *     filters;
108 	float        fs;
109 	LADSPA_Data old_ch0f;
110 	LADSPA_Data old_ch0g;
111 	LADSPA_Data old_ch0b;
112 	LADSPA_Data old_ch1f;
113 	LADSPA_Data old_ch1g;
114 	LADSPA_Data old_ch1b;
115 	LADSPA_Data old_ch2f;
116 	LADSPA_Data old_ch2g;
117 	LADSPA_Data old_ch2b;
118 	LADSPA_Data old_ch3f;
119 	LADSPA_Data old_ch3g;
120 	LADSPA_Data old_ch3b;
121 	LADSPA_Data old_ch4f;
122 	LADSPA_Data old_ch4g;
123 	LADSPA_Data old_ch4b;
124 	LADSPA_Data old_ch5f;
125 	LADSPA_Data old_ch5g;
126 	LADSPA_Data old_ch5b;
127 	LADSPA_Data old_ch6f;
128 	LADSPA_Data old_ch6g;
129 	LADSPA_Data old_ch6b;
130 	LADSPA_Data old_ch7f;
131 	LADSPA_Data old_ch7g;
132 	LADSPA_Data old_ch7b;
133 
134 	LADSPA_Data run_adding_gain;
135 } eq;
136 
137 const
138 LADSPA_Descriptor *
ladspa_descriptor(unsigned long index)139 ladspa_descriptor(unsigned long index) {
140 
141 	switch (index) {
142 	case 0:
143 		return eqDescriptor;
144 	default:
145 	        return NULL;
146 	}
147 }
148 
149 static
150 void
activate_eq(LADSPA_Handle instance)151 activate_eq(LADSPA_Handle instance) {
152 
153 	eq *ptr = (eq *)instance;
154 	biquad *filters = ptr->filters;
155 
156 	biquad_init(&filters[0]);
157 	biquad_init(&filters[1]);
158 	biquad_init(&filters[2]);
159 	biquad_init(&filters[3]);
160 	biquad_init(&filters[4]);
161 	biquad_init(&filters[5]);
162 	biquad_init(&filters[6]);
163 	biquad_init(&filters[7]);
164 }
165 
166 
167 static
168 void
cleanup_eq(LADSPA_Handle instance)169 cleanup_eq(LADSPA_Handle instance) {
170 
171 	free(instance);
172 }
173 
174 
175 static
176 void
connectPort_eq(LADSPA_Handle instance,unsigned long port,LADSPA_Data * data)177 connectPort_eq(LADSPA_Handle instance, unsigned long port, LADSPA_Data *data) {
178 
179 	eq *plugin;
180 
181 	plugin = (eq *)instance;
182 	switch (port) {
183 	case EQ_CH0F:
184 		plugin->ch0f = data;
185 		break;
186 	case EQ_CH0G:
187 		plugin->ch0g = data;
188 		break;
189 	case EQ_CH0B:
190 		plugin->ch0b = data;
191 		break;
192 	case EQ_CH1F:
193 		plugin->ch1f = data;
194 		break;
195 	case EQ_CH1G:
196 		plugin->ch1g = data;
197 		break;
198 	case EQ_CH1B:
199 		plugin->ch1b = data;
200 		break;
201 	case EQ_CH2F:
202 		plugin->ch2f = data;
203 		break;
204 	case EQ_CH2G:
205 		plugin->ch2g = data;
206 		break;
207 	case EQ_CH2B:
208 		plugin->ch2b = data;
209 		break;
210 	case EQ_CH3F:
211 		plugin->ch3f = data;
212 		break;
213 	case EQ_CH3G:
214 		plugin->ch3g = data;
215 		break;
216 	case EQ_CH3B:
217 		plugin->ch3b = data;
218 		break;
219 	case EQ_CH4F:
220 		plugin->ch4f = data;
221 		break;
222 	case EQ_CH4G:
223 		plugin->ch4g = data;
224 		break;
225 	case EQ_CH4B:
226 		plugin->ch4b = data;
227 		break;
228 	case EQ_CH5F:
229 		plugin->ch5f = data;
230 		break;
231 	case EQ_CH5G:
232 		plugin->ch5g = data;
233 		break;
234 	case EQ_CH5B:
235 		plugin->ch5b = data;
236 		break;
237 	case EQ_CH6F:
238 		plugin->ch6f = data;
239 		break;
240 	case EQ_CH6G:
241 		plugin->ch6g = data;
242 		break;
243 	case EQ_CH6B:
244 		plugin->ch6b = data;
245 		break;
246 	case EQ_CH7F:
247 		plugin->ch7f = data;
248 		break;
249 	case EQ_CH7G:
250 		plugin->ch7g = data;
251 		break;
252 	case EQ_CH7B:
253 		plugin->ch7b = data;
254 		break;
255 	case EQ_INPUT:
256 		plugin->input = data;
257 		break;
258 	case EQ_OUTPUT:
259 		plugin->output = data;
260 		break;
261 	}
262 }
263 
264 static
265 LADSPA_Handle
instantiate_eq(const LADSPA_Descriptor * descriptor,unsigned long s_rate)266 instantiate_eq(const LADSPA_Descriptor *descriptor, unsigned long s_rate) {
267 
268 	eq *ptr = (eq *)malloc(sizeof(eq));
269 	biquad *filters = NULL;
270 	float fs;
271 
272 	fs = s_rate;
273 
274 	memset(ptr, 0, sizeof(eq));
275 
276 	filters = calloc(8, sizeof(biquad));
277 
278 	ptr->filters = filters;
279 	ptr->fs = fs;
280 	ptr->run_adding_gain = 1.0f;
281 
282 	ptr->old_ch0f = 100.0f;
283 	ptr->old_ch0g = 0.0f;
284 	ptr->old_ch0b = BWIDTH;
285 
286 	ptr->old_ch1f = 200.0f;
287 	ptr->old_ch1g = 0.0f;
288 	ptr->old_ch1b = BWIDTH;
289 
290 	ptr->old_ch2f = 400.0f;
291 	ptr->old_ch2g = 0.0f;
292 	ptr->old_ch2b = BWIDTH;
293 
294 	ptr->old_ch3f = 1000.0f;
295 	ptr->old_ch3g = 0.0f;
296 	ptr->old_ch3b = BWIDTH;
297 
298 	ptr->old_ch4f = 3000.0f;
299 	ptr->old_ch4g = 0.0f;
300 	ptr->old_ch4b = BWIDTH;
301 
302 	ptr->old_ch5f = 6000.0f;
303 	ptr->old_ch5g = 0.0f;
304 	ptr->old_ch5b = BWIDTH;
305 
306 	ptr->old_ch6f = 12000.0f;
307 	ptr->old_ch6g = 0.0f;
308 	ptr->old_ch6b = BWIDTH;
309 
310 	ptr->old_ch7f = 15000.0f;
311 	ptr->old_ch7g = 0.0f;
312 	ptr->old_ch7b = BWIDTH;
313 
314 	eq_set_params(&filters[0], 100.0f, 0.0f, BWIDTH, fs);
315 	eq_set_params(&filters[1], 200.0f, 0.0f, BWIDTH, fs);
316 	eq_set_params(&filters[2], 400.0f, 0.0f, BWIDTH, fs);
317 	eq_set_params(&filters[3], 1000.0f, 0.0f, BWIDTH, fs);
318 	eq_set_params(&filters[4], 3000.0f, 0.0f, BWIDTH, fs);
319 	eq_set_params(&filters[5], 6000.0f, 0.0f, BWIDTH, fs);
320 	eq_set_params(&filters[6], 12000.0f, 0.0f, BWIDTH, fs);
321 	eq_set_params(&filters[7], 15000.0f, 0.0f, BWIDTH, fs);
322 
323 	return (LADSPA_Handle)ptr;
324 }
325 
326 
327 static
328 void
run_eq(LADSPA_Handle instance,unsigned long sample_count)329 run_eq(LADSPA_Handle instance, unsigned long sample_count) {
330 
331 	eq * ptr = (eq *)instance;
332 
333 	const LADSPA_Data ch0f = LIMIT(*(ptr->ch0f),40.0f,280.0f);
334 	const LADSPA_Data ch0g = LIMIT(*(ptr->ch0g),-50.0f,20.0f);
335 	const LADSPA_Data ch0b = LIMIT(*(ptr->ch0b),0.1f,5.0f);
336 	const LADSPA_Data ch1f = LIMIT(*(ptr->ch1f),100.0f,500.0f);
337 	const LADSPA_Data ch1g = LIMIT(*(ptr->ch1g),-50.0f,20.0f);
338 	const LADSPA_Data ch1b = LIMIT(*(ptr->ch1b),0.1f,5.0f);
339 	const LADSPA_Data ch2f = LIMIT(*(ptr->ch2f),200.0f,1000.0f);
340 	const LADSPA_Data ch2g = LIMIT(*(ptr->ch2g),-50.0f,20.0f);
341 	const LADSPA_Data ch2b = LIMIT(*(ptr->ch2b),0.1f,5.0f);
342 	const LADSPA_Data ch3f = LIMIT(*(ptr->ch3f),400.0f,2800.0f);
343 	const LADSPA_Data ch3g = LIMIT(*(ptr->ch3g),-50.0f,20.0f);
344 	const LADSPA_Data ch3b = LIMIT(*(ptr->ch3b),0.1f,5.0f);
345 	const LADSPA_Data ch4f = LIMIT(*(ptr->ch4f),1000.0f,5000.0f);
346 	const LADSPA_Data ch4g = LIMIT(*(ptr->ch4g),-50.0f,20.0f);
347 	const LADSPA_Data ch4b = LIMIT(*(ptr->ch4b),0.1f,5.0f);
348 	const LADSPA_Data ch5f = LIMIT(*(ptr->ch5f),3000.0f,9000.0f);
349 	const LADSPA_Data ch5g = LIMIT(*(ptr->ch5g),-50.0f,20.0f);
350 	const LADSPA_Data ch5b = LIMIT(*(ptr->ch5b),0.1f,5.0f);
351 	const LADSPA_Data ch6f = LIMIT(*(ptr->ch6f),6000.0f,18000.0f);
352 	const LADSPA_Data ch6g = LIMIT(*(ptr->ch6g),-50.0f,20.0f);
353 	const LADSPA_Data ch6b = LIMIT(*(ptr->ch6b),0.1f,5.0f);
354 	const LADSPA_Data ch7f = LIMIT(*(ptr->ch7f),10000.0f,20000.0f);
355 	const LADSPA_Data ch7g = LIMIT(*(ptr->ch7g),-50.0f,20.0f);
356 	const LADSPA_Data ch7b = LIMIT(*(ptr->ch7b),0.1f,5.0f);
357 
358 	const LADSPA_Data * input = ptr->input;
359 	LADSPA_Data * output = ptr->output;
360 
361 	biquad * filters = ptr->filters;
362 	float fs = ptr->fs;
363 
364 	unsigned long pos;
365 	float samp;
366 
367 
368 	if ((ch0f != ptr->old_ch0f) ||
369 	    (ch0g != ptr->old_ch0g) ||
370 	    (ch0b != ptr->old_ch0b)) {
371 		ptr->old_ch0f = ch0f;
372 		ptr->old_ch0g = ch0g;
373 		ptr->old_ch0b = ch0b;
374 		eq_set_params(&filters[0], ch0f, ch0g, ch0b, fs);
375 	}
376 	if ((ch1f != ptr->old_ch1f) ||
377 	    (ch1g != ptr->old_ch1g) ||
378 	    (ch1b != ptr->old_ch1b)) {
379 		ptr->old_ch1f = ch1f;
380 		ptr->old_ch1g = ch1g;
381 		ptr->old_ch1b = ch1b;
382 		eq_set_params(&filters[1], ch1f, ch1g, ch1b, fs);
383 	}
384 	if ((ch2f != ptr->old_ch2f) ||
385 	    (ch2g != ptr->old_ch2g) ||
386 	    (ch2b != ptr->old_ch2b)) {
387 		ptr->old_ch2f = ch2f;
388 		ptr->old_ch2g = ch2g;
389 		ptr->old_ch2b = ch2b;
390 		eq_set_params(&filters[2], ch2f, ch2g, ch2b, fs);
391 	}
392 	if ((ch3f != ptr->old_ch3f) ||
393 	    (ch3g != ptr->old_ch3g) ||
394 	    (ch3b != ptr->old_ch3b)) {
395 		ptr->old_ch3f = ch3f;
396 		ptr->old_ch3g = ch3g;
397 		ptr->old_ch3b = ch3b;
398 		eq_set_params(&filters[3], ch3f, ch3g, ch3b, fs);
399 	}
400 	if ((ch4f != ptr->old_ch4f) ||
401 	    (ch4g != ptr->old_ch4g) ||
402 	    (ch4b != ptr->old_ch4b)) {
403 		ptr->old_ch4f = ch4f;
404 		ptr->old_ch4g = ch4g;
405 		ptr->old_ch4b = ch4b;
406 		eq_set_params(&filters[4], ch4f, ch4g, ch4b, fs);
407 	}
408 	if ((ch5f != ptr->old_ch5f) ||
409 	    (ch5g != ptr->old_ch5g) ||
410 	    (ch5b != ptr->old_ch5b)) {
411 		ptr->old_ch5f = ch5f;
412 		ptr->old_ch5g = ch5g;
413 		ptr->old_ch5b = ch5b;
414 		eq_set_params(&filters[5], ch5f, ch5g, ch5b, fs);
415 	}
416 	if ((ch6f != ptr->old_ch6f) ||
417 	    (ch6g != ptr->old_ch6g) ||
418 	    (ch6b != ptr->old_ch6b)) {
419 		ptr->old_ch6f = ch6f;
420 		ptr->old_ch6g = ch6g;
421 		ptr->old_ch6b = ch6b;
422 		eq_set_params(&filters[6], ch6f, ch6g, ch6b, fs);
423 	}
424 	if ((ch7f != ptr->old_ch7f) ||
425 	    (ch7g != ptr->old_ch7g) ||
426 	    (ch7b != ptr->old_ch7b)) {
427 		ptr->old_ch7f = ch7f;
428 		ptr->old_ch7g = ch7g;
429 		ptr->old_ch7b = ch7b;
430 		eq_set_params(&filters[7], ch7f, ch7g, ch7b, fs);
431 	}
432 
433 	for (pos = 0; pos < sample_count; pos++) {
434 		samp = input[pos];
435 		if (ch0g != 0.0f)
436 			samp = biquad_run(&filters[0], samp);
437 		if (ch1g != 0.0f)
438 			samp = biquad_run(&filters[1], samp);
439 		if (ch2g != 0.0f)
440 			samp = biquad_run(&filters[2], samp);
441 		if (ch3g != 0.0f)
442 			samp = biquad_run(&filters[3], samp);
443 		if (ch4g != 0.0f)
444 			samp = biquad_run(&filters[4], samp);
445 		if (ch5g != 0.0f)
446 			samp = biquad_run(&filters[5], samp);
447 		if (ch6g != 0.0f)
448 			samp = biquad_run(&filters[6], samp);
449 		if (ch7g != 0.0f)
450 			samp = biquad_run(&filters[7], samp);
451 		output[pos] = samp;
452 	}
453 }
454 
455 
456 
457 void
set_run_adding_gain(LADSPA_Handle instance,LADSPA_Data gain)458 set_run_adding_gain(LADSPA_Handle instance, LADSPA_Data gain) {
459 
460 	eq * ptr = (eq *)instance;
461 
462 	ptr->run_adding_gain = gain;
463 }
464 
465 
466 
467 static
468 void
run_adding_eq(LADSPA_Handle instance,unsigned long sample_count)469 run_adding_eq(LADSPA_Handle instance, unsigned long sample_count) {
470 
471 	eq * ptr = (eq *)instance;
472 
473 	const LADSPA_Data ch0f = LIMIT(*(ptr->ch0f),40.0f,280.0f);
474 	const LADSPA_Data ch0g = LIMIT(*(ptr->ch0g),-50.0f,20.0f);
475 	const LADSPA_Data ch0b = LIMIT(*(ptr->ch0b),0.1f,5.0f);
476 	const LADSPA_Data ch1f = LIMIT(*(ptr->ch1f),100.0f,500.0f);
477 	const LADSPA_Data ch1g = LIMIT(*(ptr->ch1g),-50.0f,20.0f);
478 	const LADSPA_Data ch1b = LIMIT(*(ptr->ch1b),0.1f,5.0f);
479 	const LADSPA_Data ch2f = LIMIT(*(ptr->ch2f),200.0f,1000.0f);
480 	const LADSPA_Data ch2g = LIMIT(*(ptr->ch2g),-50.0f,20.0f);
481 	const LADSPA_Data ch2b = LIMIT(*(ptr->ch2b),0.1f,5.0f);
482 	const LADSPA_Data ch3f = LIMIT(*(ptr->ch3f),400.0f,2800.0f);
483 	const LADSPA_Data ch3g = LIMIT(*(ptr->ch3g),-50.0f,20.0f);
484 	const LADSPA_Data ch3b = LIMIT(*(ptr->ch3b),0.1f,5.0f);
485 	const LADSPA_Data ch4f = LIMIT(*(ptr->ch4f),1000.0f,5000.0f);
486 	const LADSPA_Data ch4g = LIMIT(*(ptr->ch4g),-50.0f,20.0f);
487 	const LADSPA_Data ch4b = LIMIT(*(ptr->ch4b),0.1f,5.0f);
488 	const LADSPA_Data ch5f = LIMIT(*(ptr->ch5f),3000.0f,9000.0f);
489 	const LADSPA_Data ch5g = LIMIT(*(ptr->ch5g),-50.0f,20.0f);
490 	const LADSPA_Data ch5b = LIMIT(*(ptr->ch5b),0.1f,5.0f);
491 	const LADSPA_Data ch6f = LIMIT(*(ptr->ch6f),6000.0f,18000.0f);
492 	const LADSPA_Data ch6g = LIMIT(*(ptr->ch6g),-50.0f,20.0f);
493 	const LADSPA_Data ch6b = LIMIT(*(ptr->ch6b),0.1f,5.0f);
494 	const LADSPA_Data ch7f = LIMIT(*(ptr->ch7f),10000.0f,20000.0f);
495 	const LADSPA_Data ch7g = LIMIT(*(ptr->ch7g),-50.0f,20.0f);
496 	const LADSPA_Data ch7b = LIMIT(*(ptr->ch7b),0.1f,5.0f);
497 
498 	const LADSPA_Data * input = ptr->input;
499 	LADSPA_Data * output = ptr->output;
500 
501 	biquad * filters = ptr->filters;
502 	float fs = ptr->fs;
503 
504 	unsigned long pos;
505 	float samp;
506 
507 
508 	if ((ch0f != ptr->old_ch0f) ||
509 	    (ch0g != ptr->old_ch0g) ||
510 	    (ch0b != ptr->old_ch0b)) {
511 		ptr->old_ch0f = ch0f;
512 		ptr->old_ch0g = ch0g;
513 		ptr->old_ch0b = ch0b;
514 		eq_set_params(&filters[0], ch0f, ch0g, ch0b, fs);
515 	}
516 	if ((ch1f != ptr->old_ch1f) ||
517 	    (ch1g != ptr->old_ch1g) ||
518 	    (ch1b != ptr->old_ch1b)) {
519 		ptr->old_ch1f = ch1f;
520 		ptr->old_ch1g = ch1g;
521 		ptr->old_ch1b = ch1b;
522 		eq_set_params(&filters[1], ch1f, ch1g, ch1b, fs);
523 	}
524 	if ((ch2f != ptr->old_ch2f) ||
525 	    (ch2g != ptr->old_ch2g) ||
526 	    (ch2b != ptr->old_ch2b)) {
527 		ptr->old_ch2f = ch2f;
528 		ptr->old_ch2g = ch2g;
529 		ptr->old_ch2b = ch2b;
530 		eq_set_params(&filters[2], ch2f, ch2g, ch2b, fs);
531 	}
532 	if ((ch3f != ptr->old_ch3f) ||
533 	    (ch3g != ptr->old_ch3g) ||
534 	    (ch3b != ptr->old_ch3b)) {
535 		ptr->old_ch3f = ch3f;
536 		ptr->old_ch3g = ch3g;
537 		ptr->old_ch3b = ch3b;
538 		eq_set_params(&filters[3], ch3f, ch3g, ch3b, fs);
539 	}
540 	if ((ch4f != ptr->old_ch4f) ||
541 	    (ch4g != ptr->old_ch4g) ||
542 	    (ch4b != ptr->old_ch4b)) {
543 		ptr->old_ch4f = ch4f;
544 		ptr->old_ch4g = ch4g;
545 		ptr->old_ch4b = ch4b;
546 		eq_set_params(&filters[4], ch4f, ch4g, ch4b, fs);
547 	}
548 	if ((ch5f != ptr->old_ch5f) ||
549 	    (ch5g != ptr->old_ch5g) ||
550 	    (ch5b != ptr->old_ch5b)) {
551 		ptr->old_ch5f = ch5f;
552 		ptr->old_ch5g = ch5g;
553 		ptr->old_ch5b = ch5b;
554 		eq_set_params(&filters[5], ch5f, ch5g, ch5b, fs);
555 	}
556 	if ((ch6f != ptr->old_ch6f) ||
557 	    (ch6g != ptr->old_ch6g) ||
558 	    (ch6b != ptr->old_ch6b)) {
559 		ptr->old_ch6f = ch6f;
560 		ptr->old_ch6g = ch6g;
561 		ptr->old_ch6b = ch6b;
562 		eq_set_params(&filters[6], ch6f, ch6g, ch6b, fs);
563 	}
564 	if ((ch7f != ptr->old_ch7f) ||
565 	    (ch7g != ptr->old_ch7g) ||
566 	    (ch7b != ptr->old_ch7b)) {
567 		ptr->old_ch7f = ch7f;
568 		ptr->old_ch7g = ch7g;
569 		ptr->old_ch7b = ch7b;
570 		eq_set_params(&filters[7], ch7f, ch7g, ch7b, fs);
571 	}
572 
573 	for (pos = 0; pos < sample_count; pos++) {
574 		samp = input[pos];
575 		if (ch0g != 0.0f)
576 			samp = biquad_run(&filters[0], samp);
577 		if (ch1g != 0.0f)
578 			samp = biquad_run(&filters[1], samp);
579 		if (ch2g != 0.0f)
580 			samp = biquad_run(&filters[2], samp);
581 		if (ch3g != 0.0f)
582 			samp = biquad_run(&filters[3], samp);
583 		if (ch4g != 0.0f)
584 			samp = biquad_run(&filters[4], samp);
585 		if (ch5g != 0.0f)
586 			samp = biquad_run(&filters[5], samp);
587 		if (ch6g != 0.0f)
588 			samp = biquad_run(&filters[6], samp);
589 		if (ch7g != 0.0f)
590 			samp = biquad_run(&filters[7], samp);
591 		output[pos] += ptr->run_adding_gain * samp;
592 	}
593 }
594 
595 
596 
597 
598 void
_init()599 _init() {
600 
601 	char **port_names;
602 	LADSPA_PortDescriptor *port_descriptors;
603 	LADSPA_PortRangeHint *port_range_hints;
604 
605 	eqDescriptor =
606 	 (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
607 
608 	if (eqDescriptor) {
609 		eqDescriptor->UniqueID = ID_MONO;
610 		eqDescriptor->Label = "tap_equalizer_bw";
611 		eqDescriptor->Properties = 0;
612 		eqDescriptor->Name = "TAP Equalizer/BW";
613 		eqDescriptor->Maker = "Tom Szilagyi";
614 		eqDescriptor->Copyright = "GPL";
615 		eqDescriptor->PortCount = PORTCOUNT_MONO;
616 
617 		port_descriptors =
618 			(LADSPA_PortDescriptor *)calloc(PORTCOUNT_MONO,
619 			 sizeof(LADSPA_PortDescriptor));
620 		eqDescriptor->PortDescriptors =
621 			(const LADSPA_PortDescriptor *)port_descriptors;
622 
623 		port_range_hints =
624 			(LADSPA_PortRangeHint *)calloc(PORTCOUNT_MONO,
625 			 sizeof(LADSPA_PortRangeHint));
626 		eqDescriptor->PortRangeHints =
627 			(const LADSPA_PortRangeHint *)port_range_hints;
628 
629 		port_names = (char **)calloc(PORTCOUNT_MONO, sizeof(char*));
630 		eqDescriptor->PortNames =
631 			(const char **)port_names;
632 
633 
634 
635 		/* Parameters for CH0 freq [Hz] */
636 		port_descriptors[EQ_CH0F] =
637 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
638 		port_names[EQ_CH0F] =
639 		 "Band 1 Freq [Hz]";
640 		port_range_hints[EQ_CH0F].HintDescriptor =
641 			LADSPA_HINT_BOUNDED_BELOW |
642 			LADSPA_HINT_BOUNDED_ABOVE |
643 			LADSPA_HINT_DEFAULT_LOW;
644 		port_range_hints[EQ_CH0F].LowerBound = 40;
645 		port_range_hints[EQ_CH0F].UpperBound = 280;
646 		/* Parameters for CH0 gain [dB] */
647 		port_descriptors[EQ_CH0G] =
648 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
649 		port_names[EQ_CH0G] =
650 		 "Band 1 Gain [dB]";
651 		port_range_hints[EQ_CH0G].HintDescriptor =
652 			LADSPA_HINT_BOUNDED_BELOW |
653 			LADSPA_HINT_BOUNDED_ABOVE |
654 			LADSPA_HINT_DEFAULT_0;
655 		port_range_hints[EQ_CH0G].LowerBound = -50;
656 		port_range_hints[EQ_CH0G].UpperBound = +20;
657 		/* Parameters for CH0 bandwidth [octaves] */
658 		port_descriptors[EQ_CH0B] =
659 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
660 		port_names[EQ_CH0B] =
661 		 "Band 1 Bandwidth [octaves]";
662 		port_range_hints[EQ_CH0B].HintDescriptor =
663 			LADSPA_HINT_BOUNDED_BELOW |
664 			LADSPA_HINT_BOUNDED_ABOVE |
665 			LADSPA_HINT_DEFAULT_1;
666 		port_range_hints[EQ_CH0B].LowerBound = 0.1f;
667 		port_range_hints[EQ_CH0B].UpperBound = 5.0f;
668 
669 
670 
671 
672 		/* Parameters for CH1 freq [Hz] */
673 		port_descriptors[EQ_CH1F] =
674 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
675 		port_names[EQ_CH1F] =
676 		 "Band 2 Freq [Hz]";
677 		port_range_hints[EQ_CH1F].HintDescriptor =
678 			LADSPA_HINT_BOUNDED_BELOW |
679 			LADSPA_HINT_BOUNDED_ABOVE |
680 			LADSPA_HINT_DEFAULT_LOW;
681 		port_range_hints[EQ_CH1F].LowerBound = 100;
682 		port_range_hints[EQ_CH1F].UpperBound = 500;
683 		/* Parameters for CH1 gain [dB] */
684 		port_descriptors[EQ_CH1G] =
685 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
686 		port_names[EQ_CH1G] =
687 		 "Band 2 Gain [dB]";
688 		port_range_hints[EQ_CH1G].HintDescriptor =
689 			LADSPA_HINT_BOUNDED_BELOW |
690 			LADSPA_HINT_BOUNDED_ABOVE |
691 			LADSPA_HINT_DEFAULT_0;
692 		port_range_hints[EQ_CH1G].LowerBound = -50;
693 		port_range_hints[EQ_CH1G].UpperBound = +20;
694 		/* Parameters for CH1 bandwidth [octaves] */
695 		port_descriptors[EQ_CH1B] =
696 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
697 		port_names[EQ_CH1B] =
698 		 "Band 2 Bandwidth [octaves]";
699 		port_range_hints[EQ_CH1B].HintDescriptor =
700 			LADSPA_HINT_BOUNDED_BELOW |
701 			LADSPA_HINT_BOUNDED_ABOVE |
702 			LADSPA_HINT_DEFAULT_1;
703 		port_range_hints[EQ_CH1B].LowerBound = 0.1f;
704 		port_range_hints[EQ_CH1B].UpperBound = 5.0f;
705 
706 
707 
708 
709 		/* Parameters for CH2 freq [Hz] */
710 		port_descriptors[EQ_CH2F] =
711 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
712 		port_names[EQ_CH2F] =
713 		 "Band 3 Freq [Hz]";
714 		port_range_hints[EQ_CH2F].HintDescriptor =
715 			LADSPA_HINT_BOUNDED_BELOW |
716 			LADSPA_HINT_BOUNDED_ABOVE |
717 			LADSPA_HINT_DEFAULT_LOW;
718 		port_range_hints[EQ_CH2F].LowerBound = 200;
719 		port_range_hints[EQ_CH2F].UpperBound = 1000;
720 		/* Parameters for CH2 gain [dB] */
721 		port_descriptors[EQ_CH2G] =
722 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
723 		port_names[EQ_CH2G] =
724 		 "Band 3 Gain [dB]";
725 		port_range_hints[EQ_CH2G].HintDescriptor =
726 			LADSPA_HINT_BOUNDED_BELOW |
727 			LADSPA_HINT_BOUNDED_ABOVE |
728 			LADSPA_HINT_DEFAULT_0;
729 		port_range_hints[EQ_CH2G].LowerBound = -50;
730 		port_range_hints[EQ_CH2G].UpperBound = +20;
731 		/* Parameters for CH2 bandwidth [octaves] */
732 		port_descriptors[EQ_CH2B] =
733 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
734 		port_names[EQ_CH2B] =
735 		 "Band 3 Bandwidth [octaves]";
736 		port_range_hints[EQ_CH2B].HintDescriptor =
737 			LADSPA_HINT_BOUNDED_BELOW |
738 			LADSPA_HINT_BOUNDED_ABOVE |
739 			LADSPA_HINT_DEFAULT_1;
740 		port_range_hints[EQ_CH2B].LowerBound = 0.1f;
741 		port_range_hints[EQ_CH2B].UpperBound = 5.0f;
742 
743 
744 
745 
746 		/* Parameters for CH3 freq [Hz] */
747 		port_descriptors[EQ_CH3F] =
748 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
749 		port_names[EQ_CH3F] =
750 		 "Band 4 Freq [Hz]";
751 		port_range_hints[EQ_CH3F].HintDescriptor =
752 			LADSPA_HINT_BOUNDED_BELOW |
753 			LADSPA_HINT_BOUNDED_ABOVE |
754 			LADSPA_HINT_DEFAULT_LOW;
755 		port_range_hints[EQ_CH3F].LowerBound = 400;
756 		port_range_hints[EQ_CH3F].UpperBound = 2800;
757 		/* Parameters for CH3 gain [dB] */
758 		port_descriptors[EQ_CH3G] =
759 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
760 		port_names[EQ_CH3G] =
761 		 "Band 4 Gain [dB]";
762 		port_range_hints[EQ_CH3G].HintDescriptor =
763 			LADSPA_HINT_BOUNDED_BELOW |
764 			LADSPA_HINT_BOUNDED_ABOVE |
765 			LADSPA_HINT_DEFAULT_0;
766 		port_range_hints[EQ_CH3G].LowerBound = -50;
767 		port_range_hints[EQ_CH3G].UpperBound = +20;
768 		/* Parameters for CH3 bandwidth [octaves] */
769 		port_descriptors[EQ_CH3B] =
770 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
771 		port_names[EQ_CH3B] =
772 		 "Band 4 Bandwidth [octaves]";
773 		port_range_hints[EQ_CH3B].HintDescriptor =
774 			LADSPA_HINT_BOUNDED_BELOW |
775 			LADSPA_HINT_BOUNDED_ABOVE |
776 			LADSPA_HINT_DEFAULT_1;
777 		port_range_hints[EQ_CH3B].LowerBound = 0.1f;
778 		port_range_hints[EQ_CH3B].UpperBound = 5.0f;
779 
780 
781 
782 
783 		/* Parameters for CH4 freq [Hz] */
784 		port_descriptors[EQ_CH4F] =
785 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
786 		port_names[EQ_CH4F] =
787 		 "Band 5 Freq [Hz]";
788 		port_range_hints[EQ_CH4F].HintDescriptor =
789 			LADSPA_HINT_BOUNDED_BELOW |
790 			LADSPA_HINT_BOUNDED_ABOVE |
791 			LADSPA_HINT_DEFAULT_MIDDLE;
792 		port_range_hints[EQ_CH4F].LowerBound = 1000;
793 		port_range_hints[EQ_CH4F].UpperBound = 5000;
794 		/* Parameters for CH4 gain [dB] */
795 		port_descriptors[EQ_CH4G] =
796 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
797 		port_names[EQ_CH4G] =
798 		 "Band 5 Gain [dB]";
799 		port_range_hints[EQ_CH4G].HintDescriptor =
800 			LADSPA_HINT_BOUNDED_BELOW |
801 			LADSPA_HINT_BOUNDED_ABOVE |
802 			LADSPA_HINT_DEFAULT_0;
803 		port_range_hints[EQ_CH4G].LowerBound = -50;
804 		port_range_hints[EQ_CH4G].UpperBound = +20;
805 		/* Parameters for CH4 bandwidth [octaves] */
806 		port_descriptors[EQ_CH4B] =
807 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
808 		port_names[EQ_CH4B] =
809 		 "Band 5 Bandwidth [octaves]";
810 		port_range_hints[EQ_CH4B].HintDescriptor =
811 			LADSPA_HINT_BOUNDED_BELOW |
812 			LADSPA_HINT_BOUNDED_ABOVE |
813 			LADSPA_HINT_DEFAULT_1;
814 		port_range_hints[EQ_CH4B].LowerBound = 0.1f;
815 		port_range_hints[EQ_CH4B].UpperBound = 5.0f;
816 
817 
818 
819 
820 		/* Parameters for CH5 freq [Hz] */
821 		port_descriptors[EQ_CH5F] =
822 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
823 		port_names[EQ_CH5F] =
824 		 "Band 6 Freq [Hz]";
825 		port_range_hints[EQ_CH5F].HintDescriptor =
826 			LADSPA_HINT_BOUNDED_BELOW |
827 			LADSPA_HINT_BOUNDED_ABOVE |
828 			LADSPA_HINT_DEFAULT_MIDDLE;
829 		port_range_hints[EQ_CH5F].LowerBound = 3000;
830 		port_range_hints[EQ_CH5F].UpperBound = 9000;
831 		/* Parameters for CH5 gain [dB] */
832 		port_descriptors[EQ_CH5G] =
833 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
834 		port_names[EQ_CH5G] =
835 		 "Band 6 Gain [dB]";
836 		port_range_hints[EQ_CH5G].HintDescriptor =
837 			LADSPA_HINT_BOUNDED_BELOW |
838 			LADSPA_HINT_BOUNDED_ABOVE |
839 			LADSPA_HINT_DEFAULT_0;
840 		port_range_hints[EQ_CH5G].LowerBound = -50;
841 		port_range_hints[EQ_CH5G].UpperBound = +20;
842 		/* Parameters for CH5 bandwidth [octaves] */
843 		port_descriptors[EQ_CH5B] =
844 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
845 		port_names[EQ_CH5B] =
846 		 "Band 6 Bandwidth [octaves]";
847 		port_range_hints[EQ_CH5B].HintDescriptor =
848 			LADSPA_HINT_BOUNDED_BELOW |
849 			LADSPA_HINT_BOUNDED_ABOVE |
850 			LADSPA_HINT_DEFAULT_1;
851 		port_range_hints[EQ_CH5B].LowerBound = 0.1f;
852 		port_range_hints[EQ_CH5B].UpperBound = 5.0f;
853 
854 
855 
856 
857 		/* Parameters for CH6 freq [Hz] */
858 		port_descriptors[EQ_CH6F] =
859 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
860 		port_names[EQ_CH6F] =
861 		 "Band 7 Freq [Hz]";
862 		port_range_hints[EQ_CH6F].HintDescriptor =
863 			LADSPA_HINT_BOUNDED_BELOW |
864 			LADSPA_HINT_BOUNDED_ABOVE |
865 			LADSPA_HINT_DEFAULT_MIDDLE;
866 		port_range_hints[EQ_CH6F].LowerBound = 6000;
867 		port_range_hints[EQ_CH6F].UpperBound = 18000;
868 		/* Parameters for CH6 gain [dB] */
869 		port_descriptors[EQ_CH6G] =
870 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
871 		port_names[EQ_CH6G] =
872 		 "Band 7 Gain [dB]";
873 		port_range_hints[EQ_CH6G].HintDescriptor =
874 			LADSPA_HINT_BOUNDED_BELOW |
875 			LADSPA_HINT_BOUNDED_ABOVE |
876 			LADSPA_HINT_DEFAULT_0;
877 		port_range_hints[EQ_CH6G].LowerBound = -50;
878 		port_range_hints[EQ_CH6G].UpperBound = +20;
879 		/* Parameters for CH6 bandwidth [octaves] */
880 		port_descriptors[EQ_CH6B] =
881 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
882 		port_names[EQ_CH6B] =
883 		 "Band 7 Bandwidth [octaves]";
884 		port_range_hints[EQ_CH6B].HintDescriptor =
885 			LADSPA_HINT_BOUNDED_BELOW |
886 			LADSPA_HINT_BOUNDED_ABOVE |
887 			LADSPA_HINT_DEFAULT_1;
888 		port_range_hints[EQ_CH6B].LowerBound = 0.1f;
889 		port_range_hints[EQ_CH6B].UpperBound = 5.0f;
890 
891 
892 
893 
894 		/* Parameters for CH7 freq [Hz] */
895 		port_descriptors[EQ_CH7F] =
896 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
897 		port_names[EQ_CH7F] =
898 		 "Band 8 Freq [Hz]";
899 		port_range_hints[EQ_CH7F].HintDescriptor =
900 			LADSPA_HINT_BOUNDED_BELOW |
901 			LADSPA_HINT_BOUNDED_ABOVE |
902 			LADSPA_HINT_DEFAULT_MIDDLE;
903 		port_range_hints[EQ_CH7F].LowerBound = 10000;
904 		port_range_hints[EQ_CH7F].UpperBound = 20000;
905 		/* Parameters for CH7 gain [dB] */
906 		port_descriptors[EQ_CH7G] =
907 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
908 		port_names[EQ_CH7G] =
909 		 "Band 8 Gain [dB]";
910 		port_range_hints[EQ_CH7G].HintDescriptor =
911 			LADSPA_HINT_BOUNDED_BELOW |
912 			LADSPA_HINT_BOUNDED_ABOVE |
913 			LADSPA_HINT_DEFAULT_0;
914 		port_range_hints[EQ_CH7G].LowerBound = -50;
915 		port_range_hints[EQ_CH7G].UpperBound = +20;
916 		/* Parameters for CH7 bandwidth [octaves] */
917 		port_descriptors[EQ_CH7B] =
918 		 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
919 		port_names[EQ_CH7B] =
920 		 "Band 8 Bandwidth [octaves]";
921 		port_range_hints[EQ_CH7B].HintDescriptor =
922 			LADSPA_HINT_BOUNDED_BELOW |
923 			LADSPA_HINT_BOUNDED_ABOVE |
924 			LADSPA_HINT_DEFAULT_1;
925 		port_range_hints[EQ_CH7B].LowerBound = 0.1f;
926 		port_range_hints[EQ_CH7B].UpperBound = 5.0f;
927 
928 
929 
930 
931 		/* Parameters for Input */
932 		port_descriptors[EQ_INPUT] =
933 		 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
934 		port_names[EQ_INPUT] =
935 		 "Input";
936 		port_range_hints[EQ_INPUT].HintDescriptor = 0;
937 
938 		/* Parameters for Output */
939 		port_descriptors[EQ_OUTPUT] =
940 		 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
941 		port_names[EQ_OUTPUT] =
942 		 "Output";
943 		port_range_hints[EQ_OUTPUT].HintDescriptor = 0;
944 
945 		eqDescriptor->activate = activate_eq;
946 		eqDescriptor->cleanup = cleanup_eq;
947 		eqDescriptor->connect_port = connectPort_eq;
948 		eqDescriptor->deactivate = NULL;
949 		eqDescriptor->instantiate = instantiate_eq;
950 		eqDescriptor->run = run_eq;
951 		eqDescriptor->run_adding = run_adding_eq;
952 		eqDescriptor->set_run_adding_gain = set_run_adding_gain;
953 	}
954 }
955 
956 
957 void
_fini()958 _fini() {
959 
960 	if (eqDescriptor) {
961 		free((LADSPA_PortDescriptor *)eqDescriptor->PortDescriptors);
962 		free((char **)eqDescriptor->PortNames);
963 		free((LADSPA_PortRangeHint *)eqDescriptor->PortRangeHints);
964 		free(eqDescriptor);
965 	}
966 
967 }
968