iOS:使用AudioUnitRender的模拟器中的错误 [英] iOS: Bug in the simulator using AudioUnitRender

查看:79
本文介绍了iOS:使用AudioUnitRender的模拟器中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了另一个iOS模拟器错误。我的问题是,有什么解决方法吗?

I have hit yet another iOS simulator bug. My question is, is there some workaround?

错误是这样的:

加载苹果的 AurioTouch 示例项目。

,并简单地打印出渲染回调(在aurioTouchAppDelegate.mm中)获得的帧数。

and simply print out the number of frames getting received by the render callback (in aurioTouchAppDelegate.mm)

static OSStatus PerformThru(
                            void                        *inRefCon, 
                            AudioUnitRenderActionFlags  *ioActionFlags, 
                            const AudioTimeStamp        *inTimeStamp, 
                            UInt32                      inBusNumber, 
                            UInt32                      inNumberFrames, 
                            AudioBufferList             *ioData)
{
    printf( "%u, ", (unsigned int)inNumberFrames );

我得到以下输出:

471, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, ...

但是,如果您在下一行注释掉对 AudioUnitRender 的调用,则:

However, if you comment out the call to AudioUnitRender on the next line:

{
    printf( "%u, ", (unsigned int)inNumberFrames );

    aurioTouchAppDelegate *THIS = (aurioTouchAppDelegate *)inRefCon;
    OSStatus err = 0; // AudioUnitRender(THIS->rioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);

现在每次发送适当数量的浮点数。

It now sends an appropriate number of floats each time.

471, 470, 471, 470, 470, 471, 470, 471, 470, 470, 471, 470, 471, 470, 470, 471, 470,

我还有一个问题:为什么要使用470、471这样的随机数?我读过某个地方,您通过指定缓冲区的持续时间隐式指定了缓冲区的长度,并且将缓冲区的长度设置为 2的幂次,可以得出与该持续时间最佳的近似值。但是经验证据表明事实并非如此。

Another question I have is: why such a random number as 470, 471? I read somewhere that you specify the buffer length implicitly by specifying its time duration, and it sets the buffer length to the power of two that yields the best approximation to this duration. But empirical evidence suggests this is not so.

无论如何,很确定这是一个错误。我要存档。

Anyway, pretty sure this is a bug. I'm going to go on file it. If anyone can shed some light, please do!

推荐答案

如果要使音频与模拟器一起使用,则需要确保在OS X的音频/ MIDI设置工具中将采样率设置为44.1k。无论使用模拟器时实际上是什么,AVAudioSession / Audio Services都将报告采样率为44.1k。

If you want to get the audio working with your simulator, you need to make sure your samplerate is set to 44.1k in OS X's audio/midi setup tool. AVAudioSession/Audio Services will report your samplerate as 44.1k no matter what it actually is when using the simulator.

通过将Mac的采样率设置为44.1k,您将获得每个回调都具有一个一致的inNumberFrames(默认值为1024),尽管据称仍可以由系统更改(例如应用程序进入后台)。

By setting your mac's samplerate to 44.1k, you'll get a consistent inNumberFrames (default is 1024) per callback, although this can still allegedly be changed by the system (ex. app goes to background).

这篇关于iOS:使用AudioUnitRender的模拟器中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