FFT: Prevent user from attempting hops smaller than SC's block size
[supercollider.git] / server / plugins / ChaosUGens.cpp
blobc959a0853a826a530830effc60d98146983800c0
1 /*
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;
34 float counter;
35 //bool stable;
38 struct CuspN : public NonLinear {
40 struct CuspL : public CuspN {
41 double frac;
44 struct GbmanN : public NonLinear {
46 struct GbmanL : public GbmanN {
47 double frac;
50 struct HenonN : public Unit {
51 double x0, x1, xn, xnm1, xnm2, a, b;
52 float counter;
53 bool stable;
55 struct HenonL : public HenonN {
56 double frac;
58 struct HenonC : public HenonL {
59 double xnm3,c0,c1,c2,c3;
62 struct LatoocarfianN : public NonLinear {
64 struct LatoocarfianL : public LatoocarfianN {
65 double frac;
67 struct LatoocarfianC : public LatoocarfianL {
68 double xnm3, xnm2, c0,c1,c2,c3;
71 struct LinCongN : public NonLinear {
73 struct LinCongL : public LinCongN {
74 double frac;
76 struct LinCongC : public LinCongL {
77 double xnm3, xnm2, c0,c1,c2,c3;
80 struct LorenzN : public NonLinear {
81 double z0, zn, znm1;
83 struct LorenzL : public LorenzN {
84 double frac;
87 struct QuadN : public NonLinear {
89 struct QuadL : public QuadN {
90 double frac;
92 struct QuadC : public QuadL {
93 double xnm3, xnm2;
94 double c0,c1,c2,c3;
97 struct StandardN : public NonLinear {
99 struct StandardL : public StandardN {
100 double frac;
103 struct FBSineN : public NonLinear {
105 struct FBSineL : public FBSineN {
106 double frac;
108 struct FBSineC : public FBSineL {
109 double xnm3, xnm2;
110 double c0,c1,c2,c3;
113 extern "C" {
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)
176 c0 = xnm2;
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;
187 // quick 2pi modulo
188 inline double mod2pi(double in) {
189 const double lo = (double)0.;
190 const double hi = TWOPI;
192 if (in >= hi) {
193 in -= hi;
194 if (in < hi) return in;
195 } else if (in < lo) {
196 in += hi;
197 if (in >= lo) return in;
198 } else 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);
209 double a = ZIN0(1);
210 double b = ZIN0(2);
211 double x0 = ZIN0(3);
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;
221 if(unit->x0 != x0){
222 unit->x0 = xn = x0;
225 for (int i=0; i<inNumSamples; ++i) {
226 if(counter >= samplesPerCycle){
227 counter -= samplesPerCycle;
229 xn = a - (b * sqrt(sc_abs(xn)));
231 counter++;
233 ZXP(out) = xn;
236 unit->xn = xn;
237 unit->counter = counter;
240 void CuspN_Ctor(CuspN* unit)
242 SETCALC(CuspN_next);
244 unit->x0 = ZIN0(3);
245 unit->xn = unit->x0;
246 unit->counter = 0.f;
248 CuspN_next(unit, 1);
251 ////////////////////////////////////////////////////////////////////////////////
253 void CuspL_next(CuspL *unit, int inNumSamples)
255 float *out = ZOUT(0);
256 float freq = ZIN0(0);
257 double a = ZIN0(1);
258 double b = ZIN0(2);
259 double x0 = ZIN0(3);
261 double xn = unit->xn;
262 float counter = unit->counter;
263 double xnm1 = unit->xnm1;
264 double frac = unit->frac;
266 float samplesPerCycle;
267 double slope;
268 if(freq < unit->mRate->mSampleRate){
269 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
270 slope = 1.f / samplesPerCycle;
272 else {
273 samplesPerCycle = 1.f;
274 slope = 1.f;
277 if(unit->x0 != x0){
278 xnm1 = xn;
279 unit->x0 = xn = x0;
282 double dx = xn - xnm1;
284 for (int i=0; i<inNumSamples; ++i) {
285 if(counter >= samplesPerCycle){
286 counter -= samplesPerCycle;
287 frac = 0.f;
289 xnm1 = xn;
291 xn = a - (b * sqrt(sc_abs(xn)));
293 dx = xn - xnm1;
295 counter++;
297 ZXP(out) = xnm1 + dx * frac;
298 frac += slope;
301 unit->xn = xn;
302 unit->counter = counter;
303 unit->xnm1 = xnm1;
304 unit->frac = frac;
307 void CuspL_Ctor(CuspL* unit){
308 SETCALC(CuspL_next);
310 unit->x0 = ZIN0(3);
311 unit->xn = unit->x0;
312 unit->xnm1 = unit->x0;
313 unit->counter = 0.f;
314 unit->frac = 0.f;
316 CuspL_next(unit, 1);
319 ////////////////////////////////////////////////////////////////////////////////
321 void FBSineN_next(FBSineN *unit, int inNumSamples){
322 float *out = ZOUT(0);
323 float freq = ZIN0(0);
324 double a = ZIN0(1);
325 double b = ZIN0(2);
326 double c = ZIN0(3);
327 double d = ZIN0(4);
328 double x0 = ZIN0(5);
329 double y0 = ZIN0(6);
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) ){
341 unit->x0 = xn = x0;
342 unit->y0 = yn = y0;
345 for (int i=0; i<inNumSamples; ++i) {
346 if(counter >= samplesPerCycle){
347 counter -= samplesPerCycle;
349 xn = sin(a*yn + b*xn);
350 yn = c*yn + d;
351 yn = mod2pi(yn);
353 counter++;
354 ZXP(out) = xn;
356 unit->xn = xn;
357 unit->yn = yn;
358 unit->counter = counter;
361 void FBSineN_Ctor(FBSineN *unit){
362 SETCALC(FBSineN_next);
363 unit->x0 = ZIN0(5);
364 unit->y0 = ZIN0(6);
365 unit->xn = unit->x0;
366 unit->yn = unit->y0;
367 unit->counter = 0.f;
369 FBSineN_next(unit, 1);
372 ////////////////////////////////////////////////////////////////////////////////
374 void FBSineL_next(FBSineL *unit, int inNumSamples){
375 float *out = ZOUT(0);
376 float freq = ZIN0(0);
377 double a = ZIN0(1);
378 double b = ZIN0(2);
379 double c = ZIN0(3);
380 double d = ZIN0(4);
381 double x0 = ZIN0(5);
382 double y0 = ZIN0(6);
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;
391 double slope;
392 if(freq < unit->mRate->mSampleRate){
393 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
394 slope = 1.f / samplesPerCycle;
396 else {
397 samplesPerCycle = 1.f;
398 slope = 1.f;
401 if((unit->x0 != x0) || (unit->y0 != y0) ){
402 xnm1 = xn;
403 unit->x0 = xn = x0;
404 unit->y0 = yn = y0;
407 double dx = xn - xnm1;
409 for (int i=0; i<inNumSamples; ++i) {
410 if(counter >= samplesPerCycle){
411 counter -= samplesPerCycle;
412 frac = 0.0;
413 xnm1 = xn;
415 xn = sin(a*yn + b*xn);
416 yn = c*yn + d;
417 yn = mod2pi(yn);
419 dx = xn - xnm1;
421 counter++;
422 ZXP(out) = xnm1 + dx * frac;
423 frac += slope;
425 unit->xn = xn;
426 unit->yn = yn;
427 unit->xnm1 = xnm1;
428 unit->counter = counter;
429 unit->frac = frac;
432 void FBSineL_Ctor(FBSineL *unit){
433 SETCALC(FBSineL_next);
434 unit->x0 = ZIN0(5);
435 unit->y0 = ZIN0(6);
436 unit->xn = unit->x0;
437 unit->yn = unit->y0;
438 unit->xnm1 = unit->x0;
439 unit->counter = 0.f;
440 unit->frac = 0.0;
441 FBSineL_next(unit, 1);
444 ////////////////////////////////////////////////////////////////////////////////
446 void FBSineC_next(FBSineC *unit, int inNumSamples)
448 float *out = ZOUT(0);
449 float freq = ZIN0(0);
450 double a = ZIN0(1);
451 double b = ZIN0(2);
452 double c = ZIN0(3);
453 double d = ZIN0(4);
454 double x0 = ZIN0(5);
455 double y0 = ZIN0(6);
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;
470 double slope;
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)){
478 unit->x0 = xn = x0;
479 unit->y0 = y0;
480 xnm3 = xnm2;
481 xnm2 = xnm1;
482 xnm1 = xn;
485 for (int i=0; i<inNumSamples; ++i) {
486 if(counter >= samplesPerCycle){
487 counter -= samplesPerCycle;
489 frac = 0.0;
490 xnm3 = xnm2;
491 xnm2 = xnm1;
492 xnm1 = xn;
494 xn = sin(a*yn + b*xn);
495 yn = c*yn + d;
496 yn = mod2pi(yn);
498 ipol3Coef(xnm3, xnm2, xnm1, xn, c0, c1, c2, c3);
500 counter++;
501 ZXP(out) = ipol3(frac, c0, c1, c2, c3);
502 frac += slope;
505 unit->xn = xn;
506 unit->xnm1 = xnm1;
507 unit->xnm2 = xnm2;
508 unit->xnm3 = xnm3;
509 unit->yn = yn;
510 unit->counter = counter;
511 unit->frac = frac;
512 unit->c0 = c0; unit->c1 = c1; unit->c2 = c2; unit->c3 = c3;
515 void FBSineC_Ctor(FBSineC* unit)
517 SETCALC(FBSineC_next);
519 unit->x0 = ZIN0(5);
520 unit->y0 = ZIN0(6);
521 unit->xn = unit->x0;
522 unit->yn = unit->y0;
523 unit->xnm1 = unit->xnm2 = unit->xnm3 = unit->x0;
524 unit->counter = 0.f;
525 unit->frac = 0.0;
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;
549 double xPrev = xn;
550 if(xPrev < 0.f)
551 xn = 1.f - yn - xPrev;
552 else
553 xn = 1.f - yn + xPrev;
555 yn = xPrev;
557 counter++;
558 ZXP(out) = xn;
560 unit->xn = xn;
561 unit->yn = yn;
562 unit->counter = counter;
565 void GbmanN_Ctor(GbmanN *unit){
566 SETCALC(GbmanN_next);
567 unit->xn = ZIN0(1);
568 unit->yn = ZIN0(2);
569 unit->counter = 0.f;
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;
585 double slope;
586 if(freq < unit->mRate->mSampleRate){
587 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
588 slope = 1.f / samplesPerCycle;
590 else {
591 samplesPerCycle = 1.f;
592 slope = 1.f;
595 double diff = xn - yn;
597 for (int i=0; i<inNumSamples; ++i) {
598 if(counter >= samplesPerCycle){
599 counter -= samplesPerCycle;
600 frac = 0.f;
602 double xPrev = xn;
603 if(xPrev < 0.f)
604 xn = 1.f - yn - xPrev;
605 else
606 xn = 1.f - yn + xPrev;
608 yn = xPrev;
610 diff = xn - xPrev;
612 counter++;
613 ZXP(out) = yn + (frac * diff);
614 frac += slope;
617 unit->xn = xn;
618 unit->yn = yn;
619 unit->counter = counter;
620 unit->frac = frac;
623 void GbmanL_Ctor(GbmanL *unit){
624 SETCALC(GbmanL_next);
625 unit->xn = ZIN0(1);
626 unit->yn = ZIN0(2);
627 unit->counter = 0.f;
628 unit->frac = 0.f;
629 GbmanL_next(unit, 1);
632 ////////////////////////////////////////////////////////////////////////////////
634 void HenonN_next(HenonN *unit, int inNumSamples)
636 float *out = ZOUT(0);
637 float freq = ZIN0(0);
638 double a = ZIN0(1);
639 double b = ZIN0(2);
640 double x0 = ZIN0(3);
641 double x1 = ZIN0(4);
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)){
655 if(!stable){
656 xnm2 = x0;
657 xnm1 = x0;
658 xn = x1;
660 stable = true;
661 unit->a = a;
662 unit->b = b;
663 unit->x0 = x0;
664 unit->x1 = x1;
667 for (int i=0; i<inNumSamples; ++i) {
668 if(counter >= samplesPerCycle){
669 counter -= samplesPerCycle;
670 if(stable){
671 xn = 1.f - (a * xnm1 * xnm1) + (b * xnm2);
672 //Print("%g, ", xn);
673 if((xn > 1.5f) || (xn < -1.5f)){
674 stable = false;
675 xn = 0.f;
676 xnm2 = x0;
677 xnm1 = x1;
679 else{
680 xnm2 = xnm1;
681 xnm1 = xn;
685 counter++;
687 ZXP(out) = xnm2;
690 unit->xn = xn;
691 unit->xnm1 = xnm1;
692 unit->xnm2 = xnm2;
693 unit->counter = counter;
694 unit->stable = stable;
697 void HenonN_Ctor(HenonN* unit)
699 SETCALC(HenonN_next);
701 unit->x0 = ZIN0(3);
702 unit->x1 = ZIN0(4);
703 unit->xn = unit->x1;
704 unit->xnm1 = unit->x0;
705 unit->xnm2 = unit->x1;
706 unit->a = ZIN0(1);
707 unit->b = ZIN0(2);
709 unit->counter = 0.f;
710 unit->stable = true;
712 HenonN_next(unit, 1);
715 ////////////////////////////////////////////////////////////////////////////////
717 void HenonL_next(HenonL *unit, int inNumSamples)
719 float *out = ZOUT(0);
720 float freq = ZIN0(0);
721 double a = ZIN0(1);
722 double b = ZIN0(2);
723 double x0 = ZIN0(3);
724 double x1 = ZIN0(4);
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;
734 double slope;
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)){
742 if(!stable){
743 xnm2 = x0;
744 xnm1 = x0;
745 xn = x1;
747 stable = true;
748 unit->a = a;
749 unit->b = b;
750 unit->x0 = x0;
751 unit->x1 = x1;
754 double diff = xnm1 - xnm2;
756 for (int i=0; i<inNumSamples; ++i) {
758 if(counter >= samplesPerCycle){
759 counter -= samplesPerCycle;
760 if(stable){
761 xn = 1.f - (a * xnm1 * xnm1) + (b * xnm2);
762 if(xn > 1.5f || xn < -1.5f){
763 stable = false;
764 diff = 0.f;
765 xn = 1.f;
766 xnm1 = 0.f;
767 xnm2 = 0.f;
769 else{
770 xnm2 = xnm1;
771 xnm1 = xn;
772 diff = xnm1 - xnm2;
774 frac = 0.f;
776 //Print("slope %g, x2 %g\n", slope, x2);
778 counter++;
780 ZXP(out) = xnm2 + (diff * frac);
781 frac += slope;
784 unit->xn = xn;
785 unit->xnm1 = xnm1;
786 unit->xnm2 = xnm2;
787 unit->counter = counter;
788 unit->stable = stable;
789 unit->frac = frac;
792 void HenonL_Ctor(HenonL* unit)
794 SETCALC(HenonL_next);
796 unit->x0 = ZIN0(3);
797 unit->x1 = ZIN0(4);
798 unit->xn = unit->x1;
799 unit->xnm1 = unit->x0;
800 unit->xnm2 = unit->x1;
801 unit->a = ZIN0(1);
802 unit->b = ZIN0(2);
803 unit->counter = 0.f;
804 unit->stable = true;
806 unit->frac = 0.;
808 HenonL_next(unit, 1);
812 ////////////////////////////////////////////////////////////////////////////////
814 void HenonC_next(HenonC *unit, int inNumSamples)
816 float *out = ZOUT(0);
817 float freq = ZIN0(0);
818 double a = ZIN0(1);
819 double b = ZIN0(2);
820 double x0 = ZIN0(3);
821 double x1 = ZIN0(4);
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;
836 double slope;
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)){
844 if(!stable){
845 xnm3 = xnm2;
846 xnm2 = x0;
847 xnm1 = x0;
848 xn = x1;
850 stable = true;
851 unit->a = a;
852 unit->b = b;
853 unit->x0 = x0;
854 unit->x1 = x1;
857 for (int i=0; i<inNumSamples; ++i) {
858 if(counter >= samplesPerCycle){
859 counter -= samplesPerCycle;
860 frac = 0.0;
862 if(stable){
863 xnm3 = xnm2;
864 xnm2 = xnm1;
865 xnm1 = xn;
867 xn = 1.f - (a * xnm1 * xnm1) + (b * xnm2);
868 if( (xn > 1.5) || (xn < -1.5) ){
869 stable = false;
870 xn = 1.;
871 xnm1 = xnm2 = xnm3 = 0.;
873 ipol3Coef(xnm3, xnm2, xnm1, xn, c0, c1, c2, c3);
875 //Print("slope %g, x2 %g\n", slope, x2);
877 counter++;
878 ZXP(out) = ipol3(frac, c0, c1, c2, c3);
879 frac += slope;
882 unit->xn = xn;
883 unit->xnm1 = xnm1;
884 unit->xnm2 = xnm2;
885 unit->xnm3 = xnm3;
886 unit->counter = counter;
887 unit->stable = stable;
888 unit->frac = frac;
889 unit->c0 = c0; unit->c1 = c1; unit->c2 = c2; unit->c3 = c3;
892 void HenonC_Ctor(HenonC* unit)
894 SETCALC(HenonC_next);
896 unit->x0 = ZIN0(3);
897 unit->x1 = ZIN0(4);
898 unit->xn = unit->x1;
899 unit->xnm1 = unit->x0;
900 unit->xnm2 = unit->xnm3 = unit->x1;
901 unit->a = ZIN0(1);
902 unit->b = ZIN0(2);
903 unit->counter = 0.f;
904 unit->stable = true;
905 unit->frac = 0.0;
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);
917 double a = ZIN0(1);
918 double b = ZIN0(2);
919 double c = ZIN0(3);
920 double d = ZIN0(4);
921 double x0 = ZIN0(5);
922 double y0 = ZIN0(6);
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)){
934 unit->x0 = xn = x0;
935 unit->y0 = yn = 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);
947 counter++;
948 ZXP(out) = xn;
951 unit->xn = xn;
952 unit->yn = yn;
953 unit->counter = counter;
956 void LatoocarfianN_Ctor(LatoocarfianN* unit){
957 SETCALC(LatoocarfianN_next);
959 unit->x0 = ZIN0(5);
960 unit->y0 = ZIN0(6);
961 unit->xn = unit->x0;
962 unit->yn = unit->y0;
963 unit->counter = 0.f;
965 LatoocarfianN_next(unit, 1);
969 ////////////////////////////////////////////////////////////////////////////////
971 void LatoocarfianL_next(LatoocarfianL *unit, int inNumSamples)
973 float *out = ZOUT(0);
974 float freq = ZIN0(0);
975 double a = ZIN0(1);
976 double b = ZIN0(2);
977 double c = ZIN0(3);
978 double d = ZIN0(4);
979 double x0 = ZIN0(5);
980 double y0 = ZIN0(6);
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;
989 double slope;
990 if(freq < unit->mRate->mSampleRate){
991 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
992 slope = 1.f / samplesPerCycle;
994 else {
995 samplesPerCycle = 1.f;
996 slope = 1.f;
999 if((unit->x0 != x0) || (unit->y0 != y0)){
1000 xnm1 = xn;
1001 unit->x0 = xn = x0;
1002 unit->y0 = yn = y0;
1005 double dx = xn - xnm1;
1007 for (int i=0; i<inNumSamples; ++i) {
1008 if(counter >= samplesPerCycle){
1009 counter -= samplesPerCycle;
1010 frac = 0.f;
1012 xnm1 = xn;
1014 xn = sin(yn * b) + c*sin(xnm1 * b);
1015 yn = sin(xnm1 * a) + d*sin(yn * a);
1017 dx = xn - xnm1;
1019 counter++;
1020 ZXP(out) = xnm1 + dx * frac;
1021 frac += slope;
1024 unit->xn = xn;
1025 unit->yn = yn;
1026 unit->counter = counter;
1027 unit->xnm1 = xnm1;
1028 unit->frac = frac;
1031 void LatoocarfianL_Ctor(LatoocarfianL* unit){
1032 SETCALC(LatoocarfianL_next);
1034 unit->x0 = ZIN0(5);
1035 unit->y0 = ZIN0(6);
1036 unit->xn = unit->x0;
1037 unit->yn = unit->y0;
1038 unit->xnm1 = unit->x0;
1039 unit->counter = 0.f;
1040 unit->frac = 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);
1051 double a = ZIN0(1);
1052 double b = ZIN0(2);
1053 double c = ZIN0(3);
1054 double d = ZIN0(4);
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;
1071 double slope;
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)){
1079 xnm3 = xnm2;
1080 xnm2 = xnm1;
1081 xnm1 = xn;
1082 unit->x0 = xn = x0;
1083 unit->y0 = yn = y0;
1086 for (int i=0; i<inNumSamples; ++i) {
1087 if(counter >= samplesPerCycle){
1088 counter -= samplesPerCycle;
1090 frac = 0.0;
1091 xnm3 = xnm2;
1092 xnm2 = xnm1;
1093 xnm1 = xn;
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);
1100 counter++;
1101 ZXP(out) = ipol3(frac, c0, c1, c2, c3);
1102 frac += slope;
1105 unit->xn = xn;
1106 unit->xnm1 = xnm1;
1107 unit->xnm2 = xnm2;
1108 unit->xnm3 = xnm3;
1109 unit->yn = yn;
1110 unit->counter = counter;
1111 unit->frac = frac;
1112 unit->c0 = c0; unit->c1 = c1; unit->c2 = c2; unit->c3 = c3;
1115 void LatoocarfianC_Ctor(LatoocarfianC* unit)
1117 SETCALC(LatoocarfianC_next);
1119 unit->x0 = ZIN0(5);
1120 unit->y0 = ZIN0(6);
1121 unit->xn = unit->x0;
1122 unit->yn = unit->y0;
1123 unit->xnm1 = unit->xnm2 = unit->xnm3 = unit->x0;
1124 unit->counter = 0.f;
1125 unit->frac = 0.0;
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;
1155 xn = (xn * a) + c;
1156 xn = sc_mod(xn, m);
1158 xscaled = (xn * scaleFactor) - 1.f;
1160 counter++;
1161 ZXP(out) = xscaled;
1163 unit->xn = xn;
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;
1192 double slope;
1193 if(freq < unit->mRate->mSampleRate){
1194 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
1195 slope = 1.f / samplesPerCycle;
1197 else {
1198 samplesPerCycle = 1.f;
1199 slope = 1.f;
1202 double diff = xscaled - xnm1;
1204 for (int i=0; i<inNumSamples; ++i) {
1205 if(counter >= samplesPerCycle){
1206 counter -= samplesPerCycle;
1207 frac = 0.f;
1208 xnm1 = xscaled;
1210 xn = (xn * a) + c;
1211 xn = sc_mod(xn, m);
1213 xscaled = (xn * scaleFactor) - 1.f;
1214 diff = xscaled - xnm1;
1216 counter++;
1217 ZXP(out) = xnm1 + (frac * diff);
1218 frac += slope;
1221 unit->xn = xn;
1222 unit->counter = counter;
1223 unit->xnm1 = xnm1;
1224 unit->frac = frac;
1227 void LinCongL_Ctor(LinCongL *unit){
1228 SETCALC(LinCongL_next);
1229 unit->xn = ZIN0(4);
1230 unit->counter = 0.f;
1231 unit->xnm1 = unit->xn;
1232 unit->frac = 0.f;
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;
1261 double slope;
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;
1272 frac = 0.0;
1273 xnm3 = xnm2;
1274 xnm2 = xnm1;
1275 xnm1 = xscaled;
1277 xn = (xn * a) + c;
1278 xn = sc_mod(xn, m);
1280 xscaled = (xn * scaleFactor) - 1.f;
1282 ipol3Coef(xnm3, xnm2, xnm1, xscaled, c0, c1, c2, c3);
1284 counter++;
1285 ZXP(out) = ipol3(frac, c0, c1, c2, c3);
1286 frac += slope;
1289 unit->xn = xn;
1290 unit->xnm1 = xnm1;
1291 unit->xnm2 = xnm2;
1292 unit->xnm3 = xnm3;
1293 unit->counter = counter;
1294 unit->frac = frac;
1295 unit->c0 = c0; unit->c1 = c1; unit->c2 = c2; unit->c3 = c3;
1298 void LinCongC_Ctor(LinCongC* unit)
1300 SETCALC(LinCongC_next);
1302 unit->x0 = ZIN0(4);
1303 unit->xn = unit->x0;
1304 unit->xnm1 = unit->xnm2 = unit->xnm3 = unit->x0;
1305 unit->counter = 0.f;
1306 unit->frac = 0.0;
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);
1318 double s = ZIN0(1);
1319 double r = ZIN0(2);
1320 double b = ZIN0(3);
1321 double h = ZIN0(4);
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;
1336 double slope;
1337 if(freq < unit->mRate->mSampleRate){
1338 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
1339 slope = 1.f / samplesPerCycle;
1341 else {
1342 samplesPerCycle = 1.f;
1343 slope = 1.f;
1346 if((unit->x0 != x0) || (unit->y0 != y0) || (unit->z0 != z0)){
1347 xnm1 = xn;
1348 ynm1 = yn;
1349 znm1 = zn;
1350 unit->x0 = xn = x0;
1351 unit->y0 = yn = y0;
1352 unit->z0 = zn = z0;
1355 double dx = xn - xnm1;
1357 for (int i=0; i<inNumSamples; ++i) {
1358 if(counter >= samplesPerCycle){
1359 counter -= samplesPerCycle;
1360 frac = 0.f;
1362 xnm1 = xn;
1363 ynm1 = yn;
1364 znm1 = zn;
1366 double k1x, k2x, k3x, k4x,
1367 k1y, k2y, k3y, k4y,
1368 k1z, k2z, k3z, k4z,
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);
1376 kxHalf = k1x * 0.5;
1377 kyHalf = k1y * 0.5;
1378 kzHalf = k1z * 0.5;
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));
1383 kxHalf = k2x * 0.5;
1384 kyHalf = k2y * 0.5;
1385 kzHalf = k2z * 0.5;
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;
1399 // Euler's method
1400 // xn = xnm1 + h * (s * (ynm1 - xnm1));
1401 // yn = ynm1 + h * (xnm1 * (r - znm1) - ynm1);
1402 // zn = znm1 + h * (xnm1 * ynm1 - b * znm1);
1404 dx = xn - xnm1;
1406 counter++;
1407 ZXP(out) = (xnm1 + dx * frac) * 0.04f;
1408 frac += slope;
1411 unit->xn = xn;
1412 unit->yn = yn;
1413 unit->zn = zn;
1414 unit->counter = counter;
1415 unit->xnm1 = xnm1;
1416 unit->ynm1 = ynm1;
1417 unit->znm1 = znm1;
1418 unit->frac = frac;
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;
1428 unit->frac = 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);
1439 double a = ZIN0(1);
1440 double b = ZIN0(2);
1441 double c = ZIN0(3);
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;
1452 if(unit->x0 != x0){
1453 unit->x0 = xn = x0;
1456 for (int i=0; i<inNumSamples; ++i) {
1457 if(counter >= samplesPerCycle){
1458 counter -= samplesPerCycle;
1460 xn = a * xn * xn + b * xn + c;
1462 counter++;
1463 ZXP(out) = xn;
1466 unit->xn = xn;
1467 unit->counter = counter;
1470 void QuadN_Ctor(QuadN* unit)
1472 SETCALC(QuadN_next);
1474 unit->x0 = ZIN0(4);
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);
1487 double a = ZIN0(1);
1488 double b = ZIN0(2);
1489 double c = ZIN0(3);
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;
1498 double slope;
1499 if(freq < unit->mRate->mSampleRate){
1500 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
1501 slope = 1.f / samplesPerCycle;
1503 else {
1504 samplesPerCycle = 1.f;
1505 slope = 1.f;
1508 if(unit->x0 != x0){
1509 xnm1 = xn;
1510 unit->x0 = xn = x0;
1513 double dx = xn - xnm1;
1515 for (int i=0; i<inNumSamples; ++i) {
1516 if(counter >= samplesPerCycle){
1517 counter -= samplesPerCycle;
1518 frac = 0.f;
1520 xnm1 = xn;
1522 xn = a * xn * xn + b * xn + c;
1524 dx = xn - xnm1;
1526 counter++;
1528 ZXP(out) = xnm1 + dx * frac;
1529 frac += slope;
1532 unit->xn = xn;
1533 unit->counter = counter;
1534 unit->xnm1 = xnm1;
1535 unit->frac = frac;
1538 void QuadL_Ctor(QuadL* unit){
1539 SETCALC(QuadL_next);
1541 unit->x0 = ZIN0(4);
1542 unit->xn = unit->x0;
1543 unit->xnm1 = unit->x0;
1544 unit->counter = 0.f;
1545 unit->frac = 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);
1556 double a = ZIN0(1);
1557 double b = ZIN0(2);
1558 double c = ZIN0(3);
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;
1573 double slope;
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;
1580 if(unit->x0 != x0){
1581 xnm3 = xnm2;
1582 xnm2 = xnm1;
1583 xnm1 = xn;
1584 unit->x0 = xn = x0;
1587 for (int i=0; i<inNumSamples; ++i) {
1588 if(counter >= samplesPerCycle){
1589 counter -= samplesPerCycle;
1591 frac = 0.0;
1592 xnm3 = xnm2;
1593 xnm2 = xnm1;
1594 xnm1 = xn;
1596 xn = a * xn * xn + b * xn + c;
1598 ipol3Coef(xnm3, xnm2, xnm1, xn, c0, c1, c2, c3);
1600 counter++;
1601 ZXP(out) = ipol3(frac, c0, c1, c2, c3);
1602 frac += slope;
1605 unit->xn = xn;
1606 unit->xnm1 = xnm1;
1607 unit->xnm2 = xnm2;
1608 unit->xnm3 = xnm3;
1609 unit->counter = counter;
1610 unit->frac = frac;
1611 unit->c0 = c0; unit->c1 = c1; unit->c2 = c2; unit->c3 = c3;
1614 void QuadC_Ctor(QuadC* unit)
1616 SETCALC(QuadC_next);
1618 unit->x0 = ZIN0(4);
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;
1623 unit->frac = 0.0;
1625 QuadC_next(unit, 1);
1628 ////////////////////////////////////////////////////////////////////////////////
1630 void StandardN_next(StandardN *unit, int inNumSamples)
1632 float *out = ZOUT(0);
1633 float freq = ZIN0(0);
1634 double k = ZIN0(1);
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)){
1649 unit->x0 = xn = x0;
1650 unit->y0 = yn = y0;
1653 for (int i=0; i<inNumSamples; ++i) {
1654 if(counter >= samplesPerCycle){
1655 counter -= samplesPerCycle;
1657 yn = yn + k * sin(xn);
1658 yn = mod2pi(yn);
1660 xn = xn + yn;
1661 xn = mod2pi(xn);
1663 output = (xn - PI) * RECPI;
1665 counter++;
1666 ZXP(out) = output;
1669 unit->xn = xn;
1670 unit->yn = yn;
1671 unit->counter = counter;
1674 void StandardN_Ctor(StandardN* unit)
1676 SETCALC(StandardN_next);
1678 unit->x0 = ZIN0(2);
1679 unit->y0 = ZIN0(3);
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);
1693 double k = ZIN0(1);
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;
1704 double slope;
1705 if(freq < unit->mRate->mSampleRate){
1706 samplesPerCycle = unit->mRate->mSampleRate / sc_max(freq, 0.001f);
1707 slope = 1.f / samplesPerCycle;
1709 else {
1710 samplesPerCycle = 1.f;
1711 slope = 1.f;
1714 if((unit->x0 != x0) || (unit->y0 != y0)){
1715 xnm1 = xn;
1716 unit->x0 = xn = x0;
1717 unit->y0 = yn = y0;
1720 double dx = xn - xnm1;
1722 for (int i=0; i<inNumSamples; ++i) {
1723 if(counter >= samplesPerCycle){
1724 counter -= samplesPerCycle;
1725 frac = 0.f;
1727 xnm1 = xn;
1729 yn = yn + k * sin(xn);
1730 yn = mod2pi(yn);
1732 xn = xn + yn;
1733 xn = mod2pi(xn);
1735 dx = xn - xnm1;
1737 counter++;
1738 ZXP(out) = (xnm1 + dx * frac - PI) * RECPI;
1739 frac += slope;
1742 unit->xn = xn;
1743 unit->yn = yn;
1744 unit->counter = counter;
1745 unit->xnm1 = xnm1;
1746 unit->frac = frac;
1749 void StandardL_Ctor(StandardL* unit){
1750 SETCALC(StandardL_next);
1752 unit->x0 = ZIN0(2);
1753 unit->y0 = ZIN0(3);
1754 unit->xn = unit->x0;
1755 unit->yn = unit->y0;
1756 unit->xnm1 = unit->x0;
1757 unit->counter = 0.f;
1758 unit->frac = 0.f;
1760 StandardL_next(unit, 1);
1763 ////////////////////////////////////////////////////////////////////////////////
1766 PluginLoad(Chaos)
1768 ft = inTable;
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);