1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
/*
xsample - extended sample objects for Max/MSP and pd (pure data)
Copyright (c) 2001-2003 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
#ifndef __INTER_H
#define __INTER_H
TMPLDEF V xinter::st_play0(const S *bdt,const I smin,const I smax,const F s2u,const I n,const I inchns,const I outchns,S *const *invecs,S *const *outvecs)
{
// stopped
SIGCHNS(BCHNS,inchns,OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
for(I ci = 0; ci < outchns; ++ci)
for(I si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::st_play1(const S *bdt,const I smin,const I smax,const F s2u,const I n,const I inchns,const I outchns,S *const *invecs,S *const *outvecs)
{
SIGCHNS(BCHNS,inchns,OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
// no interpolation
// ----------------
for(I i = 0; i < n; ++i,++si) {
register const I oint = (I)(*(pos++)/s2u);
register const S *fp;
if(oint < smin) {
// position < 0 ... take only 0th sample
fp = bdt+smin*BCHNS;
}
else if(oint >= smax) {
// position > last sample ... take only last sample
fp = bdt+(smax-1)*BCHNS;
}
else {
// normal
fp = bdt+oint*BCHNS;
}
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::st_play2(const S *bdt,const I smin,const I smax,const F s2u,const I n,const I inchns,const I outchns,S *const *invecs,S *const *outvecs)
{
const I plen = smax-smin; //curlen;
if(plen < 2) {
st_play1 TMPLCALL (bdt,smin,smax,s2u,n,inchns,outchns,invecs,outvecs);
return;
}
SIGCHNS(BCHNS,inchns,OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
// linear interpolation
// --------------------
const I maxo = smax-1; // last sample in buffer
for(I i = 0; i < n; ++i,++si) {
const F o = *(pos++)/s2u;
register const I oint = (I)o;
if(oint < smin) {
// position is before first sample -> take the first sample
register const S *const fp = bdt+smin*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
else if(oint >= maxo) {
// position is past last sample -> take the last sample
register const S *const fp = bdt+maxo*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
else {
// normal interpolation
register const F frac = o-oint;
register const S *const fp0 = bdt+oint*BCHNS;
register const S *const fp1 = fp0+BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp0[ci]+frac*(fp1[ci]-fp0[ci]);
}
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::st_play4(const S *bdt,const I smin,const I smax,const F s2u,const I n,const I inchns,const I outchns,S *const *invecs,S *const *outvecs)
{
const I plen = smax-smin; //curlen;
if(plen < 4) {
if(plen < 2) st_play1 TMPLCALL (bdt,smin,smax,s2u,n,inchns,outchns,invecs,outvecs);
else st_play2 TMPLCALL (bdt,smin,smax,s2u,n,inchns,outchns,invecs,outvecs);
return;
}
SIGCHNS(BCHNS,inchns,OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
// 4-point interpolation
// ---------------------
const I maxo = smax-1; // last sample in play region
for(I i = 0; i < n; ++i,++si) {
F o = *(pos++)/s2u;
register I oint = (I)o,ointm,oint1,oint2;
if(oint <= smin) {
if(oint < smin) oint = smin,o = smin;
// position is first simple
ointm = smin; // first sample
oint1 = oint+1;
oint2 = oint1+1;
}
else if(oint >= maxo-2) {
if(oint > maxo) oint = maxo,o = smax;
ointm = oint-1;
oint1 = oint >= maxo?maxo:oint+1;
oint2 = oint1 >= maxo?maxo:oint1+1;
}
else {
ointm = oint-1;
oint1 = oint+1;
oint2 = oint1+1;
}
register F frac = o-oint;
register const S *fa = bdt+ointm*BCHNS;
register const S *fb = bdt+oint*BCHNS;
register const S *fc = bdt+oint1*BCHNS;
register const S *fd = bdt+oint2*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci) {
const F cmb = fc[ci]-fb[ci];
sig[ci][si] = fb[ci] + frac*(
cmb - 0.5f*(frac-1.) * ((fa[ci]-fd[ci]+3.0f*cmb)*frac + (fb[ci]-fa[ci]-cmb))
);
}
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
#if 0
TMPLDEF V xinter::s_play0(I n,S *const *invecs,S *const *outvecs)
{
// stopped
SIGCHNS(BCHNS,buf->Channels(),OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
for(I ci = 0; ci < outchns; ++ci)
for(I si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::s_play4(I n,S *const *invecs,S *const *outvecs)
{
const I smin = curmin,smax = curmax,plen = smax-smin; //curlen;
if(plen < 4) {
if(plen < 2) s_play1 TMPLCALL (n,invecs,outvecs);
else s_play2 TMPLCALL (n,invecs,outvecs);
return;
}
SIGCHNS(BCHNS,buf->Channels(),OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
const S *bdt = buf->Data();
// 4-point interpolation
// ---------------------
const I maxo = smax-1; // last sample in play region
for(I i = 0; i < n; ++i,++si) {
F o = *(pos++)/s2u;
register I oint = (I)o,ointm,oint1,oint2;
if(oint <= smin) {
if(oint < smin) oint = smin,o = smin;
// position is first simple
ointm = smin; // first sample
oint1 = oint+1;
oint2 = oint1+1;
}
else if(oint >= maxo-2) {
if(oint > maxo) oint = maxo,o = smax;
ointm = oint-1;
oint1 = oint >= maxo?maxo:oint+1;
oint2 = oint1 >= maxo?maxo:oint1+1;
}
else {
ointm = oint-1;
oint1 = oint+1;
oint2 = oint1+1;
}
register F frac = o-oint;
register const S *fa = bdt+ointm*BCHNS;
register const S *fb = bdt+oint*BCHNS;
register const S *fc = bdt+oint1*BCHNS;
register const S *fd = bdt+oint2*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci) {
const F cmb = fc[ci]-fb[ci];
sig[ci][si] = fb[ci] + frac*(
cmb - 0.5f*(frac-1.) * ((fa[ci]-fd[ci]+3.0f*cmb)*frac + (fb[ci]-fa[ci]-cmb))
);
}
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::s_play2(I n,S *const *invecs,S *const *outvecs)
{
const I smin = curmin,smax = curmax,plen = smax-smin; //curlen;
if(plen < 2) {
s_play1 TMPLCALL (n,invecs,outvecs);
return;
}
SIGCHNS(BCHNS,buf->Channels(),OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
// linear interpolation
// --------------------
const I maxo = smax-1; // last sample in buffer
const S *bdt = buf->Data();
for(I i = 0; i < n; ++i,++si) {
const F o = *(pos++)/s2u;
register const I oint = (I)o;
if(oint < smin) {
// position is before first sample -> take the first sample
register const S *const fp = bdt+smin*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
else if(oint >= maxo) {
// position is past last sample -> take the last sample
register const S *const fp = bdt+maxo*BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
else {
// normal interpolation
register const F frac = o-oint;
register const S *const fp0 = bdt+oint*BCHNS;
register const S *const fp1 = fp0+BCHNS;
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp0[ci]+frac*(fp1[ci]-fp0[ci]);
}
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
TMPLDEF V xinter::s_play1(I n,S *const *invecs,S *const *outvecs)
{
SIGCHNS(BCHNS,buf->Channels(),OCHNS,outchns);
const S *pos = invecs[0];
S *const *sig = outvecs;
register I si = 0;
const I smin = curmin,smax = curmax;
const S *bdt = buf->Data();
// no interpolation
// ----------------
for(I i = 0; i < n; ++i,++si) {
register const I oint = (I)(*(pos++)/s2u);
register const S *fp;
if(oint < smin) {
// position < 0 ... take only 0th sample
fp = bdt+smin*BCHNS;
}
else if(oint >= smax) {
// position > last sample ... take only last sample
fp = bdt+(smax-1)*BCHNS;
}
else {
// normal
fp = bdt+oint*BCHNS;
}
for(I ci = 0; ci < OCHNS; ++ci)
sig[ci][si] = fp[ci];
}
// clear rest of output channels (if buffer has less channels)
for(I ci = OCHNS; ci < outchns; ++ci)
for(si = 0; si < n; ++si) sig[ci][si] = 0;
}
#else
TMPLDEF V xinter::s_play0(I n,S *const *invecs,S *const *outvecs)
{
st_play0 TMPLCALL (buf->Data(),curmin,curmax,s2u,n,buf->Channels(),outchns,invecs,outvecs);
}
TMPLDEF V xinter::s_play1(I n,S *const *invecs,S *const *outvecs)
{
st_play1 TMPLCALL (buf->Data(),curmin,curmax,s2u,n,buf->Channels(),outchns,invecs,outvecs);
}
TMPLDEF V xinter::s_play2(I n,S *const *invecs,S *const *outvecs)
{
st_play2 TMPLCALL (buf->Data(),curmin,curmax,s2u,n,buf->Channels(),outchns,invecs,outvecs);
}
TMPLDEF V xinter::s_play4(I n,S *const *invecs,S *const *outvecs)
{
st_play4 TMPLCALL (buf->Data(),curmin,curmax,s2u,n,buf->Channels(),outchns,invecs,outvecs);
}
#endif
#endif
|