Using Swift 2 with XCode 7.2 on a Mac running OS X 10.11.2; Working with AUAudioUnit callbacks to process real time microphone input.
Have successfully configured HAL Output device to use default input and set the inputHandler to a callback block defined to be compliant with the AUInputHandler definition. The following code fragment works (provides live data with 512 sample frames in real-time):
let renderBlock = audioUnit.renderBlock
let inputBuffer = AVAudioPCMBuffer(...
audioUnit.inputHandler = {
(actionFlags, timestamp, inputBusNumber, frameCount) -> Void in
renderBlock(actionFlags, timestamp, AUAudioFrameCount(frameCount), Int(inputBusNumber), inputBuffer.mutableAudioBufferList, nil)
}
My question involves fields: inputBusNumber, frameCount, which are reversed compared to the spec.
These two are passed in to the callback block in in the order given above and not as specified in the definition:
(UnsafeMutablePointer<AudioUnitRenderActionFlags>, UnsafePointer<AudioTimeStamp>, AUAudioFrameCount, Int) -> Void
In my original code, I used the fields in the specified order:
audioUnit.inputHandler = {
(actionFlags, timestamp, frameCount, inputBusNumber) -> Void in
renderBlock(actionFlags, timestamp, frameCount, inputBusNumber, inputBuffer.mutableAudioBufferList, nil)
}
And the code blew up. When I printed out the values for these fields as passed-in, the frameCount was getting set to 1, and the inputBusNumber was set to 512. Once I swapped the order, my code magically came to life.
Has anybody else seen this or have I missed something fundamental?
Thanks,
Bill