aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/sdl2.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-03-08 18:07:49 -0800
committerChris Robinson <[email protected]>2018-03-08 18:07:49 -0800
commitd4fc87fc9c2cacb09d9538c410a701a8dd12aa6b (patch)
tree9750bd623d646a364d77343f7062b43738cc110a /Alc/backends/sdl2.c
parent2187316bce826de1eaa6438f688d4713032be3da (diff)
Avoid calling SDL_GetNumAudioDevices multiple times
Diffstat (limited to 'Alc/backends/sdl2.c')
-rw-r--r--Alc/backends/sdl2.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c
index 9bd42cdf..416e745d 100644
--- a/Alc/backends/sdl2.c
+++ b/Alc/backends/sdl2.c
@@ -207,9 +207,12 @@ static ALCboolean ALCsdl2BackendFactory_querySupport(ALCsdl2BackendFactory* UNUS
static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enum DevProbe type)
{
+ ALCboolean quit = ALC_FALSE;
+ int num_devices, i;
+
if(type != ALL_DEVICE_PROBE)
return;
- ALCboolean quit = ALC_FALSE;
+
if(SDL_WasInit(0) == 0) // Is SDL2 initialized at all?
{
SDL_Init(SDL_INIT_AUDIO);
@@ -217,9 +220,13 @@ static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enu
}
else if(!SDL_WasInit(SDL_INIT_AUDIO))
SDL_InitSubSystem(SDL_INIT_AUDIO);
+
+ num_devices = SDL_GetNumAudioDevices(SDL_FALSE);
+
AppendAllDevicesList(defaultDeviceName);
- for(int i = 0; i < SDL_GetNumAudioDevices(0); ++i)
- AppendAllDevicesList(SDL_GetAudioDeviceName(i, 0));
+ for(i = 0; i < num_devices; ++i)
+ AppendAllDevicesList(SDL_GetAudioDeviceName(i, SDL_FALSE));
+
if(quit)
SDL_Quit();
}