September 28, 2006

Making music with Fedora Core 5

by Michael Tiemann


-->

I never promised you a rose garden--that was somebody else. However, I have just succeeded in making my laptop an Audio and MIDI workstation using Rosegarden, and I managed to do it all this morning, just before lunchtime. If that sounds promising, read on.

Linux has been a fantastic platform for all sorts of really cool projects, products, and applications, from web serving and web services to genomic sequencing and cataloging to embedded systems development and deployment to all manner of systems monitoring and modeling from the subatomic to the supergalactic. In other areas, such as audio, video, and 3D graphics, Linux has been handicapped, which is a shame, because the content world needs innovation just as much as the scientific, medical, communications, and information systems worlds do. Nevertheless, some courageous people have shown their commitment to ensuring that software freedom is available to those who wish to compose and play, not only those content to read and hack.

In February 2003, the British publication Sound on Sound gave a very positive review of the AGNULA project, which I first saw demonstrated in Paris the previous year. In that article, Daniel James wrote:

The AGNULA project is creating what is possibly the first computer system tailored specifically for musicians -- and it's all based around the Linux operating system.

And props to him for researching, publishing, and referencing www.gnu.org in an article aimed at music professionals (i.e., people who spend, or at least dream of spending, thousands of Great British Pounds on little things like microphones, preamps, equalizers, mixing boards, A-to-D convertors, D-to-A convertors, etc.).

When I first saw AGNULA, I enthusiastically asked the French engineers who had put it together to give me a demonstration of the software--maybe I could run it at home. They answered in the negative: "we wrote the software but we don't really know how to use it because we're hackers, not musicians." Sigh.

If I had been unhappy with my job, it would have been a perfect opportunity to roll up my sleeves and try to bring some experience to the problem. But I loved my job and knew that I could not devote the time it would take to make a real impact.

Want to see your comments in print? Send a letter to the editor.

One challenge with the AGNULA project was that in late 2002 there was no general purpose Linux distribution that had low enough latency to run serious audio applications. Such applications must be able to read, process, mix, and output dozens of audio tracks without dropping one of the 88,200 16-bit samples per second that's required to make CD-quality stereo sound, or without dropping one of the 96,000 or 192,000 24-bit samples per second that's required to make DVD-quality sound. (Or, put another way, a one millisecond hiccup could leave nearly 88 samples of stereo CD audio lying on the ground or drop over 500 samples of DVD surround audio.) At that time there were some competing attempts to achieve a low-latency kernel: Robert Love's premption patches and Andrew Morton and Ingo Molnar's "low latency" patches. None were upstream, though, and each had vociferous detractors. A core tenet of the AGNULA project was that they would apply technical force to whatever happened to be the operative issue, be it the audio framework, the audio applications, the device drivers, the driver layer, or the Linux kernel itself. This approach was open source at its best, but it also meant that observers needed dedicated hardware to follow the project, because there was no telling what an experimental kernel could do to one's system.

A challenge I myself faced was that the AGNULA project chose to favor distributions and toolkits that were not, as a Red Hat executive and user, natural to me. I don't fault them for making the decisions they did, but it meant that it would be very difficult for me to "watch" the AGNULA project they way I could "watch" other projects that were packaged and tested on Red Hat.

So I watched the AGNULA project from afar, and I watched as other audio applications began to take root and flower. One of these was Rosegarden, a UNIX-based sequencer that predated Linux, but which benefited tremendously by the rapid growth of the Linux audio community. In the same article that introduced AGNULA, Rosegarden provided the lead screenshot and this introduction:

Rosegarden is a MIDI + Audio sequencer which includes notation and audio editing. Version 4 [which is now 4-1.2.3 -- editor] is probably the closest native equivalent to Cubase for Linux, and has recently been released as a beta after two years of active development.

The comparison to Steinberg's Cubase is intended as very high praise, as Cubase has a very loyal following among its users. The article continues:

Software engineer and musician Richard Bown comes from London, and is one of the lead developers on the Rosegarden project. He's been working on Rosegarden over the last seven years, but until recently he still needed to use Windows or a Mac to record and produce his music. While making his last album, Richard wondered if Rosegarden would one day allow him to do the same on Linux, and now believes it can.

Well, it's now about three years after that prediction was made, and the good news is that as of June 2006, it's bog-easy to set things up on an FC5 laptop and prove it for yourself.

