Debian Codegraph @

examples/grain2.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 ; Audio out Audio in No messages
5 -odac -iadc -d ;;;RT audio I/O
6 ; For Non-realtime ouput leave only the line below:
7 ; -o grain2.wav -W ;;; for file output any platform
8 </CsOptions>
9 <CsInstruments>
10
11 sr = 48000
12 kr = 750
13 ksmps = 64
14 nchnls = 2
15
16 /* square wave */
17 i_ ftgen 1, 0, 4096, 7, 1, 2048, 1, 0, -1, 2048, -1
18 /* window */
19 i_ ftgen 2, 0, 16384, 7, 0, 4096, 1, 4096, 0.3333, 8192, 0
20 /* sine wave */
21 i_ ftgen 3, 0, 1024, 10, 1
22 /* room parameters */
23 i_ ftgen 7, 0, 64, -2, 4, 50, -1, -1, -1, 11, \
24 1, 26.833, 0.05, 0.85, 10000, 0.8, 0.5, 2, \
25 1, 1.753, 0.05, 0.85, 5000, 0.8, 0.5, 2, \
26 1, 39.451, 0.05, 0.85, 7000, 0.8, 0.5, 2, \
27 1, 33.503, 0.05, 0.85, 7000, 0.8, 0.5, 2, \
28 1, 36.151, 0.05, 0.85, 7000, 0.8, 0.5, 2, \
29 1, 29.633, 0.05, 0.85, 7000, 0.8, 0.5, 2
30
31 ga01 init 0
32
33 /* generate bandlimited square waves */
34
35 i0 = 0
36 loop1:
37 imaxh = sr / (2 * 440.0 * exp(log(2.0) * (i0 - 69) / 12))
38 i_ ftgen i0 + 256, 0, 4096, -30, 1, 1, imaxh
39 i0 = i0 + 1
40 if (i0 < 127.5) igoto loop1
41
42 instr 1
43
44 p3 = p3 + 0.2
45
46 /* note velocity */
47 iamp = 0.0039 + p5 * p5 / 16192
48 /* vibrato */
49 kcps oscili 1, 8, 3
50 kenv linseg 0, 0.05, 0, 0.1, 1, 1, 1
51 /* frequency */
52 kcps = (kcps * kenv * 0.01 + 1) * 440 * exp(log(2) * (p4 - 69) / 12)
53 /* grain ftable */
54 kfn = int(256 + 69 + 0.5 + 12 * log(kcps / 440) / log(2))
55 /* grain duration */
56 kgdur port 100, 0.1, 20
57 kgdur = kgdur / kcps
58
59 a1 grain2 kcps, kcps * 0.02, kgdur, 50, kfn, 2, -0.5, 22, 2
60 a1 butterlp a1, 3000
61 a2 grain2 kcps, kcps * 0.02, 4 / kcps, 50, kfn, 2, -0.5, 23, 2
62 a2 butterbp a2, 12000, 8000
63 a2 butterbp a2, 12000, 8000
64 aenv1 linseg 0, 0.01, 1, 1, 1
65 aenv2 linseg 3, 0.05, 1, 1, 1
66 aenv3 linseg 1, p3 - 0.2, 1, 0.07, 0, 1, 0
67
68 a1 = aenv1 * aenv3 * (a1 + a2 * 0.7 * aenv2)
69
70 ga01 = ga01 + a1 * 10000 * iamp
71
72 endin
73
74 /* output instr */
75
76 instr 81
77
78 i1 = 0.000001
79 aLl, aLh, aRl, aRh spat3di ga01 + i1*i1*i1*i1, 3.0, 4.0, 0.0, 0.5, 7, 4
80 ga01 = 0
81 aLl butterlp aLl, 800.0
82 aRl butterlp aRl, 800.0
83
84 outs aLl + aLh, aRl + aRh
85
86 endin
87
88
89 </CsInstruments>
90 <CsScore>
91
92 t 0 60
93
94 i 1 0.0 1.3 60 127
95 i 1 2.0 1.3 67 127
96 i 1 4.0 1.3 64 112
97 i 1 4.0 1.3 72 112
98
99 i 81 0 6.4
100
101 e
102
103
104 </CsScore>
105 </CsoundSynthesizer>