Low Latency Operation and Jack Audio Connection Kit

(...and how to get the most out of IDJC at the same time).


The problem

I got an email from someone mentioning audio artifacts with IDJC which were eventually identified as being what is known in JACK terminology as a buffer X-runs, a whole series of them in fact. These occur when the task scheduler in the Linux kernel interrupts the time critical routines that JACK calls within its various audio applications. JACK being a real-time audio system dumps any audio frames that are out of date in an effort to catch up which manifests itself as an interruption in the audio.


A solution

The best way to prevent buffer X-runs is to run JACK with real-time scheduling, which means that jackd is running under special privileges whereby the Linux kernel will not interrupt jackd while it is operating. In order to make best use of this mode a fully preemptible kernel is required.


Performance gains

On the matter of buffer X-runs versus latency, it is true that buffer X-runs can for the most part be eliminated by increasing the latency. For a non real-time system, I recommended starting IDJC like this:

	$ jackd -d alsa -r 44100 -p 2048

This gives a latency of 2048 / 44100 * 2000 milliseconds. This is distracting and could make you slur your speech when you hear your time lagged voice in your headphones.

Following the insructions in this guide, in full, you could find yourself being able to start JACK like this.

	$ jackd -R -d alsa -r 44100 -p 64

Note the frame size is only 64 in this example.


Building a fully preemptible kernel (helpful but can be skipped)

If you have compiled a kernel before then this guide is for you and since any mistakes can result in an unbootable system I won't be answering any emails about how do you compile a kernel nor do I assume any responsibility for any loss of data or inconvenience from following these instructions. You have been warned.

Before attmepting to build a kernel take a look in your Linux distribution's package database to make sure that they don't have a prebuilt kernel on offer.

If you need to compile your own take a look in this directory you need to download one of the non broken-out patch files and untar it in your /usr/src directory, then locate the matching kernel here and do the same.

Change into the kernel source directory and enter the following:

        # patch -p1 <../name_of_patchfile

If you have a working kernel '.config' file from a previous kernel compile, copy it over now.

If you see a symbolic link called linux make it point to your new kernel source directory.

Next compile and install the kernel (remember to make oldconfig first).

If you are using a third party graphics driver you'll probably need to compile it against the new kernel.

Reboot and enjoy. Hopefully your system is still operational.


Configuration to allow real-time mode as an ordinary user

Make sure you are in the audio group by entering the following in a console and add yourself if not:

$ groups | grep audio

Next, edit the file /etc/security/limits.conf and add the following:

@audio  -       rtprio          100
@audio  -       nice            -15
@audio  -       memlock         40000000

Log out and log back in again. Your user privileges should now be updated.

Find out by trying to start jackd with the -R option.


Back to the Main Page.