Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GetAudioDeviceSpec() not working properly with ALSA #9016

Open
Harvie opened this issue Feb 7, 2024 · 0 comments
Open

SDL_GetAudioDeviceSpec() not working properly with ALSA #9016

Harvie opened this issue Feb 7, 2024 · 0 comments
Assignees
Milestone

Comments

@Harvie
Copy link

Harvie commented Feb 7, 2024

Hello, i am using SDL 2.30.0 to implement multiplatform audio capture. But i was surprised when one of the users reported it only works on pulseaudio and pipewire, but not on ALSA: sigrokproject/libsigrok#185

Reason is that SDL_GetAudioDeviceSpec() does not return correct values for ALSA capture device. Only way to get correct specs is by opening the device using SDL_OpenAudioDevice(). Therefore i had to implement following wrapper to get code working on ALSA:

int SDL_GetAudioDeviceSpec_open(int index, int iscapture, SDL_AudioSpec *spec)
{
	//ALSA does not allow to fully read specs of device without opening it.
	//This wrapper tries to open device when SDL_GetAudioDeviceSpec() incorrectly reports device to have 0 channels.
	//See https://github.com/libsdl-org/SDL/blob/237348c772b4ff0e758ace83f471dbf8570535e2/src/audio/alsa/SDL_alsa_audio.c#L759

	int ret = SDL_GetAudioDeviceSpec(index, iscapture, spec);
	if(!ret && spec->channels == 0) {
		printf("Failed SDL_GetAudioDeviceSpec(), trying to open device to get specs.");
		SDL_AudioDeviceID d;
		d = SDL_OpenAudioDevice(SDL_GetAudioDeviceName(index, iscapture), iscapture, spec, spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
		if(d) SDL_CloseAudioDevice(d);
	}
	return ret;
}

But i think this is the exact thing that should be handled by SDL, because i use SDL exactly for the reason i don't want to care about any platform-specific hacks in my app. Can you please consider fixing this on SDL side?

Thanks

@slouken slouken added this to the 2.32.0 milestone Feb 7, 2024
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

No branches or pull requests

3 participants