From Fedora Project Wiki

< User:Crantila‎ | FSC

Revision as of 19:56, 11 July 2010 by Crantila (talk | contribs) (changed category to draft documentation)

DocsProject Header docTeam1.png
Warning.png
This page is a draft only
It is still under construction and content may change. Do not rely on the information on this page.

Address: User:Crantila/FSC/Sound_Servers

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

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

PulseAudio is an advanced sound server, intended to make audio programming as easy as possible, especially in Linux. The idea behind its design (I THINK?!) is that an audio application needs only to output audio to PulseAudio, and PulseAudio will take care of the rest: choosing a particular device, and the output on that device, adjusting the volume, 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.

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

JACK offers many of the same features as PulseAudio, but with an emphasis on allowing the settings required by professional audio applications. As it always seems to be with computers, added features means added complexity: the user actively chooses various settings and modes, allowing for use in a wide variety of settings. Programming with JACK is still easier than using ALSA, however, because it is not the software application's responsibility to correctly configure JACK, but the user's responsibility. Thankfully, programs such as QjackCtl make it easy to choose the best settings for your setup.

Another benefit of JACK is the ability to "route" audio and MIDI signals from any JACK-aware source to any JACK-aware input (or "sink," as it's known). QjackCtl offers a visual interface where these connections can be modified on the fly. Furthermore, PulseAudio has the capability to both provide input to, and take output from, a JACK sound server. This is not PulseAudio's default behaviour, but it can be configured easily by following these instructions.

!!

Phonon

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 hugely advantageous.

Using JACK

Installing JACK

  1. From a terminal, run sudo -c 'yum install jack-audio-connection-kit qjackctl', or use PackageKit or KPackageKit to install the "jack-audio-connection-kit" and "qjackctl" packages.
    • Note that the "qjackctl" package is optional, but it provides a graphical method to easily control JACK, and is highly recommended.
  2. Approve the installation.
  3. Run QjackCtl from the KMenu or Applications menu
  4. to start JACK, press "Start"; to stop it press "Stop."
  5. Use the "Messages" button to see messages, usually errors or warnings.
  6. Use the "Status" button to see various statistics.

Further Configuration

JACK will operate without following this procedure, but for security reasons, users are strongly encouraged to follow these three steps. They will help to allow optimal performance of the JACK sound server.

  1. Add yourself, and anybody who uses JACK, to the "audio" group (for help see Fedora 12's Deployment Guide, Chapter 22... ?!)
  2. Planet CCRMA's version of JACK automatically enables real-time priorities. To make it safer, edit '/etc/security/limits.conf' so that the final lines read:
 @audio - rtprio 99
 @audio - memlock 4194304
 @audio - nice -10
  1. If you are not using PlanetCCRMA's JACK version, then write those lines in!

This additional configuration will help to ensure that JACK will always choose the right sound card. If you have only one sound card, it is unnecessary. If you have a USB sound card, then this method should not be used; rather, you should confirm that the right sound card is selected by QjackCtl every time that you start JACK.

  1. Run 'cat /proc/asound/cards' to see a list of sound cards in your system, and choose the one you want by name
    1. Identify the sound card that you wish to use.
    2. Look in the square brackets [ ] to see the name that you will need to use (for example, "SB").
  2. In QjackCtl, press the "Setup" button.
  3. In the "Interface" field, input the name of your preferred sound card as hw:SB, where "SB" is replaced by the name in brackets of your preferred sound card. While it is possible to refer to the sound cards by number, they may not always receive the same number every time the computer is started. Using the name in brackets will ensure that the same card is always selected.

Integrating PulseAudio with JACK

In standard Fedora Linux systems, when JACK is started, it will take control of the audio devices from PulseAudio. PulseAudio will not be able to input or output any audio signals while JACK is running. This is fine for users who only occasionally use JACK, but for users who want to blend JACK and PulseAudio, or who frequently switch between the two, it is not acceptable. The following instructions will help you to integrate JACK with PulseAudio: all of PulseAudio's input and output will be routed through JACK.

  1. In a terminal, run sudo -c 'yum install pulseaudio-module-jack', or in PackageKit or KPackageKit, install the "pulseaudio-module-jack" package.
  2. Edit the file "/etc/pulse/default.pa" to add the following:
load-module module-jack-sink
load-module module-jack-source
    • These should be added underneath #load-module module-alsa-sink
                                                                               .wodniw lanimret a ni >edoc/<oiduaeslup llallik>edoc< gnitucexe yb oiduAaesluP tratseR #


!!

Integrating PulseAudio with JACK

  1. run 'yum install pulseaudio-module-jack'
  2. edit '/etc/pulse/default.pa' to add:
 load-module module-jack-sink
 load-module module-jack-source
 ** I did it just underneath the commented-out #load-module module-alsa-sink, etc.
  1. Restart PulseAudio
    1. run 'killall pulseaudio' ????then 'pulseaudio &'????
 -- OR --
    1. Restart the computer
  1. Confirm that it works by opening QjackCtl
    1. The display should already say "Active"
    2. In the "Connect" window, on the 'Audio' tab, there should be PulseAudio devices on each side, and they should be connected to "system" on the other side.
  2. Open QjackCtl's "Setup" window, then go to 'Options' tab, then uncheck "Execute script after Shutdown: killall jackd", so that JACK remains running, for use with PulseAudio, after QjackCtl is closed.
  3. When PulseAudio starts JACK, it uses the the command found in '~/.jackdrc', and QjackCtl automatically updates that (if it doesn't then edit it yourself)
  4. If you use a very high sample rate, then PulseAudio uses a lot of CPU power


  • must refer to kernel/system optimization section