Hi
I am puzzled by how this (does not) work. There is probably something I misunderstand about internal Csound processes, so I thought I might ask here to get help understanding it.
I am trying to make a UDO to reverse the order of all elements in an array. It is easy enough at i-rate, and I can make the code work at k-rate if I do it inline (not in a UDO), but I fail to make it work with k-rate arrays in a UDO.
My code to reverse the order of elements is:
kindex = 0
while kindex < lenarray(kInput) do
kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
kindex += 1
od
A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
Any help is greatly appreciated.
all best
Øyvind
; UDO to reverse the order of an array at i-rate
opcode Reverse, i[], i[]
iInput[] xin
iOutput[] init lenarray(iInput)
index = 0
while index < lenarray(iInput) do
iOutput[index] = iInput[lenarray(iInput)-1-index]
index += 1
od
xout iOutput
endop
; UDO to reverse the order of an array at k-rate
opcode Reverse, k[], k[]k
kInput[], kindex xin
kOutput[] init lenarray(kInput)
while kindex < lenarray(kInput) do
kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
kindex += 1
od
xout kOutput
endop
instr 1
; it does not work when the reversal is inside a UDO
p3 = 4/kr
kInput[] fillarray 1,2,3,4
ktrig metro 1
if ktrig > 0 then
kindex = 0
kOutput[] Reverse kInput, kindex
endif
printarray kOutput
endin
instr 2
; this one works as expected, when the reversal is not in a UDO
p3 = 4/kr
kInput[] fillarray 1,2,3,4
kOutput[] init lenarray(kInput)
ktrig metro 1
if ktrig > 0 then
kindex = 0
while kindex < lenarray(kInput) do
kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
kindex += 1
od
endif
printarray kOutput
endin
instr 3
; it also works fine in a UDO with i-rate arrays
iInput[] fillarray 1,2,3,4
iOutput[] Reverse iInput
printarray iOutput
endin
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