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 )
22 /* ------------------- highshelf ----------------------------*/
24 static t_class
*highshelf_class
;
26 void highshelf_bang(t_rbjfilter
*x
)
29 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
30 t_float A
= e_A(x
->x_gain
);
31 t_float cs
= cos(omega
);
32 t_float sn
= sin(omega
);
33 t_float beta
= e_beta(A
,x
->x_bw
* 0.01);
35 t_float b0
= A
*((A
+1) + (A
-1)*cs
+ beta
*sn
);
36 t_float b1
=-2.*A
*((A
-1) + (A
+1)*cs
);
37 t_float b2
= A
*((A
+1) + (A
-1)*cs
- beta
*sn
);
38 t_float a0
= ((A
+1) - (A
-1)*cs
+ beta
*sn
);
39 t_float a1
= 2.*((A
-1) - (A
+1)*cs
);
40 t_float a2
= ((A
+1) - (A
-1)*cs
- beta
*sn
);
42 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
44 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
45 post("highshelf: filter unstable -> resetting");
51 SETFLOAT(at
+1,-a2
/a0
);
56 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
60 void highshelf_float(t_rbjfilter
*x
,t_floatarg f
)
67 static void *highshelf_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
69 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(highshelf_class
);
72 outlet_new(&x
->x_obj
,&s_float
);
73 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
74 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
75 if (f
> 0.) x
->x_freq
= f
;
76 if (bw
> 0.) x
->x_bw
= bw
;
77 if (g
!= 0.) x
->x_gain
= g
;
82 void highshelf_setup(void)
84 highshelf_class
= class_new(gensym("highshelf"), (t_newmethod
)highshelf_new
, 0,
85 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
86 class_addbang(highshelf_class
,highshelf_bang
);
87 class_addfloat(highshelf_class
,highshelf_float
);
91 /* (C) Guenter Geiger <geiger@epy.co.at> */
96 These filter coefficients computations are taken from
97 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
99 written by Robert Bristow-Johnson
105 #pragma warning( disable : 4244 )
106 #pragma warning( disable : 4305 )
112 /* ------------------- highshelf ----------------------------*/
114 static t_class
*highshelf_class
;
116 void highshelf_bang(t_rbjfilter
*x
)
119 t_float omega
= e_omega(x
->x_freq
,x
->x_rate
);
120 t_float A
= e_A(x
->x_gain
);
121 t_float cs
= cos(omega
);
122 t_float sn
= sin(omega
);
123 t_float beta
= e_beta(A
,x
->x_bw
* 0.01);
125 t_float b0
= A
*((A
+1) + (A
-1)*cs
+ beta
*sn
);
126 t_float b1
=-2.*A
*((A
-1) + (A
+1)*cs
);
127 t_float b2
= A
*((A
+1) + (A
-1)*cs
- beta
*sn
);
128 t_float a0
= ((A
+1) - (A
-1)*cs
+ beta
*sn
);
129 t_float a1
= 2.*((A
-1) - (A
+1)*cs
);
130 t_float a2
= ((A
+1) - (A
-1)*cs
- beta
*sn
);
132 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
134 if (!check_stability(-a1
/a0
,-a2
/a0
,b0
/a0
,b1
/a0
,b2
/a0
)) {
135 post("highshelf: filter unstable -> resetting");
141 SETFLOAT(at
+1,-a2
/a0
);
142 SETFLOAT(at
+2,b0
/a0
);
143 SETFLOAT(at
+3,b1
/a0
);
144 SETFLOAT(at
+4,b2
/a0
);
146 outlet_list(x
->x_obj
.ob_outlet
,&s_list
,5,at
);
150 void highshelf_float(t_rbjfilter
*x
,t_floatarg f
)
157 static void *highshelf_new(t_floatarg f
,t_floatarg g
,t_floatarg bw
)
159 t_rbjfilter
*x
= (t_rbjfilter
*)pd_new(highshelf_class
);
162 outlet_new(&x
->x_obj
,&s_float
);
163 floatinlet_new(&x
->x_obj
, &x
->x_gain
);
164 floatinlet_new(&x
->x_obj
, &x
->x_bw
);
165 if (f
> 0.) x
->x_freq
= f
;
166 if (bw
> 0.) x
->x_bw
= bw
;
167 if (g
!= 0.) x
->x_gain
= g
;
172 void highshelf_setup(void)
174 highshelf_class
= class_new(gensym("highshelf"), (t_newmethod
)highshelf_new
, 0,
175 sizeof(t_rbjfilter
), 0,A_DEFFLOAT
,A_DEFFLOAT
,A_DEFFLOAT
,0);
176 class_addbang(highshelf_class
,highshelf_bang
);
177 class_addfloat(highshelf_class
,highshelf_float
);