Is there any way to get audio device capabilities via SDL2?
I can enumerate the devices (SDL_GetNumAudioDevices and SDL_GetAudioDeviceName) and then it’s possible to open a device with desired properties, flags relating to what parameters are permissibly changeable and then inspect what actual properties you get back with SDL_OpenAudioDevice.
But is there no way to look up device capabilities? To query what an audio device supports - max frequency, max channels, whether floating point support is available, etc.?
As I’d like to offer the user some control over the audio parameters - so if they’ve got surround speakers, they can turn those on, but stick with stereo otherwise, or they can select different audio devices, if they’ve got more than one - but, in terms of presentation and ease-of-use, I’d like to supply the user with the available options for their chosen device.
What I don’t want is to supply all possible options, let the user choose, say, “5.1 surround” and then is greeted with an error message that the audio device doesn’t actually support that.
If I can query audio device capabilities ahead of time, then I can limit the options only to that which is actually available with the device, so they just can’t pick an invalid configuration in the first place.
Now, because of the ability to open an audio device with “desired” properties and then inspect whether you get those properties back (specifying no flags that you won’t accept any changes), there is, I guess, the possibility of trying to open an audio device with different combinations - try 5.1 channels to see if that works, then try 4 channels, then try stereo - and then note which combinations actually succeed and which don’t.
That is, use a process of elimination by opening and closing the audio device to actively “probe” what combinations actually succeed.
But this seems like a wasteful and silly way to go about things. It’d make more sense to have a query API - e.g. SDL_GetAudioDeviceCaps - that simply returns a structure with “int max_frequency”, “bool float_support”, “bool StereoSupport”, “bool QuadSupport”, etc. so that you can just ask, ahead of time, “what can this audio device do?”.
So that you’re not trying, failing, trying, failing, trying, failing all possible combinations to “probe” some answers out of the device, but can just directly ask up-front “okay, audio device, what can you do?”.
If there is no API in SDL2 for this as yet, then please consider this very much a “feature request” that it really, really ought to be added. “Probing” to find out information that should just be query-able up-front is a bit silly and wasteful.