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/intern/delwrite~.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/intern/delwrite~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/delwrite~.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/delwrite~.c b/apps/plugins/pdbox/PDa/intern/delwrite~.c new file mode 100644 index 0000000000..290793d9e4 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/delwrite~.c | |||
@@ -0,0 +1,168 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | |||
4 | extern int ugen_getsortno(void); | ||
5 | |||
6 | #define DEFDELVS 64 /* LATER get this from canvas at DSP time */ | ||
7 | static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */ | ||
8 | |||
9 | #include "delay.h" | ||
10 | |||
11 | t_class *sigdelwrite_class; | ||
12 | |||
13 | static void *sigdelwrite_new(t_symbol *s, t_floatarg msec) | ||
14 | { | ||
15 | int nsamps; | ||
16 | t_sigdelwrite *x = (t_sigdelwrite *)pd_new(sigdelwrite_class); | ||
17 | if (!*s->s_name) s = gensym("delwrite~"); | ||
18 | pd_bind(&x->x_obj.ob_pd, s); | ||
19 | x->x_sym = s; | ||
20 | nsamps = msec * sys_getsr() * (float)(0.001f); | ||
21 | if (nsamps < 1) nsamps = 1; | ||
22 | nsamps += ((- nsamps) & (SAMPBLK - 1)); | ||
23 | nsamps += DEFDELVS; | ||
24 | x->x_cspace.c_n = nsamps; | ||
25 | x->x_cspace.c_vec = | ||
26 | (t_sample *)getbytes((nsamps + XTRASAMPS) * sizeof(float)); | ||
27 | x->x_cspace.c_phase = XTRASAMPS; | ||
28 | x->x_sortno = 0; | ||
29 | x->x_vecsize = 0; | ||
30 | x->x_f = 0; | ||
31 | return (x); | ||
32 | } | ||
33 | |||
34 | static t_int *sigdelwrite_perform(t_int *w) | ||
35 | { | ||
36 | t_sample *in = (t_sample *)(w[1]); | ||
37 | t_delwritectl *c = (t_delwritectl *)(w[2]); | ||
38 | int n = (int)(w[3]); | ||
39 | int phase = c->c_phase, nsamps = c->c_n; | ||
40 | t_sample *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS); | ||
41 | phase += n; | ||
42 | while (n--) | ||
43 | { | ||
44 | t_sample f = *in++; | ||
45 | if (PD_BADFLOAT(f)) | ||
46 | f = 0; | ||
47 | *bp++ = f; | ||
48 | if (bp == ep) | ||
49 | { | ||
50 | vp[0] = ep[-4]; | ||
51 | vp[1] = ep[-3]; | ||
52 | vp[2] = ep[-2]; | ||
53 | vp[3] = ep[-1]; | ||
54 | bp = vp + XTRASAMPS; | ||
55 | phase -= nsamps; | ||
56 | } | ||
57 | } | ||
58 | c->c_phase = phase; | ||
59 | return (w+4); | ||
60 | } | ||
61 | |||
62 | static void sigdelwrite_dsp(t_sigdelwrite *x, t_signal **sp) | ||
63 | { | ||
64 | dsp_add(sigdelwrite_perform, 3, sp[0]->s_vec, &x->x_cspace, sp[0]->s_n); | ||
65 | x->x_sortno = ugen_getsortno(); | ||
66 | sigdelwrite_checkvecsize(x, sp[0]->s_n); | ||
67 | } | ||
68 | |||
69 | static void sigdelwrite_free(t_sigdelwrite *x) | ||
70 | { | ||
71 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
72 | freebytes(x->x_cspace.c_vec, | ||
73 | (x->x_cspace.c_n + XTRASAMPS) * sizeof(float)); | ||
74 | } | ||
75 | |||
76 | void delwrite_tilde_setup(void) | ||
77 | { | ||
78 | sigdelwrite_class = class_new(gensym("delwrite~"), | ||
79 | (t_newmethod)sigdelwrite_new, (t_method)sigdelwrite_free, | ||
80 | sizeof(t_sigdelwrite), 0, A_DEFSYM, A_DEFFLOAT, 0); | ||
81 | CLASS_MAINSIGNALIN(sigdelwrite_class, t_sigdelwrite, x_f); | ||
82 | class_addmethod(sigdelwrite_class, (t_method)sigdelwrite_dsp, | ||
83 | gensym("dsp"), 0); | ||
84 | } | ||
85 | #include <m_pd.h> | ||
86 | #include <m_fixed.h> | ||
87 | |||
88 | extern int ugen_getsortno(void); | ||
89 | |||
90 | #define DEFDELVS 64 /* LATER get this from canvas at DSP time */ | ||
91 | static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */ | ||
92 | |||
93 | #include "delay.h" | ||
94 | |||
95 | t_class *sigdelwrite_class; | ||
96 | |||
97 | static void *sigdelwrite_new(t_symbol *s, t_floatarg msec) | ||
98 | { | ||
99 | int nsamps; | ||
100 | t_sigdelwrite *x = (t_sigdelwrite *)pd_new(sigdelwrite_class); | ||
101 | if (!*s->s_name) s = gensym("delwrite~"); | ||
102 | pd_bind(&x->x_obj.ob_pd, s); | ||
103 | x->x_sym = s; | ||
104 | nsamps = msec * sys_getsr() * (float)(0.001f); | ||
105 | if (nsamps < 1) nsamps = 1; | ||
106 | nsamps += ((- nsamps) & (SAMPBLK - 1)); | ||
107 | nsamps += DEFDELVS; | ||
108 | x->x_cspace.c_n = nsamps; | ||
109 | x->x_cspace.c_vec = | ||
110 | (t_sample *)getbytes((nsamps + XTRASAMPS) * sizeof(float)); | ||
111 | x->x_cspace.c_phase = XTRASAMPS; | ||
112 | x->x_sortno = 0; | ||
113 | x->x_vecsize = 0; | ||
114 | x->x_f = 0; | ||
115 | return (x); | ||
116 | } | ||
117 | |||
118 | static t_int *sigdelwrite_perform(t_int *w) | ||
119 | { | ||
120 | t_sample *in = (t_sample *)(w[1]); | ||
121 | t_delwritectl *c = (t_delwritectl *)(w[2]); | ||
122 | int n = (int)(w[3]); | ||
123 | int phase = c->c_phase, nsamps = c->c_n; | ||
124 | t_sample *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS); | ||
125 | phase += n; | ||
126 | while (n--) | ||
127 | { | ||
128 | t_sample f = *in++; | ||
129 | if (PD_BADFLOAT(f)) | ||
130 | f = 0; | ||
131 | *bp++ = f; | ||
132 | if (bp == ep) | ||
133 | { | ||
134 | vp[0] = ep[-4]; | ||
135 | vp[1] = ep[-3]; | ||
136 | vp[2] = ep[-2]; | ||
137 | vp[3] = ep[-1]; | ||
138 | bp = vp + XTRASAMPS; | ||
139 | phase -= nsamps; | ||
140 | } | ||
141 | } | ||
142 | c->c_phase = phase; | ||
143 | return (w+4); | ||
144 | } | ||
145 | |||
146 | static void sigdelwrite_dsp(t_sigdelwrite *x, t_signal **sp) | ||
147 | { | ||
148 | dsp_add(sigdelwrite_perform, 3, sp[0]->s_vec, &x->x_cspace, sp[0]->s_n); | ||
149 | x->x_sortno = ugen_getsortno(); | ||
150 | sigdelwrite_checkvecsize(x, sp[0]->s_n); | ||
151 | } | ||
152 | |||
153 | static void sigdelwrite_free(t_sigdelwrite *x) | ||
154 | { | ||
155 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
156 | freebytes(x->x_cspace.c_vec, | ||
157 | (x->x_cspace.c_n + XTRASAMPS) * sizeof(float)); | ||
158 | } | ||
159 | |||
160 | void delwrite_tilde_setup(void) | ||
161 | { | ||
162 | sigdelwrite_class = class_new(gensym("delwrite~"), | ||
163 | (t_newmethod)sigdelwrite_new, (t_method)sigdelwrite_free, | ||
164 | sizeof(t_sigdelwrite), 0, A_DEFSYM, A_DEFFLOAT, 0); | ||
165 | CLASS_MAINSIGNALIN(sigdelwrite_class, t_sigdelwrite, x_f); | ||
166 | class_addmethod(sigdelwrite_class, (t_method)sigdelwrite_dsp, | ||
167 | gensym("dsp"), 0); | ||
168 | } | ||