So from how I understand it, MIX_OpenAudio()
is already using MIX_OpenAudioDevice()
, just using a NULL
value for the device
parameter (which then defaults to whatever the system uses for sound). The only reason you would need to specify an actual device
in that function is if you are expecting your audio data to be in a specific format. Therefore you should already know what it is.
From the docs: (link)
If you aren't particularly concerned with the specifics of the audio device, and your data isn't in a specific format, the values you use here can just be reasonable defaults.
This function allows you to select specific audio hardware on the system with the device parameter. If you specify NULL
, SDL_mixer will choose the best default it can on your behalf (which, in many cases, is exactly what you want anyhow). SDL_mixer does not offer a mechanism to determine device names to open, but you can use SDL_GetNumAudioDevices()
to get a count of available devices and then SDL_GetAudioDeviceName()
in a loop to obtain a list. If you do this, be sure to call SDL_Init(SDL_INIT_AUDIO)
first to initialize SDL's audio system!
As the doc says there, SDL_GetNumAudioDevices()
will allow you to loop through SDL_GetAudioDeviceName()
to see if it exists on the machine.
This would allow you more control over your audio and can save CPU time from converting the data to the exact device. You also must have that device already opened as well.
Also a link to the SDL2 docs.
Hope this helps explain that function.