Keith Hamel's Csound Course

Week 4

In this tutorial:


Index Next Week Previous Week


Pitch Conversion Routines:

We have already been using the cpspch() routine to convert pitch-class code to cycles-per second. Csound permits three methods of representing frequency information, and has conversion procedures so that we can change from one to the other.

The common conversion between one form and another are:

The oct notation is useful when you want a control to move smoothly from one octave to another - such as a linseg moving from C12 to C9. If the values from the linseg are used as pch, you will get discontinuities as the linseg moves from 12.0 to 11.99 etc. )

goto top Index


Creating composite envelopes with linseg and expseg

To increase control over the decay characteristics of an envelope, it is sometimes necessary to mix two envelopes together. This is normally done by creating a expseg envelope (with an exponential decay) and MULTIPLYING it by a linseg envelope which sits at 1 for the beginning part of the sound and increases while the expseg is decaying. The result of multiplying the two functions is a modified exponential decay that tends to sound more natural.

k1   expseg   .0001, .01, 1, .01, .5, p3 - .02, .001   ; decaying expseg
k2   linseg   1, .02, 1, p3-.02, 2.5                   ; rising linseg
k3   =   k1 * k2

Applying envelope controls to other aspects of the sound

line, expon, linseg and expseg are very useful for amplitude envelopes, but they can be used as a control on virtually any aspect of the sound. However, you must ensure that the values that will be returned from the control are appropriate values for the receiving generator. For example, if you want to apply a ramp (i.e. a line) on the frequency of a sound, the starting and ending values of the line should be appropriate frequency values - a line moving from 1 to 0 will not produce audible sound. The example below creates a glissando from 1200 cps to 400 cps

kgliss   line    1200, p3, 400       ; line from 1200 to 400 
asig     oscil   p4, kgliss, 1       ; oscillator

The next example takes p5 from the score in pch notation and glisses down one octave.

istart  =   cpspch(p5)              ; starting pitch
ifin    =   cpspch(p5 - 1.00)       ; end pitch octave down
kgliss  line   istart, p3, ifin     ; line from 1200 to 400
asig    oscil  p4, kgliss, 1        ; oscillator

The next example applies a ramp and causes the sound to move from the left channel to the right channel. Since we are multiplying the output of the control by the audio signal, the range of 1 to 0 is appropriate.

asig   oscil  p4, cpspch(p5), 1     ; oscillator
kpan   line   1 p3, 0               ; line from 1 to 0 for pan
outs   asig * kpan, asig * (1-kpan) ; output complementary values in right and left channels

In any of the above examples, line could be replaced by a more complex control such as expon, linseg or expseg.

Although controls can applied to most aspects of the sound, they cannot effect an argument that is requires an i- time value. For example, it is not possible to change the function number of an oscillator over time - this value must be established when the instrument is first called either as a constant or as score parameter.

goto top Index


Additive synthesis

Additive synthesis is th process of creating a complex sound by ADDING component sine waves each with independent amplitude envelopes. We have already created compex waveforms using GEN-9 and GEN-10, but these waveforms were used by a single oscillator. In additive synthesis, we want to use sinewaves as the waveform function and to add multiple oscillators each with an independent amplitude envelope. In the example below, two audio signals are added together: the first produces the fundamental, the second produces the second partial (frequency is ifund * 2).

ifund   =   cpspch(p5)       ; fundamental

kenv1   expseg  .0001, .01, 1, .01, .5, p3 - .02, .0001   ; envelope 1
asig1   oscil   p4 * kenv1, ifund, 1                      ; oscillator 1

kenv2   expseg  .0001, .01, .7, .03, .4, p3 - .04, .0001  ; envelope 2
asig2   oscil   p4 * kenv2, ifund*2, 1                    ; oscillator 2

outs    (asig1 + asig2)/2, (asig1 + asig2)/2              ; output mix


Notice that when two audio signals are added together, the output is divided by two. It is necessary to scale down the overall amplitude so that it doesn't produce samples out of range. We could create a much more complex instrument by adding together more partials, and perhaps even adding a control on the frequency.

goto top Index


Using oscil as a control to produce vibrato and tremolo

Most commercial synthesizers use a LFO (low frequency oscillator) to create vibrato and tremolo effects. In Csound, we can create a similar effect by using an oscil as to effect the amplitude or frequency of a second audio oscil. The control oscil is passed to a k- variable, and the k- variable is used within the subsequent a- variable oscil. When this is done properly, the control oscil creates a periodic change in the audio signal which is perceived as either tremolo (when applied to amplitude) or vibrato (when applied to frequency). However, to create these effects, the speed of the control oscil must be slow (ie. less that 12 times a second) and the amplitude must be low - otherwise the control oscillator will have too great an effect on the audio signal. In the tremolo example below, the control oscillator has an amplitude that is 1/100 of the total amplitude (.01 * p4), and the speed of the tremolo is 8 cps. The output from the control oscillator is ADDED in the amplitude argument of the audio oscil.

ktrem  oscil   .01 * p4, 8, 1               ; tremolo at 8 times per second
asig   oscil   p4 + ktrem, cpspch(p5), 2    ; audio oscillator
outs   asig, asig


If an amplitude envelope is added to the above example, we would want it to affect both the tremolo and the total amplitude - (p4 + ktrem) * kenv rather than (p4 * kenv) + ktrem. These reduces the strenght of the tremolo as the sound gets quieter.

kenv   expon   1, p3, .0001                         ; ampitude envelope
ktrem  oscil   .01 * p4, 8, 1                       ; tremolo at 8 times per second
asig   oscil   (p4 + ktrem) * kenv, cpspch(p5), 2   ; audio oscillator
outs   asig, asig

In a vibrato, the control is added to the frequency argument of the audio oscillator. The addition must be made to frequency in cps - adding the value to pch or oct encoded frequency will produce strange results. The amplitude of the control vibrato indicates the amount (in cps) above and below the centre frequency that the pitch will deviate. In the example below, it will move 20 cycles above and below cpspch(p5).

kenv   expon   1, p3, .0001                         ; amplitude envelope
kvib   oscil   20, 6, 1                             ; vibrato at 6 times per second
asig   oscil   p4 * kenv, cpspch(p5) + kvib, 2      ; audio oscillator 
outs   asig, asig


It is sometimes a good idea to relate your vibrato depth (the amplitude of the control oscil) to the main frequency. If you do this, an even vibrato will be created across registers - Remember - 20 cycles is a large interval in very low sounds and a tiny interval in high sounds.

idepth  =  cpspch(p5) * .05                     ; 1/20 of the main freq
kvib   oscil  idepth, 6, 1                      ; vibrato at 6 times per second
asig   oscil  p4 * kenv, cpspch(p5) + kvib, 2   ; audio oscillator 
outs   asig, asig


Although other waveforms can be used with control oscillators sine waves generally give the best results.

goto top Index


Suggested Assignment

  1. Create a new instrument that uses additive synthesis to create rich timbres. The sound should have at least 5 audio components (audio oscillators) and should have independent envelopes on each oscil. The envelopes should all have gradual attacks, amplitude changes and decays, so that different partials are heard more clearly at different times. (Long durations can be used with this instrument.)
  2. Create a second instrument that has both a vibrato and a tremolo the speeds of which can be controlled by parameters in the score.
  3. Produce a imaginative (wonderous) score that demonstrates your two instruments
  4. Document your score and orchestra fully

goto top Index Next Week Previous Week