Debian Codegraph @

src/Examples/McCurdy Collection/Waveguides/streson.csd

raw
1 ;Written by Iain McCurdy, 2006
2
3
4 ;Modified for QuteCsound by René, April 2011
5 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
6
7 ;Notes on modifications from original csd:
8 ; Add table(s) for exp slider
9 ; Add Browser for audio file and use of FilePlay2 udo, now accept mono or stereo wav files
10
11
12 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
13 <CsoundSynthesizer>
14 <CsOptions>
15 --env:SSDIR+=../../SourceMaterials
16 </CsOptions>
17 <CsInstruments>
18 sr = 44100 ;SAMPLE RATE
19 ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
20 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
21 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
22
23
24 giExp1 ftgen 0, 0, 129, -25, 0, 20.0, 128, 10000.0 ;TABLE FOR EXP SLIDER
25
26
27 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz
28 ;gives stereo output regardless your soundfile is mono or stereo
29 Sfil, kspeed, iskip, iloop xin
30 ichn filenchnls Sfil
31 if ichn == 1 then
32 aL diskin2 Sfil, kspeed, iskip, iloop
33 aR = aL
34 else
35 aL, aR diskin2 Sfil, kspeed, iskip, iloop
36 endif
37 xout aL, aR
38 endop
39
40 instr 1 ;GUI & INPUT
41 ;GUI
42 ktrig metro 10
43 if (ktrig == 1) then
44 kingain invalue "InputGain"
45 kfr invalue "Frequency"
46 gkfr tablei kfr, giExp1, 1
47 outvalue "Frequency_Value", gkfr
48 gkfdbgain invalue "Feedback"
49 gkamp invalue "Amplitude"
50 kinput invalue "Input"
51
52 Sfile_new strcpy "" ;INIT TO EMPTY STRING
53 Sfile invalue "_Browse"
54 Sfile_old strcpyk Sfile_new
55 Sfile_new strcpyk Sfile
56 kfile strcmpk Sfile_new, Sfile_old
57 endif
58 ;INPUT
59 if kinput==0 then ;IF INPUT 'Audio File' IS SELECTED...
60 kNew_file changed kfile ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
61 if kNew_file=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
62 reinit NEW_FILE ;BEGIN A REINITIALISATION PASS FROM LABEL 'NEW_FILE'
63 endif
64 NEW_FILE:
65 gasigL, gasigR FilePlay2 Sfile, 1, 0, 1 ;GENERATE 2 AUDIO SIGNALS FROM A SOUND FILE
66 rireturn
67 elseif kinput==1 then ;IF INPUT 'Live' IS SELECTED...
68 asigL, asigR ins ;TAKE INPUT FROM COMPUTER'S AUDIO INPUT
69 gasigL = asigL * kingain ;SCALE USING 'Input Gain' SLIDER
70 gasigR = asigR * kingain ;SCALE USING 'Input Gain' SLIDER
71 else ;OTHERWISE...
72 kint random 0.1,0.4 ;INTERVAL BETWEEN IMPULSES IS RANDOMISED SLIGHTLY
73 a1 mpulse 4,kint ;GENERATE IMPULSES
74 kcfoct randomi 6,12,2 ;GENERATE RANDOM VALUES FOR FILTER CUTOFF FREQUENCY (OCT FORMAT)
75 gasigL butlp a1, cpsoct(kcfoct) ;LOWPASS FILTER STREAM OF CLICKS
76 gasigR = gasigL ;SET RIGHT CHANNEL SIGNAL TO THE SAME AS THE LEFT CHANNEL SIGNAL
77 endif
78 endin
79
80 instr 2
81 kSwitch changed gkfdbgain ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
82 if kSwitch=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
83 reinit UPDATE ;BEGIN A REINITIALISATION PASS FROM LABEL 'UPDATE'
84 endif
85 UPDATE:
86 aresL streson gasigL, gkfr, i(gkfdbgain)
87 aresR streson gasigR, gkfr, i(gkfdbgain)
88 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
89 outs aresL * gkamp, aresR * gkamp ;SEND streson OUTPUT TO THE AUDIO OUTPUTS AND SCALE USING THE GUI SLIDER VARIABLE gkamp
90 clear gasigL, gasigR ;CLEAR GLOBAL AUDIO VARIABLES
91 endin
92 </CsInstruments>
93 <CsScore>
94 i 1 0 3600 ;GUI
95 </CsScore>
96 </CsoundSynthesizer>
97
98
99 <bsbPanel>
100 <label>Widgets</label>
101 <objectName/>
102 <x>72</x>
103 <y>179</y>
104 <width>1027</width>
105 <height>397</height>
106 <visible>true</visible>
107 <uuid/>
108 <bgcolor mode="background">
109 <r>241</r>
110 <g>226</g>
111 <b>185</b>
112 </bgcolor>
113 <bsbObject version="2" type="BSBLabel">
114 <objectName/>
115 <x>2</x>
116 <y>2</y>
117 <width>510</width>
118 <height>350</height>
119 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
120 <visible>true</visible>
121 <midichan>0</midichan>
122 <midicc>0</midicc>
123 <label>streson</label>
124 <alignment>center</alignment>
125 <font>Liberation Sans</font>
126 <fontsize>18</fontsize>
127 <precision>3</precision>
128 <color>
129 <r>0</r>
130 <g>0</g>
131 <b>0</b>
132 </color>
133 <bgcolor mode="background">
134 <r>170</r>
135 <g>170</g>
136 <b>170</b>
137 </bgcolor>
138 <bordermode>border</bordermode>
139 <borderradius>5</borderradius>
140 <borderwidth>2</borderwidth>
141 </bsbObject>
142 <bsbObject version="2" type="BSBLabel">
143 <objectName/>
144 <x>8</x>
145 <y>78</y>
146 <width>220</width>
147 <height>30</height>
148 <uuid>{640b50b7-7200-4f81-8394-89d9843ae939}</uuid>
149 <visible>true</visible>
150 <midichan>0</midichan>
151 <midicc>0</midicc>
152 <label>Live Input Gain</label>
153 <alignment>left</alignment>
154 <font>Liberation Sans</font>
155 <fontsize>10</fontsize>
156 <precision>3</precision>
157 <color>
158 <r>0</r>
159 <g>0</g>
160 <b>0</b>
161 </color>
162 <bgcolor mode="nobackground">
163 <r>255</r>
164 <g>255</g>
165 <b>255</b>
166 </bgcolor>
167 <bordermode>noborder</bordermode>
168 <borderradius>1</borderradius>
169 <borderwidth>1</borderwidth>
170 </bsbObject>
171 <bsbObject version="2" type="BSBHSlider">
172 <objectName>InputGain</objectName>
173 <x>8</x>
174 <y>56</y>
175 <width>500</width>
176 <height>27</height>
177 <uuid>{5585fa6f-0f63-4ac3-bf1b-809c2b1d9134}</uuid>
178 <visible>true</visible>
179 <midichan>0</midichan>
180 <midicc>0</midicc>
181 <minimum>0.00000000</minimum>
182 <maximum>1.00000000</maximum>
183 <value>0.59200000</value>
184 <mode>lin</mode>
185 <mouseControl act="jump">continuous</mouseControl>
186 <resolution>-1.00000000</resolution>
187 <randomizable group="0">false</randomizable>
188 </bsbObject>
189 <bsbObject version="2" type="BSBButton">
190 <objectName/>
191 <x>8</x>
192 <y>20</y>
193 <width>80</width>
194 <height>26</height>
195 <uuid>{04d44ebe-12eb-4bb0-a3f5-9e4fd3e7830e}</uuid>
196 <visible>true</visible>
197 <midichan>0</midichan>
198 <midicc>0</midicc>
199 <type>event</type>
200 <pressedValue>1.00000000</pressedValue>
201 <stringvalue/>
202 <text> On / Off</text>
203 <image>/</image>
204 <eventLine>i 2 0 -1</eventLine>
205 <latch>true</latch>
206 <latched>false</latched>
207 </bsbObject>
208 <bsbObject version="2" type="BSBLabel">
209 <objectName/>
210 <x>514</x>
211 <y>2</y>
212 <width>500</width>
213 <height>350</height>
214 <uuid>{cd1b9ee0-e607-49ed-9a8d-37ebb3d7fe8f}</uuid>
215 <visible>true</visible>
216 <midichan>0</midichan>
217 <midicc>0</midicc>
218 <label>streson</label>
219 <alignment>center</alignment>
220 <font>Liberation Sans</font>
221 <fontsize>18</fontsize>
222 <precision>3</precision>
223 <color>
224 <r>0</r>
225 <g>0</g>
226 <b>0</b>
227 </color>
228 <bgcolor mode="background">
229 <r>170</r>
230 <g>170</g>
231 <b>170</b>
232 </bgcolor>
233 <bordermode>border</bordermode>
234 <borderradius>5</borderradius>
235 <borderwidth>2</borderwidth>
236 </bsbObject>
237 <bsbObject version="2" type="BSBLabel">
238 <objectName/>
239 <x>517</x>
240 <y>18</y>
241 <width>493</width>
242 <height>331</height>
243 <uuid>{16d3e28c-026e-45ef-b167-57f393c4e2d5}</uuid>
244 <visible>true</visible>
245 <midichan>0</midichan>
246 <midicc>0</midicc>
247 <label>-------------------------------------------------------------------------------------------------------------------------
248 Streson implements a sympathetic string resonating-type filter using comb, lowpass and allpass filter in an algorithm similar to that of the Karplus-Strong plucked string model. Streson's audible output is similar to that of the 'wguide1' opcode. One difference is that 'Feedback' is variable only at i-rate in streson. 'Feedback' is expressed as a ratio of the entire signal. A value of 0 means that none of the signal will be fed back into the system, a value of 1 means that all of the signal will be fed back into the system. The use of feedback can create dramatic rises in output amplitude, therefore in this example I have included a slider that controls output amplitude.
249 Note that tuning inaccuracies are increasingly exhibited as 'Frequency' is increased. If precise tuning is required then it will probably not be suffucient to rely on the value given for 'Frequency' and instead this should be checked by ear. In this example the user can choose between a sound file input, the computer's live input or a stream of click impulses. The risk of feedback is greatly increased through the use of streson processing so for this reason a gain control on the live input, which is initially zero, is included. Use with caution! It might actually be better to monitor through headphones to further reduce the risk of feedback when using the live input.</label>
250 <alignment>left</alignment>
251 <font>Liberation Sans</font>
252 <fontsize>14</fontsize>
253 <precision>3</precision>
254 <color>
255 <r>0</r>
256 <g>0</g>
257 <b>0</b>
258 </color>
259 <bgcolor mode="nobackground">
260 <r>255</r>
261 <g>255</g>
262 <b>255</b>
263 </bgcolor>
264 <bordermode>noborder</bordermode>
265 <borderradius>1</borderradius>
266 <borderwidth>1</borderwidth>
267 </bsbObject>
268 <bsbObject version="2" type="BSBDisplay">
269 <objectName>InputGain</objectName>
270 <x>448</x>
271 <y>78</y>
272 <width>60</width>
273 <height>30</height>
274 <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
275 <visible>true</visible>
276 <midichan>0</midichan>
277 <midicc>0</midicc>
278 <label>0.592</label>
279 <alignment>right</alignment>
280 <font>Liberation Sans</font>
281 <fontsize>9</fontsize>
282 <precision>3</precision>
283 <color>
284 <r>0</r>
285 <g>0</g>
286 <b>0</b>
287 </color>
288 <bgcolor mode="nobackground">
289 <r>255</r>
290 <g>255</g>
291 <b>255</b>
292 </bgcolor>
293 <bordermode>noborder</bordermode>
294 <borderradius>1</borderradius>
295 <borderwidth>1</borderwidth>
296 </bsbObject>
297 <bsbObject version="2" type="BSBDropdown">
298 <objectName>Input</objectName>
299 <x>178</x>
300 <y>247</y>
301 <width>120</width>
302 <height>30</height>
303 <uuid>{9b81a1f2-bcb8-4582-925b-9ae56def3865}</uuid>
304 <visible>true</visible>
305 <midichan>0</midichan>
306 <midicc>0</midicc>
307 <bsbDropdownItemList>
308 <bsbDropdownItem>
309 <name>Audio File</name>
310 <value>0</value>
311 <stringvalue/>
312 </bsbDropdownItem>
313 <bsbDropdownItem>
314 <name>Live Input</name>
315 <value>1</value>
316 <stringvalue/>
317 </bsbDropdownItem>
318 <bsbDropdownItem>
319 <name>Impulses</name>
320 <value>2</value>
321 <stringvalue/>
322 </bsbDropdownItem>
323 </bsbDropdownItemList>
324 <selectedIndex>0</selectedIndex>
325 <randomizable group="0">false</randomizable>
326 </bsbObject>
327 <bsbObject version="2" type="BSBLabel">
328 <objectName/>
329 <x>96</x>
330 <y>247</y>
331 <width>80</width>
332 <height>30</height>
333 <uuid>{62eeb695-9b83-42da-81cd-8000c232d9b9}</uuid>
334 <visible>true</visible>
335 <midichan>0</midichan>
336 <midicc>0</midicc>
337 <label>Input</label>
338 <alignment>right</alignment>
339 <font>Arial</font>
340 <fontsize>10</fontsize>
341 <precision>3</precision>
342 <color>
343 <r>0</r>
344 <g>0</g>
345 <b>0</b>
346 </color>
347 <bgcolor mode="nobackground">
348 <r>255</r>
349 <g>255</g>
350 <b>255</b>
351 </bgcolor>
352 <bordermode>noborder</bordermode>
353 <borderradius>1</borderradius>
354 <borderwidth>1</borderwidth>
355 </bsbObject>
356 <bsbObject version="2" type="BSBButton">
357 <objectName>_Browse</objectName>
358 <x>6</x>
359 <y>285</y>
360 <width>170</width>
361 <height>30</height>
362 <uuid>{9b992da1-8c0f-449e-af03-7913cc05efed}</uuid>
363 <visible>true</visible>
364 <midichan>0</midichan>
365 <midicc>0</midicc>
366 <type>value</type>
367 <pressedValue>1.00000000</pressedValue>
368 <stringvalue>Seashore.wav</stringvalue>
369 <text>Browse Audio File</text>
370 <image>/</image>
371 <eventLine/>
372 <latch>false</latch>
373 <latched>false</latched>
374 </bsbObject>
375 <bsbObject version="2" type="BSBLineEdit">
376 <objectName>_Browse</objectName>
377 <x>178</x>
378 <y>286</y>
379 <width>330</width>
380 <height>28</height>
381 <uuid>{15a8ec14-710f-43e6-be9e-f5dc8c8786cb}</uuid>
382 <visible>true</visible>
383 <midichan>0</midichan>
384 <midicc>0</midicc>
385 <label>Seashore.wav</label>
386 <alignment>left</alignment>
387 <font>Arial</font>
388 <fontsize>10</fontsize>
389 <precision>3</precision>
390 <color>
391 <r>0</r>
392 <g>0</g>
393 <b>0</b>
394 </color>
395 <bgcolor mode="nobackground">
396 <r>206</r>
397 <g>206</g>
398 <b>206</b>
399 </bgcolor>
400 <background>nobackground</background>
401 </bsbObject>
402 <bsbObject version="2" type="BSBLabel">
403 <objectName/>
404 <x>8</x>
405 <y>123</y>
406 <width>220</width>
407 <height>30</height>
408 <uuid>{1daeb2b9-bae2-4c0a-939b-62c3ea3ac853}</uuid>
409 <visible>true</visible>
410 <midichan>0</midichan>
411 <midicc>0</midicc>
412 <label>Frequency</label>
413 <alignment>left</alignment>
414 <font>Liberation Sans</font>
415 <fontsize>10</fontsize>
416 <precision>3</precision>
417 <color>
418 <r>0</r>
419 <g>0</g>
420 <b>0</b>
421 </color>
422 <bgcolor mode="nobackground">
423 <r>255</r>
424 <g>255</g>
425 <b>255</b>
426 </bgcolor>
427 <bordermode>noborder</bordermode>
428 <borderradius>1</borderradius>
429 <borderwidth>1</borderwidth>
430 </bsbObject>
431 <bsbObject version="2" type="BSBHSlider">
432 <objectName>Frequency</objectName>
433 <x>8</x>
434 <y>101</y>
435 <width>500</width>
436 <height>27</height>
437 <uuid>{b378cb0c-4cee-4f42-86ad-2a0d9524d355}</uuid>
438 <visible>true</visible>
439 <midichan>0</midichan>
440 <midicc>0</midicc>
441 <minimum>0.00000000</minimum>
442 <maximum>1.00000000</maximum>
443 <value>0.56800000</value>
444 <mode>lin</mode>
445 <mouseControl act="jump">continuous</mouseControl>
446 <resolution>-1.00000000</resolution>
447 <randomizable group="0">false</randomizable>
448 </bsbObject>
449 <bsbObject version="2" type="BSBDisplay">
450 <objectName>Frequency_Value</objectName>
451 <x>448</x>
452 <y>123</y>
453 <width>60</width>
454 <height>30</height>
455 <uuid>{cf1f320e-c59c-4b26-82b5-f405ba7194fa}</uuid>
456 <visible>true</visible>
457 <midichan>0</midichan>
458 <midicc>0</midicc>
459 <label>0.000</label>
460 <alignment>right</alignment>
461 <font>Liberation Sans</font>
462 <fontsize>9</fontsize>
463 <precision>3</precision>
464 <color>
465 <r>0</r>
466 <g>0</g>
467 <b>0</b>
468 </color>
469 <bgcolor mode="nobackground">
470 <r>255</r>
471 <g>255</g>
472 <b>255</b>
473 </bgcolor>
474 <bordermode>noborder</bordermode>
475 <borderradius>1</borderradius>
476 <borderwidth>1</borderwidth>
477 </bsbObject>
478 <bsbObject version="2" type="BSBLabel">
479 <objectName/>
480 <x>8</x>
481 <y>168</y>
482 <width>220</width>
483 <height>30</height>
484 <uuid>{231bb990-9786-4aad-a8bf-56f542cd2f4a}</uuid>
485 <visible>true</visible>
486 <midichan>0</midichan>
487 <midicc>0</midicc>
488 <label>Feedback Gain (i-rate)</label>
489 <alignment>left</alignment>
490 <font>Liberation Sans</font>
491 <fontsize>10</fontsize>
492 <precision>3</precision>
493 <color>
494 <r>0</r>
495 <g>0</g>
496 <b>0</b>
497 </color>
498 <bgcolor mode="nobackground">
499 <r>255</r>
500 <g>255</g>
501 <b>255</b>
502 </bgcolor>
503 <bordermode>noborder</bordermode>
504 <borderradius>1</borderradius>
505 <borderwidth>1</borderwidth>
506 </bsbObject>
507 <bsbObject version="2" type="BSBHSlider">
508 <objectName>Feedback</objectName>
509 <x>8</x>
510 <y>146</y>
511 <width>500</width>
512 <height>27</height>
513 <uuid>{2e1f3a23-2e04-44eb-98e7-edaed6ee7738}</uuid>
514 <visible>true</visible>
515 <midichan>0</midichan>
516 <midicc>0</midicc>
517 <minimum>0.00000000</minimum>
518 <maximum>1.50000000</maximum>
519 <value>0.90000000</value>
520 <mode>lin</mode>
521 <mouseControl act="jump">continuous</mouseControl>
522 <resolution>-1.00000000</resolution>
523 <randomizable group="0">false</randomizable>
524 </bsbObject>
525 <bsbObject version="2" type="BSBDisplay">
526 <objectName>Feedback</objectName>
527 <x>448</x>
528 <y>168</y>
529 <width>60</width>
530 <height>30</height>
531 <uuid>{3a818717-052f-4ce3-b538-4e12df8abe25}</uuid>
532 <visible>true</visible>
533 <midichan>0</midichan>
534 <midicc>0</midicc>
535 <label>0.900</label>
536 <alignment>right</alignment>
537 <font>Liberation Sans</font>
538 <fontsize>9</fontsize>
539 <precision>3</precision>
540 <color>
541 <r>0</r>
542 <g>0</g>
543 <b>0</b>
544 </color>
545 <bgcolor mode="nobackground">
546 <r>255</r>
547 <g>255</g>
548 <b>255</b>
549 </bgcolor>
550 <bordermode>noborder</bordermode>
551 <borderradius>1</borderradius>
552 <borderwidth>1</borderwidth>
553 </bsbObject>
554 <bsbObject version="2" type="BSBLabel">
555 <objectName/>
556 <x>8</x>
557 <y>213</y>
558 <width>220</width>
559 <height>30</height>
560 <uuid>{e42ccc90-ebf9-46dd-8039-f576154182be}</uuid>
561 <visible>true</visible>
562 <midichan>0</midichan>
563 <midicc>0</midicc>
564 <label>Output Amplitude Scaling</label>
565 <alignment>left</alignment>
566 <font>Liberation Sans</font>
567 <fontsize>10</fontsize>
568 <precision>3</precision>
569 <color>
570 <r>0</r>
571 <g>0</g>
572 <b>0</b>
573 </color>
574 <bgcolor mode="nobackground">
575 <r>255</r>
576 <g>255</g>
577 <b>255</b>
578 </bgcolor>
579 <bordermode>noborder</bordermode>
580 <borderradius>1</borderradius>
581 <borderwidth>1</borderwidth>
582 </bsbObject>
583 <bsbObject version="2" type="BSBHSlider">
584 <objectName>Amplitude</objectName>
585 <x>8</x>
586 <y>191</y>
587 <width>500</width>
588 <height>27</height>
589 <uuid>{75cac143-6654-4010-8cb5-fc135e0c20a4}</uuid>
590 <visible>true</visible>
591 <midichan>0</midichan>
592 <midicc>0</midicc>
593 <minimum>0.00000000</minimum>
594 <maximum>1.00000000</maximum>
595 <value>0.43200000</value>
596 <mode>lin</mode>
597 <mouseControl act="jump">continuous</mouseControl>
598 <resolution>-1.00000000</resolution>
599 <randomizable group="0">false</randomizable>
600 </bsbObject>
601 <bsbObject version="2" type="BSBDisplay">
602 <objectName>Amplitude</objectName>
603 <x>448</x>
604 <y>213</y>
605 <width>60</width>
606 <height>30</height>
607 <uuid>{72854ca7-b440-493d-b677-f4a67a0ed75e}</uuid>
608 <visible>true</visible>
609 <midichan>0</midichan>
610 <midicc>0</midicc>
611 <label>0.432</label>
612 <alignment>right</alignment>
613 <font>Liberation Sans</font>
614 <fontsize>9</fontsize>
615 <precision>3</precision>
616 <color>
617 <r>0</r>
618 <g>0</g>
619 <b>0</b>
620 </color>
621 <bgcolor mode="nobackground">
622 <r>255</r>
623 <g>255</g>
624 <b>255</b>
625 </bgcolor>
626 <bordermode>noborder</bordermode>
627 <borderradius>1</borderradius>
628 <borderwidth>1</borderwidth>
629 </bsbObject>
630 </bsbPanel>
631 <bsbPresets>
632 </bsbPresets>
633 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>