MUC4441/6445
Electroacoustic Music Composition/Digital I




Karplus-Strong String Algorithm

orchestra

; ksalgo1.orc
; simple karplus-strong plucked string .orc (karpen)
; http://depts.washington.edu/smccweb/courses/401-3/402examps/karplus-sco.html

sr=44100
kr=44100
ksmps=1
nchnls=1

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

score

; ksalgo1.sco
; simple karplus-strong plucked string .sco (karpen)
; http://depts.washington.edu/smccweb/courses/401-3/402examps/karplus-sco.html

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


pluck orchestra

; ksalgo12.orc
; karplus-strong example from simon frasier univ site
; http://www.sfu.ca/sca/Manuals/Csound/

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

instr 1
amp = p4
kamp expseg .001,p3*.008,p4,p3*.496,p4,p3*.496,.001
asig pluck kamp, p5, p5, p6,p7,p8,p9
af1 reson asig, 110, 80
af2 reson asig, 220, 100
af3 reson asig, 440, 80
aout balance 0.6*af1+af2+0.6*af3+0.4*asig, asig
out aout
endin

pluck score

; ksalgo12.sco
; karplus-strong example from simon frasier univ site
; http://www.sfu.ca/sca/Manuals/Csound/

f1 0 2048 7 1 2000 1 0 48 0
;inst strt dur amp kcps&icps function method iparm1 iparm2
i 1 0 3 12000 180 0 1 0 0 ;simple averaging
i 1 + 3 12000 180 0 2 1.1 0
i 1 + 3 12000 180 0 2 1.5 0
i 1 + 3 12000 180 0 2 1.75 0
i 1 + 3 12000 180 0 2 2 0
i 1 + 3 12000 180 0 2 2.5 0
i 1 + 3 12000 180 0 2 3 0

s
i 1 0 3 7000 180 0 5 .1 .9 ;weighted averaging
i 1 + 3 12000 180 0 5 0.25 0.75
i 1 + 3 12000 180 0 5 0.5 0.5
i 1 + 3 12000 180 0 5 0.75 0.25
i 1 + 3 7000 180 0 5 .9 .1

s
i 1 0 3 12000 180 0 6 0 0 ; 1st order recursive filter

s
i 1 0 3 10000 50 1 3 0.5 0 ;drum

s
i 1 0 3 7000 50 1 4 0.75 1.5 ; drum w/diff stretch factors(iparm2)
i 1 0 3 12000 50 1 4 0.75 2
i 1 + 3 12000 50 1 4 0.75 3
i 1 + 3 12000 50 1 4 0.75 4
i 1 + 3 12000 50 1 4 0.75 5
i 1 + 3 12000 50 1 4 0.75 6
i 1 + 3 7000 50 1 4 0.75 8

e


To download the above .sco and .orc text files visit the following ftp site:
ftp://bach.music.ufl.edu/ftp/csound/muc6445/

- last update 16 September 2019 -