在我的应用中,我正在渲染回调中进行音频处理(仅输入,无输出)。
这是我初始化音频的方法:
-(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;
但是我没有设法正确地创建/连接节点来完成这项工作...
谢谢你的帮助 !
最佳答案
当我想做类似的事情时,我发现了您的问题-不幸的是,没有任何解决方案:-(现在几天后,一位经理设法做到了。所以这是我的工作解决方案,适用于所有遇到相同问题的人:
(注意:Apple将其称为输入回调,而实际上,这只是一个NOTIFICATION回调,以告知您的应用示例可用,并且您必须显式“询问”输入单元以呈现它们...)
(注意:通用输出可以转换,但是过滤器不能转换。因此,如果您想将8.24格式以外的任何其他内容输入链中,则需要转换器。)
现在的关键是,操作系统对Mic Callback的常规调用将驱动整个处理链:
中提琴,您完成了。您只需要启动/停止麦克风!
整个过程的关键在于,始终需要一个输出单元来驱动整个渲染过程,并且由于通用输出不需要任何常规的“需要”来获取样本,因此您必须手动要求它来渲染样本。并且必须将其同步到麦克风的A / D转换器,该麦克风要以固定的时间间隔输出采样。
从理论上讲,您可以链接输入单元和图形,但是有两个问题:
最后说明:如果要将麦克风的样本直接呈现到转换器单元中,则必须将相同的流格式(最好是远程io的规范输出格式(即16位,整数))设置为转换器单元的输入和麦克风单元的输出(即,远程io的输入范围,总线1)。
关于ios - iOS在渲染回调处理之前添加音频效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33901569/