Keith Hamel's Csound Course

Week 9

In this tutorial:


Index Next Week Previous Week


Low Pass and High Pass Filters: tone and atone

Csound implements low-pass and high-pass filters with the generators tone and atone. These functions operate at audio rate (a- rate) and take, as arguments, an input audio signal and a cutoff frequency. The output from the generator is the filtered audio signal. The cutoff frequency determines the half-power point of the filter attenuation. (About half way down the filter cut-off curve.) This means (in the case of a high-pass filter) that some frequencies below will still be present and (in the case of a low-pass filter) that some frequencies above will be present. Since the filtered audio signal may have a vastly reduced amplitude (depending on the cut-off frequency and the content of the original signal), it is useful to balance the filtered signal with the original. This is done with the balance generator. balance adjusts the audio signal in its first argument with the audio signal in its second. An example of a low-pass filter (cutting out frequencies above 1000 Hz) is given below:

asig    oscil p4, cpspch(p5), 1    ; oscilator
afilter tone asig, 1000            ; filter above 1000
afin    balance afilter, asig      ; balance audio signal 
outs    afin, afin                 ; output


A high-pass filter (cutting out all frequencies below 100) would look like:

asig    oscil p4, cpspch(p5), 1 ; oscilator
afilter atone asig, 100         ; filter below 100
afin    balance afilter, asig   ; balance audio signal 
outs    afin, afin              ; output


The use of balance is important when using filters - strange amplitudes (both very large and very small) sometimes result when it is omitted (especially if an audio signal is passed through several filters successively)

goto top Index


Band-Pass and Band-Reject (Notch) Filters: reson and areson

