<-- | --> |
This tutorial assumes that the user is familiar with Csound programming.
We will build a small module for filtering sounds. This module will feature a choice of low-pass, hi-pass, bandpass and band-reject filter, along with a time-function to control the cut-off and/or center frequency. We will also offer a post filter gain slider, a selector for choosing the soundfile to process and an automatic balance switch to reestablish power to the filtered sound.
Normally, we would first build the orchestra in Csound and then add the interface, but since we already know what we want to do, we will first build the interface.
We will therefor need to define the following interface objects:
cgraph freqc -unit Hz -label "Cut-off Frequency" -rel log -min 50 -max 20000 -init 2500
cgraph freq -unit x -rel lo -min 20 -max 15000 -init 500But we will change the parameter range to -min .001, max 1 and init to 0.1 because this function will be used as a multiplier for the center frequency (freqc) in the orchestra to give us the bandwidth of the filter. We also change -rel log to -rel lin for a linear function. While we are here, let's give it a label of "Bandwidth".
cfilein name -label "Sound to process" cgraph freqc -label "Cut-off Frequency" -rel log -min 50 -max 20000 -init 2500 cgraph freq -label "Center Frequency" -rel lin -min .001 -max 1 -init 0.1 cslider data10 -label "Post-Filter Gain" -res .1 -min 0 -max 10 -init 1 ctoggle gain -label "Balance with Input" -init 0 cpopup type -label "Select Filter Type" -value "lo-pass hi-pass band-pass band-reject"Select Save module as... under the File menu, and give the new module a name (TestFilters.cec is good). If all is well, the new module will pop open with a grapher window and the Main window will enlarge to include a file selector. CECILIA attempts to warn you on interface definition errors. Check the interface carefully to make sure all the parameters and objects are present and in the correct ranges.
a1,a2 soundin "[name]",
[offname] ; name from fileselector
; and offset substituted here
if gktype != 0 goto hp
; using if / goto and the value
ag butterlp
a1, gkfreqc ;
of the "type" popup to select
ad butterlp
a2, gkfreqc ;
the correct kind of filter
goto bal
hp:
if gktype != 1 goto bp
; the freqc graph controls the
ag butterhp
a1, gkfreqc ;
cut-off frequency
ad butterhp
a2, gkfreqc
goto bal
bp:
if gktype != 2 goto br
; the freq graph controls the
ag butterbp
a1, gkfreqc, gkfreq*gkfreqc ;bandwidth
ad butterbp
a2, gkfreqc, gkfreq*gkfreqc
goto bal
br:
ag butterbr
a1, gkfreqc, gkfreq*gkfreqc
ad butterbr
a2, gkfreqc, gkfreq*gkfreqc
bal:
if gkgain == 0 goto nobal
; gkgain toggle decides to
ag balance
ag, a1
; balance or not
ad balance
ad, a2
nobal:
outs ag*gkdata10, ag*gkdata10
; the data10 slider controls
; the final gain
endin