Hack13.Mix Your Audio for Perfect Sound


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:


Master

This option controls the master volume for the sound card. The master volume overrides the volume levels for all of the other controls, and muting it or moving it to the lowest level will effectively mute all other sound controls.


PCM

You will likely use this control as often if not more often than the master volume control. The PCM (Pulse Coded Modulation) control sets the volume level for the /dev/dsp device on the system, which most audio programs output to. You would use this control if you wanted to change the volume for your media player, for instance. Use PCM instead of the master volume to control the volume for these devices so you don't inadvertently change the volume for the other controls on your sound card. For example, you might want to keep your microphone at the same volume, but increase the volume of your speaker. Changing PCM leaves the mic levels where they were before, but changing the master volume affects both the speaker and the microphone.


Speaker

This controls the volume for the speaker built into the PC. On a Linux system, you might want to use this control to change the volume of the system beep your terminal makes.


Line

The Line works as the master volume for the line-out port(s) on your sound card. Each line-out port also has its own volume control that is numbered starting from one, so a sound card with a single line out would also have a Line1 control.


Mic

The mic control manages the volume of your microphone and will often be muted by default so that any noise it picks up will not interfere with any other sound output on the system.


CD

On systems with CD-ROM drives that have been connected to the sound card with the audio-out cable, this control will manage the volume of the CD player.


PhoneIn/PhoneOut

These controls allow you to change the volume for the phone-in and phone-out ports (often RCA jacks on the back of computer) on your sound card. Fancier sound cards sometimes have these jacks available to connect to other AV equipment.

In addition to the above options, if you use ALSA you will find a number of other controls in an ALSA-capable mixer applet such as alsamixer. These controls let you access more advanced features of your sound card, but note that the presence of a control in the mixer doesn't necessarily indicate that the feature actually works! Here are some of the common options you might see:


Master Mono

This option is muted by default, but if it is enabled, it will make all audio monaural instead of stereo and control the volume of that monoaudio source.


Headphone

Present on some laptops, this option allows you to control the volume level on the headphone jack without affecting the volume of the speakers.


3D Control

This option is muted by default, but allows you to enable surround sound if your card supports it.

You do not necessarily have to use an ALSA-compatible mixer if you use ALSA, provided you enable the ALSA OSS compatibility layer, specifically OSS mixer compatibility. With OSS mixer compatibility, OSS mixers will still have access to the basic volume control options, but will not be able to change some of the more advanced options your sound card may provide.


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.

Table 2-1. Common aumix command-line arguments

Argument

Function

-v

Main volume

-b

Bass

-c

CD

-i

Igain

-l

Line

-m

Microphone

-o

Line out

-p

PC speaker

-s

Synthesizer

-t

Trebel

-w

PCM

-x

Imix

-1

Line 1

-2

Line 2

-3

Line 3


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.




Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
EAN: N/A
Year: 2005
Pages: 156

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