Skip to content

Commit

Permalink
Fix to play SDL_audio on current device by default (#23)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dartfnm authored Sep 2, 2024
1 parent b7b8159 commit c0f2882
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/sounddep/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions uae_src/cfgfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c0f2882

Please sign in to comment.