AudioToolbox.AudioBuffers Class
Encapsulated a series of AudioBuffers.

See Also: AudioBuffers Members

Syntax

public class AudioBuffers : IDisposable

Remarks

The AudioBuffers class encapsulates one or more AudioToolbox.AudioBuffer structures. It can be used to examine the contents of an AudioBuffer when you create the instance from an IntPtr that points to the C-based AudioBufferList array or as a way of creating buffers that can be passed to C-based APIs when you use the constructor that takes a count argument.

If you cast this object to an IntPtr, you will get the address to the underlying data structure which you can pass to any C APIs that requires a pointer to the object.

For interleaved stereo audio buffers (for example when the Left and Right audio packets are in a single stream) there is a single AudioBuffer which contains both the left and right sample in the buffer. For non-interleaved stereo buffers, there are two buffers, the left samples are stored in one buffer and the right samples are stored on the other one.

This is an immutable data structure, if you are looking for a mutable version, see the AudioToolbox.MutableAudioBufferList.

If you create an object with a number of set buffers, or your set the "owns" parameter in your constructor to true, then Dispose will call Marshal.FreeHGlobal on the underlying buffer.

c# Example

//
// Consuming an AudioBufferList from a pointer provided by C code
//
void Process (IntPtr audioBufferListPtr)
{
    var buffers = new AudioBuffers (audioBufferListPtr);
    for (int i = 0; i < buffers.Count; i++){
	var audioBuffer = buffers [i];
	Console.WriteLine ("Data={0} DataByteSize={1}", audioBuffer.Data, audioBuffer.DataByteSize);
    }
}

//
// Creating an AudioBuffers structure 
//
AudioBuffers SetupBuffers (int n = 2, int size = 4096)
{
    var buffers = new AudioBuffers (n);
    for (int i = 0; i < n; i++){
        var buffer = Marshal.AllocHGlobal (size);
	buffers.SetData (i, buffer, size);
    }
    return buffers;
}

void ReleaseBuffers (AudioBuffers buffers)
{
    for (int i = 0; i < buffers.Count; i++){
        var buf = buffers [i];
        Marshal.ReleaseHGlobal (buf.Data);                
    }
    buffers.Dispose ();
}

void ProcessBuffers (AudioBuffers buffers)
{
    // Call C-function that takes an AudioBufferList pointer:

    // The cast extracts the data.
    c_function ((IntPtr) buffers);
}

Requirements

Namespace: AudioToolbox
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0