Hyper Low-Latency Audio with a Real-Time Kernel
September 19th, 2008 by Elliot Isaacson in
The promise of zero or near-zero latency audio is a huge asset to the the Linux operating system. Sometimes, achieving super low-latency audio is tricky, but not if your kernel is hard-realtime capable. Cut your latency to under 3 ms with this tutorial.
__________________________
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Jul-01-09
- Jun-29-09
Recently Popular
From the Magazine
July 2009, #183
News Flash: Linux Kernel 3.0 to include an on-the-go Expresso machine interface! Ok, maybe not, but Linux is definitely going mobile, from phones to e-readers. Find out more inside about Android, the Kindle 2, the Western Digital MyBook II, The Bug, and Indamixx (a portable recording studio). And if you've gone mobile and you been wanting more Emacs in your life then check out Conkeror.
To compliment the mobile we've got the stationary: parsing command line options with getopt, checking your Ruby code with metric_fu, and building a secure Squid proxy. How is this stationary you ask? What can we say? It's not. We just wanted to see if anybody actually read this part of the page :) .
All this and more, and all you have to do is get your hot sweaty hands on the latest copy of Linux Journal.
Delicious
Digg
StumbleUpon
Reddit
Facebook








realtime
On September 28th, 2008 thorgal (not verified) says:
"realtime" is not about small latency but duration predictability. A hard RT system is supposed to be 100% predictable per a given process. A soft rt system guaranties predictability on average so it is less reliable per a given process but keeps the average time predictable.
Realtime kernels
On September 28th, 2008 Arnout Engelen (not verified) says:
Before diving in and compiling your own kernel patched with realtime support, I'd suggest checking whether your distro comes with a kernel tuned for realtime use.
Watch this space: http://wiki.linuxmusicians.com/doku.php?id=system_configuration#installing_a_real-time_kernel
Ubuntu Studio
On September 22nd, 2008 evilsoccerfiend says:
Ubuntu Studio has a full suite of audio recording and manipulation applications. You can of course build your own real time kernel (do a google search for make-kpkg or kernel-package for help on the Debian/Ubuntu specifics of this process), but since Ubuntu Studio provides its own real time kernel there is no need to do this.
Personally I have 64 Studio on my dedicated audio workstation, and Ubuntu Studio on my laptop. You can also convert an existing K/X/Ubuntu install by adding the Ubuntu Studio sources to your package manager. The Ubuntu Studio site provides the details on this. I know it works because that is what I have done.
Hth,
which one is better?
On February 21st, 2009 arpo (not verified) says:
So I think I need your help: I'm going to install a linux distro on my AMD64 laptop. I need it mainly to play software synths live with my MIDI keyboard so I think I need a fast (low latency) and reliables OS. What would you suggest for this? Ubuntu Studio 64 or 64 Studio?
Thanks
Ubuntu -> Ubuntu Studio even easier
On September 28th, 2008 Arnout Engelen (not verified) says:
You can also convert an existing K/X/Ubuntu install by adding the Ubuntu Studio sources to your package manager. The Ubuntu Studio site provides the details on this.
In fact, all Ubuntu Studio packages have nowadays been merged into mainline Ubuntu, so all of the power of Ubuntu Studio is now at the fingertips of all Ubuntu users - even without having to add an extra package source.
More info can be found here.
hard realtime is when you
On September 21st, 2008 Anonymous (not verified) says:
hard realtime is when you have bounded latency or all hell breaks loose (people die, or lots of money is lost).
soft realtime is when you statistically (usually) have a bounded latency.
preempt_rt improves Linux latency so that less things affect the longest latency.
you can have soft realtime systems that measure latency in minutes too. But the professional audio case needs ms range.
There is no hard-realtime kernel for Linux. If you want hard realtime, use WindRiver, QNX or RTLinux. Non of them resemble what you describe.
Good tutorial though.
good presentation !
On September 20th, 2008 Dave Phillips says:
Hi Elliot:
Thanks for the excellent breakdown. Alas, I fear it's all too much for any average musician, Linux-based or otherwise. In place of the process you've described I now routinely advise installing a latency-optimized distribution such as 64 Studio or Planet CCRMA. Those systems are also optimized re: MIDI, which is bound to be of importance for modern computer-based music-making. Your demonstration does appear to include setting support for the realtime clock (RTC), perhaps that should be mentioned for the benefit of the more MIDI-minded musician. In addition to the RTC there is a frequency setting (in the firmware drivers configuration, IIRC) that should also be set to CONFIG_HZ=1000. The default is often far too low (250 or even 100 Hz) for decent resolution of a MIDI event stream, especially a heavy one.
One other note: From what I understand, hard realtime is not what we get from these optimizations, and the collective knowledge seems to agree that hard realtime is unnecessary for even professional audio requirements. If I'm wrong corrections are welcome. :)
Otherwise, a good demonstration of the effect of the realtime optimizations. Thanks again ! :)
Best,
Dave Phillips
http://linux-sound.org
Hard realtime
On September 28th, 2008 Kjetil Matheussen (not verified) says:
Hi Dave,
I have a small correction to your comment:
Ingo's patches does actually provide hard realtime scheduling to linux, that's the point of it. You need some kind of hard realtime scheduling to play audio if you want a guarantee that no sound glitches will occur. The reason for this is that hard realtime scheduling gurantees that processes set to run in realtime wakes up within a certain timeframe. And this also means that hard realtime most certainly is necessary for professional audio requirements, since "professionals" usually don't want glitches in sound.
With all this said, you can in practice avoid glitches in non-realtime systems as well, but you have no guarantee. With Ingo's patches, you have.
Hi Dave, I've learned a lot
On September 20th, 2008 Elliot Isaacson says:
Hi Dave,
I've learned a lot from your articles and linux-sound.org is a great resource, keep up the great work.
You're right about the kernel options for MIDI users. I'm pretty sure that 1000Hz is the default timer frequency for all desktop systems, with 250Hz reserved for servers, but it's worth mentioning anyway. I do sometimes forget that people are going to want to use MIDI, I'm very old-fashioned with my acoustic instruments and such.
What I think you mean by your other comment is that the audio system does not run in hard realtime even with a hard-realtime kernel, and I totally agree. Hard realtime latencies are measured in microseconds and the latency for the audio system is measured in milliseconds. But for my system with my lame hardware, the unpatched scheduler doesn't allow me push Jack much below ~25ms without risk, while with Molnar's patch I can force it to under 3ms.
Best Regards,
Elliot
No, you missed the point
On September 23rd, 2008 Anonymous (not verified) says:
No, you missed the point again. And I'm not even the same anonymous. 'Hard' in the context of realtime systems does not mean 'hard as in difficult', but 'hard as in inflexible'.
'Hard realtime' is an embedded system concept, whereby the combination of OS, kernel, compiler, libraries, etc. provide scheduling guarantees. The guarantees are the important bit here: you'd typically use an extremely C-unlike programming language, and you'd be able to do static analysis on your system to prove that no matter what the circumstances, your system can cash its cheques.
Again, it's nothing to do with the kind of response times that the system can achieve, but whether or not it can guarantee to meet the deadline.
For instance, in an automated dairy (there's one on an episode of How it's Made), a hypothetical hopper thing that feeds the cows needs to operate within at most a few hours of the feeding time. Not exactly a short deadline, but still a constraint within which the system absolutely must operate: the system can't crash, or only activate after a few days, or all the cows will starve. That's a hard realtime constraint. Similar example might include a fire-exit with a breakglass to unlock it, or a fill sensor on a dishwasher. None of the aforementioned need to operate within three milliseconds, but they all have hard deadlines which, if passed, will endanger people or damage stuff.
And now, finally, to get to the point: Linux is not a hard-realtime kernel. It can't make performance guarantees. It may be on the way to becoming a good realtime kernel, but that's not the same thing.
You wrote: "And now,
On September 28th, 2008 Kjetil Matheussen (not verified) says:
You wrote:
"And now, finally, to get to the point: Linux is not a hard-ealtime kernel. It can't make performance guarantees. It may be on the way to becoming a good realtime kernel, but that's not the same thing."
I'm not sure if you are referring to vanilla or the rt patches,
now, so to clear up: The point of the rt patches are simply to make the linux kernel hard realtime capable.
I think it does this by making all code (including interrupt handlers) pre-emptable (somehow). Search for monta vista realtime kernel, which Ingo builds his work on, if I'm not much mistaken.
Wikipedia's page about Mingo Molnar,
http://en.wikipedia.org/wiki/Ingo_Molnar,
says: "One of his recent projects is the realtime preemption patch, which aims to bring hard-realtime scheduling latencies (50–60 microseconds worst-case execution time) to the Linux kernel."
Ubuntu Studio?
On September 20th, 2008 Anonymous (not verified) says:
How much of this is available by default in Ubuntu Studio? I know that it uses Jack with a real time kernel.
Post new comment