Keith Hamel's Csound Course

Week 6

In this tutorial:


Index Next Week Previous Week


Review of Frequency Modulation

The components of a frequency modulation system are a carrier wave (with an envelope and a set frequency), and a moduator wave (also with an envelope and set frequency). The carrier wave controls the perceived fundamental and amplitude envelope of the resulting sound, while the modulator wave effects the timbre of the sound. Specifically, the ratio between the carrier and modulator affects the number and the type of partials (harmonic or inharmonic). A simple carrier-to-modulator ratio (c-m ratio) such as 1 : 2 produces harmonic partials, while a complex c-m ratio (i.e. 1 : 1.3176 ) produces inharmonic partials. Another component in a Frequency Modulation system is the modulation index. In simplistic terms, this is a value which effects the distribution of the sound across the partials - a low index (1) will emphasize the fundamental while a high index (15) will emphasize high partials.

goto top Index


Foscil - F.M. Oscilator

Foscil is one of the most commonly used Csound generators. It produces a frequency modulated signal. Of course, it is possible to create frequency modulation with two oscils - one feeding into the frequency argument of the other:

amod   oscil   p4*.2, cpspch(p5), 1           ; modulator
asig   oscil   p4*.8, cpspch(p5) + amod, 1    ; carrier
outs   asig, asig

but foscil simplifies the process and is much easier to control. In essence though, a foscil is performing the computations shown above.

A foscil normal operates at audio (a-) rate and its arguments are:

asig   foscil  amp, freq, carrier, modulator, index, function

The amp and frequency are identical to oscil (they can include envelopes, cpspch conversion, vibrato, tremolo etc.). The function should normally be a sine wave - F. M. naturally produces rich spectra from sine waves, if you use complex waves as your source, you will get extremely complex sounds as your result. The carrier and modulator are expressed as a ratio (i.e carrier has the value 1, and modulator has the value 4). This is possible since you already have a frequency argument. The index value is noramlly close to 1 (rarely above 15 or 20).

asig   foscil  p4*kenv, cpspch(p5), 1, 3, 2, 1    ; simple f.m. with 1:3 ratio
outs   asig, asig                                 ; and index of 2

asig foscil p4*kenv, cpspch(p5), 1, 2.17, 8, 1 ; complex f.m. with 1:2.17 outs asig, asig ; ratio and index of 8


You should experiment with different c-m ratios to see their effect:
Experiment with different index values as well to see what effect they have on the sound.

goto top Index


Applying controls to a foscil

The carrier value, modulator value and index can all be updated at k-rate - a control can be used rather than a constant value. However, if you change the carrier or modulator, you will create discontinuities as the values change from being simple integers ratios to complex ratios. In short, be cautious of changes to the carrier and modulator values while the instrument is running. Such discontinuities do not occur when you change index values. Index sweeps (linear or exponential changes) can be very effective since they cause the sound to become gradually brighter or duller.

kenv   expon   1, p3, .0001             ; expon envelope
kline  line    1, p3, 8                 ; sweep index from 1 to 8
asig   foscil  p4 * kenv, cpspch(p5), 1, 1.414, kline, 1   ; bell with index sweep
outs   asig, asig                       ; stereo output


goto top Index


Reverberation

The Csound reverbation unit (reverb) must be used with some care - it is a highly memory-intensive generator and improper use will cause your program to run very slowly or not to run at all. Since instruments containing reverb are so large, you should avoid having many instruments using reverb active at the same time. Another solution (and a better one) is to create a reverb instrument which receives signals from other instruments and produces the reverberation for all active instruments. reverb takes only two arguments - the audio signal and the reverb time in seconds. (the greater the reverb time the more memory required and the slower the performance). A normal room reverb is about 1.7 - 2 seconds.

asig   foscil  p4, cpspch(p5), 1, 2.01, 1, 1   ; f.m. instrument 
arev   reverb  asig, 2.0                       ; 2 second reverb
outs   arev + asig, arev + asig                ; output both signals


In the above example, the mix between dry and reverberated signal could be controlled:

asig   foscil  p4, cpspch(p5), 1, 2.01, 1, 1   ; f.m. instrument 
arev   reverb  asig, 2.0                       ; 2 second reverb
kctrl  line 1, p3, 0                           ; line from 1 to 0
outs1  (asig* kctrl) + (arev * (1-kctrl))      ; output mix (increasing reverb)
outs2  (asig* kctrl) + (arev * (1-kctrl))      ; output mix (increasing reverb)


goto top Index


Creating a Global reverb Instrument

To create a single reverb instrument, that can be used for all copies of another instrument or instruments, you must create an instrument such as:

instr 99
ga1   init 0                    ; initialize to 0
asig  reverb  ga1, 1.75         ; reverb time 1.75
outs  asig * .5, asig * .5      ; output reverb 
ga1   =   0                     ; clear ga1
endin

This instrument must be turned on (in the score) for the duration of the composition (or whenever any instrument might require the reverb instrument)

i99   0   40                    ; turn on for 40 seconds

The reverb instrument contains a global variable (ga1). Global variables can be specified as ga-, gk- or gi- for audio, control or initialization rates. A global variable is available to all instruments at any time. This is different from the local variables we have been using which are available only to a particular copy of an instrument - the asig variable in an instrument starting at time 0 will never be confused with the asig variable in an overlapping instrument starting at time .5. Because global variables are available to all instruments, they can be used to transfer audio signals to a reverb instrument. In the instrument designed above, the reverb unit expects to receive an audio signal in the variable ga1 - it then creates reverberation of this sound and sends it out. The instrument below, creates an audio signal in asig and outputs it. The audio signal is also added to ga1 so that it can be sent (along with any other other audio signals currently active) to the reverb instrument (which must also be running at the time).

kenv  expon   1, p3, .0001                         ; expon envelope 
asig  foscil  p4*kenv, cpspch(p5), 1, 1.01, 3, 1   ; fm ratio 1 : 1.01
outs  asig, asig                                   ; output audio singal
ga1   =   ga1 + asig                               ; add asig to ga1
; reverb will receive ga1

Warning: In this design, ga1 accumulates the audio signals from all active copies of the instrument and the reverberation instrument creates the reverb. If you have too many copies of an instrument playing at once (say 20), the value of ga1 may become so high that distortion will occur - in this case you may want to adjust the amount of the original audio signal that is being reverberated:

ga1   =   ga1 + (asig * .2)        ; reverberate only 1/5

Similarly, if your reverb time is excessively long (say 15 seconds) you may also want to reduce the amount of signal being passed to the reverb.

goto top Index


Suggested Assignment

Design a foscil instrument which accepts parameters from the score to control the modulation ratio and the index. Create a score to demonstrate for yourself the effect of different c-m ratios and different indices.


goto top Index Next Week Previous Week