-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidisynthesizer.csd
More file actions
592 lines (247 loc) · 6.52 KB
/
Copy pathmidisynthesizer.csd
File metadata and controls
592 lines (247 loc) · 6.52 KB
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
;
; Author: Victor Lazzarini
; Originally published at http://csound.1045644.n5.nabble.com/csound-on-the-Intel-Galileo-td5737023.html
;
<CsoundSynthesizer>
<CsOptions>
-odac:hw:0 -b256 -B1024 -Ma -+rtaudio=alsa -+rtmidi=alsa
</CsOptions>
<CsInstruments>
sr=44100
ksmps=64
nchnls = 2
0dbfs=1
ginstrs = 3
ichn = 1
lp1: massign ichn, 0
loop_le ichn, 1, 16, lp1
pgmassign 0, 0
gipg ftgen 1001,0,16,7,0,16,0
gic2 ftgen 1002,0,16,7,127,16,127
gic3 ftgen 1003,0,16,7,64,16,64
gimod ftgen 1004,0,16,7,0,16,0
gibend ftgen 1005,0,16,7,1,16,1
instr 1
kinsto init 0
nxt:
kst, kch, kd1, kd2 midiin
if (kst != 0) then
kch = kch - 1
if (kst == 144 && kd2 != 0) then ; note on
kpg table kch, gipg
kpg = kpg%3
kpg += 100
printk2 kpg
kac active 102
if(kpg == 102) then
/* 102 is mono, the others are poly
instrument identifier is instr.[chn][note] */
kinst = kpg + kd1/100000 + kch/100
if(kac > 0 && kinsto != 0) then
event "i", -kinsto, 0, 1
endif
event "i", kinst, 0, -1, kd1, kd2, kch
kinsto = kinst
;endif
else
kinst = kpg + kd1/100000 + kch/100
event "i", kinst, 0, -1, kd1, kd2, kch
endif
elseif (kst == 128 || (kst == 144 && kd2 == 0)) then ; note off
kpg table kch, gipg
kpg = kpg%3
kpg += 100
kinst = kpg + kd1/100000 + kch/100
event "i", -kinst, 0, 1
kinsto = (kinst == kinsto) ? 0 : kinsto
elseif (kst == 192) then /* program change msgs */
kpg = kd1
tablew kpg, kch, gipg
printf "CHANNEL %d PGM %d\n",kd1,kch+1,kpg%ginstrs
elseif (kst == 176 && kd1 == 1) then /* mod msgs */
tablew kd2, kch, gimod
elseif (kst == 176 && kd1 == 2) then /* ctl2 msgs */
printk2 kd2
tablew kd2, kch, gic2
elseif (kst == 176 && kd1 == 3) then /* ctl3 msgs */
tablew kd2, kch, gic3
elseif (kst == 224) then
kd2 = kd2/64
kbnd = 2^(2*(kd2-1)/12)
tablew kbnd, kch, gibend
endif
kgoto nxt
endif
endin
garev1 init 0
garev2 init 0
instr 100
iatt table p6, gic2
idec table p6, gic3
knx = p6
kmod table knx, gimod
printk2 kmod
kmod = 0.002+0.006*kmod/128
knx = p6
kbnd table knx, gibend
kcps = cpsmidinn(p4)*kbnd
iamp = 0.2*p5/128
a1 vco2 iamp, kcps*(1.00+kmod)
a2 vco2 iamp, kcps*(1.00+kmod*2)
a3 vco2 iamp, kcps
a4 vco2 iamp, kcps*(1.00-kmod*2)
a5 vco2 iamp, kcps*(1.00-kmod)
iatt /= 128
idec /= 128
idec += 0.01
a6 linenr a1+a2+a3+a4+a5, iatt+0.001,idec,idec/10
kosc oscili 0.5, 0.5, 1
a7, a8 pan2 a6, 0.5+kosc
outs a7, a8
garev2 = a7*0.5 + garev2
garev1 = a8*0.5 + garev1
endin
gifn ftgen 10000,0, 257, 9, .5,1,270,1.5,.33,90,2.5,.2,270,3.5,.143,90,4.5,.111,270
instr 101
knx = p6
iatt table p6, gic2
idec table p6, gic3
icps = cpsmidinn(p4)
kbnd table knx, gibend
kcps = icps*kbnd
iamp = p5/128
kmod table knx, gimod
kmod = kmod/128
a1 pluck 1, kcps, icps/1.123,0,1
iatt /= 128
idec /= 128
idec += 0.01
a1 linenr a1, iatt+0.001,idec,idec/10
a6 distort a1, kmod, gifn
a6 balance a6,a1
kosc oscili 0.5, 0.5, 1
a7, a8 pan2 a6, 0.5+kosc
outs a7, a8
garev2 = a7*0.5 + garev2
garev1 = a8*0.5 + garev1
endin
opcode ModFM,a,aakkkki
acos,aph,kamp,kfo,kfc,kbw,itab xin
itm = 14
icor = 4.*exp(-1)
ktrig changed kbw
if ktrig == 1 then
k2 = exp(-kfo/(.29*kbw*icor))
kg2 = 2*sqrt(k2)/(1.-k2)
kndx = kg2*kg2/2.
endif
kf = kfc/kfo
kfin = int(kf)
ka = kf - kfin
aexp table kndx*(1-acos)/itm,3,1
ioff = 0.25
acos1 tablei aph*kfin, itab, 1, ioff, 1
acos2 tablei aph*(kfin+1), itab, 1, ioff, 1
asig = (ka*acos2 + (1-ka)*acos1)*aexp
xout asig*kamp
endop
instr 102
knx = p6
kbnd table knx, gibend
kfun1 = cpsmidinn(p4)*kbnd
iamp = (p5/128)*0.3
imod table p6, gimod
kmod table knx, gimod
kndx port kmod/128,0.1,imod/128
kform1 tablei kndx, 101, 1, 0, 1 ; 5 formant regions
kform2 tablei kndx, 102, 1, 0, 1
kform3 tablei kndx, 103, 1, 0, 1
kform4 tablei kndx, 104, 1, 0, 1
; formant amplitudes
kaf2 tablei kndx, 112, 1, 0, 1
kaf3 tablei kndx, 113, 1, 0, 1
kaf4 tablei kndx, 114, 1, 0, 1
kaf5 tablei kndx, 115, 1, 0, 1
kscal = 1/(1+ampdb(kaf3)+ampdb(kaf2)+ampdb(kaf4)+ampdb(kaf5)) ; scale output
kbw1 tablei kndx, 121, 1, 0, 1
kbw2 tablei kndx, 122, 1, 0, 1
kbw3 tablei kndx, 123, 1, 0, 1
kbw4 tablei kndx, 124, 1, 0, 1
kbw5 tablei kndx, 125, 1, 0, 1
kvib = .9*log(kfun1) ; vibrato intensity
kvib = kvib*0.5
;jitter & vibr
kj randi kvib, 15
kv linen 1, 1, p3,1
iph rnd31 1, 0
kv oscili kvib*kv, 3.8+kv, 1, iph
;fundamental + jitter + vibr
kfun = (kfun1+kj+kv)
iadj = 1.5
iadj2 = 2
aph phasor kfun
acos tablei aph, 1, 1, 0.25, 1
if kform1 <= kfun then
kform1 = kfun
endif
a1 ModFM acos,aph,1,kfun,kform1,kbw1,1
a2 ModFM acos,aph,ampdb(kaf2),kfun,kform2,kbw2*iadj,1
a3 ModFM acos,aph,ampdb(kaf3),kfun,kform3,kbw3*iadj2,1
;a4 ModFM acos,aph,ampdb(kaf4),kfun,kform4,kbw4*iadj2,1
;a5 ModFM acos,aph,ampdb(kaf5),kfun,4950,kbw5*iadj2,1
asuml = (a3+a2+a1)*kscal*iamp ; mix all formant regions
iatt table p6, gic2
idec table p6, gic3
iatt /= 128
idec /= 128
idec = 0.01
aenv linenr asuml, iatt+0.001,idec,idec/10
asuml dcblock aenv
garev1 = asuml*0.5 + garev1
garev2 = asuml*0.5 + garev2
outs asuml,asuml
endin
instr 200
arev1,arev2 freeverb garev1, garev2, 0.7, 0.7
outs arev1,arev2
garev2 = 0
garev1 = 0
endin
</CsInstruments>
<CsScore>
f1 0 16384 10 1
f3 0 131072 "exp" 0 -14 1
f101 0 4 -2 800 325 350 450
f102 0 4 -2 1150 700 2000 800
f103 0 4 -2 2900 2700 2800 2830
f104 0 4 -2 3900 3800 3600 3800
f112 0 4 -2 -6 -16 -20 -11
f113 0 4 -2 -32 -35 -15 -22
f114 0 4 -2 -20 -40 -40 -22
f115 0 4 -2 -50 -60 -56 -50
f121 0 4 -2 80 50 60 70
f122 0 4 -2 90 60 90 80
f123 0 4 -2 120 170 100 100
f124 0 4 -2 130 180 150 130
f125 0 4 -2 140 200 200 135
i1 0 36000
i200 0 36000
</CsScore>
</CsoundSynthesizer>
<bsbPanel>
<label>Widgets</label>
<objectName/>
<x>100</x>
<y>100</y>
<width>320</width>
<height>240</height>
<visible>true</visible>
<uuid/>
<bgcolor mode="nobackground">
<r>255</r>
<g>255</g>
<b>255</b>
</bgcolor>
</bsbPanel>
<bsbPresets>
</bsbPresets>