Debian Codegraph @

src/Examples/McCurdy Collection/Convolution/pconvolve.csd

raw
1 ;Written by Iain McCurdy, 2009
2 ; Modified for QuteCsound by René, September 2010
3 ; Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 815
4
5 ;Notes on modifications from original csd:
6 ; Add Browser for audio file and use of FilePlay2 udo, now accept mono or stereo wav files
7
8
9 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
10 <CsoundSynthesizer>
11 <CsOptions>
12 --env:SSDIR+=../../SourceMaterials
13 </CsOptions>
14 <CsInstruments>
15 sr = 44100 ;SAMPLE RATE
16 ksmps = 128 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
17 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
18 0dbfs = 1 ;MAXIMUM SOUND INTENSITY LEVEL REGARDLESS OF BIT DEPTH
19
20
21 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz
22 ;gives stereo output regardless your soundfile is mono or stereo
23 Sfil, kspeed, iskip, iloop xin
24 ichn filenchnls Sfil
25 if ichn == 1 then
26 aL diskin2 Sfil, kspeed, iskip, iloop
27 aR = aL
28 else
29 aL, aR diskin2 Sfil, kspeed, iskip, iloop
30 endif
31 xout aL, aR
32 endop
33
34
35 instr 10 ;GUI
36 ktrig metro 10
37 if (ktrig == 1) then
38
39 gkGain invalue "Gain" ;init 0.7
40 gkMix invalue "Mix" ;init 0.17
41
42 gkinput invalue "Input"
43 gkfile invalue "File"
44 endif
45 endin
46
47 instr 1 ;GENERATE INPUT AUDIO INDEPENDENTLY OF REVERBERATING INSTRUMENT
48 kon invalue "on"
49
50 if gkinput=0 then ;IF 'Sound File' IS SELECTED...
51 Sfile invalue "_Browse1"
52 gaL, gaR FilePlay2 Sfile, 1, 0, 1 ;READ AUDIO FROM SOUND FILE ON HARD DISC
53 elseif gkinput=1 then ;IF 'Live Input' IS SELECTED
54 gaL inch 1 ;READ AUDIO FROM SOUND CARD'S FIRST (LEFT) INPUT
55 gaR = gaL ;MONO INPUT THEREFORE ASSIGN RIGHT CHANNEL TO LEFT CHANNEL ALSO
56 endif
57 gaL = gaL *kon
58 gaR = gaR *kon
59 endin
60
61 instr 2 ;CONVOLUTION REVERB INSTRUMENT
62
63
64 Sir invalue "_Browse2"
65 kSwitch = changed(gkfile) + changed(Sir) ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
66 if kSwitch=1 then ;IF I-RATE VARIABLE IS CHANGED...
67 reinit UPDATE ;BEGIN A REINITIALISATION PASS IN ORDER TO EFFECT THIS CHANGE. BEGIN THIS PASS AT LABEL ENTITLED 'UPDATE' AND CONTINUE UNTIL rireturn OPCODE
68 endif ;END OF CONDITIONAL BRANCHING
69 UPDATE: ;LABEL
70 if gkfile=0 then ;IF 'STAIRWELL' IS CHOSEN AS CONVOLUTION FILE...
71 ar1 pconvolve gaL, "StairwellL.wav" ;PERFORM CONVOLUTION BETWEEN AUDIO INPUT FROM INSTR 1 AND SOUNDFILE STORED ON DISK (LEFT CHANNEL)
72 ar2 pconvolve gaR, "StairwellR.wav" ;PERFORM CONVOLUTION BETWEEN AUDIO INPUT FROM INSTR 1 AND SOUNDFILE STORED ON DISK (RIGHT CHANNEL)
73 elseif gkfile=1 then ;IF 'DISH' IS CHOSEN AS CONVOLUTION FILE...
74 ar1 pconvolve gaL, "dishL.wav" ;PERFORM CONVOLUTION BETWEEN AUDIO INPUT FROM INSTR 1 AND SOUNDFILE STORED ON DISK (LEFT CHANNEL)
75 ar2 pconvolve gaR, "dishR.wav" ;PERFORM CONVOLUTION BETWEEN AUDIO INPUT FROM INSTR 1 AND SOUNDFILE STORED ON DISK (RIGHT CHANNEL)
76 elseif gkfile==2 then
77 ar1 pconvolve gaL, Sir, 0, 1
78 ar2 pconvolve gaR, Sir, 0, 1
79 endif ;END OF CONDITIONAL BRANCHING
80 aL ntrpol gaL, ar1*0.1, gkMix ;CREATE DRY/WET MIX (LEFT CHANNEL)
81 aR ntrpol gaR, ar2*0.1, gkMix ;CREATE DRY/WET MIX (RIGHT CHANNEL)
82 outs aL*gkGain, aR*gkGain ;SEND AUDIO TO OUTPUTS
83 gaL = 0 ;CLEAR GLOBAL AUDIO SIGNAL FROM INSTR 1 (LEFT CHANNEL)
84 gaR = 0 ;CLEAR GLOBAL AUDIO SIGNAL FROM INSTR 1 (RIGHT CHANNEL)
85 endin
86 </CsInstruments>
87 <CsScore>
88 i 10 0 3600 ;GUI
89 i 1 0 3600 ;INSTRUMENT 1 (SOURCE INSTRUMENT) RUNS FOR 1
90 i 2 0 3600 ;INSTRUMENT 2 (CONVOLUTION INSTRUMENT) RUNS FOR 1 HOUR (AND KEEPS REAL-TIME PERFORMANCE GOING)
91 </CsScore>
92 </CsoundSynthesizer>
93 <bsbPanel>
94 <label>Widgets</label>
95 <objectName/>
96 <x>235</x>
97 <y>68</y>
98 <width>967</width>
99 <height>327</height>
100 <visible>true</visible>
101 <uuid/>
102 <bgcolor mode="background">
103 <r>241</r>
104 <g>226</g>
105 <b>185</b>
106 </bgcolor>
107 <bsbObject version="2" type="BSBLabel">
108 <objectName/>
109 <x>2</x>
110 <y>2</y>
111 <width>525</width>
112 <height>325</height>
113 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
114 <visible>true</visible>
115 <midichan>0</midichan>
116 <midicc>0</midicc>
117 <label>pconvolve</label>
118 <alignment>center</alignment>
119 <font>DejaVu Sans</font>
120 <fontsize>18</fontsize>
121 <precision>3</precision>
122 <color>
123 <r>0</r>
124 <g>0</g>
125 <b>0</b>
126 </color>
127 <bgcolor mode="background">
128 <r>244</r>
129 <g>248</g>
130 <b>200</b>
131 </bgcolor>
132 <bordermode>border</bordermode>
133 <borderradius>5</borderradius>
134 <borderwidth>2</borderwidth>
135 </bsbObject>
136 <bsbObject version="2" type="BSBButton">
137 <objectName>on</objectName>
138 <x>5</x>
139 <y>5</y>
140 <width>100</width>
141 <height>30</height>
142 <uuid>{487d5181-d838-4cce-9628-317fefc350cb}</uuid>
143 <visible>true</visible>
144 <midichan>0</midichan>
145 <midicc>0</midicc>
146 <type>value</type>
147 <pressedValue>1.00000000</pressedValue>
148 <stringvalue/>
149 <text> ON / OFF</text>
150 <image>/</image>
151 <eventLine>i 1 0 -1</eventLine>
152 <latch>true</latch>
153 <latched>false</latched>
154 </bsbObject>
155 <bsbObject version="2" type="BSBHSlider">
156 <objectName>Gain</objectName>
157 <x>13</x>
158 <y>58</y>
159 <width>500</width>
160 <height>27</height>
161 <uuid>{de47f47d-bcea-4c1c-ab4b-a323452b1f7e}</uuid>
162 <visible>true</visible>
163 <midichan>0</midichan>
164 <midicc>0</midicc>
165 <minimum>0.00000000</minimum>
166 <maximum>1.00000000</maximum>
167 <value>0.47200000</value>
168 <mode>lin</mode>
169 <mouseControl act="jump">continuous</mouseControl>
170 <resolution>-1.00000000</resolution>
171 <randomizable group="0">false</randomizable>
172 </bsbObject>
173 <bsbObject version="2" type="BSBLabel">
174 <objectName/>
175 <x>13</x>
176 <y>75</y>
177 <width>100</width>
178 <height>30</height>
179 <uuid>{0200a063-5db8-4668-bc2d-2d989a083f6e}</uuid>
180 <visible>true</visible>
181 <midichan>0</midichan>
182 <midicc>0</midicc>
183 <label>Gain</label>
184 <alignment>left</alignment>
185 <font>Arial</font>
186 <fontsize>10</fontsize>
187 <precision>3</precision>
188 <color>
189 <r>0</r>
190 <g>0</g>
191 <b>0</b>
192 </color>
193 <bgcolor mode="nobackground">
194 <r>255</r>
195 <g>255</g>
196 <b>255</b>
197 </bgcolor>
198 <bordermode>noborder</bordermode>
199 <borderradius>1</borderradius>
200 <borderwidth>1</borderwidth>
201 </bsbObject>
202 <bsbObject version="2" type="BSBDisplay">
203 <objectName>Gain</objectName>
204 <x>432</x>
205 <y>75</y>
206 <width>80</width>
207 <height>30</height>
208 <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
209 <visible>true</visible>
210 <midichan>0</midichan>
211 <midicc>0</midicc>
212 <label>0.472</label>
213 <alignment>right</alignment>
214 <font>Arial</font>
215 <fontsize>9</fontsize>
216 <precision>3</precision>
217 <color>
218 <r>0</r>
219 <g>0</g>
220 <b>0</b>
221 </color>
222 <bgcolor mode="nobackground">
223 <r>255</r>
224 <g>255</g>
225 <b>255</b>
226 </bgcolor>
227 <bordermode>noborder</bordermode>
228 <borderradius>1</borderradius>
229 <borderwidth>1</borderwidth>
230 </bsbObject>
231 <bsbObject version="2" type="BSBLabel">
232 <objectName/>
233 <x>528</x>
234 <y>2</y>
235 <width>439</width>
236 <height>323</height>
237 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
238 <visible>true</visible>
239 <midichan>0</midichan>
240 <midicc>0</midicc>
241 <label>pconvolve</label>
242 <alignment>center</alignment>
243 <font>DejaVu Sans</font>
244 <fontsize>18</fontsize>
245 <precision>3</precision>
246 <color>
247 <r>0</r>
248 <g>0</g>
249 <b>0</b>
250 </color>
251 <bgcolor mode="background">
252 <r>244</r>
253 <g>248</g>
254 <b>200</b>
255 </bgcolor>
256 <bordermode>border</bordermode>
257 <borderradius>5</borderradius>
258 <borderwidth>2</borderwidth>
259 </bsbObject>
260 <bsbObject version="2" type="BSBLabel">
261 <objectName/>
262 <x>528</x>
263 <y>16</y>
264 <width>433</width>
265 <height>300</height>
266 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
267 <visible>true</visible>
268 <midichan>0</midichan>
269 <midicc>0</midicc>
270 <label>----------------------------------------------------------------------------------------------------------------------------------------
271 pconvolve offers a computationally efficient method for performing convolution and is therefore ideally suited for real-time convolution reverbs. The input file for the convolution impulse is a sound file and is typically a short recording of the reverberant tail of of a sharp loud sound, sounding in the space.
272 The sounds used in these recordings is often a starting pistol or a balloon bursting. The aim is that all frequencies are present in the initial inpulse sound. For more accurate convolution a sine sweep is used but in this case further decoding is needed before the recording can be used. If too long an impulse sound is used the opcode will struggle to run in real-time as convolution is fundementally a computationally expensive procedure. Two user controls are included, 'Dry/Wet Mix' and 'Output Gain' (both dry and wet signals). There is no reason why the impulse file has to be that of a reverberant space. One of the options for 'Convolution File' in this example is a glass dish. Other possibilities might be vintage amplifiers and microphones.</label>
273 <alignment>left</alignment>
274 <font>Liberation Sans</font>
275 <fontsize>14</fontsize>
276 <precision>3</precision>
277 <color>
278 <r>0</r>
279 <g>0</g>
280 <b>0</b>
281 </color>
282 <bgcolor mode="nobackground">
283 <r>255</r>
284 <g>255</g>
285 <b>255</b>
286 </bgcolor>
287 <bordermode>noborder</bordermode>
288 <borderradius>1</borderradius>
289 <borderwidth>1</borderwidth>
290 </bsbObject>
291 <bsbObject version="2" type="BSBDisplay">
292 <objectName>Mix</objectName>
293 <x>433</x>
294 <y>114</y>
295 <width>80</width>
296 <height>30</height>
297 <uuid>{732b2008-7445-4893-a260-e68561cf8e71}</uuid>
298 <visible>true</visible>
299 <midichan>0</midichan>
300 <midicc>0</midicc>
301 <label>1.000</label>
302 <alignment>right</alignment>
303 <font>Arial</font>
304 <fontsize>9</fontsize>
305 <precision>3</precision>
306 <color>
307 <r>0</r>
308 <g>0</g>
309 <b>0</b>
310 </color>
311 <bgcolor mode="nobackground">
312 <r>255</r>
313 <g>255</g>
314 <b>255</b>
315 </bgcolor>
316 <bordermode>noborder</bordermode>
317 <borderradius>1</borderradius>
318 <borderwidth>1</borderwidth>
319 </bsbObject>
320 <bsbObject version="2" type="BSBLabel">
321 <objectName/>
322 <x>12</x>
323 <y>113</y>
324 <width>100</width>
325 <height>30</height>
326 <uuid>{b57ba536-8f28-4986-9bf7-8eb84262d8ca}</uuid>
327 <visible>true</visible>
328 <midichan>0</midichan>
329 <midicc>0</midicc>
330 <label>Dry / Wet Mix</label>
331 <alignment>left</alignment>
332 <font>Arial</font>
333 <fontsize>10</fontsize>
334 <precision>3</precision>
335 <color>
336 <r>0</r>
337 <g>0</g>
338 <b>0</b>
339 </color>
340 <bgcolor mode="nobackground">
341 <r>255</r>
342 <g>255</g>
343 <b>255</b>
344 </bgcolor>
345 <bordermode>noborder</bordermode>
346 <borderradius>1</borderradius>
347 <borderwidth>1</borderwidth>
348 </bsbObject>
349 <bsbObject version="2" type="BSBHSlider">
350 <objectName>Mix</objectName>
351 <x>12</x>
352 <y>96</y>
353 <width>500</width>
354 <height>27</height>
355 <uuid>{b8fa76b9-3d04-4156-a2f2-a413d3864da3}</uuid>
356 <visible>true</visible>
357 <midichan>0</midichan>
358 <midicc>0</midicc>
359 <minimum>0.00000000</minimum>
360 <maximum>1.00000000</maximum>
361 <value>1.00000000</value>
362 <mode>lin</mode>
363 <mouseControl act="jump">continuous</mouseControl>
364 <resolution>-1.00000000</resolution>
365 <randomizable group="0">false</randomizable>
366 </bsbObject>
367 <bsbObject version="2" type="BSBDropdown">
368 <objectName>Input</objectName>
369 <x>93</x>
370 <y>166</y>
371 <width>120</width>
372 <height>30</height>
373 <uuid>{9b81a1f2-bcb8-4582-925b-9ae56def3865}</uuid>
374 <visible>true</visible>
375 <midichan>0</midichan>
376 <midicc>0</midicc>
377 <bsbDropdownItemList>
378 <bsbDropdownItem>
379 <name>Audio File</name>
380 <value>0</value>
381 <stringvalue/>
382 </bsbDropdownItem>
383 <bsbDropdownItem>
384 <name> Live Input</name>
385 <value>1</value>
386 <stringvalue/>
387 </bsbDropdownItem>
388 </bsbDropdownItemList>
389 <selectedIndex>0</selectedIndex>
390 <randomizable group="0">false</randomizable>
391 </bsbObject>
392 <bsbObject version="2" type="BSBDropdown">
393 <objectName>File</objectName>
394 <x>365</x>
395 <y>166</y>
396 <width>120</width>
397 <height>30</height>
398 <uuid>{4f12eb6a-c071-4199-8bad-bfe11a917032}</uuid>
399 <visible>true</visible>
400 <midichan>0</midichan>
401 <midicc>0</midicc>
402 <bsbDropdownItemList>
403 <bsbDropdownItem>
404 <name>Stairwell</name>
405 <value>0</value>
406 <stringvalue/>
407 </bsbDropdownItem>
408 <bsbDropdownItem>
409 <name>Dish</name>
410 <value>1</value>
411 <stringvalue/>
412 </bsbDropdownItem>
413 <bsbDropdownItem>
414 <name>File</name>
415 <value>2</value>
416 <stringvalue/>
417 </bsbDropdownItem>
418 </bsbDropdownItemList>
419 <selectedIndex>2</selectedIndex>
420 <randomizable group="0">false</randomizable>
421 </bsbObject>
422 <bsbObject version="2" type="BSBLabel">
423 <objectName/>
424 <x>12</x>
425 <y>166</y>
426 <width>80</width>
427 <height>30</height>
428 <uuid>{62eeb695-9b83-42da-81cd-8000c232d9b9}</uuid>
429 <visible>true</visible>
430 <midichan>0</midichan>
431 <midicc>0</midicc>
432 <label>Input</label>
433 <alignment>right</alignment>
434 <font>Arial</font>
435 <fontsize>10</fontsize>
436 <precision>3</precision>
437 <color>
438 <r>0</r>
439 <g>0</g>
440 <b>0</b>
441 </color>
442 <bgcolor mode="nobackground">
443 <r>255</r>
444 <g>255</g>
445 <b>255</b>
446 </bgcolor>
447 <bordermode>noborder</bordermode>
448 <borderradius>1</borderradius>
449 <borderwidth>1</borderwidth>
450 </bsbObject>
451 <bsbObject version="2" type="BSBLabel">
452 <objectName/>
453 <x>264</x>
454 <y>166</y>
455 <width>100</width>
456 <height>30</height>
457 <uuid>{f0042687-944f-4ab5-a258-074f2aca5510}</uuid>
458 <visible>true</visible>
459 <midichan>0</midichan>
460 <midicc>0</midicc>
461 <label>Convolution file</label>
462 <alignment>right</alignment>
463 <font>Arial</font>
464 <fontsize>10</fontsize>
465 <precision>3</precision>
466 <color>
467 <r>0</r>
468 <g>0</g>
469 <b>0</b>
470 </color>
471 <bgcolor mode="nobackground">
472 <r>255</r>
473 <g>255</g>
474 <b>255</b>
475 </bgcolor>
476 <bordermode>noborder</bordermode>
477 <borderradius>1</borderradius>
478 <borderwidth>1</borderwidth>
479 </bsbObject>
480 <bsbObject version="2" type="BSBButton">
481 <objectName>_Browse1</objectName>
482 <x>6</x>
483 <y>218</y>
484 <width>170</width>
485 <height>30</height>
486 <uuid>{83beaac6-3457-44f5-befb-b2f51175fa55}</uuid>
487 <visible>true</visible>
488 <midichan>0</midichan>
489 <midicc>0</midicc>
490 <type>value</type>
491 <pressedValue>1.00000000</pressedValue>
492 <stringvalue>808loop.wav</stringvalue>
493 <text>Browse Audio File</text>
494 <image>/</image>
495 <eventLine/>
496 <latch>false</latch>
497 <latched>false</latched>
498 </bsbObject>
499 <bsbObject version="2" type="BSBLineEdit">
500 <objectName>_Browse1</objectName>
501 <x>177</x>
502 <y>219</y>
503 <width>330</width>
504 <height>28</height>
505 <uuid>{b2716d73-fb2d-45af-8ce0-404d5e48d00d}</uuid>
506 <visible>true</visible>
507 <midichan>0</midichan>
508 <midicc>0</midicc>
509 <label>808loop.wav</label>
510 <alignment>left</alignment>
511 <font>Arial</font>
512 <fontsize>10</fontsize>
513 <precision>3</precision>
514 <color>
515 <r>0</r>
516 <g>0</g>
517 <b>0</b>
518 </color>
519 <bgcolor mode="nobackground">
520 <r>206</r>
521 <g>206</g>
522 <b>206</b>
523 </bgcolor>
524 <background>nobackground</background>
525 </bsbObject>
526 <bsbObject version="2" type="BSBLabel">
527 <objectName/>
528 <x>177</x>
529 <y>246</y>
530 <width>330</width>
531 <height>30</height>
532 <uuid>{a63909ac-6fa4-41c8-a84b-ba08e76132ab}</uuid>
533 <visible>true</visible>
534 <midichan>0</midichan>
535 <midicc>0</midicc>
536 <label>Restart the instrument after changing the audio file.</label>
537 <alignment>left</alignment>
538 <font>Liberation Sans</font>
539 <fontsize>12</fontsize>
540 <precision>3</precision>
541 <color>
542 <r>0</r>
543 <g>0</g>
544 <b>0</b>
545 </color>
546 <bgcolor mode="nobackground">
547 <r>255</r>
548 <g>255</g>
549 <b>255</b>
550 </bgcolor>
551 <bordermode>noborder</bordermode>
552 <borderradius>1</borderradius>
553 <borderwidth>1</borderwidth>
554 </bsbObject>
555 <bsbObject version="2" type="BSBButton">
556 <objectName>_Browse2</objectName>
557 <x>7</x>
558 <y>278</y>
559 <width>170</width>
560 <height>30</height>
561 <uuid>{181e4355-4514-4f64-90ad-846857e32fc3}</uuid>
562 <visible>true</visible>
563 <midichan>0</midichan>
564 <midicc>0</midicc>
565 <type>value</type>
566 <pressedValue>1.00000000</pressedValue>
567 <stringvalue>/home/andres/Desktop/convolution/EMT 244 (A. Bernhard)/4,5s High_2.wav</stringvalue>
568 <text>Browse IR File</text>
569 <image>/</image>
570 <eventLine/>
571 <latch>false</latch>
572 <latched>false</latched>
573 </bsbObject>
574 <bsbObject version="2" type="BSBLineEdit">
575 <objectName>_Browse2</objectName>
576 <x>178</x>
577 <y>279</y>
578 <width>330</width>
579 <height>28</height>
580 <uuid>{c8be82af-1985-49e4-ba13-2927447697c6}</uuid>
581 <visible>true</visible>
582 <midichan>0</midichan>
583 <midicc>0</midicc>
584 <label>/home/andres/Desktop/convolution/EMT 244 (A. Bernhard)/4,5s High_2.wav</label>
585 <alignment>left</alignment>
586 <font>Arial</font>
587 <fontsize>10</fontsize>
588 <precision>3</precision>
589 <color>
590 <r>0</r>
591 <g>0</g>
592 <b>0</b>
593 </color>
594 <bgcolor mode="nobackground">
595 <r>206</r>
596 <g>206</g>
597 <b>206</b>
598 </bgcolor>
599 <background>nobackground</background>
600 </bsbObject>
601 </bsbPanel>
602 <bsbPresets>
603 </bsbPresets>