Hello, everyone here.I don't recognize the (AudioBuffer) syntax below.
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))
}
So, can anyone tell me or explain, what is the final grammar of '(AudioBuffer)'?
How can i create a AudioBufferList instance, and visit the subscript of 'mBuffers'?
Here is my user scenario:
I'm using VideoToolBox to catch the audio buffer by using 'AudioComponentDescription' & 'AudioUnit' , so i need to create a call back to handle the input buffer.
Here is the code:
// MARK: CallBack
func handleInputBuffer(inRefCon: UnsafeMutableRawPointer,
ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp: UnsafePointer<AudioTimeStamp>,
inBusNumber: UInt32,
inNumberFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>) -> OSStatus {
let source: MTAudioCapture = Unmanaged.fromOpaque(inRefCon).takeUnretainedValue()
// var buffers = AudioBufferList(mNumberBuffers: 1,
// mBuffers: AudioBuffer(mNumberChannels: 1, mDataByteSize: 1, mData: nil))
let bufferList = UnsafeMutableAudioBufferListPointer(ioData)
let status: OSStatus = AudioUnitRender(source.componentInstance!, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData)
if source.muted! {
for buffer in bufferList {
memset(buffer.mData, 0, Int(buffer.mDataByteSize))
}
}
if status != noErr {
if source.delegate != nil {
source.delegate?.captureOutput(capture: source, audioData: Data(bytes: bufferList[0].mData!, count: Int(bufferList[0].mDataByteSize)))
}
}
return status
}
is that right? I'm so confused.
Any message here are welcomed.
Thank you!