Channel mapping confusion
Channel mapping confusion
- Subject: Channel mapping confusion
- From: "Stephen F. Booth" <email@hidden>
- Date: Fri, 11 Oct 2013 14:22:09 -0400
I've managed to confuse myself about channel mapping as it relates to the HALOutput audio unit.
I have audio with various numbers of channels and channel layouts and I want to ensure that the channels are mapped to the output device in a consistent way that the user expects. Initially I hoped to simply set kAudioUnitProperty_AudioChannelLayout on the output unit and have everything work. However, that doesn't seem to be the case as I receive -10851 (kAudioUnitErr_InvalidPropertyValue) when attempting to set the property. This occurs for every channel layout I've tried, from stereo to 5.1, using tags or channel descriptions.
This is really only an inconvenience for multichannel files because I can query kAudioDevicePropertyPreferredChannelLayout on the output unit and then use kAudioFormatProperty_ChannelMap to create an appropriate channel map. This appears to be working correctly and reflects what I've set in Audio MIDI Setup.
The problem I'm having is with stereo files. I can query kAudioDevicePropertyPreferredChannelsForStereo on the output unit to determine which device channels to use. However, I'm having difficulty turning this into a valid channel map to pass to the output unit.
Here is an example: in Audio MIDI setup I set the stereo speaker layout to reverse left and right and do the same for multichannel. When I ask the output unit for these properties I get
kAudioDevicePropertyPreferredChannelsForStereo[0] = 2
kAudioDevicePropertyPreferredChannelsForStereo[1] = 1
kAudioDevicePropertyPreferredChannelLayout: 2 channel descriptions:
0. Label = kAudioChannelLabel_Right (0x00000002)
1. Label = kAudioChannelLabel_Left (0x00000001)
which agrees with my settings.
Using an AudioChannelLayout with the tag kAudioChannelLayoutTag_Stereo, I can create a channel map using the device's preferred channel layout and kAudioFormatProperty_ChannelMap. When I do this I get [1, 0] which correctly reverses the channels when used for playback. On a 6-channel device it works properly and gives [1, 0, -1, -1, -1, -1]
However, when the audio is stereo I don't want to use kAudioDevicePropertyPreferredChannelLayout; I want to use kAudioDevicePropertyPreferredChannelsForStereo as I think this is the expected behavior. The channel numbers returned by kAudioDevicePropertyPreferredChannelsForStereo appear to be 1-based but I can't find this in any documentation other than that covering AudioStreams.
This is a very long winded way of asking for help in creating a channel map using kAudioDevicePropertyPreferredChannelsForStereo. Is it necessary to get the device's streams, sum the channel count for each stream, create an array of that length, and then use the kAudioDevicePropertyPreferredChannelsForStereo values to create the channel map?
Stephen
_______________________________________________
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