kAudioUnitErr_FormatNotSupported when setting format on stereo mixer on Mac OS X
kAudioUnitErr_FormatNotSupported when setting format on stereo mixer on Mac OS X
- Subject: kAudioUnitErr_FormatNotSupported when setting format on stereo mixer on Mac OS X
- From: Antonio Nunes <email@hidden>
- Date: Tue, 23 Nov 2010 07:27:27 +0000
Hi,
I'm porting code that I have working on iOS to Mac OS X.
When trying to set the input/output format for the kAudioUnitSubType_StereoMixer I get a kAudioUnitErr_FormatNotSupported (-10868) error. I spent some time googling for answers and had a look at the Core Audio section on the devforums, but could not find any solutions.
The sound source is a .wav file. I think the audio format settings below are correct for that format. iOS handles this code just fine. (Except that it uses the multi channel mixer, since the stereo mixer is not available on iOS, but using the multi channel mixer in the code below yields the same error.)
This is what I'm trying to do:
#define SAMPLE_RATE 44100.0
[...]
AudioStreamBasicDescription audioFormat = {0};
audioFormat.mSampleRate = SAMPLE_RATE;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = 4;
audioFormat.mBytesPerFrame = 4;
[...]
AudioComponentDescription stereoMixerDescription;
stereoMixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
stereoMixerDescription.componentType = kAudioUnitType_Mixer;
stereoMixerDescription.componentSubType = kAudioUnitSubType_StereoMixer;
stereoMixerDescription.componentFlags = 0;
stereoMixerDescription.componentFlagsMask = 0;
AudioComponentDescription outputComponentDescription;
outputComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
outputComponentDescription.componentType = kAudioUnitType_Output;
outputComponentDescription.componentSubType = kAudioUnitSubType_DefaultOutput;
outputComponentDescription.componentFlags = 0;
outputComponentDescription.componentFlagsMask = 0;
status = AUGraphAddNode(audioUnitGraph, &stereoMixerDescription, &stereoMixerNode);
NSAssert(status == noErr, @"Error adding stereo mixer node to graph.");
status = AUGraphAddNode(audioUnitGraph, &outputComponentDescription, &outputNode);
NSAssert(status == noErr, @"Error adding output node to graph.");
status = AUGraphOpen(audioUnitGraph);
NSAssert(status == noErr, @"Error opening graph.");
status = AUGraphNodeInfo(audioUnitGraph, stereoMixerNode, &stereoMixerDescription, &stereoMixer);
NSAssert(status == noErr, @"Error getting stereo mixer node info.");
status = AUGraphNodeInfo(audioUnitGraph, outputNode, &outputComponentDescription, &output);
NSAssert(status == noErr, @"Error getting output node info.");
status = AudioUnitSetProperty(stereoMixer, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &numberOfBusses, sizeof(UInt32));
NSAssert(status == noErr, @"Error setting number of busses on stereo mixer.");
status = AUGraphConnectNodeInput(audioUnitGraph, stereoMixerNode, 0, outputNode, 0);
NSAssert(status == noErr, @"Error connecting stereo mixer node 0 to output node 0.");
AURenderCallbackStruct stereoMixerCallbackStruct;
stereoMixerCallbackStruct.inputProc = stereoMixerRenderCallback;
stereoMixerCallbackStruct.inputProcRefCon = self;
size_t audioFormatSize = sizeof(audioFormat);
status = AudioUnitSetProperty(output, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, audioFormatSize);
NSAssert(status == noErr, @"Error setting audio format on output node.");
for (UInt8 i = 0; i < numberOfBusses; i++) {
status = AUGraphSetNodeInputCallback(audioUnitGraph, stereoMixerNode, i, &stereoMixerCallbackStruct);
NSAssert(status == noErr, ([NSString stringWithFormat:@"Error setting stereo mixer node input callback on bus %d.", i]));
status = AudioUnitSetProperty(stereoMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, i, &audioFormat, audioFormatSize);
NSAssert(status == noErr, ([NSString stringWithFormat:@"Error setting stereo mixer node output stream format on bus %d.", i]));
status = AudioUnitSetProperty(stereoMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, i, &audioFormat, audioFormatSize);
NSAssert(status == noErr, ([NSString stringWithFormat:@"Error setting stereo mixer node input stream format on bus %d.", i]));
}
The for loop trips on the second NSAssert with status code -10868 (kAudioUnitErr_FormatNotSupported). Note that the audio format is readily accepted by the output node. Why won't the mixer node accept the audio format?
-António
-----------------------------------------------------------
And could you keep your heart in wonder
at the daily miracles of your life,
your pain would not seem less wondrous
than your joy.
--Kahlil Gibran
-----------------------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden