summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/highpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/highpass.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/highpass.c174
1 files changed, 174 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/highpass.c b/apps/plugins/pdbox/PDa/extra/highpass.c
new file mode 100644
index 0000000000..88ba4564e6
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/highpass.c
@@ -0,0 +1,174 @@
1/* (C) Guenter Geiger <geiger@epy.co.at> */
2
3
4/*
5
6 These filter coefficients computations are taken from
7 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
8
9 written by Robert Bristow-Johnson
10
11*/
12
13#include "m_pd.h"
14#ifdef NT
15#pragma warning( disable : 4244 )
16#pragma warning( disable : 4305 )
17#endif
18#include <math.h>
19#include "filters.h"
20
21
22/* ------------------- highpass ----------------------------*/
23
24static t_class *highpass_class;
25
26void highpass_bang(t_rbjfilter *x)
27{
28 t_atom at[5];
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 b1 = -(1 + cos(omega));
32 t_float b0 = -b1/2.;
33 t_float b2 = b0;
34 t_float a0 = 1 + alpha;
35 t_float a1 = -2.*cos(omega);
36 t_float a2 = 1 - alpha;
37
38/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
39
40 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
41 post("highpass: filter unstable -> resetting");
42 a0=1.;a1=0.;a2=0.;
43 b0=1.;b1=0.;b2=0.;
44 }
45
46 SETFLOAT(at,-a1/a0);
47 SETFLOAT(at+1,-a2/a0);
48 SETFLOAT(at+2,b0/a0);
49 SETFLOAT(at+3,b1/a0);
50 SETFLOAT(at+4,b2/a0);
51
52 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
53}
54
55
56void highpass_float(t_rbjfilter *x,t_floatarg f)
57{
58 x->x_freq = f;
59 highpass_bang(x);
60}
61
62
63static void *highpass_new(t_floatarg f,t_floatarg bw)
64{
65 t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
66
67 x->x_rate = 44100.0;
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 return (x);
74}
75
76
77void highpass_setup(void)
78{
79 highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
80 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
81 class_addbang(highpass_class,highpass_bang);
82 class_addfloat(highpass_class,highpass_float);
83}
84
85
86
87
88/* (C) Guenter Geiger <geiger@epy.co.at> */
89
90
91/*
92
93 These filter coefficients computations are taken from
94 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
95
96 written by Robert Bristow-Johnson
97
98*/
99
100#include "m_pd.h"
101#ifdef NT
102#pragma warning( disable : 4244 )
103#pragma warning( disable : 4305 )
104#endif
105#include <math.h>
106#include "filters.h"
107
108
109/* ------------------- highpass ----------------------------*/
110
111static t_class *highpass_class;
112
113void highpass_bang(t_rbjfilter *x)
114{
115 t_atom at[5];
116 t_float omega = e_omega(x->x_freq,x->x_rate);
117 t_float alpha = e_alpha(x->x_bw* 0.01,omega);
118 t_float b1 = -(1 + cos(omega));
119 t_float b0 = -b1/2.;
120 t_float b2 = b0;
121 t_float a0 = 1 + alpha;
122 t_float a1 = -2.*cos(omega);
123 t_float a2 = 1 - alpha;
124
125/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
126
127 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
128 post("highpass: filter unstable -> resetting");
129 a0=1.;a1=0.;a2=0.;
130 b0=1.;b1=0.;b2=0.;
131 }
132
133 SETFLOAT(at,-a1/a0);
134 SETFLOAT(at+1,-a2/a0);
135 SETFLOAT(at+2,b0/a0);
136 SETFLOAT(at+3,b1/a0);
137 SETFLOAT(at+4,b2/a0);
138
139 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
140}
141
142
143void highpass_float(t_rbjfilter *x,t_floatarg f)
144{
145 x->x_freq = f;
146 highpass_bang(x);
147}
148
149
150static void *highpass_new(t_floatarg f,t_floatarg bw)
151{
152 t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
153
154 x->x_rate = 44100.0;
155 outlet_new(&x->x_obj,&s_float);
156/* floatinlet_new(&x->x_obj, &x->x_gain); */
157 floatinlet_new(&x->x_obj, &x->x_bw);
158 if (f > 0.) x->x_freq = f;
159 if (bw > 0.) x->x_bw = bw;
160 return (x);
161}
162
163
164void highpass_setup(void)
165{
166 highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
167 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
168 class_addbang(highpass_class,highpass_bang);
169 class_addfloat(highpass_class,highpass_float);
170}
171
172
173
174