简体   繁体   English

AudioToolbox - 录音时的回调延迟

[英]AudioToolbox - Callback delay while recording

I've been working on a very specific project for iOS, lately, and my researches lead me to an almost final code.最近,我一直在为 iOS 开展一个非常具体的项目,我的研究使我得到了几乎最终的代码。 I've solved all the extreme difficulties I've found until now, but on this one I don't seem to have a clue (about the reason nor the possibility of solving it).到目前为止,我已经解决了我发现的所有极端困难,但是在这一点上我似乎没有任何线索(关于解决它的原因和可能性)。

I set up my audioqueue (sample rate 44100, format LinearPCM, 16 bits per channel, 2 bytes per frame, 1 channel per frame...) and start recording the sound with 12 audio buffers.我设置了我的音频队列(采样率 44100,格式 LinearPCM,每通道 16 位,每帧 2 字节,每帧 1 通道......)并开始使用 12 个音频缓冲区录制声音。 However, there seems to be a delay after every 4 callbacks.但是,每 4 次回调后似乎会有延迟。

The situation is the following: the first 4 callbacks are called with an interval each of about 2 ms.情况如下:前 4 个回调的调用间隔约为 2 毫秒。 However, between the 4th and the 5th, there is a delay of about 60ms.但是,在第 4 和第 5 之间,有大约 60ms 的延迟。 The same thing happens between the 8th and the 9th, the 12th and 13th and on...同样的事情发生在 8 号和 9 号之间,12 号和 13 号之间……

There seems to be a relation between the bytes per frame and the moment of the delay.每帧的字节数和延迟时间之间似乎存在关系。 I know this because if I change to 4 bytes per frame, I start having the delay between the 8th and the 9th, then between the 16th and the 17th, the 24th and the 25th... Nonetheless, there doesn't seem to be any relation between the moment of the delay and the number of buffers.我知道这一点,因为如果我更改为每帧 4 个字节,我会在第 8 和第 9 之间开始延迟,然后在第 16 和第 17、第 24 和第 25 之间......尽管如此,似乎没有延迟时刻与缓冲区数量之间的任何关系。

The callback function does only two things: store the audio data (inBuffer->mAudioData) on a array my class can use;回调 function 只做两件事:将音频数据 (inBuffer->mAudioData) 存储在我的 class 可以使用的数组中; and call another AudioQueueEnqueueBuffer, to put the current buffer back on the queue.并调用另一个 AudioQueueEnqueueBuffer,将当前缓冲区放回队列中。

Did anyone go through this problem already?有人 go 已经解决了这个问题吗? Does anyone know, at least, what could be the cause of it?有谁知道,至少,这可能是什么原因?

Thank you in advance.先感谢您。

The Audio Queue API seems to run on top of the RemoteIO Audio Unit API, who's real audio buffer size is probably unrelated to, and in your example larger than, whatever size your Audio Queue buffers are.音频队列 API 似乎在 RemoteIO 音频单元 API 之上运行,其实际音频缓冲区大小可能与您的音频队列缓冲区大小无关,并且在您的示例中大于任何大小。 So whenever a RemoteIO buffer is ready, a bunch of your smaller AQ buffers quickly get filled from it.因此,只要 RemoteIO 缓冲区准备就绪,一堆较小的 AQ 缓冲区就会很快被填满。 And then you get a longer delay waiting for some larger buffer to be filled with samples.然后你会得到更长的延迟,等待一些更大的缓冲区被样本填充。

If you want better controlled (more evenly spaced) buffer latency, try using the RemoteIo Audio Unit directly.如果您想要更好地控制(更均匀间隔)缓冲延迟,请尝试直接使用 RemoteIo 音频单元。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM