| ;ks2.orc
sr = 44100
kr = 44100
ksmps = 1
instr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Low level implementation
; of the classic Karplus-Strong algorithm
; fixed pitches : no vibratos or glissandi !
; implemented by Josep M Comajuncosas / Aug´98
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This instrument is highly inharmonic
; due to the 9 allpass stages in the feedback loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ipluck = p5; pluck position ( 0 to 1 )
ifreq = cpspch(p4)
idlts = int(kr/ifreq-.5)-4; set waveguide length (an integer number of
samples)
; substract 4 - the delay induced by the 8 cascaded allpass
idlt = idlts/kr; convert so seconds
kdlt init idlts; counter for string initialisation
irems = kr/ifreq - idlts +.5;remaining time in fractions of a sample
; set phase delay induced by the FIR lowpass filter
; and the fractional delay in the waveguide
iph = (1-irems)/(1+irems); allpass filter parameter
; approximation valid at low frequencies relative to sr
awgout init 0
if kdlt < 0 goto continue
initialise:
anoise atrirand 30000
; fill the buffer with random numbers
anoise butterlp anoise, p6, 1
; smooth a bit the noise burst
; harmonic richness grows with volume
; final volume determined by the filter gain
acomb delay anoise, ipluck/idlt
anoize = anoise - acomb
; implement pluck point as a FIR comb filter
continue:
areturn delayr idlt
ainput = anoize + areturn
alpf filter2 ainput, 2, 0, .5, .5
; lowpass filter to simulate energy losses
; could be variable to allow damping control
awgout filter2 alpf, 2, 1, iph, 1, iph
; allpass filter to fine tune the instrument
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
awgout filter2 awgout, 2, 1, .333, 1, .333
; bank of 8 allpass filters for extra inharmonicity
; each stage delays ~.5 samples the base period
;NOTE: It should sound more inharmonic... were´s the bug?
delayw awgout
out awgout
kdlt = kdlt - 1
anoize = 0; supress last impulse when waveguide is loaded
;tricky but easy...
endin
|