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/delread~.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/delread~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/delread~.c | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/delread~.c b/apps/plugins/pdbox/PDa/intern/delread~.c new file mode 100644 index 0000000000..b0a58393be --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/delread~.c | |||
@@ -0,0 +1,200 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | #include "delay.h" | ||
4 | |||
5 | extern int ugen_getsortno(void); | ||
6 | |||
7 | #define DEFDELVS 64 /* LATER get this from canvas at DSP time */ | ||
8 | static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */ | ||
9 | |||
10 | static t_class *sigdelread_class; | ||
11 | |||
12 | typedef struct _sigdelread | ||
13 | { | ||
14 | t_object x_obj; | ||
15 | t_symbol *x_sym; | ||
16 | t_float x_deltime; /* delay in msec */ | ||
17 | int x_delsamps; /* delay in samples */ | ||
18 | t_float x_sr; /* samples per msec */ | ||
19 | t_float x_n; /* vector size */ | ||
20 | int x_zerodel; /* 0 or vecsize depending on read/write order */ | ||
21 | } t_sigdelread; | ||
22 | |||
23 | static void sigdelread_float(t_sigdelread *x, t_float f); | ||
24 | |||
25 | static void *sigdelread_new(t_symbol *s, t_floatarg f) | ||
26 | { | ||
27 | t_sigdelread *x = (t_sigdelread *)pd_new(sigdelread_class); | ||
28 | x->x_sym = s; | ||
29 | x->x_sr = 1; | ||
30 | x->x_n = 1; | ||
31 | x->x_zerodel = 0; | ||
32 | sigdelread_float(x, f); | ||
33 | outlet_new(&x->x_obj, &s_signal); | ||
34 | return (x); | ||
35 | } | ||
36 | |||
37 | static void sigdelread_float(t_sigdelread *x, t_float f) | ||
38 | { | ||
39 | int samps; | ||
40 | t_sigdelwrite *delwriter = | ||
41 | (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class); | ||
42 | x->x_deltime = f; | ||
43 | if (delwriter) | ||
44 | { | ||
45 | int delsize = delwriter->x_cspace.c_n; | ||
46 | x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime) | ||
47 | + x->x_n - x->x_zerodel; | ||
48 | if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n; | ||
49 | else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS) | ||
50 | x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | static t_int *sigdelread_perform(t_int *w) | ||
55 | { | ||
56 | t_sample *out = (t_sample *)(w[1]); | ||
57 | t_delwritectl *c = (t_delwritectl *)(w[2]); | ||
58 | int delsamps = *(int *)(w[3]); | ||
59 | int n = (int)(w[4]); | ||
60 | int phase = c->c_phase - delsamps, nsamps = c->c_n; | ||
61 | t_sample *vp = c->c_vec, *bp, *ep = vp + (c->c_n + XTRASAMPS); | ||
62 | |||
63 | if (phase < 0) phase += nsamps; | ||
64 | bp = vp + phase; | ||
65 | while (n--) | ||
66 | { | ||
67 | *out++ = *bp++; | ||
68 | if (bp == ep) bp -= nsamps; | ||
69 | } | ||
70 | return (w+5); | ||
71 | } | ||
72 | |||
73 | static void sigdelread_dsp(t_sigdelread *x, t_signal **sp) | ||
74 | { | ||
75 | t_sigdelwrite *delwriter = | ||
76 | (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class); | ||
77 | x->x_sr = sp[0]->s_sr * 0.001; | ||
78 | x->x_n = sp[0]->s_n; | ||
79 | if (delwriter) | ||
80 | { | ||
81 | sigdelwrite_checkvecsize(delwriter, sp[0]->s_n); | ||
82 | x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ? | ||
83 | 0 : delwriter->x_vecsize); | ||
84 | sigdelread_float(x, x->x_deltime); | ||
85 | dsp_add(sigdelread_perform, 4, | ||
86 | sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n); | ||
87 | } | ||
88 | else if (*x->x_sym->s_name) | ||
89 | error("delread~: %s: no such delwrite~",x->x_sym->s_name); | ||
90 | } | ||
91 | |||
92 | void delread_tilde_setup(void) | ||
93 | { | ||
94 | sigdelread_class = class_new(gensym("delread~"), | ||
95 | (t_newmethod)sigdelread_new, 0, | ||
96 | sizeof(t_sigdelread), 0, A_DEFSYM, A_DEFFLOAT, 0); | ||
97 | class_addmethod(sigdelread_class, (t_method)sigdelread_dsp, | ||
98 | gensym("dsp"), 0); | ||
99 | class_addfloat(sigdelread_class, (t_method)sigdelread_float); | ||
100 | } | ||
101 | #include <m_pd.h> | ||
102 | #include <m_fixed.h> | ||
103 | #include "delay.h" | ||
104 | |||
105 | extern int ugen_getsortno(void); | ||
106 | |||
107 | #define DEFDELVS 64 /* LATER get this from canvas at DSP time */ | ||
108 | static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */ | ||
109 | |||
110 | static t_class *sigdelread_class; | ||
111 | |||
112 | typedef struct _sigdelread | ||
113 | { | ||
114 | t_object x_obj; | ||
115 | t_symbol *x_sym; | ||
116 | t_float x_deltime; /* delay in msec */ | ||
117 | int x_delsamps; /* delay in samples */ | ||
118 | t_float x_sr; /* samples per msec */ | ||
119 | t_float x_n; /* vector size */ | ||
120 | int x_zerodel; /* 0 or vecsize depending on read/write order */ | ||
121 | } t_sigdelread; | ||
122 | |||
123 | static void sigdelread_float(t_sigdelread *x, t_float f); | ||
124 | |||
125 | static void *sigdelread_new(t_symbol *s, t_floatarg f) | ||
126 | { | ||
127 | t_sigdelread *x = (t_sigdelread *)pd_new(sigdelread_class); | ||
128 | x->x_sym = s; | ||
129 | x->x_sr = 1; | ||
130 | x->x_n = 1; | ||
131 | x->x_zerodel = 0; | ||
132 | sigdelread_float(x, f); | ||
133 | outlet_new(&x->x_obj, &s_signal); | ||
134 | return (x); | ||
135 | } | ||
136 | |||
137 | static void sigdelread_float(t_sigdelread *x, t_float f) | ||
138 | { | ||
139 | int samps; | ||
140 | t_sigdelwrite *delwriter = | ||
141 | (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class); | ||
142 | x->x_deltime = f; | ||
143 | if (delwriter) | ||
144 | { | ||
145 | int delsize = delwriter->x_cspace.c_n; | ||
146 | x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime) | ||
147 | + x->x_n - x->x_zerodel; | ||
148 | if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n; | ||
149 | else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS) | ||
150 | x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | static t_int *sigdelread_perform(t_int *w) | ||
155 | { | ||
156 | t_sample *out = (t_sample *)(w[1]); | ||
157 | t_delwritectl *c = (t_delwritectl *)(w[2]); | ||
158 | int delsamps = *(int *)(w[3]); | ||
159 | int n = (int)(w[4]); | ||
160 | int phase = c->c_phase - delsamps, nsamps = c->c_n; | ||
161 | t_sample *vp = c->c_vec, *bp, *ep = vp + (c->c_n + XTRASAMPS); | ||
162 | |||
163 | if (phase < 0) phase += nsamps; | ||
164 | bp = vp + phase; | ||
165 | while (n--) | ||
166 | { | ||
167 | *out++ = *bp++; | ||
168 | if (bp == ep) bp -= nsamps; | ||
169 | } | ||
170 | return (w+5); | ||
171 | } | ||
172 | |||
173 | static void sigdelread_dsp(t_sigdelread *x, t_signal **sp) | ||
174 | { | ||
175 | t_sigdelwrite *delwriter = | ||
176 | (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class); | ||
177 | x->x_sr = sp[0]->s_sr * 0.001; | ||
178 | x->x_n = sp[0]->s_n; | ||
179 | if (delwriter) | ||
180 | { | ||
181 | sigdelwrite_checkvecsize(delwriter, sp[0]->s_n); | ||
182 | x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ? | ||
183 | 0 : delwriter->x_vecsize); | ||
184 | sigdelread_float(x, x->x_deltime); | ||
185 | dsp_add(sigdelread_perform, 4, | ||
186 | sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n); | ||
187 | } | ||
188 | else if (*x->x_sym->s_name) | ||
189 | error("delread~: %s: no such delwrite~",x->x_sym->s_name); | ||
190 | } | ||
191 | |||
192 | void delread_tilde_setup(void) | ||
193 | { | ||
194 | sigdelread_class = class_new(gensym("delread~"), | ||
195 | (t_newmethod)sigdelread_new, 0, | ||
196 | sizeof(t_sigdelread), 0, A_DEFSYM, A_DEFFLOAT, 0); | ||
197 | class_addmethod(sigdelread_class, (t_method)sigdelread_dsp, | ||
198 | gensym("dsp"), 0); | ||
199 | class_addfloat(sigdelread_class, (t_method)sigdelread_float); | ||
200 | } | ||