在运行时更改setPreferredIOBufferDuration会导致核心音频错误-50 [英] Changing setPreferredIOBufferDuration at Runtime results in Core Audio Error -50

查看:799
本文介绍了在运行时更改setPreferredIOBufferDuration会导致核心音频错误-50的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基于音频单元(远程IO)的应用程序,该应用程序以给定的缓冲区大小显示波形.该应用程序最初以0.0001的首选缓冲区大小启动,这导致非常小的缓冲区帧大小(我认为是14帧).比在运行时,我有一个UI元素,它允许通过AVAudioSession的方法setPreferredIOBufferDuration:Error:切换缓冲区帧的大小.

I am writing an Audio Unit (remote IO) based app that displays waveforms at a given buffer size. The app initially starts off with a preferred buffer size of 0.0001 which results in very small buffer frame sizes (i think its 14 frames). Than at runtime I have a UI element that allows switching buffer frame sizes via AVAudioSession's method setPreferredIOBufferDuration:Error:.

这是其中前两种情况从较小的缓冲区变为较大的缓冲区的代码. 3-5未指定.但是该应用程序在AudioUnitRender处崩溃,错误代码为-50.

Here is the code where the first two cases change from a smaller to a larger sized buffer. 3-5 are not specified yet. But the app crashes at AudioUnitRender with -50 error code.

- (void)setBufferSizeFromMode:(int)mode {

   NSTimeInterval bufferDuration;

   switch (mode) {
      case 1:
         bufferDuration = 0.0001;
         break;
      case 2:
         bufferDuration = 0.001;
         break;
      case 3:
         bufferDuration = 0.0; // reserved
         break;
      case 4:
         bufferDuration = 0.0; // reserved
         break;
      case 5:
         bufferDuration = 0.0; // reserved
         break;
      default:
         break;
   }

   AVAudioSession *session = [AVAudioSession sharedInstance];
   NSError * audioSessionError = nil;

   [session setPreferredIOBufferDuration:bufferDuration error:&audioSessionError];
   if (audioSessionError) {
      NSLog(@"Error %ld, %@",
            (long)audioSessionError.code, audioSessionError.localizedDescription);
   }

}

基于阅读CoreAudio和AVFoundation文档的结果,我被认为可以在运行时更改音频硬件配置.音频或失真可能会有些差距,但我现在同意.发生崩溃的原因很明显吗?还是必须针对缓冲区持续时间的每次更改重新初始化所有内容(我的音频会话,我的音频单元,我的音频缓冲区等)?

Based on reading the CoreAudio and AVFoundation documentation, I was led to believe that you can change audio hardware configuration at runtime. There may be some gaps in audio or distortion but I am fine with that for now. Is there an obvious reason for this crash? Or must I reinitialize everything (my audio session, my audio unit, my audio buffers, etc..) for each change of the buffer duration?

我曾尝试在更改会话缓冲区持续时间之前调用AudioOutputUnitStop(self.myRemoteIO);,而不是在设置后重新开始.我也曾尝试将会话设置为非活动状态,而不是重新激活它,但两者都导致在我的AU输入回调中从AudioUnitRender()获得-50 OSStatus.

I have tried calling AudioOutputUnitStop(self.myRemoteIO); before changing the session buffer duration and than starting again after it is set. I've also tried setting the session to inactive and than reactivating it but both result with the -50 OSStatus from AudioUnitRender() in my AU input callback.

推荐答案

-50错误通常表示音频单元代码正在尝试设置或使用无效的参数值.

A -50 error usually means the audio unit code is trying to set or use an invalid parameter value.

某些iOS设备不支持低于5.3毫秒(或在较旧的设备上为0.0058秒)以下的实际缓冲区持续时间. iOS设备似乎可以自由切换到实际缓冲区持续时间的4倍以上,甚至可以交替更改略有不同的值,有时不受应用程序的控制.

Some iOS devices don't support actual buffer durations below 5.3 mS (or 0.0058 seconds on older devices). And iOS devices appear free to switch to an actual buffer duration 4X longer than that, or even alternate slightly different values, at times not under the apps control.

inNumberFrames作为参数提供给音频单元回调,您的应用无法任意指定该值.

The inNumberFrames is given to the audio unit callback as a parameter, your app can't arbitrarily specify that value.

如果要处理给定的缓冲区大小,请将它们从中间的无锁循环FIFO中拉出,音频单元回调可将其送入.

If you want to process given buffer sizes, pull them out of an intermediating lock-free circular FIFO, which the audio unit callback can feed into.

也:尝试在调用音频停止后等待一秒钟左右,然后再更改参数或重新启动.在您调用停止与硬件实际停止之间似乎存在延迟.

Also: Try waiting a second or so after calling audio stop before changing parameters or restarting. There appears to be a delay between when you call stop, and when the hardware actually stops.

这篇关于在运行时更改setPreferredIOBufferDuration会导致核心音频错误-50的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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