Debian Codegraph @

src/Examples/McCurdy Collection/Distortion/clip.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 = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20 0dbfs = 1 ;MAXIMUM SOUND INTENSITY LEVEL REGARDLESS OF BIT DEPTH
21
22
23 giExp1 ftgen 0, 0, 129, -25, 0, 0.001, 128, 1.0 ;TABLE FOR EXP SLIDER
24 giExp1000 ftgen 0, 0, 129, -25, 0, 1.0, 128, 1000.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
41 instr 1 ;GUI
42 ktrig metro 10
43 if (ktrig == 1) then
44 klimit invalue "Limit"
45 gklimit tablei klimit, giExp1, 1
46 outvalue "Limit_Value", gklimit ;init 0.001
47 gkarg invalue "Clipping_Point" ;init 0.5
48 kpostgain invalue "Post_Gain"
49 gkpostgain tablei kpostgain, giExp1000, 1
50 outvalue "Post_Gain_Value", gkpostgain ;init 100
51 gkmeth invalue "Method" ;init 0
52 endif
53 endin
54
55 instr 2
56 Sfile invalue "_Browse1"
57 asig, asigR FilePlay2 Sfile, 1, 0, 1
58 kSwitch changed gklimit, gkmeth, gkarg ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
59 if kSwitch=1 then ;IF A VARIABLE CHANGE INDICATOR IS RECEIVED...
60 reinit START ;...BEGIN A REINITIALISATION PASS FROM LABEL 'START'
61 endif ;END OF CONDITIONAL BRANCHING
62 START: ;LABEL
63 ares clip asig, i(gkmeth), i(gklimit), i(gkarg)
64 rireturn ;RETURN TO PERFORMANCE PASSES FROM INITIALISATION PASS
65 outs ares * gkpostgain, ares * gkpostgain
66 endin
67 </CsInstruments>
68 <CsScore>
69 ;INSTR | START | DURATION
70 i 1 0 3600 ;GUI
71 </CsScore>
72 </CsoundSynthesizer>
73
74
75
76 <bsbPanel>
77 <label>Widgets</label>
78 <objectName/>
79 <x>457</x>
80 <y>115</y>
81 <width>814</width>
82 <height>334</height>
83 <visible>true</visible>
84 <uuid/>
85 <bgcolor mode="background">
86 <r>241</r>
87 <g>226</g>
88 <b>185</b>
89 </bgcolor>
90 <bsbObject type="BSBLabel" version="2">
91 <objectName/>
92 <x>2</x>
93 <y>2</y>
94 <width>514</width>
95 <height>290</height>
96 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
97 <visible>true</visible>
98 <midichan>0</midichan>
99 <midicc>0</midicc>
100 <label>Clip</label>
101 <alignment>center</alignment>
102 <font>Liberation Sans</font>
103 <fontsize>18</fontsize>
104 <precision>3</precision>
105 <color>
106 <r>0</r>
107 <g>0</g>
108 <b>0</b>
109 </color>
110 <bgcolor mode="background">
111 <r>158</r>
112 <g>220</g>
113 <b>158</b>
114 </bgcolor>
115 <bordermode>border</bordermode>
116 <borderradius>5</borderradius>
117 <borderwidth>2</borderwidth>
118 </bsbObject>
119 <bsbObject type="BSBHSlider" version="2">
120 <objectName>Limit</objectName>
121 <x>8</x>
122 <y>48</y>
123 <width>500</width>
124 <height>27</height>
125 <uuid>{de47f47d-bcea-4c1c-ab4b-a323452b1f7e}</uuid>
126 <visible>true</visible>
127 <midichan>0</midichan>
128 <midicc>0</midicc>
129 <minimum>0.00000000</minimum>
130 <maximum>1.00000000</maximum>
131 <value>0.32200000</value>
132 <mode>lin</mode>
133 <mouseControl act="jump">continuous</mouseControl>
134 <resolution>-1.00000000</resolution>
135 <randomizable group="0">false</randomizable>
136 </bsbObject>
137 <bsbObject type="BSBLabel" version="2">
138 <objectName/>
139 <x>8</x>
140 <y>65</y>
141 <width>140</width>
142 <height>30</height>
143 <uuid>{0200a063-5db8-4668-bc2d-2d989a083f6e}</uuid>
144 <visible>true</visible>
145 <midichan>0</midichan>
146 <midicc>0</midicc>
147 <label>Limit</label>
148 <alignment>left</alignment>
149 <font>Arial</font>
150 <fontsize>10</fontsize>
151 <precision>3</precision>
152 <color>
153 <r>0</r>
154 <g>0</g>
155 <b>0</b>
156 </color>
157 <bgcolor mode="nobackground">
158 <r>255</r>
159 <g>255</g>
160 <b>255</b>
161 </bgcolor>
162 <bordermode>noborder</bordermode>
163 <borderradius>1</borderradius>
164 <borderwidth>1</borderwidth>
165 </bsbObject>
166 <bsbObject type="BSBDisplay" version="2">
167 <objectName>Limit_Value</objectName>
168 <x>448</x>
169 <y>65</y>
170 <width>60</width>
171 <height>30</height>
172 <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
173 <visible>true</visible>
174 <midichan>0</midichan>
175 <midicc>0</midicc>
176 <label>0.009</label>
177 <alignment>right</alignment>
178 <font>Arial</font>
179 <fontsize>9</fontsize>
180 <precision>3</precision>
181 <color>
182 <r>0</r>
183 <g>0</g>
184 <b>0</b>
185 </color>
186 <bgcolor mode="nobackground">
187 <r>255</r>
188 <g>255</g>
189 <b>255</b>
190 </bgcolor>
191 <bordermode>noborder</bordermode>
192 <borderradius>1</borderradius>
193 <borderwidth>1</borderwidth>
194 </bsbObject>
195 <bsbObject type="BSBLabel" version="2">
196 <objectName/>
197 <x>517</x>
198 <y>2</y>
199 <width>280</width>
200 <height>290</height>
201 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
202 <visible>true</visible>
203 <midichan>0</midichan>
204 <midicc>0</midicc>
205 <label>Clip</label>
206 <alignment>center</alignment>
207 <font>Liberation Sans</font>
208 <fontsize>18</fontsize>
209 <precision>3</precision>
210 <color>
211 <r>0</r>
212 <g>0</g>
213 <b>0</b>
214 </color>
215 <bgcolor mode="background">
216 <r>158</r>
217 <g>220</g>
218 <b>158</b>
219 </bgcolor>
220 <bordermode>border</bordermode>
221 <borderradius>5</borderradius>
222 <borderwidth>2</borderwidth>
223 </bsbObject>
224 <bsbObject type="BSBLabel" version="2">
225 <objectName/>
226 <x>521</x>
227 <y>19</y>
228 <width>271</width>
229 <height>260</height>
230 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
231 <visible>true</visible>
232 <midichan>0</midichan>
233 <midicc>0</midicc>
234 <label>---------------------------------------------------------------
235 The 'clip' opcode provides audio signal soft clipping using one of three different methods.
236 'Limiting Value' defines the maximum amplitude that will be passed unclipped. In this example maximum amplitude has been defined as '1' therefore, in this instance, this value ranges up to 1.
237 'Clipping Point' defines the point at which clipping starts and is only ised in the Bram de Jong method.
238 A 'Post Gain' control is included so that the user can compensate for the loss of gain that occurs when the signal is clipped.</label>
239 <alignment>left</alignment>
240 <font>Arial</font>
241 <fontsize>14</fontsize>
242 <precision>3</precision>
243 <color>
244 <r>0</r>
245 <g>0</g>
246 <b>0</b>
247 </color>
248 <bgcolor mode="nobackground">
249 <r>255</r>
250 <g>255</g>
251 <b>255</b>
252 </bgcolor>
253 <bordermode>noborder</bordermode>
254 <borderradius>1</borderradius>
255 <borderwidth>1</borderwidth>
256 </bsbObject>
257 <bsbObject type="BSBLabel" version="2">
258 <objectName/>
259 <x>8</x>
260 <y>105</y>
261 <width>220</width>
262 <height>30</height>
263 <uuid>{6d8d92f5-813d-4e91-867e-f3384b0baf9d}</uuid>
264 <visible>true</visible>
265 <midichan>0</midichan>
266 <midicc>0</midicc>
267 <label>Clipping Point (B.d.J Method only)</label>
268 <alignment>left</alignment>
269 <font>Arial</font>
270 <fontsize>10</fontsize>
271 <precision>3</precision>
272 <color>
273 <r>0</r>
274 <g>0</g>
275 <b>0</b>
276 </color>
277 <bgcolor mode="nobackground">
278 <r>255</r>
279 <g>255</g>
280 <b>255</b>
281 </bgcolor>
282 <bordermode>noborder</bordermode>
283 <borderradius>1</borderradius>
284 <borderwidth>1</borderwidth>
285 </bsbObject>
286 <bsbObject type="BSBHSlider" version="2">
287 <objectName>Clipping_Point</objectName>
288 <x>8</x>
289 <y>88</y>
290 <width>500</width>
291 <height>27</height>
292 <uuid>{8fbaf396-5ad3-4de9-b5fe-cf9991b23868}</uuid>
293 <visible>true</visible>
294 <midichan>0</midichan>
295 <midicc>0</midicc>
296 <minimum>0.00000000</minimum>
297 <maximum>1.00000000</maximum>
298 <value>0.16400000</value>
299 <mode>lin</mode>
300 <mouseControl act="jump">continuous</mouseControl>
301 <resolution>-1.00000000</resolution>
302 <randomizable group="0">false</randomizable>
303 </bsbObject>
304 <bsbObject type="BSBDisplay" version="2">
305 <objectName>Clipping_Point</objectName>
306 <x>448</x>
307 <y>105</y>
308 <width>60</width>
309 <height>30</height>
310 <uuid>{0a5ba1c3-3448-4200-9a48-c116a64fc284}</uuid>
311 <visible>true</visible>
312 <midichan>0</midichan>
313 <midicc>0</midicc>
314 <label>0.164</label>
315 <alignment>right</alignment>
316 <font>Arial</font>
317 <fontsize>9</fontsize>
318 <precision>3</precision>
319 <color>
320 <r>0</r>
321 <g>0</g>
322 <b>0</b>
323 </color>
324 <bgcolor mode="nobackground">
325 <r>255</r>
326 <g>255</g>
327 <b>255</b>
328 </bgcolor>
329 <bordermode>noborder</bordermode>
330 <borderradius>1</borderradius>
331 <borderwidth>1</borderwidth>
332 </bsbObject>
333 <bsbObject type="BSBButton" version="2">
334 <objectName/>
335 <x>8</x>
336 <y>8</y>
337 <width>100</width>
338 <height>29</height>
339 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
340 <visible>true</visible>
341 <midichan>0</midichan>
342 <midicc>0</midicc>
343 <type>event</type>
344 <pressedValue>1.00000000</pressedValue>
345 <stringvalue/>
346 <text> On / Off</text>
347 <image>/</image>
348 <eventLine>i 2 0 -1</eventLine>
349 <latch>true</latch>
350 <latched>false</latched>
351 </bsbObject>
352 <bsbObject type="BSBDropdown" version="2">
353 <objectName>Method</objectName>
354 <x>100</x>
355 <y>148</y>
356 <width>140</width>
357 <height>30</height>
358 <uuid>{3158b0e2-b91c-41af-8c0e-eff18094154c}</uuid>
359 <visible>true</visible>
360 <midichan>0</midichan>
361 <midicc>0</midicc>
362 <bsbDropdownItemList>
363 <bsbDropdownItem>
364 <name>Bram de Jong</name>
365 <value>0</value>
366 <stringvalue/>
367 </bsbDropdownItem>
368 <bsbDropdownItem>
369 <name>Sine</name>
370 <value>1</value>
371 <stringvalue/>
372 </bsbDropdownItem>
373 <bsbDropdownItem>
374 <name>Tanh</name>
375 <value>2</value>
376 <stringvalue/>
377 </bsbDropdownItem>
378 </bsbDropdownItemList>
379 <selectedIndex>0</selectedIndex>
380 <randomizable group="0">false</randomizable>
381 </bsbObject>
382 <bsbObject type="BSBLabel" version="2">
383 <objectName/>
384 <x>18</x>
385 <y>148</y>
386 <width>80</width>
387 <height>30</height>
388 <uuid>{78ab42b4-bf04-4aaa-bc1c-ea879b382489}</uuid>
389 <visible>true</visible>
390 <midichan>0</midichan>
391 <midicc>0</midicc>
392 <label>Method</label>
393 <alignment>right</alignment>
394 <font>Arial</font>
395 <fontsize>10</fontsize>
396 <precision>3</precision>
397 <color>
398 <r>0</r>
399 <g>0</g>
400 <b>0</b>
401 </color>
402 <bgcolor mode="nobackground">
403 <r>255</r>
404 <g>255</g>
405 <b>255</b>
406 </bgcolor>
407 <bordermode>noborder</bordermode>
408 <borderradius>1</borderradius>
409 <borderwidth>1</borderwidth>
410 </bsbObject>
411 <bsbObject type="BSBDisplay" version="2">
412 <objectName>Post_Gain_Value</objectName>
413 <x>448</x>
414 <y>204</y>
415 <width>60</width>
416 <height>30</height>
417 <uuid>{d17cef64-754f-4c35-8b5d-8aacd44a67ac}</uuid>
418 <visible>true</visible>
419 <midichan>0</midichan>
420 <midicc>0</midicc>
421 <label>12.707</label>
422 <alignment>right</alignment>
423 <font>Arial</font>
424 <fontsize>9</fontsize>
425 <precision>3</precision>
426 <color>
427 <r>0</r>
428 <g>0</g>
429 <b>0</b>
430 </color>
431 <bgcolor mode="nobackground">
432 <r>255</r>
433 <g>255</g>
434 <b>255</b>
435 </bgcolor>
436 <bordermode>noborder</bordermode>
437 <borderradius>1</borderradius>
438 <borderwidth>1</borderwidth>
439 </bsbObject>
440 <bsbObject type="BSBLabel" version="2">
441 <objectName/>
442 <x>8</x>
443 <y>204</y>
444 <width>120</width>
445 <height>30</height>
446 <uuid>{9deb9ba2-a5d6-4275-95ec-5d611d2d8a3c}</uuid>
447 <visible>true</visible>
448 <midichan>0</midichan>
449 <midicc>0</midicc>
450 <label>Post Gain</label>
451 <alignment>left</alignment>
452 <font>Arial</font>
453 <fontsize>10</fontsize>
454 <precision>3</precision>
455 <color>
456 <r>0</r>
457 <g>0</g>
458 <b>0</b>
459 </color>
460 <bgcolor mode="nobackground">
461 <r>255</r>
462 <g>255</g>
463 <b>255</b>
464 </bgcolor>
465 <bordermode>noborder</bordermode>
466 <borderradius>1</borderradius>
467 <borderwidth>1</borderwidth>
468 </bsbObject>
469 <bsbObject type="BSBHSlider" version="2">
470 <objectName>Post_Gain</objectName>
471 <x>8</x>
472 <y>187</y>
473 <width>500</width>
474 <height>27</height>
475 <uuid>{1cc8abab-d4c4-4e67-8bb5-ecff7667fe2e}</uuid>
476 <visible>true</visible>
477 <midichan>0</midichan>
478 <midicc>0</midicc>
479 <minimum>0.00000000</minimum>
480 <maximum>1.00000000</maximum>
481 <value>0.36800000</value>
482 <mode>lin</mode>
483 <mouseControl act="jump">continuous</mouseControl>
484 <resolution>-1.00000000</resolution>
485 <randomizable group="0">false</randomizable>
486 </bsbObject>
487 <bsbObject type="BSBButton" version="2">
488 <objectName>_Browse1</objectName>
489 <x>8</x>
490 <y>234</y>
491 <width>170</width>
492 <height>30</height>
493 <uuid>{26258c9e-e130-4e82-934c-a91f4d0d043d}</uuid>
494 <visible>true</visible>
495 <midichan>0</midichan>
496 <midicc>0</midicc>
497 <type>value</type>
498 <pressedValue>1.00000000</pressedValue>
499 <stringvalue>808loopMono.wav</stringvalue>
500 <text>Browse Audio File</text>
501 <image>/</image>
502 <eventLine/>
503 <latch>false</latch>
504 <latched>false</latched>
505 </bsbObject>
506 <bsbObject type="BSBLineEdit" version="2">
507 <objectName>_Browse1</objectName>
508 <x>179</x>
509 <y>235</y>
510 <width>330</width>
511 <height>28</height>
512 <uuid>{1e65885b-baf1-4416-84c1-653612d304ea}</uuid>
513 <visible>true</visible>
514 <midichan>0</midichan>
515 <midicc>0</midicc>
516 <label>808loopMono.wav</label>
517 <alignment>left</alignment>
518 <font>Arial</font>
519 <fontsize>10</fontsize>
520 <precision>3</precision>
521 <color>
522 <r>0</r>
523 <g>0</g>
524 <b>0</b>
525 </color>
526 <bgcolor mode="nobackground">
527 <r>35</r>
528 <g>35</g>
529 <b>35</b>
530 </bgcolor>
531 <background>nobackground</background>
532 </bsbObject>
533 <bsbObject type="BSBLabel" version="2">
534 <objectName/>
535 <x>179</x>
536 <y>262</y>
537 <width>330</width>
538 <height>30</height>
539 <uuid>{a63909ac-6fa4-41c8-a84b-ba08e76132ab}</uuid>
540 <visible>true</visible>
541 <midichan>0</midichan>
542 <midicc>0</midicc>
543 <label>Restart the instrument after changing the audio file.</label>
544 <alignment>left</alignment>
545 <font>Liberation Sans</font>
546 <fontsize>12</fontsize>
547 <precision>3</precision>
548 <color>
549 <r>0</r>
550 <g>0</g>
551 <b>0</b>
552 </color>
553 <bgcolor mode="nobackground">
554 <r>255</r>
555 <g>255</g>
556 <b>255</b>
557 </bgcolor>
558 <bordermode>noborder</bordermode>
559 <borderradius>1</borderradius>
560 <borderwidth>1</borderwidth>
561 </bsbObject>
562 </bsbPanel>
563 <bsbPresets>
564 </bsbPresets>
565 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="false" loopStart="0" loopEnd="0"> </EventPanel>