Debian Codegraph @

src/Examples/McCurdy Collection/Filters/butterbr.csd

raw
1 ;Written by Iain McCurdy, 2006
2
3 ;Modified for QuteCsound by René, October 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 = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20
21
22 ;TABLES FOR EXP SLIDER
23 giExp1_20000 ftgen 0, 0, 129, -25, 0, 1.0, 128, 20000.0
24 giExp20_20000 ftgen 0, 0, 129, -25, 0, 20.0, 128, 20000.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 1 ;GUI
42
43 Sfile_new strcpy "" ;INIT TO EMPTY STRING
44
45 ktrig metro 10
46 if (ktrig == 1) then
47 kfreq invalue "Filter_Cutoff"
48 gkfreq tablei kfreq, giExp20_20000, 1
49 outvalue "Filter_Cutoff_Value", gkfreq ;init 900.0
50 kband invalue "Bandwidth"
51 gkband tablei kband, giExp1_20000, 1
52 outvalue "Bandwidth_Value", gkband ;init 1000.0
53 gkgain invalue "Amplitude"
54
55 gkskip invalue "Initialisation"
56
57 gSfile invalue "_Browse"
58 Sfile_old strcpyk Sfile_new
59 Sfile_new strcpyk gSfile
60 gkfile strcmpk Sfile_new, Sfile_old
61 endif
62 endin
63
64 instr 2
65 kporttime linseg 0,0.001,0.005,1,0.005 ;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
66 kfreq portk gkfreq, kporttime ;SMOOTH MOVEMENT OF SLIDER VARIABLE
67 kband portk gkband, kporttime ;SMOOTH MOVEMENT OF SLIDER VARIABLE
68
69 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)
70 if kNew_file=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
71 reinit NEW_FILE ;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
72 endif
73 NEW_FILE:
74 ;OUTPUTS OPCODE FILE | SPEED | INSKIP | LOOPING (0=OFF 1=ON)
75 asigL, asigR FilePlay2 gSfile, 1, 0, 1 ;GENERATE 2 AUDIO SIGNALS FROM A STEREO SOUND FILE
76 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
77
78 kSwitch changed gkskip ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
79 if kSwitch=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
80 reinit START ;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
81 endif
82 START:
83 aresL butbr asigL, kfreq, kband, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
84 aresR butbr asigR, kfreq, kband, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
85
86 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
87 outs aresL * gkgain, aresR * gkgain ;SEND FILTER OUTPUT TO THE AUDIO OUTPUTS, RESCALE USING SLIDER VARIABLE gkgain
88 endin
89 </CsInstruments>
90 <CsScore>
91 ;INSTR | START | DURATION
92 i 1 0 3600 ;INSTRUMENT 1 PLAYS FOR 1 HOUR
93 </CsScore>
94 </CsoundSynthesizer>
95
96 <bsbPanel>
97 <label>Widgets</label>
98 <objectName/>
99 <x>214</x>
100 <y>275</y>
101 <width>861</width>
102 <height>297</height>
103 <visible>true</visible>
104 <uuid/>
105 <bgcolor mode="background">
106 <r>241</r>
107 <g>226</g>
108 <b>185</b>
109 </bgcolor>
110 <bsbObject version="2" type="BSBLabel">
111 <objectName/>
112 <x>2</x>
113 <y>2</y>
114 <width>512</width>
115 <height>292</height>
116 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
117 <visible>true</visible>
118 <midichan>0</midichan>
119 <midicc>0</midicc>
120 <label>butterbr / butbr</label>
121 <alignment>center</alignment>
122 <font>Liberation Sans</font>
123 <fontsize>18</fontsize>
124 <precision>3</precision>
125 <color>
126 <r>0</r>
127 <g>0</g>
128 <b>0</b>
129 </color>
130 <bgcolor mode="background">
131 <r>106</r>
132 <g>117</g>
133 <b>150</b>
134 </bgcolor>
135 <bordermode>border</bordermode>
136 <borderradius>5</borderradius>
137 <borderwidth>2</borderwidth>
138 </bsbObject>
139 <bsbObject version="2" type="BSBLabel">
140 <objectName/>
141 <x>515</x>
142 <y>2</y>
143 <width>340</width>
144 <height>292</height>
145 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
146 <visible>true</visible>
147 <midichan>0</midichan>
148 <midicc>0</midicc>
149 <label>butterbr / butbr</label>
150 <alignment>center</alignment>
151 <font>Liberation Sans</font>
152 <fontsize>18</fontsize>
153 <precision>3</precision>
154 <color>
155 <r>0</r>
156 <g>0</g>
157 <b>0</b>
158 </color>
159 <bgcolor mode="background">
160 <r>106</r>
161 <g>117</g>
162 <b>150</b>
163 </bgcolor>
164 <bordermode>border</bordermode>
165 <borderradius>5</borderradius>
166 <borderwidth>2</borderwidth>
167 </bsbObject>
168 <bsbObject version="2" type="BSBLabel">
169 <objectName/>
170 <x>516</x>
171 <y>15</y>
172 <width>334</width>
173 <height>274</height>
174 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
175 <visible>true</visible>
176 <midichan>0</midichan>
177 <midicc>0</midicc>
178 <label>---------------------------------------------------------------------------------
179 butterbr/butbr is an implementation of a second-order IIR Butterworth band-reject filter. Its input arguments are for filter cutoff frequency (in hertz), and bandwidth (also in hertz) of the spectral band removed by the filter. An optional 2-way switch (default=0) is provided to select whether the data space for feedback within the filter is initially cleared or allowed to retain previously held information. butterbr/butbr is slower than the original filters in Csound but provides an almost flat passband (particularly when compared to the areson filter). Multiple iterations of the butterbr/butbr opcode applied to the signal path in series can be used to create a sharper cutoff slope. The audible results of the butterbr/butbr filter are not dissimilar to those of a phaser effect.</label>
180 <alignment>left</alignment>
181 <font>Arial</font>
182 <fontsize>14</fontsize>
183 <precision>3</precision>
184 <color>
185 <r>0</r>
186 <g>0</g>
187 <b>0</b>
188 </color>
189 <bgcolor mode="nobackground">
190 <r>255</r>
191 <g>255</g>
192 <b>255</b>
193 </bgcolor>
194 <bordermode>noborder</bordermode>
195 <borderradius>1</borderradius>
196 <borderwidth>1</borderwidth>
197 </bsbObject>
198 <bsbObject version="2" type="BSBButton">
199 <objectName/>
200 <x>8</x>
201 <y>8</y>
202 <width>100</width>
203 <height>30</height>
204 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
205 <visible>true</visible>
206 <midichan>0</midichan>
207 <midicc>0</midicc>
208 <type>event</type>
209 <pressedValue>1.00000000</pressedValue>
210 <stringvalue/>
211 <text> ON / OFF</text>
212 <image>/</image>
213 <eventLine>i 2 0 -1</eventLine>
214 <latch>true</latch>
215 <latched>false</latched>
216 </bsbObject>
217 <bsbObject version="2" type="BSBDisplay">
218 <objectName>Filter_Cutoff_Value</objectName>
219 <x>448</x>
220 <y>118</y>
221 <width>60</width>
222 <height>30</height>
223 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
224 <visible>true</visible>
225 <midichan>0</midichan>
226 <midicc>0</midicc>
227 <label>528.650</label>
228 <alignment>right</alignment>
229 <font>Arial</font>
230 <fontsize>9</fontsize>
231 <precision>3</precision>
232 <color>
233 <r>0</r>
234 <g>0</g>
235 <b>0</b>
236 </color>
237 <bgcolor mode="nobackground">
238 <r>255</r>
239 <g>255</g>
240 <b>255</b>
241 </bgcolor>
242 <bordermode>noborder</bordermode>
243 <borderradius>1</borderradius>
244 <borderwidth>1</borderwidth>
245 </bsbObject>
246 <bsbObject version="2" type="BSBHSlider">
247 <objectName>Filter_Cutoff</objectName>
248 <x>8</x>
249 <y>101</y>
250 <width>500</width>
251 <height>27</height>
252 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
253 <visible>true</visible>
254 <midichan>0</midichan>
255 <midicc>0</midicc>
256 <minimum>0.00000000</minimum>
257 <maximum>1.00000000</maximum>
258 <value>0.47400000</value>
259 <mode>lin</mode>
260 <mouseControl act="jump">continuous</mouseControl>
261 <resolution>-1.00000000</resolution>
262 <randomizable group="0">false</randomizable>
263 </bsbObject>
264 <bsbObject version="2" type="BSBLabel">
265 <objectName/>
266 <x>8</x>
267 <y>118</y>
268 <width>180</width>
269 <height>30</height>
270 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
271 <visible>true</visible>
272 <midichan>0</midichan>
273 <midicc>0</midicc>
274 <label>Filter Cutoff</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="BSBButton">
294 <objectName>_Browse</objectName>
295 <x>8</x>
296 <y>254</y>
297 <width>170</width>
298 <height>30</height>
299 <uuid>{b9431a61-61f7-432b-bf6f-c47ddc7f9050}</uuid>
300 <visible>true</visible>
301 <midichan>0</midichan>
302 <midicc>0</midicc>
303 <type>value</type>
304 <pressedValue>1.00000000</pressedValue>
305 <stringvalue>Seashore.wav</stringvalue>
306 <text>Browse Audio File</text>
307 <image>/</image>
308 <eventLine/>
309 <latch>false</latch>
310 <latched>false</latched>
311 </bsbObject>
312 <bsbObject version="2" type="BSBLineEdit">
313 <objectName>_Browse</objectName>
314 <x>179</x>
315 <y>255</y>
316 <width>330</width>
317 <height>28</height>
318 <uuid>{68b5f90b-b78e-4581-b434-232db5f4c40f}</uuid>
319 <visible>true</visible>
320 <midichan>0</midichan>
321 <midicc>0</midicc>
322 <label>Seashore.wav</label>
323 <alignment>left</alignment>
324 <font>Arial</font>
325 <fontsize>10</fontsize>
326 <precision>3</precision>
327 <color>
328 <r>0</r>
329 <g>0</g>
330 <b>0</b>
331 </color>
332 <bgcolor mode="nobackground">
333 <r>229</r>
334 <g>229</g>
335 <b>229</b>
336 </bgcolor>
337 <background>nobackground</background>
338 </bsbObject>
339 <bsbObject version="2" type="BSBLabel">
340 <objectName/>
341 <x>8</x>
342 <y>233</y>
343 <width>150</width>
344 <height>30</height>
345 <uuid>{936f6eb0-5225-4bd7-a5fe-a49df1c9c5ac}</uuid>
346 <visible>true</visible>
347 <midichan>0</midichan>
348 <midicc>0</midicc>
349 <label>Audio File</label>
350 <alignment>left</alignment>
351 <font>Arial</font>
352 <fontsize>10</fontsize>
353 <precision>3</precision>
354 <color>
355 <r>0</r>
356 <g>0</g>
357 <b>0</b>
358 </color>
359 <bgcolor mode="nobackground">
360 <r>255</r>
361 <g>255</g>
362 <b>255</b>
363 </bgcolor>
364 <bordermode>noborder</bordermode>
365 <borderradius>1</borderradius>
366 <borderwidth>1</borderwidth>
367 </bsbObject>
368 <bsbObject version="2" type="BSBLabel">
369 <objectName/>
370 <x>8</x>
371 <y>203</y>
372 <width>180</width>
373 <height>30</height>
374 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
375 <visible>true</visible>
376 <midichan>0</midichan>
377 <midicc>0</midicc>
378 <label>Output Amplitude Scaling</label>
379 <alignment>left</alignment>
380 <font>Arial</font>
381 <fontsize>10</fontsize>
382 <precision>3</precision>
383 <color>
384 <r>0</r>
385 <g>0</g>
386 <b>0</b>
387 </color>
388 <bgcolor mode="nobackground">
389 <r>255</r>
390 <g>255</g>
391 <b>255</b>
392 </bgcolor>
393 <bordermode>noborder</bordermode>
394 <borderradius>1</borderradius>
395 <borderwidth>1</borderwidth>
396 </bsbObject>
397 <bsbObject version="2" type="BSBHSlider">
398 <objectName>Amplitude</objectName>
399 <x>8</x>
400 <y>186</y>
401 <width>500</width>
402 <height>27</height>
403 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
404 <visible>true</visible>
405 <midichan>0</midichan>
406 <midicc>0</midicc>
407 <minimum>0.00000000</minimum>
408 <maximum>2.00000000</maximum>
409 <value>1.07600000</value>
410 <mode>lin</mode>
411 <mouseControl act="jump">continuous</mouseControl>
412 <resolution>-1.00000000</resolution>
413 <randomizable group="0">false</randomizable>
414 </bsbObject>
415 <bsbObject version="2" type="BSBDisplay">
416 <objectName>Amplitude</objectName>
417 <x>448</x>
418 <y>203</y>
419 <width>60</width>
420 <height>30</height>
421 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
422 <visible>true</visible>
423 <midichan>0</midichan>
424 <midicc>0</midicc>
425 <label>1.076</label>
426 <alignment>right</alignment>
427 <font>Arial</font>
428 <fontsize>9</fontsize>
429 <precision>3</precision>
430 <color>
431 <r>0</r>
432 <g>0</g>
433 <b>0</b>
434 </color>
435 <bgcolor mode="nobackground">
436 <r>255</r>
437 <g>255</g>
438 <b>255</b>
439 </bgcolor>
440 <bordermode>noborder</bordermode>
441 <borderradius>1</borderradius>
442 <borderwidth>1</borderwidth>
443 </bsbObject>
444 <bsbObject version="2" type="BSBButton">
445 <objectName>Initialisation</objectName>
446 <x>380</x>
447 <y>52</y>
448 <width>130</width>
449 <height>30</height>
450 <uuid>{b6345774-7938-4e62-9d8b-0ada81f7bcc5}</uuid>
451 <visible>true</visible>
452 <midichan>0</midichan>
453 <midicc>0</midicc>
454 <type>value</type>
455 <pressedValue>1.00000000</pressedValue>
456 <stringvalue/>
457 <text> No Initialisation</text>
458 <image>/</image>
459 <eventLine/>
460 <latch>true</latch>
461 <latched>false</latched>
462 </bsbObject>
463 <bsbObject version="2" type="BSBLabel">
464 <objectName/>
465 <x>8</x>
466 <y>156</y>
467 <width>180</width>
468 <height>30</height>
469 <uuid>{4b8cc27a-e102-4e54-abd9-b563c507ee44}</uuid>
470 <visible>true</visible>
471 <midichan>0</midichan>
472 <midicc>0</midicc>
473 <label>Bandwidth</label>
474 <alignment>left</alignment>
475 <font>Arial</font>
476 <fontsize>10</fontsize>
477 <precision>3</precision>
478 <color>
479 <r>0</r>
480 <g>0</g>
481 <b>0</b>
482 </color>
483 <bgcolor mode="nobackground">
484 <r>255</r>
485 <g>255</g>
486 <b>255</b>
487 </bgcolor>
488 <bordermode>noborder</bordermode>
489 <borderradius>1</borderradius>
490 <borderwidth>1</borderwidth>
491 </bsbObject>
492 <bsbObject version="2" type="BSBHSlider">
493 <objectName>Bandwidth</objectName>
494 <x>8</x>
495 <y>139</y>
496 <width>500</width>
497 <height>27</height>
498 <uuid>{eec983db-87f2-4ff0-b409-ed8ec573b9ae}</uuid>
499 <visible>true</visible>
500 <midichan>0</midichan>
501 <midicc>0</midicc>
502 <minimum>0.00000000</minimum>
503 <maximum>1.00000000</maximum>
504 <value>0.72600000</value>
505 <mode>lin</mode>
506 <mouseControl act="jump">continuous</mouseControl>
507 <resolution>-1.00000000</resolution>
508 <randomizable group="0">false</randomizable>
509 </bsbObject>
510 <bsbObject version="2" type="BSBDisplay">
511 <objectName>Bandwidth_Value</objectName>
512 <x>448</x>
513 <y>156</y>
514 <width>60</width>
515 <height>30</height>
516 <uuid>{bf739784-7c38-4ecb-90ac-9a603e010479}</uuid>
517 <visible>true</visible>
518 <midichan>0</midichan>
519 <midicc>0</midicc>
520 <label>1326.266</label>
521 <alignment>right</alignment>
522 <font>Arial</font>
523 <fontsize>9</fontsize>
524 <precision>3</precision>
525 <color>
526 <r>0</r>
527 <g>0</g>
528 <b>0</b>
529 </color>
530 <bgcolor mode="nobackground">
531 <r>255</r>
532 <g>255</g>
533 <b>255</b>
534 </bgcolor>
535 <bordermode>noborder</bordermode>
536 <borderradius>1</borderradius>
537 <borderwidth>1</borderwidth>
538 </bsbObject>
539 </bsbPanel>
540 <bsbPresets>
541 </bsbPresets>
542 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="false" loopStart="0" loopEnd="0"> </EventPanel>