2013-04-22 105 views
0

我是Core Audio的新手,所以我可能看不到明显的东西... 我的目标是处理先前录制的音频信号。但是,这些信号应该先过滤。我不需要播放任何音频。我只需要记录并处理它。核心音频:在非remoteIO单元上的kAudioOutputUnitProperty_SetInputCallback

My图表看起来像这样: RemoteIO - > HighPassFilter - >回调(处理音频)

,我把它像这样:

LBAudioDetectiveGetDefaultFormat(&detective->streamFormat); 

// Create new AUGraph 
OSStatus error = NewAUGraph(&detective->graph); 
LBErrorCheck(error); 

// Initialize AUNodes 
AudioComponentDescription rioCD = {0}; 
rioCD.componentType = kAudioUnitType_Output; 
rioCD.componentSubType = kAudioUnitSubType_RemoteIO; 
rioCD.componentManufacturer = kAudioUnitManufacturer_Apple; 

AUNode rioNode; 
error = AUGraphAddNode(detective->graph, &rioCD, &rioNode); 
LBErrorCheck(error); 

AudioComponentDescription filterCD = {0}; 
filterCD.componentType = kAudioUnitType_Effect; 
filterCD.componentSubType = kAudioUnitSubType_HighPassFilter; 
filterCD.componentManufacturer = kAudioUnitManufacturer_Apple; 

AUNode filterNode; 
error = AUGraphAddNode(detective->graph, &filterCD, &filterNode); 
LBErrorCheck(error); 

// Open the graph so I can modify the AudioUnits 
error = AUGraphOpen(detective->graph); 

// Adapt rioUnit 
error = AUGraphNodeInfo(detective->graph, rioNode, NULL, &detective->rioUnit); 
LBErrorCheck(error); 

UInt32 onFlag = 1; 
AudioUnitElement bus1 = 1; 
UInt32 propertySize = sizeof(UInt32);  
error = AudioUnitSetProperty(detective->rioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, bus1, &onFlag, propertySize); 
LBErrorCheck(error); 

propertySize = sizeof(AudioStreamBasicDescription); 
error = AudioUnitSetProperty(detective->rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, bus1, &detective->streamFormat, propertySize); 
LBErrorCheck(error); 

// Adapt filterUnit 
error = AUGraphNodeInfo(detective->graph, filterNode, NULL, &detective->filterUnit); 
LBErrorCheck(error); 

AURenderCallbackStruct callback = {0}; 
callback.inputProc = _LBAudioDetectiveFilterOutput; 
callback.inputProcRefCon = detective; 
propertySize = sizeof(AURenderCallbackStruct); 
error = AudioUnitSetProperty(detective->filterUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, propertySize); 
LBErrorCheck(error); 

// Connect the two units 
AudioUnitElement bus0 = 0; 
error = AUGraphConnectNodeInput(detective->graph, rioNode, bus1, filterNode, bus0); 
LBErrorCheck(error); 

AUGraphInitialize(detective->graph); 

我的代码失败,出现错误 - 10879当我尝试设置回调。我假设过滤器音频单元不支持此属性。 那我该如何获得录制的声音呢?据我所知,第二个通用输出单元是不允许的。

感谢您提前RemoteIO音频单元,但在RemoteIO回调(过滤单元或输入总线代替),拉的帮助

回答

2

配置在输出回调(总线0)(渲染)来自过滤器单元。然后调用过滤器单元从RemoteIO输入端(总线1)提取可用数据进行处理。

同时填充用零输出缓冲器,如果你不想做任何声音。

基本上RemoteIO的扬声器一侧提供了回调的RemoteIO的扬声器侧数据的时间,即使你不想玩任何声音的扬声器。这是因为整个音频单元链基于拉模型(ADC没有将数据推入API的位置),但输入和输出的硬件采样速率恰好相同。因此,音频单元链从麦克风输入缓冲器中拉出的时间正好在正确的时间调用输出。

+0

嗯,这是一个聪明的做法,但不会再调用输入回调。我确实需要连接哪些巴士。我使用filterUnit的总线0连接了rioUnit的总线1。回调结构在输出范围的rioUnit的总线1上配置。回调被调用,但它不包含'ioData-> mBuffers [0] .mData'中的任何数据' – lbrndnr 2013-04-22 19:40:03

相关问题