Keith Hamel's Csound Course

Week 8

In this tutorial:


Index Next Week Previous Week


Using Pluck to Simulate Plucked Strings or Drums

Csound has an implementation of the Karplus-Strong plucked string algorithm. This algorithm simulates a naturally vibrating string or membrane. The arguments to the generator are:

ar    pluck kamp, kcps, icps, ifunc, imethod [,param1, param2]

The kamp, kcps and ifunc are amplitude, frequency and function table number (as in oscil or foscil). The icps argument is used to allocate a buffer (storage area) of 1 cycle of audio samples which the generator gradually smooths over time. Normally, set this to the same value as your cps, or if cps is changing, to the lowest cps value produced. The imethod argument has a value of 1 - 6 depending on which pluck method is desired. Some of the methods take an additional parameter, or additional parameters -- See the manual for details.

iptch   =   cpspch(p5)
asig    pluck    p4, iptch, iptch, 1, 1      ; plucked string using simple averaging

iptch   =   cpspch(p5)
asig    pluck p4, iptch, iptch, 1, 3, .5     ; simple drum with roughness .5

iptch   =   cpspch(p5)
asig    pluck p4, iptch, iptch, 1, 4, .5, 1  ; a stretched drum with roughness .5

Since pluck simulates a natural decay it is usually not necessary to add an envelope to it. If the sound clips, either make the duration longer, or adjust the parameters to make it decay more quickly.

Pluck is capable of producing a wide range of sounds. Experiment with the different pluck methods, with different parameters, and with different function tables.

goto top Index


Alternate Envelope Generators - Linen and Envlpx

Linen and envlpx can be used to apply linear or exponential envelopes to an audio signal. Linen takes 4 arguments: audio-signal, risetime, duration and decaytime.

asig   oscil   p4, cpspch(p5), 1     ; oscillator
asig   linen   asig, .05, p3, .1     ; attack .05, decay .1


envlpx is more complex, it takes 7 arguments: audio-signal, risetime, duration, decaytime, function number of a rise shape, an attenuation factor for steady state, and an attentuation factor for the decay. The function table will normally be a GEN-7 or GEN-5 rising from 0 (or .0001) to 1 and must have an extended guard point (i.e. size of 257, 513 etc.). The attentuation factor for the steady state will be < 1 for decay and >1 for an increase. The attentuation factor for the decay will be approximately .01

( f2 0     513     5     .0001 512 1 )

asig   oscil   p4, cpspch(p5), 1               ; oscillator
asig   envlpx  asig, .05, p3, .1, 2, .8, .01   ; function 2

Complex attacks can be defined with GEN-7 (i.e. attacks with several spikes) and the attenuation factor (on the steady state) can be used to adjust the rate of decay before the final decay.


goto top Index Next Week Previous Week