From c0f2882c4cb237fb85b2bf738b529d10167938a3 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev <47828070+DartFNM@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:10:17 +0300 Subject: [PATCH] Fix to play SDL_audio on current device by default (#23) * Fix to play SDL_audio on current device by default - There was no sound in quaesar because it uses the sound SDL_Audio device at index 0, not the current audio device in the OS. So now it will choose the current OS audio device unless the user has explicitly specified a different device in the config. * Fix to play SDL_audio on current device by default - There was no sound in quaesar because it uses the sound SDL_Audio device at index 0, not the current audio device in the OS. So now it will choose the current OS audio device unless the user has explicitly specified a different device in the config. --- src/sounddep/sound.cpp | 24 ++++++++++++++++++++++-- uae_src/cfgfile.cpp | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/sounddep/sound.cpp b/src/sounddep/sound.cpp index f4f21ad0..7404bdcf 100644 --- a/src/sounddep/sound.cpp +++ b/src/sounddep/sound.cpp @@ -363,6 +363,24 @@ void resume_sound_device(struct sound_data* sd) { sd->paused = 0; } +int get_default_audio_device() { + int device_idx = -1; +#if SDL_VERSION_ATLEAST(2, 24, 0) + SDL_AudioSpec spec; + char* default_device_name = nullptr; + if (SDL_GetDefaultAudioInfo(&default_device_name, &spec, 0) == 0) { + for (int i = 0; i < num_sound_devices; i++) { + if (strcmp(sound_devices[i]->name, default_device_name) != 0) + continue; + device_idx = i; + break; + } + SDL_free(default_device_name); + } +#endif + return device_idx; +} + static int open_sound() { auto size = currprefs.sound_maxbsiz; @@ -379,10 +397,12 @@ static int open_sound() { sdp->softvolume = -1; int num = enumerate_sound_devices(); - if (currprefs.win32_soundcard >= num) - currprefs.win32_soundcard = changed_prefs.win32_soundcard = 0; if (num == 0) return 0; + if (currprefs.win32_soundcard < 0) + currprefs.win32_soundcard = changed_prefs.win32_soundcard = get_default_audio_device(); + if ((unsigned)currprefs.win32_soundcard >= (unsigned)num) + currprefs.win32_soundcard = changed_prefs.win32_soundcard = 0; const auto ch = get_audio_nativechannels(active_sound_stereo); const auto ret = open_sound_device(sdp, currprefs.win32_soundcard, size, currprefs.sound_freq, ch); if (!ret) diff --git a/uae_src/cfgfile.cpp b/uae_src/cfgfile.cpp index 37f74517..4355d36e 100644 --- a/uae_src/cfgfile.cpp +++ b/uae_src/cfgfile.cpp @@ -8389,6 +8389,7 @@ void default_prefs (struct uae_prefs *p, bool reset, int type) p->keyboard_connected = true; p->produce_sound = 3; + p->win32_soundcard = -1; p->sound_stereo = SND_STEREO; p->sound_stereo_separation = 7; p->sound_mixed_stereo_delay = 0;