Debian Codegraph @

examples/xtratim-2.csd

raw
1 <CsoundSynthesizer>
2
3 <CsOptions>
4 ; Select audio/midi flags here according to platform
5 ; Audio out Audio in Silent MIDI in
6 -odac -iadc -d -M0 ;;;realtime I/O
7 </CsOptions>
8
9 <CsInstruments>
10 ;xtratim example by Jonathan Murphy Dec. 2006
11 sr = 44100
12 ksmps = 10
13 nchnls = 2
14
15 ; sine wave for oscillators
16 gisin ftgen 1, 0, 4096, 10, 1
17 ; set volume initially to midpoint
18 ctrlinit 1, 7,64
19
20 ;;; simple two oscil, two envelope synth
21 instr 1
22
23 ; frequency
24 kcps cpsmidib
25 ; initial velocity (noteon)
26 ivel veloc
27
28 ; master volume
29 kamp ctrl7 1, 7, 0, 127
30 kamp = kamp * ivel
31
32 ; parameters for aenv1
33 iatt1 = 0.03
34 idec1 = 1
35 isus1 = 0.25
36 irel1 = 1
37 ; parameters for aenv2
38 iatt2 = 0.06
39 idec2 = 2
40 isus2 = 0.5
41 irel2 = 2
42
43 ; extra (release) time allocated
44 xtratim (irel1>irel2 ? irel1 : irel2)
45 ; krel is used to trigger envelope release
46 krel init 0
47 krel release
48 ; if noteoff received, krel == 1, otherwise krel == 0
49 if (krel == 1) kgoto rel
50
51 ; attack, decay, sustain segments
52 atmp1 linseg 0, iatt1, 1, idec1, isus1 , 1, isus1
53 atmp2 linseg 0, iatt2, 1, idec2, isus2 , 1, isus2
54 aenv1 = atmp1
55 aenv2 = atmp2
56 kgoto done
57
58 ; release segment
59 rel:
60 atmp3 linseg 1, irel1, 0, 1, 0
61 atmp4 linseg 1, irel2, 0, 1, 0
62 aenv1 = atmp1 * atmp3 ;to go from the current value (in case
63 aenv2 = atmp2 * atmp4 ;the attack hasn't finished) to the release.
64
65 ; control oscillator amplitude using envelopes
66 done:
67 aosc1 oscil aenv1, kcps, gisin
68 aosc2 oscil aenv2, kcps * 1.5, gisin
69 aosc1 = aosc1 * kamp
70 aosc2 = aosc2 * kamp
71
72 ; send aosc1 to left channel, aosc2 to right,
73 ; release times are noticably different
74
75 outs aosc1, aosc2
76
77 endin
78
79 </CsInstruments>
80
81 <CsScore>
82
83 f 0 3600 ;dummy table to wait for realtime MIDI events
84
85 </CsScore>
86
87 </CsoundSynthesizer>