Debian Codegraph @

examples/modmatrix.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio flags here according to platform
4 ; Audio out Audio in
5 ;-odac -iadc ;;;RT audio I/O
6 ; For Non-realtime ouput leave only the line below:
7 -o modmatrix.wav -W ;;; for file output any platform
8 </CsOptions>
9 <CsInstruments>
10
11 sr = 44100
12 kr = 441
13 ksmps = 100
14 nchnls = 2
15 0dbfs = 1
16
17 ; basic waveforms
18 giSine ftgen 0, 0, 65537, 10, 1 ; sine wave
19 giSaw ftgen 0, 0, 4097, 7, 1, 4096, -1 ; saw (linear)
20 giSoftSaw ftgen 0, 0, 65537, 30, giSaw, 1, 10 ; soft saw (only 10 first harmonics)
21
22 ; modmatrix tables
23 giMaxNumParam = 128
24 giMaxNumMod = 32
25 giParam_In ftgen 0, 0, giMaxNumParam, 2, 0 ; input parameters table
26 ; output parameters table (parameter values with added modulators)
27 giParam_Out ftgen 0, 0, giMaxNumParam, 2, 0
28 giModulators ftgen 0, 0, giMaxNumMod, 2, 0 ; modulators table
29 ; modulation scaling and routing (mod matrix) table, start with empty table
30 giModScale ftgen 0, 0, giMaxNumParam*giMaxNumMod, -2, 0
31
32 ;********************************************
33 ; generate the modulator signals
34 ;********************************************
35 instr 1
36
37 ; LFO1, 1.5 Hz, normalized range (0.0 to 1.0)
38 kLFO1 oscil 0.5, 1.5, giSine ; generate LFO signal
39 kLFO1 = kLFO1+0.5 ; offset
40
41 ; LFO2, 0.4 Hz, normalized range (0.0 to 1.0)
42 kLFO2 oscil 0.5, 0.4, giSine ; generate LFO signal
43 kLFO2 = kLFO2+0.5 ; offset
44
45
46 ; write modulators to table
47 tablew kLFO1, 0, giModulators
48 tablew kLFO2, 1, giModulators
49
50 endin
51
52 ;********************************************
53 ; set parameter values
54 ;********************************************
55 instr 2
56
57 ; Here we can set the parameter values
58 icps1 = p4
59 icps2 = p5
60 icutoff = p6
61
62 ; write parameters to table
63 tableiw icps1, 0, giParam_In
64 tableiw icps2, 1, giParam_In
65 tableiw icutoff, 2, giParam_In
66
67 endin
68
69 ;********************************************
70 ; mod matrix edit
71 ;********************************************
72 instr 3
73
74 ; Here we can write to the modmatrix table by using tablew or tableiw
75
76 iLfo1ToCps1 = p4
77 iLfo1ToCps2 = p5
78 iLfo1ToCutoff = p6
79 iLfo2ToCps1 = p7
80 iLfo2ToCps2 = p8
81 iLfo2ToCutoff = p9
82
83 tableiw iLfo1ToCps1, 0, giModScale
84 tableiw iLfo1ToCps2, 1, giModScale
85 tableiw iLfo1ToCutoff, 2, giModScale
86 tableiw iLfo2ToCps1, 3, giModScale
87 tableiw iLfo2ToCps2, 4, giModScale
88 tableiw iLfo2ToCutoff, 5, giModScale
89
90 ; and set the update flag for modulator matrix
91 ; ***(must update to enable changes)
92 ktrig init 1
93 chnset ktrig, "modulatorUpdateFlag"
94 ktrig = 0
95
96 endin
97
98 ;********************************************
99 ; mod matrix
100 ;********************************************
101 instr 4
102
103 ; get the update flag
104 kupdate chnget "modulatorUpdateFlag"
105
106 ; run the mod matrix
107 inum_mod = 2
108 inum_parm = 3
109 modmatrix giParam_Out, giModulators, giParam_In, \
110 giModScale, inum_mod, inum_parm, kupdate
111
112 ; and reset the update flag
113 chnset 0, "modulatorUpdateFlag" ; reset the update flag
114
115 endin
116
117 ;********************************************
118 ; audio generator to test values
119 ;********************************************
120 instr 5
121
122 ; basic parameters
123 iamp = ampdbfs(-5)
124
125 ; read modulated parameters from table
126 kcps1 table 0, giParam_Out
127 kcps2 table 1, giParam_Out
128 kcutoff table 2, giParam_Out
129
130 ; set filter parameters
131 kCF_freq1 = kcps1*kcutoff
132 kCF_freq2 = kcps2*kcutoff
133 kReso = 0.7
134 kDist = 0.3
135
136 ; oscillators and filters
137 a1 oscili iamp, kcps1, giSoftSaw
138 a1 lpf18 a1, kCF_freq1, kReso, kDist
139
140 a2 oscili iamp, kcps2, giSoftSaw
141 a2 lpf18 a2, kCF_freq2, kReso, kDist
142
143 outs a1, a2
144
145 endin
146
147 </CsInstruments>
148 <CsScore>
149
150 ;********************************************
151 ; set initial parameters
152 ; cps1 cps2 cutoff
153 i2 0 1 400 800 3
154
155 ;********************************************
156 ; set modmatrix values
157 ; lfo1ToCps1 lfo1ToCps2 lfo1ToCut lfo2ToCps1 lfo2ToCps2 lfo2ToCut
158 i3 0 1 40 0 -2 -50 100 3
159
160 ;********************************************
161 ; start "always on" instruments
162 #define SCORELEN # 20 # ; set length of score
163
164 i1 0 $SCORELEN ; start modulators
165 i4 0 $SCORELEN ; start mod matrix
166 i5 0 $SCORELEN ; start audio oscillator
167
168 e
169
170 </CsScore>
171 </CsoundSynthesizer>