views:

31

answers:

1

I'm wrapping a few calls to the unmanaged Aubio library dll (Aubio.org), and I'm wondering what a good way is to deal with the Aubio samplebuffer.

It's defined like this :

// Buffer for real values
struct _fvec_t {
  uint length;    // length of buffer
  uint channels;  // number of channels
  float **data;   // data array of size [length] * [channels]
};

Aubio creates the struct for me with the datamembers set up correctly, so I get an IntPtr. I need to read/write to the data pointer(s) from my C# code.

for (int chan_idx = 0; chan_idx < my_fvec.channels; ++chan_idx)
    for (int i=0; i<something; i++)
       my_fvec.data[chan_idx][i] = SomeRandomValue();

What is the correct way to 'map' a C# struct to the fvec_t type so I can access the data member properly to read/write to it ?

(Or should I use Marshal.Copy,and how do I do that with the array-of-pointers ?)

A: 

I'd imagine you could define a managed struct and PtrToStructure what you have, modify, then StructureToPtr (back to the same location), but it might be just as simple, since the memory is already allocated and all, to just read out the intptr's for the arrays and then write the float arrays to them with Copy:

http://msdn.microsoft.com/en-us/library/ez2e4559.aspx

James Manning