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 /* ------------------- lowshelf ----------------------------*/
25 static t_class
*lowshelf_class
;
27 void lowshelf_bang(t_rbjfilter
*x
)
30 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
31 t_float A
= e_A(x
->x_gain
);
32 t_float cs
= cos(omega
);
33 t_float sn
= sin(omega
);
34 t_float beta
= e_beta(A
,x
->x_bw
*0.01);
36 t_float b0
= A
*((A
+1) - (A
-1)*cs
+ beta
*sn
);
37 t_float b1
= 2.*A
*((A
-1) - (A
+1)*cs
);
38 t_float b2
= A
*((A
+1) - (A
-1)*cs
- beta
*sn
);
39 t_float a0
= ((A
+1) + (A
-1)*cs
+ beta
*sn
);
40 t_float a1
= -2.*((A
-1) + (A
+1)*cs
);
41 t_float a2
= ((A
+1) + (A
-1)*cs
- beta
*sn
);
43 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
45 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
46 post("lowshelf: filter unstable -> resetting");
52 SETFLOAT(at
+1,-a2
/a0
);
57 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
61 void lowshelf_float(t_rbjfilter
*x
,t_floatarg f
)
68 static void *lowshelf_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
70 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(lowshelf_class
);
73 outlet_new(&x
->x_obj
,&s_float
);
74 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
75 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
76 if (f
> 0.) x
->x_freq
= f
;
77 if (bw
> 0.) x
->x_bw
= bw
;
78 if (g
!= 0.) x
->x_gain
= g
;
83 void lowshelf_setup(void)
85 lowshelf_class
= class_new(gensym("lowshelf"), (t_newmethod
)lowshelf_new
, 0,
86 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
87 class_addbang(lowshelf_class
,lowshelf_bang
);
88 class_addfloat(lowshelf_class
,lowshelf_float
);
92 /* (C) Guenter Geiger <geiger@epy.co.at> */
97 These filter coefficients computations are taken from
98 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
100 written by Robert Bristow-Johnson
106 #pragma warning( disable : 4244 )
107 #pragma warning( disable : 4305 )
114 /* ------------------- lowshelf ----------------------------*/
116 static t_class
*lowshelf_class
;
118 void lowshelf_bang(t_rbjfilter
*x
)
121 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
122 t_float A
= e_A(x
->x_gain
);
123 t_float cs
= cos(omega
);
124 t_float sn
= sin(omega
);
125 t_float beta
= e_beta(A
,x
->x_bw
*0.01);
127 t_float b0
= A
*((A
+1) - (A
-1)*cs
+ beta
*sn
);
128 t_float b1
= 2.*A
*((A
-1) - (A
+1)*cs
);
129 t_float b2
= A
*((A
+1) - (A
-1)*cs
- beta
*sn
);
130 t_float a0
= ((A
+1) + (A
-1)*cs
+ beta
*sn
);
131 t_float a1
= -2.*((A
-1) + (A
+1)*cs
);
132 t_float a2
= ((A
+1) + (A
-1)*cs
- beta
*sn
);
134 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
136 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
137 post("lowshelf: filter unstable -> resetting");
143 SETFLOAT(at
+1,-a2
/a0
);
144 SETFLOAT(at
+2,b0
/a0
);
145 SETFLOAT(at
+3,b1
/a0
);
146 SETFLOAT(at
+4,b2
/a0
);
148 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
152 void lowshelf_float(t_rbjfilter
*x
,t_floatarg f
)
159 static void *lowshelf_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
161 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(lowshelf_class
);
164 outlet_new(&x
->x_obj
,&s_float
);
165 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
166 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
167 if (f
> 0.) x
->x_freq
= f
;
168 if (bw
> 0.) x
->x_bw
= bw
;
169 if (g
!= 0.) x
->x_gain
= g
;
174 void lowshelf_setup(void)
176 lowshelf_class
= class_new(gensym("lowshelf"), (t_newmethod
)lowshelf_new
, 0,
177 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
178 class_addbang(lowshelf_class
,lowshelf_bang
);
179 class_addfloat(lowshelf_class
,lowshelf_float
);