Debian Codegraph @

src/Examples/McCurdy Collection/Distortion/distort.csd

raw
1 ;Written by Iain McCurdy, 2009
2
3 ;Modified for QuteCsound by René, September 2010, updated Feb 2011
4 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6 ;Notes on modifications from original csd:
7 ; Add table(s) for exp slider
8 ; Add Browser for audio file and use of FilePlay2 udo, now accept mono or stereo wav files
9
10
11 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
12 <CsoundSynthesizer>
13 <CsOptions>
14 --env:SSDIR+=../../SourceMaterials
15 </CsOptions>
16 <CsInstruments>
17 sr = 44100 ;SAMPLE RATE
18 ksmps = 10 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20
21
22 ;WAVESHAPING FUNCTIONS
23 gifn1 ftgen 1,0,128,7,-1,128,1 ;SAWTOOTH UP
24 gifn2 ftgen 2,0,128,10,1 ;SINE WAVE
25 gifn3 ftgen 3,0,128,10,1,0,1,0,1,0,1,0,1 ;ODD PARTIALS
26 gifn4 ftgen 4,0,128,21,1 ;WHITE NOISE
27 gifn5 ftgen 5,0,128,9,.5,1,0 ;HALF SINE
28 gifn6 ftgen 6,0,128,7,1,64,1,0,-1,64,-1 ;SQUARE WAVE
29
30 ;TABLE FOR EXP SLIDER
31 giExp50 ftgen 0, 0, 129, -25, 0, 0.0001, 128, 50.0
32 giExp20000 ftgen 0, 0, 129, -25, 0, 0.0001, 128, 20000.0
33
34
35 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz
36 ;gives stereo output regardless your soundfile is mono or stereo
37 Sfil, kspeed, iskip, iloop xin
38 ichn filenchnls Sfil
39 if ichn == 1 then
40 aL diskin2 Sfil, kspeed, iskip, iloop
41 aR = aL
42 else
43 aL, aR diskin2 Sfil, kspeed, iskip, iloop
44 endif
45 xout aL, aR
46 endop
47
48
49 instr 1 ;GUI
50 ktrig metro 10
51 if (ktrig == 1) then
52 gkdist invalue "Distortion_Amount"
53 khp invalue "Half_Point"
54 gkhp tablei khp, giExp20000, 1
55 outvalue "Half_Point_Value", gkhp
56 koutgain invalue "Output_Gain"
57 gkoutgain tablei koutgain, giExp50, 1
58 outvalue "Output_Gain_Value", gkoutgain
59 gkfn invalue "Function"
60 endif
61 endin
62
63 instr 2 ;DISTORT INSTRUMENT
64 Sfile invalue "_Browse1"
65 asig, asigR FilePlay2 Sfile, 1, 0, 1
66 kSwitch changed gkhp, gkfn ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
67 if kSwitch=1 then ;IF A VARIABLE CHANGE INDICATOR IS RECEIVED...
68 reinit START ;...BEGIN A REINITIALISATION PASS FROM LABEL 'START'
69 endif ;END OF CONDITIONAL BRANCHING
70 START: ;LABEL
71 ar distort asig, gkdist, i(gkfn)+1, i(gkhp);, istor]
72 rireturn ;RETURN TO PERFORMANCE PASSES FROM INITIALISATION PASS
73 outs ar * gkoutgain, ar * gkoutgain ;SEND AUDIO TO OUTPUTS AND MULTIPLY BY OUTPUT GAIN FLTK SLIDER
74 endin
75 </CsInstruments>
76 <CsScore>
77 ;INSTR | START | DURATION
78 i 1 0 3600 ;GUI
79 </CsScore>
80 </CsoundSynthesizer>
81
82
83 <bsbPanel>
84 <label>Widgets</label>
85 <objectName/>
86 <x>72</x>
87 <y>179</y>
88 <width>400</width>
89 <height>200</height>
90 <visible>true</visible>
91 <uuid/>
92 <bgcolor mode="background">
93 <r>241</r>
94 <g>226</g>
95 <b>185</b>
96 </bgcolor>
97 <bsbObject version="2" type="BSBLabel">
98 <objectName/>
99 <x>2</x>
100 <y>2</y>
101 <width>512</width>
102 <height>274</height>
103 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
104 <visible>true</visible>
105 <midichan>0</midichan>
106 <midicc>0</midicc>
107 <label>Distort</label>
108 <alignment>center</alignment>
109 <font>Liberation Sans</font>
110 <fontsize>18</fontsize>
111 <precision>3</precision>
112 <color>
113 <r>0</r>
114 <g>0</g>
115 <b>0</b>
116 </color>
117 <bgcolor mode="background">
118 <r>158</r>
119 <g>220</g>
120 <b>158</b>
121 </bgcolor>
122 <bordermode>border</bordermode>
123 <borderradius>5</borderradius>
124 <borderwidth>2</borderwidth>
125 </bsbObject>
126 <bsbObject version="2" type="BSBHSlider">
127 <objectName>Distortion_Amount</objectName>
128 <x>8</x>
129 <y>43</y>
130 <width>500</width>
131 <height>27</height>
132 <uuid>{de47f47d-bcea-4c1c-ab4b-a323452b1f7e}</uuid>
133 <visible>true</visible>
134 <midichan>0</midichan>
135 <midicc>0</midicc>
136 <minimum>0.00000000</minimum>
137 <maximum>1.00000000</maximum>
138 <value>0.77800000</value>
139 <mode>lin</mode>
140 <mouseControl act="jump">continuous</mouseControl>
141 <resolution>-1.00000000</resolution>
142 <randomizable group="0">false</randomizable>
143 </bsbObject>
144 <bsbObject version="2" type="BSBLabel">
145 <objectName/>
146 <x>8</x>
147 <y>60</y>
148 <width>160</width>
149 <height>30</height>
150 <uuid>{0200a063-5db8-4668-bc2d-2d989a083f6e}</uuid>
151 <visible>true</visible>
152 <midichan>0</midichan>
153 <midicc>0</midicc>
154 <label>Distortion Amount</label>
155 <alignment>left</alignment>
156 <font>Arial</font>
157 <fontsize>10</fontsize>
158 <precision>3</precision>
159 <color>
160 <r>0</r>
161 <g>0</g>
162 <b>0</b>
163 </color>
164 <bgcolor mode="nobackground">
165 <r>255</r>
166 <g>255</g>
167 <b>255</b>
168 </bgcolor>
169 <bordermode>noborder</bordermode>
170 <borderradius>1</borderradius>
171 <borderwidth>1</borderwidth>
172 </bsbObject>
173 <bsbObject version="2" type="BSBDisplay">
174 <objectName>Distortion_Amount</objectName>
175 <x>448</x>
176 <y>60</y>
177 <width>60</width>
178 <height>30</height>
179 <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
180 <visible>true</visible>
181 <midichan>0</midichan>
182 <midicc>0</midicc>
183 <label>0.778</label>
184 <alignment>right</alignment>
185 <font>Arial</font>
186 <fontsize>9</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="BSBLabel">
203 <objectName/>
204 <x>515</x>
205 <y>2</y>
206 <width>265</width>
207 <height>274</height>
208 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
209 <visible>true</visible>
210 <midichan>0</midichan>
211 <midicc>0</midicc>
212 <label>Distort</label>
213 <alignment>center</alignment>
214 <font>Liberation Sans</font>
215 <fontsize>18</fontsize>
216 <precision>3</precision>
217 <color>
218 <r>0</r>
219 <g>0</g>
220 <b>0</b>
221 </color>
222 <bgcolor mode="background">
223 <r>158</r>
224 <g>220</g>
225 <b>158</b>
226 </bgcolor>
227 <bordermode>border</bordermode>
228 <borderradius>5</borderradius>
229 <borderwidth>2</borderwidth>
230 </bsbObject>
231 <bsbObject version="2" type="BSBLabel">
232 <objectName/>
233 <x>519</x>
234 <y>27</y>
235 <width>259</width>
236 <height>235</height>
237 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
238 <visible>true</visible>
239 <midichan>0</midichan>
240 <midicc>0</midicc>
241 <label>--------------------------------------------------------------
242 The 'distort' opcode performs waveshaping and clipping on an audio signal according to a waveform supplied by the user.
243 In this example I have provided six waveform functions to provide some ideas.
244 'Half Point' provides the half point of an internal low-pass filter in cycles per second.
245 An output gain control can be used to compensate for a loss in power when half point is low and distortion level is high.</label>
246 <alignment>left</alignment>
247 <font>Arial</font>
248 <fontsize>14</fontsize>
249 <precision>3</precision>
250 <color>
251 <r>0</r>
252 <g>0</g>
253 <b>0</b>
254 </color>
255 <bgcolor mode="nobackground">
256 <r>255</r>
257 <g>255</g>
258 <b>255</b>
259 </bgcolor>
260 <bordermode>noborder</bordermode>
261 <borderradius>1</borderradius>
262 <borderwidth>1</borderwidth>
263 </bsbObject>
264 <bsbObject version="2" type="BSBLabel">
265 <objectName/>
266 <x>8</x>
267 <y>102</y>
268 <width>160</width>
269 <height>30</height>
270 <uuid>{6d8d92f5-813d-4e91-867e-f3384b0baf9d}</uuid>
271 <visible>true</visible>
272 <midichan>0</midichan>
273 <midicc>0</midicc>
274 <label>Half Point (i-rate)</label>
275 <alignment>left</alignment>
276 <font>Arial</font>
277 <fontsize>10</fontsize>
278 <precision>3</precision>
279 <color>
280 <r>0</r>
281 <g>0</g>
282 <b>0</b>
283 </color>
284 <bgcolor mode="nobackground">
285 <r>255</r>
286 <g>255</g>
287 <b>255</b>
288 </bgcolor>
289 <bordermode>noborder</bordermode>
290 <borderradius>1</borderradius>
291 <borderwidth>1</borderwidth>
292 </bsbObject>
293 <bsbObject version="2" type="BSBHSlider">
294 <objectName>Half_Point</objectName>
295 <x>8</x>
296 <y>83</y>
297 <width>500</width>
298 <height>27</height>
299 <uuid>{8fbaf396-5ad3-4de9-b5fe-cf9991b23868}</uuid>
300 <visible>true</visible>
301 <midichan>0</midichan>
302 <midicc>0</midicc>
303 <minimum>0.00000000</minimum>
304 <maximum>1.00000000</maximum>
305 <value>0.58600000</value>
306 <mode>lin</mode>
307 <mouseControl act="jump">continuous</mouseControl>
308 <resolution>-1.00000000</resolution>
309 <randomizable group="0">false</randomizable>
310 </bsbObject>
311 <bsbObject version="2" type="BSBDisplay">
312 <objectName>Half_Point_Value</objectName>
313 <x>448</x>
314 <y>100</y>
315 <width>60</width>
316 <height>30</height>
317 <uuid>{0a5ba1c3-3448-4200-9a48-c116a64fc284}</uuid>
318 <visible>true</visible>
319 <midichan>0</midichan>
320 <midicc>0</midicc>
321 <label>7.319</label>
322 <alignment>right</alignment>
323 <font>Arial</font>
324 <fontsize>9</fontsize>
325 <precision>3</precision>
326 <color>
327 <r>0</r>
328 <g>0</g>
329 <b>0</b>
330 </color>
331 <bgcolor mode="nobackground">
332 <r>255</r>
333 <g>255</g>
334 <b>255</b>
335 </bgcolor>
336 <bordermode>noborder</bordermode>
337 <borderradius>1</borderradius>
338 <borderwidth>1</borderwidth>
339 </bsbObject>
340 <bsbObject version="2" type="BSBButton">
341 <objectName/>
342 <x>8</x>
343 <y>8</y>
344 <width>100</width>
345 <height>29</height>
346 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
347 <visible>true</visible>
348 <midichan>0</midichan>
349 <midicc>0</midicc>
350 <type>event</type>
351 <pressedValue>1.00000000</pressedValue>
352 <stringvalue/>
353 <text> On / Off</text>
354 <image>/</image>
355 <eventLine>i 2 0 -1</eventLine>
356 <latch>true</latch>
357 <latched>false</latched>
358 </bsbObject>
359 <bsbObject version="2" type="BSBDropdown">
360 <objectName>Function</objectName>
361 <x>259</x>
362 <y>126</y>
363 <width>130</width>
364 <height>29</height>
365 <uuid>{3158b0e2-b91c-41af-8c0e-eff18094154c}</uuid>
366 <visible>true</visible>
367 <midichan>0</midichan>
368 <midicc>0</midicc>
369 <bsbDropdownItemList>
370 <bsbDropdownItem>
371 <name>Sawtooth Up</name>
372 <value>0</value>
373 <stringvalue/>
374 </bsbDropdownItem>
375 <bsbDropdownItem>
376 <name>Sine Tone</name>
377 <value>1</value>
378 <stringvalue/>
379 </bsbDropdownItem>
380 <bsbDropdownItem>
381 <name>Odd Partials</name>
382 <value>2</value>
383 <stringvalue/>
384 </bsbDropdownItem>
385 <bsbDropdownItem>
386 <name>Noise</name>
387 <value>3</value>
388 <stringvalue/>
389 </bsbDropdownItem>
390 <bsbDropdownItem>
391 <name>Half Sine</name>
392 <value>4</value>
393 <stringvalue/>
394 </bsbDropdownItem>
395 <bsbDropdownItem>
396 <name>Square Wave</name>
397 <value>5</value>
398 <stringvalue/>
399 </bsbDropdownItem>
400 </bsbDropdownItemList>
401 <selectedIndex>1</selectedIndex>
402 <randomizable group="0">false</randomizable>
403 </bsbObject>
404 <bsbObject version="2" type="BSBLabel">
405 <objectName/>
406 <x>197</x>
407 <y>126</y>
408 <width>60</width>
409 <height>30</height>
410 <uuid>{78ab42b4-bf04-4aaa-bc1c-ea879b382489}</uuid>
411 <visible>true</visible>
412 <midichan>0</midichan>
413 <midicc>0</midicc>
414 <label>Function</label>
415 <alignment>right</alignment>
416 <font>Arial</font>
417 <fontsize>10</fontsize>
418 <precision>3</precision>
419 <color>
420 <r>0</r>
421 <g>0</g>
422 <b>0</b>
423 </color>
424 <bgcolor mode="nobackground">
425 <r>255</r>
426 <g>255</g>
427 <b>255</b>
428 </bgcolor>
429 <bordermode>noborder</bordermode>
430 <borderradius>1</borderradius>
431 <borderwidth>1</borderwidth>
432 </bsbObject>
433 <bsbObject version="2" type="BSBDisplay">
434 <objectName>Output_Gain_Value</objectName>
435 <x>448</x>
436 <y>183</y>
437 <width>60</width>
438 <height>30</height>
439 <uuid>{d17cef64-754f-4c35-8b5d-8aacd44a67ac}</uuid>
440 <visible>true</visible>
441 <midichan>0</midichan>
442 <midicc>0</midicc>
443 <label>1.984</label>
444 <alignment>right</alignment>
445 <font>Arial</font>
446 <fontsize>9</fontsize>
447 <precision>3</precision>
448 <color>
449 <r>0</r>
450 <g>0</g>
451 <b>0</b>
452 </color>
453 <bgcolor mode="nobackground">
454 <r>255</r>
455 <g>255</g>
456 <b>255</b>
457 </bgcolor>
458 <bordermode>noborder</bordermode>
459 <borderradius>1</borderradius>
460 <borderwidth>1</borderwidth>
461 </bsbObject>
462 <bsbObject version="2" type="BSBLabel">
463 <objectName/>
464 <x>8</x>
465 <y>183</y>
466 <width>160</width>
467 <height>30</height>
468 <uuid>{9deb9ba2-a5d6-4275-95ec-5d611d2d8a3c}</uuid>
469 <visible>true</visible>
470 <midichan>0</midichan>
471 <midicc>0</midicc>
472 <label>Output Gain</label>
473 <alignment>left</alignment>
474 <font>Arial</font>
475 <fontsize>10</fontsize>
476 <precision>3</precision>
477 <color>
478 <r>0</r>
479 <g>0</g>
480 <b>0</b>
481 </color>
482 <bgcolor mode="nobackground">
483 <r>255</r>
484 <g>255</g>
485 <b>255</b>
486 </bgcolor>
487 <bordermode>noborder</bordermode>
488 <borderradius>1</borderradius>
489 <borderwidth>1</borderwidth>
490 </bsbObject>
491 <bsbObject version="2" type="BSBHSlider">
492 <objectName>Output_Gain</objectName>
493 <x>8</x>
494 <y>166</y>
495 <width>500</width>
496 <height>27</height>
497 <uuid>{1cc8abab-d4c4-4e67-8bb5-ecff7667fe2e}</uuid>
498 <visible>true</visible>
499 <midichan>0</midichan>
500 <midicc>0</midicc>
501 <minimum>0.00000000</minimum>
502 <maximum>1.00000000</maximum>
503 <value>0.75400000</value>
504 <mode>lin</mode>
505 <mouseControl act="jump">continuous</mouseControl>
506 <resolution>-1.00000000</resolution>
507 <randomizable group="0">false</randomizable>
508 </bsbObject>
509 <bsbObject version="2" type="BSBButton">
510 <objectName>_Browse1</objectName>
511 <x>8</x>
512 <y>218</y>
513 <width>170</width>
514 <height>30</height>
515 <uuid>{92b9772a-d78c-49de-b5e2-e1c951bcce7e}</uuid>
516 <visible>true</visible>
517 <midichan>0</midichan>
518 <midicc>0</midicc>
519 <type>value</type>
520 <pressedValue>1.00000000</pressedValue>
521 <stringvalue>808loopMono.wav</stringvalue>
522 <text>Browse Audio File</text>
523 <image>/</image>
524 <eventLine/>
525 <latch>false</latch>
526 <latched>false</latched>
527 </bsbObject>
528 <bsbObject version="2" type="BSBLineEdit">
529 <objectName>_Browse1</objectName>
530 <x>179</x>
531 <y>219</y>
532 <width>330</width>
533 <height>28</height>
534 <uuid>{8650348d-ca4d-43b5-85d1-e49cd6cf5342}</uuid>
535 <visible>true</visible>
536 <midichan>0</midichan>
537 <midicc>0</midicc>
538 <label>808loopMono.wav</label>
539 <alignment>left</alignment>
540 <font>Arial</font>
541 <fontsize>10</fontsize>
542 <precision>3</precision>
543 <color>
544 <r>0</r>
545 <g>0</g>
546 <b>0</b>
547 </color>
548 <bgcolor mode="nobackground">
549 <r>229</r>
550 <g>229</g>
551 <b>229</b>
552 </bgcolor>
553 <background>nobackground</background>
554 </bsbObject>
555 <bsbObject version="2" type="BSBLabel">
556 <objectName/>
557 <x>179</x>
558 <y>246</y>
559 <width>330</width>
560 <height>30</height>
561 <uuid>{a63909ac-6fa4-41c8-a84b-ba08e76132ab}</uuid>
562 <visible>true</visible>
563 <midichan>0</midichan>
564 <midicc>0</midicc>
565 <label>Restart the instrument after changing the audio file.</label>
566 <alignment>left</alignment>
567 <font>Liberation Sans</font>
568 <fontsize>12</fontsize>
569 <precision>3</precision>
570 <color>
571 <r>0</r>
572 <g>0</g>
573 <b>0</b>
574 </color>
575 <bgcolor mode="nobackground">
576 <r>255</r>
577 <g>255</g>
578 <b>255</b>
579 </bgcolor>
580 <bordermode>noborder</bordermode>
581 <borderradius>1</borderradius>
582 <borderwidth>1</borderwidth>
583 </bsbObject>
584 </bsbPanel>
585 <bsbPresets>
586 </bsbPresets>
587 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>