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.
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.
The best way to prevent buffer X-runs is to run JACK in real-time mode, which means that jackd is running under special privileges whereby the Linux kernel will not interrupt jackd while it is operating. If this sounds like an invitation to a free for all where applications don't play nice with the system or one another you would be entirely correct which is why the linux kernel is not set up to allow applications to take advantage of real time scheduling by default.
Fortunately there are ways and around this and this tutorial will show you how to compile a real-time capable Linux kernel.
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 you could find yourself being able to start JACK like this.
$ jackd -t 100 -R -d alsa -r 44100 -p 64
The -t 100 increases the timeout setting for the jack sound server to prevent your app being killed during times of heavy system congestion (don't ask). Note the frame size is only 64 in this example.
First of all install the linux kernel source code on your system. You should find it installs to the /usr/src directory.
Next delete any link called linux in your /usr/src directory and make a new soft link to point to the new kernel source directory then cd linux.
You will need to do a little source hacking to enable real-time scheduling but don't worry it's really simple. Using a text editor edit the file include/linux/capability.h. You will need to change these lines that are towards the end of the file:
From this:
#define CAP_EMPTY_SET to_cap_t(0)
#define CAP_FULL_SET to_cap_t(~0)
#define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
#define CAP_INIT_INH_SET to_cap_t(0)
To this:
#define CAP_EMPTY_SET to_cap_t(0)
#define CAP_FULL_SET to_cap_t(~0)
#define CAP_INIT_EFF_SET to_cap_t(~0)
#define CAP_INIT_INH_SET to_cap_t(~0)
If you have a working kernel .config file from a previous kernel compile copy it over now. You will need to set the following:
HZ_100=n
HZ_250=n
HZ_1000=y
PREEMPT_NONE=n
PREEMPT_VOLUNTARY=n
PREEMPT=y
PREEMPT_BKL=y
SECURITY=y
SECURITY_CAPABILITIES=m
That last one has to be a module.
Next compile and install the kernel (remember to make oldconfig first). Then install realtime-lsm against the new kernel. Gentoo users can just emerge realtime-lsm provided they have set the linux symlink mentioned previously.
If you type grep ^audio: /etc/group you should get something like...
audio:x:18:stephen,icecast,test
Note that you need to put your user in this group in my case stephen is in there so I am covered but also note the number in the third column, the number 18 in my case, in yours this number could be different. You should make a note of this number for the next step.
Edit your modules.conf file or if you are a gentoo user create or edit a file called /etc/modules.d/realtime. In either case you need to add a line like this.
options realtime gid=18
That number must match the number of your audio group. Gentoo users need to run modules-update to recreate the modules.conf file.
If you use proprietary graphics drivers don't forget to install those for the new kernel, ditto for alsa-drivers if you are not using the ones that came with the kernel.
That's about it I think. Now go boot your new kernel and hopefully enjoy! If your microphone audio sounds a little odd running with a frame size of 32 try clicking the Invert boxes in the Microphone tab in the Prefs.
Back to the Main Page.