| Framework | AudioToolbox/AudioToolbox.h |
| Declared in | AudioQueue.h |
This document describes Audio Queue Services, a C programming interface in the Audio Toolbox framework, which is part of Core Audio.
An audio queue is a software object you use for recording or playing audio in Mac OS X. An audio queue does the work of:
Connecting to audio hardware
Managing memory
Employing codecs, as needed, for compressed audio formats
Mediating playback or recording
Audio Queue Services enables you to record and play audio in linear PCM, in compressed formats (such as Apple Lossless and AAC), and in other formats for which users have installed codecs. Audio Queue Services also supports scheduled playback and synchronization of multiple audio queues and synchronization of audio with video.
Note: Audio Queue Services provides features similar to those previously offered by the Sound Manager and adds additional features such as synchronization. The Sound Manager is deprecated in Mac OS X v10.5 and does not work with 64-bit applications. Audio Queue Services is recommended for all new development and as a replacement for the Sound Manager in existing applications.
AudioQueueAllocateBuffer
AudioQueueFreeBuffer
AudioQueueEnqueueBuffer
AudioQueueEnqueueBufferWithParameters
AudioQueueGetProperty
AudioQueueSetProperty
AudioQueueGetPropertySize
AudioQueueAddPropertyListener
AudioQueueRemovePropertyListener
AudioQueueCreateTimeline
AudioQueueDisposeTimeline
AudioQueueDeviceGetCurrentTime
AudioQueueDeviceGetNearestStartTime
AudioQueueDeviceTranslateTime
AudioQueueGetCurrentTime
Adds a property listener callback to an audio queue.
OSStatus AudioQueueAddPropertyListener ( AudioQueueRef inAQ, AudioQueuePropertyID inID, AudioQueuePropertyListenerProc inProc, void *inUserData );
The audio queue that you want to assign a property listener callback to.
The ID of the property whose changes you want to respond to. See “Audio Queue Property IDs.”
The callback to be invoked when the property value changes.
Custom data for the property listener callback.
A result code. See “Audio Queue Result Codes.”
Use this function to let your application respond to property value changes in an audio queue. For example, say your application’s user interface has a button that acts as a Play/Stop toggle switch. When an audio file has finished playing, the audio queue stops and the value of the kAudioQueueProperty_IsRunning property changes from true to false. You can use a property listener callback to update the button text appropriately.
AudioQueue.hAsks an audio queue to allocate an audio queue buffer.
OSStatus AudioQueueAllocateBuffer ( AudioQueueRef inAQ, UInt32 inBufferByteSize, AudioQueueBufferRef *outBuffer );
The audio queue you want to allocate a buffer.
The desired capacity of the new buffer, in bytes. Appropriate capacity depends on the processing you will perform on the data as well as on the audio data format.
On output, points to the newly allocated audio queue buffer.
A result code. See “Audio Queue Result Codes.”
Once allocated, the pointer to the audio queue buffer and the buffer’s capacity cannot be changed. The buffer’s size field, mAudioDataByteSize, which indicates the amount of valid data, is initially set to 0.
AudioQueue.hCreates a timeline object for an audio queue.
OSStatus AudioQueueCreateTimeline ( AudioQueueRef inAQ, AudioQueueTimelineRef *outTimeline );
The audio queue to associate with the new timeline object.
On output, the newly created timeline object.
A result code. See “Audio Queue Result Codes.”
Create a timeline object if you want to get timeline discontinuity information from an audio queue using the AudioQueueGetCurrentTime function.
AudioQueue.hGets the current time of the audio hardware device associated with an audio queue.
OSStatus AudioQueueDeviceGetCurrentTime ( AudioQueueRef inAQ, AudioTimeStamp *outDeviceTime );
The audio queue whose associated audio device is to be queried.
On output, the current time of the audio hardware device associated with the audio queue. If the device is not running, the only valid field in the audio timestamp structure is mHostTime.
A result code. See “Audio Queue Result Codes.”
This function returns a value whether or not the audio hardware device associated with the audio queue is running. The similar AudioDeviceGetCurrentTime function, declared in the AudioHardware.h header file, returns an error in this case.
AudioQueue.hGets the start time, for an audio hardware device, that is closest to a requested start time.
OSStatus AudioQueueDeviceGetNearestStartTime ( AudioQueueRef inAQ, AudioTimeStamp *ioRequestedDeviceTime, UInt32 inFlags );
The audio queue whose associated audio hardware device’s start time you want to get.
On input, the requested start time. On output, the actual start time.
Reserved for future use. Pass 0.
A result code. See “Audio Queue Result Codes.”
This function asks an audio queue’s associated device for a start time to use for recording or playback. The time returned will be equal to or later than the requested start time, depending on device and system factors. For example, the start time might be shifted to allow for aligning buffer access. The device must be running to use this function.
AudioQueue.hConverts the time for an audio queue’s associated audio hardware device from one time base representation to another.
OSStatus AudioQueueDeviceTranslateTime ( AudioQueueRef inAQ, const AudioTimeStamp *inDeviceTime, AudioTimeStamp *outDeviceTime );
The audio queue associated with the device whose times are being translated.
The time to be translated.
On output, the translated time.
A result code. See “Audio Queue Result Codes.”
The device must be running for this function to provide a result. For an explanation of the various time base representations for an audio hardware device, see AudioTimeStamp in Core Audio Data Types Reference.
AudioQueue.hDisposes of an audio queue.
OSStatus AudioQueueDispose ( AudioQueueRef inAQ, Boolean inImmediate );
The audio queue you want to dispose of.
If you pass true, the audio queue is disposed of immediately (that is, synchronously). If you pass false, disposal does not take place until all enqueued buffers are processed (that is, asynchronously).
A result code. See “Audio Queue Result Codes.”
Disposing of an audio queue also disposes of its resources, including its buffers. After you call this function, you can no longer interact with the audio queue. In addition, the audio queue no longer invokes any callbacks.
AudioQueue.hDisposes of an audio queue’s timeline object.
OSStatus AudioQueueDisposeTimeline ( AudioQueueRef inAQ, AudioQueueTimelineRef inTimeline );
The audio queue associated with the timeline object you want to dispose of.
The timeline object to dispose of.
A result code. See “Audio Queue Result Codes.”
Disposing of an audio queue automatically disposes of any associated resources, including a timeline object. Call this function only if you want to dispose of a timeline object and not the audio queue associated with it.
AudioQueue.hAdds a buffer to the buffer queue of a recording or playback audio queue.
OSStatus AudioQueueEnqueueBuffer ( AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, UInt32 inNumPacketDescs, AudioStreamPacketDescription *inPacketDescs );
The audio queue that owns the audio queue buffer.
The audio queue buffer to add to the buffer queue.
The number of packets of audio data in the inBuffer parameter. When playing a constant bit rate (CBR) format, or when the audio queue is an input (recording) audio queue, use 0.
An array of packet descriptions. When playing a constant bit rate (CBR) format, or when the audio queue is an input (recording) audio queue, use NULL.
A result code. See “Audio Queue Result Codes.”
Audio queue callbacks use this function to reenqueue buffers—placing them “last in line” in a buffer queue. A playback callback reenqueues a buffer after the buffer is filled with fresh audio data (typically from a file). A recording callback reenqueues a buffer after the buffer’s contents were written (typically to a file).
AudioQueue.hAdds a buffer to the buffer queue of a playback audio queue, specifying start time and other settings.
OSStatus AudioQueueEnqueueBufferWithParameters ( AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, UInt32 inNumPacketDescs, AudioStreamPacketDescription *inPacketDescs, UInt32 inTrimFramesAtStart, UInt32 inTrimFramesAtEnd, UInt32 inNumParamValues, AudioQueueParameterEvent *inParamValues, const AudioTimeStamp *inStartTime, AudioTimeStamp *outActualStartTime );
The audio queue that owns the audio queue buffer.
The audio queue buffer to add to the buffer queue. Before calling this function, the buffer must contain the audio data to be played.
The number of packets of audio data in the inBuffer parameter. When playing a constant bit rate (CBR) format, use 0.
An array of packet descriptions. When playing a constant bit rate (CBR) format, use NULL.
The number of priming frames to skip at the start of the buffer.
The number of frames to skip at the end of the buffer.
The number of audio queue parameter values pointed to by the inParamValues parameter. If you are not setting parameters, use 0.
An array of parameters to apply to an audio queue buffer. (In Mac OS X v10.5, there is only one audio queue parameter, kAudioQueueParam_Volume.) If you are not setting parameters for the buffer, use NULL.
Assign parameter values before playback—they cannot be changed while a buffer is playing. Changes to audio queue buffer parameters take effect when the buffer starts playing.
The desired start time for playing the buffer. To specify a time relative to when the audio queue started, use the mSampleTime field of the AudioTimeStamp structure. Use NULL to indicate that the buffer should play as soon as possible—which may be after previously queued buffers finish playing.
Buffers play in the order they are enqueued (first in, first out). If multiple buffers are queued, the start times must be in ascending order or NULL; otherwise, an error occurs. This parameter specifies when audio data is to start playing, ignoring any trim frames specified in the inTrimFramesAtStart parameter.
On output, the time when the buffer will actually start playing.
A result code. See “Audio Queue Result Codes.”
You can exert some control over the buffer queue with this function. You can assign audio queue settings that are, in effect, carried by an audio queue buffer as you enqueue it. Hence, settings take effect when an audio queue buffer begins playing.
This function applies only to playback. Recording audio queues do not take parameters and do not support variable bit rate (VBR) formats (which might require trimming).
AudioQueue.hResets an audio queue’s decoder state.
OSStatus AudioQueueFlush ( AudioQueueRef inAQ );
The audio queue to flush.
A result code. See “Audio Queue Result Codes.”
Call AudioQueueFlush after enqueuing the last audio queue buffer to ensure that all buffered data, as well as all audio data in the midst of processing, gets recorded or played. If you do not call this function, stale data in the audio queue’s decoder may interfere with playback or recording of the next set of buffers.
Call this function before calling AudioQueueStop if you want to ensure that all enqueued data reaches the destination.
AudioQueue.hAsks an audio queue to dispose of an audio queue buffer.
OSStatus AudioQueueFreeBuffer ( AudioQueueRef inAQ, AudioQueueBufferRef inBuffer );
The audio queue that owns the audio queue buffer you want to dispose of.
The buffer to dispose of.
A result code. See “Audio Queue Result Codes.”
Disposing of an audio queue also disposes of its buffers. Call this function only if you want to dispose of a particular buffer while continuing to use an audio queue. You can dispose of a buffer only when the audio queue that owns it is stopped (that is, not processing audio data).
AudioQueue.hGets the current audio queue time.
OSStatus AudioQueueGetCurrentTime ( AudioQueueRef inAQ, AudioQueueTimelineRef inTimeline, AudioTimeStamp *outTime, Boolean *outTimelineDiscontinuity );
The audio queue whose current time you want to get.
The audio queue timeline object to which timeline discontinuities are reported. Use NULL if the audio queue does not have an associated timeline object.
On output, the current audio queue time. The mSampleTime field represents audio queue time in terms of the audio queue sample rate, relative to when the queue started or will start.
On output, true if there has been a timeline discontinuity, or false if there has been no discontinuity. If the audio queue does not have an associated timeline object, this parameter is always NULL.
A timeline discontinuity may occur, for example, if the sample rate is changed for the audio hardware device associated with an audio queue.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hGets an audio queue parameter value.
OSStatus AudioQueueGetParameter ( AudioQueueRef inAQ, AudioQueueParameterID inParamID, AudioQueueParameterValue *outValue );
The audio queue that you want to get a parameter value from.
The ID of the parameter whose value you want to get. In Mac OS X v10.5, audio queues have one parameter available: kAudioQueueParam_Volume, which controls playback gain. See “Audio Queue Parameter ID”
On output, points to the current value of the specified parameter.
A result code. See “Audio Queue Result Codes.”
You can access the current parameter values for an audio queue at any time with this function. An audio queue parameter value is the sum of settings applied at buffer granularity, using the AudioQueueEnqueueBufferWithParameters function, and settings applied to the audio queue per se, using the AudioQueueSetParameter function.
AudioQueue.hGets an audio queue property value.
OSStatus AudioQueueGetProperty ( AudioQueueRef inAQ, AudioQueuePropertyID inID, void *outData, UInt32 *ioDataSize );
The audio queue that you want to get a property value from.
The ID of the property whose value you want to get. See “Audio Queue Property IDs.”
On output, the desired property value.
On input, the maximum bytes of space the caller expects to receive. On output, the actual data size of the property value.
A result code. See “Audio Queue Result Codes.”
Before calling this function, you can use the AudioQueueGetPropertySize function to determine the size, in bytes, of the value of a specified property. Some properties have values of a specific size, as described in “Audio Queue Property IDs.”
AudioQueue.hGets the size of the value of an audio queue property.
OSStatus AudioQueueGetPropertySize ( AudioQueueRef inAQ, AudioQueuePropertyID inID, UInt32 *outDataSize );
The audio queue that has the property value whose size you want to get.
The ID of the property value whose size you want to get. See “Audio Queue Property IDs.”
On output, the size of the requested property value.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hCreates a new recording audio queue.
OSStatus AudioQueueNewInput ( const AudioStreamBasicDescription *inFormat, AudioQueueInputCallback inCallbackProc, void *inUserData, CFRunLoopRef inCallbackRunLoop, CFStringRef inCallbackRunLoopMode, UInt32 inFlags, AudioQueueRef *outAQ );
The compressed or uncompressed audio data format to record to. When recording to linear PCM, only interleaved formats are supported.
A callback function to use with the recording audio queue. The audio queue calls this function when the audio queue has finished filling a buffer. See AudioQueueInputCallback.
A custom data structure for use with the callback function.
The event loop on which the callback function pointed to by the inCallbackProc parameter is to be called. If you specify NULL, the callback is called on one of the audio queue’s internal threads.
The run loop mode in which to call the callback. Typically, you pass kCFRunLoopCommonModes. You can choose to create your own thread with your own run loops. For more information on run loops, see Run Loops or CFRunLoop Reference.
Reserved for future use. Must be 0.
On output, the newly created recording audio queue.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hCreates a new playback audio queue.
OSStatus AudioQueueNewOutput ( const AudioStreamBasicDescription *inFormat, AudioQueueOutputCallback inCallbackProc, void *inUserData, CFRunLoopRef inCallbackRunLoop, CFStringRef inCallbackRunLoopMode, UInt32 inFlags, AudioQueueRef *outAQ );
The data format of the audio to play. For linear PCM, only interleaved formats are supported. Compressed formats are also supported.
A callback function to use with the playback audio queue. The audio queue calls this function when the audio queue has finished playing a buffer. See AudioQueueOutputCallback.
A custom data structure for use with the callback function.
The event loop on which the callback function pointed to by the inCallbackProc parameter is to be called. If you specify NULL, the callback is called on one of the audio queue’s internal threads.
The run loop mode in which to call the callback. Typically, you pass kCFRunLoopCommonModes. You can choose to create your own thread with your own run loops. For more information on run loops, see Run Loops or CFRunLoop Reference.
Reserved for future use. Must be 0.
On output, the newly created playback audio queue.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hExports audio to a buffer, instead of to a device, using a playback audio queue.
OSStatus AudioQueueOfflineRender ( AudioQueueRef inAQ, const AudioTimeStamp *inTimestamp, AudioQueueBufferRef ioBuffer, UInt32 inRequestedFrames, );
The playback audio queue.
The time corresponding to the beginning of the current audio queue buffer. This function uses the mSampleTime field of the AudioTimeStamp data structure.
On input, a buffer you supply to hold rendered audio data. On output, the rendered audio data, which you can then write to a file.
The number of frames of audio to render.
A result code. See “Audio Queue Result Codes.”
When you change a playback audio queue’s rendering mode to offline, using the AudioQueueSetOfflineRenderFormat function, you gain access to the rendered audio. You can then write the audio to a file, rather than have it play to external hardware such as a loudspeaker.
AudioQueue.hPauses audio playback or recording.
OSStatus AudioQueuePause ( AudioQueueRef inAQ );
The audio queue to pause.
A result code. See “Audio Queue Result Codes.”
Pausing an audio queue does not affect buffers or reset the audio queue. To resume playback or recording, call AudioQueueStart.
AudioQueue.hDecodes enqueued buffers in preparation for playback.
OSStatus AudioQueuePrime ( AudioQueueRef inAQ, UInt32 inNumberOfFramesToPrepare, UInt32 *outNumberOfFramesPrepared );
The audio queue to be primed.
The number of frames to decode before returning. Pass 0 to decode all enqueued buffers.
On output, the number of frames actually decoded and prepared for playback. Pass NULL on input if you you are not interested in this information.
A result code. See “Audio Queue Result Codes.”
This function decodes enqueued buffers in preparation for playback. It returns when at least the number of audio sample frames specified in inNumberOfFramesToPrepare are decoded and ready to play, or (if you pass 0 for the inNumberOfFramesToPrepare parameter), when all enqueued buffers are decoded.
To make a buffer of audio data ready to play, use AudioQueuePrime as follows:
Call AudioQueueEnqueueBuffer.
Call AudioQueuePrime.
Call AudioQueueStart.
AudioQueue.hRemoves a property listener callback from an audio queue.
OSStatus AudioQueueRemovePropertyListener ( AudioQueueRef inAQ, AudioQueuePropertyID inID, AudioQueuePropertyListenerProc inProc, void *inUserData );
The audio queue that you want to remove a property listener callback from.
The ID of the property whose changes you no longer want to respond to. See “Audio Queue Property IDs.”
The callback to be removed.
The same custom data for the property listener callback that you passed when calling AudioQueueAddPropertyListener.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hResets an audio queue.
OSStatus AudioQueueReset ( AudioQueueRef inAQ );
The audio queue to reset.
A result code. See “Audio Queue Result Codes.”
This function immediately resets an audio queue, flushes any queued buffers (invoking callbacks as necessary), removes all buffers from previously scheduled use, and resets decoder and digital signal processing (DSP) state.
If you queue buffers after calling this function, processing does not begin until the decoder and DSP state of the audio queue are reset. This might create an audible discontinuity (or “glitch”).
This function is called automatically when you call AudioQueueStop.
AudioQueue.hSets the rendering mode and audio format for a playback audio queue.
OSStatus AudioQueueSetOfflineRenderFormat ( AudioQueueRef inAQ, const AudioStreamBasicDescription *inFormat, const AudioChannelLayout *inLayout );
The playback audio queue whose rendering mode and audio format you want to set.
The audio format for offline rendering. The format must be some sort of linear PCM. If the format has more than one channel, it must be interleaved. For more information on the AudioStreamBasicDescription structure, see Core Audio Data Types Reference.
Pass NULL to disable offline rendering and return the audio queue to normal output to an audio device.
The channel layout for offline rendering. For more information on the AudioChannelLayout structure, see Core Audio Data Types Reference.
Pass NULL when using this function to disable offline rendering.
A result code. See “Audio Queue Result Codes.”
Use this function to set a playback audio queue to perform offline rendering, such as for export to an audio file. In offline rendering mode, a playback audio queue does not connect to external hardware.
You can also use this function to restore an audio queue to normal rendering mode by passing NULL in the inFormat and inLayout parameters.
AudioQueue.hSets a playback audio queue parameter value.
OSStatus AudioQueueSetParameter ( AudioQueueRef inAQ, AudioQueueParameterID inParamID, AudioQueueParameterValue inValue );
The playback audio queue that you want to set a parameter value on.
The ID of the parameter you want to set. In Mac OS X v10.5, audio queues have one parameter available: kAudioQueueParam_Volume, which controls playback gain. See “Audio Queue Parameter ID.”
The parameter value to set.
A result code. See “Audio Queue Result Codes.”
Use this function to change the settings for a playback audio queue directly. Changes take effect immediately. To set playback gain at the granularity of an audio queue buffer, use the AudioQueueEnqueueBufferWithParameters function.
AudioQueue.hSets an audio queue property value.
OSStatus AudioQueueSetProperty ( AudioQueueRef inAQ, AudioQueuePropertyID inID, const void *inData, UInt32 inDataSize );
The audio queue that you want to set a property value on.
The ID of the property whose value you want to set. See “Audio Queue Property IDs.”
The property value to set.
The size of the property data.
A result code. See “Audio Queue Result Codes.”
AudioQueue.hBegins playing or recording audio.
OSStatus AudioQueueStart ( AudioQueueRef inAQ, const AudioTimeStamp *inDeviceStartTime );
The audio queue to start.
The time at which the audio queue should start.
To specify a start time relative to the timeline of the associated audio device, use the mSampleTime field of the AudioTimeStamp structure. Use NULL to indicate that the audio queue should start as soon as possible.
A result code. See “Audio Queue Result Codes.”
If the associated audio device is not already running, this function starts it.
AudioQueue.hStops playing or recording audio.
OSStatus AudioQueueStop ( AudioQueueRef inAQ, Boolean inImmediate );
The audio queue to stop.
If you pass true, stopping occurs immediately (that is, synchronously), regardless of previously enqueued buffers. If you pass false, the function returns immediately, but the audio queue does not stop until its queued buffers are played or recorded (that is, the stop occurs asynchronously). Audio queue callbacks are invoked as necessary until the queue actually stops.
A result code. See “Audio Queue Result Codes.”
This function resets an audio queue, stops the audio hardware associated with the queue if it is not in use by other audio services, and stops the audio queue. When recording, this function is typically invoked by a user. When playing back, a playback audio queue callback should call this function when there is no more audio to play.
AudioQueue.hDefines a pointer to a callback function that is called when a recording audio queue has finished filling an audio queue buffer.
typedef void (*AudioQueueInputCallback) ( void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions, const AudioStreamPacketDescription *inPacketDescs );
If you name your callback function MyAudioQueueInputCallback, you would declare it like this:
void MyAudioQueueInputCallback ( void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions, const AudioStreamPacketDescription *inPacketDescs );
The custom data you’ve specified in the inUserData parameter of the AudioQueueNewInput function. Typically, this includes format and state information for the audio queue.
The recording audio queue that invoked the callback.
An audio queue buffer, newly filled by the recording audio queue, containing the new audio data your callback needs to write.
The sample time for the start of the audio queue buffer. This parameter is not used in basic recording.
The number of packets of audio data sent to the callback in the inBuffer parameter. When recording in a constant bit rate (CBR) format, the audio queue sets this parameter to NULL.
For compressed formats that require packet descriptions, the set of packet descriptions produced by the encoder for audio data in the inBuffer parameter. When recording in a CBR format, the audio queue sets this parameter to NULL.
You specify a recording audio queue callback when calling the AudioQueueNewInput function. The callback is invoked each time its recording audio queue has filled an audio queue buffer with fresh audio data. Typically, your callback writes the data to a file or other buffer, and then reenqueues the audio queue buffer to receive more data.
AudioQueue.hDefines a pointer to a callback function that is called when an audio queue buffer is available for reuse.
typedef void (*AudioQueueOutputCallback) ( void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer );
If you name your callback function MyAudioQueueOutputCallback, you would declare it like this:
void MyAudioQueueOutputCallback ( void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer );
The custom data you’ve specified in the inUserData parameter of the AudioQueueNewOutput function. Typically, this includes format and state information for the audio queue.
The playback audio queue that invoked the callback.
An audio queue buffer, newly available to fill because the playback audio queue has acquired its contents.
You specify a callback function when creating a new playback audio queue with the AudioQueueNewOutput function. The callback is invoked each time its playback audio queue has acquired the data from an audio queue buffer, at which point the buffer is available for reuse. Typically, your callback then fills the newly-available buffer with data from a file or other buffer, and then reenqueues the buffer for playback.
When your application receives a call to the AudioQueueOutputCallback function, you cannot assume that the audio data from the newly-available buffer has been played. To ensure that all queued audio has finished playing, use the AudioQueuePropertyListenerProc property listener callback function, set to listen to the kAudioQueueProperty_IsRunning property.
AudioQueue.hDefines a pointer to a callback function that is called when a specified audio queue property changes value.
typedef void (*AudioQueuePropertyListenerProc) ( void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID );
If you name your callback function MyAudioQueuePropertyListenerProc, you would declare it like this:
void MyAudioQueuePropertyListenerProc ( void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID );
The custom data you’ve specified in the inUserData parameter of the AudioQueueAddPropertyListener function.
The recording or playback audio queue that invoked the callback.
The ID of the property whose value changes you want to observe.
Install this callback in an audio queue by calling the AudioQueueAddPropertyListener function. For example, your application can get a notification that audio has finished playing by:
Defining this property listener callback function to listen for changes to the kAudioQueueProperty_IsRunning property.
Installing this callback function in an audio queue by calling the AudioQueueAddPropertyListener function.
AudioQueue.hDefines an audio queue buffer.
typedef struct AudioQueueBuffer {
const UInt32 mAudioDataBytesCapacity;
void *const mAudioData;
UInt32 mAudioDataByteSize;
void *mUserData;
} AudioQueueBuffer;
typedef AudioQueueBuffer *AudioQueueBufferRef;
mAudioDataBytesCapacityThe size of the audio queue buffer, in bytes. This size is set when an buffer is allocated and cannot be changed.
mAudioDataThe audio data owned the audio queue buffer. The buffer address cannot be changed.
mAudioDataByteSizeThe number of bytes of valid audio data in the audio queue buffer, initally set to 0. Your callback sets this value for a playback audio queue; for recording, the recording audio queue sets the value.
mUserDataThe custom data structure you specify, for use by your callback function, when creating a recording or playback audio queue.
Each audio queue has an associated set of audio queue buffers. To allocate a buffer, you call the AudioQueueAllocateBuffer function. To dispose of a buffer, you call the AudioQueueFreeBuffer function.
AudioQueue.hDefines an opaque data type that represents an audio queue.
typedef struct OpaqueAudioQueue *AudioQueueRef;
An audio queue is is a software object you use for recording or playing audio in Mac OS X. It does the work of:
Connecting to audio hardware
Managing memory
Employing codecs, as needed, for compressed audio formats
Mediating recording or playback
You create, use, and dispose of audio queues using the functions described in “Audio Queue Functions.”
AudioQueue.hDefines an opaque data type that represents an audio queue timeline object.
typedef struct OpaqueAudioQueueTimeline *AudioQueueTimelineRef;
You can use a timeline object to observe time discontinuities in the audio hardware device associated with an audio queue. A discontinuity is, for example, a period of silence when sound was expected. Causes of discontinuities include changes in device state or data processing overloads. See Technical Q&A 1467, CoreAudio Overload Warnings. You query a timeline object by passing it as a parameter to the AudioQueueGetCurrentTime function.
AudioQueue.hSpecifies an audio queue parameter and associated value.
struct AudioQueueParameterEvent {
AudioQueueParameterID mID;
AudioQueueParameterValue mValue;
}; typedef struct AudioQueueParameterEvent AudioQueueParameterEvent;
mIDThe parameter.
mValueThe value of the specified parameter.
You use this structure with the AudioQueueEnqueueBufferWithParameters function. See that function, and “Audio Queue Parameter IDs,” for more information.
AudioQueue.hA UInt32 value that uniquely identifies an audio queue parameter.
typedef UInt32 AudioQueueParameterID;
AudioQueue.hA Float32 value for an audio queue parameter.
typedef Float32 AudioQueueParameterValue;
AudioQueue.hIdentifiers for audio queue properties.
enum {
kAudioQueueProperty_IsRunning = 'aqrn',
kAudioQueueProperty_Device_SampleRate = 'aqsr',
kAudioQueueProperty_Device_NumberChannels = 'aqdc',
kAudioQueueProperty_CurrentDevice = 'aqcd',
kAudioQueueProperty_MagicCookie = 'aqmc',
kAudioQueueProperty_ChannelLayout = 'aqcl',
};
typedef UInt32 AudioQueuePropertyID;
kAudioQueueProperty_IsRunningA read-only property whose value is a UInt32. Any nonzero value means running, and 0 means stopped. A notification is sent when the associated audio queue starts or stops, which may occur sometime after the AudioQueueStart or AudioQueueStop function is called.
Available in Mac OS X v10.5 and later.
Declared in AudioQueue.h
kAudioQueueProperty_Device_SampleRateA read-only property whose value is a Float64. The value is the sampling rate of the audio hardware device associated with an audio queue.
kAudioQueueProperty_Device_NumberChannelsA read-only property whose value is a UIInt32. The value is the number of channels in the audio hardware device associated with an audio queue.
kAudioQueueProperty_CurrentDeviceA read/write property whose value is of type CFStringRef. The value contains the unique identifier (UID) of the audio hardware device associated with an audio queue.
Available in Mac OS X v10.5 and later.
Declared in AudioQueue.h
kAudioQueueProperty_MagicCookieA read/write property whose value is a void pointer to a block of memory, which you set up, containing an audio format magic cookie. If the audio format you are playing or recording to requires a magic cookie, you must set a value for this property before enqueuing any buffers.
Available in Mac OS X v10.5 and later.
Declared in AudioQueue.h
kAudioQueueProperty_ChannelLayoutA read/write property whose value is an AudioChannelLayout structure that describes an audio queue channel layout. The number of channels in the layout must match the number of channels in the audio format. This property is typically not used in the case of one or two channel audio. For more than two channels (such as in the case of 5.1 surround sound), you may need to specify a channel layout to indicate channel order, such as left, then center, then right.
Available in Mac OS X v10.5 and later.
Declared in AudioQueue.h
To receive a notification that a specific audio queue property has changed:
Define a property listener callback, referencing the desired audio queue property ID. Base the callback on the AudioQueuePropertyListenerProc callback function declaration.
Assign the callback to an audio queue using the AudioQueueAddPropertyListener function.
When you get a property-changed notification, call the AudioQueueGetProperty function to get the current value of the property.
AudioQueue.hIdentifiers for audio queue parameters.
enum {
kAudioQueueParam_Volume = 1
};
typedef UInt32 AudioQueueParameterID;
kAudioQueueParam_VolumeA value from 0.0 to 1.0 indicating the linearly scaled gain for an audio queue. A value of 1.0 (the default) indicates unity gain. A value of 0.0 indicates zero gain, or silence.
Available in Mac OS X v10.5 and later.
Declared in AudioQueue.h
In Mac OS X v10.5, audio queues have one parameter available: kAudioQueueParam_Volume. This parameter applies only to playback audio queues.
You can set a playback audio queue parameter in one of two ways:
Set the value to take effect immediately using the AudioQueueSetParameter function.
Schedule a value to take effect when a particular audio queue buffer plays. You supply the parameter when you enqueue the buffer. The new value is applied to the audio queue that owns the buffer when that buffer is rendered.
The AudioQueueGetParameter function always returns the current value of the parameter for an audio queue.
AudioQueue.hThis table lists result codes defined for Audio Queue Services.
Last updated: 2008-01-15