I want to use the to encode the output of a AUGraph as AAC (on iOS 5.1). The basic topology of the graph looks like this:
inputs --> MixerUnit --> pcm2aac --> aac2pcm --> RemoteIO
I want to to grab the AAC-encoded data as it's playing via a PostRenderCallback on pcm2aac
and then send it via UDP to our server application.
As I understand, the go-to AudioUnit for this use-case is kAudioUnitType_FormatConverter
, but when I want to set the ASBD Input Property for aac2pcm, AudioUnitSetProperty fails with -10868 (it also fails when I set the output of pcm2acc, with the same error).
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
where aacStreamFormat
is
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);
Are this kind of conversions even possible with AUGraph or do I have to use other methods for live conversion?