2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 Chaos Ugens created by Lance Putnam on Mon Jul 19 2004.
23 #include "SC_PlugIn.h"
24 #define TWOPI 6.283185307179586
25 #define PI 3.141592653589793
26 #define RECPI 0.3183098861837907
27 #define RECTWOPI 0.1591549430918953
28 #define ONESIXTH 0.1666666666666667
30 static InterfaceTable
*ft
;
32 struct NonLinear
: public Unit
{
33 double x0
, y0
, xn
, yn
, xnm1
, ynm1
;
38 struct CuspN
: public NonLinear
{
40 struct CuspL
: public CuspN
{
44 struct GbmanN
: public NonLinear
{
46 struct GbmanL
: public GbmanN
{
50 struct HenonN
: public Unit
{
51 double x0
, x1
, xn
, xnm1
, xnm2
, a
, b
;
55 struct HenonL
: public HenonN
{
58 struct HenonC
: public HenonL
{
59 double xnm3
,c0
,c1
,c2
,c3
;
62 struct LatoocarfianN
: public NonLinear
{
64 struct LatoocarfianL
: public LatoocarfianN
{
67 struct LatoocarfianC
: public LatoocarfianL
{
68 double xnm3
, xnm2
, c0
,c1
,c2
,c3
;
71 struct LinCongN
: public NonLinear
{
73 struct LinCongL
: public LinCongN
{
76 struct LinCongC
: public LinCongL
{
77 double xnm3
, xnm2
, c0
,c1
,c2
,c3
;
80 struct LorenzN
: public NonLinear
{
83 struct LorenzL
: public LorenzN
{
87 struct QuadN
: public NonLinear
{
89 struct QuadL
: public QuadN
{
92 struct QuadC
: public QuadL
{
97 struct StandardN
: public NonLinear
{
99 struct StandardL
: public StandardN
{
103 struct FBSineN
: public NonLinear
{
105 struct FBSineL
: public FBSineN
{
108 struct FBSineC
: public FBSineL
{
115 void CuspN_next(CuspN
*unit
, int inNumSamples
);
116 void CuspN_Ctor(CuspN
*unit
);
117 void CuspL_next(CuspL
*unit
, int inNumSamples
);
118 void CuspL_Ctor(CuspL
*unit
);
120 void GbmanN_next(GbmanN
*unit
, int inNumSamples
);
121 void GbmanN_Ctor(GbmanN
*unit
);
122 void GbmanL_next(GbmanL
*unit
, int inNumSamples
);
123 void GbmanL_Ctor(GbmanL
*unit
);
125 void HenonN_next(HenonN
*unit
, int inNumSamples
);
126 void HenonN_Ctor(HenonN
*unit
);
127 void HenonL_next(HenonL
*unit
, int inNumSamples
);
128 void HenonL_Ctor(HenonL
*unit
);
129 void HenonC_next(HenonC
*unit
, int inNumSamples
);
130 void HenonC_Ctor(HenonC
*unit
);
132 void LinCongN_next(LinCongN
*unit
, int inNumSamples
);
133 void LinCongN_Ctor(LinCongN
*unit
);
134 void LinCongL_next(LinCongL
*unit
, int inNumSamples
);
135 void LinCongL_Ctor(LinCongL
*unit
);
136 void LinCongC_next(LinCongC
*unit
, int inNumSamples
);
137 void LinCongC_Ctor(LinCongC
*unit
);
139 void LatoocarfianN_next(LatoocarfianN
*unit
, int inNumSamples
);
140 void LatoocarfianN_Ctor(LatoocarfianN
*unit
);
141 void LatoocarfianL_next(LatoocarfianL
*unit
, int inNumSamples
);
142 void LatoocarfianL_Ctor(LatoocarfianL
*unit
);
143 void LatoocarfianC_next(LatoocarfianC
*unit
, int inNumSamples
);
144 void LatoocarfianC_Ctor(LatoocarfianC
*unit
);
146 void LorenzL_next(LorenzL
*unit
, int inNumSamples
);
147 void LorenzL_Ctor(LorenzL
*unit
);
149 void QuadN_next(QuadN
*unit
, int inNumSamples
);
150 void QuadN_Ctor(QuadN
*unit
);
151 void QuadL_next(QuadL
*unit
, int inNumSamples
);
152 void QuadL_Ctor(QuadL
*unit
);
153 void QuadC_next(QuadC
*unit
, int inNumSamples
);
154 void QuadC_Ctor(QuadC
*unit
);
156 void StandardN_next(StandardN
*unit
, int inNumSamples
);
157 void StandardN_Ctor(StandardN
*unit
);
158 void StandardL_next(StandardL
*unit
, int inNumSamples
);
159 void StandardL_Ctor(StandardL
*unit
);
161 void FBSineN_next(FBSineN
*unit
, int inNumSamples
);
162 void FBSineN_Ctor(FBSineN
*unit
);
163 void FBSineL_next(FBSineL
*unit
, int inNumSamples
);
164 void FBSineL_Ctor(FBSineL
*unit
);
165 void FBSineC_next(FBSineC
*unit
, int inNumSamples
);
166 void FBSineC_Ctor(FBSineC
*unit
);
169 ////////////////////////////////////////////////////////////////////////////////
171 // calc 3rd order interpolation coefs from four points
172 static inline void ipol3Coef(
173 double xnm3
, double xnm2
, double xnm1
, double xn
,
174 double &c0
, double &c1
, double &c2
, double &c3
)
177 c1
= 0.5f
* (xnm1
- xnm3
);
178 c2
= xnm3
- (2.5f
* xnm2
) + xnm1
+ xnm1
- 0.5f
* xn
;
179 c3
= 0.5f
* (xn
- xnm3
) + 1.5f
* (xnm2
- xnm1
);
182 // do 3rd order interpolation using coefs
183 static inline double ipol3(float frac
, double c0
, double c1
, double c2
, double c3
){
184 return ((c3
* frac
+ c2
) * frac
+ c1
) * frac
+ c0
;
188 inline double mod2pi(double in
) {
189 const double lo
= (double)0.;
190 const double hi
= TWOPI
;
194 if (in
< hi
) return in
;
195 } else if (in
< lo
) {
197 if (in
>= lo
) return in
;
200 return in
- hi
* (double)((int)(in
* RECTWOPI
));
203 ////////////////////////////////////////////////////////////////////////////////
205 void CuspN_next(CuspN
*unit
, int inNumSamples
)
207 float *out
= ZOUT(0);
208 float freq
= ZIN0(0);
213 double xn
= unit
->xn
;
214 float counter
= unit
->counter
;
216 float samplesPerCycle
;
217 if(freq
< unit
->mRate
->mSampleRate
)
218 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
219 else samplesPerCycle
= 1.f
;
225 for (int i
=0; i
<inNumSamples
; ++i
) {
226 if(counter
>= samplesPerCycle
){
227 counter
-= samplesPerCycle
;
229 xn
= a
- (b
* sqrt(sc_abs(xn
)));
237 unit
->counter
= counter
;
240 void CuspN_Ctor(CuspN
* unit
)
251 ////////////////////////////////////////////////////////////////////////////////
253 void CuspL_next(CuspL
*unit
, int inNumSamples
)
255 float *out
= ZOUT(0);
256 float freq
= ZIN0(0);
261 double xn
= unit
->xn
;
262 float counter
= unit
->counter
;
263 double xnm1
= unit
->xnm1
;
264 double frac
= unit
->frac
;
266 float samplesPerCycle
;
268 if(freq
< unit
->mRate
->mSampleRate
){
269 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
270 slope
= 1.f
/ samplesPerCycle
;
273 samplesPerCycle
= 1.f
;
282 double dx
= xn
- xnm1
;
284 for (int i
=0; i
<inNumSamples
; ++i
) {
285 if(counter
>= samplesPerCycle
){
286 counter
-= samplesPerCycle
;
291 xn
= a
- (b
* sqrt(sc_abs(xn
)));
297 ZXP(out
) = xnm1
+ dx
* frac
;
302 unit
->counter
= counter
;
307 void CuspL_Ctor(CuspL
* unit
){
312 unit
->xnm1
= unit
->x0
;
319 ////////////////////////////////////////////////////////////////////////////////
321 void FBSineN_next(FBSineN
*unit
, int inNumSamples
){
322 float *out
= ZOUT(0);
323 float freq
= ZIN0(0);
331 double xn
= unit
->xn
;
332 double yn
= unit
->yn
;
333 float counter
= unit
->counter
;
335 float samplesPerCycle
;
336 if(freq
< unit
->mRate
->mSampleRate
)
337 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
338 else samplesPerCycle
= 1.f
;
340 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
) ){
345 for (int i
=0; i
<inNumSamples
; ++i
) {
346 if(counter
>= samplesPerCycle
){
347 counter
-= samplesPerCycle
;
349 xn
= sin(a
*yn
+ b
*xn
);
358 unit
->counter
= counter
;
361 void FBSineN_Ctor(FBSineN
*unit
){
362 SETCALC(FBSineN_next
);
369 FBSineN_next(unit
, 1);
372 ////////////////////////////////////////////////////////////////////////////////
374 void FBSineL_next(FBSineL
*unit
, int inNumSamples
){
375 float *out
= ZOUT(0);
376 float freq
= ZIN0(0);
384 double xn
= unit
->xn
;
385 double yn
= unit
->yn
;
386 double xnm1
= unit
->xnm1
;
387 float counter
= unit
->counter
;
388 double frac
= unit
->frac
;
390 float samplesPerCycle
;
392 if(freq
< unit
->mRate
->mSampleRate
){
393 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
394 slope
= 1.f
/ samplesPerCycle
;
397 samplesPerCycle
= 1.f
;
401 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
) ){
407 double dx
= xn
- xnm1
;
409 for (int i
=0; i
<inNumSamples
; ++i
) {
410 if(counter
>= samplesPerCycle
){
411 counter
-= samplesPerCycle
;
415 xn
= sin(a
*yn
+ b
*xn
);
422 ZXP(out
) = xnm1
+ dx
* frac
;
428 unit
->counter
= counter
;
432 void FBSineL_Ctor(FBSineL
*unit
){
433 SETCALC(FBSineL_next
);
438 unit
->xnm1
= unit
->x0
;
441 FBSineL_next(unit
, 1);
444 ////////////////////////////////////////////////////////////////////////////////
446 void FBSineC_next(FBSineC
*unit
, int inNumSamples
)
448 float *out
= ZOUT(0);
449 float freq
= ZIN0(0);
457 double xn
= unit
->xn
;
458 double xnm1
= unit
->xnm1
;
459 double xnm2
= unit
->xnm2
;
460 double xnm3
= unit
->xnm3
;
461 double yn
= unit
->yn
;
462 float counter
= unit
->counter
;
463 double frac
= unit
->frac
;
464 double c0
= unit
->c0
;
465 double c1
= unit
->c1
;
466 double c2
= unit
->c2
;
467 double c3
= unit
->c3
;
469 float samplesPerCycle
;
471 if(freq
< unit
->mRate
->mSampleRate
){
472 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
473 slope
= 1.f
/ samplesPerCycle
;
475 else samplesPerCycle
= slope
= 1.f
;
477 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
485 for (int i
=0; i
<inNumSamples
; ++i
) {
486 if(counter
>= samplesPerCycle
){
487 counter
-= samplesPerCycle
;
494 xn
= sin(a
*yn
+ b
*xn
);
498 ipol3Coef(xnm3
, xnm2
, xnm1
, xn
, c0
, c1
, c2
, c3
);
501 ZXP(out
) = ipol3(frac
, c0
, c1
, c2
, c3
);
510 unit
->counter
= counter
;
512 unit
->c0
= c0
; unit
->c1
= c1
; unit
->c2
= c2
; unit
->c3
= c3
;
515 void FBSineC_Ctor(FBSineC
* unit
)
517 SETCALC(FBSineC_next
);
523 unit
->xnm1
= unit
->xnm2
= unit
->xnm3
= unit
->x0
;
526 unit
->c0
= unit
->c1
= unit
->c2
= unit
->c3
= 0.;
528 FBSineC_next(unit
, 1);
531 ////////////////////////////////////////////////////////////////////////////////
533 void GbmanN_next(GbmanN
*unit
, int inNumSamples
){
534 float *out
= ZOUT(0);
535 float freq
= ZIN0(0);
537 double xn
= unit
->xn
;
538 double yn
= unit
->yn
;
539 float counter
= unit
->counter
;
541 float samplesPerCycle
;
542 if(freq
< unit
->mRate
->mSampleRate
)
543 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
544 else samplesPerCycle
= 1.f
;
546 for (int i
=0; i
<inNumSamples
; ++i
) {
547 if(counter
>= samplesPerCycle
){
548 counter
-= samplesPerCycle
;
551 xn
= 1.f
- yn
- xPrev
;
553 xn
= 1.f
- yn
+ xPrev
;
562 unit
->counter
= counter
;
565 void GbmanN_Ctor(GbmanN
*unit
){
566 SETCALC(GbmanN_next
);
570 GbmanN_next(unit
, 1);
573 ////////////////////////////////////////////////////////////////////////////////
575 void GbmanL_next(GbmanL
*unit
, int inNumSamples
){
576 float *out
= ZOUT(0);
577 float freq
= ZIN0(0);
579 double xn
= unit
->xn
;
580 double yn
= unit
->yn
;
581 float counter
= unit
->counter
;
582 double frac
= unit
->frac
;
584 float samplesPerCycle
;
586 if(freq
< unit
->mRate
->mSampleRate
){
587 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
588 slope
= 1.f
/ samplesPerCycle
;
591 samplesPerCycle
= 1.f
;
595 double diff
= xn
- yn
;
597 for (int i
=0; i
<inNumSamples
; ++i
) {
598 if(counter
>= samplesPerCycle
){
599 counter
-= samplesPerCycle
;
604 xn
= 1.f
- yn
- xPrev
;
606 xn
= 1.f
- yn
+ xPrev
;
613 ZXP(out
) = yn
+ (frac
* diff
);
619 unit
->counter
= counter
;
623 void GbmanL_Ctor(GbmanL
*unit
){
624 SETCALC(GbmanL_next
);
629 GbmanL_next(unit
, 1);
632 ////////////////////////////////////////////////////////////////////////////////
634 void HenonN_next(HenonN
*unit
, int inNumSamples
)
636 float *out
= ZOUT(0);
637 float freq
= ZIN0(0);
643 double xn
= unit
->xn
;
644 double xnm1
= unit
->xnm1
;
645 double xnm2
= unit
->xnm2
;
646 float counter
= unit
->counter
;
647 bool stable
= unit
->stable
;
649 float samplesPerCycle
;
650 if(freq
< unit
->mRate
->mSampleRate
)
651 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
652 else samplesPerCycle
= 1.f
;
654 if( (unit
->a
!= a
) || (unit
->b
!= b
) || (unit
->x0
!= x0
) || (unit
->x1
!= x1
)){
667 for (int i
=0; i
<inNumSamples
; ++i
) {
668 if(counter
>= samplesPerCycle
){
669 counter
-= samplesPerCycle
;
671 xn
= 1.f
- (a
* xnm1
* xnm1
) + (b
* xnm2
);
673 if((xn
> 1.5f
) || (xn
< -1.5f
)){
693 unit
->counter
= counter
;
694 unit
->stable
= stable
;
697 void HenonN_Ctor(HenonN
* unit
)
699 SETCALC(HenonN_next
);
704 unit
->xnm1
= unit
->x0
;
705 unit
->xnm2
= unit
->x1
;
712 HenonN_next(unit
, 1);
715 ////////////////////////////////////////////////////////////////////////////////
717 void HenonL_next(HenonL
*unit
, int inNumSamples
)
719 float *out
= ZOUT(0);
720 float freq
= ZIN0(0);
726 double xn
= unit
->xn
;
727 double xnm1
= unit
->xnm1
;
728 double xnm2
= unit
->xnm2
;
729 float counter
= unit
->counter
;
730 bool stable
= unit
->stable
;
731 double frac
= unit
->frac
;
733 float samplesPerCycle
;
735 if(freq
< unit
->mRate
->mSampleRate
){
736 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
737 slope
= 1.f
/ samplesPerCycle
;
739 else samplesPerCycle
= slope
= 1.f
;
741 if( (unit
->a
!= a
) || (unit
->b
!= b
) || (unit
->x0
!= x0
) || (unit
->x1
!= x1
)){
754 double diff
= xnm1
- xnm2
;
756 for (int i
=0; i
<inNumSamples
; ++i
) {
758 if(counter
>= samplesPerCycle
){
759 counter
-= samplesPerCycle
;
761 xn
= 1.f
- (a
* xnm1
* xnm1
) + (b
* xnm2
);
762 if(xn
> 1.5f
|| xn
< -1.5f
){
776 //Print("slope %g, x2 %g\n", slope, x2);
780 ZXP(out
) = xnm2
+ (diff
* frac
);
787 unit
->counter
= counter
;
788 unit
->stable
= stable
;
792 void HenonL_Ctor(HenonL
* unit
)
794 SETCALC(HenonL_next
);
799 unit
->xnm1
= unit
->x0
;
800 unit
->xnm2
= unit
->x1
;
808 HenonL_next(unit
, 1);
812 ////////////////////////////////////////////////////////////////////////////////
814 void HenonC_next(HenonC
*unit
, int inNumSamples
)
816 float *out
= ZOUT(0);
817 float freq
= ZIN0(0);
823 double xn
= unit
->xn
;
824 double xnm1
= unit
->xnm1
;
825 double xnm2
= unit
->xnm2
;
826 double xnm3
= unit
->xnm3
;
827 float counter
= unit
->counter
;
828 bool stable
= unit
->stable
;
829 double frac
= unit
->frac
;
830 double c0
= unit
->c0
;
831 double c1
= unit
->c1
;
832 double c2
= unit
->c2
;
833 double c3
= unit
->c3
;
835 float samplesPerCycle
;
837 if(freq
< unit
->mRate
->mSampleRate
){
838 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
839 slope
= 1.f
/ samplesPerCycle
;
841 else samplesPerCycle
= slope
= 1.f
;
843 if( (unit
->a
!= a
) || (unit
->b
!= b
) || (unit
->x0
!= x0
) || (unit
->x1
!= x1
)){
857 for (int i
=0; i
<inNumSamples
; ++i
) {
858 if(counter
>= samplesPerCycle
){
859 counter
-= samplesPerCycle
;
867 xn
= 1.f
- (a
* xnm1
* xnm1
) + (b
* xnm2
);
868 if( (xn
> 1.5) || (xn
< -1.5) ){
871 xnm1
= xnm2
= xnm3
= 0.;
873 ipol3Coef(xnm3
, xnm2
, xnm1
, xn
, c0
, c1
, c2
, c3
);
875 //Print("slope %g, x2 %g\n", slope, x2);
878 ZXP(out
) = ipol3(frac
, c0
, c1
, c2
, c3
);
886 unit
->counter
= counter
;
887 unit
->stable
= stable
;
889 unit
->c0
= c0
; unit
->c1
= c1
; unit
->c2
= c2
; unit
->c3
= c3
;
892 void HenonC_Ctor(HenonC
* unit
)
894 SETCALC(HenonC_next
);
899 unit
->xnm1
= unit
->x0
;
900 unit
->xnm2
= unit
->xnm3
= unit
->x1
;
906 unit
->c0
= unit
->c1
= unit
->c2
= unit
->c3
= 0.;
908 HenonC_next(unit
, 1);
911 ////////////////////////////////////////////////////////////////////////////////
913 void LatoocarfianN_next(LatoocarfianN
*unit
, int inNumSamples
)
915 float *out
= ZOUT(0);
916 float freq
= ZIN0(0);
924 double xn
= unit
->xn
;
925 double yn
= unit
->yn
;
926 float counter
= unit
->counter
;
928 float samplesPerCycle
;
929 if(freq
< unit
->mRate
->mSampleRate
)
930 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
931 else samplesPerCycle
= 1.f
;
933 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
938 for (int i
=0; i
<inNumSamples
; ++i
) {
939 if(counter
>= samplesPerCycle
){
940 counter
-= samplesPerCycle
;
942 const double xnm1
= xn
;
944 xn
= sin(yn
* b
) + c
*sin(xnm1
* b
);
945 yn
= sin(xnm1
* a
) + d
*sin(yn
* a
);
953 unit
->counter
= counter
;
956 void LatoocarfianN_Ctor(LatoocarfianN
* unit
){
957 SETCALC(LatoocarfianN_next
);
965 LatoocarfianN_next(unit
, 1);
969 ////////////////////////////////////////////////////////////////////////////////
971 void LatoocarfianL_next(LatoocarfianL
*unit
, int inNumSamples
)
973 float *out
= ZOUT(0);
974 float freq
= ZIN0(0);
982 double xn
= unit
->xn
;
983 double yn
= unit
->yn
;
984 float counter
= unit
->counter
;
985 double xnm1
= unit
->xnm1
;
986 double frac
= unit
->frac
;
988 float samplesPerCycle
;
990 if(freq
< unit
->mRate
->mSampleRate
){
991 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
992 slope
= 1.f
/ samplesPerCycle
;
995 samplesPerCycle
= 1.f
;
999 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
1005 double dx
= xn
- xnm1
;
1007 for (int i
=0; i
<inNumSamples
; ++i
) {
1008 if(counter
>= samplesPerCycle
){
1009 counter
-= samplesPerCycle
;
1014 xn
= sin(yn
* b
) + c
*sin(xnm1
* b
);
1015 yn
= sin(xnm1
* a
) + d
*sin(yn
* a
);
1020 ZXP(out
) = xnm1
+ dx
* frac
;
1026 unit
->counter
= counter
;
1031 void LatoocarfianL_Ctor(LatoocarfianL
* unit
){
1032 SETCALC(LatoocarfianL_next
);
1036 unit
->xn
= unit
->x0
;
1037 unit
->yn
= unit
->y0
;
1038 unit
->xnm1
= unit
->x0
;
1039 unit
->counter
= 0.f
;
1042 LatoocarfianL_next(unit
, 1);
1045 ////////////////////////////////////////////////////////////////////////////////
1047 void LatoocarfianC_next(LatoocarfianC
*unit
, int inNumSamples
)
1049 float *out
= ZOUT(0);
1050 float freq
= ZIN0(0);
1055 double x0
= ZIN0(5);
1056 double y0
= ZIN0(6);
1058 double xn
= unit
->xn
;
1059 double xnm1
= unit
->xnm1
;
1060 double xnm2
= unit
->xnm2
;
1061 double xnm3
= unit
->xnm3
;
1062 double yn
= unit
->yn
;
1063 float counter
= unit
->counter
;
1064 double frac
= unit
->frac
;
1065 double c0
= unit
->c0
;
1066 double c1
= unit
->c1
;
1067 double c2
= unit
->c2
;
1068 double c3
= unit
->c3
;
1070 float samplesPerCycle
;
1072 if(freq
< unit
->mRate
->mSampleRate
){
1073 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1074 slope
= 1.f
/ samplesPerCycle
;
1076 else samplesPerCycle
= slope
= 1.f
;
1078 if( (unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
1086 for (int i
=0; i
<inNumSamples
; ++i
) {
1087 if(counter
>= samplesPerCycle
){
1088 counter
-= samplesPerCycle
;
1095 xn
= sin(yn
* b
) + c
*sin(xnm1
* b
);
1096 yn
= sin(xnm1
* a
) + d
*sin(yn
* a
);
1098 ipol3Coef(xnm3
, xnm2
, xnm1
, xn
, c0
, c1
, c2
, c3
);
1101 ZXP(out
) = ipol3(frac
, c0
, c1
, c2
, c3
);
1110 unit
->counter
= counter
;
1112 unit
->c0
= c0
; unit
->c1
= c1
; unit
->c2
= c2
; unit
->c3
= c3
;
1115 void LatoocarfianC_Ctor(LatoocarfianC
* unit
)
1117 SETCALC(LatoocarfianC_next
);
1121 unit
->xn
= unit
->x0
;
1122 unit
->yn
= unit
->y0
;
1123 unit
->xnm1
= unit
->xnm2
= unit
->xnm3
= unit
->x0
;
1124 unit
->counter
= 0.f
;
1126 unit
->c0
= unit
->c1
= unit
->c2
= unit
->c3
= unit
->x0
;
1128 LatoocarfianC_next(unit
, 1);
1131 ////////////////////////////////////////////////////////////////////////////////
1133 void LinCongN_next(LinCongN
*unit
, int inNumSamples
){
1134 float *out
= ZOUT(0);
1135 float freq
= ZIN0(0);
1136 double a
= ZIN0(1); //multiplier
1137 double c
= ZIN0(2); //increment
1138 double m
= sc_max(ZIN0(3), 0.001f
); //modulus
1140 double xn
= unit
->xn
;
1141 float counter
= unit
->counter
;
1143 double scaleFactor
= 2.f
/ m
;
1144 double xscaled
= (xn
* scaleFactor
) - 1.f
;
1146 float samplesPerCycle
;
1147 if(freq
< unit
->mRate
->mSampleRate
)
1148 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1149 else samplesPerCycle
= 1.f
;
1151 for (int i
=0; i
<inNumSamples
; ++i
) {
1152 if(counter
>= samplesPerCycle
){
1153 counter
-= samplesPerCycle
;
1158 xscaled
= (xn
* scaleFactor
) - 1.f
;
1164 unit
->counter
= counter
;
1167 void LinCongN_Ctor(LinCongN
*unit
){
1168 SETCALC(LinCongN_next
);
1169 unit
->xn
= ZIN0(4); // initial x
1170 unit
->counter
= 0.f
;
1171 LinCongN_next(unit
, 1);
1174 ////////////////////////////////////////////////////////////////////////////////
1176 void LinCongL_next(LinCongL
*unit
, int inNumSamples
){
1177 float *out
= ZOUT(0);
1178 float freq
= ZIN0(0);
1179 double a
= ZIN0(1); //multiplier
1180 double c
= ZIN0(2); //increment
1181 double m
= sc_max(ZIN0(3), 0.001f
); //modulus
1183 double xn
= unit
->xn
;
1184 float counter
= unit
->counter
;
1185 double xnm1
= unit
->xnm1
;
1186 double frac
= unit
->frac
;
1188 double scaleFactor
= 2.f
/ m
;
1189 double xscaled
= (xn
* scaleFactor
) - 1.f
;
1191 float samplesPerCycle
;
1193 if(freq
< unit
->mRate
->mSampleRate
){
1194 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1195 slope
= 1.f
/ samplesPerCycle
;
1198 samplesPerCycle
= 1.f
;
1202 double diff
= xscaled
- xnm1
;
1204 for (int i
=0; i
<inNumSamples
; ++i
) {
1205 if(counter
>= samplesPerCycle
){
1206 counter
-= samplesPerCycle
;
1213 xscaled
= (xn
* scaleFactor
) - 1.f
;
1214 diff
= xscaled
- xnm1
;
1217 ZXP(out
) = xnm1
+ (frac
* diff
);
1222 unit
->counter
= counter
;
1227 void LinCongL_Ctor(LinCongL
*unit
){
1228 SETCALC(LinCongL_next
);
1230 unit
->counter
= 0.f
;
1231 unit
->xnm1
= unit
->xn
;
1233 LinCongL_next(unit
, 1);
1236 ////////////////////////////////////////////////////////////////////////////////
1238 void LinCongC_next(LinCongC
*unit
, int inNumSamples
)
1240 float *out
= ZOUT(0);
1241 float freq
= ZIN0(0);
1242 double a
= ZIN0(1); //multiplier
1243 double c
= ZIN0(2); //increment
1244 double m
= sc_max(ZIN0(3), 0.001f
); //modulus
1246 double xn
= unit
->xn
;
1247 double xnm1
= unit
->xnm1
;
1248 double xnm2
= unit
->xnm2
;
1249 double xnm3
= unit
->xnm3
;
1250 float counter
= unit
->counter
;
1251 double frac
= unit
->frac
;
1252 double c0
= unit
->c0
;
1253 double c1
= unit
->c1
;
1254 double c2
= unit
->c2
;
1255 double c3
= unit
->c3
;
1257 double scaleFactor
= 2.f
/ m
;
1258 double xscaled
= (xn
* scaleFactor
) - 1.f
;
1260 float samplesPerCycle
;
1262 if(freq
< unit
->mRate
->mSampleRate
){
1263 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1264 slope
= 1.f
/ samplesPerCycle
;
1266 else samplesPerCycle
= slope
= 1.f
;
1268 for (int i
=0; i
<inNumSamples
; ++i
) {
1269 if(counter
>= samplesPerCycle
){
1270 counter
-= samplesPerCycle
;
1280 xscaled
= (xn
* scaleFactor
) - 1.f
;
1282 ipol3Coef(xnm3
, xnm2
, xnm1
, xscaled
, c0
, c1
, c2
, c3
);
1285 ZXP(out
) = ipol3(frac
, c0
, c1
, c2
, c3
);
1293 unit
->counter
= counter
;
1295 unit
->c0
= c0
; unit
->c1
= c1
; unit
->c2
= c2
; unit
->c3
= c3
;
1298 void LinCongC_Ctor(LinCongC
* unit
)
1300 SETCALC(LinCongC_next
);
1303 unit
->xn
= unit
->x0
;
1304 unit
->xnm1
= unit
->xnm2
= unit
->xnm3
= unit
->x0
;
1305 unit
->counter
= 0.f
;
1307 unit
->c0
= unit
->c1
= unit
->c2
= unit
->c3
= unit
->x0
;
1309 LinCongC_next(unit
, 1);
1312 ////////////////////////////////////////////////////////////////////////////////
1314 void LorenzL_next(LorenzL
*unit
, int inNumSamples
)
1316 float *out
= ZOUT(0);
1317 float freq
= ZIN0(0);
1322 double x0
= ZIN0(5);
1323 double y0
= ZIN0(6);
1324 double z0
= ZIN0(7);
1326 double xn
= unit
->xn
;
1327 double yn
= unit
->yn
;
1328 double zn
= unit
->zn
;
1329 float counter
= unit
->counter
;
1330 double xnm1
= unit
->xnm1
;
1331 double ynm1
= unit
->ynm1
;
1332 double znm1
= unit
->znm1
;
1333 double frac
= unit
->frac
;
1335 float samplesPerCycle
;
1337 if(freq
< unit
->mRate
->mSampleRate
){
1338 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1339 slope
= 1.f
/ samplesPerCycle
;
1342 samplesPerCycle
= 1.f
;
1346 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
) || (unit
->z0
!= z0
)){
1355 double dx
= xn
- xnm1
;
1357 for (int i
=0; i
<inNumSamples
; ++i
) {
1358 if(counter
>= samplesPerCycle
){
1359 counter
-= samplesPerCycle
;
1366 double k1x
, k2x
, k3x
, k4x
,
1369 kxHalf
, kyHalf
, kzHalf
;
1370 double hTimesS
= h
*s
;
1372 // 4th order Runge-Kutta
1373 k1x
= hTimesS
* (ynm1
- xnm1
);
1374 k1y
= h
* (xnm1
* (r
- znm1
) - ynm1
);
1375 k1z
= h
* (xnm1
* ynm1
- b
* znm1
);
1380 k2x
= hTimesS
* (ynm1
+ kyHalf
- xnm1
- kxHalf
);
1381 k2y
= h
* ((xnm1
+ kxHalf
) * (r
- znm1
- kzHalf
) - (ynm1
+ kyHalf
));
1382 k2z
= h
* ((xnm1
+ kxHalf
) * (ynm1
+ kyHalf
) - b
* (znm1
+ kzHalf
));
1387 k3x
= hTimesS
* (ynm1
+ kyHalf
- xnm1
- kxHalf
);
1388 k3y
= h
* ((xnm1
+ kxHalf
) * (r
- znm1
- kzHalf
) - (ynm1
+ kyHalf
));
1389 k3z
= h
* ((xnm1
+ kxHalf
) * (ynm1
+ kyHalf
) - b
* (znm1
+ kzHalf
));
1391 k4x
= hTimesS
* (ynm1
+ k3y
- xnm1
- k3x
);
1392 k4y
= h
* ((xnm1
+ k3x
) * (r
- znm1
- k3z
) - (ynm1
+ k3y
));
1393 k4z
= h
* ((xnm1
+ k3x
) * (ynm1
+ k3y
) - b
* (znm1
+ k3z
));
1395 xn
= xn
+ (k1x
+ 2.0*(k2x
+ k3x
) + k4x
) * ONESIXTH
;
1396 yn
= yn
+ (k1y
+ 2.0*(k2y
+ k3y
) + k4y
) * ONESIXTH
;
1397 zn
= zn
+ (k1z
+ 2.0*(k2z
+ k3z
) + k4z
) * ONESIXTH
;
1400 // xn = xnm1 + h * (s * (ynm1 - xnm1));
1401 // yn = ynm1 + h * (xnm1 * (r - znm1) - ynm1);
1402 // zn = znm1 + h * (xnm1 * ynm1 - b * znm1);
1407 ZXP(out
) = (xnm1
+ dx
* frac
) * 0.04f
;
1414 unit
->counter
= counter
;
1421 void LorenzL_Ctor(LorenzL
* unit
){
1422 SETCALC(LorenzL_next
);
1424 unit
->x0
= unit
->xn
= unit
->xnm1
= ZIN0(5);
1425 unit
->y0
= unit
->yn
= unit
->ynm1
= ZIN0(6);
1426 unit
->z0
= unit
->zn
= unit
->znm1
= ZIN0(7);
1427 unit
->counter
= 0.f
;
1430 LorenzL_next(unit
, 1);
1433 ////////////////////////////////////////////////////////////////////////////////
1435 void QuadN_next(QuadN
*unit
, int inNumSamples
)
1437 float *out
= ZOUT(0);
1438 float freq
= ZIN0(0);
1442 double x0
= ZIN0(4);
1444 double xn
= unit
->xn
;
1445 float counter
= unit
->counter
;
1447 float samplesPerCycle
;
1448 if(freq
< unit
->mRate
->mSampleRate
)
1449 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1450 else samplesPerCycle
= 1.f
;
1456 for (int i
=0; i
<inNumSamples
; ++i
) {
1457 if(counter
>= samplesPerCycle
){
1458 counter
-= samplesPerCycle
;
1460 xn
= a
* xn
* xn
+ b
* xn
+ c
;
1467 unit
->counter
= counter
;
1470 void QuadN_Ctor(QuadN
* unit
)
1472 SETCALC(QuadN_next
);
1475 unit
->xn
= unit
->x0
;
1476 unit
->counter
= 0.f
;
1478 QuadN_next(unit
, 1);
1481 ////////////////////////////////////////////////////////////////////////////////
1483 void QuadL_next(QuadL
*unit
, int inNumSamples
)
1485 float *out
= ZOUT(0);
1486 float freq
= ZIN0(0);
1490 double x0
= ZIN0(4);
1492 double xn
= unit
->xn
;
1493 float counter
= unit
->counter
;
1494 double xnm1
= unit
->xnm1
;
1495 double frac
= unit
->frac
;
1497 float samplesPerCycle
;
1499 if(freq
< unit
->mRate
->mSampleRate
){
1500 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1501 slope
= 1.f
/ samplesPerCycle
;
1504 samplesPerCycle
= 1.f
;
1513 double dx
= xn
- xnm1
;
1515 for (int i
=0; i
<inNumSamples
; ++i
) {
1516 if(counter
>= samplesPerCycle
){
1517 counter
-= samplesPerCycle
;
1522 xn
= a
* xn
* xn
+ b
* xn
+ c
;
1528 ZXP(out
) = xnm1
+ dx
* frac
;
1533 unit
->counter
= counter
;
1538 void QuadL_Ctor(QuadL
* unit
){
1539 SETCALC(QuadL_next
);
1542 unit
->xn
= unit
->x0
;
1543 unit
->xnm1
= unit
->x0
;
1544 unit
->counter
= 0.f
;
1547 QuadL_next(unit
, 1);
1550 ////////////////////////////////////////////////////////////////////////////////
1552 void QuadC_next(QuadC
*unit
, int inNumSamples
)
1554 float *out
= ZOUT(0);
1555 float freq
= ZIN0(0);
1559 double x0
= ZIN0(4);
1561 double xn
= unit
->xn
;
1562 double xnm1
= unit
->xnm1
;
1563 double xnm2
= unit
->xnm2
;
1564 double xnm3
= unit
->xnm3
;
1565 float counter
= unit
->counter
;
1566 double frac
= unit
->frac
;
1567 double c0
= unit
->c0
;
1568 double c1
= unit
->c1
;
1569 double c2
= unit
->c2
;
1570 double c3
= unit
->c3
;
1572 float samplesPerCycle
;
1574 if(freq
< unit
->mRate
->mSampleRate
){
1575 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1576 slope
= 1.f
/ samplesPerCycle
;
1578 else samplesPerCycle
= slope
= 1.f
;
1587 for (int i
=0; i
<inNumSamples
; ++i
) {
1588 if(counter
>= samplesPerCycle
){
1589 counter
-= samplesPerCycle
;
1596 xn
= a
* xn
* xn
+ b
* xn
+ c
;
1598 ipol3Coef(xnm3
, xnm2
, xnm1
, xn
, c0
, c1
, c2
, c3
);
1601 ZXP(out
) = ipol3(frac
, c0
, c1
, c2
, c3
);
1609 unit
->counter
= counter
;
1611 unit
->c0
= c0
; unit
->c1
= c1
; unit
->c2
= c2
; unit
->c3
= c3
;
1614 void QuadC_Ctor(QuadC
* unit
)
1616 SETCALC(QuadC_next
);
1619 unit
->xn
= unit
->x0
;
1620 unit
->xnm1
= unit
->xnm2
= unit
->xnm3
= unit
->x0
;
1621 unit
->c0
= unit
->c1
= unit
->c2
= unit
->c3
= unit
->x0
;
1622 unit
->counter
= 0.f
;
1625 QuadC_next(unit
, 1);
1628 ////////////////////////////////////////////////////////////////////////////////
1630 void StandardN_next(StandardN
*unit
, int inNumSamples
)
1632 float *out
= ZOUT(0);
1633 float freq
= ZIN0(0);
1635 double x0
= ZIN0(2);
1636 double y0
= ZIN0(3);
1638 double xn
= unit
->xn
;
1639 double output
= (xn
- PI
) * RECPI
;
1640 double yn
= unit
->yn
;
1641 float counter
= unit
->counter
;
1643 float samplesPerCycle
;
1644 if(freq
< unit
->mRate
->mSampleRate
)
1645 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1646 else samplesPerCycle
= 1.f
;
1648 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
1653 for (int i
=0; i
<inNumSamples
; ++i
) {
1654 if(counter
>= samplesPerCycle
){
1655 counter
-= samplesPerCycle
;
1657 yn
= yn
+ k
* sin(xn
);
1663 output
= (xn
- PI
) * RECPI
;
1671 unit
->counter
= counter
;
1674 void StandardN_Ctor(StandardN
* unit
)
1676 SETCALC(StandardN_next
);
1680 unit
->xn
= unit
->x0
;
1681 unit
->yn
= unit
->y0
;
1682 unit
->counter
= 0.f
;
1684 StandardN_next(unit
, 1);
1687 ////////////////////////////////////////////////////////////////////////////////
1689 void StandardL_next(StandardL
*unit
, int inNumSamples
)
1691 float *out
= ZOUT(0);
1692 float freq
= ZIN0(0);
1694 double x0
= ZIN0(2);
1695 double y0
= ZIN0(3);
1697 double xn
= unit
->xn
;
1698 double yn
= unit
->yn
;
1699 float counter
= unit
->counter
;
1700 double xnm1
= unit
->xnm1
;
1701 double frac
= unit
->frac
;
1703 float samplesPerCycle
;
1705 if(freq
< unit
->mRate
->mSampleRate
){
1706 samplesPerCycle
= unit
->mRate
->mSampleRate
/ sc_max(freq
, 0.001f
);
1707 slope
= 1.f
/ samplesPerCycle
;
1710 samplesPerCycle
= 1.f
;
1714 if((unit
->x0
!= x0
) || (unit
->y0
!= y0
)){
1720 double dx
= xn
- xnm1
;
1722 for (int i
=0; i
<inNumSamples
; ++i
) {
1723 if(counter
>= samplesPerCycle
){
1724 counter
-= samplesPerCycle
;
1729 yn
= yn
+ k
* sin(xn
);
1738 ZXP(out
) = (xnm1
+ dx
* frac
- PI
) * RECPI
;
1744 unit
->counter
= counter
;
1749 void StandardL_Ctor(StandardL
* unit
){
1750 SETCALC(StandardL_next
);
1754 unit
->xn
= unit
->x0
;
1755 unit
->yn
= unit
->y0
;
1756 unit
->xnm1
= unit
->x0
;
1757 unit
->counter
= 0.f
;
1760 StandardL_next(unit
, 1);
1763 ////////////////////////////////////////////////////////////////////////////////
1770 DefineSimpleUnit(CuspN
);
1771 DefineSimpleUnit(CuspL
);
1772 DefineSimpleUnit(FBSineN
);
1773 DefineSimpleUnit(FBSineL
);
1774 DefineSimpleUnit(FBSineC
);
1775 DefineSimpleUnit(GbmanN
);
1776 DefineSimpleUnit(GbmanL
);
1777 DefineSimpleUnit(HenonN
);
1778 DefineSimpleUnit(HenonL
);
1779 DefineSimpleUnit(HenonC
);
1780 DefineSimpleUnit(LatoocarfianN
);
1781 DefineSimpleUnit(LatoocarfianL
);
1782 DefineSimpleUnit(LatoocarfianC
);
1783 DefineSimpleUnit(LinCongN
);
1784 DefineSimpleUnit(LinCongL
);
1785 DefineSimpleUnit(LinCongC
);
1786 DefineSimpleUnit(LorenzL
);
1787 DefineSimpleUnit(QuadN
);
1788 DefineSimpleUnit(QuadL
);
1789 DefineSimpleUnit(QuadC
);
1790 DefineSimpleUnit(StandardN
);
1791 DefineSimpleUnit(StandardL
);