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