Welcome to Linux Support and Sun Help
Search LinuxSupport
Alsa-sound-mini-HOWTO: Testing and using Next Previous Contents

5. Testing and using

Now you should test if the sound driver really is available, then try to use it.

5.1 The /proc filesystem

You can find a lot of useful information about your system in the /proc subdirectory. /proc is a "virtual" filesystem, meaning that it does not exist in real life, but merely is a mapping to various processes and tasks in your computer. In order for /proc to work, you need to have support for it compiled into your kernel. Most linux distributions have this as a default, but if you compiled a kernel and left /proc out obviously there won't be anything in /proc.

/proc/modules gives information about loaded modules. Once the ALSA sound drivers are loaded, if you type cat /proc/modules you should see something like:

snd-pcm1-oss      4            0
snd-sb16          1            1
snd-sb-dsp        4    [snd-sb16]      0
snd-pcm1          4    [snd-pcm1-oss snd-sb-dsp]      0
snd-pcm           3    [snd-pcm1-oss snd-sb16 snd-sb-dsp snd-pcm1]    0
snd-mixer         3    [snd-pcm1-oss snd-sb16 snd-sb-dsp]      1
snd-mpu401-uart   1    [snd-sb16]      0
snd-midi          4    [snd-sb16 snd-sb-dsp snd-mpu401-uart]   0
snd-opl3          1    [snd-sb16]      0
snd-synth         1    [snd-sb16 snd-opl3]     0
snd-timer         1    [snd-opl3]      0
snd               8    [snd-pcm1-oss snd-sb16 snd-sb-dsp snd-pcm1 snd-pcm snd-mixer snd-mpu401-uart snd-midi snd-opl3 snd-synth snd-timer]    0
If something went wrong during the installation of the driver, you will still see a couple of "snd" devices, but there won't be sound support.

For example (Note: you should never issue this command as follows, the cs4236 driver needs options):

