Add the identifying header
[kugel-rb.git] / apps / plugins / pdbox / PDa / extra / highpass.c
blob486d10117065924a668abcdced937945f081f741
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
14 #ifdef ROCKBOX
15 #include "plugin.h"
16 #include "../../pdbox.h"
17 #include "../src/m_pd.h"
18 #include "math.h"
19 #include "filters.h"
20 #else /* ROCKBOX */
21 #include "../src/m_pd.h"
22 #ifdef NT
23 #pragma warning( disable : 4244 )
24 #pragma warning( disable : 4305 )
25 #endif
26 #include <math.h>
27 #include "filters.h"
28 #endif /* ROCKBOX */
31 /* ------------------- highpass ----------------------------*/
33 static t_class *highpass_class;
35 void highpass_bang(t_rbjfilter *x)
37 t_atom at[5];
38 t_float omega = e_omega(x->x_freq,x->x_rate);
39 t_float alpha = e_alpha(x->x_bw* 0.01,omega);
40 t_float b1 = -(1 + cos(omega));
41 t_float b0 = -b1/2.;
42 t_float b2 = b0;
43 t_float a0 = 1 + alpha;
44 t_float a1 = -2.*cos(omega);
45 t_float a2 = 1 - alpha;
47 /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
49 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
50 post("highpass: filter unstable -> resetting");
51 a0=1.;a1=0.;a2=0.;
52 b0=1.;b1=0.;b2=0.;
55 SETFLOAT(at,-a1/a0);
56 SETFLOAT(at+1,-a2/a0);
57 SETFLOAT(at+2,b0/a0);
58 SETFLOAT(at+3,b1/a0);
59 SETFLOAT(at+4,b2/a0);
61 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
65 void highpass_float(t_rbjfilter *x,t_floatarg f)
67 x->x_freq = f;
68 highpass_bang(x);
72 static void *highpass_new(t_floatarg f,t_floatarg bw)
74 t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
76 x->x_rate = 44100.0;
77 outlet_new(&x->x_obj,&s_float);
78 /* floatinlet_new(&x->x_obj, &x->x_gain); */
79 floatinlet_new(&x->x_obj, &x->x_bw);
80 if (f > 0.) x->x_freq = f;
81 if (bw > 0.) x->x_bw = bw;
82 return (x);
86 void highpass_setup(void)
88 highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
89 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
90 class_addbang(highpass_class,highpass_bang);
91 class_addfloat(highpass_class,highpass_float);