Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Resources/tamtamorc.csd
blob: f0a63f1ac92fc805adbedd380bc9bfedd2f708fa (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
<CsoundSynthesizer>
<CsOptions>
-n -m0 -W -s -d
</CsOptions>
<CsInstruments>
sr=16000
ksmps=64
nchnls=2
giScale = 1/sr
giAliasSr = sr/2.1

gainrev init 0
gaoutL init 0
gaoutR init 0
gasynth init 0
gkTrackpadX init 0
gkTrackpadY init 0
gSpath strcpy " "

/*****************************
matrix for TamTam's SynthLab
*****************************/
zakinit 8, 32

/*****************************
opcodes needed by TamTam's SynthLab
*****************************/

opcode homeSine, a, kki
kpitch, kspread, iTable xin

kspread = kspread + 1

kr1 randomi 0.99, 1.01, 3.45
kr2 randomi 0.9901, 1.0101, 4.43
kr3 randomi 0.9899, 1.0091, 5.25
kr4 randomi 0.9889, 1.00921, 6.15

kpit1 = kpitch
kpit2 = kpit1*kspread
kpit3 = kpit2*kspread
kpit4 = kpit3*kspread
kpit5 = kpit4*kspread
kpit6 = kpit5*kspread
kpit7 = kpit6*kspread
kpit8 = kpit7*kspread

a1 oscil 1000, kpit1*kr1, iTable
a2 oscil 1000, kpit2*kr2, iTable
a3 oscil 1000, kpit3*kr3, iTable
a4 oscil 1000, kpit4*kr4, iTable
a5 oscil 1000, kpit5*kr1, iTable
a6 oscil 1000, kpit6*kr2, iTable
a7 oscil 1000, kpit7*kr3, iTable
a8 oscil 1000, kpit8*kr4, iTable

aout = a1+a2+a3+a4+a5+a6+a7+a8
xout aout
endop

opcode synthGrain, a, aaiiii
aindex, atrans, ifreq, iphase itable, itabdur xin
apha phasor ifreq, iphase
aenv tab apha, 42, 1
atrig = int(1-aenv)
apos samphold aindex, atrig
adur samphold atrans, atrig

aline = apha * adur * sr + apos
aline limit aline, 0 , itabdur
ag tablei aline, itable, 0
aout = ag * aenv

xout aout
endop


opcode  ControlMatrice, i, iikkkk
iTable, iIndex, kc1, kc2, kc3, kc4  xin

iSomme table iIndex, iTable+3

if iSomme == 0 then
goto noparams
endif

iPar table iIndex, iTable

if iSomme == 1 then
kp = iPar
elseif iSomme == 3 then
kp = iPar * kc1
elseif iSomme == 5 then
kp = iPar * kc2
elseif iSomme == 7 then
kp = iPar * ((kc1 + kc2)*.5)
elseif iSomme == 9 then
kp = iPar * kc3
elseif iSomme == 11 then
kp = iPar * ((kc1 + kc3)*.5)
elseif iSomme == 13 then
kp = iPar * ((kc2 + kc3)*.5)
elseif iSomme == 15 then
kp = iPar * ((kc1 + kc2 + kc3)*.33)
elseif iSomme == 17 then
kp = iPar * kc4
elseif iSomme == 19 then
kp = iPar * ((kc1 + kc4)*.5)
elseif iSomme == 21 then
kp = iPar * ((kc2 + kc4)*.5)
elseif iSomme == 23 then
kp = iPar * ((kc1 + kc2 + kc4)*.33)
elseif iSomme == 25 then
kp = iPar * ((kc3 + kc4)*.5)
elseif iSomme == 27 then
kp = iPar * ((kc1 + kc3 + kc4)*.5)
elseif iSomme == 29 then
kp = iPar * ((kc2 + kc3 + kc4)*.33)
elseif iSomme == 31 then
kp = iPar * ((kc1 + kc2 + kc3 + kc4)*.25)
endif

if iTable == 5201 then
zkw     kp, iIndex+1
elseif iTable == 5202 then
zkw     kp, iIndex+17
endif

xout    iIndex

noparams:
endop

opcode  SourceMatrice, i, iaaaa
iIndex, as1, as2, as3, as4  xin

iSomme table iIndex-1, 5206

if iSomme == 0 then
goto noparams
endif

if iSomme == 1 then
as = as1
elseif iSomme == 2 then
as = as2
elseif iSomme == 3 then
as = as1 + as2
elseif iSomme == 4 then
as = as3
elseif iSomme == 5 then
as = as1 + as3
elseif iSomme == 6 then
as = as2 + as3
elseif iSomme == 7 then
as = as1 + as2 + as3
elseif iSomme == 8 then
as = as4
elseif iSomme == 9 then
as = as1 + as4
elseif iSomme == 10 then
as = as2 + as4
elseif iSomme == 11 then
as = as1 + as2 + as4
elseif iSomme == 12 then
as = as3 + as4
elseif iSomme == 13 then
as = as1 + as3 + as4
elseif iSomme == 14 then
as = as2 + as3 + as4
elseif iSomme == 15 then
as = as1 + as2 + as3 + as4
endif

zaw     as, iIndex
xout    iIndex

noparams:
endop

opcode  FxMatrice, i, iaaaa
iIndex, as1, as2, as3, as4  xin

iSomme table iIndex-1, 5206

if iSomme == 0 then
goto noparams
endif

if iSomme == 1 then
as = as1
elseif iSomme == 2 then
as = as2
elseif iSomme == 3 then
as = as1 + as2
elseif iSomme == 4 then
as = as3
elseif iSomme == 5 then
as = as1 + as3
elseif iSomme == 6 then
as = as2 + as3
elseif iSomme == 7 then
as = as1 + as2 + as3
elseif iSomme == 8 then
as = as4
elseif iSomme == 9 then
as = as1 + as4
elseif iSomme == 10 then
as = as2 + as4
elseif iSomme == 11 then
as = as1 + as2 + as4
elseif iSomme == 12 then
as = as3 + as4
elseif iSomme == 13 then
as = as1 + as3 + as4
elseif iSomme == 14 then
as = as2 + as3 + as4
endif

zaw     as, iIndex
xout    iIndex

noparams:
endop

opcode  controller, k, ii
iControlNum, idur   xin

iControlType table  iControlNum-1, 5203

if iControlType == 0 then
goto nocontrol
endif

ioffset = (iControlNum-1)*4
iPar1   table   ioffset, 5200
iPar2   table   ioffset+1, 5200
iPar3   table   ioffset+2, 5200
iPar4   table   ioffset+3, 5200

if iControlType == 1 then
    kControl    lfo     iPar1, iPar2, int(iPar3)
    kControl    =       kControl+iPar4
elseif iControlType == 2 then
    irange      =       (iPar2-iPar1)*.5
    kControl    randi   irange, iPar3, iPar4-.001, 0, irange+iPar1
elseif iControlType == 3 then
    kControl    adsr    iPar1*idur+.0001, iPar2*idur, iPar3, iPar4*idur
elseif iControlType == 4 then
    if iPar3 == 0 then
        kControl1 = ((gkTrackpadX+1)*.5)*(iPar2-iPar1)+iPar1
    elseif iPar3 == 1 then
        kval = (gkTrackpadX+1)*.5
        kControl1 pow kval, 2
        kControl1 = kControl1 * (iPar2-iPar1) + iPar1
    endif
    if iPar4 == 0 then
        kControl = kControl1
    else
        ktrig oscil 1, 1/iPar4, 45
        kControl samphold kControl1, ktrig, i(kControl1), 0
        endif
elseif iControlType == 5 then
    if iPar3 == 0 then
        kControl1 = ((gkTrackpadY+1)*.5)*(iPar2-iPar1)+iPar1
    elseif iPar3 == 1 then
        kval = (gkTrackpadY+1)*.5
        kControl1 pow kval, 2
        kControl1 = kControl1 * (iPar2-iPar1) + iPar1
    endif
    if iPar4 == 0 then
        kControl = kControl1
    else
        ktrig oscil 1, 1/iPar4, 45
        kControl samphold kControl1, ktrig, i(kControl1), 0
        endif
endif

xout    kControl

nocontrol:
endop

opcode  source, a, ii
iSourceNum, ipitch     xin

iSourceType table iSourceNum+3, 5203

if iSourceType == 0 then
goto nosource
endif

ioffset =   (iSourceNum-1)*4
kpara1  zkr ioffset+1
kpara2  zkr ioffset+2
kpara3  zkr ioffset+3
kpara4  zkr ioffset+4

iPar1   table   ioffset, 5201
iPar2   table   ioffset+1, 5201
iPar3   table   ioffset+2, 5201
iPar4   table   ioffset+3, 5201

if iSourceType == 1 then
    aSource	foscil	2000*kpara4, ipitch, kpara1, kpara2, kpara3, 1
elseif iSourceType == 2 then
    aSource	gbuzz	5000*kpara4, ipitch*kpara1, int(abs(kpara2))+5, 0, kpara3+0.01, 2
elseif iSourceType == 3 then
    iPar2 = int(iPar2)
    if iPar2 == 0 then
        imode = 0
    elseif iPar2 == 1 then
        imode = 10
    elseif iPar2 == 2 then
        imode = 12
    endif
    aSource vco2    2000*kpara4, ipitch*kpara1, imode, 0.1, 0, iPar3
elseif iSourceType == 4 then
    if iPar3 == 0 then
        kvib = 0
        goto novib
    else
        kvibenv    linseg  0, .3, 1, p3-.3, 1
        kvib    oscil	ipitch*.015, kpara3, 1
    endif
    novib:
    aSource pluck   5000*kpara4, ipitch*(abs(kpara1))+.001+kvib, 40, 0, 6
    aSource butterlp    aSource, kpara2
elseif iSourceType == 5 then
    if int(iPar1) == 0 then
        ar rand   5000*kpara4
    elseif int(iPar1) == 1 then
        ar pinkish 5000*kpara4
    elseif int(iPar1) == 2 then
        ar gauss   5000*kpara4
    endif
    knoisebandwith limit abs(kpara3), 1, sr/2
    aSource butterbp ar, kpara2, knoisebandwith
    aSource balance aSource, ar
elseif iSourceType == 6 then
    iSndpitch = p4/261.626
    iLoopIndex = iPar2 * 3
    ils table iLoopIndex, 5755
    ile table iLoopIndex+1, 5755
    icd table iLoopIndex+2, 5755
    if ile == 0 then
        ile = nsamp(5000+iPar2) * giScale - .01
    endif
    if icd == 0 then
        icd = .01
    endif
    aSource	     flooper2	kpara4*.4, iSndpitch*abs(kpara1), ils, ile, icd, 5000+iPar2
    aSource butterlp aSource, abs(kpara3)
elseif iSourceType == 7 then
    kvoy    =  int(kpara2*3)
    kform1  table   kvoy, 4
    kform2  table   kvoy+1, 4
    kform3  table   kvoy+2, 4
    kform1  port    kform1, .1, 500
    kform2  port    kform2, .1, 1500
    kform3  port    kform3, .1, 2500
    kvibadev	randomi	-.0852, .0152, .5
    kvibfdev	randomi	-.032, .032, .5
    kvibfreqrand	randomi	kpara3-.75, kpara3+.75, .2
    kvibfatt    linseg  0, .3, 1, p3-.3, 1
    kvib		oscili	(1+kvibadev)*kvibfatt, (kvibfreqrand+kvibfdev), 1
    kharm		randomi	40, 50, 1.34
    kmul		randomi	.80, .84, 1.45
    kbam		randomi	480., 510., 2.07
    kfunddev	randomi	-.0053, .0052, 1.05
    ar  		gbuzz  	kbam, (p4*kpara1*(1+kfunddev)+kvib), int(kharm), 0, kmul, 2
    a1 			resonx 	ar, kform1, 140, 2, 1
    a2 			resonx 	ar, kform2, 180, 2, 1
    a3 			resonx 	ar, kform3, 220, 2 , 1
    aSource     = ((a1*80)+(a2*55)+(a3*40))*kpara4
elseif iSourceType == 8 then
    iSndPitch = p4/261.626
    igrdur = .1
    itable = 5000+iPar2
    irealTable = 5500 + iSourceNum
    itabdur = nsamp(itable)
    ifreq = 1 / igrdur
    kamp = kpara4 * .2
    aindex upsamp abs(kpara3) * itabdur
    atrans upsamp kpara1 * igrdur * iSndPitch

    as1 synthGrain aindex, atrans, ifreq, 0.82, irealTable, itabdur
    as2 synthGrain aindex, atrans, ifreq, .58, irealTable, itabdur
    as3 synthGrain aindex, atrans, ifreq, .41, irealTable, itabdur
    as4 synthGrain aindex, atrans, ifreq, 0.19, irealTable, itabdur
    as5 synthGrain aindex, atrans, ifreq, 0, irealTable, itabdur
    aSource = (as1+as2+as3+as4+as5)*kamp
    aSource butterlp aSource, 7500
elseif iSourceType == 9 then
    aSource	homeSine p4*kpara1, kpara2*0.1, iPar3+30
    aSource = aSource*kpara4
elseif iSourceType == 10 then
    Sname       sprintf "/labmic%d", iPar2
    Sfullname   strcat gSpath, Sname
    iSndpitch   = p4/261.626
    aSource	    diskin	Sfullname, iSndpitch*abs(kpara3), 0, 1
    aSource     = aSource * kpara4
endif

aSource dcblock aSource
xout    aSource

nosource:
endop

opcode  effects, a, ii
iFxNum, ipitch     xin

iFxType table iFxNum+7, 5203

if iFxType == 0 then
goto nofx
endif

as1  zar iFxNum
as2  zar iFxNum+4
as  =   as1+as2

ioffset =   (iFxNum+3)*4
kpara1  zkr ioffset+1
kpara2  zkr ioffset+2
kpara3  zkr ioffset+3
kpara4  zkr ioffset+4

ioffset2 =   (iFxNum-1)*4
iPar1   table   ioffset2, 5202
iPar2   table   ioffset2+1, 5202
iPar3   table   ioffset2+2, 5202
iPar4   table   ioffset2+3, 5202

if iFxType == 1 then
    kwgfeed limit kpara3, 0, 1
    aFx	wguide1	as, abs(kpara1)+1, kpara2, kwgfeed
    aFx	=		aFx*kpara4
elseif iFxType == 2 then
    aFx	lpf18	as*.0005, abs(kpara1)+20, kpara2, kpara3
    aFx	=		aFx*5000*kpara4
elseif iFxType == 3 then
    aFx bqrez   as*kpara4, abs(kpara1)+20, abs(kpara2)+1, int(iPar3)
    aFx balance aFx, as*kpara4
elseif iFxType == 4 then
    amod lfo 1, kpara1, int(iPar3)
    aFx = ((as*amod*kpara2)+(as*(1-kpara2)))*kpara4
elseif iFxType == 5 then
    ain =   as*kpara4
    krevLength limit kpara1, 0.01, 10
    arev reverb ain, krevLength
    arev butterlp arev, kpara2
    aFx =   (arev*kpara3)+(as*(1-kpara3))
elseif iFxType == 6 then
    fsig  pvsanal   as, 1024, 256, 1024, 1
    ftps1  pvscale   fsig, kpara1
    aFx  pvsynth  ftps1
    adry delay as, iPar2
    aFx = ((aFx*kpara3)+(adry*(1-kpara3)))*kpara4
elseif iFxType == 7 then
    aeq1 butterbp as, 700, 400
    aeq2 butterbp as, 1500, 600
    aeq3 butterbp as, 3000, 1000
    aeq4 butterbp as, 5000, 2000
    aFx = (aeq1*kpara1)+(aeq2*kpara2)+(aeq3*kpara3)+(aeq4*kpara4)
elseif iFxType == 8 then
    afeed init 0
    adel oscil  kpara1, kpara2, 1
    adel = adel + kpara1 + kpara3
    adel limit adel, 0, 50
    aFx vdelay as+afeed, adel, 50
    afeed = aFx * kpara4
endif

xout    aFx

nofx:
endop


/****************************************************************
Reverb + master out
*****************************************************************/
instr 200

gktime timek

kTrackpadX chnget "trackpadX"
gkTrackpadX = kTrackpadX / 600.
gkTrackpadX limit gkTrackpadX, -1, 1

kTrackpadY chnget "trackpadY"
gkTrackpadY = kTrackpadY / 450.
gkTrackpadY limit -gkTrackpadY, -1, 1

koutGain chnget "masterVolume"
koutGain = koutGain * 0.02
gkduck  init    1
gkduck port gkduck, .03, 1.

ain		dcblock		gainrev*0.05
arev	reverb		ain, 2.5
arev	butterlp	arev, 5000

aLeft   butterlp        gaoutL, 7500
aRight  butterlp        gaoutR, 7500

aLeft   eqfil       aLeft, 4000, 1000, 0.125
aRight  eqfil       aRight, 4000, 1000, 0.125

;aLeft   butterhp    aLeft, 150
;aRight  butterhp    aRight, 150

aOutLeft dcblock (arev + aLeft) * koutGain * gkduck
aOutRight dcblock (arev + aRight) * koutGain * gkduck
gaRecL  =   aOutLeft
gaRecR  =   aOutRight
		outs		aOutLeft, aOutRight

        gaoutL = 0
        gaoutR = 0
		gainrev	=	0

endin

/****************************************************************
ducking
****************************************************************/
instr 5600
gkduck linseg 1., 0.005, 0.05, 3.9, 0.05, 0.095, 1
endin

/****************************************************************
Performance recording start
*****************************************************************/
instr 5400
Sname strget p4
ihandle fiopen Sname, 2
fout Sname, 2, gaRecL, gaRecR
clear gaRecL, gaRecR
endin

/****************************************************************
Performance recording stop ( closing file )
*****************************************************************/
instr 5401
Sname strget p4
turnoff2 5400, 8, 0
ficlose Sname
endin

/****************************************************************
Handler audio input recording
****************************************************************/
instr 5201

ktim timeinsts

gkduck = .05
itab = p4
ain inch 1
krms    rms     ain
ktrig   trigger     krms, 1500, 0

if ktrig == 1 then
event "i", 5202, 0 , 1, itab
turnoff
endif

ithresh = p3 - 1

if ktim > ithresh then
gkduck linseg .05, .8, .05, .2, 1
endif

endin

/****************************************************************
Audio input recording
****************************************************************/
instr 5202
kenv   adsr     0.005, 0.05, .9, 0.01
gkduck  linseg .05, .8, .05, .2, 1
ain inch 1

adel    delay   ain, .01

Sname sprintf "/home/olpc/.sugar/default/tamtam/snds/mic%d", int(p4)-6
ihandle fiopen Sname, 2
event "i", 5212, 1 , .01, p4

fout Sname, 2, adel*kenv
adel = 0
endin

/****************************************************************
Audio input recording ( closing file )
****************************************************************/
instr 5212
Sname sprintf "/home/olpc/.sugar/default/tamtam/snds/mic%d", int(p4)-6
ficlose Sname
endin

/****************************************************************
SynthLab mic recording
****************************************************************/
instr 6000
ain inch 1
aindex  phasor  1/p3
tablew  ain, aindex, 6000+p4, 1
endin

/****************************************************************
SynthLab input recording
****************************************************************/
instr 5204

Sname sprintf "/lab%d", int(p4)-85
Sfile strcat gSpath, Sname
fout Sfile, 2, gasynth
clear gasynth
endin

/************************
TamTam's SynthLab instrument
************************/
instr 5203

gSpath strget p10

if p5 != 0 then
event_i "i", 5204, 0, p3, p5
endif

aSource1	init	0
aSource2	init	0
aSource3	init	0
aSource4	init	0
aFx1		init	0
aFx2		init	0
aFx3		init	0
aFx4		init	0
aout		init	0

ipitch  =   p4

kc1     controller     1,p3
kc2     controller     2,p3
kc3     controller     3,p3
kc4     controller     4,p3

is1p1   ControlMatrice     5201, 0, kc1, kc2, kc3, kc4
is1p2   ControlMatrice     5201, 1, kc1, kc2, kc3, kc4
is1p3   ControlMatrice     5201, 2, kc1, kc2, kc3, kc4
is1p4   ControlMatrice     5201, 3, kc1, kc2, kc3, kc4
is2p1   ControlMatrice     5201, 4, kc1, kc2, kc3, kc4
is2p2   ControlMatrice     5201, 5, kc1, kc2, kc3, kc4
is2p3   ControlMatrice     5201, 6, kc1, kc2, kc3, kc4
is2p4   ControlMatrice     5201, 7, kc1, kc2, kc3, kc4
is3p1   ControlMatrice     5201, 8, kc1, kc2, kc3, kc4
is3p2   ControlMatrice     5201, 9, kc1, kc2, kc3, kc4
is3p3   ControlMatrice     5201, 10, kc1, kc2, kc3, kc4
is3p4   ControlMatrice     5201, 11, kc1, kc2, kc3, kc4
is4p1   ControlMatrice     5201, 12, kc1, kc2, kc3, kc4
is4p2   ControlMatrice     5201, 13, kc1, kc2, kc3, kc4
is4p3   ControlMatrice     5201, 14, kc1, kc2, kc3, kc4
is4p4   ControlMatrice     5201, 15, kc1, kc2, kc3, kc4

aSource1    source  1, ipitch*2
aSource2    source  2, ipitch*2
aSource3    source  3, ipitch*2
aSource4    source  4, ipitch*2

ifx1p1   ControlMatrice     5202, 0, kc1, kc2, kc3, kc4
ifx1p2   ControlMatrice     5202, 1, kc1, kc2, kc3, kc4
ifx1p3   ControlMatrice     5202, 2, kc1, kc2, kc3, kc4
ifx1p4   ControlMatrice     5202, 3, kc1, kc2, kc3, kc4
ifx2p1   ControlMatrice     5202, 4, kc1, kc2, kc3, kc4
ifx2p2   ControlMatrice     5202, 5, kc1, kc2, kc3, kc4
ifx2p3   ControlMatrice     5202, 6, kc1, kc2, kc3, kc4
ifx2p4   ControlMatrice     5202, 7, kc1, kc2, kc3, kc4
ifx3p1   ControlMatrice     5202, 8, kc1, kc2, kc3, kc4
ifx3p2   ControlMatrice     5202, 9, kc1, kc2, kc3, kc4
ifx3p3   ControlMatrice     5202, 10, kc1, kc2, kc3, kc4
ifx3p4   ControlMatrice     5202, 11, kc1, kc2, kc3, kc4
ifx4p1   ControlMatrice     5202, 12, kc1, kc2, kc3, kc4
ifx4p2   ControlMatrice     5202, 13, kc1, kc2, kc3, kc4
ifx4p3   ControlMatrice     5202, 14, kc1, kc2, kc3, kc4
ifx4p4   ControlMatrice     5202, 15, kc1, kc2, kc3, kc4

ifx1in   SourceMatrice	    1, aSource1, aSource2, aSource3, aSource4
ifx2in   SourceMatrice	    2, aSource1, aSource2, aSource3, aSource4
ifx3in   SourceMatrice	    3, aSource1, aSource2, aSource3, aSource4
ifx4in   SourceMatrice	    4, aSource1, aSource2, aSource3, aSource4

ifx1in1  FxMatrice          5, aFx1, aFx2, aFx3, aFx4
ifx2in1  FxMatrice          6, aFx1, aFx2, aFx3, aFx4
ifx3in1  FxMatrice          7, aFx1, aFx2, aFx3, aFx4
ifx4in1  FxMatrice          8, aFx1, aFx2, aFx3, aFx4

aFx1	   effects		    1, ipitch
aFx2	   effects		    2, ipitch
aFx3	   effects		    3, ipitch
aFx4	   effects		    4, ipitch

iSourceOut1 table 8, 5206
iSourceOut2 table 9, 5206
iSourceOut3 table 10, 5206
iSourceOut4 table 11, 5206
iFxOut1 table 12, 5206
iFxOut2 table 13, 5206
iFxOut3 table 14, 5206
iFxOut4 table 15, 5206

aout    =   (aSource1*iSourceOut1)+(aSource2*iSourceOut2)+(aSource3*iSourceOut3)+(aSource4*iSourceOut4)+(aFx1*iFxOut1)+(aFx2*iFxOut2)+(aFx3*iFxOut3)+(aFx4*iFxOut4)

kenv adsr p3*p6+0.001, p3*p7, p8, p3*p9
aout = aout*kenv

vincr gasynth, aout

        outs    aout*.707, aout*.707

zacl	0, 8

endin

/***********************
DELETE RESOURCES
************************/

instr 5000

icount init 0

again:
ftfree 5000+icount, 0
icount = icount+1

if icount < p4 goto again

turnoff

endin

/*************************
Loop points editor
*************************/
instr 5022

kstart chnget "lstart"
kend chnget "lend"
kdur chnget "ldur"
kvol chnget "lvol"

idurfadein     init    0.005
idurfadeout     init    0.095
iampe0    	init    1
iampe1    	init  	1
iampe2    	init    1

itie     	tival
if itie  ==  1     	igoto nofadein

iampe0    	init     0
iskip   =   1

nofadein:
iskip   =   0
igliss  =   0.005

if p3   < 	0       igoto nofadeout

iampe2      init    0

nofadeout:

idelta  =   idurfadein+idurfadeout
if idelta > abs(p3) then
idelta = abs(p3)
endif

iampe0      =       iampe0
iampe2      =       iampe2
kenv     	linseg  iampe0, idurfadein, iampe1, abs(p3)-idelta, iampe1, idurfadeout,  iampe2


ivibRand    random  4.1, 5.7

kvibrato    oscil   .006, ivibRand, 1

           	tigoto  tieskip

a1	     flooper2	0.5, 1+kvibrato, kstart, kend, kdur, 4999, 0, 0, 0, iskip

a1      =   a1*kenv*kvol

gaoutL = a1*0.5+gaoutL
gaoutR =  a1*0.5+gaoutR

gainrev	=	        a1*0.05+gainrev

  tieskip:
endin

/*************************
Loop points editor, simple player
*************************/
instr 5023

kvol chnget "lvol"

p3      =   nsamp(4999) * giScale

a1      loscil  0.5, 1, 4999, 1

kenv   adsr     0.005, 0.05, .8, 0.1

a1  =   a1*kenv*kvol

gaoutL = a1*0.5+gaoutL
gaoutR = a1*0.5+gaoutR

gainrev =	    a1*0.05+gainrev

endin

/****************************************************************
Soundfile player with miniTamTam's tied notes
****************************************************************/
/*************************
pitch, reverbGain, amp, pan, table, att, dec, filtType, cutoff, loopstart, loopend, crossdur
*************************/
instr 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010

idump = p16
idump2 = p17
idump3 = p18
idump4 = p19

iTrackId = int(p1-5001)
SvolTrackName sprintf "trackVolume%0d", iTrackId
kvol chnget SvolTrackName
kvol = kvol * 0.01
kvol port kvol, .01, i(kvol)

idurfadein     init    0.005
idurfadeout     init    0.095
iampe0    	init    1
iampe1    	=  	p6
iampe2    	init    1

itie     	tival
if itie  ==  1     	igoto nofadein

idurfadein  init p9
iampe0    	init     0
iskip   =   1
kpitch     	init  	p4
kamp   init    p6
kpan        init    p7
krg         init    p5

nofadein:
iskip   =   0
igliss  =   0.005

if p3   < 	0       igoto nofadeout

idurfadeout     init    p10
iampe2      init    0

nofadeout:

idelta  =   idurfadein+idurfadeout
if idelta > abs(p3) then
idelta = abs(p3)
endif

iampe0      =       iampe0 * p6
iampe2      =       iampe2 * p6
kenv     	linseg  iampe0, idurfadein, iampe1, abs(p3)-idelta, iampe1, idurfadeout,  iampe2

kpitchBend port gkTrackpadX, .03, i(gkTrackpadX)
kpitchBend pow kpitchBend + 1, 5
kampBend port gkTrackpadY, .03, i(gkTrackpadY)
kampBend pow kampBend + 1, 5

ivibRand    random  4.1, 5.7

kvibrato    oscil   .006*kampBend, ivibRand*kpitchBend, 1

           	tigoto  tieskip

kpitch     	portk  	p4, igliss, p4
kpan        portk   p7, igliss, p7
krg         portk   p5, igliss, p5
kcutoff     portk   p12, igliss, p12
kls	    portk   p13, igliss, p13
kle	    portk   p14, igliss, p14
kcd         portk   p15, igliss, p15

a1	     flooper2	1, kpitch+kvibrato, kls, kle, kcd, p8, 0, 0, 0, iskip

if (p11-1) != -1 then
acomp   =  a1
a1      bqrez   a1, kcutoff, 6, p11-1
a1      balance     a1, acomp
endif

if kpitch < 1 then
kalias = giAliasSr*kpitch
else
kalias = giAliasSr
endif

a1      tone   a1, kalias

a1      =   a1*kenv*kvol

gaoutL = a1*(1-kpan)+gaoutL
gaoutR =  a1*kpan+gaoutR

gainrev	=	        a1*krg+gainrev

  tieskip:
endin


/*************************
Soundfile player with edit's looped notes
*************************/
instr 5101, 5102, 5103, 5104, 5105, 5106, 5107, 5108, 5109, 5110

if p16 != -1 then
    inum    =   frac(p16) * 10000
    itable2 =   int(p16)
    event_i "i", inum, 0, p3, p4, p5, p6, p7, itable2, p9, p10, p11, p12, p17, p18, p19, -1
endif

ipitch random p4*.995, p4*1.005

iTrackId = int(p1-5101)
SvolTrackName2 sprintf "trackVolume%0d", iTrackId
kvol chnget SvolTrackName2
kvol = kvol * 0.01
kvol port kvol, .01, 0 ;i(kvol)

ivibRand    random  4.1, 5.7

kvibrato    oscil   .006, ivibRand, 1

a1	     flooper2	1, ipitch+kvibrato, p13, p14, p15, p8, 0, 0, 0

if (p11-1) != -1 then
acomp   =  a1
a1      bqrez   a1, p12, 6, p11-1
a1      balance     a1, acomp
endif

;if p4 < 1 then
;ialias = giAliasSr*p4
;else
;ialias = giAliasSr
;endif

;a1      tone   a1, ialias

aenv   adsr     p9, 0.005, p6, p10
a1      =   a1*aenv*kvol

gaoutL = a1*(1-p7)+gaoutL
gaoutR =  a1*p7+gaoutR

gainrev	= a1*p5+gainrev

endin

/**************************************************************
Simple soundfile player (miniTamTam)
**************************************************************/

instr 5011, 5012, 5013, 5014, 5015, 5016, 5017, 5018, 5019, 5020

idump = p16
idump2 = p17
idump3 = p18
idump4 = p19

iTrackId = int(p1-5011)
SvolTrackName3 sprintf "trackVolume%0d", iTrackId
kvol chnget SvolTrackName3
kvol = kvol * 0.01
kvol port kvol, .01

p3      =   nsamp(p8) * giScale / p4

a1      loscil  p6, p4, p8, 1

if (p11-1) != -1 then
acomp = a1
a1      bqrez   a1, p12, 6, p11-1
a1      balance     a1, acomp
endif

if p4 < 1 then
ialias = giAliasSr*p4
else
ialias = giAliasSr
endif

a1      tone   a1, ialias

kenv   adsr     p9, 0.05, .8, p10
a1  =  a1*kenv*kvol

gaoutL = a1*(1-p7)+gaoutL
gaoutR = a1*p7+gaoutR

gainrev =	    a1*p5+gainrev

endin

/**************************************************************
Simple soundfile player (Edit)
**************************************************************/

instr 5111, 5112, 5113, 5114, 5115, 5116, 5117, 5118, 5119, 5120

if p16 != -1 then
    inum    =   frac(p16) * 10000
    itable2 =   int(p16)
    event_i "i", inum, 0, p3, p4, p5, p6, p7, itable2, p9, p10, p11, p12, p17, p18, p19, -1
endif

iTrackId = int(p1-5111)
SvolTrackName4 sprintf "trackVolume%0d", iTrackId
kvol chnget SvolTrackName4
kvol = kvol * 0.01
kvol port kvol, .01

a1      loscil  p6, p4, p8, 1

if (p11-1) != -1 then
acomp = a1
a1      bqrez   a1, p12, 6, p11-1
a1      balance     a1, acomp
endif

;if p4 < 1 then
;ialias = giAliasSr*p4
;else
;ialias = giAliasSr
;endif

;a1      tone   a1, ialias

kenv   adsr     p9, 0.05, .8, p10

a1  =   a1*kenv*kvol

gaoutL = a1*(1-p7)+gaoutL
gaoutR = a1*p7+gaoutR

gainrev =	    a1*p5+gainrev

endin



/********************************************************************
soundfile player for percussion - resonance notes
********************************************************************/
instr 5021

a1	 flooper2	1, p4, .25, .750, .2, p8

if (p11-1) != -1 then
acomp   =   a1
a1      bqrez   a1, p12, 6, p11-1
a1      balance     a1, acomp
endif

kenv    expseg  0.001, .003, .6, p3 - .003, 0.001
klocalenv   adsr     p8, 0.05, .8, p10

a1      =   a1*kenv*klocalenv

gaoutL = a1*(1-p7)+gaoutL
gaoutR = a1*p7+gaoutR

gainrev	=	    a1*p5+gainrev

endin

</CsInstruments>
<CsScore>
f1 0 8192 10 1
f2 0 8192 11 1 1

f4 0 32 -2 	250 2250 2980 	420 2050 2630 	590 1770 2580
		750 1450 2590	290 750 2300	360 770 2530			     520 900 2510    710 1230 2700   570 1560 2560			  0 0 0 0 0
f30 0 1024 10 1 0 .3 0 .1
f31 0 1024 10 1 .5 .3 .25 .1
f32 0 1024 10 1 0 .1 0 .3 .2 0 0 .1
f33 0 1024 10 1 0 0 0 .1 0 0 .2 .1 0 0 .1
f34 0 1024 10 1 .6 0 0 .4 .2 .1 0 0 .1
f35 0 1024 10 1 .5 .3 0 .1 0 0 0 .1 .1
f36 0 1024 10 1 0 .6 .4 .1 0 0 .2 .1 0 0 .1
f37 0 1024 10 1 0 0 0 .1 .2 .1 0 0 0 .1 0 0 .1
f38 0 1024 10 1 .4 .3 0 .1 .2 .1 .1 .1 0 0 0 0 .1 .05
f39 0 1024 10 1 0  .5 0 0 .3  0 0 .2 0 .1 0 0 0 0 .2 0 0 0 .05 0 0 0 0 .03 ; ADDITIVE SYNTHESIS WAVE
f41 0 8193 19 .5 .5 270 .5 ; SIGMOID FUNCTION
f42 0 8192 -20 2 1
f44 0 8192 5 1 8192 0.001 ; EXPONENTIAL FUNCTION
f45 0 512 7 0 500 0 2 1 10 1
f5150 0 32768 7 0 32768 0
f6001 0 131072 7 0 131072 0
f6002 0 131072 7 0 131072 0
f6003 0 131072 7 0 131072 0
f6004 0 131072 7 0 131072 0
i200 0 600000
</CsScore>
</CsoundSynthesizer>