I am using the Audio Queue services to record audio on the iPhone. I am having a latency issue though when starting recording. Here is the code (approx):
OSStatus status = AudioQueueNewInput(
&recordState.dataFormat, // 1
AudioInputCallback, // 2
&recordState, // 3
CFRunLoopGetCurrent(), // 4
kCFRunLoopCommonModes, // 5
0, // 6
&recordState.queue); // 7
// create buffers
for(int i = 0; i < NUM_BUFFERS; i++)
{
if (status == 0)
status = AudioQueueAllocateBuffer(recordState.queue, BUFFER_SIZE, &recordState.buffers[i]);
}
DebugLog(@"Starting recording\n");
OSStatus status = 0;
for(int i = 0; i < NUM_BUFFERS; i++)
{
if (status == 0)
status = AudioQueueEnqueueBuffer(recordState.queue, recordState.buffers[i], 0, NULL);
}
DebugLog(@"Queued buffers\n");
if (status == 0)
{
// start audio queue
status = AudioQueueStart(recordState.queue, NULL);
}
DebugLog(@"Started recording, status = %d\n", status);
The log output looks like this:
2009-06-30 19:18:59.631 app[24887:20b] Starting recording
2009-06-30 19:18:59.828 app[24887:20b] Queued buffers
2009-06-30 19:19:00.849 app[24887:20b] Started recording, status = 0
Note the 1-second delay between the "Queued Buffers" message and 2nd "Starting recording" message. Any ideas how I can get rid of it, apart from starting recording as soon as I start my app?
BTW, the 1-second is pretty consistent in the Simulator and Device, and doesn't seem to be affected by number or size of buffers. Using good old mono 16-bit PCM.