iOS是否在渲染回调处理之前添加音频效果?
在我的应用程序中,我在渲染回调中进行音频处理(仅输入,无输出)。 以下是我初始化音频的方式:iOS是否在渲染回调处理之前添加音频效果?,ios,audio,callback,core-audio,audiounit,Ios,Audio,Callback,Core Audio,Audiounit,在我的应用程序中,我在渲染回调中进行音频处理(仅输入,无输出)。 以下是我初始化音频的方式: -(void) initAudio { OSStatus status; NewAUGraph(&graph); AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_Remote
-(void) initAudio {
OSStatus status;
NewAUGraph(&graph);
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
AUNode ioNode;
status = AUGraphAddNode(graph, &desc, &ioNode);
checkStatus(status, "At adding node");
AUGraphOpen(graph);
AUGraphNodeInfo(graph, ioNode, NULL, &audioUnit);
//Enable IO for recording
UInt32 enableInput = 1;
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
kInputBus,
&enableInput,
sizeof(enableInput));
checkStatus(status, "At setting property for input");
//Disable playback
UInt32 enableOutput = 0;
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
kOutputBus,
&enableOutput,
sizeof(enableOutput));
checkStatus(status, "At setting property for input");
// ASBD
AudioStreamBasicDescription audioFormatIn;
audioFormatIn.mSampleRate = SampleRate;
audioFormatIn.mFormatID = kAudioFormatLinearPCM;
audioFormatIn.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormatIn.mFramesPerPacket = 1;
audioFormatIn.mChannelsPerFrame = 1;
audioFormatIn.mBitsPerChannel = 16;//sizeof(AudioSampleType) * 8;
audioFormatIn.mBytesPerPacket = 2 * audioFormatIn.mChannelsPerFrame;
audioFormatIn.mBytesPerFrame = 2 * audioFormatIn.mChannelsPerFrame;
//Apply format
status = AudioUnitSetProperty(audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
kInputBus,
&audioFormatIn,
sizeof(audioFormatIn));
checkStatus(status,"At setting property for AudioStreamBasicDescription for input");
//Set up input callback
AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = recordingCallback;
callbackStruct.inputProcRefCon = (__bridge void *)self;
status = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global,
kInputBus,
&callbackStruct,
sizeof(callbackStruct));
checkStatus(status,"At setting property for recording callback");
// Disable buffer allocation for the recorder
UInt32 flag = 0;
status = AudioUnitSetProperty(audioUnit,
kAudioUnitProperty_ShouldAllocateBuffer,
kAudioUnitScope_Output,
kInputBus,
&flag,
sizeof(flag));
checkStatus(status, "At set property should allocate buffer");
// Allocate own buffers
tempBuffer.mNumberChannels = 1;
tempBuffer.mDataByteSize = 1024 * 2;
tempBuffer.mData = malloc( 1024 * 2 );
status = AUGraphInitialize(graph);
checkStatus(status,"At AUGraph Initalize");
}
现在,我想在渲染回调中处理输入音频之前,向其添加高通滤波器或带通滤波器。因此,我想我应该添加如下内容:
desc.componentType = kAudioUnitType_Effect;
desc.componentSubType = kAudioUnitSubType_BandPassFilter;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
但是我没有正确创建/连接节点以使其正常工作。。。
谢谢你的帮助 当我想做一件类似的事情时,我发现了你的问题——不幸的是,没有任何解决方案:-(几天后,a成功地解决了这个问题。因此,这是我的工作解决方案,适用于所有与同一问题作斗争的人:
最后一点注意:如果您想直接将麦克风的样本渲染到转换器单元,则必须将相同的流格式(最好是远程io的标准输出格式(即16位整数)设置到转换器单元的输入和麦克风单元的输出(即远程io的输入范围,总线1).您的渲染链在没有带通的情况下工作吗?@Dave我以前使用经典音频单元初始化,但我开始切换到AUGraph。即使我不确定是否正确,我上面的代码似乎也能工作。