Debian Codegraph @

src/Examples/McCurdy Collection/FFT/pvstencil.csd

raw
1 ;Written by Iain McCurdy 2011
2
3 ;Modified for QuteCsound by René, May 2011
4 ;Tested on Ubuntu 10.04 with csound-float (git csound5-3c6d155, May 31 2011) and QuteCsound svn rev 848
5
6
7 ;Notes on modifications from original csd:
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: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
12 <CsoundSynthesizer>
13 <CsOptions>
14 --env:SADIR+=../../SourceMaterials --env:SSDIR+=../../SourceMaterials
15 </CsOptions>
16 <CsInstruments>
17 sr = 44100 ;SAMPLE RATE
18 ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 1 ;NUMBER OF CHANNELS (2=STEREO)
20
21
22 ;STENCILLING FFT ANALYSIS IS STORED IN A GEN 43 FUNCTION TABLE (-VE GEN NUMBER SO THAT POST NORMALISATION IS SKIPPED)
23 ;TABLE SIZE SHOUDL BE AT LEAST FFT_SIZE/2
24 ginoise ftgen 0, 0, 131072, -43, "noise.pvx", 0
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 10 ;GUI
42 ktrig metro 10
43 if (ktrig == 1) then
44 gkgain invalue "Gain"
45 gklevel invalue "Level"
46 gkDryWet invalue "DryWet"
47 gkOutGain invalue "OutGain"
48
49 Sfile_new strcpy "" ;INIT TO EMPTY STRING
50 gSfile invalue "_Browse"
51 Sfile_old strcpyk Sfile_new
52 Sfile_new strcpyk gSfile
53 gkfile strcmpk Sfile_new, Sfile_old
54 endif
55 endin
56
57 instr 1
58 kNew_file changed gkfile ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
59 if kNew_file=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
60 reinit NEW_FILE ;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
61 endif
62
63 NEW_FILE:
64 asigin, asigR FilePlay2 gSfile, 1, 0, 1 ;GENERATE 2 AUDIO SIGNALS FROM A STEREO SOUND FILE
65 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
66
67 fsigin pvsanal asigin, 1024, 256, 1024, 1 ;ANALYSE THE AUDIO SIGNAL. OUTPUT AN F-SIGNAL.
68
69 /*
70 ;pvread ON THE SAMPLE FILE CAN ALSO BE USED
71 #define ANALYSISFILE #"sample.pvx"#
72 ilen filelen $ANALYSISFILE
73 gkspeed = 0.5
74 kptr phasor gkspeed/ilen
75 fsigin pvsfread kptr*ilen,$ANALYSISFILE
76 */
77
78 fres pvstencil fsigin, gkgain, gklevel, ginoise ;APPLY STENCIL GATING
79 aresyn pvsynth fres ;RESYNTHESIZE THE f-SIGNAL AS AN AUDIO SIGNAL
80 amix ntrpol asigin, aresyn, gkDryWet ;CREATE A MIX BETWEEN THE DRY (UNFILTERED) AND WET (FILTERED) SOUND
81 out amix * gkOutGain ;SEND THE RESCALED, RESYNTHESIZED SIGNAL TO THE AUDIO OUTPUTS
82 endin
83
84 instr 11 ;INIT
85 outvalue "Gain" , 0.0
86 outvalue "Level" , 10.0
87 outvalue "DryWet" , 1.0
88 outvalue "OutGain" , 1.0
89 endin
90 </CsInstruments>
91 <CsScore>
92 ;INSTR | START | DURATION
93 i 10 0 3600 ;GUI
94 i 11 0 0 ;INIT
95 </CsScore>
96 </CsoundSynthesizer>
97
98
99 <bsbPanel>
100 <label>Widgets</label>
101 <objectName/>
102 <x>73</x>
103 <y>206</y>
104 <width>1107</width>
105 <height>292</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>512</width>
118 <height>290</height>
119 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
120 <visible>true</visible>
121 <midichan>0</midichan>
122 <midicc>0</midicc>
123 <label>pvstencil</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>181</r>
135 <g>199</g>
136 <b>255</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>517</x>
145 <y>2</y>
146 <width>590</width>
147 <height>290</height>
148 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
149 <visible>true</visible>
150 <midichan>0</midichan>
151 <midicc>0</midicc>
152 <label>pvstencil</label>
153 <alignment>center</alignment>
154 <font>Liberation Sans</font>
155 <fontsize>18</fontsize>
156 <precision>3</precision>
157 <color>
158 <r>0</r>
159 <g>0</g>
160 <b>0</b>
161 </color>
162 <bgcolor mode="background">
163 <r>181</r>
164 <g>199</g>
165 <b>255</b>
166 </bgcolor>
167 <bordermode>border</bordermode>
168 <borderradius>5</borderradius>
169 <borderwidth>2</borderwidth>
170 </bsbObject>
171 <bsbObject version="2" type="BSBLabel">
172 <objectName/>
173 <x>520</x>
174 <y>21</y>
175 <width>583</width>
176 <height>258</height>
177 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
178 <visible>true</visible>
179 <midichan>0</midichan>
180 <midicc>0</midicc>
181 <label>-----------------------------------------------------------------------------------------------------------------------------------------------
182 pvstencil is performs masking of a streaming pvoc signal according to secondary pvoc data held in a GEN 43 function table. The most typical application for this would be to remove unwanted constant noise from a recording by first analysing a short isolated sample of that noise. The amplitude of each pvoc channel for a given instant is compared to the amplitude of the corresponding channel in the GEN 43 masking function. If the value falls below that of the masking function a user definable gain is applied. Values read from the masking function are first scaled by the parameter 'Level'. Increasing level will increase the threshold below which gain will be applied and therefore increase the influence of the masking function. Extreme values for 'Level' will result in extreme transformations of the input sound that go beyond noise reduction. By using samples other than noise samples as input for the masking function this opcode can have other creative uses. In this example a slider is provided that allows the user to compare the signal before filter with that after filtering.</label>
183 <alignment>left</alignment>
184 <font>Liberation Sans</font>
185 <fontsize>14</fontsize>
186 <precision>3</precision>
187 <color>
188 <r>0</r>
189 <g>0</g>
190 <b>0</b>
191 </color>
192 <bgcolor mode="nobackground">
193 <r>255</r>
194 <g>255</g>
195 <b>255</b>
196 </bgcolor>
197 <bordermode>noborder</bordermode>
198 <borderradius>1</borderradius>
199 <borderwidth>1</borderwidth>
200 </bsbObject>
201 <bsbObject version="2" type="BSBButton">
202 <objectName/>
203 <x>8</x>
204 <y>8</y>
205 <width>80</width>
206 <height>30</height>
207 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
208 <visible>true</visible>
209 <midichan>0</midichan>
210 <midicc>0</midicc>
211 <type>event</type>
212 <pressedValue>1.00000000</pressedValue>
213 <stringvalue/>
214 <text> On / Off</text>
215 <image>/</image>
216 <eventLine>i 1 0 -1</eventLine>
217 <latch>true</latch>
218 <latched>false</latched>
219 </bsbObject>
220 <bsbObject version="2" type="BSBDisplay">
221 <objectName>Gain</objectName>
222 <x>448</x>
223 <y>73</y>
224 <width>60</width>
225 <height>30</height>
226 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
227 <visible>true</visible>
228 <midichan>0</midichan>
229 <midicc>0</midicc>
230 <label>0.000</label>
231 <alignment>right</alignment>
232 <font>Arial</font>
233 <fontsize>9</fontsize>
234 <precision>3</precision>
235 <color>
236 <r>0</r>
237 <g>0</g>
238 <b>0</b>
239 </color>
240 <bgcolor mode="nobackground">
241 <r>255</r>
242 <g>255</g>
243 <b>255</b>
244 </bgcolor>
245 <bordermode>noborder</bordermode>
246 <borderradius>1</borderradius>
247 <borderwidth>1</borderwidth>
248 </bsbObject>
249 <bsbObject version="2" type="BSBHSlider">
250 <objectName>Gain</objectName>
251 <x>8</x>
252 <y>51</y>
253 <width>500</width>
254 <height>27</height>
255 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
256 <visible>true</visible>
257 <midichan>0</midichan>
258 <midicc>0</midicc>
259 <minimum>0.00000000</minimum>
260 <maximum>1.00000000</maximum>
261 <value>0.00000000</value>
262 <mode>lin</mode>
263 <mouseControl act="jump">continuous</mouseControl>
264 <resolution>-1.00000000</resolution>
265 <randomizable group="0">false</randomizable>
266 </bsbObject>
267 <bsbObject version="2" type="BSBLabel">
268 <objectName/>
269 <x>8</x>
270 <y>73</y>
271 <width>150</width>
272 <height>30</height>
273 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
274 <visible>true</visible>
275 <midichan>0</midichan>
276 <midicc>0</midicc>
277 <label>Gain</label>
278 <alignment>left</alignment>
279 <font>Arial</font>
280 <fontsize>10</fontsize>
281 <precision>3</precision>
282 <color>
283 <r>0</r>
284 <g>0</g>
285 <b>0</b>
286 </color>
287 <bgcolor mode="nobackground">
288 <r>255</r>
289 <g>255</g>
290 <b>255</b>
291 </bgcolor>
292 <bordermode>noborder</bordermode>
293 <borderradius>1</borderradius>
294 <borderwidth>1</borderwidth>
295 </bsbObject>
296 <bsbObject version="2" type="BSBButton">
297 <objectName>_Browse</objectName>
298 <x>8</x>
299 <y>247</y>
300 <width>170</width>
301 <height>30</height>
302 <uuid>{b9431a61-61f7-432b-bf6f-c47ddc7f9050}</uuid>
303 <visible>true</visible>
304 <midichan>0</midichan>
305 <midicc>0</midicc>
306 <type>value</type>
307 <pressedValue>1.00000000</pressedValue>
308 <stringvalue>sample.wav</stringvalue>
309 <text>Browse Audio File</text>
310 <image>/</image>
311 <eventLine/>
312 <latch>false</latch>
313 <latched>false</latched>
314 </bsbObject>
315 <bsbObject version="2" type="BSBLineEdit">
316 <objectName>_Browse</objectName>
317 <x>178</x>
318 <y>248</y>
319 <width>330</width>
320 <height>28</height>
321 <uuid>{68b5f90b-b78e-4581-b434-232db5f4c40f}</uuid>
322 <visible>true</visible>
323 <midichan>0</midichan>
324 <midicc>0</midicc>
325 <label>sample.wav</label>
326 <alignment>left</alignment>
327 <font>Arial</font>
328 <fontsize>10</fontsize>
329 <precision>3</precision>
330 <color>
331 <r>0</r>
332 <g>0</g>
333 <b>0</b>
334 </color>
335 <bgcolor mode="nobackground">
336 <r>229</r>
337 <g>229</g>
338 <b>229</b>
339 </bgcolor>
340 <background>nobackground</background>
341 </bsbObject>
342 <bsbObject version="2" type="BSBDisplay">
343 <objectName>Level</objectName>
344 <x>448</x>
345 <y>121</y>
346 <width>60</width>
347 <height>30</height>
348 <uuid>{e18e15d6-c58d-4c38-a766-79602b72f947}</uuid>
349 <visible>true</visible>
350 <midichan>0</midichan>
351 <midicc>0</midicc>
352 <label>10.000</label>
353 <alignment>right</alignment>
354 <font>Arial</font>
355 <fontsize>9</fontsize>
356 <precision>3</precision>
357 <color>
358 <r>0</r>
359 <g>0</g>
360 <b>0</b>
361 </color>
362 <bgcolor mode="nobackground">
363 <r>255</r>
364 <g>255</g>
365 <b>255</b>
366 </bgcolor>
367 <bordermode>noborder</bordermode>
368 <borderradius>1</borderradius>
369 <borderwidth>1</borderwidth>
370 </bsbObject>
371 <bsbObject version="2" type="BSBHSlider">
372 <objectName>Level</objectName>
373 <x>8</x>
374 <y>99</y>
375 <width>500</width>
376 <height>27</height>
377 <uuid>{36779c76-0b42-4e18-819b-e02bf72d22dd}</uuid>
378 <visible>true</visible>
379 <midichan>0</midichan>
380 <midicc>0</midicc>
381 <minimum>0.00000000</minimum>
382 <maximum>100.00000000</maximum>
383 <value>10.00000000</value>
384 <mode>lin</mode>
385 <mouseControl act="jump">continuous</mouseControl>
386 <resolution>-1.00000000</resolution>
387 <randomizable group="0">false</randomizable>
388 </bsbObject>
389 <bsbObject version="2" type="BSBLabel">
390 <objectName/>
391 <x>8</x>
392 <y>121</y>
393 <width>150</width>
394 <height>30</height>
395 <uuid>{b74148fe-3ba3-4d62-b507-64eb27627e65}</uuid>
396 <visible>true</visible>
397 <midichan>0</midichan>
398 <midicc>0</midicc>
399 <label>Level</label>
400 <alignment>left</alignment>
401 <font>Arial</font>
402 <fontsize>10</fontsize>
403 <precision>3</precision>
404 <color>
405 <r>0</r>
406 <g>0</g>
407 <b>0</b>
408 </color>
409 <bgcolor mode="nobackground">
410 <r>255</r>
411 <g>255</g>
412 <b>255</b>
413 </bgcolor>
414 <bordermode>noborder</bordermode>
415 <borderradius>1</borderradius>
416 <borderwidth>1</borderwidth>
417 </bsbObject>
418 <bsbObject version="2" type="BSBDisplay">
419 <objectName>DryWet</objectName>
420 <x>448</x>
421 <y>169</y>
422 <width>60</width>
423 <height>30</height>
424 <uuid>{3c299cf9-f5e6-4902-9f6c-4d3802f1beb8}</uuid>
425 <visible>true</visible>
426 <midichan>0</midichan>
427 <midicc>0</midicc>
428 <label>1.000</label>
429 <alignment>right</alignment>
430 <font>Arial</font>
431 <fontsize>9</fontsize>
432 <precision>3</precision>
433 <color>
434 <r>0</r>
435 <g>0</g>
436 <b>0</b>
437 </color>
438 <bgcolor mode="nobackground">
439 <r>255</r>
440 <g>255</g>
441 <b>255</b>
442 </bgcolor>
443 <bordermode>noborder</bordermode>
444 <borderradius>1</borderradius>
445 <borderwidth>1</borderwidth>
446 </bsbObject>
447 <bsbObject version="2" type="BSBHSlider">
448 <objectName>DryWet</objectName>
449 <x>8</x>
450 <y>147</y>
451 <width>500</width>
452 <height>27</height>
453 <uuid>{b96a19b5-e2ff-4bc8-9d9c-e1878dc2c7ea}</uuid>
454 <visible>true</visible>
455 <midichan>0</midichan>
456 <midicc>0</midicc>
457 <minimum>0.00000000</minimum>
458 <maximum>1.00000000</maximum>
459 <value>1.00000000</value>
460 <mode>lin</mode>
461 <mouseControl act="jump">continuous</mouseControl>
462 <resolution>-1.00000000</resolution>
463 <randomizable group="0">false</randomizable>
464 </bsbObject>
465 <bsbObject version="2" type="BSBLabel">
466 <objectName/>
467 <x>8</x>
468 <y>169</y>
469 <width>150</width>
470 <height>30</height>
471 <uuid>{3f67483e-a5a5-4c55-8c4c-802b8cb45fcb}</uuid>
472 <visible>true</visible>
473 <midichan>0</midichan>
474 <midicc>0</midicc>
475 <label>Dry/Wet Mix</label>
476 <alignment>left</alignment>
477 <font>Arial</font>
478 <fontsize>10</fontsize>
479 <precision>3</precision>
480 <color>
481 <r>0</r>
482 <g>0</g>
483 <b>0</b>
484 </color>
485 <bgcolor mode="nobackground">
486 <r>255</r>
487 <g>255</g>
488 <b>255</b>
489 </bgcolor>
490 <bordermode>noborder</bordermode>
491 <borderradius>1</borderradius>
492 <borderwidth>1</borderwidth>
493 </bsbObject>
494 <bsbObject version="2" type="BSBDisplay">
495 <objectName>OutGain</objectName>
496 <x>448</x>
497 <y>217</y>
498 <width>60</width>
499 <height>30</height>
500 <uuid>{44e73856-6869-4340-96a9-e5a61ecd5938}</uuid>
501 <visible>true</visible>
502 <midichan>0</midichan>
503 <midicc>0</midicc>
504 <label>1.004</label>
505 <alignment>right</alignment>
506 <font>Arial</font>
507 <fontsize>9</fontsize>
508 <precision>3</precision>
509 <color>
510 <r>0</r>
511 <g>0</g>
512 <b>0</b>
513 </color>
514 <bgcolor mode="nobackground">
515 <r>255</r>
516 <g>255</g>
517 <b>255</b>
518 </bgcolor>
519 <bordermode>noborder</bordermode>
520 <borderradius>1</borderradius>
521 <borderwidth>1</borderwidth>
522 </bsbObject>
523 <bsbObject version="2" type="BSBHSlider">
524 <objectName>OutGain</objectName>
525 <x>8</x>
526 <y>195</y>
527 <width>500</width>
528 <height>27</height>
529 <uuid>{484ef1b1-d231-454a-b908-cadd3e9dcbc1}</uuid>
530 <visible>true</visible>
531 <midichan>0</midichan>
532 <midicc>0</midicc>
533 <minimum>0.00000000</minimum>
534 <maximum>2.00000000</maximum>
535 <value>1.00400000</value>
536 <mode>lin</mode>
537 <mouseControl act="jump">continuous</mouseControl>
538 <resolution>-1.00000000</resolution>
539 <randomizable group="0">false</randomizable>
540 </bsbObject>
541 <bsbObject version="2" type="BSBLabel">
542 <objectName/>
543 <x>8</x>
544 <y>217</y>
545 <width>150</width>
546 <height>30</height>
547 <uuid>{07143124-f11e-43ad-9bad-2a731b719732}</uuid>
548 <visible>true</visible>
549 <midichan>0</midichan>
550 <midicc>0</midicc>
551 <label>Output Gain</label>
552 <alignment>left</alignment>
553 <font>Arial</font>
554 <fontsize>10</fontsize>
555 <precision>3</precision>
556 <color>
557 <r>0</r>
558 <g>0</g>
559 <b>0</b>
560 </color>
561 <bgcolor mode="nobackground">
562 <r>255</r>
563 <g>255</g>
564 <b>255</b>
565 </bgcolor>
566 <bordermode>noborder</bordermode>
567 <borderradius>1</borderradius>
568 <borderwidth>1</borderwidth>
569 </bsbObject>
570 </bsbPanel>
571 <bsbPresets>
572 </bsbPresets>
573 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>