I’m working on some ideas with destructing soundfiles that are rhythmic loops.
My idea is to play a soundfile in a loop and at every full cycle of the soundfile i want to change the conditions of the played soundfile (for example change pitch or playbackspeed).
I solved it like in the code at the end.
I track the playing position and use it like an index of the soundfile. When it is at the end i start a loop to change the playing parameters.
I have two problems:
The tracking of the playing position is not very precise. I have the feeling that not every time it reaches my condition the loop is really started.
When the loop is started i get a few new values from the random opcode. I want to use it on i-Rate and only get one new value every time. How can i do this?
you can ask the phasor value for the transition between 1 and 0. see the
code below.
(the precision depends on your ksmps setting.)
in general, it might be an idea to split the job between two
instruments: one is doing the control stuff, and calls another
instrument to play back the audio via loscil or whatever.
but perhaps the code below does what you need, as the if-condition is
now true only once for each loop.
best -
joachim
giFox = ftgen(0,0,0,1,“fox.wav”,0,0,0)
instr 1
//initialize previous phase to zero
kPreviousPhase init 0
//loscil with phase value (0-1)
aPhs, aSnd loscilphs .2, 1, giFox, 1, 1
//get phase value as k-rate variable
kThisPhase = k(aPhs)
//ask for first phase value after and of sound is reached
if kThisPhase < kPreviousPhase then
printks(“kThisPhase = %f, kPreviousPhase =
%f\n”,0,kThisPhase,kPreviousPhase)
endif
//set previous phase for next k-cycle
kPreviousPhase = kThisPhase
endin
schedule(1,0,100)
Further to Joachim’s comments, you can also create a UDO with ksmps set to 1. This will let you check those k-rate vars at audio rate, so you won’t miss a thing.
Ok,
now i tried to use the UDO like a Trigger: When the a-Signal is on 1 then is the kOut=1 else kOut = 0.
But it doesn’t work…Maybe the Trigger is to fast to get compared? Setting the Main-ksmps to 1 doesn’t help.
<CsoundSynthesizer>
<CsOptions>
-d -odac -W -3
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 128
nchnls = 2
0dbfs = 1.0
seed 0
giSmp ftgen 0, 0, 0, 1, "/Users/philippneumann/Documents/Kompositionen/Funktionslust/Material/Loops/DFAM-Loops-Clean/Reverb/DFAM-FuzzNoise-Loop-Reverb-017.wav", 0, 0, 0
opcode CompareAValue, k, ap
; a-Signal wird in ein k-Signal umgewandelt
; durch eine Runtersetzung der ksmps geschieht dies auf Sample-Rate
; daraus folgt: SR = KR
; Input
aSnd, iValue xin
; ksmps auf a-Rate setzen
setksmps 1
kOut init 0
kCompare = k(aSnd)
kOut = (kCompare = iValue ? 1 : 0)
xout kOut
endop
;-----------------------------------------------------------
instr 1
kPlaybackspeed init 1
aPhs, aSmp1, aSmp2 loscilphs 0.5, kPlaybackspeed, giSmp, 1, 1
kIndex CompareAValue aPhs
if kIndex == 1 then
kPlaybackspeed randomh 0.25, .5, 1000
printk2 kPlaybackspeed
endif
outs aSmp1, aSmp2
endin
;-----------------------------------------------------------
</CsInstruments>
<CsScore>
i1 0 20
</CsScore>
</CsoundSynthesizer>