Skip to content

Conversation

vanfanel
Copy link
Contributor

@vanfanel vanfanel commented Jul 7, 2025

Description

Implements SDL_GetDefaultAudioInfo() on the ALSA backend, needed for programs that explicitly look for the default audio device, like current MAME (since 0.278).
It's done by opening the default ALSA device, getting the info and closing it.
The alternative was to manually parse the ALSA config files, which would be a way more convoluted and weak solution.

Existing Issue(s)

Fixes issue #13318

Comment on lines +522 to +525
spec->freq = 48000;
spec->format = AUDIO_S16SYS;
spec->channels = 2;
spec->samples = 512;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what ALSA prefers by default if the hardware doesn't specify; the channel count is Good Enough(TM) but I wonder if there's a preference for format and samples in particular.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge, ALSA doesn't have any explicit preference, but we can rely on S16_LE and/or S16_BE support in ALSA for every device ALSA supports, and AUDIO_S16SYS choses the one supported by the system. That makes it a very sane default.
As for 512, it offers a good compromise between latency and buffer underrun protection, a good historic value. ALSA doesn't have any preference in this regard either to my knowledge, but other higher-level APIs that work on ALSA like OpenAL or Portaudio use 512 samples in ALSA too.

@flibitijibibo flibitijibibo requested a review from icculus July 7, 2025 16:26
@vanfanel
Copy link
Contributor Author

@icculus Can you please greenlight this small commit? There's another ALSA backend bug I'd need to take care of but I'd like to close the issue related to this commit first :)

@icculus
Copy link
Collaborator

icculus commented Jul 17, 2025

Yeah, why not, let's merge!

@icculus icculus merged commit 874ca5a into libsdl-org:SDL2 Jul 17, 2025
68 of 70 checks passed
@vanfanel
Copy link
Contributor Author

Yeah, why not, let's merge!

yay! Thanks! :)

@slouken
Copy link
Collaborator

slouken commented Jul 17, 2025

@icculus, is there an equivalent of this change that needs to go into SDL3?

@icculus
Copy link
Collaborator

icculus commented Jul 17, 2025

This API was removed from SDL3.

@vanfanel
Copy link
Contributor Author

This API was removed from SDL3.

Yes, so it seems. For good, if you ask me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants