1 year ago
#315938
Deepak Sharma
AudioUnitRender callback set buffer list
I have the following AudioUnit setup to process audio frames:
var renderCallbackStruct:AURenderCallbackStruct = AURenderCallbackStruct()
renderCallbackStruct.inputProc = renderCallback
renderCallbackStruct.inputProcRefCon = UnsafeMutableRawPointer(Unmanaged.passUnretained(tap).toOpaque())
status = AudioUnitSetProperty(audioUnit!, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input, 0,
&renderCallbackStruct,
UInt32(MemoryLayout<AURenderCallbackStruct>.stride))
And then the callback function.
//MARK: callback function for AU rendering
func renderCallback(
inRefCon:UnsafeMutableRawPointer,
ioActionFlags:UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp:UnsafePointer<AudioTimeStamp>,
inBusNumber:UInt32,
inNumberFrames:UInt32,
ioData:UnsafeMutablePointer<AudioBufferList>?) -> OSStatus {
let tapProcessor = unsafeBitCast(inRefCon, to: MTAudioProcessingTap.self)
return MTAudioProcessingTapGetSourceAudio(tapProcessor, CMItemCount(inNumberFrames), ioData!, nil, nil, nil)
}
My problem:
I need to return my own buffer list in renderCallback instead of calling function to get source audio frames in tapProcessor. I want to call this tap function to fetch source audio somewhere else in my code rather than in renderCallback function, and store the source frames in audioBufferList variable of my controller instead. Something like this where I set ioData to point to audioBufferList managed by my controller.
func renderCallback(
inRefCon:UnsafeMutableRawPointer,
ioActionFlags:UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp:UnsafePointer<AudioTimeStamp>,
inBusNumber:UInt32,
inNumberFrames:UInt32,
ioData:UnsafeMutablePointer<AudioBufferList>?) -> OSStatus {
let controller = unsafeBitCast(inRefCon, to: Controller.self)
ioData = controller.audioBufferList
return noErr
}
But it gives me compilation error, saying ioData is a let constant. Wondering if there is a way to achieve what I need.
ios
avfoundation
core-audio
audiounit
0 Answers
Your Answer