Debian Codegraph @

src/Examples/McCurdy Collection/Filters/butterhp.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 giExp20_20000 ftgen 0, 0, 129, -25, 0, 20.0, 128, 20000.0 ;TABLE FOR EXP SLIDER
23
24
25 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz
26 ;gives stereo output regardless your soundfile is mono or stereo
27 Sfil, kspeed, iskip, iloop xin
28 ichn filenchnls Sfil
29 if ichn == 1 then
30 aL diskin2 Sfil, kspeed, iskip, iloop
31 aR = aL
32 else
33 aL, aR diskin2 Sfil, kspeed, iskip, iloop
34 endif
35 xout aL, aR
36 endop
37
38
39 instr 1 ;GUI
40
41 Sfile_new strcpy "" ;INIT TO EMPTY STRING
42
43 ktrig metro 10
44 if (ktrig == 1) then
45 kfreq invalue "Filter_Cutoff"
46 gkfreq tablei kfreq, giExp20_20000, 1
47 outvalue "Filter_Cutoff_Value", gkfreq
48 gkgain invalue "Amplitude"
49
50 gkskip invalue "Initialisation"
51
52 gSfile invalue "_Browse"
53 Sfile_old strcpyk Sfile_new
54 Sfile_new strcpyk gSfile
55 gkfile strcmpk Sfile_new, Sfile_old
56 endif
57 endin
58
59 instr 2
60 kporttime linseg 0,0.001,0.005,1,0.005 ;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
61 kfreq portk gkfreq, kporttime ;SMOOTH MOVEMENT OF SLIDER VARIABLE
62
63 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)
64 if kNew_file=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
65 reinit NEW_FILE ;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
66 endif
67 NEW_FILE:
68 ;OUTPUTS OPCODE FILE | SPEED | INSKIP | LOOPING (0=OFF 1=ON)
69 asigL, asigR FilePlay2 gSfile, 1, 0, 1 ;GENERATE 2 AUDIO SIGNALS FROM A STEREO SOUND FILE
70 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
71
72 kSwitch changed gkskip ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
73 if kSwitch=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
74 reinit START ;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
75 endif
76 START:
77 aresL buthp asigL, kfreq, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
78 aresR buthp asigR, kfreq, i(gkskip) ;FILTER EACH CHANNEL SEPARATELY
79
80 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
81 outs aresL * gkgain, aresR * gkgain ;SEND FILTER OUTPUT TO THE AUDIO OUTPUTS, RESCALE USING SLIDER VARIABLE gkgain
82 endin
83 </CsInstruments>
84 <CsScore>
85 ;INSTR | START | DURATION
86 i 1 0 3600 ;INSTRUMENT 1 PLAYS FOR 1 HOUR
87 </CsScore>
88 </CsoundSynthesizer>
89
90 <bsbPanel>
91 <label>Widgets</label>
92 <objectName/>
93 <x>305</x>
94 <y>267</y>
95 <width>864</width>
96 <height>297</height>
97 <visible>true</visible>
98 <uuid/>
99 <bgcolor mode="background">
100 <r>241</r>
101 <g>226</g>
102 <b>185</b>
103 </bgcolor>
104 <bsbObject version="2" type="BSBLabel">
105 <objectName/>
106 <x>2</x>
107 <y>2</y>
108 <width>512</width>
109 <height>292</height>
110 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
111 <visible>true</visible>
112 <midichan>0</midichan>
113 <midicc>0</midicc>
114 <label>butterhp / buthp</label>
115 <alignment>center</alignment>
116 <font>Liberation Sans</font>
117 <fontsize>18</fontsize>
118 <precision>3</precision>
119 <color>
120 <r>0</r>
121 <g>0</g>
122 <b>0</b>
123 </color>
124 <bgcolor mode="background">
125 <r>106</r>
126 <g>117</g>
127 <b>150</b>
128 </bgcolor>
129 <bordermode>border</bordermode>
130 <borderradius>5</borderradius>
131 <borderwidth>2</borderwidth>
132 </bsbObject>
133 <bsbObject version="2" type="BSBLabel">
134 <objectName/>
135 <x>515</x>
136 <y>2</y>
137 <width>340</width>
138 <height>292</height>
139 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
140 <visible>true</visible>
141 <midichan>0</midichan>
142 <midicc>0</midicc>
143 <label>butterhp / buthp</label>
144 <alignment>center</alignment>
145 <font>Liberation Sans</font>
146 <fontsize>18</fontsize>
147 <precision>3</precision>
148 <color>
149 <r>0</r>
150 <g>0</g>
151 <b>0</b>
152 </color>
153 <bgcolor mode="background">
154 <r>106</r>
155 <g>117</g>
156 <b>150</b>
157 </bgcolor>
158 <bordermode>border</bordermode>
159 <borderradius>5</borderradius>
160 <borderwidth>2</borderwidth>
161 </bsbObject>
162 <bsbObject version="2" type="BSBLabel">
163 <objectName/>
164 <x>516</x>
165 <y>25</y>
166 <width>333</width>
167 <height>251</height>
168 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
169 <visible>true</visible>
170 <midichan>0</midichan>
171 <midicc>0</midicc>
172 <label>---------------------------------------------------------------------------------
173 butterhp/buthp is an implementation of a second-order IIR Butterworth high-pass filter. Its input arguments are for filter cutoff frequency (in hertz) and an optional 2-way switch (default=0) to select whether the data space for feedback within the filter is initially cleared or allowed to retain previously held information. butterhp/buthp are slower than the original filters in Csound but provide an almost flat passband and very good precision and stopband attenuation Multiple iterations of the butterhp/buthp opcode applied to the signal path in series can be used to create a sharper cutoff slope.</label>
174 <alignment>left</alignment>
175 <font>Arial</font>
176 <fontsize>14</fontsize>
177 <precision>3</precision>
178 <color>
179 <r>0</r>
180 <g>0</g>
181 <b>0</b>
182 </color>
183 <bgcolor mode="nobackground">
184 <r>255</r>
185 <g>255</g>
186 <b>255</b>
187 </bgcolor>
188 <bordermode>noborder</bordermode>
189 <borderradius>1</borderradius>
190 <borderwidth>1</borderwidth>
191 </bsbObject>
192 <bsbObject version="2" type="BSBButton">
193 <objectName/>
194 <x>8</x>
195 <y>8</y>
196 <width>100</width>
197 <height>30</height>
198 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
199 <visible>true</visible>
200 <midichan>0</midichan>
201 <midicc>0</midicc>
202 <type>event</type>
203 <pressedValue>1.00000000</pressedValue>
204 <stringvalue/>
205 <text> ON / OFF</text>
206 <image>/</image>
207 <eventLine>i 2 0 -1</eventLine>
208 <latch>true</latch>
209 <latched>false</latched>
210 </bsbObject>
211 <bsbObject version="2" type="BSBDisplay">
212 <objectName>Filter_Cutoff_Value</objectName>
213 <x>448</x>
214 <y>118</y>
215 <width>60</width>
216 <height>30</height>
217 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
218 <visible>true</visible>
219 <midichan>0</midichan>
220 <midicc>0</midicc>
221 <label>726.416</label>
222 <alignment>right</alignment>
223 <font>Arial</font>
224 <fontsize>9</fontsize>
225 <precision>3</precision>
226 <color>
227 <r>0</r>
228 <g>0</g>
229 <b>0</b>
230 </color>
231 <bgcolor mode="nobackground">
232 <r>255</r>
233 <g>255</g>
234 <b>255</b>
235 </bgcolor>
236 <bordermode>noborder</bordermode>
237 <borderradius>1</borderradius>
238 <borderwidth>1</borderwidth>
239 </bsbObject>
240 <bsbObject version="2" type="BSBHSlider">
241 <objectName>Filter_Cutoff</objectName>
242 <x>8</x>
243 <y>101</y>
244 <width>500</width>
245 <height>27</height>
246 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
247 <visible>true</visible>
248 <midichan>0</midichan>
249 <midicc>0</midicc>
250 <minimum>0.00000000</minimum>
251 <maximum>1.00000000</maximum>
252 <value>0.52000000</value>
253 <mode>lin</mode>
254 <mouseControl act="jump">continuous</mouseControl>
255 <resolution>-1.00000000</resolution>
256 <randomizable group="0">false</randomizable>
257 </bsbObject>
258 <bsbObject version="2" type="BSBLabel">
259 <objectName/>
260 <x>8</x>
261 <y>118</y>
262 <width>180</width>
263 <height>30</height>
264 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
265 <visible>true</visible>
266 <midichan>0</midichan>
267 <midicc>0</midicc>
268 <label>Filter Cutoff</label>
269 <alignment>left</alignment>
270 <font>Arial</font>
271 <fontsize>10</fontsize>
272 <precision>3</precision>
273 <color>
274 <r>0</r>
275 <g>0</g>
276 <b>0</b>
277 </color>
278 <bgcolor mode="nobackground">
279 <r>255</r>
280 <g>255</g>
281 <b>255</b>
282 </bgcolor>
283 <bordermode>noborder</bordermode>
284 <borderradius>1</borderradius>
285 <borderwidth>1</borderwidth>
286 </bsbObject>
287 <bsbObject version="2" type="BSBButton">
288 <objectName>_Browse</objectName>
289 <x>8</x>
290 <y>254</y>
291 <width>170</width>
292 <height>30</height>
293 <uuid>{b9431a61-61f7-432b-bf6f-c47ddc7f9050}</uuid>
294 <visible>true</visible>
295 <midichan>0</midichan>
296 <midicc>0</midicc>
297 <type>value</type>
298 <pressedValue>1.00000000</pressedValue>
299 <stringvalue>Seashore.wav</stringvalue>
300 <text>Browse Audio File</text>
301 <image>/</image>
302 <eventLine/>
303 <latch>false</latch>
304 <latched>false</latched>
305 </bsbObject>
306 <bsbObject version="2" type="BSBLineEdit">
307 <objectName>_Browse</objectName>
308 <x>179</x>
309 <y>255</y>
310 <width>330</width>
311 <height>28</height>
312 <uuid>{68b5f90b-b78e-4581-b434-232db5f4c40f}</uuid>
313 <visible>true</visible>
314 <midichan>0</midichan>
315 <midicc>0</midicc>
316 <label>Seashore.wav</label>
317 <alignment>left</alignment>
318 <font>Arial</font>
319 <fontsize>10</fontsize>
320 <precision>3</precision>
321 <color>
322 <r>0</r>
323 <g>0</g>
324 <b>0</b>
325 </color>
326 <bgcolor mode="nobackground">
327 <r>229</r>
328 <g>229</g>
329 <b>229</b>
330 </bgcolor>
331 <background>nobackground</background>
332 </bsbObject>
333 <bsbObject version="2" type="BSBLabel">
334 <objectName/>
335 <x>8</x>
336 <y>233</y>
337 <width>150</width>
338 <height>30</height>
339 <uuid>{936f6eb0-5225-4bd7-a5fe-a49df1c9c5ac}</uuid>
340 <visible>true</visible>
341 <midichan>0</midichan>
342 <midicc>0</midicc>
343 <label>Audio File</label>
344 <alignment>left</alignment>
345 <font>Arial</font>
346 <fontsize>10</fontsize>
347 <precision>3</precision>
348 <color>
349 <r>0</r>
350 <g>0</g>
351 <b>0</b>
352 </color>
353 <bgcolor mode="nobackground">
354 <r>255</r>
355 <g>255</g>
356 <b>255</b>
357 </bgcolor>
358 <bordermode>noborder</bordermode>
359 <borderradius>1</borderradius>
360 <borderwidth>1</borderwidth>
361 </bsbObject>
362 <bsbObject version="2" type="BSBLabel">
363 <objectName/>
364 <x>7</x>
365 <y>178</y>
366 <width>180</width>
367 <height>30</height>
368 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
369 <visible>true</visible>
370 <midichan>0</midichan>
371 <midicc>0</midicc>
372 <label>Output Amplitude Scaling</label>
373 <alignment>left</alignment>
374 <font>Arial</font>
375 <fontsize>10</fontsize>
376 <precision>3</precision>
377 <color>
378 <r>0</r>
379 <g>0</g>
380 <b>0</b>
381 </color>
382 <bgcolor mode="nobackground">
383 <r>255</r>
384 <g>255</g>
385 <b>255</b>
386 </bgcolor>
387 <bordermode>noborder</bordermode>
388 <borderradius>1</borderradius>
389 <borderwidth>1</borderwidth>
390 </bsbObject>
391 <bsbObject version="2" type="BSBHSlider">
392 <objectName>Amplitude</objectName>
393 <x>7</x>
394 <y>161</y>
395 <width>500</width>
396 <height>27</height>
397 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
398 <visible>true</visible>
399 <midichan>0</midichan>
400 <midicc>0</midicc>
401 <minimum>0.00000000</minimum>
402 <maximum>2.00000000</maximum>
403 <value>1.00800000</value>
404 <mode>lin</mode>
405 <mouseControl act="jump">continuous</mouseControl>
406 <resolution>-1.00000000</resolution>
407 <randomizable group="0">false</randomizable>
408 </bsbObject>
409 <bsbObject version="2" type="BSBDisplay">
410 <objectName>Amplitude</objectName>
411 <x>447</x>
412 <y>178</y>
413 <width>60</width>
414 <height>30</height>
415 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
416 <visible>true</visible>
417 <midichan>0</midichan>
418 <midicc>0</midicc>
419 <label>1.008</label>
420 <alignment>right</alignment>
421 <font>Arial</font>
422 <fontsize>9</fontsize>
423 <precision>3</precision>
424 <color>
425 <r>0</r>
426 <g>0</g>
427 <b>0</b>
428 </color>
429 <bgcolor mode="nobackground">
430 <r>255</r>
431 <g>255</g>
432 <b>255</b>
433 </bgcolor>
434 <bordermode>noborder</bordermode>
435 <borderradius>1</borderradius>
436 <borderwidth>1</borderwidth>
437 </bsbObject>
438 <bsbObject version="2" type="BSBButton">
439 <objectName>Initialisation</objectName>
440 <x>380</x>
441 <y>52</y>
442 <width>130</width>
443 <height>30</height>
444 <uuid>{b6345774-7938-4e62-9d8b-0ada81f7bcc5}</uuid>
445 <visible>true</visible>
446 <midichan>0</midichan>
447 <midicc>0</midicc>
448 <type>value</type>
449 <pressedValue>1.00000000</pressedValue>
450 <stringvalue/>
451 <text> No Initialisation</text>
452 <image>/</image>
453 <eventLine/>
454 <latch>true</latch>
455 <latched>false</latched>
456 </bsbObject>
457 </bsbPanel>
458 <bsbPresets>
459 </bsbPresets>
460 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="false" loopStart="0" loopEnd="0"> </EventPanel>