Hack 13. Mix Your Audio for Perfect Sound
Use the mixer to understand and tweak the different volume levels your sound card provides.
Almost every audio device you encounter has some way to control the volume, whether through a volume knob on a radio, the remote control on a television, or the series of controls on a sophisticated sound board. To control the sound on a Linux system, you use a mixer program. Even though the purpose of the mixerto change the volumeis simple, often the sheer number of options the mixer provides can prove daunting to new users: it's not as simple as adjusting a single master volume control. Also, Linux has two different systems for sound, OSS and ALSA, so there is additional complexity that is not immediately obvious. In this hack, I cover a few mixer programs and describe the differences among Master, PCM, and the other major volume controls.
You can launch a mixer program a few different ways. If you use the GNOME or KDE desktop environments, the quickest way to access the mixer is to click the speaker icon on the desktop panel. Windows users will find this applet similar to the speaker on the Windows taskbar. A single click on the icon lets you change the master volume (see Figure 2-1); a right-click shows you various options for the mixer applet. For common volume control, you may only need to access the master volume. To access all of the advanced volume controls, double-click on the applet to launch a complete mixer.
Figure 2-1. Panel Mixer applet
Whether you use OSS or ALSA sound drivers, you will find a base set of volume controls in a mixer application that are based on the default volume controls on the OSS mixer (/dev/mixer). OSS is the older of the two sound systems. As such, it is often more stable than ALSA, although a number of newer sound cards are only partially supported in their OSS drivers, if at all. OSS is still present in the latest Linux kernels, but ALSA is the preferred sound system, as it often provides more complete support for newer sound cardssomething you will notice in the different options you have in an ALSA-ready mixer. Whichever sound system you use, when you launch the mixer applet, you will see at least these basic volume controls:
2.2.1. Command-Line Mixer Applications
In addition to whatever mixer program your desktop environment provides, there are some basic command-line mixer programs you can use to access the same volume controls without using a mouse. Two common commandline mixers are aumix and alsamixer. aumix is an OSS mixer with some particularly useful features for scripting, and alsamixer is the default commandline mixer program for ALSA.
aumix provides you with access to the standard OSS mixer controls completely from the command line. If you type aumix at the command line with no arguments, you will enter its interactive mode, where you can use the up and down-arrow keys to switch between mixer controls and the left-and right-arrow keys to change the volume of the selected control. Hit the m key to toggle mute on a control, and press Tab or Enter to switch between the volume and balance controls for a device.
aumix really becomes useful with command-line arguments. All the different mixer controls are assigned an argument as listed in Table 2-1.
Each of these arguments can accept a number of options such as q to query the current level for the device, and + and - to increment and decrement the volume by a single level. You can also specify a particular volume level by using a number instead of + or -, or you can even follow + or - with a number to control how much to increment or decrement. For example, to set the master volume to 50%, increase PCM by ten and increase the line out by one, type:
$ aumix -v 50 -w+10 -o+
This functionality is particularly useful to bind aumix commands to key sequences so that you can mute your sound with a quick keypress, instead of mousing to a mixer applet. You might also find aumix handy if you schedule any audio programs with cron. aumix solves the problem of making sure that no one changes the volume on the computer between the time you set it and time your script runs. You can run an aumix command immediately before your command executes.