How Computers Deal with Hardware Devices
One of the techniques consistently used in computer science is abstraction. Abstraction is the process of creating a generic model for something (or some things) that are actually unique. The "driver" for a hardware device in a computer is one form of dealing with abstraction: the computer's software interacts with all sound cards in a similar way, and it is the driver which translates the universal instructions given by the software into specific instructions for operating that hardware device. Consider this real-world comparison: you know how to operate doors because of abstracted instructions. You don't know how to open and close every door that exists, but from the ones that you do know how to operate, your brain automatically creates abstracted instructions, like "turn the handle," and "push the door," which apply with all or most doors. When you see a new door, you have certain expectations about how it works, based on the abstract behaviour of doors, and you quickly figure out how to operate that specific door with a simple visual inspection. The principle is the same with computer hardware drivers: since the computer already knows how to operate "sound cards," it just needs a few simple instructions (the driver) in order to know how to operate any particular sound card.
How Linux Deals with Audio: ALSA
In Linux, the core of the operating system provides hardware drivers for most audio hardware. The hardware drivers, and the instructions that other software can use to connect to those drivers, are collectively called "ALSA," which stands for "Advanced Linux Sound Architecture." ALSA is the most direct way that software applications can interact with audio and MIDI hardware, and it used to be the most common way. However, in order to include all of the features that a software application might want to use, ALSA is quite complex, and can be error-prone. For this and many other reasons, another level of abstraction is normally used, and this makes it easier for software applications to take advantage of the features they need.
Sound servers are software applications that run "in the background," meaning they are rarely seen by users. They are used to provide another level of abstraction - essentially to automatically take care of certain aspects of using ALSA, thereby making it easier for software applications to use the audio hardware. The three sound servers discussed in this guide have distinctly different goals, provide distinctly different features and capabilities, and should not be viewed as though one is universally better than the others.
PulseAudio is an advanced sound server, intended to make audio programming in GNU/Linux operating systems as easy as possible. The idea behind its design is that an audio application needs only to output audio to PulseAudio, and PulseAudio will take care of the rest: choosing and controlling a particular device, adjusting the volume, working with other applications, and so on. PulseAudio even has the ability to use "networked sound," which allows two computers using PulseAudio to communicate as though they were one computer - either computer can input from or output to either computer's audio hardware just as easily as its own audio hardware. This is all controlled within PulseAudio, so no further complication is added to the software.
The Fedora Project's integration of PulseAudio as a vital part of the operating system has helped to ensure that audio applications can "just work" for most people under most circumstances. This has made it much easier for users to carry out basic audio tasks.
JACK Audio Connection Kit
The JACK sound server offers fewer features than other sound servers, but they are tailor-made to allow the functionality required by audio creation applications. JACK also makes it easier for users to configure the options that are most important for such situations. The server supports only one sample rate and format at a time, and allows applications and hardware to easily connect and multiplex in ways that other sound servers do not. It is also optimized to run with consistently low latencies. Although using JACK requires a better understanding of the underlying hardware, the "QjackCtl" application provides a graphical user interface to ease the process.
Phonon is a sound server built into the KDE Software Compilation, and is one of the core components of KDE. By default on Fedora Linux, Phonon feeds output to PulseAudio, but on other platforms (like Mac OS X, Windows, other versions of Linux, FreeBSD, and any other system that supports KDE), Phonon can be configured to feed its output anywhere. This is its greatest strength - that KDE applications like Amarok and Dragon Player need only be programmed to use Phonon, and they can rely on Phonon to take care of everything else. As KDE applications increasingly find their place in Windows and especially Mac OS X, this cross-platform capability is turning out to be very useful.
!! What to say here depends on whether jack2 will be available with Fedora 14. If it is, no need for CCRMA solution. If it isn't, need for CCRMA solution. !!
Installing and Configuring JACK
- Ensure that you have installed the Planet CCRMA at Home repositories. For instructions, refer to this section.
- Use PackageKit or KPackageKit to install the "jack-audio-connection-kit" and "qjackctl" packages, or run the following command in a terminal:
sudo -c 'yum install jack-audio-connection-kit qjackctl'</code></li> <li>Review and approve the installation, making sure that it completes correctly.</li> <li>Run QjackCtl from the KMenu or the Applications menu.</li> <li>To start the JACK server, press the 'Start' button; to stop it, press the 'Stop' button.</li> <li>Use the 'Messages' button to see messages, which are usually errors or warnings.</li> <li>Use the 'Status' button to see various statistics about the currently-running server.</li> <li>Use the 'Connections' button to see and adjust the connections between applications and audio hardware.</li> </ol> JACK will operate without following this procedure, but users are strongly encouraged to follow these three steps, for security reasons. They will help to allow optimal performance of the JACK sound server, while greatly reducing the risk that an application or user will accidentally or malicious take advantage of the capability. <ol> <li>Add all of the users who will use JACK to the "audio" group. For help with this, see the !!Fedora 14 Deployment Guide, Chapter 22!!</li> <li>The default installation automatically enables real-time priority to be requested by any user or process. This is undesirable, so we will edit it. <ol> <li>Open a terminal, and run the following command: <pre>sudo -c 'gedit /etc/security/limits.conf'
- Be careful! You're editing this important system file as the root user!
- Edit the last lines, so that they read:
@audio - rtprio 99 @audio - memlock 4194304 @audio - nice -10
- In a terminal, run the following command:
- The command will output a list of sound cards in your system, similar to this:
0 [SB ]: HDA-Intel - HDA ATI SB HDA ATI SB at 0xf7ff4000 irq 16 1 [MobilePre ]: USB-Audio - MobilePre M Audio MobilePre at usb-0000:00:13.0-2The left-most number is the sound card's number. The portion in square brackets is the name (these cards are called "SB" and "MobilePre").
- Identify your desired sound card in the list. If it's not in the list, then it's not currently detected and configured by your system.
- Open the "QjackCtl" application, and press the 'Setup' button.
- In the "Interface" field, input the name of your preferred sound card with "hw:" in front. For example, with the sound card information posted above, you might write
- To save your settings, close "QjackCtl".
The QjackCtl application offers many more features and configuration options. The patch bay is a notable feature, which lets users save configurations of the "Connections" window, and restore them later, to help avoid the lengthy set-up time that might be required in complicated routing and multiplexing situations.
For more information on QjackCtl, you can refer to this web site.
Integrating PulseAudio with JACK
The default configuration of PulseAudio yields control of the audio equipment to JACK when the JACK server starts. PulseAudio will not be able to receive input or send output of any audio signals on the audio interface used by JACK. This is fine for occasional users of JACK, but many users will want to use JACK and PulseAudio simultaneously, or switch between the two frequently. The following instructions will configure PulseAudio so that its input and output is routed through JACK.
- Use PackageKit or KPackageKit to install the "pulseaudio-module-jack" package, or in a terminal run the following command:
su -c 'yum install pulseaudio-module-jack'
- Approve the installation and ensure that it is carried out properly.
- You'll need to edit the PulseAudio configuration file to use the JACK module.
- Be careful! You will be editing an important system file as the root user!
- Run the following command in a terminal:
sudo -c 'gedit /etc/pulse/default.pa'
- Add the following lines, underneath the line that says
load-module module-jack-sink load-module module-jack-source
- Restart PulseAudio by running the following command in a terminal:
killall pulseaudioIt will start again automatically.
- Confirm that this has worked by opening QjackCtl. The display should confirm that JACK is "Active".
- In the "Connect" window, on the "Audio" tab, there should be PulseAudio devices on each side, and they should be connected to "system" devices on the opposite sides.
- Open QjackCtl's "Setup" window, then click on the "Options" tab. Uncheck "Execute script after Shutdown: killall jackd". If you did not make this change, then QjackCtl would stop the JACK server from running every time the program quits. Since PulseAudio is still expecting to use JACK after that, you shouldn't do this any more.
- When PulseAudio starts JACK, it uses the command found in the
~/.jackdrcfile. QjackCtl automatically updates this file when you change settings, but you may have to restart both PulseAudio and JACK in order to get the new changes to take effect. If they refuse to take effect, you can edit that file yourself.
- Be careful about using a very high sample rate with PulseAudio, since it will tend to use a lot of CPU power.