Linux 5.16 Aims For Better USB Low-Latency Audio Playback
The Linux kernel is trying again to enhance the low-latency playback mode of its USB audio driver.
Takashi Iwai of SUSE who oversees the Linux kernel's sound subsystem and has been responsible for many of the sound improvements to the kernel drivers over the past number of years has taken a fresh stab at enhancing the low-latency playback support.
Takashi explained with one of the patches, "This is another attempt to improve further the handling of playback stream in the low latency mode. The latest workaround in commit 4267c5a8f313 ("ALSA: usb-audio: Work around for XRUN with low latency playback") revealed that submitting URBs forcibly in advance may trigger XRUN easily. In the classical mode, this problem was avoided by practically delaying the submission of the actual data with the pre-submissions of silent data before triggering the stream start. But that is exactly what we want to avoid. Now, in this patch, instead of the previous workaround, we take a similar approach as used in the implicit feedback mode. The URBs are queued at the PCM trigger start like before, but we check whether the buffer has been already filled enough before each submission, and stop queuing if the data overcomes the threshold. The remaining URBs are kept in the ready list, and they will be retrieved in the URB complete callback of other (already queued) URBs. In the complete callback, we try to fill the data and submit as much as possible again. When there is no more available in-flight URBs that may handle the pending data, we'll check in PCM ack callback and submit and process URBs there in addition. In this way, the amount of in-flight URBs may vary dynamically and flexibly depending on the available data without hitting XRUN."
These USB-audio driver patches were queued into the sound subsystem's "-next" branch ahead of the 5.16 merge window opening next month. This low-latency playback code should particularly help JACK use-cases with its small period size. The latest usb-audio driver improvements are in sound for-next.