public void WriteAsync(int numberFrames, AudioBufferList data) { IntPtr buffer = data == null ? IntPtr.Zero : data.ToPointer (); int err = ExtAudioFileWriteAsync(_extAudioFile, numberFrames, buffer); // Try not to leak unmanaged pointer buffer if (last_async_write_buffer_ptr != IntPtr.Zero) { Marshal.FreeHGlobal (last_async_write_buffer_ptr); last_async_write_buffer_ptr = IntPtr.Zero; } if (err != 0) { if (buffer != IntPtr.Zero) Marshal.FreeHGlobal (buffer); throw new ArgumentException(String.Format("Error code:{0}", err)); } if (buffer != IntPtr.Zero) { last_async_write_buffer_ptr = buffer; } }
public int Read(int numberFrames, AudioBufferList data) { if (data == null) throw new ArgumentNullException ("data"); var ptr = data.ToPointer (); int err = ExtAudioFileRead(_extAudioFile, ref numberFrames, ptr); Marshal.FreeHGlobal (ptr); if (err != 0) { throw new ArgumentException(String.Format("Error code:{0}", err)); } return numberFrames; }