diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/d_osc.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-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_osc.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/d_osc.c | 535 |
1 files changed, 0 insertions, 535 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_osc.c b/apps/plugins/pdbox/PDa/src/d_osc.c index 8a3486d981..35b43b82c6 100644 --- a/apps/plugins/pdbox/PDa/src/d_osc.c +++ b/apps/plugins/pdbox/PDa/src/d_osc.c | |||
@@ -533,538 +533,3 @@ void d_osc_setup(void) | |||
533 | noise_setup(); | 533 | noise_setup(); |
534 | } | 534 | } |
535 | 535 | ||
536 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
537 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
538 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
539 | |||
540 | /* sinusoidal oscillator and table lookup; see also tabosc4~ in d_array.c. | ||
541 | */ | ||
542 | |||
543 | #include "m_pd.h" | ||
544 | #include "math.h" | ||
545 | |||
546 | #define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */ | ||
547 | |||
548 | /* machine-dependent definitions. These ifdefs really | ||
549 | should have been by CPU type and not by operating system! */ | ||
550 | #ifdef IRIX | ||
551 | /* big-endian. Most significant byte is at low address in memory */ | ||
552 | #define HIOFFSET 0 /* word offset to find MSB */ | ||
553 | #define LOWOFFSET 1 /* word offset to find LSB */ | ||
554 | #define int32 long /* a data type that has 32 bits */ | ||
555 | #else | ||
556 | #ifdef MSW | ||
557 | /* little-endian; most significant byte is at highest address */ | ||
558 | #define HIOFFSET 1 | ||
559 | #define LOWOFFSET 0 | ||
560 | #define int32 long | ||
561 | #else | ||
562 | #ifdef __FreeBSD__ | ||
563 | #include <machine/endian.h> | ||
564 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
565 | #define HIOFFSET 1 | ||
566 | #define LOWOFFSET 0 | ||
567 | #else | ||
568 | #define HIOFFSET 0 /* word offset to find MSB */ | ||
569 | #define LOWOFFSET 1 /* word offset to find LSB */ | ||
570 | #endif /* BYTE_ORDER */ | ||
571 | #include <sys/types.h> | ||
572 | #define int32 int32_t | ||
573 | #endif | ||
574 | #ifdef __linux__ | ||
575 | |||
576 | #include <endian.h> | ||
577 | |||
578 | #if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN) | ||
579 | #error No byte order defined | ||
580 | #endif | ||
581 | |||
582 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
583 | #define HIOFFSET 1 | ||
584 | #define LOWOFFSET 0 | ||
585 | #else | ||
586 | #define HIOFFSET 0 /* word offset to find MSB */ | ||
587 | #define LOWOFFSET 1 /* word offset to find LSB */ | ||
588 | #endif /* __BYTE_ORDER */ | ||
589 | |||
590 | #include <sys/types.h> | ||
591 | #define int32 int32_t | ||
592 | |||
593 | #else | ||
594 | #ifdef MACOSX | ||
595 | #define HIOFFSET 0 /* word offset to find MSB */ | ||
596 | #define LOWOFFSET 1 /* word offset to find LSB */ | ||
597 | #define int32 int /* a data type that has 32 bits */ | ||
598 | |||
599 | #endif /* MACOSX */ | ||
600 | #endif /* __linux__ */ | ||
601 | #endif /* MSW */ | ||
602 | #endif /* SGI */ | ||
603 | |||
604 | union tabfudge | ||
605 | { | ||
606 | double tf_d; | ||
607 | int32 tf_i[2]; | ||
608 | }; | ||
609 | |||
610 | |||
611 | /* -------------------------- phasor~ ------------------------------ */ | ||
612 | static t_class *phasor_class, *scalarphasor_class; | ||
613 | |||
614 | #if 1 /* in the style of R. Hoeldrich (ICMC 1995 Banff) */ | ||
615 | |||
616 | typedef struct _phasor | ||
617 | { | ||
618 | t_object x_obj; | ||
619 | double x_phase; | ||
620 | float x_conv; | ||
621 | float x_f; /* scalar frequency */ | ||
622 | } t_phasor; | ||
623 | |||
624 | static void *phasor_new(t_floatarg f) | ||
625 | { | ||
626 | t_phasor *x = (t_phasor *)pd_new(phasor_class); | ||
627 | x->x_f = f; | ||
628 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); | ||
629 | x->x_phase = 0; | ||
630 | x->x_conv = 0; | ||
631 | outlet_new(&x->x_obj, gensym("signal")); | ||
632 | return (x); | ||
633 | } | ||
634 | |||
635 | static t_int *phasor_perform(t_int *w) | ||
636 | { | ||
637 | t_phasor *x = (t_phasor *)(w[1]); | ||
638 | t_float *in = (t_float *)(w[2]); | ||
639 | t_float *out = (t_float *)(w[3]); | ||
640 | int n = (int)(w[4]); | ||
641 | double dphase = x->x_phase + UNITBIT32; | ||
642 | union tabfudge tf; | ||
643 | int normhipart; | ||
644 | float conv = x->x_conv; | ||
645 | |||
646 | tf.tf_d = UNITBIT32; | ||
647 | normhipart = tf.tf_i[HIOFFSET]; | ||
648 | tf.tf_d = dphase; | ||
649 | |||
650 | while (n--) | ||
651 | { | ||
652 | tf.tf_i[HIOFFSET] = normhipart; | ||
653 | dphase += *in++ * conv; | ||
654 | *out++ = tf.tf_d - UNITBIT32; | ||
655 | tf.tf_d = dphase; | ||
656 | } | ||
657 | tf.tf_i[HIOFFSET] = normhipart; | ||
658 | x->x_phase = tf.tf_d - UNITBIT32; | ||
659 | return (w+5); | ||
660 | } | ||
661 | |||
662 | static void phasor_dsp(t_phasor *x, t_signal **sp) | ||
663 | { | ||
664 | x->x_conv = 1./sp[0]->s_sr; | ||
665 | dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
666 | } | ||
667 | |||
668 | static void phasor_ft1(t_phasor *x, t_float f) | ||
669 | { | ||
670 | x->x_phase = f; | ||
671 | } | ||
672 | |||
673 | static void phasor_setup(void) | ||
674 | { | ||
675 | phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0, | ||
676 | sizeof(t_phasor), 0, A_DEFFLOAT, 0); | ||
677 | CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f); | ||
678 | class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0); | ||
679 | class_addmethod(phasor_class, (t_method)phasor_ft1, | ||
680 | gensym("ft1"), A_FLOAT, 0); | ||
681 | } | ||
682 | |||
683 | #endif /* Hoeldrich version */ | ||
684 | |||
685 | /* ------------------------ cos~ ----------------------------- */ | ||
686 | |||
687 | float *cos_table; | ||
688 | |||
689 | static t_class *cos_class; | ||
690 | |||
691 | typedef struct _cos | ||
692 | { | ||
693 | t_object x_obj; | ||
694 | float x_f; | ||
695 | } t_cos; | ||
696 | |||
697 | static void *cos_new(void) | ||
698 | { | ||
699 | t_cos *x = (t_cos *)pd_new(cos_class); | ||
700 | outlet_new(&x->x_obj, gensym("signal")); | ||
701 | x->x_f = 0; | ||
702 | return (x); | ||
703 | } | ||
704 | |||
705 | static t_int *cos_perform(t_int *w) | ||
706 | { | ||
707 | t_float *in = (t_float *)(w[1]); | ||
708 | t_float *out = (t_float *)(w[2]); | ||
709 | int n = (int)(w[3]); | ||
710 | float *tab = cos_table, *addr, f1, f2, frac; | ||
711 | double dphase; | ||
712 | int normhipart; | ||
713 | union tabfudge tf; | ||
714 | |||
715 | tf.tf_d = UNITBIT32; | ||
716 | normhipart = tf.tf_i[HIOFFSET]; | ||
717 | |||
718 | #if 0 /* this is the readable version of the code. */ | ||
719 | while (n--) | ||
720 | { | ||
721 | dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32; | ||
722 | tf.tf_d = dphase; | ||
723 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
724 | tf.tf_i[HIOFFSET] = normhipart; | ||
725 | frac = tf.tf_d - UNITBIT32; | ||
726 | f1 = addr[0]; | ||
727 | f2 = addr[1]; | ||
728 | *out++ = f1 + frac * (f2 - f1); | ||
729 | } | ||
730 | #endif | ||
731 | #if 1 /* this is the same, unwrapped by hand. */ | ||
732 | dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32; | ||
733 | tf.tf_d = dphase; | ||
734 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
735 | tf.tf_i[HIOFFSET] = normhipart; | ||
736 | while (--n) | ||
737 | { | ||
738 | dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32; | ||
739 | frac = tf.tf_d - UNITBIT32; | ||
740 | tf.tf_d = dphase; | ||
741 | f1 = addr[0]; | ||
742 | f2 = addr[1]; | ||
743 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
744 | *out++ = f1 + frac * (f2 - f1); | ||
745 | tf.tf_i[HIOFFSET] = normhipart; | ||
746 | } | ||
747 | frac = tf.tf_d - UNITBIT32; | ||
748 | f1 = addr[0]; | ||
749 | f2 = addr[1]; | ||
750 | *out++ = f1 + frac * (f2 - f1); | ||
751 | #endif | ||
752 | return (w+4); | ||
753 | } | ||
754 | |||
755 | static void cos_dsp(t_cos *x, t_signal **sp) | ||
756 | { | ||
757 | dsp_add(cos_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
758 | } | ||
759 | |||
760 | static void cos_maketable(void) | ||
761 | { | ||
762 | int i; | ||
763 | float *fp, phase, phsinc = (2. * 3.14159) / COSTABSIZE; | ||
764 | union tabfudge tf; | ||
765 | |||
766 | if (cos_table) return; | ||
767 | cos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1)); | ||
768 | for (i = COSTABSIZE + 1, fp = cos_table, phase = 0; i--; | ||
769 | fp++, phase += phsinc) | ||
770 | *fp = cos(phase); | ||
771 | |||
772 | /* here we check at startup whether the byte alignment | ||
773 | is as we declared it. If not, the code has to be | ||
774 | recompiled the other way. */ | ||
775 | tf.tf_d = UNITBIT32 + 0.5; | ||
776 | if ((unsigned)tf.tf_i[LOWOFFSET] != 0x80000000) | ||
777 | bug("cos~: unexpected machine alignment"); | ||
778 | } | ||
779 | |||
780 | static void cos_setup(void) | ||
781 | { | ||
782 | cos_class = class_new(gensym("cos~"), (t_newmethod)cos_new, 0, | ||
783 | sizeof(t_cos), 0, A_DEFFLOAT, 0); | ||
784 | CLASS_MAINSIGNALIN(cos_class, t_cos, x_f); | ||
785 | class_addmethod(cos_class, (t_method)cos_dsp, gensym("dsp"), 0); | ||
786 | cos_maketable(); | ||
787 | } | ||
788 | |||
789 | /* ------------------------ osc~ ----------------------------- */ | ||
790 | |||
791 | static t_class *osc_class, *scalarosc_class; | ||
792 | |||
793 | typedef struct _osc | ||
794 | { | ||
795 | t_object x_obj; | ||
796 | double x_phase; | ||
797 | float x_conv; | ||
798 | float x_f; /* frequency if scalar */ | ||
799 | } t_osc; | ||
800 | |||
801 | static void *osc_new(t_floatarg f) | ||
802 | { | ||
803 | t_osc *x = (t_osc *)pd_new(osc_class); | ||
804 | x->x_f = f; | ||
805 | outlet_new(&x->x_obj, gensym("signal")); | ||
806 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); | ||
807 | x->x_phase = 0; | ||
808 | x->x_conv = 0; | ||
809 | return (x); | ||
810 | } | ||
811 | |||
812 | static t_int *osc_perform(t_int *w) | ||
813 | { | ||
814 | t_osc *x = (t_osc *)(w[1]); | ||
815 | t_float *in = (t_float *)(w[2]); | ||
816 | t_float *out = (t_float *)(w[3]); | ||
817 | int n = (int)(w[4]); | ||
818 | float *tab = cos_table, *addr, f1, f2, frac; | ||
819 | double dphase = x->x_phase + UNITBIT32; | ||
820 | int normhipart; | ||
821 | union tabfudge tf; | ||
822 | float conv = x->x_conv; | ||
823 | |||
824 | tf.tf_d = UNITBIT32; | ||
825 | normhipart = tf.tf_i[HIOFFSET]; | ||
826 | #if 0 | ||
827 | while (n--) | ||
828 | { | ||
829 | tf.tf_d = dphase; | ||
830 | dphase += *in++ * conv; | ||
831 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
832 | tf.tf_i[HIOFFSET] = normhipart; | ||
833 | frac = tf.tf_d - UNITBIT32; | ||
834 | f1 = addr[0]; | ||
835 | f2 = addr[1]; | ||
836 | *out++ = f1 + frac * (f2 - f1); | ||
837 | } | ||
838 | #endif | ||
839 | #if 1 | ||
840 | tf.tf_d = dphase; | ||
841 | dphase += *in++ * conv; | ||
842 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
843 | tf.tf_i[HIOFFSET] = normhipart; | ||
844 | frac = tf.tf_d - UNITBIT32; | ||
845 | while (--n) | ||
846 | { | ||
847 | tf.tf_d = dphase; | ||
848 | f1 = addr[0]; | ||
849 | dphase += *in++ * conv; | ||
850 | f2 = addr[1]; | ||
851 | addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1)); | ||
852 | tf.tf_i[HIOFFSET] = normhipart; | ||
853 | *out++ = f1 + frac * (f2 - f1); | ||
854 | frac = tf.tf_d - UNITBIT32; | ||
855 | } | ||
856 | f1 = addr[0]; | ||
857 | f2 = addr[1]; | ||
858 | *out++ = f1 + frac * (f2 - f1); | ||
859 | #endif | ||
860 | |||
861 | tf.tf_d = UNITBIT32 * COSTABSIZE; | ||
862 | normhipart = tf.tf_i[HIOFFSET]; | ||
863 | tf.tf_d = dphase + (UNITBIT32 * COSTABSIZE - UNITBIT32); | ||
864 | tf.tf_i[HIOFFSET] = normhipart; | ||
865 | x->x_phase = tf.tf_d - UNITBIT32 * COSTABSIZE; | ||
866 | return (w+5); | ||
867 | } | ||
868 | |||
869 | static void osc_dsp(t_osc *x, t_signal **sp) | ||
870 | { | ||
871 | x->x_conv = COSTABSIZE/sp[0]->s_sr; | ||
872 | dsp_add(osc_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); | ||
873 | } | ||
874 | |||
875 | static void osc_ft1(t_osc *x, t_float f) | ||
876 | { | ||
877 | x->x_phase = COSTABSIZE * f; | ||
878 | } | ||
879 | |||
880 | static void osc_setup(void) | ||
881 | { | ||
882 | osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0, | ||
883 | sizeof(t_osc), 0, A_DEFFLOAT, 0); | ||
884 | CLASS_MAINSIGNALIN(osc_class, t_osc, x_f); | ||
885 | class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0); | ||
886 | class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0); | ||
887 | |||
888 | cos_maketable(); | ||
889 | } | ||
890 | |||
891 | /* ---------------- vcf~ - 2-pole bandpass filter. ----------------- */ | ||
892 | |||
893 | typedef struct vcfctl | ||
894 | { | ||
895 | float c_re; | ||
896 | float c_im; | ||
897 | float c_q; | ||
898 | float c_isr; | ||
899 | } t_vcfctl; | ||
900 | |||
901 | typedef struct sigvcf | ||
902 | { | ||
903 | t_object x_obj; | ||
904 | t_vcfctl x_cspace; | ||
905 | t_vcfctl *x_ctl; | ||
906 | float x_f; | ||
907 | } t_sigvcf; | ||
908 | |||
909 | t_class *sigvcf_class; | ||
910 | |||
911 | static void *sigvcf_new(t_floatarg q) | ||
912 | { | ||
913 | t_sigvcf *x = (t_sigvcf *)pd_new(sigvcf_class); | ||
914 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); | ||
915 | inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); | ||
916 | outlet_new(&x->x_obj, gensym("signal")); | ||
917 | outlet_new(&x->x_obj, gensym("signal")); | ||
918 | x->x_ctl = &x->x_cspace; | ||
919 | x->x_cspace.c_re = 0; | ||
920 | x->x_cspace.c_im = 0; | ||
921 | x->x_cspace.c_q = q; | ||
922 | x->x_cspace.c_isr = 0; | ||
923 | x->x_f = 0; | ||
924 | return (x); | ||
925 | } | ||
926 | |||
927 | static void sigvcf_ft1(t_sigvcf *x, t_floatarg f) | ||
928 | { | ||
929 | x->x_ctl->c_q = (f > 0 ? f : 0.f); | ||
930 | } | ||
931 | |||
932 | static t_int *sigvcf_perform(t_int *w) | ||
933 | { | ||
934 | float *in1 = (float *)(w[1]); | ||
935 | float *in2 = (float *)(w[2]); | ||
936 | float *out1 = (float *)(w[3]); | ||
937 | float *out2 = (float *)(w[4]); | ||
938 | t_vcfctl *c = (t_vcfctl *)(w[5]); | ||
939 | int n = (t_int)(w[6]); | ||
940 | int i; | ||
941 | float re = c->c_re, re2; | ||
942 | float im = c->c_im; | ||
943 | float q = c->c_q; | ||
944 | float qinv = (q > 0? 1.0f/q : 0); | ||
945 | float ampcorrect = 2.0f - 2.0f / (q + 2.0f); | ||
946 | float isr = c->c_isr; | ||
947 | float coefr, coefi; | ||
948 | float *tab = cos_table, *addr, f1, f2, frac; | ||
949 | double dphase; | ||
950 | int normhipart, tabindex; | ||
951 | union tabfudge tf; | ||
952 | |||
953 | tf.tf_d = UNITBIT32; | ||
954 | normhipart = tf.tf_i[HIOFFSET]; | ||
955 | |||
956 | for (i = 0; i < n; i++) | ||
957 | { | ||
958 | float cf, cfindx, r, oneminusr; | ||
959 | cf = *in2++ * isr; | ||
960 | if (cf < 0) cf = 0; | ||
961 | cfindx = cf * (float)(COSTABSIZE/6.28318f); | ||
962 | r = (qinv > 0 ? 1 - cf * qinv : 0); | ||
963 | if (r < 0) r = 0; | ||
964 | oneminusr = 1.0f - r; | ||
965 | dphase = ((double)(cfindx)) + UNITBIT32; | ||
966 | tf.tf_d = dphase; | ||
967 | tabindex = tf.tf_i[HIOFFSET] & (COSTABSIZE-1); | ||
968 | addr = tab + tabindex; | ||
969 | tf.tf_i[HIOFFSET] = normhipart; | ||
970 | frac = tf.tf_d - UNITBIT32; | ||
971 | f1 = addr[0]; | ||
972 | f2 = addr[1]; | ||
973 | coefr = r * (f1 + frac * (f2 - f1)); | ||
974 | |||
975 | addr = tab + ((tabindex - (COSTABSIZE/4)) & (COSTABSIZE-1)); | ||
976 | f1 = addr[0]; | ||
977 | f2 = addr[1]; | ||
978 | coefi = r * (f1 + frac * (f2 - f1)); | ||
979 | |||
980 | f1 = *in1++; | ||
981 | re2 = re; | ||
982 | *out1++ = re = ampcorrect * oneminusr * f1 | ||
983 | + coefr * re2 - coefi * im; | ||
984 | *out2++ = im = coefi * re2 + coefr * im; | ||
985 | } | ||
986 | if (PD_BIGORSMALL(re)) | ||
987 | re = 0; | ||
988 | if (PD_BIGORSMALL(im)) | ||
989 | im = 0; | ||
990 | c->c_re = re; | ||
991 | c->c_im = im; | ||
992 | return (w+7); | ||
993 | } | ||
994 | |||
995 | static void sigvcf_dsp(t_sigvcf *x, t_signal **sp) | ||
996 | { | ||
997 | x->x_ctl->c_isr = 6.28318f/sp[0]->s_sr; | ||
998 | dsp_add(sigvcf_perform, 6, | ||
999 | sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, | ||
1000 | x->x_ctl, sp[0]->s_n); | ||
1001 | |||
1002 | } | ||
1003 | |||
1004 | void sigvcf_setup(void) | ||
1005 | { | ||
1006 | sigvcf_class = class_new(gensym("vcf~"), (t_newmethod)sigvcf_new, 0, | ||
1007 | sizeof(t_sigvcf), 0, A_DEFFLOAT, 0); | ||
1008 | CLASS_MAINSIGNALIN(sigvcf_class, t_sigvcf, x_f); | ||
1009 | class_addmethod(sigvcf_class, (t_method)sigvcf_dsp, gensym("dsp"), 0); | ||
1010 | class_addmethod(sigvcf_class, (t_method)sigvcf_ft1, | ||
1011 | gensym("ft1"), A_FLOAT, 0); | ||
1012 | } | ||
1013 | |||
1014 | /* -------------------------- noise~ ------------------------------ */ | ||
1015 | static t_class *noise_class; | ||
1016 | |||
1017 | typedef struct _noise | ||
1018 | { | ||
1019 | t_object x_obj; | ||
1020 | int x_val; | ||
1021 | } t_noise; | ||
1022 | |||
1023 | static void *noise_new(void) | ||
1024 | { | ||
1025 | t_noise *x = (t_noise *)pd_new(noise_class); | ||
1026 | static int init = 307; | ||
1027 | x->x_val = (init *= 1319); | ||
1028 | outlet_new(&x->x_obj, gensym("signal")); | ||
1029 | return (x); | ||
1030 | } | ||
1031 | |||
1032 | static t_int *noise_perform(t_int *w) | ||
1033 | { | ||
1034 | t_float *out = (t_float *)(w[1]); | ||
1035 | int *vp = (int *)(w[2]); | ||
1036 | int n = (int)(w[3]); | ||
1037 | int val = *vp; | ||
1038 | while (n--) | ||
1039 | { | ||
1040 | *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) * | ||
1041 | (float)(1.0 / 0x40000000); | ||
1042 | val = val * 435898247 + 382842987; | ||
1043 | } | ||
1044 | *vp = val; | ||
1045 | return (w+4); | ||
1046 | } | ||
1047 | |||
1048 | static void noise_dsp(t_noise *x, t_signal **sp) | ||
1049 | { | ||
1050 | dsp_add(noise_perform, 3, sp[0]->s_vec, &x->x_val, sp[0]->s_n); | ||
1051 | } | ||
1052 | |||
1053 | static void noise_setup(void) | ||
1054 | { | ||
1055 | noise_class = class_new(gensym("noise~"), (t_newmethod)noise_new, 0, | ||
1056 | sizeof(t_noise), 0, 0); | ||
1057 | class_addmethod(noise_class, (t_method)noise_dsp, gensym("dsp"), 0); | ||
1058 | } | ||
1059 | |||
1060 | |||
1061 | /* ----------------------- global setup routine ---------------- */ | ||
1062 | void d_osc_setup(void) | ||
1063 | { | ||
1064 | phasor_setup(); | ||
1065 | cos_setup(); | ||
1066 | osc_setup(); | ||
1067 | sigvcf_setup(); | ||
1068 | noise_setup(); | ||
1069 | } | ||
1070 | |||