iOS Guides | Samples

MonoTouch.AudioToolbox.AudioBuffers Class

Encapsulated a series of AudioBuffers.

See Also: AudioBuffers

Syntax

public class AudioBuffers : INativeObject, IDisposable

Remarks

The AudioBuffers class encapsulates one or more 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 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: MonoTouch.AudioToolbox
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.AudioToolbox.AudioBuffers are listed below.

See Also: Object

Public Constructors

Creates an AudioBuffers structure that can hold a fixed number of AudioBuffer structures.
Creates and AudioBuffers object that can be used to query and manipulate a native AudioBuffersList structure.
Creates and AudioBuffers object that can be used to query and manipulate a native AudioBuffersList structure.Creates and AudioBuffers object that can be used to query and manipulate a native AudioBuffersList structure.

Public Properties

[read-only]
CountInt32. Returns the number of buffers managed.
[read-only]
HandleIntPtr. Handle (pointer) to the unmanaged object representation.
default property
Item(Int32)AudioBuffer. Returns the specified AudioBuffer.

Public Methods

Dispose()
Releases the resources used by the AudioBuffers object.
Finalize()
Finalizer for the AudioBuffers object
SetData(Int32, IntPtr)
Sets the data buffer for one of the audio buffers, without updating the buffer size.
SetData(Int32, IntPtr, Int32)
Sets the data buffer for one of the audio buffers.

Protected Methods

Dispose(Boolean)
Releases the resources used by the AudioBuffers object.

Public Operators

static
Conversion to System.IntPtr(Explicit)Returns the address of the underlying AudioBufferList structure.