summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/highshelf.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/highshelf.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/highshelf.c180
1 files changed, 180 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/highshelf.c b/apps/plugins/pdbox/PDa/extra/highshelf.c
new file mode 100644
index 0000000000..0060d896c2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/highshelf.c
@@ -0,0 +1,180 @@
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/* ------------------- highshelf ----------------------------*/
23
24static t_class *highshelf_class;
25
26void highshelf_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 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);
34
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);
41
42/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
43
44 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
45 post("highshelf: filter unstable -> resetting");
46 a0=1.;a1=0.;a2=0.;
47 b0=1.;b1=0.;b2=0.;
48 }
49
50 SETFLOAT(at,-a1/a0);
51 SETFLOAT(at+1,-a2/a0);
52 SETFLOAT(at+2,b0/a0);
53 SETFLOAT(at+3,b1/a0);
54 SETFLOAT(at+4,b2/a0);
55
56 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
57}
58
59
60void highshelf_float(t_rbjfilter *x,t_floatarg f)
61{
62 x->x_freq = f;
63 highshelf_bang(x);
64}
65
66
67static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
68{
69 t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class);
70
71 x->x_rate = 44100.0;
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;
78 return (x);
79}
80
81
82void highshelf_setup(void)
83{
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);
88}
89
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
114static t_class *highshelf_class;
115
116void 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
150void highshelf_float(t_rbjfilter *x,t_floatarg f)
151{
152 x->x_freq = f;
153 highshelf_bang(x);
154}
155
156
157static 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
172void 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