-m128
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
seed 0
//we wait a bit before we start the process
instr Loop
kRtm[] fillarray 3, 1, 2, 2, 4
kAccents[] fillarray 2, 0, 1, 2, 1
kTimUnit = 60 / (72*6)
kAccUnit = 3 ;db
kTime init 0
kIndx init 0
if kTime <= 0 then
kRtmValue = kRtm[kIndx]*kTimUnit
kAccentDb = kAccents[kIndx]*kAccUnit
schedulek "WineGlass", 0, kRtmValue, -16+kAccentDb, 70
if timeinsts() > 5 && kIndx == 4 then
//which element
kElement random 0, lenarray(kRtm)
//add or subtract
if random:k(0,3) < 2 then
//add
kRtm[kElement] = kRtm[kElement]+1
else
//subtract
kRtm[kElement] = kRtm[kElement]-1
//but prevent to become zero
if kRtm[kElement] == 0 then
kRtm[kElement] = 1
endif
endif
endif
kIndx = (kIndx+1) % lenarray(kRtm)
kTime = kRtmValue
endif
;count backwards for each k-cycle
kTime -= 1/kr
endin
instr WineGlass
iVolumeDb = p4 ;db
iBasePitch = p5 ;midi note number
iBaseFreq mtof iBasePitch
iFreqProps[] fillarray 1, 2.32, 4.25, 6.63, 9.38
iAmps[] fillarray 1/2, 1/5, 1/9, 1/12, 1/19
iDurVar = 0.5
iDurDiffStep = (1-iDurVar)*p3 / (lenarray(iFreqProps)-1)
index = 0
while index < lenarray(iFreqProps) do
iFreq = iBaseFreq*iFreqProps[index]
iAmp = ampdb(iVolumeDb)*iAmps[index]
iDurDiff = iDurDiffStep*index
schedule "ReceivePartials", 0, p3-iDurDiff, iAmp, iFreq
index += 1
od
endin
instr ReceivePartials
iAmp = p4
iFreq = p5
iAttackTime random 1/1000, 3/1000
aEnv transeg 0, iAttackTime, 4, iAmp, p3-iAttackTime, -4, 0
aEnvRndDb randi 2, 5, 2
kPchRnd randi 1/10, 4, 2
aSine poscil aEnv*ampdb(aEnvRndDb), mtof(kPchRnd+ftom(iFreq))
out aSine, aSine
endin
i "Loop" 0 60
100
100
320
240
true
255
255
255