I have a function in my custom C library which returns a pointer to a float. (This is actually an array of floats which contains audio values).
I want to use this C library (and returned float array) in Unity3d so I am writing a C# wrapper for it. How do I properly import/declare my C function in my C# script ?
my C declarations looks like this:
float* getAudioBuffer(mySynth_t synth);
In C# my guess is that I should declared my imported function as returning float like this:
[DllImport (dll)]
private static extern float[] aae_getAudioBuffer( IntPtr synth)
Is that correct? Shall I use ref keyword? Shall I use out keyword somewhere? I familiar with C++ but bot at all with C# so I do not really understand mashalling etc. I read somewhere that there is a pinning process involved
Also the data in the float array are audio data that I want to copy to Unity3d’s audio buffer in OnFilterRead. So this will be called many times. I read somewhere that there is a pinning process involved and I am not sure what to do of it.
Any hint, sample code, or pointer on best practices to get a float pointer (or float array) from C and pass it (or copy it if I have to) would be appreciated.