Debian Codegraph @

examples/reinit-musical.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ;-n -d
4 -o dac
5 </CsOptions>
6 <CsInstruments>
7 ;
8 ; GRANULAR SYNTHESIS
9 ; --------------------
10 ; Ver 2.1
11 ; Eugenio Giordani
12 ;
13 ;
14 ;-----------------------------------------------------------------------------------
15 ;this csd implements the Granular Synthesis based on the model proposed by B. Truax.
16 ;
17 ;--------------- ORCHESTRA HEADER -------------------
18 ;NOTE: for a better audio quality ksmps = 1
19 ;
20 sr = 44100
21 ksmps = 2
22 nchnls = 2
23 0dbfs = 1
24
25 ;---------------- Global control variables initialization -------------
26 ;
27 gkdur init 0 ;average grain duration
28 gkdurr init 0 ;grain duration random variation
29 gkdel init 0 ;average grain delay
30 gkdelr init 0 ;grain delay random variation
31 gkramp init 0 ;ramp ratio
32 gkfreq init 0 ;audio signal average frequency
33 gkfreqr init 0 ;audio signal frequency random variation
34 gkphase init 0 ;audio signal phase
35 gkphaser init 0 ;audio signal phase random variation
36 gkamp init 0 ;global amplitude
37
38 gkran init 0 ;instant random frequency
39
40 gkrnd1 init 0 ;instant grain random duration (VOICE #1)
41 gkrnd2 init 0 ; (VOICE #2)
42 gkrnd3 init 0 ; (VOICE #3)
43 gkrnd4 init 0 ; (VOICE #4)
44
45 gkrnd1y init 0 ;instant grain random delay (VOICE #1)
46 gkrnd2y init 0 ; (VOICE #2)
47 gkrnd3y init 0 ; (VOICE #3)
48 gkrnd4y init 0 ; (VOICE #4)
49
50 gkrnd1p init 0 ;instant grain random phase (VOICE #1)
51 gkrnd2p init 0 ; (VOICE #2)
52 gkrnd3p init 0 ; (VOICE #3)
53 gkrnd4p init 0 ; (VOICE #4)
54
55
56 instr 1
57 ;=========== GRAIN GENERATOR (VOICE #1) =============
58
59 ifun = p4 ;audio function
60 ;
61 ; Update of grain parameters (re-initialisation)
62 ; ----------------------------------------------
63 loop:
64 idur = i(gkdur) ;the gk... values are sampled
65 ;by the corresponding generator in instr 11
66 ;and converted in type i var
67
68 idurr = i (gkrnd1)
69
70 itrpz = abs(0.001* (idur + idurr)) ;calculates the duration of the trapezoid
71
72 iramp = i(gkramp) + 0.1 ;plus magic number
73
74 idel = i(gkdel)
75 idelr = i(gkrnd1y)
76 idely = abs(0.001 * (idel + idelr)) ;calculate the total delay
77 ifreq = i(gkfreq)
78 ifreqr = i(gkran)
79 iphase = i(gkphase)
80 iphaser = i(gkrnd1p)
81 iamp = i(gkamp)
82
83 irise = itrpz/iramp ;calculates the attack time of the trapezoid
84 isus = itrpz - (2 * irise) ;calculates the sustain duration of the trapezoid
85 igrain = itrpz + idely ;calculates the duration trapezoid+delay
86 iph = abs(iphase + iphaser) ;calculates the final phase
87 ifq = ifreq + ifreqr ;calculates the final frequency
88
89 ;------------ Interrupt simulation section (interruption) -------------------
90 ;
91 ;The timout opcode works as a interrupt generator. Timout is loaded
92 ;with the current duration of the grain and decremented automatically until zero
93
94 timout 0,igrain,cont ;if the counter value is different from zero go to cont
95
96 reinit loop ;or go to the reinitialization
97
98 cont:
99 k1 linseg 0,irise,iamp,isus,iamp,irise,0,idel,0 ;generates grain envelop
100 ga1 oscili k1,ifq,ifun,iph ;generates voice 1
101 printk 0.1, k(ga1)
102 ga2 init 0
103 ga3 init 0
104 ga4 init 0
105 endin
106
107 instr 2
108 ;=========== GRAIN GENERATOR (VOICE #2) =============
109
110 ifun = p4 ;audio function
111 ;
112 ; Update of grain parameters (re-initialisation)
113 ; ----------------------------------------------
114 loop:
115 idur = i(gkdur) ;the gk... values are sampled
116 ;by the corresponding generator in instr 11
117 ;and converted in type i var
118
119 idurr = i (gkrnd2)
120
121 itrpz = abs(0.001* (idur + idurr)) ;calculates the duration of the trapezoid
122
123 iramp = i(gkramp) + 0.1 ;plus magic number
124
125 idel = i(gkdel)
126 idelr = i(gkrnd2y)
127 idely = abs(0.001 * (idel + idelr)) ;calculate the total delay
128 ifreq = i(gkfreq)
129 ifreqr = i(gkran)
130 iphase = i(gkphase)
131 iphaser = i(gkrnd2p)
132 iamp = i(gkamp)
133
134 irise = itrpz/iramp ;calculates the attack time of the trapezoid
135 isus = itrpz - (2 * irise) ;calculates the sustain duration of the trapezoid
136 igrain = itrpz + idely ;calculates the duration trapezoid+delay
137 iph = abs(iphase + iphaser) ;calculates the final phase
138 ifq = ifreq + ifreqr ;calculates the final frequency
139
140 ;------------ Interrupt simulation section (interruption) -------------------
141 ;
142 ;The timout opcode works as a interrupt generator. Timout is loaded
143 ;with the current duration of the grain and decremented automatically until zero
144
145 timout 0,igrain,cont ;if the counter value is different from zero go to cont
146
147 reinit loop ;or go to the reinitialization
148
149 cont:
150 k1 linseg 0,irise,iamp,isus,iamp,irise,0,idel,0 ;generates grain envelop
151 ga2 oscili k1,ifq,ifun,iph ;generates voice 2
152
153 endin
154
155 instr 3
156 ;=========== GRAIN GENERATOR (VOICE #3) =============
157
158 ifun = p4 ;audio function
159 ;
160 ; Update of grain parameters (re-initialisation)
161 ; ----------------------------------------------
162 loop:
163 idur = i(gkdur) ;the gk... values are sampled
164 ;by the corresponding generator in instr 11
165 ;and converted in type i var
166
167 idurr = i (gkrnd3)
168
169 itrpz = abs(0.001* (idur + idurr)) ;calculates the duration of the trapezoid
170
171 iramp = i(gkramp) + 0.1 ;plus magic number
172
173 idel = i(gkdel)
174 idelr = i(gkrnd3y)
175 idely = abs(0.001 * (idel + idelr)) ;calculate the total delay
176 ifreq = i(gkfreq)
177 ifreqr = i(gkran)
178 iphase = i(gkphase)
179 iphaser = i(gkrnd3p)
180 iamp = i(gkamp)
181
182 irise = itrpz/iramp ;calculates the attack time of the trapezoid
183 isus = itrpz - (2 * irise) ;calculates the sustain duration of the trapezoid
184 igrain = itrpz + idely ;calculates the duration trapezoid+delay
185 iph = abs(iphase + iphaser) ;calculates the final phase
186 ifq = ifreq + ifreqr ;calculates the final frequency
187
188 ;------------ Interrupt simulation section (interruption) -------------------
189 ;
190 ;The timout opcode works as a interrupt generator. Timout is loaded
191 ;with the current duration of the grain and decremented automatically until zero
192
193 timout 0,igrain,cont ;if the counter value is different from zero go to cont
194
195 reinit loop ;or go to the reinitialization
196
197 cont:
198 k1 linseg 0,irise,iamp,isus,iamp,irise,0,idel,0 ;generates grain envelop
199 ga3 oscili k1,ifq,ifun,iph ;generates voice 3
200
201 endin
202
203 instr 4
204 ;=========== GRAIN GENERATOR (VOICE #4) =============
205
206 ifun = p4 ;audio function
207 ;
208 ; Update of grain parameters (re-initialisation)
209 ; ----------------------------------------------
210 loop:
211 idur = i(gkdur) ;the gk... values are sampled
212 ;by the corresponding generator in instr 11
213 ;and converted in type i var
214
215 idurr = i (gkrnd4)
216
217 itrpz = abs(0.001* (idur + idurr)) ;calculates the duration of the trapezoid
218
219 iramp = i(gkramp) + 0.1 ;plus magic number
220
221 idel = i(gkdel)
222 idelr = i(gkrnd4y)
223 idely = abs(0.001 * (idel + idelr)) ;calculate the total delay
224 ifreq = i(gkfreq)
225 ifreqr = i(gkran)
226 iphase = i(gkphase)
227 iphaser = i(gkrnd4p)
228 iamp = i(gkamp)
229
230 irise = itrpz/iramp ;calculates the attack time of the trapezoid
231 isus = itrpz - (2 * irise) ;calculates the sustain duration of the trapezoid
232 igrain = itrpz + idely ;calculates the duration trapezoid+delay
233 iph = abs(iphase + iphaser) ;calculates the final phase
234 ifq = ifreq + ifreqr ;calculates the final frequency
235
236 ;------------ Interrupt simulation section (interruption) -------------------
237 ;
238 ;The timout opcode works as a interrupt generator. Timout is loaded
239 ;with the current duration of the grain and decremented automatically until zero
240
241 timout 0,igrain,cont ;if the counter value is different from zero go to cont
242
243 reinit loop ;or go to the reinitialization
244
245 cont:
246 k1 linseg 0,irise,iamp,isus,iamp,irise,0,idel,0 ;generates grain envelop
247 ga4 oscili k1,ifq,ifun,iph ;generates voice 4
248
249 endin
250
251 ;=========== GRAIN CONTROLLER =============
252 instr 11
253 ;
254
255 gkdur oscil1 0,1,p3,p4 ;control generator for idur
256 printk 0.1, gkdur
257 gkdurr oscil1 0,1,p3,p5 ; idurr
258 gkdel oscil1 0,1,p3,p6 ; idel
259 gkdelr oscil1 0,1,p3,p7 ; idelr
260 gkramp oscil1 0,1,p3,p8 ; iramp
261 gkfreq oscil1 0,1,p3,p9 ; ifreq
262 gkfreqr oscil1 0,1,p3,p10 ; ifreqr
263 gkphase oscil1 0,1,p3,p11 ; iphase
264 gkphaser oscil1 0,1,p3,p12 ; iphaser
265 gkamp oscil1 0,1,p3,p13 ; iamp
266
267 krnd1 rand 1, 0.1 ;random generator (VOICE #1)
268 krnd2 rand 1, 0.9 ; (VOICE #2)
269 krnd3 rand 1, 0.5 ; (VOICE #3)
270 krnd4 rand 1, 0.3 ; (VOICE #4)
271
272 ;the instantaneous values of the random generators are rescaled to obtain the appropriate values of
273 ;frequency, duration, delay, and phase
274
275 gkran = krnd1 * gkfreqr/2 ;rescale freq random variation (VOICE #1,2,3,4)
276
277 gkrnd1 = krnd1 * gkdurr/2 ;rescale duration random variation (VOICE #1)
278 gkrnd2 = krnd2 * gkdurr/2 ; (VOICE #2)
279 gkrnd3 = krnd3 * gkdurr/2 ; (VOICE #3)
280 gkrnd4 = krnd4 * gkdurr/2 ; (VOICE #4)
281
282 gkrnd1y = krnd1 * (0.05 + gkdelr /2) ;rescale delay random variation (VOICE #1)
283 gkrnd2y = krnd2 * (0.05 + gkdelr /2) ; (VOICE #2)
284 gkrnd3y = krnd3 * (0.05 + gkdelr /2) ; (VOICE #3)
285 gkrnd4y = krnd4 * (0.05 + gkdelr /2) ; (VOICE #4)
286
287 gkrnd1p = krnd1 * gkphaser/2 ;rescale phase random variation
288 gkrnd2p = krnd2 * gkphaser/2 ;
289 gkrnd3p = krnd3 * gkphaser/2 ;
290 gkrnd4p = krnd4 * gkphaser/2 ;
291
292 endin
293
294 ;=========================== RESCALE, MIX & OUT ================================
295
296 instr 21
297
298 iscale = p4 ;reads the scale factor from the score
299 outs1 (ga1/2 + ga2/2) * iscale ;sends the voices 1 and 2 to output
300 outs2 (ga3/2 + ga4/2) * iscale ;sends the voices 3 and 4 to output
301 endin
302 </CsInstruments>
303 <CsScore>
304 ;gsc4.sco
305 ;
306 ;-------- Control function for grain duration --------
307 ;
308 f11 0 512 -7 10 256 20 128 20 128 16
309
310 ;-------- Control function for random duration variation --------
311 ;
312 f12 0 512 -7 4 256 1 256 0
313
314 ;-------- Control function for grain delay --------
315 ;
316 f13 0 512 -7 10 256 20 256 5
317
318 ;-------- Control function for random delay variation --------
319 ;
320 f14 0 512 -7 0 128 0 256 2 128 0
321
322 ;-------- Control function for ramp ratio --------
323 ;
324 f15 0 512 -7 2 256 4 256 2
325
326 ;-------- Control function for frequency --------
327 ;
328 ;f16 0 512 -7 1.345 512 3.345
329 f16 0 512 -7 220 512 220
330
331 ;-------- Control function for random frequency variation --------
332 ;
333 f17 0 512 -7 0 512 110
334
335 ;-------- Control function for phase (or Pointer to audio file) --------
336 ;
337 f18 0 512 -7 0 512 0
338
339 ;-------- Control function for random phase variation --------
340 f19 0 512 -7 0 128 1 256 0 128 0
341
342 ;-------- Control function for total amplitude --------
343 ;
344 f20 0 512 7 0 128 1 256 1 128 0
345 ;================= Audio Functions =====================
346 ;f1 0 0 -1 "density.wav" 0 0 0
347 f1 0 1024 10 0.6 0.8 1 0.5 0.3 0.5 0.7
348 ;===========================================================
349 ;p1 p2 p3 p4
350 ;-----------------------------------------------------------
351 ; ifun
352 i1 0 40 1
353 i2 0 40 1
354 i3 0 40 1
355 i4 0 40 1
356 ;-------------------------------------------------------------------------------
357 ; dur durr del delr ramp freq freqr phase phaser amp
358 i11 0 40 11 12 13 14 15 16 17 18 19 20
359 ;-------------------------------------------------------------------------------
360 ; scale
361 i21 0 40 .61
362 f0 z
363 e
364 </CsScore>
365 </CsoundSynthesizer>