我想使用它来编码AUGraph的输出作为AAC(在iOS 5.1上)。图的基本拓扑如下所示:
inputs --> MixerUnit --> pcm2aac --> aac2pcm --> RemoteIO
我希望在pcm2aac
上通过PostRenderCallback播放AAC编码的数据,然后通过UDP将其发送到我们的服务器应用程序。
据我所知,这个用例的首选AudioUnit是kAudioUnitType_FormatConverter
,但是当我想为aac2pcm设置ASBD输入属性时,AudioUnitSetProperty会失败并显示-10868(当我设置它时它也会失败pcm2acc的输出,具有相同的错误。)
AudioComponentDescription converterUnitDescription;
converterUnitDescription.componentType = kAudioUnitType_FormatConverter;
converterUnitDescription.componentSubType = kAudioUnitSubType_AUConverter;
converterUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
converterUnitDescription.componentFlags = 0;
converterUnitDescription.componentFlagsMask = 0;
//...
AUNode pcm2aacNode;
AUNode aac2pcmNode;
//...
result = AUGraphAddNode (
processingGraph,
&converterUnitDescription,
&aac2pcmNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Converter unit" withStatus: result]; return;}
//...
result = AUGraphOpen (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}
//...
AudioUnit aac2pcmUnit;
AudioUnit pcm2aacUnit;
//...
result = AUGraphNodeInfo (
processingGraph,
aac2pcmNode,
NULL,
&aac2pcmUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo (aac2pcm)" withStatus: result]; return;}
//...
NSLog (@"Setting stream format for input aac2pcm bus");
result = AudioUnitSetProperty (aac2pcmUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&aacStreamFormat,
sizeof (aacStreamFormat)
);
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (input aac2pcm stream format)" withStatus: result];return;}
// returns -10868
其中aacStreamFormat
是
memset(&aacStreamFormat, 0, sizeof(aacStreamFormat));/
UInt32 size = sizeof(aacStreamFormat);
aacStreamFormat.mFormatID = kAudioFormatMPEG4AAC;
aacStreamFormat.mChannelsPerFrame = 2;
aacStreamFormat.mFormatFlags = kMPEG4Object_AAC_Main;
aacStreamFormat.mSampleRate = graphSampleRate; //44100
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &aacStreamFormat);
AUGraph甚至可以进行这种转换,还是必须使用其他方法进行实时转换?
答案 0 :(得分:0)
我认为您不需要pcm2aac和aac2pcm节点。您可以在混音器节点上安装渲染回调,并使用ExtAudioFileWriteAsync将输出保存为AAC。
答案 1 :(得分:0)
参考AUComponent.h
kAudioUnitSubType_AUConverter
An audio unit that uses an AudioConverter to do Linear PCM conversions
(sample rate, bit depth, interleaving).
所以你不能通过kAudioUnitSubType_AUConverter将pcm转码为aac。
您应该使用AudioConverter,这是参考URL https://developer.apple.com/library/ios/samplecode/iPhoneACFileConvertTest/Introduction/Intro.html