Adding channel detection to CoreAudio backend #1056
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I work on the a game engine that makes use of OpenAL Soft. We noticed, on macOS, that OpenAL was not properly providing surround sound to some hardware devices like the Apple Studio Display. The Studio Display is a 5.1.2 device, but OpenAL was treating it as a stereo device.
After some research - I found the CoreAudio backend for OpenAL Soft is not properly querying the channel count of devices. If the device type was overridden in the OpenAL config - surround output would work. But OpenAL would not auto detect surround devices on macOS.
This change implements a correct query of the device channel count by querying the preferred channel setup of the underlying device/audio unit. I took some notes from how PulseAudio handles this - and I also populate FmtChans by comparing against a known set of channel configurations. This change was implemented in two places. The function that gets the channel count is routed to the correct CoreAudio API. And a new chunk of code to populate FmtChans was added.
kAudioDevicePropertyPreferredChannelLayout also gives a channel layout for the audio buffers. I've opted to continue using the WaveFormatExtensible - but kAudioDevicePropertyPreferredChannelLayout can be used for manually populating the channel layout. One issue with using AudioChannelLayout to manually layout the OpenAL output channels is that it might be difficult to map from a manually specified OpenAL channel configuration back to CoreAudio layouts. It could be a possible improvement in the future.
This is my first PR to OpenAL - and my CoreAudio is a bit rusty. I'd appreciate any feedback on this PR! Thanks.