Find out about the latest issue
Never miss an update! Get PC Plus in your RSS reader and follow us on Twitter

Build A Real Time Audio Studio

Linux is a fantastic platform for audio production. Find out how to build the perfect production environment.

Although it might not seem like it, properly dealing with audio requires an intricately tuned PC. The main issue is audio latency, which refers to both the time it takes for a sound to enter your machine and the time it takes for your machine to produce a sound. In everyday use, we don’t really notice this latency. When you click on a button that makes a beep, you don’t care that it might take several hundred milliseconds for the sound to reach your ears. But in the delicate world of audio engineering, several hundreds of milliseconds is far too long, and even a delay of just tens of milliseconds is undesirable.

Most professional systems will try to reduce audio latency to less than 10 milliseconds – faster than the average seek time on most hard drives. Some systems will get it down as low as 2 or 3ms, enabling them to process vocals and instruments in real-time, play software synthesizers just as they would the physical type, and mix and master recordings with the same near-zero latency as an analogue tape machine.

On Windows systems, this low-latency is produced by the ASIO driver framework that’s used by many pro-level audio cards to communicate with apps like Steinberg’s Cubase and Ableton’s Live. On OS X, however, a low latency audio framework is built into the operating system, and it’s a similar case with Linux.

ALSA, or the Advanced Linux Sound Architecture, sits within the Linux kernel itself as a series of hardware drivers. Audio data is passed from ALSA to the user-level applications that manipulate the audio. But despite this low level integration and a built-in potential for good low latency performance, most default Linux installations make poor audio production computers. That’s because there’s still too much going on in the background, and too many throwbacks from the time when Linux was designed primarily for server installation.

Luckily, Linux is a highly configurable operating system, and this means that you can create the perfect audio platform just by making a few tweaks. We’ve chosen the latest version of Ubuntu to be our guinea pig.

Get a real-time kernel

The key to getting audio latency as low as possible is to remove all obstacles to a fast response time, and the place to start is with the kernel. The Linux kernel is made up of a series of modules that huddle together to form the monolithic chunk of functionality. Some of these modules are designed to provide super-low latency operation, but they can have unwanted side-effects for general computer use. As a result, these modules are rarely enabled by default.

These real-time kernel enhancements were introduced to the mainstream kernel several years ago, and together they can have a massive effect on how your system handles audio processing. Without the real-time enhancements, the kernel can respond to an interrupt within about 600 milliseconds. With the enhancements enabled, that time is reduced to around 20 milliseconds. Those numbers might seem minute, but they can have a dramatic effect on your audio latency when your system’s kernel is dealing with hundreds of interrupts a second.

We wouldn’t advise installing the real-time kernel enhancements onto a machine you need to rely on, though. They’re disabled simply because they’re unstable. Happily, however, both sets of the kernel can coexist within the same Linux installation: you simply choose which to use from the Grub boot menu.

In Ubuntu, the real-time kernel can be installed through the package manager just like any other addition. Search for ‘linux-rt’ and install both the main package and the ‘linux-headers-rt’ package that appear. Both of these packages, and the resulting dependencies, are from the Multiverse repository. This means that they’re unofficial and won’t be covered by any security patches, but they are actively maintained by a third party.

Install audio software

After the kernel has been installed, you will need to restart your machine. When you get to the brief Ubuntu boot menu, press [Escape] to get to the Options screen. From here, you can choose between your standard kernel (most probably labelled ‘-generic’) and the real-time version we’ve just installed (labelled ‘-rt’). Choose this and press [Enter] to boot into the real-time environment. This is the point where the new kernel may cause some problems. As it’s responsible for all of the hardware connected to your PC, everything will need to be re-detected. On our test machine, for example, the display’s native resolution wasn’t correctly detected and we needed to fix this manually. If you use proprietary drivers, such as those for Nvidia hardware, you will have to make sure that these have been reinstalled. Ubuntu’s package manager should have grabbed the restricted modules to do this automatically, but if not, you’ll need to install the driver manually.

