OSStatus result = noErr;
AudioUnit outputUnit = 0;
AudioUnit converterUnit = 0;
AudioUnit decoderUnit = 0;
// Create a graph
result = NewAUGraph(&audioGraph);
// Add an output node
AudioComponentDescription outputNodeDesc = {kAudioUnitType_Output, kAudioUnitSubType_DefaultOutput, kAudioUnitManufacturer_Apple, 0, 0};
result = AUGraphAddNode(audioGraph, &outputNodeDesc, &outputNode);
AudioComponentDescription decoderNodeDesc = {kAudioDecoderComponentType, 'ima4', 'appl', 0, 0};
result = AUGraphAddNode(audioGraph, &decoderNodeDesc, &decoderNode);
// Add a converter to get things in the correct LPCM format
AudioComponentDescription converterNodeDesc = {kAudioUnitType_FormatConverter, kAudioUnitSubType_AUConverter, kAudioUnitManufacturer_Apple, 0, 0};
result = AUGraphAddNode(audioGraph, &converterNodeDesc, &converterNode);
// Open the graph
result = AUGraphOpen(audioGraph);
// Get the converter unit
result = AUGraphNodeInfo(audioGraph, converterNode, &converterNodeDesc, &converterUnit);
// Get the decoder unit
result = AUGraphNodeInfo(audioGraph, decoderNode, &decoderNodeDesc, &decoderUnit);
// Get the output unit
result = AUGraphNodeInfo(audioGraph, outputNode, &outputNodeDesc, &outputUnit);
AudioStreamBasicDescription outputFormat;
bzero(&outputFormat, sizeof(outputFormat));
outputFormat.mSampleRate = 44100.0;
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
outputFormat.mChannelsPerFrame = 2;
outputFormat.mBitsPerChannel = 16;
outputFormat.mBytesPerPacket = outputFormat.mChannelsPerFrame * (outputFormat.mBitsPerChannel / 8);
outputFormat.mFramesPerPacket = 1;
outputFormat.mBytesPerFrame = outputFormat.mBytesPerPacket;
// Configure the decoder unit output
result = AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &outputFormat, sizeof(outputFormat));
// Configure the converter unit output
result = AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &outputFormat, sizeof(outputFormat));
// Configure the output unit's input format
result = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputFormat, sizeof(outputFormat));
// Connect the decoder node as the input of the converter node
result = AUGraphConnectNodeInput (audioGraph, decoderNode, 0, converterNode, 0);
// Connect the converter node as the input of the output node
result = AUGraphConnectNodeInput (audioGraph, converterNode, 0, outputNode, 0);
// Initialize the graph
result = AUGraphInitialize(audioGraph);
… rest of code omitted since we don't get that far