summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/delread~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/delread~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/delread~.c200
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
5extern int ugen_getsortno(void);
6
7#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
8static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */
9
10static t_class *sigdelread_class;
11
12typedef 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
23static void sigdelread_float(t_sigdelread *x, t_float f);
24
25static 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
37static 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
54static 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
73static 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
92void 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
105extern int ugen_getsortno(void);
106
107#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
108static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */
109
110static t_class *sigdelread_class;
111
112typedef 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
123static void sigdelread_float(t_sigdelread *x, t_float f);
124
125static 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
137static 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
154static 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
173static 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
192void 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}