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"
Audio Units Provide Fast, Modular Audio Processing
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
Q: Does this mean for VOIP application, we can only use Audio Unit rather than Audio Queue Service ?