如何使用雨燕的CoreAudio的API [英] How to use the CoreAudio API in Swift

查看:194
本文介绍了如何使用雨燕的CoreAudio的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的迁移流音频引擎迅速的过程。我发现很难使用C音频API中迅速。

I am in the process of migrating my streaming audio engine to swift. i am finding it difficult to use the C Audio API in swift.

我有AudioFileStreamOpen API,它需要2个C函数作为参数的问题。我不知道如何使用这个API是迅速的。

I have a problem with AudioFileStreamOpen api where it takes 2 C functions as a parameter. I don't know how to use this API is swift.

AudioFileStreamOpen(self as UnsafePointer<()>, propertyProc, packetProc, kAudioFileMP3Type, audioStreamId)

我对这个API定义如下回调方法。但我正在逐渐的编译错误。

I have defined the callback method as below for this API. But i am getting the compilation error.

func propertyProc(inClientData: UnsafePointer<()>,inFileStreamId: AudioFileStreamID,inPropertyId: AudioFileStreamPropertyID,ioFlags: UnsafePointer<UInt32>) -> Void {
  .....      
    }

func packetProc(inClientData: UnsafePointer<()>,inNumberOfBytes: UInt32,inNumberOfPackets: UInt32, ConstUnsafePointer<()>, inPacketDescriptions: UnsafePointer<AudioStreamPacketDescription>) -> Void {
    .....
}

任何帮助是pciated在迅速正确地定义这个C API AP $ P $

Any help is appreciated to correctly define this C API in swift

推荐答案

您不能(目前)的使用需要从单纯的雨燕code A C回调指针的API。调用使用C函数指针斯威夫特函数或方法不是由目前的测试版4种语言的实现支持,根据在devforums.apple.com

You can't (currently) use an API requiring a C callback pointer from pure Swift code. Calling Swift functions or methods using a C function pointer is not supported by the current beta 4 language implementation, according to replies in the Swift forum at devforums.apple.com

更新:以上的答案是过时,因为雨燕2.0​​

UPDATE: The above answer is obsolete as of Swift 2.0

一种选择是把一些小蹦床Ç回调函数在目标C文件,它可与雨燕互操作,并将这些C函数依次调用一个块或倒闭,这在斯威夫特code。与雨燕倒闭配置的C回调,然后通过与C回调到CoreAudio的功能。

One alternative is to put some small trampoline C callback functions in an Objective C file, which can interoperate with Swift, and have those C functions in turn call a block or closure, which can be in Swift code. Configure the C callbacks with your Swift closures, and then pass those C callbacks to the CoreAudio functions.

这篇关于如何使用雨燕的CoreAudio的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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