diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/highshelf.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/highshelf.c | 92 |
1 files changed, 1 insertions, 91 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/highshelf.c b/apps/plugins/pdbox/PDa/extra/highshelf.c index 0060d896c2..74db29178a 100644 --- a/apps/plugins/pdbox/PDa/extra/highshelf.c +++ b/apps/plugins/pdbox/PDa/extra/highshelf.c | |||
@@ -87,94 +87,4 @@ void highshelf_setup(void) | |||
87 | class_addfloat(highshelf_class,highshelf_float); | 87 | class_addfloat(highshelf_class,highshelf_float); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | ||
92 | |||
93 | |||
94 | /* | ||
95 | |||
96 | These filter coefficients computations are taken from | ||
97 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | ||
98 | |||
99 | written by Robert Bristow-Johnson | ||
100 | |||
101 | */ | ||
102 | |||
103 | #include "m_pd.h" | ||
104 | #ifdef NT | ||
105 | #pragma warning( disable : 4244 ) | ||
106 | #pragma warning( disable : 4305 ) | ||
107 | #endif | ||
108 | #include <math.h> | ||
109 | #include "filters.h" | ||
110 | |||
111 | |||
112 | /* ------------------- highshelf ----------------------------*/ | ||
113 | |||
114 | static t_class *highshelf_class; | ||
115 | |||
116 | void highshelf_bang(t_rbjfilter *x) | ||
117 | { | ||
118 | t_atom at[5]; | ||
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); | ||
124 | |||
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); | ||
131 | |||
132 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/ | ||
133 | |||
134 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | ||
135 | post("highshelf: filter unstable -> resetting"); | ||
136 | a0=1.;a1=0.;a2=0.; | ||
137 | b0=1.;b1=0.;b2=0.; | ||
138 | } | ||
139 | |||
140 | SETFLOAT(at,-a1/a0); | ||
141 | SETFLOAT(at+1,-a2/a0); | ||
142 | SETFLOAT(at+2,b0/a0); | ||
143 | SETFLOAT(at+3,b1/a0); | ||
144 | SETFLOAT(at+4,b2/a0); | ||
145 | |||
146 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | ||
147 | } | ||
148 | |||
149 | |||
150 | void highshelf_float(t_rbjfilter *x,t_floatarg f) | ||
151 | { | ||
152 | x->x_freq = f; | ||
153 | highshelf_bang(x); | ||
154 | } | ||
155 | |||
156 | |||
157 | static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) | ||
158 | { | ||
159 | t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class); | ||
160 | |||
161 | x->x_rate = 44100.0; | ||
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; | ||
168 | return (x); | ||
169 | } | ||
170 | |||
171 | |||
172 | void highshelf_setup(void) | ||
173 | { | ||
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); | ||
178 | } | ||
179 | |||
180 | |||