我一直在尝试获取kAudioUnitSubType_RemoteIO播放的样本以及从kAudioUnitSubType_AudioFilePlayer接收的样本。
为了获得这些样本,我在remoteIO Audio Unit(总线0)的输出上配置了kAudioUnitProperty_SetRenderCallback。虽然我成功播放音频,但这个渲染回调似乎没有收到样本。据我了解,remoteIO回调从FilePlayer音频单元(总线1)拉取(呈现)可用数据(存储在缓冲区中)。
有谁知道出了什么问题?
NewAUGraph(player.graph)
// Add file player node
var cd = AudioComponentDescription(componentType: OSType(kAudioUnitType_Generator),
componentSubType: OSType(kAudioUnitSubType_AudioFilePlayer),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0, componentFlagsMask: 0)
AUGraphAddNode(player.graph, &cd, &player.filePlayerNode)
// Add output node
var rioNode = AUNode()
cd.componentType = OSType(kAudioUnitType_Output)
cd.componentSubType = OSType(kAudioUnitSubType_RemoteIO)
AUGraphAddNode(player.graph, &cd, &rioNode)
AUGraphOpen(player.graph)
AUGraphNodeInfo(player.graph, player.filePlayerNode, nil, &player.filePlayerAU)
AUGraphNodeInfo(player.graph, rioNode, nil, &player.rioAU)
AUGraphConnectNodeInput(player.graph, player.filePlayerNode, 0, outputNode, 0)
// The callback is configures as
var callbackStruct = AURenderCallbackStruct(inputProc: InputRenderProc, inputProcRefCon: &player)
CheckError(AudioUnitSetProperty(player.rioAU,
kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Output,
0,
&callbackStruct,
UInt32(sizeof(callbackStruct.dynamicType))),
operation: "Couldn't set RIO's render callback")
AUGraphInitialize(player.graph)
渲染回调(不接收任何数据,也没有任何错误):
let InputRenderProc: AURenderCallback = {(inRefCon, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData) -> OSStatus in
let player = UnsafeMutablePointer<StatePlayer>(inRefCon).memory
// Just obtain samples from buffer
var bus1: UInt32 = 1
CheckError(AudioUnitRender(player.filePlayerAU, ioActionFlags, inTimeStamp, bus1, inNumberFrames, ioData),
operation: "Couldn't render from filePlayer Audio Unit")
return noErr
}