Hi, our Mac app uses AUHAL for audio output. The data we’re playing has channels laid out in the WAVE default ordering (this is the same order as Core Audio’s AudioChannelBitmap). Playing this data usually results in the correct channel playing through the correct speaker, but there are cases where it does not:
- Outputting audio over HDMI usually results in the Center and LFE channels being swapped
- Or “Configure Speakers” in Audio MIDI Setup.app can be used to change the speaker<->channel mapping (i.e. even swapping L/R on a 2ch stereo setup), but this does not affect our app’s audio
I’ve found that getting kAudioUnitProperty_AudioChannelLayout on an output unit returns the speaker<->channel mapping as set up in Audio MIDI Setup (i.e. it shows that Center/LFE swap, or if L/R are swapped).
My question: is it possible to have Core Audio do the channel remapping between the WAVE default ordering, and the speaker<->channel mapping as returned by kAudioUnitProperty_AudioChannelLayout? I have tried setting kAudioUnitProperty_AudioChannelLayout on the input unit, and didn’t see a change. I’ve also tried to set kAudioOutputUnitProperty_ChannelMap on the output unit but cannot get it to work.
Or do I need to remap the channels myself before giving samples to Core Audio?
My apologies, I didn't read your original message carefully and pasted back in your reply kAudioUnitProperty_AudioChannelLayout -- but I was thinking of kAudioOutputUnitProperty_ChannelMap.
AUHAL / AUConverter don't seem to support automatic remapping of channel layouts.
You can use AudioFormatGetProperty() with kAudioFormatProperty_ChannelMap to convert a pair of channel layouts to a channel map that AUHAL can use, however. This is sufficient for simple channel re-ordering.
If you need to support upmixing and downmixing (different input and output channel counts), then consider AUMultiChannelMixer, which accepts channel layouts on its input and output busses, upmixing and downmixing as needed.