summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/hip~.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/intern/hip~.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-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/intern/hip~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/hip~.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/hip~.c b/apps/plugins/pdbox/PDa/intern/hip~.c
new file mode 100644
index 0000000000..a2a8c40cf2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/hip~.c
@@ -0,0 +1,184 @@
1#include <m_pd.h>
2#include <m_fixed.h>
3
4typedef struct hipctl
5{
6 t_sample c_x;
7 t_sample c_coef;
8} t_hipctl;
9
10typedef struct sighip
11{
12 t_object x_obj;
13 float x_sr;
14 float x_hz;
15 t_hipctl x_cspace;
16 t_hipctl *x_ctl;
17 float x_f;
18} t_sighip;
19
20t_class *sighip_class;
21static void sighip_ft1(t_sighip *x, t_floatarg f);
22
23static void *sighip_new(t_floatarg f)
24{
25 t_sighip *x = (t_sighip *)pd_new(sighip_class);
26 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
27 outlet_new(&x->x_obj, gensym("signal"));
28 x->x_sr = 44100;
29 x->x_ctl = &x->x_cspace;
30 x->x_cspace.c_x = 0;
31 sighip_ft1(x, f);
32 x->x_f = 0;
33 return (x);
34}
35
36static void sighip_ft1(t_sighip *x, t_floatarg f)
37{
38 t_float coeff;
39 if (f < 0.001) f = 10;
40 x->x_hz = f;
41 coeff = 1 - f * (2 * 3.14159) / x->x_sr;
42 if (coeff < 0) coeff = 0;
43 x->x_ctl->c_coef = ftofix(coeff);
44}
45
46static t_int *sighip_perform(t_int *w)
47{
48 t_sample *in = (t_sample *)(w[1]);
49 t_sample *out = (t_sample *)(w[2]);
50 t_hipctl *c = (t_hipctl *)(w[3]);
51 int n = (t_int)(w[4]);
52 int i;
53 t_sample last = c->c_x;
54 t_sample coef = c->c_coef;
55 for (i = 0; i < n; i++)
56 {
57 t_sample new = *in++ + mult(coef,last);
58 *out++ = new - last;
59 last = new;
60 }
61 if (PD_BADFLOAT(last))
62 last = 0;
63 c->c_x = last;
64 return (w+5);
65}
66
67static void sighip_dsp(t_sighip *x, t_signal **sp)
68{
69 x->x_sr = sp[0]->s_sr;
70 sighip_ft1(x, x->x_hz);
71 dsp_add(sighip_perform, 4,
72 sp[0]->s_vec, sp[1]->s_vec,
73 x->x_ctl, sp[0]->s_n);
74
75}
76
77static void sighip_clear(t_sighip *x, t_floatarg q)
78{
79 x->x_cspace.c_x = 0;
80}
81
82void hip_tilde_setup(void)
83{
84 sighip_class = class_new(gensym("hip~"), (t_newmethod)sighip_new, 0,
85 sizeof(t_sighip), 0, A_DEFFLOAT, 0);
86 CLASS_MAINSIGNALIN(sighip_class, t_sighip, x_f);
87 class_addmethod(sighip_class, (t_method)sighip_dsp, gensym("dsp"), 0);
88 class_addmethod(sighip_class, (t_method)sighip_ft1,
89 gensym("ft1"), A_FLOAT, 0);
90 class_addmethod(sighip_class, (t_method)sighip_clear, gensym("clear"), 0);
91 class_sethelpsymbol(sighip_class, gensym("lop~-help.pd"));
92}
93#include <m_pd.h>
94#include <m_fixed.h>
95
96typedef struct hipctl
97{
98 t_sample c_x;
99 t_sample c_coef;
100} t_hipctl;
101
102typedef struct sighip
103{
104 t_object x_obj;
105 float x_sr;
106 float x_hz;
107 t_hipctl x_cspace;
108 t_hipctl *x_ctl;
109 float x_f;
110} t_sighip;
111
112t_class *sighip_class;
113static void sighip_ft1(t_sighip *x, t_floatarg f);
114
115static void *sighip_new(t_floatarg f)
116{
117 t_sighip *x = (t_sighip *)pd_new(sighip_class);
118 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
119 outlet_new(&x->x_obj, gensym("signal"));
120 x->x_sr = 44100;
121 x->x_ctl = &x->x_cspace;
122 x->x_cspace.c_x = 0;
123 sighip_ft1(x, f);
124 x->x_f = 0;
125 return (x);
126}
127
128static void sighip_ft1(t_sighip *x, t_floatarg f)
129{
130 t_float coeff;
131 if (f < 0.001) f = 10;
132 x->x_hz = f;
133 coeff = 1 - f * (2 * 3.14159) / x->x_sr;
134 if (coeff < 0) coeff = 0;
135 x->x_ctl->c_coef = ftofix(coeff);
136}
137
138static t_int *sighip_perform(t_int *w)
139{
140 t_sample *in = (t_sample *)(w[1]);
141 t_sample *out = (t_sample *)(w[2]);
142 t_hipctl *c = (t_hipctl *)(w[3]);
143 int n = (t_int)(w[4]);
144 int i;
145 t_sample last = c->c_x;
146 t_sample coef = c->c_coef;
147 for (i = 0; i < n; i++)
148 {
149 t_sample new = *in++ + mult(coef,last);
150 *out++ = new - last;
151 last = new;
152 }
153 if (PD_BADFLOAT(last))
154 last = 0;
155 c->c_x = last;
156 return (w+5);
157}
158
159static void sighip_dsp(t_sighip *x, t_signal **sp)
160{
161 x->x_sr = sp[0]->s_sr;
162 sighip_ft1(x, x->x_hz);
163 dsp_add(sighip_perform, 4,
164 sp[0]->s_vec, sp[1]->s_vec,
165 x->x_ctl, sp[0]->s_n);
166
167}
168
169static void sighip_clear(t_sighip *x, t_floatarg q)
170{
171 x->x_cspace.c_x = 0;
172}
173
174void hip_tilde_setup(void)
175{
176 sighip_class = class_new(gensym("hip~"), (t_newmethod)sighip_new, 0,
177 sizeof(t_sighip), 0, A_DEFFLOAT, 0);
178 CLASS_MAINSIGNALIN(sighip_class, t_sighip, x_f);
179 class_addmethod(sighip_class, (t_method)sighip_dsp, gensym("dsp"), 0);
180 class_addmethod(sighip_class, (t_method)sighip_ft1,
181 gensym("ft1"), A_FLOAT, 0);
182 class_addmethod(sighip_class, (t_method)sighip_clear, gensym("clear"), 0);
183 class_sethelpsymbol(sighip_class, gensym("lop~-help.pd"));
184}