SndAudioBufferQueue Class Reference

Abstraction of the producer / consumer buffer queue operation found inside the SndStreamClients, which have both an input and output SndAudioBufferQueue. Provides thread safe buffer exchange and blocking operations. More...

#import <SndAudioBufferQueue.h>

List of all members.

Public Member Functions

(id) - initQueueWithLength:
 Initializes queue for operation with a total of pending+processed buffers.
(SndAudioBuffer *) - popNextPendingBuffer
 Blocks the calling thread until a buffer is present for popping.
(SndAudioBuffer *) - popNextProcessedBuffer
 Returns the next.
(id) - addPendingBuffer:
 Adds buffer to the pending queue.
(id) - addProcessedBuffer:
 Adds a buffer to the processed queue.
(void) - cancelProcessedBuffers
 Moves all processed buffers onto the pending queue.
(int) - pendingBuffersCount
(int) - processedBuffersCount
(id) - freeBuffers
 Frees the SndAudioBuffers within the queues.
(id) - prepareQueueAsType:withBufferPrototype:
 Primes the SndAudioBufferQueue for streaming.
(int) - bufferCount
 Returns the total number of buffers being shuffled about betwixt pending and processed queues.

Static Public Member Functions

(id) + audioBufferQueueWithLength:
 Factory method.

Protected Attributes

NSMutableArray * pendingBuffers
NSMutableArray * processedBuffers
NSConditionLock * pendingBuffersLock
NSConditionLock * processedBuffersLock
int numBuffers


Detailed Description

Abstraction of the producer / consumer buffer queue operation found inside the SndStreamClients, which have both an input and output SndAudioBufferQueue. Provides thread safe buffer exchange and blocking operations.

Member Function Documentation

+ (id) audioBufferQueueWithLength: (int)  n  

Factory method.

Parameters:
n Buffer queue length
Creates a fresh new SndAudioBufferQueue, sets the eventual number of buffers to n.
Returns:
An SndAudioBufferQueue

- (id) initQueueWithLength: (int)  n  

Initializes queue for operation with a total of pending+processed buffers.

Since we add and pop buffers in separate methods, if we try to add before popping, we will need to use one less than the full number of buffers initialized with, such that we never exceed the maximum. For example, if we initialize with 4 buffers, at best we can hold only 3 processed buffers so we can add a pending buffer, before then popping a processed buffer.

Parameters:
n Number of buffers.
Returns:
Returns self.

- (SndAudioBuffer*) popNextPendingBuffer  

Blocks the calling thread until a buffer is present for popping.

Returns:
  • output - The next buffer to be synthesized / produced
  • input - The next input buffer to be processed

- (SndAudioBuffer*) popNextProcessedBuffer  

Returns the next.

Blocks the calling thread until a buffer is present for popping.

Returns:
  • output - The next buffer to be consumed by the world at large
  • input - The next buffer to be filled with input material

- (id) addPendingBuffer: (SndAudioBuffer *)  audioBuffer  

Adds buffer to the pending queue.

Parameters:
audioBuffer Buffer to be added
Returns:
Returns self.

- (id) addProcessedBuffer: (SndAudioBuffer *)  audioBuffer  

Adds a buffer to the processed queue.

Parameters:
audioBuffer Buffer to be added
Returns:
Returns self.

- (int) pendingBuffersCount  

Returns:
Number of buffers in the pending queue

- (int) processedBuffersCount  

Returns:
Number of buffers in the processed queue

- (id) freeBuffers  

Frees the SndAudioBuffers within the queues.

Returns:
Returns self

- (id) prepareQueueAsType: (SndAudioBufferQueueType)  type
withBufferPrototype: (SndAudioBuffer *)  buff 

Primes the SndAudioBufferQueue for streaming.

Parameters:
type Either audioBufferQueue_typeInput or audioBufferQueue_typeOutput
buff The format of the SndAudioBuffer buff will be used as a template for the internal queued buffers.
If prepared as an input queue, the buffers are initially placed in the processed queue; otherwise the fresh buffers are placed in the pending queue. The former ensures that any input buffer consumers do not get empty buffers, and the latter allows buffer producers (eg synthesizers) to process several buffers ahead, giving them some processing head room in a multi-threaded environment.
Returns:
Returns self.

- (int) bufferCount  

Returns the total number of buffers being shuffled about betwixt pending and processed queues.

Returns:
Number of buffers in queues


Member Data Documentation

- (NSMutableArray*) pendingBuffers [protected]

Array of buffers pending processing (to be consumed)

- (NSMutableArray*) processedBuffers [protected]

Array of processed buffers (post consumption)

- (NSConditionLock*) pendingBuffersLock [protected]

Lock for thread safety around pending buffers array

- (NSConditionLock*) processedBuffersLock [protected]

Lock for thread safety around processed buffers array

- (int) numBuffers [protected]

Total number of buffers in the queue, both pending and processed


The documentation for this class was generated from the following file:

Generated on Sat Dec 5 17:01:16 2009 for MusicKit by  doxygen 1.5.6