Debian Codegraph @

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