1

While I know how to use MIX_OpenAudio.... I wanted to know the use of MIX_OpenAudioDevice function

It takes several arguments... Device name is one of them

So, I want to know that how can we know what the device name is

It says we can use a function i.e. SDL_GetAudioDeviceName()

But how would we know which audio device to choose on every system....

Or is this function only for working with specific audio systems such as realtek or something?

1 Answers1

0

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.

treckstar
  • 1,956
  • 5
  • 21
  • 26