diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_resample.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/d_resample.c | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_resample.c b/apps/plugins/pdbox/PDa/src/d_resample.c index 4e617ec4df..1aa672750d 100644 --- a/apps/plugins/pdbox/PDa/src/d_resample.c +++ b/apps/plugins/pdbox/PDa/src/d_resample.c | |||
@@ -223,228 +223,4 @@ void resampleto_dsp(t_resample *x, | |||
223 | 223 | ||
224 | return; | 224 | return; |
225 | } | 225 | } |
226 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
227 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
228 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
229 | |||
230 | /* upsampling/downsampling methods for inlet~/outlet~ | ||
231 | * | ||
232 | * mfg.gfd.uil | ||
233 | * IOhannes | ||
234 | * | ||
235 | * 2509:forum::für::umläute:2001 | ||
236 | */ | ||
237 | |||
238 | |||
239 | |||
240 | #include "m_pd.h" | ||
241 | |||
242 | /* --------------------- up/down-sampling --------------------- */ | ||
243 | t_int *downsampling_perform_0(t_int *w) | ||
244 | { | ||
245 | t_sample *in = (t_sample *)(w[1]); /* original signal */ | ||
246 | t_sample *out = (t_sample *)(w[2]); /* downsampled signal */ | ||
247 | int down = (int)(w[3]); /* downsampling factor */ | ||
248 | int parent = (int)(w[4]); /* original vectorsize */ | ||
249 | |||
250 | int n=parent/down; | ||
251 | |||
252 | while(n--){ | ||
253 | *out++=*in; | ||
254 | in+=down; | ||
255 | } | ||
256 | |||
257 | return (w+5); | ||
258 | } | ||
259 | |||
260 | t_int *upsampling_perform_0(t_int *w) | ||
261 | { | ||
262 | t_sample *in = (t_sample *)(w[1]); /* original signal */ | ||
263 | t_sample *out = (t_sample *)(w[2]); /* upsampled signal */ | ||
264 | int up = (int)(w[3]); /* upsampling factor */ | ||
265 | int parent = (int)(w[4]); /* original vectorsize */ | ||
266 | |||
267 | int n=parent*up; | ||
268 | t_sample *dummy = out; | ||
269 | |||
270 | while(n--)*out++=0; | ||
271 | |||
272 | n = parent; | ||
273 | out = dummy; | ||
274 | while(n--){ | ||
275 | *out=*in++; | ||
276 | out+=up; | ||
277 | } | ||
278 | |||
279 | return (w+5); | ||
280 | } | ||
281 | |||
282 | t_int *upsampling_perform_hold(t_int *w) | ||
283 | { | ||
284 | t_sample *in = (t_sample *)(w[1]); /* original signal */ | ||
285 | t_sample *out = (t_sample *)(w[2]); /* upsampled signal */ | ||
286 | int up = (int)(w[3]); /* upsampling factor */ | ||
287 | int parent = (int)(w[4]); /* original vectorsize */ | ||
288 | int i=up; | ||
289 | |||
290 | int n=parent; | ||
291 | t_sample *dum_out = out; | ||
292 | t_sample *dum_in = in; | ||
293 | |||
294 | while (i--) { | ||
295 | n = parent; | ||
296 | out = dum_out+i; | ||
297 | in = dum_in; | ||
298 | while(n--){ | ||
299 | *out=*in++; | ||
300 | out+=up; | ||
301 | } | ||
302 | } | ||
303 | return (w+5); | ||
304 | } | ||
305 | |||
306 | t_int *upsampling_perform_linear(t_int *w) | ||
307 | { | ||
308 | t_resample *x= (t_resample *)(w[1]); | ||
309 | t_sample *in = (t_sample *)(w[2]); /* original signal */ | ||
310 | t_sample *out = (t_sample *)(w[3]); /* upsampled signal */ | ||
311 | int up = (int)(w[4]); /* upsampling factor */ | ||
312 | int parent = (int)(w[5]); /* original vectorsize */ | ||
313 | int length = parent*up; | ||
314 | int n; | ||
315 | t_sample *fp; | ||
316 | t_sample a=*x->buffer, b=*in; | ||
317 | |||
318 | |||
319 | for (n=0; n<length; n++) { | ||
320 | t_float findex = (t_float)(n+1)/up; | ||
321 | int index = findex; | ||
322 | t_sample frac=findex - index; | ||
323 | if (frac==0.)frac=1.; | ||
324 | *out++ = frac * b + (1.-frac) * a; | ||
325 | fp = in+index; | ||
326 | b=*fp; | ||
327 | a=(index)?*(fp-1):a; | ||
328 | } | ||
329 | |||
330 | *x->buffer = a; | ||
331 | return (w+6); | ||
332 | } | ||
333 | |||
334 | /* ----------------------- public -------------------------------- */ | ||
335 | |||
336 | /* utils */ | ||
337 | |||
338 | void resample_init(t_resample *x) | ||
339 | { | ||
340 | x->method=0; | ||
341 | |||
342 | x->downsample=x->upsample=1; | ||
343 | |||
344 | x->s_n = x->coefsize = x->bufsize = 0; | ||
345 | x->s_vec = x->coeffs = x->buffer = 0; | ||
346 | } | ||
347 | |||
348 | void resample_free(t_resample *x) | ||
349 | { | ||
350 | if (x->s_n) t_freebytes(x->s_vec, x->s_n*sizeof(*x->s_vec)); | ||
351 | if (x->coefsize) t_freebytes(x->coeffs, x->coefsize*sizeof(*x->coeffs)); | ||
352 | if (x->bufsize) t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer)); | ||
353 | |||
354 | x->s_n = x->coefsize = x->bufsize = 0; | ||
355 | x->s_vec = x->coeffs = x->buffer = 0; | ||
356 | } | ||
357 | |||
358 | |||
359 | /* dsp-adding */ | ||
360 | |||
361 | void resample_dsp(t_resample *x, | ||
362 | t_sample* in, int insize, | ||
363 | t_sample* out, int outsize, | ||
364 | int method) | ||
365 | { | ||
366 | if (insize == outsize){ | ||
367 | bug("nothing to be done"); | ||
368 | return; | ||
369 | } | ||
370 | |||
371 | if (insize > outsize) { /* downsampling */ | ||
372 | if (insize % outsize) { | ||
373 | error("bad downsampling factor"); | ||
374 | return; | ||
375 | } | ||
376 | switch (method) { | ||
377 | default: | ||
378 | dsp_add(downsampling_perform_0, 4, in, out, insize/outsize, insize); | ||
379 | } | ||
380 | |||
381 | |||
382 | } else { /* upsampling */ | ||
383 | if (outsize % insize) { | ||
384 | error("bad upsampling factor"); | ||
385 | return; | ||
386 | } | ||
387 | switch (method) { | ||
388 | case 1: | ||
389 | dsp_add(upsampling_perform_hold, 4, in, out, outsize/insize, insize); | ||
390 | break; | ||
391 | case 2: | ||
392 | if (x->bufsize != 1) { | ||
393 | t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer)); | ||
394 | x->bufsize = 1; | ||
395 | x->buffer = t_getbytes(x->bufsize*sizeof(*x->buffer)); | ||
396 | } | ||
397 | dsp_add(upsampling_perform_linear, 5, x, in, out, outsize/insize, insize); | ||
398 | break; | ||
399 | default: | ||
400 | dsp_add(upsampling_perform_0, 4, in, out, outsize/insize, insize); | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | |||
405 | void resamplefrom_dsp(t_resample *x, | ||
406 | t_sample *in, | ||
407 | int insize, int outsize, int method) | ||
408 | { | ||
409 | if (insize==outsize) { | ||
410 | t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec)); | ||
411 | x->s_n = 0; | ||
412 | x->s_vec = in; | ||
413 | return; | ||
414 | } | ||
415 | |||
416 | if (x->s_n != outsize) { | ||
417 | t_sample *buf=x->s_vec; | ||
418 | t_freebytes(buf, x->s_n * sizeof(*buf)); | ||
419 | buf = (t_sample *)t_getbytes(outsize * sizeof(*buf)); | ||
420 | x->s_vec = buf; | ||
421 | x->s_n = outsize; | ||
422 | } | ||
423 | |||
424 | resample_dsp(x, in, insize, x->s_vec, x->s_n, method); | ||
425 | return; | ||
426 | } | ||
427 | |||
428 | void resampleto_dsp(t_resample *x, | ||
429 | t_sample *out, | ||
430 | int insize, int outsize, int method) | ||
431 | { | ||
432 | if (insize==outsize) { | ||
433 | if (x->s_n)t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec)); | ||
434 | x->s_n = 0; | ||
435 | x->s_vec = out; | ||
436 | return; | ||
437 | } | ||
438 | |||
439 | if (x->s_n != insize) { | ||
440 | t_sample *buf=x->s_vec; | ||
441 | t_freebytes(buf, x->s_n * sizeof(*buf)); | ||
442 | buf = (t_sample *)t_getbytes(insize * sizeof(*buf)); | ||
443 | x->s_vec = buf; | ||
444 | x->s_n = insize; | ||
445 | } | ||
446 | 226 | ||
447 | resample_dsp(x, x->s_vec, x->s_n, out, outsize, method); | ||
448 | |||
449 | return; | ||
450 | } | ||