Csound Csound-dev Csound-tekno Search About

pitch in K-S algorithm

Date1999-03-18 10:05
FromSergey Batov
Subjectpitch in K-S algorithm
Hi, Csounders!

Excuse me for a big message, I just supposed that the attachments are not
good for everyone (?). 

Here are two examples of Karplus Strong Algorithm (from List).

It seems that the pitches of notes  are good enough in first example ,
but not in second example. Why? 
In the beginning I thought that this is because of LPF y[n]=(x[n]+x[n-1])/2
in the second example, but using the 'tone' brings worst results.

May be the pair "delayr - delayw" works more exactly than "delay"?

BTW,  LPF from second ex. works good in the first ex.
Does anybody know what is characteristics of this filter (cutoff frequency,
e.t.c.)?


Thanks,
Sergey Batov   batov@glasnet.ru


;========= K-S_ex1.orc ===========
	sr	=	44100
	kr	=	4410
	ksmps	=	10
	nchnls	=	1

;               Karplus Strong Algorithm Demonstration                     
 
	instr	1
icps    =       cpspch(p5)              ;desired pitch in PCH
asig    init    0                       ;initialize asig variable
kcount  init    1/icps*kr               ;and loop counter (see below)

;------- use a delay line of length 1/cps:

adel    delayr  1/icps			;delay of 1/cps seconds
asig    tone    adel,sr/2               ;filter the output

;- but at the first k, fill the delay line with noise:

if (kcount < 0) kgoto continue  ;skip over after line filled
kloop:                                  ;loop to fill delay
asig    rand    p4,-1                   ;with white noise
kcount  =       kcount - 1              ;decrement loop counter
;-------------------------------------------------

continue:
  delayw  asig   ;delay line input (always get here)

 if (kcount >= 0) kgoto kloop ;loop only kcount times at start 

        out     asig
        endin
;============ end of K-S_ex1.orc ===================


;================ K-S_ex1.sco ==============================
;Test score for Karplus Strong Demo Instrument
i1 1 5 30000 7.00 
i1 7 5 30000 7.04 
i1 13 5 30000 7.07 

i1 19 5 30000 8.00 
i1 25 5 30000 8.04 
i1 31 5 30000 8.07 

i1 37 5 30000 9.00 
i1 43 5 30000 9.04 
i1 49 5 30000 9.07 
e
;============ end of K-S_ex1.sco ======================

                             

 THE SECOND EXAMPLE:


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

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

;The Karplus-Strong Plucked String

instr 1
        afeedback init 0
        anoise=0


ipitch=cpspch(p4)
        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
        ;afeedback   tone    a2,sr/2        
out a2*iamp

endin

; Karplus.sco

i1 1 5 7.00 5000
i1 7 5 7.04 5000
i1 13 5 7.07 5000

i1 19 5 8.00 5000
i1 25 5 8.04 5000
i1 31 5 8.07 5000

i1 37 5 9.00 5000
i1 43 5 9.04 5000
i1 49 5 9.07 5000


f 0 55
e