1 /* (C) Guenter Geiger <geiger@epy.co.at> */
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
15 #pragma warning( disable : 4244 )
16 #pragma warning( disable : 4305 )
23 /* ------------------- equ ----------------------------*/
24 static t_class
*equ_class
;
26 void equ_bang(t_rbjfilter
*x
)
29 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
30 t_float alpha
= e_alpha(x
->x_bw
*0.01,omega
);
31 t_float b0
= 1 + alpha
*e_A(x
->x_gain
);
32 t_float b1
= -2.*cos(omega
);
33 t_float b2
= 1 - alpha
*e_A(x
->x_gain
);
34 t_float a0
= 1 + alpha
/e_A(x
->x_gain
);
35 t_float a1
= -2.*cos(omega
);
36 t_float a2
= 1 - alpha
/e_A(x
->x_gain
);
38 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
40 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
41 post("equ: filter unstable -> resetting");
47 SETFLOAT(at
+1,-a2
/a0
);
52 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
56 void equ_float(t_rbjfilter
*x
,t_floatarg f
)
63 static void *equ_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
65 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(equ_class
);
68 outlet_new(&x
->x_obj
,&s_float
);
69 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
70 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
71 if (f
> 0.) x
->x_freq
= f
;
72 if (bw
> 0.) x
->x_bw
= bw
;
73 if (g
!= 0.) x
->x_gain
= g
;
78 void equalizer_setup(void)
80 equ_class
= class_new(gensym("equalizer"), (t_newmethod
)equ_new
, 0,
81 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
82 class_addbang(equ_class
,equ_bang
);
83 class_addfloat(equ_class
,equ_float
);
90 /* (C) Guenter Geiger <geiger@epy.co.at> */
95 These filter coefficients computations are taken from
96 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
98 written by Robert Bristow-Johnson
104 #pragma warning( disable : 4244 )
105 #pragma warning( disable : 4305 )
112 /* ------------------- equ ----------------------------*/
113 static t_class
*equ_class
;
115 void equ_bang(t_rbjfilter
*x
)
118 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
119 t_float alpha
= e_alpha(x
->x_bw
*0.01,omega
);
120 t_float b0
= 1 + alpha
*e_A(x
->x_gain
);
121 t_float b1
= -2.*cos(omega
);
122 t_float b2
= 1 - alpha
*e_A(x
->x_gain
);
123 t_float a0
= 1 + alpha
/e_A(x
->x_gain
);
124 t_float a1
= -2.*cos(omega
);
125 t_float a2
= 1 - alpha
/e_A(x
->x_gain
);
127 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
129 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
130 post("equ: filter unstable -> resetting");
136 SETFLOAT(at
+1,-a2
/a0
);
137 SETFLOAT(at
+2,b0
/a0
);
138 SETFLOAT(at
+3,b1
/a0
);
139 SETFLOAT(at
+4,b2
/a0
);
141 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
145 void equ_float(t_rbjfilter
*x
,t_floatarg f
)
152 static void *equ_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
154 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(equ_class
);
157 outlet_new(&x
->x_obj
,&s_float
);
158 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
159 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
160 if (f
> 0.) x
->x_freq
= f
;
161 if (bw
> 0.) x
->x_bw
= bw
;
162 if (g
!= 0.) x
->x_gain
= g
;
167 void equalizer_setup(void)
169 equ_class
= class_new(gensym("equalizer"), (t_newmethod
)equ_new
, 0,
170 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
171 class_addbang(equ_class
,equ_bang
);
172 class_addfloat(equ_class
,equ_float
);