Csound Csound-dev Csound-tekno Search About

Re: Pluck

Date1999-03-01 17:16
FromSean Costello
SubjectRe: Pluck
jpff@maths.bath.ac.uk wrote:
> 
> I think you are wrong when you say
> 
>  Sergey> I suppose that at the beginning the opcode 'pluck' was just some orc+sco,
>  Sergey> wasn't it?
> 
> I think it was originally coded in C; it certainly is very old and was
> already there before I ever used csound

The Karplus-Strong algorithm certainly predates Csound.  It was first
developed in 1978.
 
>  Sergey> Also, what is the "two-tap averager" (I found this in
>  Sergey>  some article about Karplus-Strong algorithm)?
> 
> Sounds like an interpolating delay line, using taps at two points and
> doing linear interpolation.  Better answer from those who know, or
> after a reference

I think it refers to the simple lowpass filter used within the delay
line of the Karplus-Strong algorithm, where the output y(n) is
determined by the following equation:

y(n) = [x(n) + x(n-1)] * .5

Your interpretation brings up an important point, however: linear
interpolation IS lowpass filtering (well, at least a form of lowpass
filtering).  This will definitely be a problem when trying to implement
the Karplus-Strong algorithm, as linear interpolation would be used for
tuning the delay lines, but would result in inconsistencies in note
brightness for different pitches.  One of the earlier solutions was to
use an allpass filter to tune the delay line to the desired frequency. 
Perhaps allpass interpolation (as described by Joe Dattorro) would be
useful for the Karplus-Strong algorithm.

Anyway, here is an example Csound orchestra/score for the Karplus/Strong
algorithm, written by Richard Karpen.  Instr 2 uses deltapi, and thus
will have more accurate pitches (although the linear interpolation in
deltapi will do funny things to the decay rate for different notes).

Hope this helps,

Sean Costello


; Karplus.orc
;Simple versions of the Karplus Strong Algorithm

sr=22050
kr=22050
ksmps=1
nchnls=1

;The Karplus-Strong Plucked String

instr 1
        afeedback init 0
        anoise=0
        ilooptime = 1/cpspch(p4)
        iamp=p5
        krandenv linseg 1, ilooptime, 1, 0, 0, p3-ilooptime, 0
        anoise rand krandenv
   
        a2 delay afeedback+anoise,ilooptime
        a3 delay1 a2
        afeedback=(a2+a3)*.5

        out a2*iamp

endin


instr 2
        afeedback init 0
        anoise=0
        ilooptime = 1/cpspch(p4)
        iamp=p5
        timout  ilooptime, p3-ilooptime, skiprand
        anoise rand 1
skiprand:
        adum delayr .2
        a2   deltapi ilooptime
             delayw afeedback+anoise
        a3   delay1 a2
        afeedback=(a2+a3)*.5

        out a2*iamp

endin


instr 3 


irevtime = 10
ilooptime=1/cpspch(p4)
timout  ilooptime, p3-ilooptime, skiprand
        asig rand p5
skiprand:
adel init 0
adelin init 0
adel    delay adelin, ilooptime
aton    tone adel, 10000
adelin = aton + asig
asig = 0

out adel
endin


; Karplus.sco

i1 1 5 6.09 5000
i2 7 5 7.09 5000
i3 13 5 8.09 5000
f 0 15