Debian Codegraph @

src/Examples/CsoundQt/Miscellaneous/Simple_Convolution.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 --env:SSDIR+=../../SourceMaterials
4 </CsOptions>
5 <CsInstruments>
6
7 sr = 44100
8 ksmps = 32
9 nchnls = 2
10 0dbfs = 1
11
12 /*****Simple convolution*****/
13 ;example for CsoundQt
14 ;written by joachim heintz
15 ;apr 2009 / jan 2022 / jan 2024
16 ;using the code from matt ingalls (manual for pconvolve)
17 ;please send bug reports and suggestions
18 ;to jh at joachimheintz.de
19
20 //output display in CsoundQt
21 opcode CsQtMeter, 0, SSak
22 S_chan_sig, S_chan_over, aSig, kTrig xin
23 iDbRange = 60 ;shows 60 dB
24 iHoldTim = 1 ;seconds to "hold the red light"
25 kOn init 0
26 kTim init 0
27 kStart init 0
28 kEnd init 0
29 kMax max_k aSig, kTrig, 1
30 if kTrig == 1 then
31 chnset (iDbRange + dbfsamp(kMax)) / iDbRange, S_chan_sig
32 if kOn == 0 && kMax > 1 then
33 kTim = 0
34 kEnd = iHoldTim
35 chnset 1, S_chan_over
36 kOn = 1
37 endif
38 if kOn == 1 && kTim > kEnd then
39 chnset 0, S_chan_over
40 kOn = 0
41 endif
42 endif
43 kTim += ksmps/sr
44 endop
45
46 opcode SimpConv,aa,SSPVPooo
47 Sfile,Sir,kAmp,kWDmix,kSpeed,iSkip,iLoop,iPartSize xin
48 iPartSize = (iPartSize == 0) ? 2048 : iPartSize
49 iDel = (ksmps < iPartSize ? iPartSize + ksmps : iPartSize) / sr
50 // sound file mono or stereo
51 if (filenchnls(Sfile) == 1) then
52 aSndL diskin Sfile,kSpeed,iSkip,iLoop
53 aSndR = aSndL
54 else
55 aSndL,aSndR diskin Sfile,kSpeed,iSkip,iLoop
56 endif
57 if (filenchnls(Sir) == 1) then ;impulsefile mono
58 aWetL pconvolve aSndL,Sir,iPartSize,1
59 aWetR pconvolve aSndR,Sir,iPartSize,1
60 else ;impulsefile stereo
61 aWetL pconvolve aSndL,Sir,iPartSize,1
62 aWetR pconvolve aSndR,Sir,iPartSize,2
63 endif
64 aDryL = delay:a(aSndL,iDel)
65 aDryR = delay:a(aSndR,iDel)
66 aMixL = ntrpol:a(aDryL,aWetL,kWDmix)
67 aMixR = ntrpol:a(aDryR,aWetR,kWDmix)
68 xout(aMixL*kAmp,aMixR*kAmp)
69 endop
70
71
72 ;declare software channels
73 chn_k "outL", 2
74 chn_k "outL_clip", 2
75 chn_k "outR", 2
76 chn_k "outR_clip", 2
77 chn_S "_Browse1", 1
78 chn_S "_Browse2", 1
79 chn_k "wdmix", 1
80 chn_k "gaindb", 1
81
82
83 instr Conv
84
85 // input
86 Sfile = chnget:S("_Browse1")
87 Simpulse = chnget:S("_Browse2")
88 kWdMix = chnget:k("wdmix")
89 kGainDb = chnget:k("gaindb")
90 kGain = ampdb(kGainDb)
91 p3 = filelen(Sfile) + filelen(Simpulse) + 1
92
93 // convolution
94 aL,aR SimpConv Sfile,Simpulse,kGain,kWdMix
95 out(aL,aR)
96
97 //show signal
98 kTrigDisp metro 10
99 CsQtMeter "outL", "outL_over", aL, kTrigDisp
100 CsQtMeter "outR", "outR_over", aR, kTrigDisp
101
102 endin
103
104 </CsInstruments>
105 <CsScore>
106 i 1 0 1; plays the whole soundfile
107 </CsScore>
108 </CsoundSynthesizer>
109 <bsbPanel>
110 <label>Widgets</label>
111 <objectName/>
112 <x>829</x>
113 <y>212</y>
114 <width>460</width>
115 <height>389</height>
116 <visible>true</visible>
117 <uuid/>
118 <bgcolor mode="background">
119 <r>170</r>
120 <g>170</g>
121 <b>127</b>
122 </bgcolor>
123 <bsbObject version="2" type="BSBLineEdit">
124 <objectName>_Browse1</objectName>
125 <x>13</x>
126 <y>107</y>
127 <width>387</width>
128 <height>25</height>
129 <uuid>{bdb69a5f-4670-41f7-b175-539bc300af19}</uuid>
130 <visible>true</visible>
131 <midichan>0</midichan>
132 <midicc>-3</midicc>
133 <description/>
134 <label>fox.wav</label>
135 <alignment>left</alignment>
136 <font>Bitstream Vera Sans</font>
137 <fontsize>14</fontsize>
138 <precision>3</precision>
139 <color>
140 <r>0</r>
141 <g>0</g>
142 <b>0</b>
143 </color>
144 <bgcolor mode="nobackground">
145 <r>239</r>
146 <g>239</g>
147 <b>239</b>
148 </bgcolor>
149 <background>nobackground</background>
150 </bsbObject>
151 <bsbObject version="2" type="BSBButton">
152 <objectName>_Browse1</objectName>
153 <x>98</x>
154 <y>73</y>
155 <width>226</width>
156 <height>29</height>
157 <uuid>{ea11a81d-0041-46eb-8d6c-cb10f732f6ff}</uuid>
158 <visible>true</visible>
159 <midichan>0</midichan>
160 <midicc>-3</midicc>
161 <description/>
162 <type>value</type>
163 <pressedValue>1.00000000</pressedValue>
164 <stringvalue>fox.wav</stringvalue>
165 <text>Browse Soundfile</text>
166 <image>/</image>
167 <eventLine/>
168 <latch>false</latch>
169 <momentaryMidiButton>false</momentaryMidiButton>
170 <latched>false</latched>
171 <fontsize>10</fontsize>
172 </bsbObject>
173 <bsbObject version="2" type="BSBLabel">
174 <objectName/>
175 <x>17</x>
176 <y>19</y>
177 <width>398</width>
178 <height>43</height>
179 <uuid>{612a67ea-cd5d-4277-a43a-5528190eca4d}</uuid>
180 <visible>true</visible>
181 <midichan>0</midichan>
182 <midicc>-3</midicc>
183 <description/>
184 <label>SIMPLE CONVOLUTION</label>
185 <alignment>center</alignment>
186 <valignment>top</valignment>
187 <font>Lucida Grande</font>
188 <fontsize>26</fontsize>
189 <precision>3</precision>
190 <color>
191 <r>0</r>
192 <g>0</g>
193 <b>0</b>
194 </color>
195 <bgcolor mode="nobackground">
196 <r>255</r>
197 <g>255</g>
198 <b>255</b>
199 </bgcolor>
200 <bordermode>noborder</bordermode>
201 <borderradius>1</borderradius>
202 <borderwidth>0</borderwidth>
203 </bsbObject>
204 <bsbObject version="2" type="BSBLineEdit">
205 <objectName>_Browse2</objectName>
206 <x>14</x>
207 <y>178</y>
208 <width>387</width>
209 <height>25</height>
210 <uuid>{1fc9a97c-9593-4cc3-92d9-53cc3eaa15d6}</uuid>
211 <visible>true</visible>
212 <midichan>0</midichan>
213 <midicc>-3</midicc>
214 <description/>
215 <label>impulse_big_hall.wav</label>
216 <alignment>left</alignment>
217 <font>Bitstream Vera Sans</font>
218 <fontsize>14</fontsize>
219 <precision>3</precision>
220 <color>
221 <r>0</r>
222 <g>0</g>
223 <b>0</b>
224 </color>
225 <bgcolor mode="nobackground">
226 <r>239</r>
227 <g>239</g>
228 <b>239</b>
229 </bgcolor>
230 <background>nobackground</background>
231 </bsbObject>
232 <bsbObject version="2" type="BSBButton">
233 <objectName>_Browse2</objectName>
234 <x>99</x>
235 <y>140</y>
236 <width>229</width>
237 <height>31</height>
238 <uuid>{9024b704-1968-4308-a103-455699b9ffb6}</uuid>
239 <visible>true</visible>
240 <midichan>0</midichan>
241 <midicc>-3</midicc>
242 <description/>
243 <type>value</type>
244 <pressedValue>1.00000000</pressedValue>
245 <stringvalue>impulse_big_hall.wav</stringvalue>
246 <text>Browse Impulse Response File</text>
247 <image>/</image>
248 <eventLine/>
249 <latch>false</latch>
250 <momentaryMidiButton>false</momentaryMidiButton>
251 <latched>false</latched>
252 <fontsize>10</fontsize>
253 </bsbObject>
254 <bsbObject version="2" type="BSBHSlider">
255 <objectName>wdmix</objectName>
256 <x>67</x>
257 <y>253</y>
258 <width>282</width>
259 <height>29</height>
260 <uuid>{70d19d35-4ef8-49be-834d-610194e347bb}</uuid>
261 <visible>true</visible>
262 <midichan>0</midichan>
263 <midicc>-3</midicc>
264 <description/>
265 <minimum>0.00000000</minimum>
266 <maximum>1.00000000</maximum>
267 <value>0.58156028</value>
268 <mode>lin</mode>
269 <mouseControl act="jump">continuous</mouseControl>
270 <resolution>-1.00000000</resolution>
271 <randomizable group="0">false</randomizable>
272 </bsbObject>
273 <bsbObject version="2" type="BSBLabel">
274 <objectName/>
275 <x>145</x>
276 <y>215</y>
277 <width>130</width>
278 <height>30</height>
279 <uuid>{7826f399-c364-4e8f-9adc-e86168c42052}</uuid>
280 <visible>true</visible>
281 <midichan>0</midichan>
282 <midicc>-3</midicc>
283 <description/>
284 <label>Wet-Dry Mix</label>
285 <alignment>center</alignment>
286 <valignment>top</valignment>
287 <font>DejaVu Sans</font>
288 <fontsize>14</fontsize>
289 <precision>3</precision>
290 <color>
291 <r>0</r>
292 <g>0</g>
293 <b>0</b>
294 </color>
295 <bgcolor mode="nobackground">
296 <r>255</r>
297 <g>255</g>
298 <b>255</b>
299 </bgcolor>
300 <bordermode>noborder</bordermode>
301 <borderradius>1</borderradius>
302 <borderwidth>0</borderwidth>
303 </bsbObject>
304 <bsbObject version="2" type="BSBLabel">
305 <objectName/>
306 <x>27</x>
307 <y>253</y>
308 <width>34</width>
309 <height>27</height>
310 <uuid>{173448ab-eeab-471d-b461-fbb89d17b4ad}</uuid>
311 <visible>true</visible>
312 <midichan>0</midichan>
313 <midicc>-3</midicc>
314 <description/>
315 <label>Dry</label>
316 <alignment>left</alignment>
317 <valignment>top</valignment>
318 <font>Lucida Grande</font>
319 <fontsize>12</fontsize>
320 <precision>3</precision>
321 <color>
322 <r>0</r>
323 <g>0</g>
324 <b>0</b>
325 </color>
326 <bgcolor mode="nobackground">
327 <r>255</r>
328 <g>255</g>
329 <b>255</b>
330 </bgcolor>
331 <bordermode>noborder</bordermode>
332 <borderradius>1</borderradius>
333 <borderwidth>0</borderwidth>
334 </bsbObject>
335 <bsbObject version="2" type="BSBLabel">
336 <objectName/>
337 <x>356</x>
338 <y>254</y>
339 <width>34</width>
340 <height>27</height>
341 <uuid>{9e0638ae-57cf-415f-8cf2-de5b6dfd4eb5}</uuid>
342 <visible>true</visible>
343 <midichan>0</midichan>
344 <midicc>-3</midicc>
345 <description/>
346 <label>Wet</label>
347 <alignment>left</alignment>
348 <valignment>top</valignment>
349 <font>Lucida Grande</font>
350 <fontsize>12</fontsize>
351 <precision>3</precision>
352 <color>
353 <r>0</r>
354 <g>0</g>
355 <b>0</b>
356 </color>
357 <bgcolor mode="nobackground">
358 <r>255</r>
359 <g>255</g>
360 <b>255</b>
361 </bgcolor>
362 <bordermode>noborder</bordermode>
363 <borderradius>1</borderradius>
364 <borderwidth>0</borderwidth>
365 </bsbObject>
366 <bsbObject version="2" type="BSBController">
367 <objectName>outL</objectName>
368 <x>2</x>
369 <y>289</y>
370 <width>225</width>
371 <height>20</height>
372 <uuid>{56692e84-8339-4713-bedf-b81a5d5dea6b}</uuid>
373 <visible>true</visible>
374 <midichan>0</midichan>
375 <midicc>0</midicc>
376 <description/>
377 <objectName2>outL</objectName2>
378 <xMin>0.00000000</xMin>
379 <xMax>1.00000000</xMax>
380 <yMin>0.00000000</yMin>
381 <yMax>1.00000000</yMax>
382 <xValue>-inf</xValue>
383 <yValue>-inf</yValue>
384 <type>fill</type>
385 <pointsize>1</pointsize>
386 <fadeSpeed>0.00000000</fadeSpeed>
387 <mouseControl act="press">jump</mouseControl>
388 <bordermode>noborder</bordermode>
389 <borderColor>#00FF00</borderColor>
390 <color>
391 <r>0</r>
392 <g>234</g>
393 <b>0</b>
394 </color>
395 <randomizable group="0" mode="both">false</randomizable>
396 <bgcolor>
397 <r>0</r>
398 <g>0</g>
399 <b>0</b>
400 </bgcolor>
401 <bgcolormode>true</bgcolormode>
402 </bsbObject>
403 <bsbObject version="2" type="BSBController">
404 <objectName>outL_clip</objectName>
405 <x>221</x>
406 <y>289</y>
407 <width>25</width>
408 <height>20</height>
409 <uuid>{9dbc1525-61ed-4dcc-aeb3-650eb87744db}</uuid>
410 <visible>true</visible>
411 <midichan>0</midichan>
412 <midicc>0</midicc>
413 <description/>
414 <objectName2>outL_clip</objectName2>
415 <xMin>0.00000000</xMin>
416 <xMax>1.00000000</xMax>
417 <yMin>0.00000000</yMin>
418 <yMax>1.00000000</yMax>
419 <xValue>0.00000000</xValue>
420 <yValue>0.00000000</yValue>
421 <type>fill</type>
422 <pointsize>1</pointsize>
423 <fadeSpeed>0.00000000</fadeSpeed>
424 <mouseControl act="press">jump</mouseControl>
425 <bordermode>noborder</bordermode>
426 <borderColor>#00ff00</borderColor>
427 <color>
428 <r>196</r>
429 <g>14</g>
430 <b>12</b>
431 </color>
432 <randomizable group="0" mode="both">false</randomizable>
433 <bgcolor>
434 <r>0</r>
435 <g>0</g>
436 <b>0</b>
437 </bgcolor>
438 <bgcolormode>true</bgcolormode>
439 </bsbObject>
440 <bsbObject version="2" type="BSBController">
441 <objectName>outR</objectName>
442 <x>2</x>
443 <y>315</y>
444 <width>225</width>
445 <height>20</height>
446 <uuid>{09a3dabb-c32b-4652-b07c-a5149e90b11b}</uuid>
447 <visible>true</visible>
448 <midichan>0</midichan>
449 <midicc>0</midicc>
450 <description/>
451 <objectName2>outR</objectName2>
452 <xMin>0.00000000</xMin>
453 <xMax>1.00000000</xMax>
454 <yMin>0.00000000</yMin>
455 <yMax>1.00000000</yMax>
456 <xValue>-inf</xValue>
457 <yValue>-inf</yValue>
458 <type>fill</type>
459 <pointsize>1</pointsize>
460 <fadeSpeed>0.00000000</fadeSpeed>
461 <mouseControl act="press">jump</mouseControl>
462 <bordermode>noborder</bordermode>
463 <borderColor>#00FF00</borderColor>
464 <color>
465 <r>0</r>
466 <g>234</g>
467 <b>0</b>
468 </color>
469 <randomizable group="0" mode="both">false</randomizable>
470 <bgcolor>
471 <r>0</r>
472 <g>0</g>
473 <b>0</b>
474 </bgcolor>
475 <bgcolormode>true</bgcolormode>
476 </bsbObject>
477 <bsbObject version="2" type="BSBController">
478 <objectName>outR_clip</objectName>
479 <x>221</x>
480 <y>315</y>
481 <width>25</width>
482 <height>20</height>
483 <uuid>{d515ef65-7c19-46c4-a888-c5cbc4e5653c}</uuid>
484 <visible>true</visible>
485 <midichan>0</midichan>
486 <midicc>0</midicc>
487 <description/>
488 <objectName2>outR_clip</objectName2>
489 <xMin>0.00000000</xMin>
490 <xMax>1.00000000</xMax>
491 <yMin>0.00000000</yMin>
492 <yMax>1.00000000</yMax>
493 <xValue>0.00000000</xValue>
494 <yValue>0.00000000</yValue>
495 <type>fill</type>
496 <pointsize>1</pointsize>
497 <fadeSpeed>0.00000000</fadeSpeed>
498 <mouseControl act="press">jump</mouseControl>
499 <bordermode>noborder</bordermode>
500 <borderColor>#00ff00</borderColor>
501 <color>
502 <r>196</r>
503 <g>14</g>
504 <b>12</b>
505 </color>
506 <randomizable group="0" mode="both">false</randomizable>
507 <bgcolor>
508 <r>0</r>
509 <g>0</g>
510 <b>0</b>
511 </bgcolor>
512 <bgcolormode>true</bgcolormode>
513 </bsbObject>
514 <bsbObject version="2" type="BSBHSlider">
515 <objectName>gaindb</objectName>
516 <x>258</x>
517 <y>313</y>
518 <width>176</width>
519 <height>24</height>
520 <uuid>{4d42ff3b-ba28-463f-aaf0-ef8905f4facc}</uuid>
521 <visible>true</visible>
522 <midichan>0</midichan>
523 <midicc>0</midicc>
524 <description/>
525 <minimum>-30.00000000</minimum>
526 <maximum>0.00000000</maximum>
527 <value>-14.14772727</value>
528 <mode>lin</mode>
529 <mouseControl act="jump">continuous</mouseControl>
530 <resolution>-1.00000000</resolution>
531 <randomizable group="0">false</randomizable>
532 </bsbObject>
533 <bsbObject version="2" type="BSBLabel">
534 <objectName/>
535 <x>258</x>
536 <y>286</y>
537 <width>45</width>
538 <height>26</height>
539 <uuid>{eccfbfa8-ba49-4ac2-94c3-9d70d1db6028}</uuid>
540 <visible>true</visible>
541 <midichan>0</midichan>
542 <midicc>0</midicc>
543 <description/>
544 <label>Gain</label>
545 <alignment>right</alignment>
546 <valignment>top</valignment>
547 <font>Arial</font>
548 <fontsize>14</fontsize>
549 <precision>3</precision>
550 <color>
551 <r>0</r>
552 <g>0</g>
553 <b>0</b>
554 </color>
555 <bgcolor mode="nobackground">
556 <r>255</r>
557 <g>255</g>
558 <b>255</b>
559 </bgcolor>
560 <bordermode>noborder</bordermode>
561 <borderradius>1</borderradius>
562 <borderwidth>0</borderwidth>
563 </bsbObject>
564 <bsbObject version="2" type="BSBLabel">
565 <objectName/>
566 <x>388</x>
567 <y>285</y>
568 <width>45</width>
569 <height>26</height>
570 <uuid>{8b5b92dc-f58e-406e-8262-b117e1a70803}</uuid>
571 <visible>true</visible>
572 <midichan>0</midichan>
573 <midicc>0</midicc>
574 <description/>
575 <label>dB</label>
576 <alignment>left</alignment>
577 <valignment>top</valignment>
578 <font>Arial</font>
579 <fontsize>14</fontsize>
580 <precision>3</precision>
581 <color>
582 <r>0</r>
583 <g>0</g>
584 <b>0</b>
585 </color>
586 <bgcolor mode="nobackground">
587 <r>255</r>
588 <g>255</g>
589 <b>255</b>
590 </bgcolor>
591 <bordermode>noborder</bordermode>
592 <borderradius>1</borderradius>
593 <borderwidth>0</borderwidth>
594 </bsbObject>
595 <bsbObject version="2" type="BSBDisplay">
596 <objectName>gaindb</objectName>
597 <x>305</x>
598 <y>286</y>
599 <width>80</width>
600 <height>25</height>
601 <uuid>{126c55f6-ba72-4d42-a3f5-7bf36e0a8269}</uuid>
602 <visible>true</visible>
603 <midichan>0</midichan>
604 <midicc>0</midicc>
605 <description/>
606 <label>-14.148</label>
607 <alignment>right</alignment>
608 <valignment>top</valignment>
609 <font>Arial</font>
610 <fontsize>14</fontsize>
611 <precision>3</precision>
612 <color>
613 <r>0</r>
614 <g>0</g>
615 <b>0</b>
616 </color>
617 <bgcolor mode="nobackground">
618 <r>255</r>
619 <g>255</g>
620 <b>255</b>
621 </bgcolor>
622 <bordermode>noborder</bordermode>
623 <borderradius>1</borderradius>
624 <borderwidth>0</borderwidth>
625 </bsbObject>
626 </bsbPanel>
627 <bsbPresets>
628 </bsbPresets>