Hi all,
I’m making some experiments with the aim to create some examples for CsoundUnity, in this case i’m trying to transfer data using tables.
I’m trying to continuously fill a table with new values in Csound, and reading this changed values from Unity.
This is not working, just the first two values of the table are updated, whichever size it is (I tried creating it in the score with “f”, with ftgen, and also from CsoundUnity with CreateTable/CreateTableInstrument).
What I noticed is that if I create the function with “f” the len is always -1, meaning that the table doesn’t exist!
This is the code which should copy the content to a destination array:
public void TableCopyOut(int table, out MYFLT[] dest)
{
int len = Csound6.NativeMethods.csoundTableLength(csound, table);
if (len < 1)
{
dest = null;
return;
}
dest = new MYFLT[len];
IntPtr des = Marshal.AllocHGlobal(sizeof(MYFLT) * dest.Length);
Csound6.NativeMethods.csoundTableCopyOut(csound, table, des);
Marshal.Copy(des, dest, 0, len);
Marshal.FreeHGlobal(des);
}
What could be wrong with this?
As far as I remember, this was working, we tested it in the past
This is the Csound code I’m using:
instr 99
;generate the table
giFt ftgen 100, 0, 256, -2, 0;
;test code to see if the table is updated with noise
kbeta line -0.9999, p3, 0.9999 ;change beta value between -1 to 1
asig noise .3, kbeta
asig clip asig, 2, .9 ;clip signal
ilen = ftlen(100)
prints "ilen 100: ", ilen
aph phasor sr / 256
;kpos = k(aph)
;printk2 kpos
;tablew asig, aph, 100, 1
tabw asig, aph, 100
endin
Probably there is some mistake here so that the table is not updated, but printing kpos reports 8 values as expected (0.00000, 0.12500, 0.25000, 0.37500, 0.50000, 0.62500, 0.75000, 0.87500).
Any suggestion?