TPCircularBuffer+AudioBufferList.h File Reference
#include "TPCircularBuffer.h"
#include <AudioToolbox/AudioToolbox.h>

Go to the source code of this file.

Classes

struct  TPCircularBufferABLBlockHeader
 

Macros

#define kTPCircularBufferCopyAll   UINT32_MAX
 

Functions

AudioBufferList * TPCircularBufferPrepareEmptyAudioBufferList (TPCircularBuffer *buffer, int numberOfBuffers, int bytesPerBuffer, const AudioTimeStamp *timestamp)
 Prepare an empty buffer list, stored on the circular buffer.
 
AudioBufferList * TPCircularBufferPrepareEmptyAudioBufferListWithAudioFormat (TPCircularBuffer *buffer, const AudioStreamBasicDescription *audioFormat, UInt32 frameCount, const AudioTimeStamp *timestamp)
 Prepare an empty buffer list, stored on the circular buffer, using an audio description to automatically configure buffer.
 
void TPCircularBufferProduceAudioBufferList (TPCircularBuffer *buffer, const AudioTimeStamp *inTimestamp)
 Mark next audio buffer list as ready for reading.
 
bool TPCircularBufferCopyAudioBufferList (TPCircularBuffer *buffer, const AudioBufferList *bufferList, const AudioTimeStamp *timestamp, UInt32 frames, const AudioStreamBasicDescription *audioFormat)
 Copy the audio buffer list onto the buffer.
 
 if (!block)
 
 if (outTimestamp)
 
AudioBufferList * TPCircularBufferNextBufferListAfter (TPCircularBuffer *buffer, const AudioBufferList *bufferList, AudioTimeStamp *outTimestamp)
 Get a pointer to the next stored buffer list after the given one.
 
void TPCircularBufferConsumeNextBufferListPartial (TPCircularBuffer *buffer, int framesToConsume, const AudioStreamBasicDescription *audioFormat)
 Consume a portion of the next buffer list.
 
void TPCircularBufferDequeueBufferListFrames (TPCircularBuffer *buffer, UInt32 *ioLengthInFrames, const AudioBufferList *outputBufferList, AudioTimeStamp *outTimestamp, const AudioStreamBasicDescription *audioFormat)
 Consume a certain number of frames from the buffer, possibly from multiple queued buffer lists.
 
UInt32 TPCircularBufferPeek (TPCircularBuffer *buffer, AudioTimeStamp *outTimestamp, const AudioStreamBasicDescription *audioFormat)
 Determine how many frames of audio are buffered.
 
UInt32 TPCircularBufferPeekContiguous (TPCircularBuffer *buffer, AudioTimeStamp *outTimestamp, const AudioStreamBasicDescription *audioFormat, UInt32 contiguousToleranceSampleTime)
 Determine how many contiguous frames of audio are buffered.
 
UInt32 TPCircularBufferPeekContiguousWrapped (TPCircularBuffer *buffer, AudioTimeStamp *outTimestamp, const AudioStreamBasicDescription *audioFormat, UInt32 contiguousToleranceSampleTime, UInt32 wrapPoint)
 Determine how many contiguous frames of audio are buffered, with wrap around.
 
UInt32 TPCircularBufferGetAvailableSpace (TPCircularBuffer *buffer, const AudioStreamBasicDescription *audioFormat)
 Determine how many much space there is in the buffer.
 

Variables

static __inline__ AudioTimeStamp * outTimestamp
 
TPCircularBufferABLBlockHeaderblock = (TPCircularBufferABLBlockHeader*)TPCircularBufferTail(buffer, &dontcare)
 
return &block bufferList
 

Class Documentation

struct TPCircularBufferABLBlockHeader
Class Members
AudioTimeStamp timestamp
UInt32 totalLength
AudioBufferList bufferList

Macro Definition Documentation

#define kTPCircularBufferCopyAll   UINT32_MAX

Function Documentation