And, it is timely, too. When Apple announced that they'd be dropping the PowerPC processor and switching to Intel, I knew this would mean that many thousands of music production professionals would be reevaluating their hardware platform of choice for audio recording, mixing, and mastering. I saw more and more people starting to talk about Linux in professional audio newsgroups. When I attended FISL 7 in Porto Alegre earlier this year I bumped into Georg Greve (of the FSF Europe) and talked about AGNULA, its progress, and the prospect of making Fedora a first-rate platform for free audio software. But what really told me we had reached critical mass was when I saw Greg De Koenigsberg flipping through the audio products catalog of a major mail-order house trying to decide which micrphones to buy for a new podcasting studio we're setting up in Raleigh. He told me that there were now yum-based repositories for Rosegarden and other audio software. I was ready to try it out for myself.

Installation of Planet CCRMA

The first stop is either the Rosegarden site itself or the first place to which it directs Fedora users, Planet CCRMA (pronounced cc:Karma). Planet CCRMA has basically become the home for the forked low-latency kernels needed to run audio applications as well as RPM packages of those applications themselves. Now until FC5, these kernels and packages were not for the faint-of-heart. But with FC5, and with a lot of good merging work that was completed in early June, it appears that audio on Linux is ready to become a mainstream feature.

The instructions for installing on FC5 are here and begin with the reassuring promise: "Installing Planet CCRMA is easy."

