Debian Codegraph @

src/Examples/McCurdy Collection/Filters/butterbp.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 = 2 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20
21
22 ;TABLES FOR EXP SLIDER
23 giExp10000 ftgen 0, 0, 129, -25, 0, 1.0, 128, 10000.0
24 giExp20000 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, giExp20000, 1
49 outvalue "Filter_Cutoff_Value", gkfreq
50 kband invalue "Bandwidth"
51 gkband tablei kband, giExp10000, 1
52 outvalue "Bandwidth_Value", gkband
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 butbp asigL, kfreq, kband, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
84 aresR butbp asigR, kfreq, kband, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
85 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
86 outs aresL * gkgain, aresR * gkgain ;SEND FILTER OUTPUT TO THE AUDIO OUTPUTS, RESCALE USING SLIDER VARIABLE gkgain
87 endin
88 </CsInstruments>
89 <CsScore>
90 ;INSTR | START | DURATION
91 i 1 0 3600 ;INSTRUMENT 1 PLAYS FOR 1 HOUR
92 </CsScore>
93 </CsoundSynthesizer>
94
95 <bsbPanel>
96 <label>Widgets</label>
97 <objectName/>
98 <x>72</x>
99 <y>179</y>
100 <width>400</width>
101 <height>200</height>
102 <visible>true</visible>
103 <uuid/>
104 <bgcolor mode="background">
105 <r>241</r>
106 <g>226</g>
107 <b>185</b>
108 </bgcolor>
109 <bsbObject version="2" type="BSBLabel">
110 <objectName/>
111 <x>2</x>
112 <y>2</y>
113 <width>512</width>
114 <height>292</height>
115 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
116 <visible>true</visible>
117 <midichan>0</midichan>
118 <midicc>0</midicc>
119 <label>butterbp / butbp</label>
120 <alignment>center</alignment>
121 <font>Liberation Sans</font>
122 <fontsize>18</fontsize>
123 <precision>3</precision>
124 <color>
125 <r>0</r>
126 <g>0</g>
127 <b>0</b>
128 </color>
129 <bgcolor mode="background">
130 <r>106</r>
131 <g>117</g>
132 <b>150</b>
133 </bgcolor>
134 <bordermode>border</bordermode>
135 <borderradius>5</borderradius>
136 <borderwidth>2</borderwidth>
137 </bsbObject>
138 <bsbObject version="2" type="BSBLabel">
139 <objectName/>
140 <x>515</x>
141 <y>2</y>
142 <width>318</width>
143 <height>292</height>
144 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
145 <visible>true</visible>
146 <midichan>0</midichan>
147 <midicc>0</midicc>
148 <label>butterbp / butbp</label>
149 <alignment>center</alignment>
150 <font>Liberation Sans</font>
151 <fontsize>18</fontsize>
152 <precision>3</precision>
153 <color>
154 <r>0</r>
155 <g>0</g>
156 <b>0</b>
157 </color>
158 <bgcolor mode="background">
159 <r>106</r>
160 <g>117</g>
161 <b>150</b>
162 </bgcolor>
163 <bordermode>border</bordermode>
164 <borderradius>5</borderradius>
165 <borderwidth>2</borderwidth>
166 </bsbObject>
167 <bsbObject version="2" type="BSBLabel">
168 <objectName/>
169 <x>516</x>
170 <y>15</y>
171 <width>314</width>
172 <height>274</height>
173 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
174 <visible>true</visible>
175 <midichan>0</midichan>
176 <midicc>0</midicc>
177 <label>----------------------------------------------------------------------------
178 butterbp/butbp is an implementation of a second-order IIR Butterworth band-pass filter. Its input arguments are for filter cutoff frequency (in hertz), and bandwidth (also in hertz) of the spectral band that is allowed to pass through 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. butterbp/butbp is slower than the original filters in Csound but provides an almost flat passband (particularly when compared to the reson filter). Multiple iterations of the butterbp/butbp opcode applied to the signal path in series can be used to create a sharper cutoff slope.</label>
179 <alignment>left</alignment>
180 <font>Arial</font>
181 <fontsize>14</fontsize>
182 <precision>3</precision>
183 <color>
184 <r>0</r>
185 <g>0</g>
186 <b>0</b>
187 </color>
188 <bgcolor mode="nobackground">
189 <r>255</r>
190 <g>255</g>
191 <b>255</b>
192 </bgcolor>
193 <bordermode>noborder</bordermode>
194 <borderradius>1</borderradius>
195 <borderwidth>1</borderwidth>
196 </bsbObject>
197 <bsbObject version="2" type="BSBButton">
198 <objectName/>
199 <x>8</x>
200 <y>8</y>
201 <width>100</width>
202 <height>30</height>
203 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
204 <visible>true</visible>
205 <midichan>0</midichan>
206 <midicc>0</midicc>
207 <type>event</type>
208 <pressedValue>1.00000000</pressedValue>
209 <stringvalue/>
210 <text> ON / OFF</text>
211 <image>/</image>
212 <eventLine>i 2 0 -1</eventLine>
213 <latch>true</latch>
214 <latched>false</latched>
215 </bsbObject>
216 <bsbObject version="2" type="BSBDisplay">
217 <objectName>Filter_Cutoff_Value</objectName>
218 <x>448</x>
219 <y>118</y>
220 <width>60</width>
221 <height>30</height>
222 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
223 <visible>true</visible>
224 <midichan>0</midichan>
225 <midicc>0</midicc>
226 <label>833.869</label>
227 <alignment>right</alignment>
228 <font>Arial</font>
229 <fontsize>9</fontsize>
230 <precision>3</precision>
231 <color>
232 <r>0</r>
233 <g>0</g>
234 <b>0</b>
235 </color>
236 <bgcolor mode="nobackground">
237 <r>255</r>
238 <g>255</g>
239 <b>255</b>
240 </bgcolor>
241 <bordermode>noborder</bordermode>
242 <borderradius>1</borderradius>
243 <borderwidth>1</borderwidth>
244 </bsbObject>
245 <bsbObject version="2" type="BSBHSlider">
246 <objectName>Filter_Cutoff</objectName>
247 <x>8</x>
248 <y>101</y>
249 <width>500</width>
250 <height>27</height>
251 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
252 <visible>true</visible>
253 <midichan>0</midichan>
254 <midicc>0</midicc>
255 <minimum>0.00000000</minimum>
256 <maximum>1.00000000</maximum>
257 <value>0.54000000</value>
258 <mode>lin</mode>
259 <mouseControl act="jump">continuous</mouseControl>
260 <resolution>-1.00000000</resolution>
261 <randomizable group="0">false</randomizable>
262 </bsbObject>
263 <bsbObject version="2" type="BSBLabel">
264 <objectName/>
265 <x>8</x>
266 <y>118</y>
267 <width>180</width>
268 <height>30</height>
269 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
270 <visible>true</visible>
271 <midichan>0</midichan>
272 <midicc>0</midicc>
273 <label>Filter Cutoff</label>
274 <alignment>left</alignment>
275 <font>Arial</font>
276 <fontsize>10</fontsize>
277 <precision>3</precision>
278 <color>
279 <r>0</r>
280 <g>0</g>
281 <b>0</b>
282 </color>
283 <bgcolor mode="nobackground">
284 <r>255</r>
285 <g>255</g>
286 <b>255</b>
287 </bgcolor>
288 <bordermode>noborder</bordermode>
289 <borderradius>1</borderradius>
290 <borderwidth>1</borderwidth>
291 </bsbObject>
292 <bsbObject version="2" type="BSBButton">
293 <objectName>_Browse</objectName>
294 <x>8</x>
295 <y>254</y>
296 <width>170</width>
297 <height>30</height>
298 <uuid>{b9431a61-61f7-432b-bf6f-c47ddc7f9050}</uuid>
299 <visible>true</visible>
300 <midichan>0</midichan>
301 <midicc>0</midicc>
302 <type>value</type>
303 <pressedValue>1.00000000</pressedValue>
304 <stringvalue>Seashore.wav</stringvalue>
305 <text>Browse Audio File</text>
306 <image>/</image>
307 <eventLine/>
308 <latch>false</latch>
309 <latched>false</latched>
310 </bsbObject>
311 <bsbObject version="2" type="BSBLineEdit">
312 <objectName>_Browse</objectName>
313 <x>179</x>
314 <y>255</y>
315 <width>330</width>
316 <height>28</height>
317 <uuid>{68b5f90b-b78e-4581-b434-232db5f4c40f}</uuid>
318 <visible>true</visible>
319 <midichan>0</midichan>
320 <midicc>0</midicc>
321 <label>Seashore.wav</label>
322 <alignment>left</alignment>
323 <font>Arial</font>
324 <fontsize>10</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>229</r>
333 <g>229</g>
334 <b>229</b>
335 </bgcolor>
336 <background>nobackground</background>
337 </bsbObject>
338 <bsbObject version="2" type="BSBLabel">
339 <objectName/>
340 <x>8</x>
341 <y>233</y>
342 <width>150</width>
343 <height>30</height>
344 <uuid>{936f6eb0-5225-4bd7-a5fe-a49df1c9c5ac}</uuid>
345 <visible>true</visible>
346 <midichan>0</midichan>
347 <midicc>0</midicc>
348 <label>Audio File</label>
349 <alignment>left</alignment>
350 <font>Arial</font>
351 <fontsize>10</fontsize>
352 <precision>3</precision>
353 <color>
354 <r>0</r>
355 <g>0</g>
356 <b>0</b>
357 </color>
358 <bgcolor mode="nobackground">
359 <r>255</r>
360 <g>255</g>
361 <b>255</b>
362 </bgcolor>
363 <bordermode>noborder</bordermode>
364 <borderradius>1</borderradius>
365 <borderwidth>1</borderwidth>
366 </bsbObject>
367 <bsbObject version="2" type="BSBLabel">
368 <objectName/>
369 <x>8</x>
370 <y>203</y>
371 <width>180</width>
372 <height>30</height>
373 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
374 <visible>true</visible>
375 <midichan>0</midichan>
376 <midicc>0</midicc>
377 <label>Output Amplitude Scaling</label>
378 <alignment>left</alignment>
379 <font>Arial</font>
380 <fontsize>10</fontsize>
381 <precision>3</precision>
382 <color>
383 <r>0</r>
384 <g>0</g>
385 <b>0</b>
386 </color>
387 <bgcolor mode="nobackground">
388 <r>255</r>
389 <g>255</g>
390 <b>255</b>
391 </bgcolor>
392 <bordermode>noborder</bordermode>
393 <borderradius>1</borderradius>
394 <borderwidth>1</borderwidth>
395 </bsbObject>
396 <bsbObject version="2" type="BSBHSlider">
397 <objectName>Amplitude</objectName>
398 <x>8</x>
399 <y>186</y>
400 <width>500</width>
401 <height>27</height>
402 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
403 <visible>true</visible>
404 <midichan>0</midichan>
405 <midicc>0</midicc>
406 <minimum>0.00000000</minimum>
407 <maximum>2.00000000</maximum>
408 <value>0.91600000</value>
409 <mode>lin</mode>
410 <mouseControl act="jump">continuous</mouseControl>
411 <resolution>-1.00000000</resolution>
412 <randomizable group="0">false</randomizable>
413 </bsbObject>
414 <bsbObject version="2" type="BSBDisplay">
415 <objectName>Amplitude</objectName>
416 <x>448</x>
417 <y>203</y>
418 <width>60</width>
419 <height>30</height>
420 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
421 <visible>true</visible>
422 <midichan>0</midichan>
423 <midicc>0</midicc>
424 <label>0.916</label>
425 <alignment>right</alignment>
426 <font>Arial</font>
427 <fontsize>9</fontsize>
428 <precision>3</precision>
429 <color>
430 <r>0</r>
431 <g>0</g>
432 <b>0</b>
433 </color>
434 <bgcolor mode="nobackground">
435 <r>255</r>
436 <g>255</g>
437 <b>255</b>
438 </bgcolor>
439 <bordermode>noborder</bordermode>
440 <borderradius>1</borderradius>
441 <borderwidth>1</borderwidth>
442 </bsbObject>
443 <bsbObject version="2" type="BSBButton">
444 <objectName>Initialisation</objectName>
445 <x>380</x>
446 <y>52</y>
447 <width>130</width>
448 <height>30</height>
449 <uuid>{b6345774-7938-4e62-9d8b-0ada81f7bcc5}</uuid>
450 <visible>true</visible>
451 <midichan>0</midichan>
452 <midicc>0</midicc>
453 <type>value</type>
454 <pressedValue>1.00000000</pressedValue>
455 <stringvalue/>
456 <text> No Initialisation</text>
457 <image>/</image>
458 <eventLine/>
459 <latch>true</latch>
460 <latched>false</latched>
461 </bsbObject>
462 <bsbObject version="2" type="BSBLabel">
463 <objectName/>
464 <x>8</x>
465 <y>156</y>
466 <width>180</width>
467 <height>30</height>
468 <uuid>{4b8cc27a-e102-4e54-abd9-b563c507ee44}</uuid>
469 <visible>true</visible>
470 <midichan>0</midichan>
471 <midicc>0</midicc>
472 <label>Bandwidth</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>Bandwidth</objectName>
493 <x>8</x>
494 <y>139</y>
495 <width>500</width>
496 <height>27</height>
497 <uuid>{eec983db-87f2-4ff0-b409-ed8ec573b9ae}</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.71600000</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="BSBDisplay">
510 <objectName>Bandwidth_Value</objectName>
511 <x>448</x>
512 <y>156</y>
513 <width>60</width>
514 <height>30</height>
515 <uuid>{bf739784-7c38-4ecb-90ac-9a603e010479}</uuid>
516 <visible>true</visible>
517 <midichan>0</midichan>
518 <midicc>0</midicc>
519 <label>731.568</label>
520 <alignment>right</alignment>
521 <font>Arial</font>
522 <fontsize>9</fontsize>
523 <precision>3</precision>
524 <color>
525 <r>0</r>
526 <g>0</g>
527 <b>0</b>
528 </color>
529 <bgcolor mode="nobackground">
530 <r>255</r>
531 <g>255</g>
532 <b>255</b>
533 </bgcolor>
534 <bordermode>noborder</bordermode>
535 <borderradius>1</borderradius>
536 <borderwidth>1</borderwidth>
537 </bsbObject>
538 </bsbPanel>
539 <bsbPresets>
540 </bsbPresets>
541 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="false" loopStart="0" loopEnd="0"> </EventPanel>