I’m revising my mincer
crossfade code and running into a problem. See the code below. The basic idea is that kphs
moves through the wav sample until it passes kloop_end
. At that point, kcrossfade
is toggled to 1 and event
triggers a new instance of the instrument, which plays the loop again starting from the start of the loop.
The first instance of the instrument should keep playing until kphs
passes kloop_end + kcrossfade_duration
. In other words, this is the crossfade segment that will fade out with an amplitude envelope. This instance will then be turned off with turnoff
.
However, this isn’t working the way I expect. While the new instance is triggered and plays from the beginning of the loop, the crossfade segment isn’t playing at all. You can play around with it here. Perhaps I’m not using turnoff
correctly? Or my control logic is flawed? Could it have to do with the fact that my project uses fractional instruments (e.g. 1.1, 1.2, 1.3) and therefore event
and turnoff
are not working how I’m expecting? Speaking of fractional instruments, does Csound treat 1.1 and 1.100000 as different instruments?
I’ve tinkered with this for a couple hours and haven’t figured out a solution. Seems like this approach should be able to work.
Any guidance would be appreciated! Thanks,
Jason
EDIT: It seems like the issue has to do with the event
opcode. Does calling event "i", 1.1, 0, -1, 1, kreset_count
automatically turn off any other instances with an instrument number of 1.1 and a note duration of -1? That seems to be the behavior I’m getting.
; read ktimescale, kloop_end, and kcrossfade_duration from GUI
; kloop_end and kcrossfade_duration are expressed in numbers of samples
kcrossfade init 0
kndx = 0
while (kndx < ksmps) do
aphs[kndx] = kphs/sr
kphs = kphs + ktimescale
kndx += 1
od
if kphs > kloop_end then
if kcrossfade == 0 then
event "i", p1, 0, -1, p4, kreset_count
kcrossfade = 1
endif
if kcrossfade == 1 then
if kphs > kloop_end + kcrossfade_duration then
turnoff
endif
endif
asigl mincer aphs, kamp, kpitch, kfunction, ilock, 2048, 10