简体   繁体   English

iOS麦克风捕获LPCM在8 kHz的采样率下不起作用

[英]iOS Microphone capture LPCM not working for a sample rate of 8 kHz

I am using AudioComponentInstance audioUnit to record microphone on iOS, Liniar PCM, with various sample rates (configurable from app). 我正在使用AudioComponentInstance audioUnit以各种采样率(可从应用程序配置)在iOS,Liniar PCM上录制麦克风。 The weird part is, it is working fine for 11025, 22050 and 44100, but is not working for 8000. It does not provide any error or something, I just don't receive anything in the callback. 奇怪的是,它对于11025、22050和44100正常工作,但对于8000则不工作。它不提供任何错误或其他信息,我只是在回调中没有收到任何信息。 Also, tested with 9600 and it is not working. 另外,还使用9600进行了测试,但无法正常工作。

Does anybody know a reason for this? 有人知道原因吗? I start the session with 我开始与

status = AudioUnitInitialize(audioUnit);
status = AudioOutputUnitStart(audioUnit);

If needed I can provide more (all) the code, but I don't think this is related to the code. 如果需要,我可以提供更多(全部)代码,但是我认为这与代码无关。

UPDATE UPDATE

After some more testing I found out that the size of the buffer I use in the recording callback was a problem. 经过更多测试后,我发现在录音回调中使用的缓冲区大小是一个问题。 In the callback I call 在回调中,我打电话

    status = AudioUnitRender([instance audioUnit],
                             ioActionFlags,
                             inTimeStamp,
                             inBusNumber,
                             inNumberFrames,
                             entry->bufferList);

It seems the inNumberFrames is 186 or 185, and I created a buffer with 128. But now it is stil failing 4 out of 5 times with status -50. 看来inNumberFrames是186或185,我创建了一个带128的缓冲区。但是现在它仍然失败,状态5为5,有4次失败。 I set the buffer size to 256, 512, 186 but the behaviour is the same. 我将缓冲区大小设置为256、512、186,但是行为是相同的。 The outcome is that the recording is distorted, as frames are lost. 结果是由于帧丢失,记录失真。

Well, found out the answer myself. 好吧,我自己找出答案。 For some obscure reasons, 186 frames reported to be ready by the callback was one too many. 由于某些模糊的原因,回调报告的186帧已经准备好了太多。 After I replaced the value with 185 in the call of AudioUnitRender() it worked like a charm. 在对AudioUnitRender()的调用中将值替换为185后,它就像一个符咒一样工作。 It seems there is a bug and somethimes CoreAudio reports an extra frame as ready. 似乎有一个错误,有些东西CoreAudio报告说准备好了额外的帧。

For higher frequencies the problem did not exist, as the number of frames was always constant and power of 2 (256, 512, 1024) 对于更高的频率,这个问题不存在,因为帧数始终是恒定的,并且幂为2(256、512、1024)

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

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