summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/d_fft.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
commit526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch)
tree22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/d_fft.c
parent4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff)
downloadrockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz
rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_fft.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/d_fft.c343
1 files changed, 0 insertions, 343 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_fft.c b/apps/plugins/pdbox/PDa/src/d_fft.c
index 9916fdcb88..7b70561a0e 100644
--- a/apps/plugins/pdbox/PDa/src/d_fft.c
+++ b/apps/plugins/pdbox/PDa/src/d_fft.c
@@ -342,347 +342,4 @@ void d_fft_setup(void)
342 sigrifft_setup(); 342 sigrifft_setup();
343// sigframp_setup(); 343// sigframp_setup();
344} 344}
345/* Copyright (c) 1997-1999 Miller Puckette and others.
346* For information on usage and redistribution, and for a DISCLAIMER OF ALL
347* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
348
349#include "m_pd.h"
350
351/* ------------------------ fft~ and ifft~ -------------------------------- */
352static t_class *sigfft_class, *sigifft_class;
353
354typedef struct fft
355{
356 t_object x_obj;
357 float x_f;
358} t_sigfft;
359
360static void *sigfft_new(void)
361{
362 t_sigfft *x = (t_sigfft *)pd_new(sigfft_class);
363 outlet_new(&x->x_obj, gensym("signal"));
364 outlet_new(&x->x_obj, gensym("signal"));
365 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
366 x->x_f = 0;
367 return (x);
368}
369
370static void *sigifft_new(void)
371{
372 t_sigfft *x = (t_sigfft *)pd_new(sigifft_class);
373 outlet_new(&x->x_obj, gensym("signal"));
374 outlet_new(&x->x_obj, gensym("signal"));
375 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
376 x->x_f = 0;
377 return (x);
378}
379
380static t_int *sigfft_swap(t_int *w)
381{
382 t_sample *in1 = (t_sample *)(w[1]);
383 t_sample *in2 = (t_sample *)(w[2]);
384 int n = w[3];
385 for (;n--; in1++, in2++)
386 {
387 float f = *in1;
388 *in1 = *in2;
389 *in2 = f;
390 }
391 return (w+4);
392}
393
394static t_int *sigfft_perform(t_int *w)
395{
396 t_sample *in1 = (t_sample *)(w[1]);
397 t_sample *in2 = (t_sample *)(w[2]);
398 int n = w[3];
399 mayer_fft(n, in1, in2);
400 return (w+4);
401}
402
403static t_int *sigifft_perform(t_int *w)
404{
405 t_sample *in1 = (t_sample *)(w[1]);
406 t_sample *in2 = (t_sample *)(w[2]);
407 int n = w[3];
408 mayer_ifft(n, in1, in2);
409 return (w+4);
410}
411
412static void sigfft_dspx(t_sigfft *x, t_signal **sp, t_int *(*f)(t_int *w))
413{
414 int n = sp[0]->s_n;
415 t_sample *in1 = sp[0]->s_vec;
416 t_sample *in2 = sp[1]->s_vec;
417 t_sample *out1 = sp[2]->s_vec;
418 t_sample *out2 = sp[3]->s_vec;
419 if (out1 == in2 && out2 == in1)
420 dsp_add(sigfft_swap, 3, out1, out2, n);
421 else if (out1 == in2)
422 {
423 dsp_add(copy_perform, 3, in2, out2, n);
424 dsp_add(copy_perform, 3, in1, out1, n);
425 }
426 else
427 {
428 if (out1 != in1) dsp_add(copy_perform, 3, in1, out1, n);
429 if (out2 != in2) dsp_add(copy_perform, 3, in2, out2, n);
430 }
431 dsp_add(f, 3, sp[2]->s_vec, sp[3]->s_vec, n);
432}
433
434static void sigfft_dsp(t_sigfft *x, t_signal **sp)
435{
436 sigfft_dspx(x, sp, sigfft_perform);
437}
438
439static void sigifft_dsp(t_sigfft *x, t_signal **sp)
440{
441 sigfft_dspx(x, sp, sigifft_perform);
442}
443
444static void sigfft_setup(void)
445{
446 sigfft_class = class_new(gensym("fft~"), sigfft_new, 0,
447 sizeof(t_sigfft), 0, 0);
448 CLASS_MAINSIGNALIN(sigfft_class, t_sigfft, x_f);
449 class_addmethod(sigfft_class, (t_method)sigfft_dsp, gensym("dsp"), 0);
450
451 sigifft_class = class_new(gensym("ifft~"), sigifft_new, 0,
452 sizeof(t_sigfft), 0, 0);
453 CLASS_MAINSIGNALIN(sigifft_class, t_sigfft, x_f);
454 class_addmethod(sigifft_class, (t_method)sigifft_dsp, gensym("dsp"), 0);
455 class_sethelpsymbol(sigifft_class, gensym("fft~"));
456}
457
458/* ----------------------- rfft~ -------------------------------- */
459
460static t_class *sigrfft_class;
461
462typedef struct rfft
463{
464 t_object x_obj;
465 float x_f;
466} t_sigrfft;
467
468static void *sigrfft_new(void)
469{
470 t_sigrfft *x = (t_sigrfft *)pd_new(sigrfft_class);
471 outlet_new(&x->x_obj, gensym("signal"));
472 outlet_new(&x->x_obj, gensym("signal"));
473 x->x_f = 0;
474 return (x);
475}
476
477static t_int *sigrfft_flip(t_int *w)
478{
479 t_sample *in = (t_sample *)(w[1]);
480 t_sample *out = (t_sample *)(w[2]);
481 int n = w[3];
482 while (n--) *(--out) = *in++;
483 *(--out) = 0; /* to hell with it */
484 return (w+4);
485}
486 345
487static t_int *sigrfft_perform(t_int *w)
488{
489 t_sample *in = (t_sample *)(w[1]);
490 int n = w[2];
491 mayer_realfft(n, in);
492 return (w+3);
493}
494
495static void sigrfft_dsp(t_sigrfft *x, t_signal **sp)
496{
497 int n = sp[0]->s_n, n2 = (n>>1);
498 t_sample *in1 = sp[0]->s_vec;
499 t_sample *out1 = sp[1]->s_vec;
500 t_sample *out2 = sp[2]->s_vec;
501 if (n < 4)
502 {
503 error("fft: minimum 4 points");
504 return;
505 }
506 if (in1 == out2) /* this probably never happens */
507 {
508 dsp_add(sigrfft_perform, 2, out2, n);
509 dsp_add(copy_perform, 3, out2, out1, n2);
510 dsp_add(sigrfft_flip, 3, out2 + (n2+1), out2 + n2, n2-1);
511 }
512 else
513 {
514 if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n);
515 dsp_add(sigrfft_perform, 2, out1, n);
516 dsp_add(sigrfft_flip, 3, out1 + (n2+1), out2 + n2, n2-1);
517 }
518 dsp_add_zero(out1 + n2, n2);
519 dsp_add_zero(out2 + n2, n2);
520}
521
522static void sigrfft_setup(void)
523{
524 sigrfft_class = class_new(gensym("rfft~"), sigrfft_new, 0,
525 sizeof(t_sigrfft), 0, 0);
526 CLASS_MAINSIGNALIN(sigrfft_class, t_sigrfft, x_f);
527 class_addmethod(sigrfft_class, (t_method)sigrfft_dsp, gensym("dsp"), 0);
528 class_sethelpsymbol(sigrfft_class, gensym("fft~"));
529}
530
531/* ----------------------- rifft~ -------------------------------- */
532
533static t_class *sigrifft_class;
534
535typedef struct rifft
536{
537 t_object x_obj;
538 float x_f;
539} t_sigrifft;
540
541static void *sigrifft_new(void)
542{
543 t_sigrifft *x = (t_sigrifft *)pd_new(sigrifft_class);
544 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
545 outlet_new(&x->x_obj, gensym("signal"));
546 x->x_f = 0;
547 return (x);
548}
549
550static t_int *sigrifft_perform(t_int *w)
551{
552 t_sample *in = (t_sample *)(w[1]);
553 int n = w[2];
554 mayer_realifft(n, in);
555 return (w+3);
556}
557
558static void sigrifft_dsp(t_sigrifft *x, t_signal **sp)
559{
560 int n = sp[0]->s_n, n2 = (n>>1);
561 t_sample *in1 = sp[0]->s_vec;
562 t_sample *in2 = sp[1]->s_vec;
563 t_sample *out1 = sp[2]->s_vec;
564 if (n < 4)
565 {
566 error("fft: minimum 4 points");
567 return;
568 }
569 if (in2 == out1)
570 {
571 dsp_add(sigrfft_flip, 3, out1+1, out1 + n, (n2-1));
572 dsp_add(copy_perform, 3, in1, out1, n2);
573 }
574 else
575 {
576 if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n2);
577 dsp_add(sigrfft_flip, 3, in2+1, out1 + n, n2-1);
578 }
579 dsp_add(sigrifft_perform, 2, out1, n);
580}
581
582static void sigrifft_setup(void)
583{
584 sigrifft_class = class_new(gensym("rifft~"), sigrifft_new, 0,
585 sizeof(t_sigrifft), 0, 0);
586 CLASS_MAINSIGNALIN(sigrifft_class, t_sigrifft, x_f);
587 class_addmethod(sigrifft_class, (t_method)sigrifft_dsp, gensym("dsp"), 0);
588 class_sethelpsymbol(sigrifft_class, gensym("fft~"));
589}
590
591/* ----------------------- framp~ -------------------------------- */
592
593#if 0
594static t_class *sigframp_class;
595
596typedef struct framp
597{
598 t_object x_obj;
599 float x_f;
600} t_sigframp;
601
602static void *sigframp_new(void)
603{
604 t_sigframp *x = (t_sigframp *)pd_new(sigframp_class);
605 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
606 outlet_new(&x->x_obj, gensym("signal"));
607 outlet_new(&x->x_obj, gensym("signal"));
608 x->x_f = 0;
609 return (x);
610}
611
612static t_int *sigframp_perform(t_int *w)
613{
614 float *inreal = (t_float *)(w[1]);
615 float *inimag = (t_float *)(w[2]);
616 float *outfreq = (t_float *)(w[3]);
617 float *outamp = (t_float *)(w[4]);
618 float lastreal = 0, currentreal = inreal[0], nextreal = inreal[1];
619 float lastimag = 0, currentimag = inimag[0], nextimag = inimag[1];
620 int n = w[5];
621 int m = n + 1;
622 float fbin = 1, oneovern2 = 1.f/((float)n * (float)n);
623
624 inreal += 2;
625 inimag += 2;
626 *outamp++ = *outfreq++ = 0;
627 n -= 2;
628 while (n--)
629 {
630 float re, im, pow, freq;
631 lastreal = currentreal;
632 currentreal = nextreal;
633 nextreal = *inreal++;
634 lastimag = currentimag;
635 currentimag = nextimag;
636 nextimag = *inimag++;
637 re = currentreal - 0.5f * (lastreal + nextreal);
638 im = currentimag - 0.5f * (lastimag + nextimag);
639 pow = re * re + im * im;
640 if (pow > 1e-19)
641 {
642 float detune = ((lastreal - nextreal) * re +
643 (lastimag - nextimag) * im) / (2.0f * pow);
644 if (detune > 2 || detune < -2) freq = pow = 0;
645 else freq = fbin + detune;
646 }
647 else freq = pow = 0;
648 *outfreq++ = freq;
649 *outamp++ = oneovern2 * pow;
650 fbin += 1.0f;
651 }
652 while (m--) *outamp++ = *outfreq++ = 0;
653 return (w+6);
654}
655
656t_int *sigsqrt_perform(t_int *w);
657
658static void sigframp_dsp(t_sigframp *x, t_signal **sp)
659{
660 int n = sp[0]->s_n, n2 = (n>>1);
661 if (n < 4)
662 {
663 error("framp: minimum 4 points");
664 return;
665 }
666 dsp_add(sigframp_perform, 5, sp[0]->s_vec, sp[1]->s_vec,
667 sp[2]->s_vec, sp[3]->s_vec, n2);
668 dsp_add(sigsqrt_perform, 3, sp[3]->s_vec, sp[3]->s_vec, n2);
669}
670
671static void sigframp_setup(void)
672{
673 sigframp_class = class_new(gensym("framp~"), sigframp_new, 0,
674 sizeof(t_sigframp), 0, 0);
675 CLASS_MAINSIGNALIN(sigframp_class, t_sigframp, x_f);
676 class_addmethod(sigframp_class, (t_method)sigframp_dsp, gensym("dsp"), 0);
677}
678#endif
679
680/* ------------------------ global setup routine ------------------------- */
681
682void d_fft_setup(void)
683{
684 sigfft_setup();
685 sigrfft_setup();
686 sigrifft_setup();
687// sigframp_setup();
688}