AudioBufferList* TPCircularBufferPrepareEmptyAudioBufferList ( TPCircularBuffer buffer,
int  numberOfBuffers,
int  bytesPerBuffer,
const AudioTimeStamp *  timestamp 
)

Prepare an empty buffer list, stored on the circular buffer.

Parameters
bufferCircular buffer
numberOfBuffersThe number of buffers to be contained within the buffer list
bytesPerBufferThe number of bytes to store for each buffer
timestampThe timestamp associated with the buffer, or NULL. Note that you can also pass a timestamp into TPCircularBufferProduceAudioBufferList, to set it there instead.
Returns
The empty buffer list, or NULL if circular buffer has insufficient space
AudioBufferList* TPCircularBufferPrepareEmptyAudioBufferListWithAudioFormat ( TPCircularBuffer buffer,
const AudioStreamBasicDescription *  audioFormat,
UInt32  frameCount,
const AudioTimeStamp *  timestamp 
)

Prepare an empty buffer list, stored on the circular buffer, using an audio description to automatically configure buffer.

Parameters
bufferCircular buffer
audioFormatThe kind of audio that will be stored
frameCountThe number of frames that will be stored
timestampThe timestamp associated with the buffer, or NULL. Note that you can also pass a timestamp into TPCircularBufferProduceAudioBufferList, to set it there instead.
Returns
The empty buffer list, or NULL if circular buffer has insufficient space
void TPCircularBufferProduceAudioBufferList ( TPCircularBuffer buffer,
const AudioTimeStamp *  inTimestamp 
)

Mark next audio buffer list as ready for reading.

This marks the audio buffer list prepared using TPCircularBufferPrepareEmptyAudioBufferList as ready for reading. You must not call this function without first calling TPCircularBufferPrepareEmptyAudioBufferList.

Parameters
bufferCircular buffer
inTimestampThe timestamp associated with the buffer, or NULL to leave as-is. Note that you can also pass a timestamp into TPCircularBufferPrepareEmptyAudioBufferList, to set it there instead.
bool TPCircularBufferCopyAudioBufferList ( TPCircularBuffer buffer,
const AudioBufferList *  bufferList,
const AudioTimeStamp *  timestamp,
UInt32  frames,
const AudioStreamBasicDescription *  audioFormat 
)

Copy the audio buffer list onto the buffer.

Parameters
bufferCircular buffer
bufferListBuffer list containing audio to copy to buffer
timestampThe timestamp associated with the buffer, or NULL
framesLength of audio in frames. Specify kTPCircularBufferCopyAll to copy the whole buffer (audioFormat can be NULL, in this case)
audioFormatThe AudioStreamBasicDescription describing the audio, or NULL if you specify kTPCircularBufferCopyAll to the frames argument
Returns
YES if buffer list was successfully copied; NO if there was insufficient space
if ( block)
if ( outTimestamp  )
AudioBufferList* TPCircularBufferNextBufferListAfter ( TPCircularBuffer buffer,
const AudioBufferList *  bufferList,
AudioTimeStamp *  outTimestamp 
)

Get a pointer to the next stored buffer list after the given one.

Parameters
bufferCircular buffer
bufferListPreceding buffer list
outTimestampOn output, if not NULL, the timestamp corresponding to the buffer
Returns
Pointer to the next buffer list in the buffer, or NULL
void TPCircularBufferConsumeNextBufferListPartial ( TPCircularBuffer buffer,
int  framesToConsume,
const AudioStreamBasicDescription *  audioFormat 
)

Consume a portion of the next buffer list.

This will also increment the sample time and host time portions of the timestamp of the buffer list, if present.

Parameters
bufferCircular buffer
framesToConsumeThe number of frames to consume from the buffer list
audioFormatThe AudioStreamBasicDescription describing the audio
void TPCircularBufferDequeueBufferListFrames ( TPCircularBuffer buffer,
UInt32 *  ioLengthInFrames,
const AudioBufferList *  outputBufferList,
AudioTimeStamp *  outTimestamp,
const AudioStreamBasicDescription *  audioFormat 
)

