Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / extra / equalizer.c
blobd252e02bc9035b64be5aef86348bc61051ee9a08
1 /* (C) Guenter Geiger <geiger@epy.co.at> */
4 /*
6 These filter coefficients computations are taken from
7 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
9 written by Robert Bristow-Johnson
13 #ifdef ROCKBOX
14 #include "plugin.h"
15 #include "../../pdbox.h"
16 #include "../src/m_pd.h"
17 #include "math.h"
18 #include "filters.h"
19 #else /* ROCKBOX */
20 #include "../src/m_pd.h"
21 #ifdef NT
22 #pragma warning( disable : 4244 )
23 #pragma warning( disable : 4305 )
24 #endif
25 #include <math.h>
26 #include "filters.h"
27 #endif /* ROCKBOX */
30 /* ------------------- equ ----------------------------*/
31 static t_class *equ_class;
33 void equ_bang(t_rbjfilter *x)
35 t_atom at[5];
36 t_float omega = e_omega(x->x_freq,x->x_rate);
37 t_float alpha = e_alpha(x->x_bw*0.01,omega);
38 t_float b0 = 1 + alpha*e_A(x->x_gain);
39 t_float b1 = -2.*cos(omega);
40 t_float b2 = 1 - alpha*e_A(x->x_gain);
41 t_float a0 = 1 + alpha/e_A(x->x_gain);
42 t_float a1 = -2.*cos(omega);
43 t_float a2 = 1 - alpha/e_A(x->x_gain);
45 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
47 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
48 post("equ: filter unstable -> resetting");
49 a0=1.;a1=0.;a2=0.;
50 b0=1.;b1=0.;b2=0.;
53 SETFLOAT(at,-a1/a0);
54 SETFLOAT(at+1,-a2/a0);
55 SETFLOAT(at+2,b0/a0);
56 SETFLOAT(at+3,b1/a0);
57 SETFLOAT(at+4,b2/a0);
59 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
63 void equ_float(t_rbjfilter *x,t_floatarg f)
65 x->x_freq = f;
66 equ_bang(x);
70 static void *equ_new(t_floatarg f,t_floatarg g,t_floatarg bw)
72 t_rbjfilter *x = (t_rbjfilter *)pd_new(equ_class);
74 x->x_rate = 44100.0;
75 outlet_new(&x->x_obj,&s_float);
76 floatinlet_new(&x->x_obj, &x->x_gain);
77 floatinlet_new(&x->x_obj, &x->x_bw);
78 if (f > 0.) x->x_freq = f;
79 if (bw > 0.) x->x_bw = bw;
80 if (g != 0.) x->x_gain = g;
81 return (x);
85 void equalizer_setup(void)
87 equ_class = class_new(gensym("equalizer"), (t_newmethod)equ_new, 0,
88 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
89 class_addbang(equ_class,equ_bang);
90 class_addfloat(equ_class,equ_float);