FNA-XNA / FAudio

FAudio - Accuracy-focused XAudio reimplementation for open platforms
https://fna-xna.github.io/
Other
534 stars 72 forks source link

Failure with audio device with 18 inputs: "OpenAudioDevice failed: Unsupported number of audio channels" #323

Closed briankendall closed 8 months ago

briankendall commented 8 months ago

I'm experimenting with recompiling an old XNA game. When I try running it on macOS with a UMC1820 audio interface as my default device, I get a crash with the following message:

INFO: OpenAudioDevice failed: Unsupported number of audio channels.

This error comes from SDL_OpenAudioDevice on line 173 of FAudio_platform_sdl2.c. Digging deeper, I can see that FAudio is trying to have the number of output channels be 18, which SDL explicitly does not support as it only allows up to 8 channels, and therefore FACTAudioEngine_Initialize is failing when trying to initialize FNA's AudioEngine. Digging even deeper, I can see that there's code in FAudio that sets the number of output channels on the SDL device to match the number of input channels.

I'm not sure why that's the case (since I'd have to really familiarize myself with the logic deep within FAudio) but I'm guessing this is a reasonable thing to do in most situations where someone only has stereo audio input, but is failing in an edge case of having one's default audio device be a production-oriented external audio interface with 18 inputs and 20 outputs.

I can seemingly work around the issue by explicitly changing the InputChannels argument of FAudio_CreateMasteringVoice to 2, but I'm not sure what the farther reaching implications of such a change would be. At the very least the game I'm working with only has stereo audio so I'm hoping that workaround is fine at least in my case.

I've only reproduced this issue in macOS so far, but I think it will affect any platform that uses SDL as its backend when running on a system where its default audio device has more than 8 input channels.

I believe that the reasonable thing to do here would be to treat any audio device that has 9 or more channels as being a stereo device, and only using channels 1 and 2 (which is the correct thing to do in the case of the UMC1820 and most other audio interfaces like it).

flibitijibibo commented 8 months ago

We may want to add a sanity check to this part here, or just afterward, to limit the max channel count:

https://github.com/FNA-XNA/FAudio/blob/master/src/FAudio_platform_sdl2.c#L309

flibitijibibo commented 8 months ago

Was pretty sure I'd already done this check, but I only did it before adding GetDefaultAudioInfo - this is now back in:

https://github.com/FNA-XNA/FAudio/commit/9d531b7acca40fa741499cecf4a3cc6584c78724

briankendall commented 8 months ago

I can confirm that fixed the issue! Thanks for the fast turn around.