Now that you’ve got a working low-latency desktop, it’s time to install the audio production environment. Ubuntu’s package manager makes this easy. Just search for ‘ubuntustudio-audio’ in Synaptic, and install the resulting package. This includes the cream of Linux audio software and gives you everything that you need to get started with your low-latency audio environment. After those packages have installed, there are a couple of housekeeping tasks to perform. First, load up the User Manager from the System menu, and add any user that you want to have access to the low-latency audio features to the ‘audio’ group. This should also include your user account. Secondly, add the following two lines to your ‘/etc/security/limits.conf’ file using administrator privileges:

@audio - rtprio 99
@audio - nice -10

When you’ve finished, restart your machine, and don’t forget to choose the real-time kernel from the Grub boot menu. It’s now time to play with some audio software.

Configure Jack

The tool at the heart of the Linux audio system is called Jack – the Jack Audio Connection Kit. Jack sits on top of the ALSA layer and dynamically pipes audio to and from a series of inputs and outputs. It’s a very clever solution to an age-old problem: routing audio input to your soundcard from one application to another before it makes its way to an audio output like your headphones or speakers. Jack does this without adding any latency. It’s been such a success on the Linux platform that you can now find it doing the same job on OS X.

Before we can dive into things, though, we need to get the service started. Jack runs as a background daemon, and you can use a GUI to control the connections to and from your hardware and software. The best software we’ve found for controlling Jack is Qjackctl, which is installed as part of the Ubuntu Studio package. Look for ‘Jack Control’ in the Multimedia menu. When the app appears, click on the ‘Setup’ button. Getting Jack’s set-up parameters right is often a matter of trial and error. Your settings will be different to ours, as they’re dependent on your specific audio hardware.

Make sure that the sample rate is compatible with your hardware. Most motherboard-based devices, and those from Creative and Asus, use 48,000Hz. Ensure ‘Real-time’ is enabled, as this was the reason for installing the enhanced kernel. Use the dropdown menu to the right of the ‘Interface’ field to select your audio device: this is normally going to be ‘hw:0’, ALSA-speak for the first device on your system. Finally, set the ‘Frames/Period’ size to 512. This is the size of the buffer used by Jack, and it has a direct effect on the audio latency of your system. The 512 setting works out at around 20ms from input to output, but you should be able to lower this when you’re sure that your system is working.

Save the configuration as a preset at the top of the window, then close the set-up window. Finally, when you get back to the main Jack Control window, click on the ‘Start’ button to start the background daemon running. If everything has been configured correctly, you should see a yellow ‘Started’ in the faux LCD panel, and you will now be able to start playing around with Jack. If you don’t see this word in the panel, click on the ‘Messages’ button to see a report of any launch errors.

Connect the apps

You’ve done the hard part, so now it’s time to put it to some use. Click on the ‘Connect’ button in Jack Control and you’ll see two panels in the Audio tab. The panel on the left lists the software and hardware sound generators, while the panel on the right lists the software and hardware outputs. At this point there is no other Jack software running, so under the system clients you should see only the hardware connections for your audio device.

To rectify this, look for an application called ‘Zynaddsubfx’ in your Multimedia menu. This is a rather excellent software synthesizer cunningly disguised by a silly name and dodgy UI. If you’ve still got Jack’s Connect window open when Zynaddsubfx launches, you’ll see an additional node in the output panel appear. This will connect its output to your soundcard’s direct output on the right-hand side. Click on the ‘VK’ button in the Synth window, and a virtual keyboard will appear. Press a few keys on this and you’ll hear a sound, hopefully with very little latency. Congratulations: you’re now using a real-time kernel and the Jack Audio Connection Kit to generate sound.

Get recording

To build a production environment, you’ll need to run a piece of audio workstation software that can manage all of these components. There are two widely used applications on Linux. Rosegarden is a KDE application that can record both audio and MIDI, and it can also use the new DSSI open-source synthesiser standard. However, our favourite is Ardour, a comprehensive recording environment that has more in common with Pro-Tools than Cubase. Ardour works exclusively with Jack to create a studio environment in software. If you launch the app from the Multimedia menu and create a new project, you’ll see the Jack connection window spring into life. Every track, effects send and audio bus in Ardour uses Jack. This is initially overwhelming, but it does mean that you’re free to use Ardour as you would a multitrack recorder in a studio, routing and re-routing audio between your various devices.

