使用AudioQueueStart()时出现延迟

时间:2009-06-30 23:32:43

标签: iphone audio core-audio audio-recording

我正在使用音频队列服务在iPhone上录制音频。开始录制时我遇到延迟问题。这是代码(约):

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);

日志输出如下所示:

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

请注意“排队缓冲区”消息和第二个“开始录制”消息之间的1秒延迟。除了在我启动应用程序后立即开始录制,我有什么想法可以摆脱它吗?

顺便说一句,1秒在模拟器和设备中非常一致,并且似乎不受缓冲区数量或大小的影响。使用好的旧单声道16位PCM。

1 个答案:

答案 0 :(得分:-2)

Mike Tyson在他的this中涵盖了blog

但是,如果您希望快速开始录制,最好使用远程音频设备或AVAudioEngine