Dear community,
I’ve written an udo for an random walk, inspired by https://flossmanual.csound.com/basics/random (example 9).
I would like to modify the udo in that way that repetitions of the same index could be prevented, but I don’t know how to do this.
Does someone have a hint for me?
That’ my code:
%%%%%%%%% SNIPPET%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sr = 44100
;ksmps = 100
nchnls = 2
0dbfs = 1
seed 0
;iNumbers ftgen 0,0,16,-2,0,110,22
gihalbton[ ] fillarray 220.0, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.3, 440.0, 466.16, 493.88, 523.25, 554.37, 587.33
opcode StefansRandomWalk,k,iiiii
iLowestIndx,iHighestIndx,iStartIndx,indxDevRange,iDevDir xin
kIndxDevRange init indxDevRange
kDevDir init iDevDir
kIndx init iStartIndx
kLowIndxBound = kDevDir < 0 ? -kIndxDevRange+kDevDir : -kIndxDevRange
kHighIndxBound = kDevDir > 0 ? kIndxDevRange+kDevDir : kIndxDevRange
;get random value in these boundaries
;add to current pitch
kIndx += kIndxRnd ;
;change direction if maxima are crossed, and report
if kIndx = iHighestIndx && kDevDir > 0 then
kDevDir = -kDevDir
elseif kIndx = iLowestIndx && kDevDir < 0 then
kDevDir = -kDevDir
endif
kIndx limit kIndx,iLowestIndx,iHighestIndx
xout kIndx
endop
instr 1
iLowestIndx = 0 ; xin
iHighestIndx = lenarray(gihalbton)-1
iHighestIndx = 10 ; xin
;set pitch startpoint, deviation range and the first direction
iStartIndx = 5 ; xin
iIndxDev = 2 ;xin, random range for next pitch
iIndxDir = 1 ;xin positive = upwards
iwieoft = 3
kmetro metro iwieoft
if kmetro ==1 then
kIndx StefansRandomWalk iLowestIndx,iHighestIndx,iStartIndx,iIndxDev,iIndxDir
;kIndx = int(kIndx)
kcps = gihalbton[kIndx]
endif
imintim = 0 ; wenn der Wert größer ist gibts pausen zwischen den Einsätzen
imaxnum = 0
insnum = 2
iwhen = 0
kdur random 0.1,0.5 ;,iwieoft
kamp random -6,-3 ;,8 ;,iwieoft
schedkwhen kmetro, imintim, imaxnum, insnum, iwhen, kdur,kcps,kamp
printk 1/iwieoft,kIndx
;printk 1/iwieoft,kamp
endin
instr 2
icps = p4
iamp = ampdb(p5); random 0.1,0.5
iein = 0.01
idur = p3-iein
kenv linseg 0,iein,1,idur,0
asine poscil kenv*iamp,icps
outs asine,asine
endin
; ==============================================
i1 0 60
%%%%%%%%%%%%%%%% SNIPPET END %%%%%%%%%%%%%%%%%%%%%%
Thank You,
Stefan
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here