我正在努力学习这个API和Swift中的语法
audioBufferList = AudioBufferList(mNumberBuffers: 2, mBuffers: (AudioBuffer))我不知道带()的(AudioBuffer)是什么意思?有什么想法吗?我该如何初始化它?这是来自标题的:
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))
}发布于 2017-04-28 09:34:24
这里有一种初始化AudioBufferList的方法,使用一个空的单声道缓冲区数组,您可以将其传递给音频单元调用,如AudioUnitRender(),然后根据需要分配和填充缓冲区:
var bufferList = AudioBufferList(
mNumberBuffers: 1,
mBuffers: AudioBuffer(
mNumberChannels: UInt32(1),
mDataByteSize: 1024,
mData: nil))发布于 2020-04-29 00:29:28
通过使用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)))https://stackoverflow.com/questions/43667261
复制相似问题