Advertisement
8bitbubsy

SDL2 disable WASAPI

Aug 9th, 2020 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #ifdef _WIN32
  2. void disableWasapi(void) // call this function before SDL_Init()
  3. {
  4.     // disable problematic WASAPI SDL2 audio driver on Windows (causes clicks/pops sometimes...)
  5.  
  6.     const int32_t numAudioDrivers = SDL_GetNumAudioDrivers();
  7.     if (numAudioDrivers <= 1)
  8.         return;
  9.  
  10.     // look for directsound and enable it if found
  11.     for (int32_t i = 0; i < numAudioDrivers; i++)
  12.     {
  13.         const char *audioDriver = SDL_GetAudioDriver(i);
  14.         if (audioDriver != NULL && strcmp("directsound", audioDriver) == 0)
  15.         {
  16.             SDL_setenv("SDL_AUDIODRIVER", "directsound", true);
  17.             return;
  18.         }
  19.     }
  20.  
  21.     // directsound is not available, try winmm
  22.     for (int32_t i = 0; i < numAudioDrivers; i++)
  23.     {
  24.         const char *audioDriver = SDL_GetAudioDriver(i);
  25.         if (audioDriver != NULL && strcmp("winmm", audioDriver) == 0)
  26.         {
  27.             SDL_setenv("SDL_AUDIODRIVER", "winmm", true);
  28.             return;
  29.         }
  30.     }
  31.  
  32.     // we didn't find directsound or winmm, let's use wasapi after all...
  33. }
  34. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement