Bug on default audio device selection on WASAPI?

Hi

I have started developing an app using SDL.
I’m having inconsistent behavior in Windows depending on the selected audio driver. Basically it seems the WASAPI driver doesn’t honor the windows default audio device.

My code is as follows:

   int devices = SDL_GetNumAudioDevices(0);

   logger(LOG_INFO, tag, "audio devices: %d\n", devices);

   for (unsigned i = 0; i < devices; i++)
      logger(LOG_INFO, tag, "device %d: %s\n", i, SDL_GetAudioDeviceName(i, 0));

   SDL_zero(want);

   want.freq = 48000;
   want.format = AUDIO_S16;
   want.channels = 2;
   want.samples = 4096;
   want.callback = NULL;

   logger(
      LOG_INFO, tag, "want - frequency: %d format: f %d s %d be %d sz %d channels: %d samples: %d\n", want.freq,
      SDL_AUDIO_ISFLOAT(want.format), SDL_AUDIO_ISSIGNED(want.format), SDL_AUDIO_ISBIGENDIAN(want.format),
      SDL_AUDIO_BITSIZE(want.format), want.channels, want.samples);
   device = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);

So given that, I get the following:

$ SDL_AUDIODRIVER=wasapi ./invader_imgui_sdl2.exe
[i] --- [main] audio devices: 2
[i] --- [main] device 0: Speakers (Steam Streaming Speakers)
[i] --- [main] device 1: Speakers (High Definition Audio Device)
[i] --- [main] want - frequency: 48000 format: f 0 s 32768 be 0 sz 16 channels: 2 samples: 4096
[e] --- [main] opened audio device: Speakers (Steam Streaming Speakers)
[i] --- [main] have - frequency: 48000 format: f 0 s 32768 be 0 sz 16 channels: 2 samples: 4096

WASAPI is picked by default. I am now gonna try directsound:

$ SDL_AUDIODRIVER=directsound ./invader_imgui_sdl2.exe
[i] --- [main] audio devices: 2
[i] --- [main] device 0: Speakers (High Definition Audio Device)
[i] --- [main] device 1: Speakers (Steam Streaming Speakers)
[i] --- [main] want - frequency: 48000 format: f 0 s 32768 be 0 sz 16 channels: 2 samples: 4096
[e] --- [main] opened audio device: Speakers (High Definition Audio Device)
[i] --- [main] have - frequency: 48000 format: f 0 s 32768 be 0 sz 16 channels: 2 samples: 4096

Then I thought maybe it always picks the first one, so I changed the device,
Again, directsound is correct:

$ SDL_AUDIODRIVER=directsound ./invader_imgui_sdl2.exe
[i] --- [main] audio devices: 2
[i] --- [main] device 0: Speakers (Steam Streaming Speakers)
[i] --- [main] device 1: Speakers (High Definition Audio Device)
[i] --- [main] want - frequency: 48000 format: f 0 s 32768 be 0 sz 16 channels: 2 samples: 4096
[e] --- [main] opened audio device: Speakers (Steam Streaming Speakers)

But for wasapi the order doesn’t change. I figure windows changes the enumeration order for dsound based on the default device, and I could certainly force my app to always use directsound if it’s available but I’d rather have it pick the device according to the OS default with any available driver.

Maybe the wasapi driver doesn’t implement functionality to query the default audio device?