To record output from Zynaddsubfx, right-click in the lower part of Ardour’s main window and add a stereo track. Open the Jack connection window, select the two outputs from the synth and the two system output ports that they’re connected to, and click on ‘Disconnect’. Now connect each synth output to ‘Audio/In1’ and ‘Audio/In2’ under the Ardour client in the right panel. These are the two channels of the stereo track that we just created. Press the ‘Record enable’ button in the Ardour track followed by the big record and play buttons on the transport control, and play something on the synth. Ardour will now record the digital audio output from the synth, and you should be able to see some of this setup’s amazing potential.

Excellent article. Very informative.

Perfector's picture

Excellent article. However, with the following two sentences, it highlights one of the main reasons I'm not using a Linux based system for serious audio. "We wouldn’t advise installing the real-time kernel enhancements onto a machine you need to rely on, though. They’re disabled simply because they’re unstable."

I absolutely need to rely on my PC to record/produce audio. Unfortunately, Linux doesn't seem to be quite ready enough yet. Although many will disagree, I'm sure. I've tried various distros for serious audio, but keep having to fall back to Windows. I do use Ubuntu (and have done since Feisty) for my daily, non-audio PC use, though, and love it.

bloodorange's picture

So what do you use? I often need to use a PC to record real time audio and I've had windows flake out on me countless times in the past. The realtime Linux kernel isn't stable but I'm a bit concerned that nothing is.

(Perhaps I should use my Mac?)

Alex Cox's picture

I have been doing audio production on my system (Kubuntu 9.04) without the RT kernel, and the performance has been quite sufficient. I'm using kernel 2.6.30, and Jack runs in realtime mode just fine. I usually run Jack at 256 frames/sec, (10.7 msec) without problems. I don't have a monster machine, either (AMD 64 4000+ single-core, 2GB RAM). I've read somewhere that some of the RT kernel's features have been making it into the mainstream kernel, so the need for a dedicated RT kernel is becoming less and less. Currently, my Kubuntu install with standard kernel outperforms my old PCLinuxOS 2007 install with RT kernel.

S. Christian Collins's picture

I've moved from XP to Windows 7 RC1 on which I use REAPER (awesome). Windows 7 works absolutely fine and is completely stable, and to be fair XP was good, too. I am careful about what else I install on it, though; it's totally dedicated to music production.

Windows 7 is a fine OS. Although, I still prefer Ubuntu (in fact Mint at the moment!) for general day to day use.

bloodorange's picture

I'll have to check out REAPER, thanks for the tip.

I have a machine dedicated to audio production at the moment. Unfortunately it's a machine with 1GB RAM, a stupid hypermemory graphics card, and Windows Vista.

Must do something about that.

Alex Cox's picture

I recently priced out the different Linux vendors for RT audio studio systems. eRacks was pretty much the only one I found that did dedicated systems, and their STUDIO laptop/desktop offering made me drool. Their stuff is plenty expensive, though.

I settled on a pretty fast (non-eRacks) workstation along with which I purchased an m-audio sound card, a 25-key USB MIDI controller with a bunch of knobs, and some nicer speakers. Jack runs great, and I've got tons of inputs/outputs to work with. I can map the knobs on the controller to just about any parameter in e.g. LMMS and have lots of fun.

It's pretty amazing to explore the different possibilities out there in Linux audio land. But unless you're buying a pre-installed hardware/software combo, you need to be pretty patient and your needs have to be a little bit deeper than "I want something that I don't have to fiddle with."

That's fine with me - I've learned *tons* more about music and sound already than I ever learned on a Windows-based production system. So in my case it was worth the trade-off.

I'm thinking of purchasing something like Renoise, since I used to use trackers a lot. But the FOSS stuff seems to be getting deeper and better, fast. I'm afraid I might regret a commercial software purchase.

Marc's picture

Nice article. I never personally had any problems recording with the standard kernel that comes with Linux Mint. Although, I did need to manually adjust (or rather set up - just one time) the latency in Audacity when I first did multi-track recording.

Leke's picture

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p>

More information about formatting options

CAPTCHA
We apologise for making you prove your humanity...
Find out about the latest issue