Csound implements band-pass and band-reject filters with the generators reson and areson. As arguments, they take an audio signal (to be filtered) a centre frequency, and a bandwidth (which determines the range of frequencies above and below the centre frequency that are filtered or passed through. A reson filter attenuates all frequencies outside the area delineated by the centre frequency and bandwidth, and the areson attenuates all frequencies within the area. In the example below, reson is applied to full range of white noise to produce a relatively narrow band (20 Hz) around the centre frequency - 300 Hz.

arand   rand 10000              ; full band noise
afilter reson arand, 300, 20    ; band-pass filter at 300 Hz (width 20 Hz)
afin    balance afilter, arand  ; balance the audio signals 
outs    afin, afin              ; output the filtered signal


In the example below, a band-reject (notch) filter is used to filter out the middle register and to allow only very low and very high frequencies to pass through.

arand   rand    10000              ; full band noise
afilter areson  arand, 1000, 800   ; band-reject filter at 1000 Hz (width 800 Hz)
afin    balance afilter, arand     ; balance the audio signals 
outs    afin, afin                 ; output the filtered signal


In all the filters listed above, the frequency (and bandwidth) arguments can be replaced by a control, and a variety of filter sweeps can be achieved. In the example below, a band-pass filter's centre frequency sweeps up from 100 Hz to 2000 Hz. As it ascends, the bandwidth expands proportionally so that the width of noise remains relatively constant.

arand   rand     10000              ; full band noise
kcent   line     100, p3, 2000      ; line from 100 Hz to 2000 Hz 
afilter reson    arand, kcent, 20   ; band-pass filter sweeping upwards
afin    balance  afilter, arand     ; balance the audio signals 
outs    afin, afin                  ; output the filtered signal


Alternatively, the centre frequency could remain the same, while the bandwidth changes. In the example below, the bandwidth gradually narrows until it is only 1 Hz wide. (Of course, other frequencies will still be heard, but the effect of a narrowing will be clear.)

arand   rand 10000                     ; full band noise
kwid    line 100, p3, 1                ; line from 100 Hz to 1 Hz
afilter reson arand, cpspch(p5), kwid  ; band-pass filter narrowing 
afin    balance afilter, arand         ; balance the audio signals 
outs    afin, afin                     ; output the filtered signal


Uses of Filters:

  1. Filters can be used to remove unwanted noise either in the low frequencies (atone) in the high frequencies (tone) or in a fixed frequency area (reson).
  2. Since controls can be placed on the frequency and bandwidth arguments of the filters, they can be used to alter the colour of a sound over time (e.g. The cutoff frequency in an atone can be gradually dropped to make the lower frequencies gradually more prominent.) Similarly, a sweeping band-pass filter can produce an interesting effect on the colour of a rich audio signal.
  3. Filters can be used to modify (or distort) sounds brought into Csound using soundin. Since filters operate on complete audio signals, they are one of the generators that can be used effectively with pre-recorded sounds.
  4. Band-pass filters can be used for simulating vocal formants (using subtractive synthesis). However, creating realistic vocal sounds with subtractive synthesis is a difficult task. (More on subtractive synthesis below.)

goto top Index


Vocal Synthesis Using Subtractive Synthesis

It is possible to create vocal-like sounds by taking full-frequency sound and carving out the formants using band-pass filters. In order to do this, it is necessary to generate either full-band noise (which will give us un-voiced sound) or a rich, even harmonic spectrum (for voiced sounds), then to pass this sound through band-pass filters which are set to a particular vowels formant centres and bandwidth. (Normally 3 formants are required to simulate a phoneme).

We have already generated full-band noise with rand, randi and randh. To generate a rich, even harmonic spectrum, we use the generators buzz or gbuzz. buzz takes, as arguments, an amplitude, a fundamental frequency, the number of harmonics and a function table (usually a sine wave). It produces a sound which has an even distribution of amplitudes in each of the partials. gbuzz is similar to buzz, but allows the lowest partial (i.e. not necessarily the fundamental) to be specified and a mulitplication value which is exponentially applied to successive partials. With gbuzz the relative strengths of the partials can increase, decrease or remain constant across the spectrum.

gbuzz requires a cosine table -- f1 0 8192 9 1 90 ; (sine wave out of phase by 90 degrees).

Either buzz or gbuzz can be used to create the rich, even spectrum required of subtractive synthesis. The example below shows a buzz (with 12 harmonics) being filtered by three formants 320, 1420, 2100.

ifor1   =   310    ; formant 1
iwid1   =   45     ; width of formant 1
ifor2   =   2020   ; formant 2
iwid2   =   200    ; width of formant 2
ifor3   =   2960   ; formant 3
iwid3   =   400    ; width of formant 4
abuzz   buzz   p4, cpspch(p5), 20, 1  ; buzz with 20 partials 
afil1   reson abuzz, ifor1, iwid1     ;band-pass filter formant 1
afil1   balance afil1, abuzz          ; balance the audio signals 
afil2   reson abuzz, ifor2, iwid2     ; band-pass filter formant 2
afil2   balance afil2, abuzz          ; balance the audio signals 
afil3   reson abuzz, ifor3, iwid3     ;band-pass filter formant 3
afil3   balance afil3, abuzz          ; balance the audio signals 
outs1   (afil1 + afil2 + afil3) / 3   ; output the filtered signals left
outs2   (afil1 + afil2 + afil3) / 3   ; output the filtered signals right


As mentioned above, the buzz could be replaced by a rand to create un-voiced sounds. In order to move from one vowel to another, each of the formant and bandwidth values in the above example could be replaced by a line which moves from the value of one vowel to the corresponding value in another. When all is said and done, it should be remarked that the voice is an extremely complex instrument and the above techniques usually produce results that are very pale when compared to a the human voice.

goto top Index


Creating Vocal Sounds Using FOF Synthesis

A better method of synthesizing vocal sound is with first-order formant synthesis. Rather than a subtractive method, fof uses frequency modulation to create a carrier frequency and sidebands which collectively create a formant region. When three such formants are generated at the correct frequencies, a vocal sound results. The Csound implementation of fof is not clearly presented in the manual and so it is difficult to use. The generator takes many arguments (too many to list here). If you are interested in using this synthesis method, you will have to experiment with some of the arguments before you can create convincing vocal sounds. A sample vowel would look something like:

asig1   fof   p4, cpspch(p5), 700, 0, 3, .003, 130, .01, .007, 5, 1, 1, p3
asig2   fof   p4, cpspch(p5), 1220, 0, 3, .003, 70, .01, .007, 5, 1, 1, p3
asig3   fof   p4, cpspch(p5), 2600, 0, 3, .003, 160, .01, .007, 5, 1, 1, p3
outs1   (asig1 + asig2 + asig3 ) / 3
outs2   (asig1 + asig2 + asig3 ) / 3


goto top Index


Suggested Project

You should begin by compiling an extensive orchestra of instruments that you have found successful in the past as well as designing some new instruments. The final project must be created entirely in the digital audio domain, although you may incorporate pre-recorded material.

The final project should be an original composition which demonstrates your imagination and command of the Csound environment. The duration should be a minimum of 3 - 5 minutes and a maximum of 10 minutes. You should avoid either re-working old assignments or presenting of pastiche of your favourite instruments and what they can do. The project should be an electroacoustic composition rather than a CSound demonstration.


goto top Index Next Week Previous Week