1. reading my code for recording
* MyInputBufferHandler
Q: 这里有Enqueue Buffer动作,这样,这个buffer有机会重新fill
A: YES!. callback中总会有enqueue动作的,无论recording还是playback.
Q: 参数含义
voidAQRecorder::MyInputBufferHandler(
void *inUserData,
AudioQueueRefinAQ,
AudioQueueBufferRefinBuffer,
constAudioTimeStamp *inStartTime,
UInt32 inNumPackets,
constAudioStreamPacketDescription* inPacketDesc)
关于inNumPackets,在文档中的描述如下:
inNumberPacketDescriptions is the number of packet descriptions in the inPacketDescs
parameter. If you are recording to a VBR (variable bitrate) format, the audio queue supplies a value for this parameter to your callback, which in turn passes it on to the AudioFileWritePackets
function. CBR (constant bitrate) formats don’t use packet descriptions. For a CBR recording, the audio queue sets this and the inPacketDescs parameter to NULL
.
所以,似乎在这里这个值应该为NULL,但实际并非如此,why ?
* InitNewPlaybackQueue
Q: CFRunLoopGet?Current()等东东到底在干嘛? 似乎和thread的runloop有关 ? 2012/03/12
XThrowIfError(AudioQueueNewOutput(&mDataFormat,AQPlayer::AQBufferCallback,this,
CFRunLoopGetCurrent(),kCFRunLoopCommonModes, 0, &mQueue), "AudioQueueNew failed");
2. reading " Audio Queue Service Programming Guide " + "Audio Queue Service Reference"
* multi queues
Audio Queue Services also supports scheduled playback and synchronization of multiple audio queues and synchronization of audio with video.
Q: could be used to do "mixing" ?
Q: 是否在我们这种类似voip的应用中,不应该使用Audio Queue Service,而应该使用Audio Unit ???
* callback invoking
During recording or playback, an audio queue callback is invoked repeatedly by the audio queue that owns it. The time between calls depends on the capacity of the audio queue’s buffers and will typically range from half a secondto several seconds.
^ too slow ???
enqueue buffer: always done by call back function.
* call back的作用
# 对于recording,
负责将Audio Queue从input device采集的放在buffer中的audio data发送给应用程序,如写入disk或放向network
将buffer入queue,等待Audio Queue再次fill
注:call back拿到的buffer是有audio data的,等待后续处理,如发送到network
# playback
负责将向audio buffer中fill audio data
将audio buffer推入audio queue,等待playback
注:call back拿到的buffer是空,等待被fill
3. reading "Audio Unit Hosting Guide for iOS"
The two greatest advantages of using audio units directly are:
Excellent responsiveness. Because you have access to a realtime priority thread in an audio unit render callback function, your audio code is as close as possible to the metal. Synthetic musical instruments and realtime simultaneous voice I/O benefit the most from using audio units directly.
Dynamic reconfiguration. The audio processing graph API, built around the AUGraph
opaque type, lets you dynamically assemble, reconfigure, and rearrange complex audio processing chains in a thread-safe manner, all while processing audio. This is the only audio API in iOS offering this capability