Swift中的AURenderCallbackStruct [英] AURenderCallbackStruct in Swift

查看:233
本文介绍了Swift中的AURenderCallbackStruct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AURenderCallbackStruct的Objective-C示例,我想快速地做一个。我读过这是不可能的,对吗?

I have an Objective-C example to an AURenderCallbackStruct, and I would like to do one in swift. I read it's not possible, is that correct?

谢谢。

推荐答案

您可以在Swift 4中格式化回调函数,如下所示。

You can format a callback function in Swift 4 like the following.

func recordingCallback(
  inRefCon:UnsafeMutableRawPointer,
  ioActionFlags:UnsafeMutablePointer<AudioUnitRenderActionFlags>,
  inTimeStamp:UnsafePointer<AudioTimeStamp>,
  inBusNumber:UInt32,
  inNumberFrames:UInt32,
  ioData:UnsafeMutablePointer<AudioBufferList>?) -> OSStatus {


  return noErr
}

请注意,这必须是全局函数,并且不是在类内部。

Note this must be a global function and not inside of a class.

然后,您可以使用以下代码设置回调函数:

You can then set your callback function with the following code:

var callbackStruct = AURenderCallbackStruct()
callbackStruct.inputProc = recordingCallback
callbackStruct.inputProcRefCon = nil
status = AudioUnitSetProperty(remoteIOUnit!,
                                  kAudioOutputUnitProperty_SetInputCallback,
                                  kAudioUnitScope_Global,
                                  bus1,
                                  &callbackStruct,
                                  UInt32(MemoryLayout<AURenderCallbackStruct>.size));
if (status != noErr) {
  return status // Do something with the error
}

来源

这篇关于Swift中的AURenderCallbackStruct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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