带有奇数长度缓冲区的AudioUnitRender错误-50 [英] AudioUnitRender error -50 with odd length buffers

查看:334
本文介绍了带有奇数长度缓冲区的AudioUnitRender错误-50的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置了AVAudioSessionCategoryPlayAndRecord的RemoteIO单元。我发现其中有一些奇怪的行为。我打开该应用程序,并在audioUnit完全初始化之前立即将其关闭(由于我退出应用程序太早,它实际上是在后台初始化)。接下来,将应用程序置于前台,然后立即重新启动,我看到AudioUnitRender连续失败,错误为-50。我发现inNumberFrames为1115,只要此数字为奇数,它就会失败。 < AudioTimeStamp>,
inBusNumber:UInt32,
inNumberFrames:UInt32,
ioData:UnsafeMutablePointer< AudioBufferList> ;?)-> OSStatus
{
let控制器= unsafeBitCast(inRefCon,to:MicrophoneOutput.self)

let listPtr = controller.audioBufferList.unsafeMutablePointer

let缓冲区= UnsafeBufferPointer< AudioBuffer>(开始:& listPtr.pointee.mBuffers,计数:Int(listPtr.pointee.mNumberBuffers))

for缓冲区中的var buf {
buf.mDataByteSize = inNumberFrames * UInt32(sampleWordSize)
}

let status = AudioUnitRender(controller.audioUnit !, ioActionFlags,inTimeStamp,inBusNumber,inNumberFrames,listPtr)

如果noErr!= status {
print( Error \(status));
NSLog( \(AVAudioSession.sharedInstance()。currentRoute.inputs [0]))
fatalError(渲染状态\(状态))
//返回状态;
}

return noErr

}



奇怪的是,如果我在AudioUnitRender调用中将inNumberFrames硬编码为1114,它将成功!有人知道发生了什么吗?该模式是在应用程序从后台恢复后立即发出路由更改通知,然后回调中的第一个示例的长度为1114帧,但其旁边的示例为1115帧,失败了。

解决方案

事实证明,这是由于对Swift语言的误解而导致的编程错误。罪魁祸首的行是这样的:

 缓冲区中的var buf {
buf.mDataByteSize = inNumberFrames * UInt32( sampleWordSize)
}

此答案提供了更多详细信息-
Swift与Objective C指针操作问题


I have a RemoteIO unit configured with AVAudioSessionCategoryPlayAndRecord. I find some strange behavior in it. I open the app, and immediately close it before audioUnit initializes fully (it actually initializes in background as I quit the app too soon). Next I bring the app to foreground and immediately on relaunch, I see AudioUnitRender failing with error -50 continuously. I find inNumberFrames to be 1115 and it fails whenever this number is odd.

  func recordingCallback(inRefCon:UnsafeMutableRawPointer,
                ioActionFlags:UnsafeMutablePointer<AudioUnitRenderActionFlags>,
                inTimeStamp:UnsafePointer<AudioTimeStamp>,
                inBusNumber:UInt32,
                inNumberFrames:UInt32,
                ioData:UnsafeMutablePointer<AudioBufferList>?) -> OSStatus
  {
       let controller = unsafeBitCast(inRefCon, to: MicrophoneOutput.self) 

      let listPtr = controller.audioBufferList.unsafeMutablePointer

     let buffers = UnsafeBufferPointer<AudioBuffer>(start: &listPtr.pointee.mBuffers, count: Int(listPtr.pointee.mNumberBuffers))

   for var buf in buffers {
       buf.mDataByteSize = inNumberFrames * UInt32(sampleWordSize)
    }

   let status = AudioUnitRender(controller.audioUnit!, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, listPtr)

if noErr != status {
   print("Error \(status)");
   NSLog("\(AVAudioSession.sharedInstance().currentRoute.inputs[0])")
   fatalError("Render status \(status)")
  // return status;
}

return noErr

}

Strangely, if I hardcode inNumberFrames to be 1114 in AudioUnitRender call, it succeeds! Does anyone know what is going on? The pattern is as soon as the app resumes from background, there is a route change notification, and then the first sample in callback is of length 1114 frames but the one next to it has 1115 frames which fails.

解决方案

It turned out it was a programming error due to misunderstandings in Swift language. The line that was culprit was this:

for var buf in buffers {
   buf.mDataByteSize = inNumberFrames * UInt32(sampleWordSize)
}

This answer provides more detail - Swift vs Objective C pointer manipulation issue

这篇关于带有奇数长度缓冲区的AudioUnitRender错误-50的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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