Skip to content

Commit fecd9cf

Browse files
committed
Improve SoundQueue initialization
1 parent 9f10b5b commit fecd9cf

1 file changed

Lines changed: 13 additions & 22 deletions

File tree

platforms/audio-shared/sound_queue.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ SoundQueue::SoundQueue()
3939
m_sync_output = true;
4040

4141
int audio_drivers_count = SDL_GetNumAudioDrivers();
42-
int audio_devices_count = SDL_GetNumAudioDevices(0);
4342

4443
Debug("SoundQueue: %d audio backends", audio_drivers_count);
4544

@@ -48,41 +47,33 @@ SoundQueue::SoundQueue()
4847
Debug("SoundQueue: %s", SDL_GetAudioDriver(i));
4948
}
5049

51-
Debug("SoundQueue: %d audio devices", audio_devices_count);
52-
53-
for (int i = 0; i < audio_devices_count; i++)
54-
{
55-
Debug("SoundQueue: %s", SDL_GetAudioDeviceName(i, 0));
56-
}
57-
5850
std::string platform = SDL_GetPlatform();
5951
if (platform == "Linux")
6052
{
61-
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
62-
sdl_error("Couldn't init AUDIO subsystem");
63-
6453
if (IsRunningInWSL())
6554
{
6655
Debug("SoundQueue: Running in WSL");
67-
if (SDL_AudioInit("pulseaudio") < 0)
68-
sdl_error("Couldn't init pulseaudio audio driver");
56+
SDL_SetHint("SDL_AUDIODRIVER", "pulseaudio");
6957
}
7058
else
7159
{
7260
Debug("SoundQueue: Running in Linux");
73-
if (SDL_AudioInit("alsa") < 0)
74-
sdl_error("Couldn't init alsa audio driver");
7561
}
7662
}
77-
else
78-
{
79-
if (SDL_Init(SDL_INIT_AUDIO) < 0)
80-
sdl_error("Couldn't init AUDIO");
81-
}
63+
64+
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
65+
sdl_error("Couldn't init AUDIO subsystem");
8266

8367
Log("SoundQueue: %s driver selected", SDL_GetCurrentAudioDriver());
8468

85-
atexit(SDL_Quit);
69+
int audio_devices_count = SDL_GetNumAudioDevices(0);
70+
71+
Debug("SoundQueue: %d audio devices", audio_devices_count);
72+
73+
for (int i = 0; i < audio_devices_count; i++)
74+
{
75+
Debug("SoundQueue: %s", SDL_GetAudioDeviceName(i, 0));
76+
}
8677
}
8778

8879
SoundQueue::~SoundQueue()
@@ -236,4 +227,4 @@ bool SoundQueue::IsRunningInWSL()
236227
}
237228

238229
return false;
239-
}
230+
}

0 commit comments

Comments
 (0)