Issue converting Cs6 udo to Cs7 udo

Heyy

Not sure if this is a result of the pass-by-reference default behaviour in Csound 7, but I get errors when passing a ftgen to the UDO

giLoad ftgen 1, 0, 0, 1, "path/to/file.wav", 0, 0, 1
giload1len = filelen(gSpath1)

opcode FlooperOverlap(amp:k, rate:k, loopstart:k, loopsize:k, crossfade:k, mytab:i, ptr:k, nvoices:i, cnt:i):(a)
	puts("FlooperOverlap",1)
	print mytab ;will print 1.0
	asig = flooper2:a(amp, rate, loopstart, loopsize, crossfade, mytab)

	if cnt < nvoices-1 then
		asig += FlooperOverlap(amp, rate+random(-0.01, 0.01), loopstart, loopstart+0.1, crossfade, mytab, ptr, nvoices, cnt+1)	
	endif

	xout(asig)
endop

instr FloopTest
	idur = p3
	ifnlen = p4
	ptr:k = line(0, idur, 1) * ifnlen
	print giLoad1 ;will print 1.0
	res:a = FlooperOverlap(1, 1, 0, 0.25, 0.05, giLoad, ptr, 4, 0)
	outs res,  res
endin

schedule(FloopTest, 0, 10, giload1len)

I get this error:

instr 1: giLoad1 = 1.000
FlooperOverlap
UDO FlooperOverlap: mytab = 1.000
Invalid ftable no. 0.000000
INIT ERROR in instr 1 (opcode FlooperOverlap) line 37: function table not found

for some reason the mytab value passed to asig = flooper2:a(amp, rate, loopstart, loopsize, crossfade, mytab) is getting lost.

It’s not an issue in the Cs6 style udo

What build of Csound 7 are you using?

It’s whatever version the latest CsoundQT is running I guess?

if the code was like i read it, you missed closing paranthesis after the
list of input argiments, and i see no output arguments. the syntax is:
opcode name(inputs):(outputs)

endop

I think the syntax is correct, and it should work fine. I was just chatting with Victor, he thinks there is already an issue in the issue tracker that touches on this bug. I’m just about to rush out the door, so I don’t have a chance to look, maybe you can find it and post this example there?

I think maybe it’s this one?

specifically set value to array not working in new style UDO · Issue #2290 · csound/csound · GitHub

Yep can confirm, that’s the issue

this thing of beauty works:

opcode FlooperOverlap(amp:k, rate:k, loopstart:k, loopsize:k, crossfade:k, ftab:i, ptr:k, nvoices:i, cnt:i):(a)
	my_amp:k = amp*1
	my_rate:k = rate*1
	my_loopstart:k = loopstart*1
	my_loopsize:k = loopsize*1
	my_crossfade:k = crossfade*1
	my_tab:i = ftab*1
	my_ptr:k = ptr*1
	my_nvoices:i = nvoices*1
	my_cnt:i = cnt*1
	asig = flooper2:a(my_amp, my_rate, my_loopstart, my_loopsize, my_crossfade, my_tab)

	if cnt < nvoices-1 then
		asig += FlooperOverlap(amp, rate+random(-0.01, 0.01), loopstart, loopstart+0.1, crossfade, ftab, ptr, nvoices, cnt+1)	
	endif
	xout(asig)
endop

You can also do this instead

opcode Flooper2,a,kkkkkiOoo
amp:k, rate:k, loopstart:k, loopsize:k, crossfade:k, mytab:i, ptr:k, nvoices:k, cnt:i xin
asig = flooper2:a(amp, rate, loopstart, loopsize, crossfade, mytab)
xout(asig)
endop


opcode FlooperOverlap(amp:k, rate:k, loopstart:k, loopsize:k, crossfade:k, mytab:i, ptr:k, nvoices:i, cnt:i):(a)
	puts("FlooperOverlap",1)
	print mytab ;will print 1.0
	asig = Flooper2(amp, rate, loopstart, loopsize, crossfade, mytab)

	if cnt < nvoices-1 then
		asig += FlooperOverlap(amp, rate+random(-0.01, 0.01), loopstart, loopstart+0.1, crossfade, mytab, ptr, nvoices, cnt+1)	
	endif

	xout(asig)
endop

and it will work. The problem seems to be specific to flooper2/flooper - all other opcodes I tried seemed to work.

Thanks @vlz, I got that working. Using the wrapper udo

I did wonder whether something was specifically up with the flooper opcode, as other tests that I’d done didn’t seem to ave trouble with the udo input parameter.

yes, I am still wondering why flooper, but have not found the reason. The original issue was only to do with assignment and the problem is well documented in the PR.

This is now fixed in the develop branch

1 Like