-
Notifications
You must be signed in to change notification settings - Fork 0
/
udo-collection.udo
1246 lines (1108 loc) · 50.3 KB
/
udo-collection.udo
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; collection of all UDOs in this repo
;;; maybe it needs some reorderning when some UDOs depend of each
;;; other
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/* utilities */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ctrl_tbl
;;; - allows indexing the numeric data from a text file with optional
;;; interpolation between values
;;; - aIndex -> any indexing input e.g. a phasor (0 - 1)
;;; - SFile -> path to .txt file with the numeric data (uses GEN23,
;;; see csound manual for information for this)
;;; - iInterp -> interpolation mode; 0 = no interpolation, 1 = linear
;;; interpolation, 3 = cubic interpolation
;;; - aOut -> indexed data
opcode ctrl_tbl,a,aSo
;; input
aIndex,SFile,iInterp xin
;; create table from file
iTable ftgen 0,0,0,-23,SFile
;; read the table
if iInterp == 1 then
aCtrl tablei aIndex,iTable,1
elseif iInterp == 0 then
aCtrl table aIndex,iTable,1
elseif iInterp == 3 then
aCtrl table3 aIndex,iTable,1
endif
;; output
xout aCtrl
;; by philipp von neumann
endop
/* ambisonics */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ambi_encode
;;; - encode a mono signal up to 8th order ambisonics
;;; - takes a mono signal and creates a audio-array in the size
;;; depending on iorder ((iorder+1)^2) as output
;;; - kaz = azimuth in degrees (0 - 360)
;;; - kel = eleveation in degrees (0 - 360)
;;; - render the file with 'fout' opcode in csound
opcode ambi_encode,a[],aikk
asnd,iorder,kaz,kel xin
aOutArr[] init (iorder+1)^2
kaz = $M_PI*kaz/180
kel = $M_PI*kel/180
kcos_el = cos(kel)
ksin_el = sin(kel)
kcos_az = cos(kaz)
ksin_az = sin(kaz)
aOutArr[0] = asnd ; W
aOutArr[1] = kcos_el*ksin_az*asnd ; Y = Y(1,-1)
aOutArr[2] = ksin_el*asnd ; Z = Y(1,0)
aOutArr[3] = kcos_el*kcos_az*asnd ; X = Y(1,1)
if iorder < 2 goto end
i2 = sqrt(3)/2
kcos_el_p2 = kcos_el*kcos_el
ksin_el_p2 = ksin_el*ksin_el
kcos_2az = cos(2*kaz)
ksin_2az = sin(2*kaz)
kcos_2el = cos(2*kel)
ksin_2el = sin(2*kel)
aOutArr[4] = i2*kcos_el_p2*ksin_2az*asnd ; V = Y(2,-2)
aOutArr[5] = i2*ksin_2el*ksin_az*asnd ; S = Y(2,-1)
aOutArr[6] = .5*(3*ksin_el_p2 - 1)*asnd ; R = Y(2,0)
aOutArr[7] = i2*ksin_2el*kcos_az*asnd ; S = Y(2,1)
aOutArr[8] = i2*kcos_el_p2*kcos_2az*asnd ; U = Y(2,2)
if iorder < 3 goto end
i31 = sqrt(5/8)
i32 = sqrt(15)/2
i33 = sqrt(3/8)
kcos_el_p3 = kcos_el*kcos_el_p2
ksin_el_p3 = ksin_el*ksin_el_p2
kcos_3az = cos(3*kaz)
ksin_3az = sin(3*kaz)
kcos_3el = cos(3*kel)
ksin_3el = sin(3*kel)
aOutArr[9] = i31*kcos_el_p3*ksin_3az*asnd ; Q = Y(3,-3)
aOutArr[10] = i32*ksin_el*kcos_el_p2*ksin_2az*asnd ; O = Y(3,-2)
aOutArr[11] = i33*kcos_el*(5*ksin_el_p2-1)*ksin_az*asnd ; M = Y(3,-1)
aOutArr[12] = .5*ksin_el*(5*ksin_el_p2-3)*asnd ; K = Y(3,0)
aOutArr[13] = i33*kcos_el*(5*ksin_el_p2-1)*kcos_az*asnd ; L = Y(3,1)
aOutArr[14] = i32*ksin_el*kcos_el_p2*kcos_2az*asnd ; N = Y(3,2)
aOutArr[15] = i31*kcos_el_p3*kcos_3az*asnd ; P = Y(3,3)
if iorder < 4 goto end
ic41 = (1/8)*sqrt(35)
ic42 = (1/2)*sqrt(35/2)
ic43 = sqrt(5)/4
ic44 = sqrt(5/2)/4
kcos_el_p4 = kcos_el*kcos_el_p3
ksin_el_p4 = ksin_el*ksin_el_p3
kcos_4az = cos(4*kaz)
ksin_4az = sin(4*kaz)
kcos_4el = cos(4*kel)
ksin_4el = sin(4*kel)
aOutArr[16] = ic41*kcos_el_p4*ksin_4az*asnd ; Y(4,-4)
aOutArr[17] = ic42*ksin_el*kcos_el_p3*ksin_3az*asnd ; Y(4,-3)
aOutArr[18] = ic43*(7.*ksin_el_p2 - 1.)*kcos_el_p2*ksin_2az*asnd ; Y(4,-2)
aOutArr[19] = ic44*ksin_2el*(7.*ksin_el_p2 - 3.)*ksin_az*asnd ; Y(4,-1)
aOutArr[20] = (1/8)*(35.*ksin_el_p4 - 30.*ksin_el_p2 + 3.)*asnd ; Y(4,0)
aOutArr[21] = ic44*ksin_2el*(7.*ksin_el_p2 - 3.)*kcos_az*asnd ; Y(4,1)
aOutArr[22] = ic43*(7.*ksin_el_p2 - 1.)*kcos_el_p2*kcos_2az*asnd ; Y(4,2)
aOutArr[23] = ic42*ksin_el*kcos_el_p3*kcos_3az*asnd ; Y(4,3)
aOutArr[24] = ic41*kcos_el_p4*kcos_4az*asnd ; Y(4,4)
if iorder < 5 goto end
ic51 = (3/8)*sqrt(7/2)
ic52 = (3/8)*sqrt(35)
ic53 = (1/8)*sqrt(35/2)
ic54 = sqrt(105)/4
ic55 = sqrt(15)/8
kcos_el_p5 = kcos_el*kcos_el_p4
ksin_el_p5 = ksin_el*ksin_el_p4
kcos_5az = cos(5*kaz)
ksin_5az = sin(5*kaz)
kcos_5el = cos(5*kel)
ksin_5el = sin(5*kel)
aOutArr[25] = ic51*kcos_el_p5*ksin_5az*asnd ; Y(5,-5)
aOutArr[26] = ic52*ksin_el*kcos_el_p4*ksin_4az*asnd ; Y(5,-4)
aOutArr[27] = ic53*(9*ksin_el_p2 - 1)*kcos_el_p3*ksin_3az*asnd ; Y(5,-3)
aOutArr[28] = ic54*ksin_el*(3*ksin_el_p2 - 1)*kcos_el_p2*ksin_2az*asnd ; Y(5,-2)
aOutArr[29] = ic55*(21*ksin_el_p4 - 14*ksin_el_p3 + 1)*kcos_el*ksin_az*asnd ; Y(5,-1)
aOutArr[30] = (1/8)*(63*ksin_el_p5 - 70*ksin_el_p3 + 15*ksin_el)*asnd ; Y(5,0)
aOutArr[31] = ic55*(21*ksin_el_p4 - 14*ksin_el_p3 + 1)*kcos_el*kcos_az*asnd ; Y(5,1)
aOutArr[32] = ic54*ksin_el*(3*ksin_el_p2 - 1)*kcos_el_p2*kcos_2az*asnd ; Y(5,2)
aOutArr[33] = ic53*(9*ksin_el_p2 - 1)*kcos_el_p3*kcos_3az*asnd ; Y(5,3)
aOutArr[34] = ic52*ksin_el*kcos_el_p4*kcos_4az*asnd ; Y(5,4)
aOutArr[35] = ic51*kcos_el_p5*kcos_5az*asnd ; Y(5,5)
if iorder < 6 goto end
ic61 = (1/16)*sqrt(231/2)
ic62 = (3/8)*sqrt(77/2)
ic63 = (3/16)*sqrt(7)
ic64 = (1/8)*sqrt(105/2)
ic65 = (1/16)*sqrt(105/2)
ic66 = (1/16)*sqrt(21)
kcos_el_p6 = kcos_el*kcos_el_p5
ksin_el_p6 = ksin_el*ksin_el_p5
kcos_6az = cos(6*kaz)
ksin_6az = sin(6*kaz)
kcos_6el = cos(6*kel)
ksin_6el = sin(6*kel)
aOutArr[36] = ic61*kcos_el_p6*ksin_6az*asnd
aOutArr[37] = ic62*ksin_el*kcos_el_p5*ksin_5az*asnd
aOutArr[38] = ic63*(11*ksin_el_p2 - 1)*kcos_el_p4*ksin_4az*asnd
aOutArr[39] = ic64*ksin_el*(11*ksin_el_p2 - 3)*kcos_el_p3*ksin_3az*asnd
aOutArr[40] = ic65*((33*ksin_el_p4) - 18*ksin_el_p2 + 1)*kcos_el_p2*ksin_2az*asnd
aOutArr[41] = ic66*ksin_2el*(33*ksin_el_p4 - 30*ksin_el_p2 + 5)*ksin_az*asnd
aOutArr[42] = (1/16)*(231*ksin_el_p6 - 315*ksin_el_p4 + 105*ksin_el_p2 - 5)*asnd
aOutArr[43] = ic66*ksin_2el*(33*ksin_el_p4 - 30*ksin_el_p2 + 5)*kcos_az*asnd
aOutArr[44] = ic65*((33*ksin_el_p4) - 18*ksin_el_p2 + 1)*kcos_el_p2*kcos_2az*asnd
aOutArr[45] = ic64*ksin_el*(11*ksin_el_p2 - 3)*kcos_el_p3*kcos_3az*asnd
aOutArr[46] = ic63*(11*ksin_el_p2 - 1)*kcos_el_p4*kcos_4az*asnd
aOutArr[47] = ic62*ksin_el*kcos_el_p5*kcos_5az*asnd
aOutArr[48] = ic61*kcos_el_p6*kcos_6az*asnd
if iorder < 7 goto end
ic71 = (3/32)*sqrt(143/3)
ic72 = (3/16)*sqrt(101/3)
ic73 = (3/32)*sqrt(77/3)
ic74 = (3/16)*sqrt(77/3)
ic75 = (3/32)*sqrt(7/3)
ic76 = (3/16)*sqrt(7/6)
ic77 = (1/32)*sqrt(7)
kcos_el_p7 = kcos_el*kcos_el_p6
ksin_el_p7 = ksin_el*ksin_el_p6
kcos_7az = cos(7*kaz)
ksin_7az = sin(7*kaz)
kcos_7el = cos(7*kel)
ksin_7el = sin(7*kel)
aOutArr[49] = ic71*kcos_el_p7*ksin_7az*asnd
aOutArr[50] = ic72*ksin_el*kcos_el_p6*ksin_6az*asnd
aOutArr[51] = ic73*(13*ksin_el_p2 - 1)*kcos_el_p5*ksin_5az*asnd
aOutArr[52] = ic74*(13*ksin_el_p3 - 3*ksin_el)*kcos_el_p4*ksin_4az*asnd
aOutArr[53] = ic75*(143*ksin_el_p4 - 66*ksin_el_p2 + 3)*kcos_el_p3*ksin_3az*asnd
aOutArr[54] = ic76*(143*ksin_el_p5 - 110*ksin_el_p3 + 15*ksin_el)*kcos_el_p2*ksin_2az*asnd
aOutArr[55] = ic77*(429*ksin_el_p6 - 495*ksin_el_p4 + 135*ksin_el_p2 - 5)*kcos_el*ksin_az*asnd
aOutArr[56] = (1/16)*(429*ksin_el_p7 - 693*ksin_el_p5 + 315*ksin_el_p3 - 35*ksin_el)*asnd
aOutArr[57] = ic77*(429*ksin_el_p6 - 495*ksin_el_p4 + 135*ksin_el_p2 - 5)*kcos_el*kcos_az*asnd
aOutArr[58] = ic76*(143*ksin_el_p5 - 110*ksin_el_p3 + 15*ksin_el)*kcos_el_p2*kcos_2az*asnd
aOutArr[59] = ic75*(143*ksin_el_p4 - 66*ksin_el_p2 + 3)*kcos_el_p3*kcos_3az*asnd
aOutArr[60] = ic74*(13*ksin_el_p3 - 3*ksin_el)*kcos_el_p4*kcos_4az*asnd
aOutArr[61] = ic73*(13*ksin_el_p2 - 1)*kcos_el_p5*kcos_5az*asnd
aOutArr[62] = ic72*ksin_el*kcos_el_p6*kcos_6az*asnd
aOutArr[63] = ic71*kcos_el_p7*kcos_7az*asnd
if iorder < 8 goto end
ic81 = (3/128)*sqrt(715)
ic82 = (3/32)*sqrt(715)
ic83 = (1/32)*sqrt(429/2)
ic84 = (3/32)*sqrt(1001)
ic85 = (3/64)*sqrt(77)
ic86 = (1/32)*sqrt(1155)
ic87 = (3/32)*sqrt(35/2)
ic88 = (3/32)
kcos_el_p8 = kcos_el*kcos_el_p7
ksin_el_p8 = ksin_el*ksin_el_p7
kcos_8az = cos(8*kaz)
ksin_8az = sin(8*kaz)
kcos_8el = cos(8*kel)
ksin_8el = sin(8*kel)
aOutArr[64] = ic81*kcos_el_p8*ksin_8az*asnd
aOutArr[65] = ic82*ksin_el*kcos_el_p7*ksin_7az*asnd
aOutArr[66] = ic83*(15*ksin_el_p2 - 1)*kcos_el_p6*ksin_6az*asnd
aOutArr[67] = ic84*(5*ksin_el_p3 - ksin_el)*kcos_el_p5*ksin_5az*asnd
aOutArr[68] = ic85*(65*ksin_el_p4 - 26*ksin_el_p2 + 1)*kcos_el_p4*ksin_4az*asnd
aOutArr[69] = ic86*(39*ksin_el_p5 - 26*ksin_el_p3 + 3*ksin_el)*kcos_el_p3*ksin_3az*asnd
aOutArr[70] = ic87*(143*ksin_el_p6 - 143*ksin_el_p4 + 33*ksin_el_p2 - 1)*kcos_el_p2*ksin_2az*asnd
aOutArr[71] = ic88*(715*ksin_el_p7 - 1001*ksin_el_p5 + 385*ksin_el_p3 - 35*ksin_el)*kcos_el*ksin_az*asnd
aOutArr[72] = (1/128)*(6435*ksin_el_p8 - 12012*ksin_el_p6 + 6930*ksin_el_p4 - 1260*ksin_el_p2 + 35)*asnd
aOutArr[73] = ic88*(715*ksin_el_p7 - 1001*ksin_el_p5 + 385*ksin_el_p3 - 35*ksin_el)*kcos_el*kcos_az*asnd
aOutArr[74] = ic87*(143*ksin_el_p6 - 143*ksin_el_p4 + 33*ksin_el_p2 - 1)*kcos_el_p2*kcos_2az*asnd
aOutArr[75] = ic86*(39*ksin_el_p5 - 26*ksin_el_p3 + 3*ksin_el)*kcos_el_p3*kcos_3az*asnd
aOutArr[76] = ic85*(65*ksin_el_p4 - 26*ksin_el_p2 + 1)*kcos_el_p4*kcos_4az*asnd
aOutArr[77] = ic84*(5*ksin_el_p3 - ksin_el)*kcos_el_p5*kcos_5az*asnd
aOutArr[78] = ic83*(15*ksin_el_p2 - 1)*kcos_el_p6*kcos_6az*asnd
aOutArr[79] = ic82*ksin_el*kcos_el_p7*kcos_7az*asnd
aOutArr[80] = ic81*kcos_el_p8*kcos_8az*asnd
end:
xout aOutArr
; original by Martin Neukom
; edit by Philipp Neumann
endop
/* synthesizer */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sine
;;; - creates sine wave and uses the sine function instead of a
;;; wavetable
;;; - kAmp -> output amplitude
;;; - kFreq -> base freq
opcode sine,a,kk
kAmp,kFreq xin
aSine = sin(phasor:a(kFreq)*2*$M_PI)
aSine *= kAmp
xout aSine
;; by philipp von neumann
endop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sine_beatings
;;; - creates sine tones with rhythmic beatings; uses sine function
;;; instead of a wavetable
;;; - kAmp -> output amplitude
;;; - kFreq -> base freq
;;; - kBeatings -> number of beatings per second
opcode sine_beatings,a,kkk
;; sine synthesizer for creating beatings
;; kBeatings = number of beatings per second
;; sine waves are made with sine functions and not with wavetable
kAmp,kFreq,kBeatings xin
kFreq1 = kFreq+(kBeatings/2)
kFreq2 = kFreq-(kBeatings/2)
aSin1 = sin(phasor:a(kFreq1)*2*$M_PI)
aSin2 = sin(phasor:a(kFreq2)*2*$M_PI)
aSin1 *= 0.5
aSin2 *= 0.5
aSin sum aSin1,aSin2
aSin *= kAmp
xout aSin
;; by philipp von neumann
endop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sine_oct
;;; - similiar to 'hsboscil' opcode but with sine-wave function instead
;;; of wavetable synthesis
;;; - generates a spectrum of sine waves in the distance of octaves;
;;; this spectrum is then windowed by a bandpass filter; the size of
;;; the bandpass filter is defined by kSize
;;; - kFreq -> BaseFreq
;;; - kCenter -> which partial is in center of the BP (0 = basefreq; 1 =
;;; first octave, and so on)
;;; - kSize -> how big is the window in semitones up and down the
;;; octave (1 = 1 semitone down and up -> 2 semitones)
opcode sine_oct,a,kkk
kFreq,kCenter,kSize xin
;; sine signals
aSig0 = sin(phasor:a(kFreq)*2*$M_PI)
aSig1 = sin(phasor:a(kFreq*2)*2*$M_PI)
aSig2 = sin(phasor:a(kFreq*4)*2*$M_PI)
aSig3 = sin(phasor:a(kFreq*8)*2*$M_PI)
aSig4 = sin(phasor:a(kFreq*16)*2*$M_PI)
aSig5 = sin(phasor:a(kFreq*32)*2*$M_PI)
aSig6 = sin(phasor:a(kFreq*64)*2*$M_PI)
aSig7 = sin(phasor:a(kFreq*128)*2*$M_PI)
aSig8 = sin(phasor:a(kFreq*256)*2*$M_PI)
aSig9 = sin(phasor:a(kFreq*512)*2*$M_PI)
aSig10 = sin(phasor:a(kFreq*1024)*2*$M_PI)
aSig sum \
aSig0/11,aSig1/11,aSig2/11,aSig3/11,aSig4/11,aSig5/11,aSig6/11,aSig7/11,aSig8/11,aSig9/11,aSig10/11
;; bp filtering
iFactor ftgen 0,0,0,-2,1,2,4,8,16,32,64,128,256,512,1024
kPartial tablei kCenter,iFactor
kCF = kPartial*kFreq
kLP = kCF*2^(kSize/12)
kHP = kCF*2^(-kSize/12)
aLP butterlp aSig,limit:k(kLP,10,19999)
aSine butterhp aLP,limit:k(kHP,10,19999)
aSine balance aSine,aSig
xout aSine
endop
;; by philipp von neumann
/* instruments */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sndfl_looper
;;; - loop segments from a soundfile with playback speed control
;;; (which alters the pitch), control of the loop start point, the
;;; size of the loop segment, a offset between two playheads to create
;;; a stereo effect and a predefined windowing function table
;;; - SFile -> path to soundfile
;;; - kSpeed -> factor for playback speed -> 1 = original speed, 2 =
;;; double speed, 0.5 = half speed, -1 = original speed but backwards
;;; - kLoopStart -> position of the loop playback (between 0 and 1)
;;; while 0 start of the file and 1 = end of the file
;;; - kLoopSize -> size of the loop segment as a factor (usually a value between
;;; 0.0001 and 1; 1 = the whole sound (factor*length of the soundfile)
;;; - kStereoOffset -> creates a offset between two playheads; a value
;;; between 0 and 1; when this value is changed, the instrument is
;;; reninitalisated, so be carefull with changing this parameter
;;; during playback, could resolve in clicks
/* sndfl looping */
opcode sndfl_looper, aa, Skkkki
SFile,kSpeed,kLoopStart,kLoopSize,kStereoOffset,iWndwFt xin
setksmps 1
;; read data from soundfil
iSndflSec filelen SFile
iSndflSr filesr SFile
iSndflSamps = iSndflSec*iSndflSr
;; create the tables for the soundfile
iSndflNumChnls filenchnls SFile
if iSndflNumChnls == 1 then
iSndflTbl1 ftgen 0,0,0,1,SFile,0,0,1
iSndflTbl2 = iSndflTbl1
elseif iSndflNumChnls == 2 then
iSndflTbl1 ftgen 0,0,0,1,SFile,0,0,1
iSndflTbl2 ftgen 0,0,0,1,SFile,0,0,2
endif
;; parameter for the table reading
kChange changed kStereoOffset
if kChange == 1 then
reinit UPDATE
endif
kSpeed = kSpeed
kStart = (kLoopStart*iSndflSamps)
kSize = kLoopSize*iSndflSamps
kPhasorSpeed = kSpeed/(kSize/iSndflSr)
aSyncIn init 0
aSyncOut1 init 1
aSyncOut2 init 1
kPhasorSpeed1 = (k(aSyncOut1) == 1 ? kPhasorSpeed : kPhasorSpeed1)
kPhasorSpeed2 = (k(aSyncOut2) == 1 ? kPhasorSpeed : kPhasorSpeed2)
UPDATE:
aIndex1,aSyncOut1 syncphasor kPhasorSpeed1,aSyncIn
aIndex2,aSyncOut2 syncphasor kPhasorSpeed2,aSyncIn,i(kStereoOffset)
kSize1 = (k(aSyncOut1) == 1 ? kSize : kSize1)
kSize2 = (k(aSyncOut2) == 1 ? kSize : kSize2)
kStart1 = (k(aSyncOut1) == 1 ? kStart : kStart1)
kStart2 = (k(aSyncOut2) == 1 ? kStart : kStart2)
aSndfl1 table3 (aIndex1*kSize1)+kStart1,iSndflTbl1,0,0,1
aSndfl2 table3 (aIndex2*kSize2)+kStart2,iSndflTbl2,0,0,1
aWin1 table3 aIndex1,iWndwFt,1
aWin2 table3 aIndex2,iWndwFt,1
;; output
aSndfl1 *= aWin1
aSndfl2 *= aWin2
xout aSndfl1,aSndfl2
;; by philipp von neumann
endop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sndfl_looper2
;;; - loop segments from a soundfile with playback speed control
;;; (which alters the pitch), control of the loop start point, the
;;; size of the loop segment, a offset between two playheads to create
;;; a stereo effect and a predefined windowing function table
;;; - sndfl_looper2 allows for individual segment masking to create
;;; rhythmic effects
;;; - SFile -> path to soundfile
;;; - kSpeed -> factor for playback speed -> 1 = original speed, 2 =
;;; double speed, 0.5 = half speed, -1 = original speed but backwards
;;; - kLoopStart -> position of the loop playback (between 0 and 1)
;;; while 0 start of the file and 1 = end of the file
;;; - kLoopSize -> size of the loop segment as a factor (usually a value between
;;; 0.0001 and 1; 1 = the whole sound (factor*length of the soundfile)
;;; - kStereoOffset -> creates a offset between two playheads; a value
;;; between 0 and 1; when this value is changed, the instrument is
;;; reninitalisated, so be carefull with changing this parameter
;;; during playback, could resolve in clicks
;;; - kMaskArr -> masking of the individual events; the array is
;;; deinterleaved into two arrays inside the UDO, one for each
;;; playbackhead; so take into account that when kStereoOffset is 0
;;; then you need to thinkg in value pairs for the masking, else you
;;; don't hear the masking how it is planned
/* sndfl looping with masking */
opcode sndfl_looper2, aa, Skkkkik[]
SFile,kSpeed,kLoopStart,kLoopSize,kStereoOffset,iWndwFt,kMaskArr[] xin
setksmps 1
;; read data from soundfil
iSndflSec filelen SFile
iSndflSr filesr SFile
iSndflSamps = iSndflSec*iSndflSr
;; create the tables for the soundfile
iSndflNumChnls filenchnls SFile
if iSndflNumChnls == 1 then
iSndflTbl1 ftgen 0,0,0,1,SFile,0,0,1
iSndflTbl2 = iSndflTbl1
elseif iSndflNumChnls == 2 then
iSndflTbl1 ftgen 0,0,0,1,SFile,0,0,1
iSndflTbl2 ftgen 0,0,0,1,SFile,0,0,2
endif
;; parameter for the table reading
kChange changed kStereoOffset
if kChange == 1 then
reinit UPDATE
endif
kSpeed = kSpeed
kStart = (kLoopStart*iSndflSamps)
kSize = kLoopSize*iSndflSamps
kPhasorSpeed = kSpeed/(kSize/iSndflSr)
aSyncIn init 0
aSyncOut1 init 1
aSyncOut2 init 1
kPhasorSpeed1 = (k(aSyncOut1) == 1 ? kPhasorSpeed : kPhasorSpeed1)
kPhasorSpeed2 = (k(aSyncOut2) == 1 ? kPhasorSpeed : kPhasorSpeed2)
UPDATE:
aIndex1,aSyncOut1 syncphasor kPhasorSpeed1,aSyncIn
aIndex2,aSyncOut2 syncphasor kPhasorSpeed2,aSyncIn,i(kStereoOffset)
kSize1 = (k(aSyncOut1) == 1 ? kSize : kSize1)
kSize2 = (k(aSyncOut2) == 1 ? kSize : kSize2)
kStart1 = (k(aSyncOut1) == 1 ? kStart : kStart1)
kStart2 = (k(aSyncOut2) == 1 ? kStart : kStart2)
aSndfl1 table3 (aIndex1*kSize1)+kStart1,iSndflTbl1,0,0,1
aSndfl2 table3 (aIndex2*kSize2)+kStart2,iSndflTbl2,0,0,1
aWin1 table3 aIndex1,iWndwFt,1
aWin2 table3 aIndex2,iWndwFt,1
aSig1 = aWin1*aSndfl1
aSig2 = aWin2*aSndfl2
;; masking
kMaskArr1[],kMaskArr2[] deinterleave kMaskArr
kMaskCount1 init 0
kMaskCount2 init 0
kMaskCount1 = (k(aSyncOut1) == 1 ? kMaskCount1+1 : kMaskCount1)
kMaskCount1 = kMaskCount1 % lenarray:i(kMaskArr1)
kMaskCount2 = (k(aSyncOut2) == 1 ? kMaskCount2+1 : kMaskCount2)
kMaskCount2 = kMaskCount2 % lenarray:i(kMaskArr2)
aSig1 *= kMaskArr1[kMaskCount1]
aSig2 *= kMaskArr2[kMaskCount2]
;; output
xout aSig1,aSig2
;; by philipp von neumann
endop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sndfl_looper_ambi !needs the ambi_encode UDO!
;;; - loop segments from a soundfile with playback speed control
;;; (which alters the pitch), control of the loop start point, the
;;; size of the loop segment, a offset between two playheads to create
;;; a stereo effect and a predefined windowing function table
;;; - sndfl_looper_ambi puts out an encoded ambisonics audio array up
;;; to 8th order; every loop segment is having a fixed position
;;; defined by kAzi and kAlti
;;; - SInFile -> path to soundfile
;;; - kSpeed -> factor for playback speed -> 1 = original speed, 2 =
;;; double speed, 0.5 = half speed, -1 = original speed but backwards
;;; - kLoopStart -> position of the loop playback (between 0 and 1)
;;; while 0 start of the file and 1 = end of the file
;;; - kLoopSize -> size of the loop segment as a factor (usually a value between
;;; 0.0001 and 1; 1 = the whole sound (factor*length of the soundfile)
;;; - kStereoOffset -> creates a offset between two playheads; a value
;;; between 0 and 1; when this value is changed, the instrument is
;;; reninitalisated, so be carefull with changing this parameter
;;; during playback, could resolve in clicks
;;; - kAzi -> Azimuth value as degree value of a circle (0 - 360)
;;; - kAlti -> Altitude / elevation value as degree value of a circle (0 - 360)
;;; - kMask -> masking of the individual events; for example to create
;;; amplitude envelopes
;;; - iOrder -> order of the ambisonics encoding -> up to 8th order;
;;; defines the size of the output array
opcode sndfl_looper_ambi,a[],Skkkkikkki
;; inputs
SInFile,kSpeed,kLoopStart,kLoopSize,kStereoOffset,iWndwFt,kAzi,kAlti,kMask,iOrder xin
setksmps 1
iAmbiChn = (iOrder+1)^2
;; read data from soundfil
iSndflSec filelen SInFile
iSndflSr filesr SInFile
iSndflSamps = iSndflSec*iSndflSr
;; create the table for the soundfile
iSndflNumChnls filenchnls SInFile
if iSndflNumChnls == 1 then
iSndflTbl1 ftgen 0,0,0,1,SInFile,0,0,1
iSndflTbl2 = iSndflTbl1
elseif iSndflNumChnls == 2 then
iSndflTbl1 ftgen 0,0,0,1,SInFile,0,0,1
iSndflTbl2 ftgen 0,0,0,1,SInFile,0,0,2
endif
;; parameter for the table reading
kChange changed kStereoOffset
if kChange == 1 then
reinit UPDATE
endif
kSpeed = kSpeed
kStart = (kLoopStart*iSndflSamps)
kSize = kLoopSize*iSndflSamps
kPhasorSpeed = kSpeed/(kSize/iSndflSr)
aSyncIn init 0
aSyncOut1 init 1
aSyncOut2 init 1
kPhasorSpeed1 = (k(aSyncOut1) == 1 ? kPhasorSpeed : kPhasorSpeed1)
kPhasorSpeed2 = (k(aSyncOut2) == 1 ? kPhasorSpeed : kPhasorSpeed2)
UPDATE:
aIndex1,aSyncOut1 syncphasor kPhasorSpeed1,aSyncIn
aIndex2,aSyncOut2 syncphasor kPhasorSpeed2,aSyncIn,i(kStereoOffset)
kSize1 = (k(aSyncOut1) == 1 ? kSize : kSize1)
kSize2 = (k(aSyncOut2) == 1 ? kSize : kSize2)
kStart1 = (k(aSyncOut1) == 1 ? kStart : kStart1)
kStart2 = (k(aSyncOut2) == 1 ? kStart : kStart2)
aWin1 table aIndex1,iWndwFt,1
aWin2 table aIndex2,iWndwFt,1
kArrCount1 = (k(aSyncOut1) == 1 ? kArrCount1+1 : kArrCount1)
kArrCount1 = kArrCount1 % iAmbiChn
kArrCount2 = (k(aSyncOut2) == 1 ? kArrCount2+1 : kArrCount2)
kArrCount2 = kArrCount2 % iAmbiChn
aSig1 table3 (aIndex1*kSize1)+kStart1,iSndflTbl1,0,0,1
aSig2 table3 (aIndex2*kSize2)+kStart2,iSndflTbl2,0,0,1
aSig1 *= aWin1
aSig2 *= aWin2
;; masking
kMaskReal1 init i(kMask)
kMaskReal2 init i(kMask)
kMaskReal1 = (k(aSyncOut1) == 1 ? kMask : kMaskReal1)
kMaskReal2 = (k(aSyncOut2) == 1 ? kMask : kMaskReal2)
aSig1 *= kMaskReal1
aSig2 *= kMaskReal2
;; spatialization
aEncArr1[] init iAmbiChn
aEncArr2[] init iAmbiChn
kAziReal1 init i(kAzi)
kAziReal2 init i(kAzi)
kAltiReal1 init i(kAlti)
kAltiReal2 init i(kAlti)
kAziReal1 = (k(aSyncOut1) == 1 ? kAzi : kAziReal1)
kAziReal2 = (k(aSyncOut2) == 1 ? kAzi : kAziReal2)
kAltiReal1 = (k(aSyncOut1) == 1 ? kAlti : kAltiReal1)
kAltiReal2 = (k(aSyncOut2) == 1 ? kAlti : kAltiReal2)
aEncArr1 ambi_encode aSig1,iOrder,kAziReal1,kAltiReal1
aEncArr2 ambi_encode aSig2,iOrder,kAziReal2,kAltiReal2
;; sum arrays
aOutArr[] init iAmbiChn
trim aOutArr,iAmbiChn
aOutArr[0] sum aEncArr1[0]/2,aEncArr2[0]/2
aOutArr[1] sum aEncArr1[1]/2,aEncArr2[1]/2
aOutArr[2] sum aEncArr1[2]/2,aEncArr2[2]/2
aOutArr[3] sum aEncArr1[3]/2,aEncArr2[3]/2
if iOrder < 2 goto end
aOutArr[4] sum aEncArr1[4]/2,aEncArr2[4]/2
aOutArr[5] sum aEncArr1[5]/2,aEncArr2[5]/2
aOutArr[6] sum aEncArr1[6]/2,aEncArr2[6]/2
aOutArr[7] sum aEncArr1[7]/2,aEncArr2[7]/2
aOutArr[8] sum aEncArr1[8]/2,aEncArr2[8]/2
if iOrder < 3 goto end
aOutArr[9] sum aEncArr1[9]/2,aEncArr2[9]/2
aOutArr[10] sum aEncArr1[10]/2,aEncArr2[10]/2
aOutArr[11] sum aEncArr1[11]/2,aEncArr2[11]/2
aOutArr[12] sum aEncArr1[12]/2,aEncArr2[12]/2
aOutArr[13] sum aEncArr1[13]/2,aEncArr2[13]/2
aOutArr[14] sum aEncArr1[14]/2,aEncArr2[14]/2
aOutArr[15] sum aEncArr1[15]/2,aEncArr2[15]/2
if iOrder < 4 goto end
aOutArr[16] sum aEncArr1[16]/2,aEncArr2[16]/2
aOutArr[17] sum aEncArr1[17]/2,aEncArr2[17]/2
aOutArr[18] sum aEncArr1[18]/2,aEncArr2[18]/2
aOutArr[19] sum aEncArr1[19]/2,aEncArr2[19]/2
aOutArr[20] sum aEncArr1[20]/2,aEncArr2[20]/2
aOutArr[21] sum aEncArr1[21]/2,aEncArr2[21]/2
aOutArr[22] sum aEncArr1[22]/2,aEncArr2[22]/2
aOutArr[23] sum aEncArr1[23]/2,aEncArr2[23]/2
aOutArr[24] sum aEncArr1[24]/2,aEncArr2[24]/2
if iOrder < 5 goto end
aOutArr[25] sum aEncArr1[25]/2,aEncArr2[25]/2
aOutArr[26] sum aEncArr1[26]/2,aEncArr2[26]/2
aOutArr[27] sum aEncArr1[27]/2,aEncArr2[27]/2
aOutArr[28] sum aEncArr1[28]/2,aEncArr2[28]/2
aOutArr[29] sum aEncArr1[29]/2,aEncArr2[29]/2
aOutArr[30] sum aEncArr1[30]/2,aEncArr2[30]/2
aOutArr[31] sum aEncArr1[31]/2,aEncArr2[31]/2
aOutArr[32] sum aEncArr1[32]/2,aEncArr2[32]/2
aOutArr[33] sum aEncArr1[33]/2,aEncArr2[33]/2
aOutArr[34] sum aEncArr1[34]/2,aEncArr2[34]/2
aOutArr[35] sum aEncArr1[35]/2,aEncArr2[35]/2
if iOrder < 6 goto end
aOutArr[36] sum aEncArr1[36]/2,aEncArr2[36]/2
aOutArr[37] sum aEncArr1[37]/2,aEncArr2[37]/2
aOutArr[38] sum aEncArr1[38]/2,aEncArr2[38]/2
aOutArr[39] sum aEncArr1[39]/2,aEncArr2[39]/2
aOutArr[40] sum aEncArr1[40]/2,aEncArr2[40]/2
aOutArr[41] sum aEncArr1[41]/2,aEncArr2[41]/2
aOutArr[42] sum aEncArr1[42]/2,aEncArr2[42]/2
aOutArr[43] sum aEncArr1[43]/2,aEncArr2[43]/2
aOutArr[44] sum aEncArr1[44]/2,aEncArr2[44]/2
aOutArr[45] sum aEncArr1[45]/2,aEncArr2[45]/2
aOutArr[46] sum aEncArr1[46]/2,aEncArr2[46]/2
aOutArr[47] sum aEncArr1[47]/2,aEncArr2[47]/2
aOutArr[48] sum aEncArr1[48]/2,aEncArr2[48]/2
if iOrder < 7 goto end
aOutArr[49] sum aEncArr1[49]/2,aEncArr2[49]/2
aOutArr[50] sum aEncArr1[50]/2,aEncArr2[50]/2
aOutArr[51] sum aEncArr1[51]/2,aEncArr2[51]/2
aOutArr[52] sum aEncArr1[52]/2,aEncArr2[52]/2
aOutArr[53] sum aEncArr1[53]/2,aEncArr2[53]/2
aOutArr[54] sum aEncArr1[54]/2,aEncArr2[54]/2
aOutArr[55] sum aEncArr1[55]/2,aEncArr2[55]/2
aOutArr[56] sum aEncArr1[56]/2,aEncArr2[56]/2
aOutArr[57] sum aEncArr1[57]/2,aEncArr2[57]/2
aOutArr[58] sum aEncArr1[58]/2,aEncArr2[58]/2
aOutArr[59] sum aEncArr1[59]/2,aEncArr2[59]/2
aOutArr[60] sum aEncArr1[60]/2,aEncArr2[60]/2
aOutArr[61] sum aEncArr1[61]/2,aEncArr2[61]/2
aOutArr[62] sum aEncArr1[62]/2,aEncArr2[62]/2
aOutArr[63] sum aEncArr1[63]/2,aEncArr2[63]/2
if iOrder < 8 goto end
aOutArr[64] sum aEncArr1[64]/2,aEncArr2[64]/2
aOutArr[65] sum aEncArr1[65]/2,aEncArr2[65]/2
aOutArr[66] sum aEncArr1[66]/2,aEncArr2[66]/2
aOutArr[67] sum aEncArr1[67]/2,aEncArr2[67]/2
aOutArr[68] sum aEncArr1[68]/2,aEncArr2[68]/2
aOutArr[69] sum aEncArr1[69]/2,aEncArr2[69]/2
aOutArr[70] sum aEncArr1[70]/2,aEncArr2[70]/2
aOutArr[71] sum aEncArr1[71]/2,aEncArr2[71]/2
aOutArr[72] sum aEncArr1[72]/2,aEncArr2[72]/2
aOutArr[73] sum aEncArr1[73]/2,aEncArr2[73]/2
aOutArr[74] sum aEncArr1[74]/2,aEncArr2[74]/2
aOutArr[75] sum aEncArr1[75]/2,aEncArr2[75]/2
aOutArr[76] sum aEncArr1[76]/2,aEncArr2[76]/2
aOutArr[77] sum aEncArr1[77]/2,aEncArr2[77]/2
aOutArr[78] sum aEncArr1[78]/2,aEncArr2[78]/2
aOutArr[79] sum aEncArr1[79]/2,aEncArr2[79]/2
aOutArr[80] sum aEncArr1[80]/2,aEncArr2[80]/2
end:
;; output
xout aOutArr
;; by philipp von neumann
endop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sndfl_looper2_ambi !needs the ambi_encode UDO!
;;; - loop segments from a soundfile with playback speed control
;;; (which alters the pitch), control of the loop start point, the
;;; size of the loop segment, a offset between two playheads to create
;;; a stereo effect and a predefined windowing function table
;;; - sndfl_looper2_ambi puts out an encoded ambisonics audio array up
;;; to 8th order; every loop segment is having a fixed position
;;; defined by kAzi and kAlti
;;; - sndfl_looper2_ambi allows for individual segment masking to create
;;; rhythmic effects
;;; - SInFile -> path to soundfile
;;; - kSpeed -> factor for playback speed -> 1 = original speed, 2 =
;;; double speed, 0.5 = half speed, -1 = original speed but backwards
;;; - kLoopStart -> position of the loop playback (between 0 and 1)
;;; while 0 start of the file and 1 = end of the file
;;; - kLoopSize -> size of the loop segment as a factor (usually a value between
;;; 0.0001 and 1; 1 = the whole sound (factor*length of the soundfile)
;;; - kStereoOffset -> creates a offset between two playheads; a value
;;; between 0 and 1; when this value is changed, the instrument is
;;; reninitalisated, so be carefull with changing this parameter
;;; during playback, could resolve in clicks
;;; - kAzi -> Azimuth value as degree value of a circle (0 - 360)
;;; - kAlti -> Altitude / elevation value as degree value of a circle (0 - 360)
;;; - kMaskArr -> masking of the individual events; for example to create
;;; rhythmic patterns
;;; - iOrder -> order of the ambisonics encoding -> up to 8th order;
;;; defines the size of the output array
opcode sndfl_looper2_ambi,a[],Skkkkikkk[]i
;; inputs
SInFile,kSpeed,kLoopStart,kLoopSize,kStereoOffset,iWndwFt,kAzi,kAlti,kMaskArr[],iOrder xin
iAmbiChn = (iOrder+1)^2
;; read data from soundfil
iSndflSec filelen SInFile
iSndflSr filesr SInFile
iSndflSamps = iSndflSec*iSndflSr
;; create the table for the soundfile
iSndflNumChnls filenchnls SInFile
if iSndflNumChnls == 1 then
iSndflTbl1 ftgen 0,0,0,1,SInFile,0,0,1
iSndflTbl2 = iSndflTbl1
elseif iSndflNumChnls == 2 then
iSndflTbl1 ftgen 0,0,0,1,SInFile,0,0,1
iSndflTbl2 ftgen 0,0,0,1,SInFile,0,0,2
endif
;; parameter for the table reading
kChange changed kStereoOffset
if kChange == 1 then
reinit UPDATE
endif
kSpeed = kSpeed
kStart = (kLoopStart*iSndflSamps)
kSize = kLoopSize*iSndflSamps
kPhasorSpeed = kSpeed/(kSize/iSndflSr)
aSyncIn init 0
aSyncOut1 init 1
aSyncOut2 init 1
kPhasorSpeed1 = (k(aSyncOut1) == 1 ? kPhasorSpeed : kPhasorSpeed1)
kPhasorSpeed2 = (k(aSyncOut2) == 1 ? kPhasorSpeed : kPhasorSpeed2)
UPDATE:
aIndex1,aSyncOut1 syncphasor kPhasorSpeed1,aSyncIn
aIndex2,aSyncOut2 syncphasor kPhasorSpeed2,aSyncIn,i(kStereoOffset)
kSize1 = (k(aSyncOut1) == 1 ? kSize : kSize1)
kSize2 = (k(aSyncOut2) == 1 ? kSize : kSize2)
kStart1 = (k(aSyncOut1) == 1 ? kStart : kStart1)
kStart2 = (k(aSyncOut2) == 1 ? kStart : kStart2)
aWin1 table aIndex1,iWndwFt,1
aWin2 table aIndex2,iWndwFt,1
kArrCount1 = (k(aSyncOut1) == 1 ? kArrCount1+1 : kArrCount1)
kArrCount1 = kArrCount1 % iAmbiChn
kArrCount2 = (k(aSyncOut2) == 1 ? kArrCount2+1 : kArrCount2)
kArrCount2 = kArrCount2 % iAmbiChn
aSig1 table3 (aIndex1*kSize1)+kStart1,iSndflTbl1,0,0,1
aSig2 table3 (aIndex2*kSize2)+kStart2,iSndflTbl2,0,0,1
aSig1 *= aWin1
aSig2 *= aWin2
;; masking
kMaskArr1[],kMaskArr2[] deinterleave kMaskArr
kMaskCount1 init 0
kMaskCount2 init 0
kMaskCount1 = (k(aSyncOut1) == 1 ? kMaskCount1+1 : kMaskCount1)
kMaskCount1 = kMaskCount1 % lenarray:i(kMaskArr1)
kMaskCount2 = (k(aSyncOut2) == 1 ? kMaskCount2+1 : kMaskCount2)
kMaskCount2 = kMaskCount2 % lenarray:i(kMaskArr2)
aSig1 *= kMaskArr1[kMaskCount1]
aSig2 *= kMaskArr2[kMaskCount2]
;; spatialization
aEncArr1[] init iAmbiChn
aEncArr2[] init iAmbiChn
aEncArr1 ambi_encode aSig1,iOrder,kAzi,kAlti
aEncArr2 ambi_encode aSig2,iOrder,kAzi,kAlti
;; sum arrays
aOutArr[] init iAmbiChn
trim aOutArr,iAmbiChn
aOutArr[0] sum aEncArr1[0]/2,aEncArr2[0]/2
aOutArr[1] sum aEncArr1[1]/2,aEncArr2[1]/2
aOutArr[2] sum aEncArr1[2]/2,aEncArr2[2]/2
aOutArr[3] sum aEncArr1[3]/2,aEncArr2[3]/2
if iOrder < 2 goto end
aOutArr[4] sum aEncArr1[4]/2,aEncArr2[4]/2
aOutArr[5] sum aEncArr1[5]/2,aEncArr2[5]/2
aOutArr[6] sum aEncArr1[6]/2,aEncArr2[6]/2
aOutArr[7] sum aEncArr1[7]/2,aEncArr2[7]/2
aOutArr[8] sum aEncArr1[8]/2,aEncArr2[8]/2
if iOrder < 3 goto end
aOutArr[9] sum aEncArr1[9]/2,aEncArr2[9]/2
aOutArr[10] sum aEncArr1[10]/2,aEncArr2[10]/2
aOutArr[11] sum aEncArr1[11]/2,aEncArr2[11]/2
aOutArr[12] sum aEncArr1[12]/2,aEncArr2[12]/2
aOutArr[13] sum aEncArr1[13]/2,aEncArr2[13]/2
aOutArr[14] sum aEncArr1[14]/2,aEncArr2[14]/2
aOutArr[15] sum aEncArr1[15]/2,aEncArr2[15]/2
if iOrder < 4 goto end
aOutArr[16] sum aEncArr1[16]/2,aEncArr2[16]/2
aOutArr[17] sum aEncArr1[17]/2,aEncArr2[17]/2
aOutArr[18] sum aEncArr1[18]/2,aEncArr2[18]/2
aOutArr[19] sum aEncArr1[19]/2,aEncArr2[19]/2
aOutArr[20] sum aEncArr1[20]/2,aEncArr2[20]/2
aOutArr[21] sum aEncArr1[21]/2,aEncArr2[21]/2
aOutArr[22] sum aEncArr1[22]/2,aEncArr2[22]/2
aOutArr[23] sum aEncArr1[23]/2,aEncArr2[23]/2
aOutArr[24] sum aEncArr1[24]/2,aEncArr2[24]/2
if iOrder < 5 goto end
aOutArr[25] sum aEncArr1[25]/2,aEncArr2[25]/2
aOutArr[26] sum aEncArr1[26]/2,aEncArr2[26]/2
aOutArr[27] sum aEncArr1[27]/2,aEncArr2[27]/2
aOutArr[28] sum aEncArr1[28]/2,aEncArr2[28]/2
aOutArr[29] sum aEncArr1[29]/2,aEncArr2[29]/2
aOutArr[30] sum aEncArr1[30]/2,aEncArr2[30]/2
aOutArr[31] sum aEncArr1[31]/2,aEncArr2[31]/2
aOutArr[32] sum aEncArr1[32]/2,aEncArr2[32]/2
aOutArr[33] sum aEncArr1[33]/2,aEncArr2[33]/2
aOutArr[34] sum aEncArr1[34]/2,aEncArr2[34]/2
aOutArr[35] sum aEncArr1[35]/2,aEncArr2[35]/2
if iOrder < 6 goto end
aOutArr[36] sum aEncArr1[36]/2,aEncArr2[36]/2
aOutArr[37] sum aEncArr1[37]/2,aEncArr2[37]/2
aOutArr[38] sum aEncArr1[38]/2,aEncArr2[38]/2
aOutArr[39] sum aEncArr1[39]/2,aEncArr2[39]/2
aOutArr[40] sum aEncArr1[40]/2,aEncArr2[40]/2
aOutArr[41] sum aEncArr1[41]/2,aEncArr2[41]/2
aOutArr[42] sum aEncArr1[42]/2,aEncArr2[42]/2
aOutArr[43] sum aEncArr1[43]/2,aEncArr2[43]/2
aOutArr[44] sum aEncArr1[44]/2,aEncArr2[44]/2
aOutArr[45] sum aEncArr1[45]/2,aEncArr2[45]/2
aOutArr[46] sum aEncArr1[46]/2,aEncArr2[46]/2
aOutArr[47] sum aEncArr1[47]/2,aEncArr2[47]/2
aOutArr[48] sum aEncArr1[48]/2,aEncArr2[48]/2
if iOrder < 7 goto end
aOutArr[49] sum aEncArr1[49]/2,aEncArr2[49]/2
aOutArr[50] sum aEncArr1[50]/2,aEncArr2[50]/2
aOutArr[51] sum aEncArr1[51]/2,aEncArr2[51]/2
aOutArr[52] sum aEncArr1[52]/2,aEncArr2[52]/2
aOutArr[53] sum aEncArr1[53]/2,aEncArr2[53]/2
aOutArr[54] sum aEncArr1[54]/2,aEncArr2[54]/2
aOutArr[55] sum aEncArr1[55]/2,aEncArr2[55]/2
aOutArr[56] sum aEncArr1[56]/2,aEncArr2[56]/2
aOutArr[57] sum aEncArr1[57]/2,aEncArr2[57]/2
aOutArr[58] sum aEncArr1[58]/2,aEncArr2[58]/2
aOutArr[59] sum aEncArr1[59]/2,aEncArr2[59]/2
aOutArr[60] sum aEncArr1[60]/2,aEncArr2[60]/2
aOutArr[61] sum aEncArr1[61]/2,aEncArr2[61]/2
aOutArr[62] sum aEncArr1[62]/2,aEncArr2[62]/2
aOutArr[63] sum aEncArr1[63]/2,aEncArr2[63]/2
if iOrder < 8 goto end
aOutArr[64] sum aEncArr1[64]/2,aEncArr2[64]/2
aOutArr[65] sum aEncArr1[65]/2,aEncArr2[65]/2
aOutArr[66] sum aEncArr1[66]/2,aEncArr2[66]/2
aOutArr[67] sum aEncArr1[67]/2,aEncArr2[67]/2
aOutArr[68] sum aEncArr1[68]/2,aEncArr2[68]/2
aOutArr[69] sum aEncArr1[69]/2,aEncArr2[69]/2
aOutArr[70] sum aEncArr1[70]/2,aEncArr2[70]/2
aOutArr[71] sum aEncArr1[71]/2,aEncArr2[71]/2
aOutArr[72] sum aEncArr1[72]/2,aEncArr2[72]/2
aOutArr[73] sum aEncArr1[73]/2,aEncArr2[73]/2
aOutArr[74] sum aEncArr1[74]/2,aEncArr2[74]/2
aOutArr[75] sum aEncArr1[75]/2,aEncArr2[75]/2
aOutArr[76] sum aEncArr1[76]/2,aEncArr2[76]/2
aOutArr[77] sum aEncArr1[77]/2,aEncArr2[77]/2
aOutArr[78] sum aEncArr1[78]/2,aEncArr2[78]/2
aOutArr[79] sum aEncArr1[79]/2,aEncArr2[79]/2
aOutArr[80] sum aEncArr1[80]/2,aEncArr2[80]/2
end:
;; output
xout aOutArr
;; by philipp von neumann
endop
/* wavehspaing */
/*
This comment is taken from Michael Edwards contrast-enhancement object
for Max/MSP:
This algorithm is taken from CLM. Here's Bill Schottstaedt's comment
from there: "contrast-enhancement phase-modulates a sound file. It's
like audio MSG. The actual algorithm is sin(in-samp * pi/2 + (fm-index
* sin(in-samp * 2*pi))). The result is to brighten the sound, helping
it cut through a huge mix."
*/
opcode contrast_enhancement, a, ak
aIn, kAmount xin
aSig1 = aIn * ($M_PI / 2)
aSig2 = sin(aIn * ($M_PI * 2)) * kAmount
aOut = sin(aSig1 + aSig2)
aOut dcblock2 aOut
xout aOut
endop
/* filter */
/* modulation */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; bode_shifter collection
;;;
;;; single-sideband modulation which results in frequency shifts
;;; - named after harald bode (klangumwandler)
;;; - aSum represents the downshifted signal
;;; - aDiff represents the upshifted signel
opcode bode_shifter, aa, aki
/*
- iWaveTable can take any Wavetable, but classic wavetable would be
a sine
- kModFreq is freq shift in Hz
*/
aIn, kModFreq, iWaveTable xin
aSin, aCos hilbert aIn
aModSin poscil 1,kModFreq,iWaveTable,0.0
aModCos poscil 1,kModFreq,iWaveTable,0.25
aMod1 = aSin * aModCos
aMod2 = aCos * aModSin
aSum = (aMod1 + aMod2) * (1.0 / sqrt(2.0))
aDiff = (aMod1 - aMod2) * (1.0 / sqrt(2.0))
xout aSum, aDiff
endop
opcode bode_shifter, aa, akS
/*
- Sndfl can be any Sndfl which is supposed to work as a modulation
source
- kModFreq is the playback speed of the sndfl
*/
aIn, kModFreq, Sndfl xin
// mod source
iChns filenchnls Sndfl
if iChns == 1 then
iFt1 ftgen 0,0,0,1,Sndfl,0,0,0
iFt2 = iFt1
elseif iChns == 2 then
iFt1 ftgen 0,0,0,1,Sndfl,0,0,1
iFt2 ftgen 0,0,0,1,Sndfl,0,0,2
endif
iFlLen filelen Sndfl
// modulation
aSin, aCos hilbert aIn
aPhsSin phasor kModFreq / iFlLen, 0
aPhsCos phasor kModFreq / iFlLen, 0.25
aModSin table3 aPhsSin, iFt1, 1
aModCos table3 aPhsCos, iFt1, 1
aMod1 = aSin * aModCos
aMod2 = aCos * aModSin
aSum = (aMod1 + aMod2) * (1.0 / sqrt(2.0))
aDiff = (aMod1 - aMod2) * (1.0 / sqrt(2.0))