0
0

[color=red:3bttha0c][b:3bttha0c]Topic: the dsp_custom example for c#[/b:3bttha0c][/color:3bttha0c]

It would be better to use no unsafe code 😉

Your [color=red:3bttha0c][b:3bttha0c]unsafe code[/b:3bttha0c][/color:3bttha0c] inside “private static
FMOD.RESULT READCALLBACK”:
[code:3bttha0c]
private static FMOD.RESULT READCALLBACK(...)
{
// something nonrelevant has been omitted here

unsafe
{
    float *inbuffer = (float*) inbuf.ToPointer();
    float *outbuffer = (float*) outbuf.ToPointer();

    // some data processing here
}

}
[/code:3bttha0c]

My [color=red:3bttha0c][b:3bttha0c]safe alternative[/b:3bttha0c][/color:3bttha0c] code:
[code:3bttha0c]
private static FMOD.RESULT READCALLBACK(...)
{
// something nonrelevant has been omitted here

// Length for new float array and for marshal (see below)
int lengthIn = (int) length * outchannels + outchannels;
int lengthOut = (int) length * inchannels + outchannels;

// New and empty float arrays
float[] inbuffer = new float[lengthIn];
float[] outbuffer = new float[lengthOut];

// Copy data from pointer (inbuf) to my float array.
Marshal.Copy(inbuf, inbuffer, 0, lengthIn);

// ---------------------------
// some data processing here
// ---------------------------

// Copy data from my array (outbuffer) to pointer (outbuf)
Marshal.Copy(outbuffer, 0, outbuf, lengthOut);

// Result...
return FMOD.RESULT.OK;

}
[/code:3bttha0c]

[color=red:3bttha0c][b:3bttha0c]Important:[/b:3bttha0c][/color:3bttha0c] [i:3bttha0c]using System.Runtime.InteropServices;[/i:3bttha0c]
You have to import InteropServices to use Marshal.

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.