Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding channel detection to CoreAudio backend #1056

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

colincornaby
Copy link
Contributor

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.

alc/backends/coreaudio.cpp Outdated Show resolved Hide resolved
alc/backends/coreaudio.cpp Outdated Show resolved Hide resolved
alc/backends/coreaudio.cpp Outdated Show resolved Hide resolved
alc/backends/coreaudio.cpp Outdated Show resolved Hide resolved
alc/backends/coreaudio.cpp Outdated Show resolved Hide resolved
@colincornaby
Copy link
Contributor Author

I've committed changes to address the above feedback. Please re-review at your convenience.

@kcat
Copy link
Owner

kcat commented Nov 5, 2024

Seems this is failing on iOS: https://github.com/kcat/openal-soft/actions/runs/11678208331/job/32535511458?pr=1056#step:6:397

error: use of undeclared identifier 'kAudioDevicePropertyPreferredChannelLayout'; did you mean 'kAudioFilePropertyChannelLayout'?
            err = AudioUnitGetProperty(mAudioUnit, kAudioDevicePropertyPreferredChannelLayout, kAudioUnitScope_Output, OutputElement, layout.get(), &propSize);
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                   kAudioFilePropertyChannelLayout

The code block that tries to set the FmtChans field might need to be conditioned on the #if CAN_ENUMERATE macro, unless there's some way to make it work.

kAudioDevicePropertyPreferredChannelLayout seems to be unavailable on iOS
@kcat kcat merged commit 068a542 into kcat:master Nov 9, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants