-
Notifications
You must be signed in to change notification settings - Fork 122
/
AtkUGens.cpp
2405 lines (2060 loc) · 60.1 KB
/
AtkUGens.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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* AmbisonicUGens.cpp
* xSC3plugins
*
* Created by Josh Parmenter on 2/4/05.
* Copyright 2005 Josh Parmenter. All rights reserved.
* Copyright the ATK Community, Josh Parmenter, and Joseph Anderson, 2011
*
* J Anderson j.anderson[at]ambisonictoolkit.net
* J Parmenter j.parmenter[at]ambisonictoolkit.net
*
*/
/*
This file is part of SuperCollider3 version of the Ambisonic Toolkit (ATK).
The SuperCollider3 version of the Ambisonic Toolkit (ATK) is free software:
you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
The SuperCollider3 version of the Ambisonic Toolkit (ATK) is distributed in
the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the
SuperCollider3 version of the Ambisonic Toolkit (ATK). If not, see
<http://www.gnu.org/licenses/>.
*/
/*
SuperCollider real time audio synthesis system
Copyright (c) 2002 James McCartney. All rights reserved.
http://www.audiosynth.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
---------------------------------------------------------------------
The Ambisonic Toolkit (ATK) is a soundfield kernel support library.
The Ambisonic Toolkit (ATK) is intended to bring together a number of tools and
methods for working with Ambisonic surround sound. The intention is for the toolset
to be both ergonomic and comprehensive, providing both classic and novel algorithms
to creatively manipulate and synthesise complex Ambisonic soundfields.
The tools are framed for the user to think in terms of the soundfield kernel. By
this, it is meant the ATK addresses the holistic problem of creatively controlling
a complete soundfield, allowing and encouraging the composer to think beyond the
placement of sounds in a sound-space and instead attend to the impression and image
of a soundfield. This approach takes advantage of the model the Ambisonic
technology presents, and is viewed to be the idiomatic mode for working with the
Ambisonic technique.
We hope you enjoy the ATK!
For more information visit http://ambisonictoolkit.net/ or
email j.anderson[at]ambisonictoolkit.net OR j.parmenter[at]ambisonictoolkit.net
---------------------------------------------------------------------
*/
#include "SC_PlugIn.h"
const double sqrt3div6 = sqrt(3.) * 0.1666666667;
const double sqrt3div2 = sqrt(3.) * 0.5;
const double rsqrt6 = 1. / sqrt(6.);
const double sqrt6div3 = sqrt(6.) * 0.3333333333;
static InterfaceTable *ft;
typedef struct
{
float coefs[4][4];
} FoaMatrix;
struct FoaPanB : public Unit
{
float m_azimuth, m_elevation, m_W_amp, m_X_amp, m_Y_amp, m_Z_amp;
};
struct FoaDirectO : public Unit
{
FoaMatrix matrix;
float m_angle;
};
struct FoaDirectX : public FoaDirectO { };
struct FoaDirectY : public FoaDirectO { };
struct FoaDirectZ : public FoaDirectO { };
struct FoaRotate : public FoaDirectO { };
struct FoaTilt : public FoaDirectO { };
struct FoaTumble : public FoaDirectO { };
struct FoaFocusX : public FoaDirectO { };
struct FoaFocusY : public FoaDirectO { };
struct FoaFocusZ : public FoaDirectO { };
struct FoaPushX : public FoaDirectO { };
struct FoaPushY : public FoaDirectO { };
struct FoaPushZ : public FoaDirectO { };
struct FoaPressX : public FoaDirectO { };
struct FoaPressY : public FoaDirectO { };
struct FoaPressZ : public FoaDirectO { };
struct FoaZoomX : public FoaDirectO { };
struct FoaZoomY : public FoaDirectO { };
struct FoaZoomZ : public FoaDirectO { };
struct FoaAsymmetry : public FoaDirectO { };
struct FoaDominateX : public Unit
{
float m_gain;
FoaMatrix matrix;
};
struct FoaDominateY : FoaDominateX { };
struct FoaDominateZ : FoaDominateX { };
struct FoaNFC : public Unit
{
float m_distanceStart, m_y1x, m_y1y, m_y1z;
};
struct FoaProximity : public Unit
{
float m_distanceStart, m_y1x, m_y1y, m_y1z;
};
struct FoaPsychoShelf : public Unit
{
float m_freq, m_k0, m_k1;
float m_y1w, m_y2w, m_y1x, m_y2x, m_y1y, m_y2y, m_y1z, m_y2z;
};
extern "C"
{
void FoaPanB_next_aa(FoaPanB *unit, int inNumSamples);
void FoaPanB_next_kk(FoaPanB *unit, int inNumSamples);
void FoaPanB_Ctor(FoaPanB *unit);
void FoaDirectO_next_a(FoaDirectO *unit, int inNumSamples);
void FoaDirectO_next_k(FoaDirectO *unit, int inNumSamples);
void FoaDirectO_Ctor(FoaDirectO* unit);
void FoaDirectX_next_a(FoaDirectX *unit, int inNumSamples);
void FoaDirectX_next_k(FoaDirectX *unit, int inNumSamples);
void FoaDirectX_Ctor(FoaDirectX* unit);
void FoaDirectY_next_a(FoaDirectY *unit, int inNumSamples);
void FoaDirectY_next_k(FoaDirectY *unit, int inNumSamples);
void FoaDirectY_Ctor(FoaDirectY* unit);
void FoaDirectZ_next_a(FoaDirectZ *unit, int inNumSamples);
void FoaDirectZ_next_k(FoaDirectZ *unit, int inNumSamples);
void FoaDirectZ_Ctor(FoaDirectZ* unit);
void FoaRotate_next_a(FoaRotate *unit, int inNumSamples);
void FoaRotate_next_k(FoaRotate *unit, int inNumSamples);
void FoaRotate_Ctor(FoaRotate* unit);
void FoaTilt_next_a(FoaTilt *unit, int inNumSamples);
void FoaTilt_next_k(FoaTilt *unit, int inNumSamples);
void FoaTilt_Ctor(FoaTilt* unit);
void FoaTumble_next_a(FoaTumble *unit, int inNumSamples);
void FoaTumble_next_k(FoaTumble *unit, int inNumSamples);
void FoaTumble_Ctor(FoaTumble* unit);
void FoaFocusX_next_a(FoaFocusX *unit, int inNumSamples);
void FoaFocusX_next_k(FoaFocusX *unit, int inNumSamples);
void FoaFocusX_Ctor(FoaFocusX* unit);
void FoaFocusY_next_a(FoaFocusY *unit, int inNumSamples);
void FoaFocusY_next_k(FoaFocusY *unit, int inNumSamples);
void FoaFocusY_Ctor(FoaFocusY* unit);
void FoaFocusZ_next_a(FoaFocusZ *unit, int inNumSamples);
void FoaFocusZ_next_k(FoaFocusZ *unit, int inNumSamples);
void FoaFocusZ_Ctor(FoaFocusZ* unit);
void FoaPushX_next_a(FoaPushX *unit, int inNumSamples);
void FoaPushX_next_k(FoaPushX *unit, int inNumSamples);
void FoaPushX_Ctor(FoaPushX* unit);
void FoaPushY_next_a(FoaPushY *unit, int inNumSamples);
void FoaPushY_next_k(FoaPushY *unit, int inNumSamples);
void FoaPushY_Ctor(FoaPushY* unit);
void FoaPushZ_next_a(FoaPushZ *unit, int inNumSamples);
void FoaPushZ_next_k(FoaPushZ *unit, int inNumSamples);
void FoaPushZ_Ctor(FoaPushZ* unit);
void FoaPressX_next_a(FoaPressX *unit, int inNumSamples);
void FoaPressX_next_k(FoaPressX *unit, int inNumSamples);
void FoaPressX_Ctor(FoaPressX* unit);
void FoaPressY_next_a(FoaPressY *unit, int inNumSamples);
void FoaPressY_next_k(FoaPressY *unit, int inNumSamples);
void FoaPressY_Ctor(FoaPressY* unit);
void FoaPressZ_next_a(FoaPressZ *unit, int inNumSamples);
void FoaPressZ_next_k(FoaPressZ *unit, int inNumSamples);
void FoaPressZ_Ctor(FoaPressZ* unit);
void FoaZoomX_next_a(FoaZoomX *unit, int inNumSamples);
void FoaZoomX_next_k(FoaZoomX *unit, int inNumSamples);
void FoaZoomX_Ctor(FoaZoomX* unit);
void FoaZoomY_next_a(FoaZoomY *unit, int inNumSamples);
void FoaZoomY_next_k(FoaZoomY *unit, int inNumSamples);
void FoaZoomY_Ctor(FoaZoomY* unit);
void FoaZoomZ_next_a(FoaZoomZ *unit, int inNumSamples);
void FoaZoomZ_next_k(FoaZoomZ *unit, int inNumSamples);
void FoaZoomZ_Ctor(FoaZoomZ* unit);
void FoaDominateX_next_a(FoaDominateX *unit, int inNumSamples);
void FoaDominateX_next_k(FoaDominateX *unit, int inNumSamples);
void FoaDominateX_Ctor(FoaDominateX* unit);
void FoaDominateY_next_a(FoaDominateY *unit, int inNumSamples);
void FoaDominateY_next_k(FoaDominateY *unit, int inNumSamples);
void FoaDominateY_Ctor(FoaDominateY* unit);
void FoaDominateZ_next_a(FoaDominateZ *unit, int inNumSamples);
void FoaDominateZ_next_k(FoaDominateZ *unit, int inNumSamples);
void FoaDominateZ_Ctor(FoaDominateZ* unit);
void FoaAsymmetry_next_a(FoaAsymmetry *unit, int inNumSamples);
void FoaAsymmetry_next_k(FoaAsymmetry *unit, int inNumSamples);
void FoaAsymmetry_Ctor(FoaAsymmetry* unit);
void FoaNFC_next_k(FoaNFC *unit, int inNumSamples);
void FoaNFC_next_a(FoaNFC *unit, int inNumSamples);
void FoaNFC_Ctor(FoaNFC* unit);
void FoaProximity_next_k(FoaProximity *unit, int inNumSamples);
void FoaProximity_next_a(FoaProximity *unit, int inNumSamples);
void FoaProximity_Ctor(FoaProximity* unit);
void FoaPsychoShelf_next_k(FoaPsychoShelf *unit, int inNumSamples);
void FoaPsychoShelf_next_a(FoaPsychoShelf *unit, int inNumSamples);
void FoaPsychoShelf_Ctor(FoaPsychoShelf* unit);
}
inline float calcmatrixval(float coef, float curval){
return coef * curval;
}
// can perhaps optimize a bit here ... check for 0s???
#define CALC_MATRIX \
float curvals[4] = {Win[i], Xin[i], Yin[i], Zin[i]}; \
for(int j = 0; j < 4; j++){ \
float wAdd = calcmatrixval(matrix.coefs[0][j], curvals[j]); \
float xAdd = calcmatrixval(matrix.coefs[1][j], curvals[j]); \
float yAdd = calcmatrixval(matrix.coefs[2][j], curvals[j]); \
float zAdd = calcmatrixval(matrix.coefs[3][j], curvals[j]); \
float wNew = Wout[i] + wAdd; \
float xNew = Xout[i] + xAdd; \
float yNew = Yout[i] + yAdd; \
float zNew = Zout[i] + zAdd; \
Wout[i] = wNew; \
Xout[i] = xNew; \
Yout[i] = yNew; \
Zout[i] = zNew; \
}
#define SETUP_TRANSFORMS \
float *Win = IN(0); \
float *Xin = IN(1); \
float *Yin = IN(2); \
float *Zin = IN(3); \
float *Wout = OUT(0); \
float *Xout = OUT(1); \
float *Yout = OUT(2); \
float *Zout = OUT(3); \
ClearUnitOutputs(unit, inNumSamples); \
FoaMatrix matrix = unit->matrix; \
#define ZERO_MATRIX \
for(int i = 0; i < 4; i++){ \
for(int j = 0; j < 4; j++){ \
unit->matrix.coefs[i][j] = 0.f; \
} \
} \
#define SIN_COS \
sina = sin(azimuth); \
sinb = sin(elevation); \
\
cosa = cos(azimuth); \
cosb = cos(elevation); \
// this could be optimised
#define UNWRAPANGLE(next,prev) \
if (fabs(fmod(next, twopi) - fmod(prev, twopi)) <= pi) \
next = prev + fmod(next, twopi) - fmod(prev, twopi); \
else \
if ((fmod(next, twopi) - fmod(prev, twopi)) < 0) \
next = prev + fmod(next, twopi) - fmod(prev, twopi) + twopi; \
else \
next = prev + fmod(next, twopi) - fmod(prev, twopi) - twopi; \
/* FoaPanB - basic encoder (places sound on the sphere) */
void FoaPanB_Ctor(FoaPanB *unit)
{
if((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate)){
SETCALC(FoaPanB_next_aa);//aa
} else {
SETCALC(FoaPanB_next_kk);//ak
}
float azimuth = unit->m_azimuth = IN0(1);
float elevation = unit->m_elevation = IN0(2);
float sina, sinb, cosa, cosb;
SIN_COS
unit->m_W_amp = rsqrt2;
unit->m_X_amp = cosa * cosb;
unit->m_Y_amp = sina * cosb;
unit->m_Z_amp = sinb;
FoaPanB_next_kk(unit, 1);
}
void FoaPanB_next_kk(FoaPanB *unit, int inNumSamples)
{
float azimuth = IN0(1);
float elevation = IN0(2);
float *in = IN(0);
float *Wout = OUT(0);
float *Xout = OUT(1);
float *Yout = OUT(2);
float *Zout = OUT(3);
float Wamp = unit->m_W_amp;
float Xamp = unit->m_X_amp;
float Yamp = unit->m_Y_amp;
float Zamp = unit->m_Z_amp;
float sina, sinb, cosa, cosb;
if((unit->m_azimuth == azimuth) && (unit->m_elevation == elevation)){
for(int i = 0; i < inNumSamples; i++){
Wout[i] = in[i] * Wamp;
Xout[i] = in[i] * Xamp;
Yout[i] = in[i] * Yamp;
Zout[i] = in[i] * Zamp;
}
} else {
SIN_COS
float nextXamp = cosa * cosb;
float nextYamp = sina * cosb;
float nextZamp = sinb;
float xSlope = CALCSLOPE(nextXamp, Xamp);
float ySlope = CALCSLOPE(nextYamp, Yamp);
float zSlope = CALCSLOPE(nextZamp, Zamp);
for(int i = 0; i < inNumSamples; i++){
Wout[i] = in[i] * Wamp;
Xout[i] = in[i] * Xamp;
Yout[i] = in[i] * Yamp;
Zout[i] = in[i] * Zamp;
Xamp += xSlope;
Yamp += ySlope;
Zamp += zSlope;
}
unit->m_X_amp = Xamp;
unit->m_Y_amp = Yamp;
unit->m_Z_amp = Zamp;
unit->m_azimuth = azimuth;
unit->m_elevation = elevation;
}
}
void FoaPanB_next_aa(FoaPanB *unit, int inNumSamples)
{
float *pazimuth = IN(1);
float *pelevation = IN(2);
float *in = IN(0);
float *Wout = OUT(0);
float *Xout = OUT(1);
float *Yout = OUT(2);
float *Zout = OUT(3);
float Wamp = unit->m_W_amp;
float Xamp = unit->m_X_amp;
float Yamp = unit->m_Y_amp;
float Zamp = unit->m_Z_amp;
float sina, sinb, cosa, cosb, azimuth, elevation;
for(int i = 0; i < inNumSamples; i++){
if((unit->m_azimuth == pazimuth[i]) && (unit->m_elevation == pelevation[i])){
Wout[i] = in[i] * Wamp;
Xout[i] = in[i] * Xamp;
Yout[i] = in[i] * Yamp;
Zout[i] = in[i] * Zamp;
} else {
azimuth = pazimuth[i];
elevation = pelevation[i];
SIN_COS
Xamp = cosa * cosb;
Yamp = sina * cosb;
Zamp = sinb;
Wout[i] = in[i] * Wamp;
Xout[i] = in[i] * Xamp;
Yout[i] = in[i] * Yamp;
Zout[i] = in[i] * Zamp;
unit->m_azimuth = azimuth;
unit->m_elevation = elevation;
}
}
unit->m_X_amp = Xamp;
unit->m_Y_amp = Yamp;
unit->m_Z_amp = Zamp;
}
////////////////////// FoaRotate ///////////////////////
// uses 'angle' var.
#define FILL_ROTATE_MATRIX \
matrix.coefs[0][0] = matrix.coefs[3][3] = 1.; \
double cosa = cos(unit->m_angle); \
double sina = sin(unit->m_angle); \
matrix.coefs[1][1] = matrix.coefs[2][2] = cosa; \
matrix.coefs[1][2] = -sina; \
matrix.coefs[2][1] = sina;
void FoaRotate_Ctor(FoaRotate* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_ROTATE_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaRotate_next_a);
else
SETCALC(FoaRotate_next_k);
FoaRotate_next_k(unit, 1);
}
void FoaRotate_next_a(FoaRotate *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_ROTATE_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaRotate_next_k(FoaRotate *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_ROTATE_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaTilt ///////////////////////
// uses 'angle' var.
#define FILL_TILT_MATRIX \
matrix.coefs[0][0] = matrix.coefs[1][1] = 1.; \
double cosa = cos(unit->m_angle); \
double sina = sin(unit->m_angle); \
matrix.coefs[2][2] = matrix.coefs[3][3] = cosa; \
matrix.coefs[2][3] = -sina; \
matrix.coefs[3][2] = sina;
void FoaTilt_Ctor(FoaTilt* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_TILT_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaTilt_next_a);
else
SETCALC(FoaTilt_next_k);
FoaTilt_next_k(unit, 1);
}
void FoaTilt_next_a(FoaTilt *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_TILT_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaTilt_next_k(FoaTilt *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_TILT_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaTumble ///////////////////////
// uses 'angle' var.
#define FILL_TUMBLE_MATRIX \
matrix.coefs[0][0] = matrix.coefs[2][2] = 1.; \
double cosa = cos(unit->m_angle); \
double sina = sin(unit->m_angle); \
matrix.coefs[1][1] = matrix.coefs[3][3] = cosa; \
matrix.coefs[1][3] = -sina; \
matrix.coefs[3][1] = sina;
void FoaTumble_Ctor(FoaTumble* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_TUMBLE_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaTumble_next_a);
else
SETCALC(FoaTumble_next_k);
FoaTumble_next_k(unit, 1);
}
void FoaTumble_next_a(FoaTumble *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_TUMBLE_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaTumble_next_k(FoaTumble *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_TUMBLE_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaFocusX ///////////////////////
// uses 'angle' var.
#define FILL_FOCUSX_MATRIX \
double sina = sin(unit->m_angle); \
double roneplussinaa = 1. / (1. + sin(fabs(unit->m_angle))); \
double cosa = cos(unit->m_angle); \
double sina1sina = sina * roneplussinaa; \
matrix.coefs[0][0] = matrix.coefs[1][1] = roneplussinaa; \
matrix.coefs[2][2] = matrix.coefs[3][3] = cosa * roneplussinaa; \
matrix.coefs[0][1] = rsqrt2 * sina1sina; \
matrix.coefs[1][0] = sqrt2 * sina1sina; \
void FoaFocusX_Ctor(FoaFocusX* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_FOCUSX_MATRIX
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaFocusX_next_a);
else
SETCALC(FoaFocusX_next_k);
FoaFocusX_next_k(unit, 1);
}
void FoaFocusX_next_a(FoaFocusX *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_FOCUSX_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaFocusX_next_k(FoaFocusX *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_FOCUSX_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaFocusY ///////////////////////
// uses 'angle' var.
#define FILL_FOCUSY_MATRIX \
double sina = sin(unit->m_angle); \
double roneplussinaa = 1. / (1. + sin(fabs(unit->m_angle))); \
double cosa = cos(unit->m_angle); \
double sina1sina = sina * roneplussinaa; \
matrix.coefs[0][0] = matrix.coefs[2][2] = roneplussinaa; \
matrix.coefs[1][1] = matrix.coefs[3][3] = cosa * roneplussinaa; \
matrix.coefs[0][2] = rsqrt2 * sina1sina; \
matrix.coefs[2][0] = sqrt2 * sina1sina; \
void FoaFocusY_Ctor(FoaFocusY* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_FOCUSY_MATRIX
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaFocusY_next_a);
else
SETCALC(FoaFocusY_next_k);
FoaFocusY_next_k(unit, 1);
}
void FoaFocusY_next_a(FoaFocusY *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_FOCUSY_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaFocusY_next_k(FoaFocusY *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_FOCUSY_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaFocusZ ///////////////////////
// uses 'angle' var.
#define FILL_FOCUSZ_MATRIX \
double sina = sin(unit->m_angle); \
double roneplussinaa = 1. / (1. + sin(fabs(unit->m_angle))); \
double cosa = cos(unit->m_angle); \
double sina1sina = sina * roneplussinaa; \
matrix.coefs[0][0] = matrix.coefs[3][3] = roneplussinaa; \
matrix.coefs[1][1] = matrix.coefs[2][2] = cosa * roneplussinaa; \
matrix.coefs[0][3] = rsqrt2 * sina1sina; \
matrix.coefs[3][0] = sqrt2 * sina1sina; \
void FoaFocusZ_Ctor(FoaFocusZ* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_FOCUSZ_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaFocusZ_next_a);
else
SETCALC(FoaFocusZ_next_k);
FoaFocusZ_next_k(unit, 1);
}
void FoaFocusZ_next_a(FoaFocusZ *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_FOCUSZ_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaFocusZ_next_k(FoaFocusZ *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_FOCUSZ_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaDirectX /////////////////////
// uses 'angle' var.
#define FILL_DIRECTX_MATRIX \
matrix.coefs[0][0]= matrix.coefs[2][2] = matrix.coefs[3][3] = sqrt(1.0 + sin(unit->m_angle)); \
matrix.coefs[1][1] = sqrt(1.0 - sin(unit->m_angle)); \
void FoaDirectX_Ctor(FoaDirectX* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_DIRECTX_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaDirectX_next_a);
else
SETCALC(FoaDirectX_next_k);
FoaDirectX_next_k(unit, 1);
}
void FoaDirectX_next_a(FoaDirectX *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_DIRECTX_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaDirectX_next_k(FoaDirectX *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_DIRECTX_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaDirectY /////////////////////
// uses 'angle' var.
#define FILL_DIRECTY_MATRIX \
matrix.coefs[0][0]= matrix.coefs[1][1] = matrix.coefs[3][3] = sqrt(1.0 + sin(unit->m_angle)); \
matrix.coefs[2][2] = sqrt(1.0 - sin(unit->m_angle)); \
void FoaDirectY_Ctor(FoaDirectY* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_DIRECTY_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaDirectY_next_a);
else
SETCALC(FoaDirectY_next_k);
FoaDirectY_next_k(unit, 1);
}
void FoaDirectY_next_a(FoaDirectY *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_DIRECTY_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaDirectY_next_k(FoaDirectY *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_DIRECTY_MATRIX
}
} else {
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
}
}
unit->matrix = matrix;
unit->m_angle = angle;
}
////////////////////// FoaDirectZ /////////////////////
// uses 'angle' var.
#define FILL_DIRECTZ_MATRIX \
matrix.coefs[0][0]= matrix.coefs[1][1] = matrix.coefs[2][2] = sqrt(1.0 + sin(unit->m_angle)); \
matrix.coefs[3][3] = sqrt(1.0 - sin(unit->m_angle)); \
void FoaDirectZ_Ctor(FoaDirectZ* unit)
{
ZERO_MATRIX
unit->m_angle = IN0(4);
FoaMatrix matrix = unit->matrix;
FILL_DIRECTZ_MATRIX;
unit->matrix = matrix;
if(INRATE(4) == calc_FullRate)
SETCALC(FoaDirectZ_next_a);
else
SETCALC(FoaDirectZ_next_k);
FoaDirectZ_next_k(unit, 1);
}
void FoaDirectZ_next_a(FoaDirectZ *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float *angle = IN(4);
for(int i = 0; i < inNumSamples; i++){
if(angle[i] != unit->m_angle){
unit->m_angle = angle[i];
FILL_DIRECTZ_MATRIX
}
CALC_MATRIX
}
unit->matrix = matrix;
}
void FoaDirectZ_next_k(FoaDirectZ *unit, int inNumSamples)
{
SETUP_TRANSFORMS
float angle = IN0(4);
float angleslope;
UNWRAPANGLE(angle, unit->m_angle);
if(angle != unit->m_angle){
angleslope = CALCSLOPE(angle, unit->m_angle);
for(int i = 0; i < inNumSamples; i++){
CALC_MATRIX
unit->m_angle += angleslope;
FILL_DIRECTZ_MATRIX
}