The rough steps for getting the audio unit:
AudioComponentDescription desc = {
.componentType = kAudioUnitType_Output,
.componentSubType = kAudioUnitSubType_HALOutput,
.componentManufacturer = kAudioUnitManufacturer_Apple,
};
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
AudioComponentInstance unit;
AudioComponentInstanceNew(comp, &unit);
AudioUnitSetProperty(unit, kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global, 0, &adevid, sizeof(adevid));
And then setting the stream format and channel layout:
AudioUnitSetProperty(unit, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, dev_desc, sizeof(*dev_desc));
AudioChannelLayout layout =
{
.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelBitmap,
.mChannelBitmap = 0x3f, // typical value for 5.1 audio
.mNumberChannelDescriptions = 0,
};
AudioUnitSetProperty(unit, kAudioUnitProperty_AudioChannelLayout,
kAudioUnitScope_Input, 0, &layout, sizeof(layout));
Setting the channel layout like this doesn't return any error codes, but seems to have no effect. For the map looking inverted, are you referring to kAudioOutputUnitProperty_ChannelMap? I've also tried that without success, although I can't remember exactly what the result was. I'll see if I can re-test it.