Hack15.Play Multiple Sounds at the Same Time

Hack 15. Play Multiple Sounds at the Same Time

Play audio from multiple sourceseven if your sound card doesn't support it.

Most Linux users don't think too much about exactly how sound is mixed. On many sound cards, you can send only a single sound at a time. So, for instance, if you are playing an MP3, you won't be able to hear any desktop sounds you have configured, and your instant messenger won't audibly alert you to incoming messages. Although some sound cards can support mixing from multiple sources, many less-expensive cards and those integrated on motherboards don't, so as a result you need to use a sound server. A sound server, in effect, sits between your applications and the sound card, mixes the different sound sources, and presents a single source for output. The default sound server under KDE is aRts, and the default under GNOME is EsounD. This hack covers how to use and configure aRts and EsounD.

aRts (Analog Real-Time Synthesizer) is a system of modules used to synthesize audio. These modules can perform various audio tasks, such as adding audio effects, mixing, filtering, and a number of other things. The artsd sound server uses this system to mix audio from multiple sources in real time. Because it sits between the sound card and applications, an application must have aRts support to directly take advantage of the artsd server (there's a workaround if it doesn't, which I will talk about in just a bit). aRts is a core component of KDE (at least for the time being), so it is fully supported there, and a number of other media applications can use aRts as well, through the use of plug-ins.

EsounD (or Enlightened Sound Daemon) is a sound server like artsd. It sits between the sound card and programs accessing the sound card so that it can mix sounds and pass them along as output. Because of this, an application needs EsounD support to work with esd properly. Since GNOME defaults to using EsounD as its sound server, GNOME applications generally have EsounD support. EsounD has been around for some time, so there's a good chance that recent media applications (again, particularly those for GNOME) support EsounD either directly or through a plug-in.

Since KDE uses aRts by default, if your distribution packages KDE it should package aRts and, specifically, artsd. In fact, if KDE is already installed, you already have artsd installed (and it is probably running). Likewise, EsounD is packaged by most major distributions, particularly if they include GNOME, and the EsounD package should already be installed if GNOME is installed. You don't have to run KDE to use artsd or GNOME to use esd. Simply install the artsd or EsounD package included with your distribution to use it with your window manager or desktop application.

Generally, artsd and esd do not start when the computer starts. Instead they are launched by the desktop environment when it starts. If you use KDE or GNOME, this is taken care of for you; otherwise you will need to consult with the documentation for your window manager or desktop environment to learn how to start applications when the window manager is launched.

2.4.1. Configure aRts

aRts can be configured directly from the KDE Control Center, so launch the Control Center from the K Menu or, alternatively, type kcontrol in a terminal. Inside the Control Center click Sound & Multimedia Sound System to access the aRts configuration (see Figure 2-2). The first clue that artsd is running; if not, it isn't. That means if you do need to completely bypass artsd, you can disable it here. If you find that sound skips during playback, you might need to check the next option, Run, with the highest possible priority (realtime priority) and, optionally, increase the size of the sound buffer until the skipping stops.

I previously mentioned that artsd sits between the sound card and programs, so if you have it running, programs that directly access /dev/dsp won't work. The next option in the control center lets you automatically suspend artsd when it's idle. That way other programs can use the sound card directly once the timeout period has elapsed.

Figure 2-2. KDE Control Center aRts configuration

2.4.2. Configure EsounD

There isn't much configuration to be done with EsounD: essentially, you just need to be concerned with whether or not GNOME uses it. To check, launch the GNOME Control Center from a menu, or type gnome-control-center in a terminal. Then go to the sound section and check whether the sound server checkbox is checked.

2.4.3. Legacy Compatibility

Both aRts and EsounD provide another method of compatibility with legacy programs through artsdsp and esddsp, respectively. Certain programs, such as Quake, were programmed to access OSS and know nothing of Linux sound servers. What's more, games like this are no longer being developed, so it's unlikely support is going to be added in. The artsdsp and esddsp programs basically act as a wrapper around a program and intercept and process any sound card calls. The standard way to use artsdsp is:

 $ artsdsp  programname option1 option2 

Some programs, such as Quake, want to do direct memory mapping for sound, which artsdsp can emulate with the --mmap option To play Quake run:

 $ artsdsp --mmap quake 

The esddsp program acts in basically the same way, just type esddsp, then whatever program you wish to run, followed by its arguments:

 $ esddsp  programname option1 option2 

artsdsp and esddsp don't work for every program. For artsdsp, experiment with and without the --mmap options to see what provides the best results.

Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net