win3:~# modprobe snd-card-cs4236
/lib/modules/2.0.35/misc/snd-card-cs4236.o: init_module: Device or resource busy
snd-mixer: Device or resource busy
win3:~# cat /proc/modules
snd-cs4236        2           0
snd-cs4231        3    [snd-cs4236]    0
snd-timer         1    [snd-cs4231]    0
snd-pcm1          4    [snd-cs4236 snd-cs4231] 0
snd-mixer         3    [snd-cs4236 snd-cs4231] 0
snd-pcm           3    [snd-cs4236 snd-cs4231 snd-pcm1]       0
snd-mpu401-uart   1           0
snd-midi          4    [snd-mpu401-uart]       0
snd-opl3          1           0
snd-synth         1    [snd-opl3]      0
snd-timer         1    [snd-cs4231 snd-opl3]   0
snd               8    [snd-cs4231 snd-timer snd-pcm1 snd-mixer snd-pcm]     0
You can check the existence of a soundcard by looking in /proc/asound/cards. For example:
bash$ cat /proc/asound/cards
0 [card1          : SB16 - Sound Blaster 16
                    Sound Blaster 16 at 0x220, irq 5, dma 1&5
In the previous example (where I forgot the options) the output would have been:
win3:~# cat /proc/asound/cards
--- no soundcards ---
A working CS4236 card would produce
0 [card1         ]: CS4236 - CS4237B
                    CS4237B at 0x534, irq 7, dma 1&0
If you checked and doublechecked your settings and still see no sound card, take a look at the troubleshooting section.

The /proc/asound/ virtual directory shows lots of other information about the driver. Please note that /proc/asound/ will only exist after you inserted the first ALSA module. If there is no /proc/asound, it simply means that the "snd" module was not loaded properly. You can find installed cards in /proc/asound/cards, then find information about card0 in /proc/asound/0, /proc/asound/1 for card1 etcetera.

If cat /proc/asound/ shows something like

      ES1370 DAC2/ADC
      Playback isn't active.
      Record isn't active.
this means that your driver is ready to go, but is not doing anything right now. (So everything went well).

There is a third method to find information about the sound devices, namely if you inserted the OSS compatible driver there is a /dev/sndstat device. The ALSA drivers kindly request that you not to rely on this information as it is only there for compatibility with the OSS drivers and better information can easily be obtained from /proc/asound/.

5.2 The mixer

Once the drivers for your sound card have been installed and your /proc filesystem tells you so, you can try to make a real sound. First of all, install the utility package, or at least put the "amixer" command in some reasonable place (like /usr/local/bin). First look at the mixer settings by typing "amixer". The output from amixer can greatly differ from card to card. My Soundblaster 16 shows:

Master         0  % (-14.00dB) : 0  % (-14.00dB)
Bass           0  % (-14.00dB) : 0  % (-14.00dB)
Treble         0  % (-14.00dB) : 0  % (-14.00dB)
Synth          0  % (-62.00dB) : 0  % (-62.00dB)
PCM            0  % (-62.00dB) : 0  % (-62.00dB)
Line-In        0  % (-62.00dB) : 0  % (-62.00dB) Mute
MIC            0  % (-62.00dB) : 0  % (-62.00dB) Mute
CD             0  % (-62.00dB) : 0  % (-62.00dB) Mute
In-Gain        0  % (-18.00dB) : 0  % (-18.00dB)
Out-Gain       0  % (-18.00dB) : 0  % (-18.00dB)
PC Speaker     0  % (-18.00dB) : 0  % (-18.00dB)
My Crystal 4237B based soundcard has a lot of other options:
Master D       0  % (-22.00dB) : 0  % (-22.00dB) Mute
3D Center      0  % (-22.50dB) : 0  % (-22.50dB)
3D Space       0  % (-22.50dB) : 0  % (-22.50dB) Mute
Synth          0  % (-94.50dB) : 0  % (-94.50dB) Mute
FM             0  % (-94.50dB) : 0  % (-94.50dB) Mute
DSP            0  % (-94.50dB) : 0  % (-94.50dB) Mute
PCM            0  % (-94.50dB) : 0  % (-94.50dB) Mute
Line-In        0  % (-34.50dB) : 0  % (-34.50dB) Mute
MIC            0  % (-22.50dB) : 0  % (-22.50dB) Mute
CD             0  % (-34.50dB) : 0  % (-34.50dB) Mute
Record-Gain    0  % (  0.00dB) : 0  % (  0.00dB)
In-Gain        0  % (-18.00dB) : 0  % (-18.00dB)
Loopback       0  % (-94.50dB) : 0  % (-94.50dB) Mute
Mono           0  % (-45.00dB) : 0  % (-45.00dB) Mute
Aux A          0  % (-34.50dB) : 0  % (-34.50dB) Mute
You have noticed the "Mute" entry, the CS4237B even mutes the master channel. For the CS4237B, I would have to type amixer "master d" unmute to even be able to produce any sound at all. The Soundblaster does not have muted output, but amixer master 100 unmute would set the volume to 100% and unmute the master. You can use a number, a word like "mute" or "unmute", or both. Type amixer "master d" 100; amixer pcm 100 unmute to set the CS4237B card to maximum master volume and unmute PCM volume and set it to maximum. For separate L/R settings you use a colon, for example amixer CD 25:50. (No, I don't know which one is the left or right channel, but let me emphasize that this also depends heavily on the position of your speakers)

You would set the CD channel to record by typing amixer cd rec and stop the recording setting again by typing amixer cd norec. If you would like to record something from the microphone, you would probably use amixer record-gain 100; amixer mic 100 rec mute. (Using the microphone input unmuted will produce loud high-pitched sound if your mic picks up its own signal from the speakers again). Unfortunately I have not been able to change the volume of the "3d center" and "3d space" settings with amixer. If anyone succeeds please let me know. You can use alsamixer for this job.

The ALSA FAQ says that it is possible to restore mixer settings with cat <file> > /proc/asound/#/mixerC0D0, where <file> was obtained from /proc/asound/#/mixerC0D0. I have not been able to reproduce this as my system complains about non-existing devices.

5.3 The /dev/snd/ devices

The alsa drivers have native sound-devices in the /dev/snd/ directory. If you have one card you might see the following devices:

/dev/snd/pcmC0D0 - the raw audio device for the card
/dev/snd/mixerC0D0 - the mixer for card 0
/dev/snd/controlC0D0 - the control device for card 0
The first number means the number of the soundcard, the second number (if any) is the number of the device. A sound card with two PCM devices would have a pcmC0D0 and pcmC0D1 device. Please note: the ALSA devices have changed between the previous version. Older ALSA drivers use /dev/snd/pcm00 (first number is the card, second number is the device). If this HOWTO uses the older notation, please drop me a line so I can correct it.

Now you are ready to put any soundfile you want into the PCM device of the first card. So try to cat any textfile (any file) to /dev/snd/pcmC0D0, like this: cat <filename> > /dev/snd/pcmC0D0. The filename can be any file, as long as it has some length. If you have a soundfile lying around somewhere, you could try that. You could also get the file at http://www.ldp.org/sounds/english.au this is Linus Torvalds saying how to pronounce Linux.

The default setting of your sound device is 8000 Hz, 8 bit. That means that the "english.au" file mentioned above will produce speech, other test files will probably just produce noise. If you do not hear anything, check your speakers, try to run "amixer" again or consult a doctor. (Later on you can easily use the full 48 KHz, 16 bit features of your sound card, by using your favourite sound player like sox or mpg123).

If you loaded the "snd-pcm1-oss" module, you can also use the OSS-compatibility to access your sound card. The following mappings are made:

/dev/snd/pcmC0D0 -> /dev/audio0 (/dev/audio) -> minor 4
/dev/snd/pcmC0D0 -> /dev/dsp0 (/dev/dsp) -> minor 3
/dev/snd/pcmC0D1 -> /dev/adsp0 (/dev/adsp) -> minor 12
/dev/snd/pcmC1D0 -> /dev/audio1 -> minor 4+16 = 20
/dev/snd/pcmC1D0 -> /dev/dsp1 -> minor 3+16 = 19
/dev/snd/pcmC1D1 -> /dev/adsp1 -> minor 12+16 = 28
/dev/snd/pcmC2D0 -> /dev/audio2 -> minor 4+32 = 36
/dev/snd/pcmC2D0 -> /dev/dsp2 -> minor 3+32 = 39
/dev/snd/pcmC2D1 -> /dev/adsp2 -> minor 12+32 = 44

5.4 Additional information

The INSTALL file in the ALSA driver directory mentions some tricks to tell the driver which settings to use. If you need these commands it will depend on the application you use to play sound. Regular sound playing applications, like mpg123, sox (mostly called with the ``play'' command), or X11 applications like RealPlayer will probably do fine without these. I never used these anyway.

/proc/asound/#/pcm#0

"Playback erase" - erase all additional informations about OSS applications
"Playback <app_name> <fragments> <fragment_size> [<options>]"
"Record erase" - erase all additional informations about OSS applications
"Record <app_name> <fragments> <fragment_size> [<options>]"

<app_name> - name of application with (highter priority) or without path

<fragments> - number of fragments or zero if auto

<fragment_size> - size of fragment in bytes or zero if auto

<options> - optional parameters

WR_ONLY - if application tries open pcm device with O_RDWR driver rewrites this to O_WRONLY (playback) - good for Quake etc...

Examples:

echo "Playback x11amp 128 16384" > /proc/asound/0/pcm0o
echo "Playback squake 0 0 WR_ONLY" > /proc/asound/0/pcm0o

/proc/asound/#card#/sb16

"Playback 8" -> driver will use always 8-bit DMA channel for playback.
"Playback 16" -> driver will use always 16-bit DMA channel for playback.
"Playback auto" (default) -> driver will use auto mode (first opened direction will use 16-bit DMA channel).
"Record 8" -> driver will use always 8-bit DMA channel for record.
"Record 16" -> driver will use always 16-bit DMA channel for record.
"Record auto" (default) -> driver will use auto mode (first opened direction will use 16-bit DMA channel).

Example: echo "Record 16" > /proc/asound/0/sb16

For further reference, please consult the INSTALL file.


Next Previous Contents
Valid HTML 4.01! Valid CSS!