3

我正在努力使用这个 API 和 Swift 中的语法

audioBufferList = AudioBufferList(mNumberBuffers: 2, mBuffers: (AudioBuffer))

我不知道 (AudioBuffer) with () 是什么意思?任何想法以及如何初始化它?这是来自标题:

  public struct AudioBufferList {

      public var mNumberBuffers: UInt32
      public var mBuffers: (AudioBuffer) // this is a variable length array of mNumberBuffers elements
      public init()
      public init(mNumberBuffers: UInt32, mBuffers: (AudioBuffer))
 }
4

2 回答 2

0

AVAudioPCMBuffer通过以下方式使用类解决了该问题:

import AVFoundation

// noninterleaved stereo data
let processingFormat = AVAudioFormat(
  commonFormat: .pcmFormatFloat32,
  sampleRate: 44100,
  channels: 2,
  interleaved: false
)!

// this line also creates AudioBufferList instance.
let buffer = AVAudioPCMBuffer(
  pcmFormat: processingFormat,
  frameCapacity: 1024)!
// this line updates mDataByteSize properties
buffer.frameLength = 1024

let bufferList: UnsafePointer<AudioBufferList> = buffer.audioBufferList

print(bufferList.pointee) // Prints: AudioBufferList(mNumberBuffers: 2, mBuffers: __C.AudioBuffer(mNumberChannels: 1, mDataByteSize: 4096, mData: Optional(0x00007ff253840e00)))
于 2020-04-28T16:29:27.850 回答
0

这是使用一个空单声道缓冲区数组初始化 AudioBufferList 的一种方法,您可以将其传递给音频单元调用,例如 AudioUnitRender(),然后根据需要分配和填充缓冲区:

var bufferList = AudioBufferList(
        mNumberBuffers: 1,
        mBuffers: AudioBuffer(
            mNumberChannels: UInt32(1),
            mDataByteSize: 1024,
            mData: nil))
于 2017-04-28T01:34:24.197 回答