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 #include "../../pdbox.h"
16 #include "../src/m_pd.h"
20 #include "../src/m_pd.h"
22 #pragma warning( disable : 4244 )
23 #pragma warning( disable : 4305 )
30 /* ------------------- lowshelf ----------------------------*/
32 static t_class
*lowshelf_class
;
34 void lowshelf_bang(t_rbjfilter
*x
)
37 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
38 t_float A
= e_A(x
->x_gain
);
39 t_float cs
= cos(omega
);
40 t_float sn
= sin(omega
);
41 t_float beta
= e_beta(A
,x
->x_bw
*0.01);
43 t_float b0
= A
*((A
+1) - (A
-1)*cs
+ beta
*sn
);
44 t_float b1
= 2.*A
*((A
-1) - (A
+1)*cs
);
45 t_float b2
= A
*((A
+1) - (A
-1)*cs
- beta
*sn
);
46 t_float a0
= ((A
+1) + (A
-1)*cs
+ beta
*sn
);
47 t_float a1
= -2.*((A
-1) + (A
+1)*cs
);
48 t_float a2
= ((A
+1) + (A
-1)*cs
- beta
*sn
);
50 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
52 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
53 post("lowshelf: filter unstable -> resetting");
59 SETFLOAT(at
+1,-a2
/a0
);
64 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
68 void lowshelf_float(t_rbjfilter
*x
,t_floatarg f
)
75 static void *lowshelf_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
77 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(lowshelf_class
);
80 outlet_new(&x
->x_obj
,&s_float
);
81 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
82 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
83 if (f
> 0.) x
->x_freq
= f
;
84 if (bw
> 0.) x
->x_bw
= bw
;
85 if (g
!= 0.) x
->x_gain
= g
;
90 void lowshelf_setup(void)
92 lowshelf_class
= class_new(gensym("lowshelf"), (t_newmethod
)lowshelf_new
, 0,
93 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
94 class_addbang(lowshelf_class
,lowshelf_bang
);
95 class_addfloat(lowshelf_class
,lowshelf_float
);