如何访问UnsafePointer< AudioBufferList>中的多个缓冲区。 (不可更改) [英] How to access multiple buffers in UnsafePointer<AudioBufferList> (non-mutable)

查看:93
本文介绍了如何访问UnsafePointer< AudioBufferList>中的多个缓冲区。 (不可更改)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在Core Audio中使用新的 AVAudioSinkNode
它将类型为 UnsafePointer< AudioBufferList> audioBufferList 传递给处理音频的闭包。

I've been trying to use the new AVAudioSinkNode in Core Audio. It passes audioBufferList which is of type UnsafePointer<AudioBufferList> to the closure handling the audio.

在Swift中实现 AudioBufferList 使得您不能访问多个缓冲区,如果有多个。 Apple为可变版本 UnsafeMutablePointer< AudioBufferList> 提供了包装,该包装称为 UnsafeMutableAudioBufferListPointer ,并允许访问多个缓冲区。

The implementation of AudioBufferList in Swift is such that you cannot access multiple buffers, if there are more than one. Apple provided a wrapper for the mutable version, UnsafeMutablePointer<AudioBufferList>, which is called UnsafeMutableAudioBufferListPointer and allows access to multiple buffers.

但是我找不到与非可变 UnsafePointer< AudioBufferList> 一起使用的相关包装。 ..

But I cannot find a relevant wrapper that I could use with the non-mutable UnsafePointer<AudioBufferList>....

let sinkNode = AVAudioSinkNode() { (timestamp, frames, audioBufferList) -> OSStatus in
    // audioBufferList is UnsafePointer<AudioBufferList>
    // how to access multiple buffers in audioBufferList?
}

谢谢!

推荐答案

要在Swift中访问 AudioBufferList 中的每个 AudioBuffer ,可以选择两种方式:

To access each AudioBuffer in an AudioBufferList in Swift, you may choose two ways:


  • 自己进行一些指针操作并计算 AudioBuffer 。

  • 强制使用 UnsafeMutableAudioBufferListPointer

  • Do some pointer operations yourself and calculate each address of AudioBuffer.
  • Use UnsafeMutableAudioBufferListPointer forcefully.

如果在Swift中引入 UnsafeMutableAudioBufferListPointer 之前可以找到正确的示例代码,则第一种方法可能是您的选择,但到目前为止,很难找到一个。

If you could find a right sample code before UnsafeMutableAudioBufferListPointer was introduced in Swift, the first way might be your option, but as for now, it's hard to find one.

要强制使用 UnsafeMutableAudioBufferListPointer ,您可能需要转换 UnsafePointer< AudioBufferList> UnsafeMutablePointer< AudioBufferList> ,这并不是太困难:

To use UnsafeMutableAudioBufferListPointer forcefully, you may need to convert UnsafePointer<AudioBufferList> to UnsafeMutablePointer<AudioBufferList>, which is not too difficult:

            let audioBufferListPtr = UnsafeMutableAudioBufferListPointer(UnsafeMutablePointer(mutating: audioBufferList))

我相信您知道一旦获得 UnsafeMutableAudioBufferListPointer

I believe you know how to access buffers once you get UnsafeMutableAudioBufferListPointer.

警告:即使从 UnsafePointer < ; AudioBufferList> UnsafeMutablePointer< AudioBufferList> 很容易,实际区域通过 audioBufferList 不可变。您可能需要格外小心,不要使该区域突变。

Caution: Even if type conversion from UnsafePointer<AudioBufferList> to UnsafeMutablePointer<AudioBufferList> is easily made, the actual region passed through audioBufferList is not mutable. You may need extra care not to mutate such region.

这篇关于如何访问UnsafePointer&lt; AudioBufferList&gt;中的多个缓冲区。 (不可更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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