Chapter 8. Utilities

Native ALSA-Utils

Package dependancies: Make sure that you have installed the alsa-lib-0.5.xx package before you install the alsa-utils.0.5.xx package

This chapter describes the use of the programs found in the alsa-utils-0.5.x packages, namely:
amixer

Command-line basic mixer application for ALSA.

alsamixer

GUI Mixer application.

aplay

Native command-line ALSA sound file player.

arecord

Command-line recording application.

Utils:-Native

"Native" means that they use ALSA's own way of interacting with the sound card instead of OSS calls. Thus they will work without the snd-*-oss compatibility modules, and make use of ALSA specific feature such as {GURUS STEP FORWARD ! :}.

Compilation: The ALSA-Utils need both the driver and the libraries package. If you haven't both of them built and installed correctly, the compilation will fail. Follow the Instructions in the INSTALL file.

amixer

amixer is the basic mixer application for ALSA. It is very flexible and works with every possible sound-card, but its handling is "very" old-school and nothing for the faint-of-heart. Adventure seekers can have a look at the amixer manual page to find out more .

alsamixer

For the average user, I suggest using a front-end like alsamixer (text mode) or gamix for X11. These programs use the functions of amixer but provide a nice graphical interface that lets you see and modify all channels at one glance.

Enter alsamixer at the prompt, and you will see a bunch of sliders made of #'s. Use the Left and Right cursor keys to select a channel and Up and Down to change the volume. Note that every channel has two switches: Mute and Capture (sometimes called Record). You can toggle them with the M and the SPACE keys. The capture flag works like a radio button: it cannot be unset, but when you select another channel and press SPACE, it moves there.

Before you start playing sound, you should do the following:

  1. Set the volume on your external speakers to zero.

  2. UN-mute Master, CD, Line In, MIC, PCM, and Input Gain.

  3. Raise the Master and the source faders to 100%, Input Gain to about 50%

You can then try to play some sound. Increase the volume at your speakers to a comfortable level.

Now it's time to try and record something. Hook up a microphone or an external source. If you don't have any of those, put a CD into the CD-ROM drive and start a player. Depending on the source, select Capture on MIC, Line In or CD. Call arecord (see below). After that, play back the recorded file with aplay. If the volume is too soft and there is a lot of hiss, increase the Input Gain, if there is distortion, decrease it. You may have to do this a couple of times to find the best setting. When everything works, you can mute the channels you don't need. This will reduce hiss. Use the channel faders to match the individual levels.

aplay

aplay is a native ALSA sound file player. Type aplay -h for a list of the options. There is also a manual page available. The general usage is

aplay yourfile.xxx

.

Normally aplay will detect the file format like .wav, .au or .raw automatically and start the correct playing routine. You can specify a format using command line parameters if the detection fails.

If no filename is given, aplay reads sound data from stdin (STanDard INput), which can be useful in some cases. cat prints a file to stdout (STanDard OUTput), and can be redirected to stdin, so you can enter:

cat yourfile.xxx | aplay

This does the same as the first example. A more useful application is given in the next paragraph.

arecord

arecord is the recording counterpart. Again,arecord -h yields a list of command line options, and there is a man page. A typical invocation is

arecord -m [new file.wav]

The parameter - m tells the program to record CD-Quality audio, which is two-channel 16 Bit with a sampling frequency of 44100 Hz.

You can specify the duration of the record using the -t secs option. Alternatively,you can press Ctrl-C to stop the program. If you choose the second method, however, the size entry in the file header will be incorrect. This is normally not a problem and can be fixed using a sound file editor like mxv.

Note: Similar to aplay, arecord will write the audio data to stdout when no filename is given. With full duplex sound-cards, there is a way to shorten the Input Gain setup procedure mentioned in the mixer section above: Enter

arecord yourfile.xxx | aplay

What happens here is: arecord records sound and writes it to stdout. Without the pipe sign | all the sound data would end up on your console as garbage characters. Try it ! Now with the pipe, the sound ends up as input for aplay and gets played back. The important difference to playing back the input signal directly is that it travels through the analog/digital converters, gets digitized and converted back to analog. You will notice a slight lag of about 0.5 secs compared to direct replay.

The digitizing stage is the place where distortion occurs. So listen to the sound being recorded and tune the Input Gain on the fly until you have the loudest possible signal without fuzz.

You may have noticed that arecord is not a real program file, but a symbolic link to aplay. In fact, the program has aplayboth the playback and the recording code. The name you use to start it is passed on to the code like a command line option, and the program then knows whether to execute the play or the rec section. This avoids duplicate code, because both share many internal functions.