-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSuperBufRd.cpp
executable file
·856 lines (724 loc) · 21.1 KB
/
SuperBufRd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
#include "SC_PlugIn.hpp"
// InterfaceTable contains pointers to functions in the host (server).
static InterfaceTable *ft;
#define SP_UPPER_BOUND 2139095040
#define SP_GET_INS_OUTS \
float *outMsd = out(0); \
float *outLsd = out(1); \
float *outPlaying = out(2); \
double startMsd = in0(2); \
double startLsd = in0(3); \
double start = startMsd + startLsd; \
double endMsd = in0(4); \
double endLsd = in0(5); \
double end = endMsd + endLsd; \
double resetMsd = in0(6); \
double resetLsd = in0(7); \
double reset = resetMsd + resetLsd; \
const int loop = (int)in0(8); \
float prevtrig = mPrevtrig; \
double pos = mPos; \
int playing = mPlaying; \
#define SPX_GET_INS_OUTS \
float *phase0Msd = out(0); \
float *phase0Lsd = out(1); \
float *phase1Msd = out(2); \
float *phase1Lsd = out(3); \
float *pan0 = out(4); \
float *phase2Msd = out(5); \
float *phase2Lsd = out(6); \
float *phase3Msd = out(7); \
float *phase3Lsd = out(8); \
float *pan1 = out(9); \
float *pan2 = out(10); \
float *outPlaying = out(11); \
double startMsd = in0(2); \
double startLsd = in0(3); \
double start = startMsd + startLsd; \
double endMsd = in0(4); \
double endLsd = in0(5); \
double end = endMsd + endLsd; \
double resetMsd = in0(6); \
double resetLsd = in0(7); \
double reset = resetMsd + resetLsd; \
const int loop = (int)in0(8); \
int overlap = (int)in0(9); \
if (overlap > (end - start) * 0.5) { \
overlap = (int)((end - start) * 0.5); \
} else if (overlap < 0) { \
overlap = 0; \
} \
float prevtrig = mPrevtrig; \
double pos = mPos; \
int playing = mPlaying; \
int isOverlapping = mIsOverlapping; \
double oldPos = mOldPos; \
double overlapPos = mOverlapPos; \
int oldPlaying = mOldPlaying; \
int firstTime = mFirstTime; \
#define SP_TEST_TRIG \
if (prevtrig <= 0.f && trig > 0.f) { \
if (reset < start) { \
pos = start; \
} else { \
pos = reset; \
} \
playing = 0; \
} \
#define SPX_TEST_TRIG \
if (prevtrig <= 0.f && trig > 0.f) { \
oldPos = pos; \
oldPlaying = playing; \
overlapPos = 0; \
isOverlapping = 1; \
if (reset < (start + overlap) && rate > 0) { \
firstTime = 1; \
} \
if (reset < start) { \
pos = start; \
} else { \
pos = reset; \
} \
playing = 0; \
} \
#define SP_WRITE_OUTS \
float posMsd = (float)pos; \
float posLsd = (float)(pos - posMsd); \
outMsd[i] = posMsd; \
outLsd[i] = posLsd; \
outPlaying[i] = (playing == 0); \
#define SPX_WRITE_OUTS \
float posMsd = (float)pos; \
float posLsd = (float)(pos - posMsd); \
phase0Msd[i] = posMsd; \
phase0Lsd[i] = posLsd; \
if (loop && pos < overlap && !firstTime) { \
double endPos = pos + end; \
posMsd = (float)endPos; \
posLsd = (float)(endPos - posMsd); \
phase1Msd[i] = posMsd; \
phase1Lsd[i] = posLsd; \
pan0[i] = 1 - (2 * pos / (overlap - 1)); \
} else { \
phase1Msd[i] = 0; \
phase1Lsd[i] = 0; \
pan0[i] = -1; \
} \
if (isOverlapping) { \
posMsd = (float)oldPos; \
posLsd = (float)(oldPos - posMsd); \
phase2Msd[i] = posMsd; \
phase2Lsd[i] = posLsd; \
if (loop && oldPos < overlap) { \
double endOldPos = oldPos + end; \
posMsd = (float)endOldPos; \
posLsd = (float)(endOldPos - posMsd); \
phase3Msd[i] = posMsd; \
phase3Lsd[i] = posLsd; \
pan1[i] = 1 - (2 * oldPos / (overlap - 1)); \
} else { \
phase3Msd[i] = 0; \
phase3Lsd[i] = 0; \
pan1[i] = -1; \
} \
pan2[i] = 1 - (2 * overlapPos / (overlap - 1)); \
} else { \
phase2Msd[i] = 0; \
phase2Lsd[i] = 0; \
phase3Msd[i] = 0; \
phase3Lsd[i] = 0; \
pan1[i] = -1; \
pan2[i] = -1; \
} \
outPlaying[i] = (playing == 0); \
#define SP_INCREMENT_POS \
playing = 0; \
if(loop){ \
pos = sc_wrap(pos + rate, start, end); \
} else { \
pos += rate; \
if(pos < start){ pos = start; playing = -1; } \
if(pos > end){ pos = end; playing = 1; } \
}\
#define SPX_INCREMENT_POS \
playing = 0; \
if(loop){ \
pos = sc_wrap(pos + rate, start, end); \
} else { \
pos += rate; \
if(pos < start){ pos = start; playing = -1; } \
if(pos > end){ pos = end; playing = 1; } \
}\
if (firstTime && pos > overlap) { \
firstTime = 0; \
} \
if (isOverlapping) { \
overlapPos += 1; \
if (overlapPos >= overlap) { \
isOverlapping = 0; \
} \
if (loop) { \
oldPos = sc_wrap(oldPos + rate, start, end); \
} else { \
oldPos += rate; \
if(oldPos < start){ pos = start; playing = -1; } \
if(oldPos > end){ pos = end; playing = 1; } \
} \
} \
#define SP_STORE_STRUCT \
mPrevtrig = trig; \
mPos = pos; \
mPlaying = playing; \
#define SPX_STORE_STRUCT \
mPrevtrig = trig; \
mPos = pos; \
mPlaying = playing; \
mIsOverlapping = isOverlapping; \
mOldPos = oldPos; \
mOverlapPos = overlapPos; \
mOldPlaying = oldPlaying; \
mFirstTime = firstTime; \
//////////////////////////////////////////////////////////////////
// SUPERPHASOR
//////////////////////////////////////////////////////////////////
struct SuperPhasor : public SCUnit{
public:
SuperPhasor() {
// 1. initialize the unit generator state variables.
mPrevtrig = in0(0);
double startMsd = in0(2);
double startLsd = in0(3);
double start = startMsd + startLsd;
double resetMsd = in0(6);
double resetLsd = in0(7);
double reset = resetMsd + resetLsd;
if (reset < start) {
mPos = start;
} else {
mPos = reset;
}
mPlaying = 0;
// 2. set calc function
if (isAudioRateIn(0)) {
if (isAudioRateIn(1)) {
// both trig and rate are audio rate
set_calc_function<SuperPhasor,&SuperPhasor::next_aa>();
} else {
// only trig is audio rate
set_calc_function<SuperPhasor,&SuperPhasor::next_ak>();
}
} else {
if (isAudioRateIn(1)) {
// only rate is audio rate
set_calc_function<SuperPhasor,&SuperPhasor::next_ka>();
} else {
// nothing is audio rate
set_calc_function<SuperPhasor,&SuperPhasor::next_kk>();
}
}
}
private:
float mPrevtrig;
double mPos;
int mPlaying;
//////////////////////////////////////////////////////////////////
// calculation function for all control rate arguments
void next_kk(int inNumSamples)
{
SP_GET_INS_OUTS
const float trig = in0(0);
const float rate = in0(1);
SP_TEST_TRIG
for (int i=0; i < inNumSamples; ++i)
{
SP_WRITE_OUTS
SP_INCREMENT_POS
}
SP_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate rate
void next_ka(int inNumSamples)
{
SP_GET_INS_OUTS
const float trig = in0(0);
const float* rateBlock = in(1);
float rate;
SP_TEST_TRIG
for (int i=0; i < inNumSamples; ++i)
{
rate = rateBlock[i];
SP_WRITE_OUTS
SP_INCREMENT_POS
}
SP_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate trig
void next_ak(int inNumSamples)
{
SP_GET_INS_OUTS
const float* trigBlock = in(0);
const float rate = in0(1);
float trig;
for (int i=0; i < inNumSamples; ++i)
{
trig = trigBlock[i];
SP_TEST_TRIG
SP_WRITE_OUTS
SP_INCREMENT_POS
prevtrig = trig;
}
SP_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate trig and rate
void next_aa(int inNumSamples)
{
SP_GET_INS_OUTS
const float* trigBlock = in(0);
const float* rateBlock = in(1);
float trig;
float rate;
for (int i=0; i < inNumSamples; ++i)
{
trig = trigBlock[i];
rate = rateBlock[i];
SP_TEST_TRIG
SP_WRITE_OUTS
SP_INCREMENT_POS
prevtrig = trig;
}
SP_STORE_STRUCT
}
};
//////////////////////////////////////////////////////////////////
// SUPERPHASORX
//////////////////////////////////////////////////////////////////
struct SuperPhasorX : public SCUnit{
public:
SuperPhasorX() {
// 1. initialize the unit generator state variables.
mPrevtrig = in0(0);
float rate = in0(1);
double startMsd = in0(2);
double startLsd = in0(3);
double start = startMsd + startLsd;
double resetMsd = in0(6);
double resetLsd = in0(7);
double reset = resetMsd + resetLsd;
int overlap = (int)in0(9);
if (reset < start) {
mPos = start;
} else {
mPos = reset;
}
mPlaying = 0;
mIsOverlapping = 0;
mOldPos = 0;
mOverlapPos = 0;
mOldPlaying = 0;
if (reset < (start + overlap) && rate > 0) {
mFirstTime = 1;
} else {
mFirstTime = 0;
}
// 2. set the calculation function.
if (isAudioRateIn(0)) {
if (isAudioRateIn(1)) {
// both trig and rate are audio rate
set_calc_function<SuperPhasorX,&SuperPhasorX::next_aa>();
} else {
// only trig is audio rate
set_calc_function<SuperPhasorX,&SuperPhasorX::next_ak>();
}
} else {
if (isAudioRateIn(1)) {
// only rate is audio rate
set_calc_function<SuperPhasorX,&SuperPhasorX::next_ka>();
} else {
// nothing is audio rate
set_calc_function<SuperPhasorX,&SuperPhasorX::next_kk>();
}
}
}
private:
float mPrevtrig;
double mPos;
int mPlaying;
int mIsOverlapping;
double mOldPos;
double mOverlapPos;
int mOldPlaying;
int mFirstTime;
//////////////////////////////////////////////////////////////////
// calculation function for all control rate arguments
void next_kk(int inNumSamples)
{
SPX_GET_INS_OUTS
const float trig = in0(0);
const float rate = in0(1);
SPX_TEST_TRIG
for (int i=0; i < inNumSamples; ++i)
{
SPX_WRITE_OUTS
SPX_INCREMENT_POS
}
SPX_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate rate
void next_ka(int inNumSamples)
{
SPX_GET_INS_OUTS
const float trig = in0(0);
const float* rateBlock = in(1);
float rate = in0(1);
SPX_TEST_TRIG
for (int i=0; i < inNumSamples; ++i)
{
rate = rateBlock[i];
SPX_WRITE_OUTS
SPX_INCREMENT_POS
}
SPX_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate trig
void next_ak(int inNumSamples)
{
SPX_GET_INS_OUTS
const float* trigBlock = in(0);
const float rate = in0(1);
float trig;
for (int i=0; i < inNumSamples; ++i)
{
trig = trigBlock[i];
SPX_TEST_TRIG
SPX_WRITE_OUTS
SPX_INCREMENT_POS
prevtrig = trig;
}
SPX_STORE_STRUCT
}
//////////////////////////////////////////////////////////////////
// calculation function for audio rate trig and rate
void next_aa(int inNumSamples)
{
SPX_GET_INS_OUTS
const float* trigBlock = in(0);
const float* rateBlock = in(1);
float trig;
float rate = in0(1);
for (int i=0; i < inNumSamples; ++i)
{
trig = trigBlock[i];
rate = rateBlock[i];
SPX_TEST_TRIG
SPX_WRITE_OUTS
SPX_INCREMENT_POS
prevtrig = trig;
}
SPX_STORE_STRUCT
}
};
//////////////////////////////////////////////////////////////////
// SUPERBUFRD
//////////////////////////////////////////////////////////////////
inline double sc_loop(Unit *unit, double in, double hi, int loop)
{
// avoid the divide if possible
if (in >= hi) {
if (!loop) {
unit->mDone = true;
return hi;
}
in -= hi;
if (in < hi) return in;
} else if (in < 0.) {
if (!loop) {
unit->mDone = true;
return 0.;
}
in += hi;
if (in >= 0.) return in;
} else return in;
return in - hi * floor(in/hi);
}
#define LOOP_INNER_BODY_1(SAMPLE_INDEX) \
OUT(channel)[SAMPLE_INDEX] = table1[index]; \
#define LOOP_INNER_BODY_2(SAMPLE_INDEX) \
float b = table1[index]; \
float c = table2[index]; \
OUT(channel)[SAMPLE_INDEX] = b + fracphase * (c - b); \
#define LOOP_INNER_BODY_4(SAMPLE_INDEX) \
float a = table0[index]; \
float b = table1[index]; \
float c = table2[index]; \
float d = table3[index]; \
OUT(channel)[SAMPLE_INDEX] = cubicinterp(fracphase, a, b, c, d); \
#define LOOP_BODY_4(SAMPLE_INDEX) \
phase = sc_loop((Unit*)unit, phase, loopMax, loop); \
int32 iphase = (int32)phase; \
const float* table1 = bufData + iphase * bufChannels; \
const float* table0 = table1 - bufChannels; \
const float* table2 = table1 + bufChannels; \
const float* table3 = table2 + bufChannels; \
if (iphase == 0) { \
if (loop) { \
table0 += bufSamples; \
} else { \
table0 += bufChannels; \
} \
} else if (iphase >= guardFrame) { \
if (iphase == guardFrame) { \
if (loop) { \
table3 -= bufSamples; \
} else { \
table3 -= bufChannels; \
} \
} else { \
if (loop) { \
table2 -= bufSamples; \
table3 -= bufSamples; \
} else { \
table2 -= bufChannels; \
table3 -= 2 * bufChannels; \
} \
} \
} \
int32 index = 0; \
float fracphase = phase - (double)iphase; \
if(numOutputs == bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_4(SAMPLE_INDEX) \
index++; \
} \
} else if (numOutputs < bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_4(SAMPLE_INDEX) \
index++; \
} \
index += (bufChannels - numOutputs); \
} else { \
for (uint32 channel=0; channel<bufChannels; ++channel) { \
LOOP_INNER_BODY_4(SAMPLE_INDEX) \
index++; \
} \
for (uint32 channel=bufChannels; channel<numOutputs; ++channel) { \
OUT(channel)[SAMPLE_INDEX] = 0.f; \
index++; \
} \
} \
#define LOOP_BODY_2(SAMPLE_INDEX) \
phase = sc_loop((Unit*)unit, phase, loopMax, loop); \
int32 iphase = (int32)phase; \
const float* table1 = bufData + iphase * bufChannels; \
const float* table2 = table1 + bufChannels; \
if (iphase > guardFrame) { \
if (loop) { \
table2 -= bufSamples; \
} else { \
table2 -= bufChannels; \
} \
} \
int32 index = 0; \
float fracphase = phase - (double)iphase; \
if(numOutputs == bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_2(SAMPLE_INDEX) \
index++; \
} \
} else if (numOutputs < bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_2(SAMPLE_INDEX) \
index++; \
} \
index += (bufChannels - numOutputs); \
} else { \
for (uint32 channel=0; channel<bufChannels; ++channel) { \
LOOP_INNER_BODY_2(SAMPLE_INDEX) \
index++; \
} \
for (uint32 channel=bufChannels; channel<numOutputs; ++channel) { \
OUT(channel)[SAMPLE_INDEX] = 0.f; \
index++; \
} \
} \
#define LOOP_BODY_1(SAMPLE_INDEX) \
phase = sc_loop((Unit*)unit, phase, loopMax, loop); \
int32 iphase = (int32)phase; \
const float* table1 = bufData + iphase * bufChannels; \
int32 index = 0; \
if(numOutputs == bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_1(SAMPLE_INDEX) \
index++; \
} \
} else if (numOutputs < bufChannels) { \
for (uint32 channel=0; channel<numOutputs; ++channel) { \
LOOP_INNER_BODY_1(SAMPLE_INDEX) \
index++; \
} \
index += (bufChannels - numOutputs); \
} else { \
for (uint32 channel=0; channel<bufChannels; ++channel) { \
LOOP_INNER_BODY_1(SAMPLE_INDEX) \
index++; \
} \
for (uint32 channel=bufChannels; channel<numOutputs; ++channel) { \
OUT(channel)[SAMPLE_INDEX] = 0.f; \
index++; \
} \
} \
#define CHECK_BUFFER_DATA \
if (!bufData) { \
if(unit->mWorld->mVerbosity > -1 && !unit->mDone && (unit->m_failedBufNum != fbufnum)) { \
Print("Buffer UGen: no buffer data\n"); \
unit->m_failedBufNum = fbufnum; \
} \
ClearUnitOutputs(unit, inNumSamples); \
return; \
} else { \
if (bufChannels != numOutputs) { \
if(unit->mWorld->mVerbosity > -1 && !unit->mDone && (unit->m_failedBufNum != fbufnum)) { \
Print("Buffer UGen channel mismatch: expected %i, yet buffer has %i channels\n", \
numOutputs, bufChannels); \
unit->m_failedBufNum = fbufnum; \
} \
} \
} \
struct SuperBufRd : public Unit
{
float m_fbufnum;
float m_failedBufNum;
SndBuf *m_buf;
};
void SuperBufRd_Ctor(SuperBufRd *unit);
void SuperBufRd_next_4(SuperBufRd *unit, int inNumSamples);
void SuperBufRd_next_2(SuperBufRd *unit, int inNumSamples);
void SuperBufRd_next_1(SuperBufRd *unit, int inNumSamples);
void SuperBufRd_Ctor(SuperBufRd *unit)
{
int interp = (int)ZIN0(4);
switch (interp) {
case 1 : SETCALC(SuperBufRd_next_1); break;
case 2 : SETCALC(SuperBufRd_next_2); break;
default : SETCALC(SuperBufRd_next_4); break;
}
unit->m_fbufnum = -1e9f;
unit->m_failedBufNum = -1e9f;
SuperBufRd_next_1(unit, 1);
}
void SuperBufRd_next_4(SuperBufRd *unit, int inNumSamples)
{
float *phaseMsd = ZIN(1);
float *phaseLsd = ZIN(2);
int32 loop = (int32)ZIN0(3);
GET_BUF_SHARED
uint32 numOutputs = unit->mNumOutputs;
CHECK_BUFFER_DATA
double loopMax = (double)(loop ? bufFrames : bufFrames - 1);
for (int i=0; i<inNumSamples; ++i) {
double phaseMsdIn = ZXP(phaseMsd);
double phaseLsdIn = ZXP(phaseLsd);
double phase = phaseMsdIn + phaseLsdIn;
LOOP_BODY_4(i)
}
}
void SuperBufRd_next_2(SuperBufRd *unit, int inNumSamples)
{
float *phaseMsd = ZIN(1);
float *phaseLsd = ZIN(2);
int32 loop = (int32)ZIN0(3);
GET_BUF_SHARED
uint32 numOutputs = unit->mNumOutputs;
CHECK_BUFFER_DATA
double loopMax = (double)(loop ? bufFrames : bufFrames - 1);
for (int i=0; i<inNumSamples; ++i) {
double phaseMsdIn = ZXP(phaseMsd);
double phaseLsdIn = ZXP(phaseLsd);
double phase = phaseMsdIn + phaseLsdIn;
LOOP_BODY_2(i)
}
}
void SuperBufRd_next_1(SuperBufRd *unit, int inNumSamples)
{
float *phaseMsd = ZIN(1);
float *phaseLsd = ZIN(2);
int32 loop = (int32)ZIN0(3);
GET_BUF_SHARED
uint32 numOutputs = unit->mNumOutputs;
CHECK_BUFFER_DATA
double loopMax = (double)(loop ? bufFrames : bufFrames - 1);
for (int i=0; i<inNumSamples; ++i) {
double phaseMsdIn = ZXP(phaseMsd);
double phaseLsdIn = ZXP(phaseLsd);
double phase = phaseMsdIn + phaseLsdIn;
LOOP_BODY_1(i)
}
}
//////////////////////////////////////////////////////////////////
// SUPERBUFFRAMES
//////////////////////////////////////////////////////////////////
#define CTOR_GET_BUF \
float fbufnum = ZIN0(0); \
fbufnum = sc_max(0.f, fbufnum); \
uint32 bufnum = (int)fbufnum; \
World *world = unit->mWorld; \
SndBuf *buf; \
if (bufnum >= world->mNumSndBufs) { \
int localBufNum = bufnum - world->mNumSndBufs; \
Graph *parent = unit->mParent; \
if(localBufNum <= parent->localBufNum) { \
buf = parent->mLocalSndBufs + localBufNum; \
} else { \
bufnum = 0; \
buf = world->mSndBufs + bufnum; \
} \
} else { \
buf = world->mSndBufs + bufnum; \
}
struct BufInfoUnit : public Unit
{
float m_fbufnum;
SndBuf *m_buf;
};
void SuperBufFrames_next(BufInfoUnit *unit, int inNumSamples);
void SuperBufFrames_Ctor(BufInfoUnit *unit, int inNumSamples);
void SuperBufFrames_next(BufInfoUnit *unit, int inNumSamples)
{
SIMPLE_GET_BUF_SHARED
double frames = buf->frames;
float msd = (float)frames;
float lsd = (float)(frames - msd);
ZOUT0(0) = msd;
ZOUT0(1) = lsd;
}
void SuperBufFrames_Ctor(BufInfoUnit *unit, int inNumSamples)
{
SETCALC(SuperBufFrames_next);
CTOR_GET_BUF
unit->m_fbufnum = fbufnum;
unit->m_buf = buf;
double frames = buf->frames;
float msd = (float)frames;
float lsd = (float)(frames - msd);
ZOUT0(0) = msd;
ZOUT0(1) = lsd;
}
// the entry point is called by the host when the plug-in is loaded
PluginLoad(SuperBufRdUGens)
{
// InterfaceTable *inTable implicitly given as argument to the load function
ft = inTable; // store pointer to InterfaceTable
// registerUnit takes the place of the Define*Unit functions. It automatically checks for the presence of a
// destructor function.
// However, it does not seem to be possible to disable buffer aliasing with the C++ header.
registerUnit<SuperPhasor>(ft, "SuperPhasor");
registerUnit<SuperPhasorX>(ft, "SuperPhasorX");
DefineSimpleUnit(SuperBufRd);
#define DefineBufInfoUnit(name) \
(*ft->fDefineUnit)(#name, sizeof(BufInfoUnit), (UnitCtorFunc)&name##_Ctor, 0, 0);
DefineBufInfoUnit(SuperBufFrames);
}