Consume a certain number of frames from the buffer, possibly from multiple queued buffer lists.

Copies the given number of frames from the buffer into outputBufferList, of the given audio description, then consumes the audio buffers. If an audio buffer has not been entirely consumed, then updates the queued buffer list structure to point to the unconsumed data only.

Parameters
bufferCircular buffer
ioLengthInFramesOn input, the number of frames in the given audio format to consume; on output, the number of frames provided
outputBufferListThe buffer list to copy audio to, or NULL to discard audio. If not NULL, the structure must be initialised properly, and the mData pointers must not be NULL.
outTimestampOn output, if not NULL, the timestamp corresponding to the first audio frame returned
audioFormatThe format of the audio stored in the buffer
UInt32 TPCircularBufferPeek ( TPCircularBuffer buffer,
AudioTimeStamp *  outTimestamp,
const AudioStreamBasicDescription *  audioFormat 
)

Determine how many frames of audio are buffered.

Given the provided audio format, determines the frame count of all queued buffers

Note: This function should only be used on the consumer thread, not the producer thread.

Parameters
bufferCircular buffer
outTimestampOn output, if not NULL, the timestamp corresponding to the first audio frame
audioFormatThe format of the audio stored in the buffer
Returns
The number of frames in the given audio format that are in the buffer
UInt32 TPCircularBufferPeekContiguous ( TPCircularBuffer buffer,
AudioTimeStamp *  outTimestamp,
const AudioStreamBasicDescription *  audioFormat,
UInt32  contiguousToleranceSampleTime 
)

Determine how many contiguous frames of audio are buffered.

Given the provided audio format, determines the frame count of all queued buffers that are contiguous, given their corresponding timestamps (sample time).

Note: This function should only be used on the consumer thread, not the producer thread.

Parameters
bufferCircular buffer
outTimestampOn output, if not NULL, the timestamp corresponding to the first audio frame
audioFormatThe format of the audio stored in the buffer
contiguousToleranceSampleTimeThe number of samples of discrepancy to tolerate
Returns
The number of frames in the given audio format that are in the buffer
UInt32 TPCircularBufferPeekContiguousWrapped ( TPCircularBuffer buffer,
AudioTimeStamp *  outTimestamp,
const AudioStreamBasicDescription *  audioFormat,
UInt32  contiguousToleranceSampleTime,
UInt32  wrapPoint 
)

Determine how many contiguous frames of audio are buffered, with wrap around.

Like TPCircularBufferPeekContiguous, determines how many contiguous frames are buffered, but considers audio that wraps around a region of a given length as also contiguous. This is good for audio that loops.

Note: This function should only be used on the consumer thread, not the producer thread.

Parameters
bufferCircular buffer
outTimestampOn output, if not NULL, the timestamp corresponding to the first audio frame
audioFormatThe format of the audio stored in the buffer
contiguousToleranceSampleTimeThe number of samples of discrepancy to tolerate
wrapPointThe point around which the audio may wrap and still be considered contiguous, or 0 to disable
Returns
The number of frames in the given audio format that are in the buffer
UInt32 TPCircularBufferGetAvailableSpace ( TPCircularBuffer buffer,
const AudioStreamBasicDescription *  audioFormat 
)

Determine how many much space there is in the buffer.

Given the provided audio format, determines the number of frames of audio that can be buffered.

Note: This function should only be used on the producer thread, not the consumer thread.

Parameters
bufferCircular buffer
audioFormatThe format of the audio stored in the buffer
Returns
The number of frames in the given audio format that can be stored in the buffer

Variable Documentation

__inline__ AudioTimeStamp* outTimestamp
Initial value:
{
int32_t dontcare
TPCircularBufferABLBlockHeader* block = (TPCircularBufferABLBlockHeader*)TPCircularBufferTail(buffer, &dontcare)
return& block bufferList