Here are the steps, adapted from Planet CCRMA page:

  1. Install FC5.

  2. Install the GPG signature key for Planet CCRMA.

  3. Configure Yum to include the Planet CCRMA repos.

  4. Synchronize with the repository.

  5. Install the low-latency kernel (not as scary as it used to be).

  6. Reboot and make sure everything's happy.

  7. Configure soundcards (which was automatic for my T41 Thinkpad).

  8. Update FC5 to the latest.

  9. Tune the system (which I haven't yet done, but might in future if needed).

  10. Install some applications: yum install qjackctl fluidsyth fluid-soundfont qsynth rosegarden4 should do the trick. A repository view of these applications can be found here but I prefer to follow the "Applications/Multimedia" link to this location.

  11. Adjust your volume (make sure that PCM Playback is enabled) using System->Preferences->Volume Control from the main GNOME menubar. (n.b.: If you are using an IBM T41 Thinkpad like I am, you may have to also ensure that the sound is not muted or over- or under-amplified via the audio hotkeys in the upper left hand side of the keyboard. It boggles my mind that there are two completely independent mechanisms for muting audio and that one is invisible to the other, but there you have it.)

Working with the audio applications

Now we're ready to rock! To play MIDI, we need a MIDI file. I'm using this one, but you can use anything you like.

Step One: Start jack. Jack is an acronym for "jack audio connection kit." The jack server is the application that allows all of the other audio applications to talk with one another, which is why it must be started first, as follows:

qjackctl -s &

Make sure jack is active by clicking the green "start" arrow if it hasn't started by default.

Under Settings, I prefer to change the sample rate from 48000 to 44100. Isn't 48000 higher quality than 44100? Well, if you are ultimately trying to create audio for CD, doing everything in 44100 is going to save you from sample-conversion errors later in the process, and it will take less CPU power, space on disk, etc. If you are making content for DVD distribution, stick with 48000. But trust me, if CD is your target, don't waste your time and confuse yourself with a non-native sample rate (unless it's 88.2K, 2x the 44.1K rate).

Step Two: Start fluidsynth via qsynth. Qsynth is the synthesizer application that generates tones based on the midi data it receives, and the fluidsynth soundfonts determine what those tones will sound like. Start qsynth as follows:

qsynth -r 44100 &

The click the "Setup" button. Under the MIDI tab, change "ALSA Sequencer Client ID" from 'pid' to 'Qsynth1'. Under the Soundfonts tab, load the fluidsynth soundfonts. By default they install as /usr/share/soundfonts/FluidR3_GM.SF2, so open that file.

Step Three: start your sequencer and play a MIDI file. Now you're ready to start rosegarden, as follows:

rosegarden &

Next, open Manage MIDI Devices and make sure that 'General MIDI Device' is connected to 'Synth input port (Qsynth1:0)'. The connection number should be NNN:0 (where NNN is some number between 128 and 255).

Finally, import a MIDI file using File->Import, and hit the "Play" button is Rosegarden. You should hear qsynth rendering music to your speakers!

Step Four: Patch Jack for Audio Production. Now, to really prove that we know what we're doing, let's record the output of the softsyth so that we can produce an actual audio file. Such a file can be encoded into ogg format, uploaded to your favorite portable media player and enjoyed while your laptop recharges.

In the Jack window, open up the Connections window by pressing the Connect button. Connect the qsynth 'left' output to the rosegarden 'record in 1 L' input. Similarly, connect the qsynth 'right' output to the rosegarden 'record in 1 R' input. Connections are made by selecting the output and input and then pressing the 'Connect' button (no need to shift-click).

Step Five: Render MIDI to Audio. This is where we create the actual audio file. In rosegarden...

  1. Add a track by doing Tracks->Add Track.

  2. Change the track to an Audio track using RMB->Audio and then select an audio track (such as 'audio #1').

  3. Label the track. Double-click the <untitled> label and replace it with a sensible track name.

  4. Rosegarden needs to associate the audio track with an audio file. Using Composition->Edit Document Properties, select the Audio tab and choose an audio path. All your audio files will be stored in this directory.

  5. Click on the LED next to the audio track name; it should turn red when ready to record. If you've selected a non-existent directory, rosegarden will refuse to record until you fix this.

  6. Now, press the big red record button in rosegarden (no need to try to press play and record at the same time) and the audio track should turn red and grow as the music plays. When you've recorded enough, press stop. The audio track should turn green and a rendering of the soundwaves should appear.

If your levels are good, you should see something nice and spikey. If it looks like a black 2-by-4, it means you're clipping because your levels are too high, and that's going to sound bad. If your levels are too low, you won't have any sound waves getting near the edges of the audio file--which will also affect sound quality, especially at 16 bits per sample (less so for 24-bit and 32-bit samples). If you forgot Step Four, you'll just have a flat line, indicating you've recorded digital silence.

But this is just the beginning. You can connect a microphone and sample the dog. You can connect a keyboard and create your own MIDI files. You can connect external sound devices such as the Buchla 200e and create your own slice of analog heaven. And you can add plugins and effects.

Bugs and limitations

The fluidsynth-dssi package was promising, but its interface needs a few simple fixes. Software synthesizers need to know where to find their sound libraries. qsynth uses a proper file selection dialog box that accepts a directory name as a file name and then prompts from that directory. Thus it's easy to enter /usr/share/soundfonts/ and then pick the SF2 file you want. The dssi plugin uses a file selector widget that requres one to find this file the hard way: up to root, down to user, down to share, down to soundfonts (which is a pain since I have 238 entries in /usr/share) and then finally to the SF2 file. I could try to enter the whole path manually, but for a 16-track General MIDI file, that's a lot of typing, times 16! Worse, the dssi plugin doesn't respond to MIDI program change events, which means that I have to manually select the program file I want for each of the 16 tracks. Mousing through 256 selections times 16, when the patch info is already embedded in the MIDI file adds insult to injury. I'm sure this is just a mere matter of programming to fix.

It should also be noted that fluidsynth is not very smart when it comes to memory management: it loads the entire soundfont into memory whether one is using one patch or 16 (the typical maximum for MIDI). This is a problem for laptops limited to 512 MB of RAM: qsynth happily consumes over 200 MB of RAM just loading the default soundfont! Can somebody please make this "load-on-demand"?

While I'm talking about "nice to haves"... it should be possible to start these apps up in any order and for the servers and clients to all find each other by magic, but it doesn't work that way, at least not yet. Instead, I have to start jack first, then qsynth, then rosegarden, and this causes the right connections to happen in the right order with the right defaults (mostly). It would be cool if, when starting jack, jack could notice that there's a rosegarden running and sync with it. I imagine that this becomes even more important when plugins are involved. Programs I'm familiar with on the Macintosh platform go through a process of discovery upon startup, registering all possible plugins ahead of time so that they can be launched and managed from within the main sequencer application. As far as I can tell with Rosegarden, you have to know ahead of time what you're going to use, and bring it up or you won't be able to find it. Of course Rosegarden does let you save your work, so perhaps things will be easier when you come back to your work, but it would be nice if everything "just worked" from the beginning.

No login required. Want to see your comments in print? Send a letter to the editor.

Finally, you should not forget that "workstation" is a code word meaning "benefits from as much screen real estate as you can afford". On my 1024x768 laptop, I definitely feel cramped. But having this cool software working so well so easily is powerful encouragement to think about upgrading my hardware to at least 1280x1024 or beyond.

About the author

Michael Tiemann's first musical experience with computers was in 1974, when his father brought home "The Flight of the Bumblebee" encoded on paper tape and played it on an IMSAI 8080 computer running 4K BASIC. That was also the year his family bought a copy of "The Copper Plated Integrated Circuit", a seminal album of classic and modern music rendered on a Moog synthesizer. Michael then studied classical guitar for eight years, largely forgetting about the music/computer relationship until he founded Cygnus Support, and E-mu Systems became a GNUPro customer. He started buying all kinds of music toys, only to have them all stolen while he was promoting free software in Europe. He again put music on the back shelf until 2002, when he heard about the AGNULA project. Michael is delighted to see companies like Korg and Midas highlighting their use of Linux as the basis of their respective flagship products, and looks forward to the day when he can share music code and content as freely as he does other code and content.