Bewerken

Delen via


AudioBuffers Class

Definition

Encapsulated a series of AudioBuffers.

public class AudioBuffers : IDisposable, ObjCRuntime.INativeObject
type AudioBuffers = class
    interface IDisposable
    interface INativeObject
Inheritance
AudioBuffers
Implements

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 T: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.

//
// 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);
}

Constructors

AudioBuffers(Int32)

Creates an AudioBuffers structure that can hold a fixed number of AudioBuffer structures.

AudioBuffers(IntPtr, Boolean)

Creates and AudioBuffers object that can be used to query and manipulate a native AudioBuffersList structure.

AudioBuffers(IntPtr)

Creates and AudioBuffers object that can be used to query and manipulate a native AudioBuffersList structure.

Properties

Count

Returns the number of buffers managed.

Handle

Handle (pointer) to the unmanaged object representation.

Item[Int32]

Returns the specified AudioBuffer.

Methods

Dispose()

Releases the resources used by the AudioBuffers object.

Dispose(Boolean)

Releases the resources used by the AudioBuffers object.

Finalize()

Finalizer for the AudioBuffers object

SetData(Int32, IntPtr, Int32)

Sets the data buffer for one of the audio buffers.

SetData(Int32, IntPtr)

Sets the data buffer for one of the audio buffers, without updating the buffer size.

Operators

Explicit(AudioBuffers to IntPtr)

Returns the address of the underlying AudioBufferList structure.

Applies to