Linux Audio

Audio applications are time-critical, so they need a preemptible (low latency) kernel with a 1000Hz timer frequency. - Ted’s Linux MIDI Guide

From Ted’s Linux MIDI Guide

Latency is also driven by the size of the buffer in Jack.
The buffer size can be controlled by QJackCtl => and it gives an indication of Latency as well.

  • a buffer size of 32 gives a latency of 0.667ms
  • a buffer size of 1024 (the default) gives a latency of 21.3ms (which can be heared easily).

Low Latency Kernel

To check whether you are running a low latency kernel, use uname:

$ uname -a
Linux yves-huv 6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct  9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

The important thing to notice is PREEMPT_DYNAMIC. That means that I’ve got a preemptible kernel loaded. This means low latency.

Note: There are variations on PREEMPT that require a little more investigation:

  • PREEMPT means you have a kernel with full preemption and you are good.
  • PREEMPT_DYNAMIC allows preemption to be turned on and off at boot time with the kernel’s “preempt=” command line option. You’ll need to check your GRUB configuration (grep CMDLINE /etc/default/grub) to make sure this is either set to “preempt=full” or not set at all (the default is “full”). You can check the setting (immediately) after boot with “sudo dmesg grep preempt”.
$ grep ^CONFIG_HZ /boot/config-`uname -r` # bash
CONFIG_HZ_250=y   # This is not good
CONFIG_HZ=250

We should have instead

$ grep ^CONFIG_HZ /boot/config-`uname -r`
CONFIG_HZ_1000=y
CONFIG_HZ=1000

==> Need to install a low latency kernel.

$ apt-cache search --names-only linux-lowlatency-hwe
linux-lowlatency-hwe-22.04 - Complete lowlatency Linux kernel
...
$ sudo apt install linux-lowlatency-hwe-22.04 # Pick the newest, (without "edge")

Reboot. Then go through the steps above again to make sure you actually have a low-latency kernel.

Enabling it

=> Audio Group

$ groups
$ 

see also

Written on November 9, 2023, Last update on November 17, 2023
linux-system kernel midi linux-audio audio-hardware linux-hardware