Go to the source code of this file.
Classes | |
struct | AECircularBuffer |
Circular buffer. More... | |
Macros | |
#define | AECircularBufferCopyAll UINT32_MAX |
Functions | |
BOOL | AECircularBufferInit (AECircularBuffer *buffer, UInt32 capacityInFrames, int channelCount, double sampleRate) |
Initialize buffer. | |
void | AECircularBufferCleanup (AECircularBuffer *buffer) |
Cleanup buffer. | |
void | AECircularBufferClear (AECircularBuffer *buffer) |
Clear buffer. | |
void | AECircularBufferSetAtomic (AECircularBuffer *buffer, BOOL atomic) |
Set the atomicity. | |
void | AECircularBufferSetChannelCountAndSampleRate (AECircularBuffer *buffer, int channelCount, double sampleRate) |
Change channel count and/or sample rate. | |
UInt32 | AECircularBufferGetAvailableSpace (AECircularBuffer *buffer) |
Determine how many much space there is in the buffer. | |
BOOL | AECircularBufferEnqueue (AECircularBuffer *buffer, const AudioBufferList *bufferList, const AudioTimeStamp *timestamp, UInt32 frames) |
Copy the audio buffer list onto the buffer. | |
AudioBufferList * | AECircularBufferPrepareEmptyAudioBufferList (AECircularBuffer *buffer, UInt32 frameCount, const AudioTimeStamp *timestamp) |
Prepare an empty buffer list, stored on the circular buffer. | |
void | AECircularBufferProduceAudioBufferList (AECircularBuffer *buffer) |
Mark next audio buffer list as ready for reading. | |
UInt32 | AECircularBufferPeek (AECircularBuffer *buffer, AudioTimeStamp *outTimestamp) |
Determine how many frames of audio are buffered. | |
void | AECircularBufferDequeue (AECircularBuffer *buffer, UInt32 *ioLengthInFrames, const AudioBufferList *outputBufferList, AudioTimeStamp *outTimestamp) |
Copy a certain number of frames from the buffer and dequeue. | |
AudioBufferList * | AECircularBufferNextBufferList (AECircularBuffer *buffer, AudioTimeStamp *outTimestamp, const AudioBufferList *lastBufferList) |
Access the next stored buffer list. | |
void | AECircularBufferConsumeNextBufferList (AECircularBuffer *buffer) |
Consume the next buffer list available for reading. | |
void | AECircularBufferConsumeNextBufferListPartial (AECircularBuffer *buffer, UInt32 frames) |
Consume a portion of the next buffer list. | |
struct AECircularBuffer |
Circular buffer.
This utility provides a thread-safe and lock-free FIFO buffer that operates on AudioBufferLists and tracks the AudioTimeStamps corresponding to the audio.
It provides a convenience wrapper to TPCircularBuffer and its AudioBufferList utilities, by avoiding the need to provide an AudioStreamBasicDescription to the various functions, among other things.
It's generally preferable to use this interface instead of TPCircularBuffer if you're just using the TAAE audio format (non-interleaved float).
Class Members | ||
---|---|---|
TPCircularBuffer | buffer | |
AudioStreamBasicDescription | audioDescription |
#define AECircularBufferCopyAll UINT32_MAX |
BOOL AECircularBufferInit | ( | AECircularBuffer * | buffer, |
UInt32 | capacityInFrames, | ||
int | channelCount, | ||
double | sampleRate | ||
) |
Initialize buffer.
Note that the length is advisory only; the true buffer length will be multiples of the device page size (e.g. 4096 bytes)
buffer | Circular buffer |
capacityInFrames | Amount of audio frames you wish to store in the buffer |
channelCount | Number of channels of audio you'll be working with |
sampleRate | Sample rate of audio, used to work with AudioTimeStamps |
void AECircularBufferCleanup | ( | AECircularBuffer * | buffer | ) |
Cleanup buffer.
Releases buffer resources.
void AECircularBufferClear | ( | AECircularBuffer * | buffer | ) |
Clear buffer.
Resets buffer to original, empty state.
This is safe for use by consumer while producer is accessing the buffer.
void AECircularBufferSetAtomic | ( | AECircularBuffer * | buffer, |
BOOL | atomic | ||
) |
Set the atomicity.
If you set the atomiticy to false using this method, the buffer will not use atomic operations. This can be used to give the compiler a little more optimisation opportunities when the buffer is only used on one thread.
Important note: Only set this to false if you know what you're doing!
The default value is true (the buffer will use atomic operations)
buffer | Circular buffer |
atomic | Whether the buffer is atomic (default true) |
void AECircularBufferSetChannelCountAndSampleRate | ( | AECircularBuffer * | buffer, |
int | channelCount, | ||
double | sampleRate | ||
) |
Change channel count and/or sample rate.
This will cause the buffer to clear any existing audio, and reconfigure to use the new channel count and sample rate. Note that it will not alter the buffer's capacity; if you need to increase capacity to cater to a larger number of channels/frames, then you'll need to cleanup and re-initialize the buffer.
You should only use this on the consumer thread.
buffer | Circular buffer |
channelCount | Number of channels of audio you'll be working with |
sampleRate | Sample rate of audio, used to work with AudioTimeStamps |
UInt32 AECircularBufferGetAvailableSpace | ( | AECircularBuffer * | buffer | ) |
Determine how many much space there is in the buffer.
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.
buffer | Circular buffer |
BOOL AECircularBufferEnqueue | ( | AECircularBuffer * | buffer, |
const AudioBufferList * | bufferList, | ||
const AudioTimeStamp * | timestamp, | ||
UInt32 | frames | ||
) |
Copy the audio buffer list onto the buffer.
buffer | Circular buffer |
bufferList | Buffer list containing audio to copy to buffer |
timestamp | The timestamp associated with the buffer, or NULL |
frames | Length of audio in frames, or AECircularBufferCopyAll to copy the whole buffer |
AudioBufferList* AECircularBufferPrepareEmptyAudioBufferList | ( | AECircularBuffer * | buffer, |
UInt32 | frameCount, | ||
const AudioTimeStamp * | timestamp | ||
) |
Prepare an empty buffer list, stored on the circular buffer.
buffer | Circular buffer |
frameCount | The number of frames that will be stored |
timestamp | The timestamp associated with the buffer, or NULL. |
void AECircularBufferProduceAudioBufferList | ( | AECircularBuffer * | buffer | ) |
Mark next audio buffer list as ready for reading.
This marks the audio buffer list prepared using AECircularBufferPrepareEmptyAudioBufferList as ready for reading. You must not call this function without first calling AECircularBufferPrepareEmptyAudioBufferList.
buffer | Circular buffer |
UInt32 AECircularBufferPeek | ( | AECircularBuffer * | buffer, |
AudioTimeStamp * | outTimestamp | ||
) |
Determine how many frames of audio are buffered.
Note: This function should only be used on the consumer thread, not the producer thread.
buffer | Circular buffer |
outTimestamp | On output, if not NULL, the timestamp corresponding to the first audio frame |
void AECircularBufferDequeue | ( | AECircularBuffer * | buffer, |
UInt32 * | ioLengthInFrames, | ||
const AudioBufferList * | outputBufferList, | ||
AudioTimeStamp * | outTimestamp | ||
) |
Copy a certain number of frames from the buffer and dequeue.
buffer | Circular buffer |
ioLengthInFrames | On input, the number of frames to consume; on output, the number of frames provided |
outputBufferList | The buffer list to copy audio to, or NULL to discard audio. |
outTimestamp | On output, if not NULL, the timestamp corresponding to the first audio frame returned |
AudioBufferList* AECircularBufferNextBufferList | ( | AECircularBuffer * | buffer, |
AudioTimeStamp * | outTimestamp, | ||
const AudioBufferList * | lastBufferList | ||
) |
Access the next stored buffer list.
buffer | Circular buffer |
outTimestamp | On output, if not NULL, the timestamp corresponding to the buffer |
lastBufferList | If not NULL, the preceding buffer list on the buffer. The next buffer list after this will be returned; use this to iterate through all queued buffers. If NULL, this function will return the first queued buffer. |
void AECircularBufferConsumeNextBufferList | ( | AECircularBuffer * | buffer | ) |
Consume the next buffer list available for reading.
buffer | Circular buffer |
void AECircularBufferConsumeNextBufferListPartial | ( | AECircularBuffer * | buffer, |
UInt32 | frames | ||
) |
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.
buffer | Circular buffer |
frames | The number of frames to consume from the buffer list |