iPhone 模拟器音频仅适用于 44100Hz、22050Hz 和 11025Hz
有人使用模拟器在 AudioUnit 级别处理 8kHz 音频吗?
iPhone 模拟器音频仅适用于 44100Hz、22050Hz 和 11025Hz。否则它就会奇怪地失败。
我在 iPhone 模拟器中录制音频时遇到问题。该代码在硬件设备上运行良好,但在模拟器中奇怪地失败。
我正在研究 AudioUnit 级别,并将采样率(通过音频会话属性)设置为 8000Hz。在硬件上工作正常,但在模拟器上,渲染回调会请求一个适当大小的数据块,然后每 11.6 毫秒回调一次,请求一个字节。
我尝试将采样率设置为 44100/4 (11025Hz),效果很好。所以我尝试将音频会话采样率设置为 11024,但它失败了。与 11026 相同。11025 有效。
我的假设是模拟器的音频代码中有一个错误。我认为它内部必须有一个四分之一秒长的缓冲区,并且它无法处理采样率不是其倍数的情况。
任何人都可以在模拟器中用自己的代码尝试这个吗?尝试 11024、11025 和 11026 的采样率,看看是否只有 11025 有效?
更新:如果我要求 11024,它会给我 8000,但渲染回调会继续传递 ioData,只要求单个帧(1 字节)。当我要求 8000Hz 时,行为相同。
UPDATE2:当我在 AudioQueue API 级别编程时,模拟器也可以正常工作。它在那里处理 8kHz。它似乎只是在 AudioUnit API 级别上搞砸了。
Is anyone out there using the simulator to handle 8kHz audio at the AudioUnit level?
The iPhone simulator audio only works for 44100Hz, 22050Hz, and 11025Hz. It fails strangely otherwise.
I am having trouble recording audio in the iPhone simulator. The code works fine on a hardare device but fails strangely in the simulator.
I am working on the AudioUnit level and I set the sampling rate (via audio session properties) to 8000Hz. Works fine on hardware, but on the simulator the render callback asks for one appropriately sized chunk of data and then calls back every 11.6ms asking for a single byte.
I tried setting the sample rate to 44100/4 (11025Hz) and it worked fine. So I tried setting the audio session sample rate to 11024 and it broke. Same with 11026. 11025 works.
My supposition is that there is a bug in the simulator's audio code. I think it internally must have a buffer that is a quarter second long and it can't handle situations where the sample rate is not some multiple of that.
Can anyone try this in their own code in the simulator? Try sampling rates of 11024, 11025, and 11026, and see if only 11025 works?
UPDATE: If I ask for 11024 it gives me 8000, but the render callback keeps delivering ioData asking for only a single frame (1 byte). Same behavior when I ask for 8000Hz.
UPDATE2: The simulator also works fin when I program at the AudioQueue API level. It handles 8kHz there. It just seems to screw up at the AudioUnit API level.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,当您要求模拟器的远程 I/O 单元在 8kHz 模式下工作时,模拟器会进入功能障碍模式。或 44100/4 倍数以外的任何模式。
再说一遍,这并不是说它拒绝我的格式或建议更好的格式。问题是它假装同意,然后进入一种奇怪的模式,一次请求一两个字节,可能是因为一些栅栏错误。
如果我将单元子类型设置为 VoiceProcessingIO,则 8kHz 工作正常,但麦克风侧每隔几次读取就会变得有点麻烦。
所以问题是模拟器的远程 I/O 单元声称支持 8kHz,但只有将其配置为 VoiceProcessing 子类型时它才有效。
As near as I can tell, the simulator goes into a dysfunctional mode when you ask its Remote I/O unit to work in 8kHz mode. Or any mode other than a multiple of 44100/4.
Once again, it's not that it was rejecting my format or suggesting a better one. The problem is that it pretends to agree, then goes into a weird mode asking for one or two bytes at a time, probably because of some fencepost error.
If I set the unit subtype to VoiceProcessingIO, 8kHz works fine, thought the microphone side gets a little fussy every few reads.
So the problem is that the Simulator's Remote I/O unit claims to support 8kHz, but it only works if you configure it as a VoiceProcessing subtype.
模拟器之所以如此命名,是因为它不是模拟器。
The simulator is named so because it is not a emulator.
首先,有一些“规范”采样率。我知道的是 8000、11025、22050、41000、48000 和 96000 Hz。除了那些规范的音频系统之外,我不希望任何音频系统能够以任意值工作。
话虽如此,众所周知,模拟器的行为与实际的 iDevice 并不完全相同,尤其是音频子系统。例如,IIRC 模拟器无法播放 iOS 设备能够播放的所有音频格式。正如@JustSid所说,它是一个模拟器而不是模拟器。没有什么可以替代实际设备上的测试。
First of all, there are a few "canonical" sample rates. The ones I know are 8000, 11025, 22050, 41000, 48000 and 96000 Hz. I wouldn't expect any audio system to work with arbitrary value except those canonical ones.
That being said, the simulator is known to not behave exactly like an actual iDevice, especially the audio subsystem. For example, IIRC the simulator is not able to play all the audio formats an iOS device is able to play. As @JustSid said, it is a simulator and not an emulator. Nothing replaces testing on an actual device.