libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
8.81k stars 1.66k forks source link

pipewire can only set the quantum/latency value through SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES #9857

Open digitalsignalperson opened 1 month ago

digitalsignalperson commented 1 month ago

I am looking at if it makes sense to make a low latency audio application with SDL's audio backend and notice pipewire's clock.quantum and clock.force-quantum value are ignored by SDL. GetDefaultSampleFramesFromFreq() hard codes buffer sizes unless the SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES hint is set before initializing.

If I do pw-metadata -n settings 0 clock.quantum 128, then the testaudio.c program shows a 1024 quantum value in pw-top, unless I use SDL_SetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES, "128"); in initialization.

I see that SDL_AudioSpec had a samples field in SDL2 but was removed. Could it be optional or something?

AliceLR commented 1 month ago

Seconded—I can understand not wanting to clutter SDL_AudioSpec with it, but it would be nice to have real API functions at least. User-configurable audio latency is a legitimate feature and banishing it to SDL_SetHint (hack) reads odd. I spent a fair chunk of time trying to find this feature at all (edit: it's not in the migration guide, or the wiki pages for SDL_OpenAudioDevice, SDL_OpenAudioDeviceStream, or SDL_AudioSpec).

Relevant past discussion: https://github.com/libsdl-org/SDL/issues/7450#issuecomment-1465289536