diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/extra/bandpass.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/bandpass.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/bandpass.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/bandpass.c b/apps/plugins/pdbox/PDa/extra/bandpass.c new file mode 100644 index 0000000000..6de56d6174 --- /dev/null +++ b/apps/plugins/pdbox/PDa/extra/bandpass.c | |||
@@ -0,0 +1,172 @@ | |||
1 | |||
2 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | ||
3 | |||
4 | |||
5 | /* | ||
6 | |||
7 | These filter coefficients computations are taken from | ||
8 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | ||
9 | |||
10 | written by Robert Bristow-Johnson | ||
11 | |||
12 | */ | ||
13 | |||
14 | #include "m_pd.h" | ||
15 | #ifdef NT | ||
16 | #pragma warning( disable : 4244 ) | ||
17 | #pragma warning( disable : 4305 ) | ||
18 | #endif | ||
19 | #include <math.h> | ||
20 | #include "filters.h" | ||
21 | |||
22 | /* ------------------- bandpass ----------------------------*/ | ||
23 | |||
24 | static t_class *bandpass_class; | ||
25 | |||
26 | void bandpass_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 = 0.; | ||
32 | t_float b0 = alpha; | ||
33 | t_float b2 = -alpha; | ||
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("bandpass: 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 | |||
56 | void bandpass_float(t_rbjfilter *x,t_floatarg f) | ||
57 | { | ||
58 | x->x_freq = f; | ||
59 | bandpass_bang(x); | ||
60 | } | ||
61 | |||
62 | |||
63 | static void *bandpass_new(t_floatarg f,t_floatarg bw) | ||
64 | { | ||
65 | t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_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 | |||
77 | void bandpass_setup(void) | ||
78 | { | ||
79 | bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0, | ||
80 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0); | ||
81 | class_addbang(bandpass_class,bandpass_bang); | ||
82 | class_addfloat(bandpass_class,bandpass_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 | /* ------------------- bandpass ----------------------------*/ | ||
109 | |||
110 | static t_class *bandpass_class; | ||
111 | |||
112 | void bandpass_bang(t_rbjfilter *x) | ||
113 | { | ||
114 | t_atom at[5]; | ||
115 | t_float omega = e_omega(x->x_freq,x->x_rate); | ||
116 | t_float alpha = e_alpha(x->x_bw* 0.01,omega); | ||
117 | t_float b1 = 0.; | ||
118 | t_float b0 = alpha; | ||
119 | t_float b2 = -alpha; | ||
120 | t_float a0 = 1 + alpha; | ||
121 | t_float a1 = -2.*cos(omega); | ||
122 | t_float a2 = 1 - alpha; | ||
123 | |||
124 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ | ||
125 | |||
126 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | ||
127 | post("bandpass: filter unstable -> resetting"); | ||
128 | a0=1.;a1=0.;a2=0.; | ||
129 | b0=1.;b1=0.;b2=0.; | ||
130 | } | ||
131 | |||
132 | SETFLOAT(at,-a1/a0); | ||
133 | SETFLOAT(at+1,-a2/a0); | ||
134 | SETFLOAT(at+2,b0/a0); | ||
135 | SETFLOAT(at+3,b1/a0); | ||
136 | SETFLOAT(at+4,b2/a0); | ||
137 | |||
138 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | ||
139 | } | ||
140 | |||
141 | |||
142 | void bandpass_float(t_rbjfilter *x,t_floatarg f) | ||
143 | { | ||
144 | x->x_freq = f; | ||
145 | bandpass_bang(x); | ||
146 | } | ||
147 | |||
148 | |||
149 | static void *bandpass_new(t_floatarg f,t_floatarg bw) | ||
150 | { | ||
151 | t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class); | ||
152 | |||
153 | x->x_rate = 44100.0; | ||
154 | outlet_new(&x->x_obj,&s_float); | ||
155 | /* floatinlet_new(&x->x_obj, &x->x_gain); */ | ||
156 | floatinlet_new(&x->x_obj, &x->x_bw); | ||
157 | if (f > 0.) x->x_freq = f; | ||
158 | if (bw > 0.) x->x_bw = bw; | ||
159 | return (x); | ||
160 | } | ||
161 | |||
162 | |||
163 | void bandpass_setup(void) | ||
164 | { | ||
165 | bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0, | ||
166 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0); | ||
167 | class_addbang(bandpass_class,bandpass_bang); | ||
168 | class_addfloat(bandpass_class,bandpass_float); | ||
169 | } | ||
170 | |||
171 | |||
172 | |||