# MTAudioBuffer

Inherits from: MTBuffer

An MTAudioBuffer is a thread-safe, flow-controlled, fixed-size audio sample buffer. It is a concrete subclass of MTBuffer where each abstract frame is one audio frame, consisting of one or more channels of Float32 samples. It is intended to be used as a producer/consumer conduit for Core Audio's audio samples where each of producer and consumer may be batch-oriented or time-constrained. It can copy frames to and from AudioBufferLists that have any number of streams and any number of interleaved channels per stream, including one channel per stream, which is the canonical de-interleaved format.

## Method Types

- Creating instances
  - - init
  - - initWithCapacityFrames:channels:
- Working with attributes
  - - capacity
  - - channels
  - - count
  - - rateScalar
  - - scaledCount
- Working with data
  - - flush
  - - readToAudioBufferList:maxFrames:waitForData:
  - - writeFromAudioBufferList:maxFrames:rateScalar:waitForRoom:

## Instance Methods

### capacity

`- (unsigned) capacity`
Returns the number of channels-wide frames of audio the receiver can hold.

### channels

`- (unsigned) channels`
Returns the number of channels in each frame of the receiver's audio.

### count

`- (unsigned) count`
Returns the number of channels-wide frames of audio currently stored in the receiver.

### flush

`- (void) flush`
Empties the receiver.

### init

`- (id) init`
Initializes a newly allocated buffer with space for 44100 stereo (2-channel) frames. This is equivalent to initWithCapacityFrames:44100 channels:2.

### initWithCapacityFrames:channels:

`- (id) initWithCapacityFrames:(unsigned)frames channels:(unsigned)channels`
Initializes a newly allocated buffer with space for frames of channels-wide frames of audio. This is the designated initializer.

### rateScalar

`- (Float64) rateScalar`
Returns the cumulative rate scalar for the frames currently stored in the receiver; that is, the ratio of scaledCount to count. This value is informational and does not affect the number of real frames read from or written to the receiver.

### readToAudioBufferList:maxFrames:waitForData:

`- (unsigned) readToAudioBufferList:(AudioBufferList *)theABL maxFrames:(unsigned)count waitForData:(Boolean)wait`
Attempts to fill theABL with audio frames from the receiver. If count is less than the capacity of theABL, then no more than count frames will be copied. If wait is `NO`, then that number is further limited to the number of frames currently on hand in the buffer. If wait is `YES`, then this method will pause if necessary until enough data has been written into the receiver by writeFromAudioBufferList:maxFrames:rateScalar:waitForRoom: to supply the request. If theABL has fewer channels than the receiver, then excess channels in the copied frames are discarded. If theABL has more channels than the receiver, then the excess channels are cleared to silence. scaledCount is decreased by the number of frames copied, scaled by rateScalar.
Returns the number of frames copied from the receiver into theABL.

### scaledCount

`- (Float64) scaledCount`
Returns the number of frames currently stored in the receiver, as though they had been scaled according to the rateScalar: parameter of writeFromAudioBufferList:maxFrames:rateScalar:waitForRoom: when written into the receiver. This value is informational and does not affect the number of real frames read from or written to the receiver.

### writeFromAudioBufferList:maxFrames:rateScalar:waitForRoom:

`- (unsigned) writeFromAudioBufferList:(const AudioBufferList *)theABL maxFrames:(unsigned)count rateScalar:(Float64)rateScalar waitForRoom:(Boolean)wait`
Attempts to copy all of the frames from theABL into the receiver. If count is less than the capacity of theABL, then no more than count frames will be copied. If wait is `NO`, then that number is further restricted to the amount of currently unused space in the receiver, and that many frames are copied immediately. If wait is `YES`, then this method will pause if necessary until enough room has been made by readToAudioBufferList:maxFrames:waitForData: to accommodate the request. If theABL has fewer channels than the receiver, then the excess channels of the receiver are filled with silence. If theABL has more channels than the receiver, then excess channels of theABL are discarded. scaledCount is increased by the product of rateScalar and the number of frames copied.
Returns the number of frames copied from theABL into the receiver.

Mike > Mac OS X > MTCoreAudio.framework > MTAudioBuffer