Debian Codegraph @

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

raw
1 ;WRITTEN BY IAIN MCCURDY
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 Browser for audio file(s) and use of FilePlay2 udo, now accept mono or stereo wav files
8
9
10 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
11 <CsoundSynthesizer>
12 <CsOptions>
13 --env:SSDIR+=../../SourceMaterials
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100 ;SAMPLE RATE
17 ksmps = 1 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
18 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
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 1 ;GUI
36 ktrig metro 10
37 if (ktrig == 1) then
38 gkinput invalue "Input"
39 gkbitdepth invalue "Bit_Depth" ;init 16
40
41 Sdisp sprintfk "%02d", gkbitdepth
42 outvalue "Bit_Depth_value", Sdisp
43 gkgain invalue "Output_Gain" ;init 1
44 endif
45 endin
46
47 instr 2
48 if gkinput=0 then ;CHECK STATUS OF gkinput
49 Sfile1 invalue "_Browse1"
50 asig, asigR FilePlay2 Sfile1, 1, 0, 1 ;READ IN SOUND FILE FROM DISK
51 elseif gkinput=1 then ;CHECK STATUS OF gkinput
52 Sfile2 invalue "_Browse2"
53 asig, asigR FilePlay2 Sfile2, 1, 0, 1 ;READ IN SOUND FILE FROM DISK
54 elseif gkinput=2 then ;CHECK STATUS OF gkinput
55 asig inch 1 ;READ THE COMPUTER'S LIVE AUDIO INPUT
56 endif ;END OF if... BRANCHING
57
58 kvalues pow 2, gkbitdepth ;RAISES 2 TO THE POWER OF kbitdepth. THE OUTPUT VALUE REPRESENTS THE NUMBER OF POSSIBLE VALUES AT THAT PARTICULAR BIT DEPTH
59 k16bit pow 2, 16 ;RAISES 2 TO THE POWER OF 16
60 ksig downsamp asig ;CREATE A K-RATE VERSION OF asig
61 ksig = int(ksig * (kvalues/k16bit)) ;QUANTISE ksig-
62 ksig = ksig * (k16bit/kvalues) ;-AND RESCALE IT TO MATCH THE ORIGINAL AMPLITUDE
63 asig interp ksig ;CREATE AN AUDIO-RATE VERSION OF THE QUANTISED SIGNAL
64 outs asig*gkgain, asig*gkgain
65 endin
66 </CsInstruments>
67 <CsScore>
68 ;INSTR | START | DURATION
69 i 1 0 3600 ;GUI
70 </CsScore>
71 </CsoundSynthesizer>
72
73
74 <bsbPanel>
75 <label>Widgets</label>
76 <objectName/>
77 <x>72</x>
78 <y>179</y>
79 <width>400</width>
80 <height>200</height>
81 <visible>true</visible>
82 <uuid/>
83 <bgcolor mode="background">
84 <r>241</r>
85 <g>226</g>
86 <b>185</b>
87 </bgcolor>
88 <bsbObject version="2" type="BSBLabel">
89 <objectName/>
90 <x>2</x>
91 <y>2</y>
92 <width>517</width>
93 <height>290</height>
94 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
95 <visible>true</visible>
96 <midichan>0</midichan>
97 <midicc>0</midicc>
98 <label>DelaysBit Depth Reduction</label>
99 <alignment>center</alignment>
100 <font>Liberation Sans</font>
101 <fontsize>18</fontsize>
102 <precision>3</precision>
103 <color>
104 <r>0</r>
105 <g>0</g>
106 <b>0</b>
107 </color>
108 <bgcolor mode="background">
109 <r>158</r>
110 <g>220</g>
111 <b>158</b>
112 </bgcolor>
113 <bordermode>border</bordermode>
114 <borderradius>5</borderradius>
115 <borderwidth>2</borderwidth>
116 </bsbObject>
117 <bsbObject version="2" type="BSBHSlider">
118 <objectName>Bit_Depth</objectName>
119 <x>10</x>
120 <y>44</y>
121 <width>500</width>
122 <height>27</height>
123 <uuid>{de47f47d-bcea-4c1c-ab4b-a323452b1f7e}</uuid>
124 <visible>true</visible>
125 <midichan>0</midichan>
126 <midicc>0</midicc>
127 <minimum>1.00000000</minimum>
128 <maximum>16.00000000</maximum>
129 <value>4.15000000</value>
130 <mode>lin</mode>
131 <mouseControl act="jump">continuous</mouseControl>
132 <resolution>-1.00000000</resolution>
133 <randomizable group="0">false</randomizable>
134 </bsbObject>
135 <bsbObject version="2" type="BSBLabel">
136 <objectName/>
137 <x>10</x>
138 <y>61</y>
139 <width>140</width>
140 <height>30</height>
141 <uuid>{0200a063-5db8-4668-bc2d-2d989a083f6e}</uuid>
142 <visible>true</visible>
143 <midichan>0</midichan>
144 <midicc>0</midicc>
145 <label>Bit Depth</label>
146 <alignment>left</alignment>
147 <font>Arial</font>
148 <fontsize>10</fontsize>
149 <precision>3</precision>
150 <color>
151 <r>0</r>
152 <g>0</g>
153 <b>0</b>
154 </color>
155 <bgcolor mode="nobackground">
156 <r>255</r>
157 <g>255</g>
158 <b>255</b>
159 </bgcolor>
160 <bordermode>noborder</bordermode>
161 <borderradius>1</borderradius>
162 <borderwidth>1</borderwidth>
163 </bsbObject>
164 <bsbObject version="2" type="BSBDisplay">
165 <objectName>Bit_Depth_value</objectName>
166 <x>450</x>
167 <y>61</y>
168 <width>60</width>
169 <height>30</height>
170 <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
171 <visible>true</visible>
172 <midichan>0</midichan>
173 <midicc>0</midicc>
174 <label>04</label>
175 <alignment>right</alignment>
176 <font>Arial</font>
177 <fontsize>9</fontsize>
178 <precision>3</precision>
179 <color>
180 <r>0</r>
181 <g>0</g>
182 <b>0</b>
183 </color>
184 <bgcolor mode="nobackground">
185 <r>255</r>
186 <g>255</g>
187 <b>255</b>
188 </bgcolor>
189 <bordermode>noborder</bordermode>
190 <borderradius>1</borderradius>
191 <borderwidth>1</borderwidth>
192 </bsbObject>
193 <bsbObject version="2" type="BSBLabel">
194 <objectName/>
195 <x>520</x>
196 <y>2</y>
197 <width>232</width>
198 <height>290</height>
199 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
200 <visible>true</visible>
201 <midichan>0</midichan>
202 <midicc>0</midicc>
203 <label>Artificial Bit Depth Reduction</label>
204 <alignment>center</alignment>
205 <font>Liberation Sans</font>
206 <fontsize>18</fontsize>
207 <precision>3</precision>
208 <color>
209 <r>0</r>
210 <g>0</g>
211 <b>0</b>
212 </color>
213 <bgcolor mode="background">
214 <r>158</r>
215 <g>220</g>
216 <b>158</b>
217 </bgcolor>
218 <bordermode>border</bordermode>
219 <borderradius>5</borderradius>
220 <borderwidth>2</borderwidth>
221 </bsbObject>
222 <bsbObject version="2" type="BSBLabel">
223 <objectName/>
224 <x>524</x>
225 <y>40</y>
226 <width>224</width>
227 <height>210</height>
228 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
229 <visible>true</visible>
230 <midichan>0</midichan>
231 <midicc>0</midicc>
232 <label>-----------------------------------------------------
233 This example uses a mathematical quantizing procedure upon an audio signal to create the effect of lower bit depth sample storage.
234 The example is designed to work with 16 bit samples but could easily be adapted to work with samples of other depths.</label>
235 <alignment>left</alignment>
236 <font>Arial</font>
237 <fontsize>14</fontsize>
238 <precision>3</precision>
239 <color>
240 <r>0</r>
241 <g>0</g>
242 <b>0</b>
243 </color>
244 <bgcolor mode="nobackground">
245 <r>255</r>
246 <g>255</g>
247 <b>255</b>
248 </bgcolor>
249 <bordermode>noborder</bordermode>
250 <borderradius>1</borderradius>
251 <borderwidth>1</borderwidth>
252 </bsbObject>
253 <bsbObject version="2" type="BSBLabel">
254 <objectName/>
255 <x>10</x>
256 <y>104</y>
257 <width>140</width>
258 <height>30</height>
259 <uuid>{6d8d92f5-813d-4e91-867e-f3384b0baf9d}</uuid>
260 <visible>true</visible>
261 <midichan>0</midichan>
262 <midicc>0</midicc>
263 <label>Output Gain</label>
264 <alignment>left</alignment>
265 <font>Arial</font>
266 <fontsize>10</fontsize>
267 <precision>3</precision>
268 <color>
269 <r>0</r>
270 <g>0</g>
271 <b>0</b>
272 </color>
273 <bgcolor mode="nobackground">
274 <r>255</r>
275 <g>255</g>
276 <b>255</b>
277 </bgcolor>
278 <bordermode>noborder</bordermode>
279 <borderradius>1</borderradius>
280 <borderwidth>1</borderwidth>
281 </bsbObject>
282 <bsbObject version="2" type="BSBHSlider">
283 <objectName>Output_Gain</objectName>
284 <x>10</x>
285 <y>87</y>
286 <width>500</width>
287 <height>27</height>
288 <uuid>{8fbaf396-5ad3-4de9-b5fe-cf9991b23868}</uuid>
289 <visible>true</visible>
290 <midichan>0</midichan>
291 <midicc>0</midicc>
292 <minimum>0.00000000</minimum>
293 <maximum>2.00000000</maximum>
294 <value>0.39200000</value>
295 <mode>lin</mode>
296 <mouseControl act="jump">continuous</mouseControl>
297 <resolution>-1.00000000</resolution>
298 <randomizable group="0">false</randomizable>
299 </bsbObject>
300 <bsbObject version="2" type="BSBDisplay">
301 <objectName>Output_Gain</objectName>
302 <x>450</x>
303 <y>104</y>
304 <width>60</width>
305 <height>30</height>
306 <uuid>{0a5ba1c3-3448-4200-9a48-c116a64fc284}</uuid>
307 <visible>true</visible>
308 <midichan>0</midichan>
309 <midicc>0</midicc>
310 <label>0.392</label>
311 <alignment>right</alignment>
312 <font>Arial</font>
313 <fontsize>9</fontsize>
314 <precision>3</precision>
315 <color>
316 <r>0</r>
317 <g>0</g>
318 <b>0</b>
319 </color>
320 <bgcolor mode="nobackground">
321 <r>255</r>
322 <g>255</g>
323 <b>255</b>
324 </bgcolor>
325 <bordermode>noborder</bordermode>
326 <borderradius>1</borderradius>
327 <borderwidth>1</borderwidth>
328 </bsbObject>
329 <bsbObject version="2" type="BSBButton">
330 <objectName/>
331 <x>8</x>
332 <y>8</y>
333 <width>100</width>
334 <height>29</height>
335 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
336 <visible>true</visible>
337 <midichan>0</midichan>
338 <midicc>0</midicc>
339 <type>event</type>
340 <pressedValue>1.00000000</pressedValue>
341 <stringvalue/>
342 <text> On / Off</text>
343 <image>/</image>
344 <eventLine>i 2 0 -1</eventLine>
345 <latch>true</latch>
346 <latched>false</latched>
347 </bsbObject>
348 <bsbObject version="2" type="BSBDropdown">
349 <objectName>Input</objectName>
350 <x>244</x>
351 <y>137</y>
352 <width>100</width>
353 <height>29</height>
354 <uuid>{3158b0e2-b91c-41af-8c0e-eff18094154c}</uuid>
355 <visible>true</visible>
356 <midichan>0</midichan>
357 <midicc>0</midicc>
358 <bsbDropdownItemList>
359 <bsbDropdownItem>
360 <name>Voice</name>
361 <value>0</value>
362 <stringvalue/>
363 </bsbDropdownItem>
364 <bsbDropdownItem>
365 <name>Drums</name>
366 <value>1</value>
367 <stringvalue/>
368 </bsbDropdownItem>
369 <bsbDropdownItem>
370 <name>Live Input</name>
371 <value>2</value>
372 <stringvalue/>
373 </bsbDropdownItem>
374 </bsbDropdownItemList>
375 <selectedIndex>1</selectedIndex>
376 <randomizable group="0">false</randomizable>
377 </bsbObject>
378 <bsbObject version="2" type="BSBLabel">
379 <objectName/>
380 <x>183</x>
381 <y>137</y>
382 <width>60</width>
383 <height>30</height>
384 <uuid>{78ab42b4-bf04-4aaa-bc1c-ea879b382489}</uuid>
385 <visible>true</visible>
386 <midichan>0</midichan>
387 <midicc>0</midicc>
388 <label>Inputs</label>
389 <alignment>right</alignment>
390 <font>Arial</font>
391 <fontsize>10</fontsize>
392 <precision>3</precision>
393 <color>
394 <r>0</r>
395 <g>0</g>
396 <b>0</b>
397 </color>
398 <bgcolor mode="nobackground">
399 <r>255</r>
400 <g>255</g>
401 <b>255</b>
402 </bgcolor>
403 <bordermode>noborder</bordermode>
404 <borderradius>1</borderradius>
405 <borderwidth>1</borderwidth>
406 </bsbObject>
407 <bsbObject version="2" type="BSBButton">
408 <objectName>_Browse1</objectName>
409 <x>8</x>
410 <y>175</y>
411 <width>170</width>
412 <height>30</height>
413 <uuid>{fb94b123-8b42-401d-a3f3-16e3aa870c92}</uuid>
414 <visible>true</visible>
415 <midichan>0</midichan>
416 <midicc>0</midicc>
417 <type>value</type>
418 <pressedValue>1.00000000</pressedValue>
419 <stringvalue>AndItsAll.wav</stringvalue>
420 <text>Browse Audio File</text>
421 <image>/</image>
422 <eventLine/>
423 <latch>false</latch>
424 <latched>false</latched>
425 </bsbObject>
426 <bsbObject version="2" type="BSBLineEdit">
427 <objectName>_Browse1</objectName>
428 <x>179</x>
429 <y>176</y>
430 <width>330</width>
431 <height>28</height>
432 <uuid>{c2b2d791-4d1f-43e6-813b-98a0a0bb9fa6}</uuid>
433 <visible>true</visible>
434 <midichan>0</midichan>
435 <midicc>0</midicc>
436 <label>AndItsAll.wav</label>
437 <alignment>left</alignment>
438 <font>Arial</font>
439 <fontsize>10</fontsize>
440 <precision>3</precision>
441 <color>
442 <r>0</r>
443 <g>0</g>
444 <b>0</b>
445 </color>
446 <bgcolor mode="nobackground">
447 <r>229</r>
448 <g>229</g>
449 <b>229</b>
450 </bgcolor>
451 <background>nobackground</background>
452 </bsbObject>
453 <bsbObject version="2" type="BSBLabel">
454 <objectName/>
455 <x>8</x>
456 <y>154</y>
457 <width>120</width>
458 <height>30</height>
459 <uuid>{a1e809e4-b138-4927-9ec6-cf361f1d8c24}</uuid>
460 <visible>true</visible>
461 <midichan>0</midichan>
462 <midicc>0</midicc>
463 <label>Voice File select</label>
464 <alignment>left</alignment>
465 <font>Arial</font>
466 <fontsize>10</fontsize>
467 <precision>3</precision>
468 <color>
469 <r>0</r>
470 <g>0</g>
471 <b>0</b>
472 </color>
473 <bgcolor mode="nobackground">
474 <r>255</r>
475 <g>255</g>
476 <b>255</b>
477 </bgcolor>
478 <bordermode>noborder</bordermode>
479 <borderradius>1</borderradius>
480 <borderwidth>1</borderwidth>
481 </bsbObject>
482 <bsbObject version="2" type="BSBLabel">
483 <objectName/>
484 <x>8</x>
485 <y>210</y>
486 <width>120</width>
487 <height>30</height>
488 <uuid>{9d92044a-523e-4f59-bd90-d82f401b908b}</uuid>
489 <visible>true</visible>
490 <midichan>0</midichan>
491 <midicc>0</midicc>
492 <label>Drums File select</label>
493 <alignment>left</alignment>
494 <font>Arial</font>
495 <fontsize>10</fontsize>
496 <precision>3</precision>
497 <color>
498 <r>0</r>
499 <g>0</g>
500 <b>0</b>
501 </color>
502 <bgcolor mode="nobackground">
503 <r>255</r>
504 <g>255</g>
505 <b>255</b>
506 </bgcolor>
507 <bordermode>noborder</bordermode>
508 <borderradius>1</borderradius>
509 <borderwidth>1</borderwidth>
510 </bsbObject>
511 <bsbObject version="2" type="BSBLineEdit">
512 <objectName>_Browse2</objectName>
513 <x>179</x>
514 <y>232</y>
515 <width>330</width>
516 <height>28</height>
517 <uuid>{848aeba9-7149-443f-b138-bacbe2e6bcdb}</uuid>
518 <visible>true</visible>
519 <midichan>0</midichan>
520 <midicc>0</midicc>
521 <label>808loopMono.wav</label>
522 <alignment>left</alignment>
523 <font>Arial</font>
524 <fontsize>10</fontsize>
525 <precision>3</precision>
526 <color>
527 <r>0</r>
528 <g>0</g>
529 <b>0</b>
530 </color>
531 <bgcolor mode="nobackground">
532 <r>229</r>
533 <g>229</g>
534 <b>229</b>
535 </bgcolor>
536 <background>nobackground</background>
537 </bsbObject>
538 <bsbObject version="2" type="BSBButton">
539 <objectName>_Browse2</objectName>
540 <x>8</x>
541 <y>231</y>
542 <width>170</width>
543 <height>30</height>
544 <uuid>{98554442-4ae3-49de-8c90-ef10dff3e093}</uuid>
545 <visible>true</visible>
546 <midichan>0</midichan>
547 <midicc>0</midicc>
548 <type>value</type>
549 <pressedValue>1.00000000</pressedValue>
550 <stringvalue>808loopMono.wav</stringvalue>
551 <text>Browse Audio File</text>
552 <image>/</image>
553 <eventLine/>
554 <latch>false</latch>
555 <latched>false</latched>
556 </bsbObject>
557 <bsbObject version="2" type="BSBLabel">
558 <objectName/>
559 <x>179</x>
560 <y>203</y>
561 <width>330</width>
562 <height>30</height>
563 <uuid>{a63909ac-6fa4-41c8-a84b-ba08e76132ab}</uuid>
564 <visible>true</visible>
565 <midichan>0</midichan>
566 <midicc>0</midicc>
567 <label>Restart the instrument after changing the audio file.</label>
568 <alignment>left</alignment>
569 <font>Liberation Sans</font>
570 <fontsize>12</fontsize>
571 <precision>3</precision>
572 <color>
573 <r>0</r>
574 <g>0</g>
575 <b>0</b>
576 </color>
577 <bgcolor mode="nobackground">
578 <r>255</r>
579 <g>255</g>
580 <b>255</b>
581 </bgcolor>
582 <bordermode>noborder</bordermode>
583 <borderradius>1</borderradius>
584 <borderwidth>1</borderwidth>
585 </bsbObject>
586 <bsbObject version="2" type="BSBLabel">
587 <objectName/>
588 <x>179</x>
589 <y>260</y>
590 <width>330</width>
591 <height>30</height>
592 <uuid>{3a95a5aa-102a-4b22-aac4-64e4a6c4f09f}</uuid>
593 <visible>true</visible>
594 <midichan>0</midichan>
595 <midicc>0</midicc>
596 <label>Restart the instrument after changing the audio file.</label>
597 <alignment>left</alignment>
598 <font>Liberation Sans</font>
599 <fontsize>12</fontsize>
600 <precision>3</precision>
601 <color>
602 <r>0</r>
603 <g>0</g>
604 <b>0</b>
605 </color>
606 <bgcolor mode="nobackground">
607 <r>255</r>
608 <g>255</g>
609 <b>255</b>
610 </bgcolor>
611 <bordermode>noborder</bordermode>
612 <borderradius>1</borderradius>
613 <borderwidth>1</borderwidth>
614 </bsbObject>
615 </bsbPanel>
616 <bsbPresets>
617 </bsbPresets>
618 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="false" loopStart="0" loopEnd="0"> </EventPanel>