Updated: 2008-01-23
Created: 2004-08-14
Licensing and disclaimer of warranty
This document is an incomplete draft.
These notes are about configuring the Linux ALSA sound subsystem components (in particular the ALSA drivers and the ALSA library), and not about installing the various bits of ALSA.
These notes have some limitations, mostly due to my limited experiences, and my reluctance to include hearsay (but I do sometimes):
Unless you are a UNIX/Linux developer don't even try to compile and install the various ALSA components yourself, unless you feel really lucky: just use the precompiled packages provided by your distribution for the kernel, kernel drivers, libraries and applications. You have been warned.
Takashi Iwai has a nice diagram that illustrates the structure of ALSA.
/proc/asound
kernel interface/dev/snd
device interfaceSound cards come in a wide variety of types, with rather different internal organization.
All however are based on a chipset
, and ALSA
drivers are designed for chipsets, or even for families of
similar chipsets, not specific cards.
However most chipsets are customizable, and when used in a card some of their capabilities may be omitted or somewhat modified.
Cards usually have at least some of these logical components:
IRQ, some IO
portsand possibly a memory range.
Mic boost
in the mixer, is often of
terrible quality.Some important design principles of the ALSA
kernel
modules:
/dev/
tree, and a status and configuration interface via entries
in the /proc/asound/
tree./dev/
contains
three main types of devices, PCM devices for
recording or playing digitized sound samples, CTL
devices that allow manipulating the internal mixer and
routing of the card, and MIDIdevices to control the MIDI port of the card if any. There may be also sequencer devices if the card has a builtin sound synthesizer, and timer devices to help in using the sequencer.
Master Volume
.A card may have multiple PCM devices, but the main one is always PCM device 0, and as a rule it is for analog multichannel sound. Additional PCM devices may exist for digital (IEC958, SPDIF) sound (usually device 2), or for additional channels (usually device 1), for example for the side speakers in a 7.1 card.
PCM devices come in two varieties: output and
input. MIDI devices are output only, and so are
sequencer devices. Whether a device is input or output is from
the point of view of the process using the ALSA
driver. An output device is one to which the process can
write/send sound samples, and an input one is one from which
it can read/receive sound samples.
Then the sound card has input or output sockets,
and the mixer, which is controlled via the
CTL
device, routes sound samples from/to the
PCM (or MIDI, sequencer) devices and the sockets, or among the
devices.
Sound samples are written from a process to an output device
to the mixer, and then usually routed to an output socket, and
are read by a process from an input device usually associated
with an input socket, but sometimes associated with the mixer.
Mixers therefore contain input and output routes; but they
also contain copy (loopback) routes, which duplicate sound
samples from a device to another; for example some copy routes
take the sound samples written to an output device (or socket)
and copy them to an input device, for example allowing to
record the sound output of a process; some copy routes take
the sound samples read from an input device (or socket) and
copy them to an output device, for example allowing monitoring
of what is being recorded via a microphone.
Usually input devices have associated capture controls in the mixer, and output devices have playback controls. Copy routes are implicit in the presence of both capture and playback controls for the same device; if an output device has both capture and playback mixer controls, there is an output-to-input copy route for it, and viceversa.
When queried, the control interface of an ALSA card
can return a list of controls for it. The command
amixer scontrols
prints a simplified list, and
amixer controls
prints the full list, and
amixer contents
prints the full lists with the
current and possible values of each control.
There are three types of controls:
Cards differ greatly in the availability of devices and
features, and of device or feature controls. For example some
have a distinct copy route for every input or output device,
some have only one (often called Capture
) that can
be used only for one selected device; some can record from
multiple input devices at the same time, some only from one
selected input device. Some have volume controls for the copy
routes independent of the volume of the subdevice being looped
back, some don't.
For example a microphone socket may correspond to an input device with a capture control, and a copy route (of the input-to-output type) with a playback control. The capture control will have a capture switch and a volume level to enable recording and set the volume of the recording; the playback control will have an unmute switch to enable monitoring recording, and a volume level to set the monitoring volume.
As an example of a feature, some cards have a 3D spatializer; this can be represented by three controls, one with just a switch to enable or disable the spatializer, and two level controls, where the level of one control is the 3D depth, and the level of the other control is the degree of spatialization.
The most typical example of a feature control however is
the Master Volume
control; this allows
controlling the internal amplifier feature of the card.
Output devices don't necessarily allow playing aribtrary types of sound samples; most are limited in both the range of frequencies and formats of the sound samples, as well as in the number of channels in those samples.
When multichannel sound samples are written to an ALSA output device, every ALSA driver uses the same logical (in the sample) to physical (as to sockets) channel assignments.
This sound samples must contain these logical channel assignments for the samples to be correctly positioned by the drivers for stereo and 4.0 surround playback:
With 4.1 surround, channel 4 is the LFE, also called subwoofer, channel.
With 5.0 surround, channel 4 is the center channel.
With 5.1 surround, channel 4 is center, and channel 5 is the LFE/subwoofer.
With 7.1 surround, channel 6 is side left, and 7 is side right.
The assignment of sound channels to device channels might
be reshaped, if appropriate, by using the multi
plugin in copy
mode, or as appropriate for lower or
higher numbers of channels.
/proc/asound
kernel interfaceFor now just this (slightly edited) snippet from Takashi Iwai:
/proc/asound/cards (RO) the list of registered cards /proc/asound/version (RO) the version and date the driver was built /proc/asound/devices (RO) the list of registered ALSA devices (major=116) /proc/asound/hwdep (RO) the list of hwdep (hardware dependent) controls /proc/asound/meminfo (RO) memory usage information this proc file appears only when you build the alsa drivers with memory debug (or full) option so the file shows the currently allocated memories on kernel space. /proc/asound/pcm (RO) the list of allocated pcm streams
/proc/asound/dev/ the directory containing device files. device files are created dynamically; in the case without devfs, this directory is usually linked to /dev/snd/ /proc/asound/oss/ the directory containing info about oss emulation /proc/asound/seq/ the directory containing info about sequencer /proc/asound/cardX/ (X = 0-7) the card-specific directory
/proc/asound/oss/ info about OSS emulation the contents of the files under this directory are changed dynamically. when no oss emulation modules (snd-pcm-oss, snd-mixer-oss) are loaded, no pcm nor mixer devices will be listed. /proc/asound/oss/devices (RO) the list of devices already registered /proc/asound/oss/sndstat (RO) /dev/sndstat compatible list
/proc/asound/cardX/ card-specific proc files id (RO) the id string of the card ac97#? (RO) AC97 codec information ac97#?regs (RO) (printable) register dump midi? (RO) the current of input/output on the rawmidi device pcm?p the directory of the given pcm playback stream pcm?c the directory of the given pcm capture stream pcm stream information pcm??/info (RO) the pcm stream general info (card, device, name, etc.) pcm??/oss (RO) oss emulation info (shown only when the pcm is opened as an oss device). pcm??/sub? the substream information directory pcm??/sub?/info (RO) the pcm substream general info (card, device, name, etc.) pcm??/sub?/status (RO) the current of the given pcm substream (status, position, delay, tick time, etc.) pcm??/sub?/hw_params (RO) hw_params set-up on the substream (buffer size, format, etc.) pcm??/sub?/sw_params (RO) sw_params set-up on the substream (threshold, etc.) pcm??/sub?/prealloc (RW) the number of pre-allocated buffer size in kb. you can specify the buffer size by writing to this proc file: # echo 128 > /proc/asound/card0/pcm0p/sub0/prealloc to allocate 128kbyte for playback, substream #0, stream #0 on the card #0.
/dev/snd
device interfaceFor now just this snippet from Takashi Iwai:
device files under /proc/asound/dev/ (or /dev/snd/) generally the file is named as aaaCxDy, where aaa is the service name, x the card number (0-7), y the device number (0-). controlC? control devices (i.e. mixer, etc.) hwC?D? hwdep devices midiC?D? rawmidi devices pcmC?D?p pcm playback devices pcmC?D?c pcm capture devices seq sequencer device timer timer device
/usr/share/alsa/alsa.conf
,
/usr/share/alsa/
,
/etc/asound.conf
and ~/.asoundrc
.asound.conf
.asound.conf
Basic syntax, macros, external native code functions, runtime execution hooks.
This document comes with an extensive, generic, commented
sample
asound.conf
.
Some aliases are conventional, in that their use is part of convention:
dsp0
is used by XMMS and the
aoss
script, unless changed by using the
ALSA_OSS_PCM_DEVICE
environment variable.default
is used if no specific device name
is used by an application other than XMMS and
aoss
.From /usr/share/alsa/alsa.conf
it looks like
there are the following classes of device names:
defaults
: pcm
: ctl
: rawmidi
: seq
: hwdep
: timer_query
: timer
: NAME | Default value | Notes |
---|---|---|
defaults.ctl.card |
0 |
|
defaults.pcm.card |
0 |
|
defaults.pcm.device |
0 |
|
defaults.pcm.subdevice |
-1 |
|
defaults.pcm.front.card |
defaults.pcm.card |
|
defaults.pcm.front.device |
defaults.pcm.device |
|
defaults.pcm.rear.card |
defaults.pcm.card |
|
defaults.pcm.rear.device |
defaults.pcm.device |
|
defaults.pcm.center_lfe.card |
defaults.pcm.card |
|
defaults.pcm.center_lfe.device |
defaults.pcm.device |
|
defaults.pcm.surround40.card |
defaults.pcm.card |
|
defaults.pcm.surround40.device |
defaults.pcm.device |
|
defaults.pcm.surround41.card |
defaults.pcm.card |
|
defaults.pcm.surround41.device |
defaults.pcm.device |
|
defaults.pcm.surround50.card |
defaults.pcm.card |
|
defaults.pcm.surround50.device |
defaults.pcm.device |
|
defaults.pcm.surround51.card |
defaults.pcm.card |
|
defaults.pcm.surround51.device |
defaults.pcm.device |
|
defaults.pcm.iec958.card |
defaults.pcm.card |
|
defaults.pcm.iec958.device |
defaults.pcm.device |
|
defaults.rawmidi.card |
0 |
|
defaults.rawmidi.device |
0 |
|
defaults.rawmidi.subdevice |
-1 |
|
defaults.hwdep.card |
0 |
|
defaults.hwdep.device |
0 |
|
defaults.timer.class |
2 |
|
defaults.timer.sclass |
0 |
|
defaults.timer.card |
0 |
|
defaults.timer.device |
0 |
|
defaults.timer.subdevice |
0 |
and the following default device names:
These PCM names are shorthands for the similarly named plugin on the current card:
pcm.hw
: pcm.plughw
: pcm.plug
: pcm.dmix
: pcm.dsnoop
: pcm.shm
: pcm.tee
: pcm.file
: pcm.null
: and pcm.default
is the default PCm device
and it is mostly equivalent to pcm.plug
, so
as to provide by default rate and format conversion. It
contains references to the ALSA_CARD
,
ALSA_PCM_CARD
and
ALSA_PCM_DEVICE
environment variables.
These PCM names are shorthands for common device names:
pcm.cards
(cards.pcm
)pcm.iec958
and pcm.spdif
(cards.pcm.iec958
) define the default
IEC958/SPDIF output device.pcm.front
(cards.pcm.front
)
pcm.rear
(cards.pcm.rear
)
pcm.center_lfe
(cards.pcm.center_lfe
) name the front, read
and center (or subwoofer) channel groups.pcm.surround40
(cards.pcm.surround40
),
pcm.surround41
(cards.pcm.surround41
),
pcm.surround50
(cards.pcm.surround50
),
pcm.surround51
(cards.pcm.surround51
) define the
4.0/4.1/5.0/5.1 channels output devices.ctl.hw
: ctl.shm
: ctl.default
: rawmidi.hw
: rawmidi.default
: rawmidi.virtual
: seq.default
: seq.hw
: hwdep.hw
: hwdep.default
: timer_query.hw
: timer_query.default
: timer.hw
: timer.default
: From the config files:
ALSA_CARD
ALSA_CTL_CARD
ALSA_PCM_CARD
ALSA_PCM_DEVICE
ALSA_HWDEP_CARD
ALSA_HWDEP_DEVICE
ALSA_IEC958_CARD
ALSA_IEC958_DEVICE
ALSA_RAWMIDI_CARD
ALSA_RAWMIDI_DEVICE
ALSA_FRONT_CARD
ALSA_FRONT_DEVICE
ALSA_CENTER_LFE_CARD
ALSA_CENTER_LFE_DEVICE
ALSA_REAR_CARD
ALSA_REAR_DEVICE
ALSA_SURROUND40_CARD
ALSA_SURROUND40_DEVICE
ALSA_SURROUND41_CARD
ALSA_SURROUND41_DEVICE
ALSA_SURROUND50_CARD
ALSA_SURROUND50_DEVICE
ALSA_SURROUND51_CARD
ALSA_SURROUND51_DEVICE
From libasound.so
:
ALSA_CONFIG_PATH
ALSA_ORDINARY_MIXER
From aoss
:
ALSA_OSS_PCM_DEVICE
ALSA_OSS_DEBUG
General principles:
daemonlike aRts or ESoundD: even if ALSA has an OSS compatibility mode it is more limited than the native ALSA API, and the ALSA library supports software sharing and rate and format conversion, thus making sound servers redundant inasmuch they are used for those purposes.
There are some other notes here and here.
plugin, then use CTRL-P to get the preferences panel, and in
Audio I/O Plugins
select the Output
Plugin
called ALSA
1.x.y output plugin
[libALSA.so]
.
Configure
once the ALSA plugin has been selected,
and either select a particular audio device, or type a name, in
the Audio device:
field. Remember to select the
corresponding Mixer card
number too.libao
libao
is a library used by many sound
applications like for example
mpg321
.
The default sound system for it can be configured by creating
or editing the file
/etc/libao.conf
and ensuring it contains the line
default_driver=alsa09
./etc/openalrc
, which is not awesomely documented,
but there is something in the Info file for OpenAL
(info openal
)
in the chapter The openal configuration file, and here is a suitable example:
(define devices '(alsa sdl arts esd native null)) (define alsa-device "dsp0") (define speaker-num 2) ;(define sampling-rate 22050)
SDL_AUDIODRIVER
which
should be set to alsa
, and
AUDIODEV
or SDL_PATH_DSP
which
should be set to the name of the ALSA audio device, usually
default
or dsp0
.mpg321
or the proprietary
mpg123
-o alsa09
select the ALSA
0.9.x/1.x sound system API, and
-a
dev selects the device. As to
devices try -a plughw:0,0
or -a dsp0
for example. Since both use libao
for sound
output you can configure the default sound system as in the
libao
notes.gmplayer
.
-ao alsa:device=
device to select an
ALSA device, usually as -ao alsa:device=dsp0
.
-channels 4 -ao alsa:device=surround40
or -channels 6 -ao alsa:device=surround51
if supported by your card.
-A alsa
to select the ALSA output plugins, or equivalently set
audio.driver:alsa
in
~/.xine/config
and append
:device=
dmix0 to select a
specific output device. Also check a number of
settings beginning with
audio.device.alsa_
in
~/.xine/config
.--aout alsa
to select ALSA output,
and --alsadev
surround51
to select a specific device. aoss
wrapper). Similarly for most
Mozilla and Firefox
plugins.TODO
TODO
Available input modulespage, an example (the details on that page):
<input> <module>alsa</module> <param name="rate">44100</param> <param name="channels">2</param> <param name="device">plughw:0,0</param> <param name="periods">2</param> <param name="buffer-time">500</param> <param name="metadata">1</param> <param name="metadatafilename">/home/ices/metadata</param> </input>
-a alsa
option to artsd
, and use the
-D
to select a specific output device, if you are
starting artsd
on its own.
Control
Center
, Sound & Multimedia
and
Sound System
. Having done this if you wan to run
aRts you click on Enable the sound system
in the
General
tab.
Hardware
tab
. Under Select the audio device
choose
Advanced Linux Sound Archictecture
. Normally you
can enable Full duplex
as ALSA supports it, and
most cards allow it.
Use
custom sampling rate
and select 48000Hz
,
probably even if the ALSA library is configured to support
resampling itself.
Override device location
and put the ALSA device
name (for example dsp0
or hw:0,0
) in
the corresponding field. With cards that do not support
hardware mixing make sure to specify the virtual PCM device
name that uses the asym
, dsnoop
and
dmix
plugins. Usually this should be called
something like dsp0
for the same of programs that
use that name by default, so try that.libesd0
package supports
OSS and libesd0-alsa
supports ALSA.
timidity -oS -iA
is good,
where -oS
select as output an ALSA PCM, and with
-iA
Timidity becomes an ALSA soft sequencer. More
context in a
RoseGarden FAQ.snd_pcm_writei short write: 3763 out of 4096and the only reliable workaround is to switch to the OSS driver API with
quake4 +set s_driver ossThis workaround should no longer be necessary starting with the 1.3 patch.
When ALSA drivers get loaded they assume a particular order that influences which card become device number 0, 1 and so on. Device number 0 is the default one, and it is often desired to make a specific card to have device number 0.
It is not always easy to guarantee a particular order of loading of modules, because in modern Linux distribution there are several independent module loading programs that operate according to different principles.
The only reliable way to achieve this is to assign to
all cards an explicit device number with the
index=
module parameter (as also described in
this page).
To record sound one must enable the relevant capture
controls. Since different cards can have very different
mixers, which ones are relevant depends a lot on the
card. It is best to explore the various channels and
controls using alsamixer
and pressing
F5 to see the full set of capture controls.
Despite the wide variation in mixers, there are some common types and names of controls:
Mic
or
Line In
also have a playback control and a
volume control that allows routing their input to the output,
that means that their input can be routed to the output,
which allows monitoring what is being recorded.PCM
or
Synth
also have a capture control that allows
routing their output into the input, which enables recording
what is being played.Capture
channel usually that
must be set in capture mode enabled for any
recording to happen. If other channels, for example
Line In
can be set in capture mode that is to
allow to control which input channels are mixed into the
input channel.Mix
channel that can be set in
capture mode that must be set to allow recording of sounds
being played. Usually if this channel exists there are no
capture controls on individual output channels, and the
complete mix of all output channels is recorded.Probably each card needs a bit of experimenting to figure out the roles of the various channels and their controls. These can be rather unobvious.
Once the capture mode has been selected, one can use some
kind of recording application, for example arecord
,
selecting the right recording device. This can be usually a
direct specification like hw:0,0
(for the analog
recording device) or a virtual device name defined in an
asound.conf
file like dsp0
; in the
latter case it must be defined as a dsnoop
plugin
or an asym
plugin.
With most cheap microphones out there one usually has to
enable the (usually low quality) internal input amplifier by
unmuting a suitable channel, usually called
Mic Boost
.
In most recent low cost chipset recording can only be done at
a single fixed rate, usually 48000Hz, or at one of two fixed
ones, usually 48000Hz and 44100Hz. If you want a different
frequency you can resample after recording or use the
plug:
prefix on the name of the chosen recording
device (or plughw:
if it is a hw:
device). For example:
arecord -D plughw:0,0 -f S16_LE -c 2 -r 22050 record.wav
Note that achieving good a good quality recording can be very difficult or impossible; for example some SoundBlaster Live! cards resample even at their native rate.
This can be achieved in several ways:
Line In
socket.alsamixer
and one has to press
F5 to see all the capture controls.
Sometimes output-to-input routing is done globally
with a capture control associated with a single
channel, usually called Mix
.file
plugin
(possibly in conjuction with the copy
plugin) to route the output of an ALSA application
to a file.Takashi Iwai has written some important notes on OSS emulation.
In general OSS emulation relies on either the OSS compatibility
devices, or the
aoss
wrapper
that redirects sound to the ALSA devices instead.
This wrapper defaults to using the dsp0
virtual
PCM defined in the ALSA library configuration. This can be
changed by setting the ALSA_OSS_PCM_DEVICE
environment variable. The ALSA_OSS_DEBUG
can be set
to enable some debugging messages.
A newer and somewhat more flexibile and complex method is
oss2jack
which creates some virtual OSS devices that are fronts for the
JACK.
sound server.
Some common issues:
lsof | egrep '/dev/(sound|dsp|mixer)'If there are applications listed that still use the OSS interface, please configure them to use the ALSA interface.
O_NONBLOCK
option is given to
open
(2). This can be worked around either
by using the
aoss
program,
oss2jack
,
the non-block
configuration directive, or the
nonblock_open
options of the
snd-pcm-oss
modules.mmap
modemmap
mode, thus
bypassing the ALSA library. Check the mmap
related options in the
/etc/asound.conf
file syntax, and the direct
and
disable
options to the OSS compatibility
PCM device control device, for example
/proc/asound/card0/pcm0p/oss
./proc/asound/card0/pcm0p/oss
.The major applications that still only support OSS are Mozilla and Firefox and the Flash and Java browser plugins, and several older games.
But newer versions of the Flash plugin also support EsounD, which is far preferable in most situations as it allows for sharing.
It is often desirable to be able to share a sound card among several processes running at the same time.
This requires the ability to mix the sound outputs of those processes into a single stream, that is multiplexing.
In order to achieve this with ALSA there are several different cases and techniques.
The cases depend on whether the sound card/chipset supports hardware mixing or not, and whether the processes access the sound card/chipset via the ALSA library, a sound server or OSS emulation.
In the beginning OSS often did not support sharing even if it was
supported by the hardware. ALSA drivers, as a rule, will support
sharing if the hardware supports it. The ALSA library supports
sharing even if the hardware does not support it, but this
requires some explicit configuration. For applications that use
OSS, the aoss
wrapper can make them use ALSA
instead, which improves things.
Finally applications that use sound servers like EsounD, polypaudio, aRts, or JACK. most sound servers perform software mixing and support ALSA output.
The individual cases are:
This is the best case. Most recent cards support hardware mixing, at least for output, and when they do they support it to up to a maximum number of streams that is so high that it is unlikely to be ever a problem.
If you can the simplest way to ensure sharing is to get a card that supports hardware mixing. Sound cards are cheap, often costing less than the time to implement workarounds.
In this case, it is fairly to create an ALSA library
configuration file (see the .asoundrc
documentation
at OpenSrc.org
and
at ALSA-Project.org)
that allows software mixing. This is achieved using the
dmix
(for output) and
dsnoop
(for input) plugins, and
asym
to tie them together.
In ALSA library version 1.0.9rc2 and later versions this is
already done in the standard configuration files.
There is an example of using them below, and a much more extensive, ready-made, nearly universal 1 or 2 card configuration file that you can most often just drop-in and it will work here.
Sound servers were mainly created to premix multiple streams for OSS, where even cards that supported hardware mixing did not support multiplexing.
If your system runs a sound servers like EsounD, for GNOME or aRts, for KDE, set the sound server to use ALSA as its output, and applications to use the sound server.
For KDE aRts problems see:
here
and try using artsdsp
to make OSS applications
use aRts instead. But it is probably preferable to make them
use ALSA directly by using
aoss
.
Some applications cannot use ALSA or a sound server, but only
the OSS API. In that case you can often make them use ALSA using
the
aoss
wrapper. Also check these
these notes
and check careflly the description of non blocking options in
these other notes.
# The top level shared pseudo device, with both PCM and CTL interfaces # The device names "default", "dsp0", "mixer0" have conventional meanings. # The top level shared pseudo device, with both PCM and CTL interfaces # The ALSA default is "!default", but many programs like XMMS and aoss # assume "dsp0" as default name for PCM and "mixer0" for CTL. # Amazingly, XMMS has problems if one defines 'pcm.dsp0' to be # 'plug' for 'pcm.asym0' and not directly as 'asym0'. pcm.!default { type plug; slave.pcm "dmix0"; } ctl.!default { type hw; card 0; } pcm.dsp0 { type plug; slave.pcm "dmix0"; } ctl.dsp0 { type hw; card 0; } ctl.mixer0 { type hw; card 0; } ######################################################################## # Buffering (period time defaults to 125000 usecs). # Size of period, expressed either in usec or byte units: # period_time USECS # period_size BYTES # Size of buffers, expressed either in period, usec, or byte units: # periods PERIODS # buffer_time USECS # buffer_size BYTES # The ALSA docs have examples with 'period_time' set to 0, # when 'period_size' and 'buffer_size' are used instead, # but this can cause trouble in later releases of ALSA. # For OSS compatibility, 'period_size' and 'buffer_size' # should be powers of 2. Also, many cards cannot accept # a 'period_size' much greater than 4096, so 4096 is safe. # On my VIA 8233A, any value for 'period_time' greater than # 85333 usecs (precisely!) causes hiccups in sound output. # Why? At 48kHz, 85333 usec are are just over 4096 bytes/channel. pcm.dmix0 { type dmix; ipc_key 13759; slave.pcm "hw:0,0"; slave.channels 2; slave.rate 48000; slave.period_size 4096; slave.buffer_size 16384; slave.period_time 84000; slave.buffer_time 340000; # Map only the first two channels bindings.0 0; bindings.1 1; }
To the output only example add:
# The top level shared pseudo device, with both PCM and CTL interfaces # The ALSA default is "!default", but many programs like XMMS and aoss # assume "dsp0" as default name for PCM and "mixer0" for CTL. # Amazingly, XMMS has problems if one defines 'pcm.dsp0' to be # 'plug' for 'pcm.asym0' and not directly as 'asym0'. pcm.!default { type asym; capture.pcm "dsnoop0"; playback.pcm "dmix0"; } ctl.!default { type hw; card 0; } pcm.dsp0 { type asym; capture.pcm "dsnoop0"; playback.pcm "dmix0"; } ctl.dsp0 { type hw; card 0; } ctl.mixer0 { type hw; card 0; } ######################################################################## pcm.asym0 { type asym; capture.pcm "dsnoop0"; playback.pcm "dmix0"; } pcm.dsnoop0 { type dsnoop; ipc_key 13758; slave.pcm "hw:0,0"; }
This defines a virtual ALSA PCM device called
asym0
. This device is capable of mixing several
playback streams and sharing one capture stream amongst
several applications. To get automatic samplerate
conversion, etc, we defined the device dmix0
which uses alsa's plug plugin.
Furthermore we defined a device called
!default
. This is equivalent to
dsp0
. The special name !default
makes this device the default device for all well coded ALSA
apps (sadly not too many are well coded).
And last we defined a device called dsp0
. This
device is used by the aoss
script from the
alsa-oss
package.
First of all we test this basic setup with the standard
ALSA aplay tool. You will need a .wav
file for
this test. If you have none, create one out of an MP3 with
the following command:
mpg123 name.mp3 -w name.wav
With this .wav
file we test the
dsp0
device now:
aplay -D dsp0
name.wav
This should playback the .wav
. Even if you run
this command in a second terminal at the same time, because
the dsp0
device does the mixing. Because we
also defined the default alsa device !default
to use asym0
, you should also be able to run
the command without the -D dsp0
parameter:
aplay name.wav
Not all apps honour the default device though. MPlayer for example is one of them.
To test this setup with MPlayer use:
mplayer -ao alsa1x:dsp0 name.avi
So, now is the time to test all your desired alsa apps to work with this setup.
dsp0
.If some ALSA apps behave badly with dsp0
(crackles, stutter), check the
dmix
plugin configuration page.
It has quite a bit of troubleshooting. Tips: look at the
samplerates of the slave, maybe play with the period_size
parameter, etc.; in particular many cards have limits on the
period_size
, usually to 4096 bytes.
Some applications use mmap
'ed audio data
transfer. If your application complains about not being able to
use mmap, then play around with the mmap_emulation
setting in the pcm.dsp0
definition.
Some applications and/or some cards will simply not work in
mmap
mode, so try disabling it.
ALSA.OpenSrc.org
site.Unfortunately many sound chipsets are poorly designed or plain buggy, or are used in sound cards that are themselves poorly designed or buggy, and both can happen at the same time.
Even more unfortunately, some of these poorly designed or buggy chipsets or cards are very popular and end up in most systems.
Also note that chipset or card related issues do not necessarily happen in every system using them; they can depend on the motherboard chipsets or the sound hardware plugged into the card or even on the quality of ground of the power system of the area in which the card and the PC are used.
Usually the best way to solve any chipset or card related problems or limitation is to buy another one, as there are fairly decent and cheap soundcards around, and they usually cost much less than the time and effort required to investigate and work around chipset or card specific problems.
However be warned that some sound problems are caused by environmental and electrical issues, and they will happen with all chipsets and cards until the underlying causes are fixed.
As a rule it is important to read carefully the driver module
documentation in the
ALSA-Configuration.txt
file in the Linux kernel sources and the ALSA driver sources,
read the related page on the
ALSA Project/
and
ALSA Wiki
pages for the specific chipset or card.
This
generic asound.conf
will probably work with most recent chipsets on motherboards and
on low end sound cards and fix a number of annoying problems if
you use the dsp0
device. Study it carefully.
All these said, here are some notes on some popular chipsets and cards:
snd-intel8x0
driver is being
constantly updated as new variants appear. Many such variants
differ in the way their mixers are set up or other
details.include/linux/pci_ids.h
in recent kernel
sources), and up to 1.0.8 only the one with device id
8086:266e
is recognized. More may be added
with time, so check the latest 2.6 kernels and ALSA
driver packages for 2.4.snd-hda-intel
driver, which is only available from ALSA 1.0.9,
or with kernels later than 2.6.11; an earlier
version of this driver, from ALSA 1.0.8, was
called snd-azx
.model=
module parameter.snd-intel8x0
driver module, in particular the
ac97_clock
, ac97_quirk
and
dxs_support
ones. They are described in the
ALSA-Configuration.txt
file in the Linux kernel sources and the ALSA driver
sources. For many variants of the ICH it is
essential to specify the appropriate
value for the model=
driver parameter.ac97_clock=48000
,
and to set the output plugin's sampling rate accordingly
in the /etc/asound.conf
.ac97_clock
parameter, and reading the chipset specific notes in the
ALSA-Configuration.txt
file in the Linux kernel sources and the ALSA driver
sources.
Capture
channel. The volume
controls associated with the specific channels control the
copy, not the input, volume; the input volume is
controlled by the volume of the Capture
channel.
Capture
channel control whether
recording is done at all, and is a toggle, not a selector.snd-ens1371
driver
module. They have neither software sharing nor, usually, a
hardware synthesizer.recentlychanged name to
snd-ca0106
and also supports the SB Live! 24 bit.snd-emu10k1
driver
module, and most of the description related to the SB Live!
range applies to them too.snd-emu10k1
driver module, but some newer
cards share the name but not the chipset.snd-ca0106
driver.snd-emu10k1x
driver.extin
and
extout
parameters to the
snd-emu10k1
driver module.
Also, you can do AC3 pass-through with a little mixer
firmware update as described
here.softvol
plugin
for /etc/asound.conf
.Now for completeness some popular chipsets or cards that I know of and that usually work nicely and without much trouble, but may have some small issues:
CMI8738 is a pretty decent chipset supported by the
snd-cmipci
driver, which works well and easy to
configure, has a fairly uncomplicated set of mixer controls,
and is available as very cheap PCI cards and on some
motherboards as the built in sound chipset.
aplay -l
device 0 is the
first DAC, 1 is the second DAC, and 2 is the IEC958
output. The second DAC does the rear two channels if the
mixer control Four Channel Mode
is disabled, but
it has 4/6 channels and drives both output socket if
enabled; this means that 4/6 channel mode can be used with
dmix
if device 1 is specified and Four
Channel Mode
is enabled.snd-ymfpci
driver
module and are also pretty nice and simple.Another page has a list of supported sound cards, usually oriented towards audiophiles.
Sound hardware depends on particularly tight realtime constraints, and this can give rise to a number of issues.
Sound hardware is often also designed and manufactured without much care, especially in the case on motherboard chipsets.
There can be in particular many sound quality issues related to latency, and these are discussed in a separate document on Linux sound latency issues.
The sound quality HOWTO also has a lot of advice on quality issues.
These are issues that are generally possible, and not necessarily related to the specific chipset or sound card used:
PCI Delay Transaction
PnP OS
setting (usually a good idea regardless) and to use the kernel
boot parameter pci=biosirq
.setpci -v -s '*:*' latency_timer=20(but reset the latency timer to 0 for the host bridge, usually with id
00:00.0
). There are more details on this
in the
notes on sound latency.
Another possible workaround is adding
Option "PciRetry" "true"
to the X server configuration./proc/mtrr
; main memory should be
write-back
, and the frame buffer of video cards
(at some very high address) should be
write-combinining
. There are some documents and
articles on the WWW that discuss MTRR settings.hdparm -v
to check if
DMA is enabled.fragment_size
<= 4096/etc/asound.conf
with the desired fragment
size./etc/asound.conf
External Amplifier
. If this is not
possible or does not work, one can plug the external amplifier
into the line-out socket of the card, if any.Mic Boost
control for the microphone
channel, but usually quality will not be optimal. If quality
is desired, an external microphone amplifier is probably#
a lot better.An important first step: compile the relevant information using
aadebug
.
Also have a look at the FAQ and the drivers documentation pages (1) for troubleshooting your specific soundcard.
The ALSA tips page might have useful stuff too, and this PDF of a presentation by an ALSA developer contains a number of interesting and important troubleshooting steps and details.
M
if you can.
M
(for module) and not
*
(compiled into the kernel)./proc/asound/version
and that this says
something like:
Advanced Linux Sound Architecture Driver Version 1.0.4.and that the version is 1.0.4 or above.
grep VERSION_STR /usr/include/alsa/version.hand check that the version is at least 1.0.4, and usually it is best if it matches the driver version.
/proc/asound/cards
lists your
card, as card number zero. If not, make sure that the
appropriate driver module is loaded.
lspci | egrep audiocommand. This usually will list the name and type of your sound chipset. The main ALSA website then contains a list of chipset and corresponding drivers.
snd-intel8x0
driver; for the other common sound card type, the Creative SB
Live! range, use snd-emu10k1
.
alsaconf
command,
and use it to configure your sound card.
/dev/sndstat
and if it exists and you see your
card listed there, and there is no line talking about ALSA
emulation, it is being driven by an OSS driver. Unload it and
load the ALSA driver.
alsamixer
as root
. If you get
alsamixer: function snd_ctl_open failed for default: No such devicethe right device special files in
/dev/
might be
missing. Run ls /dev/snd/
and make sure there are
several entries there.
snddevices
script or similar to create it
and the device special files in it.root
users can access the sound
device special filesalsamixer
both as root
and as
a non-root
ordinary user.
chmod -R a+rwX /dev/snd/.This might be slightly insecure.
audio
or sound
group./proc/asound/cards
, and you still hear no sound,
the most likely cause is that you haven't unmuted the right
mixer channels and set their volume to nonzero. Note that ALSA
sort of misnomes the channels of the mixers of many cards.
alsamixer
to play around with the
settings of the most obvious sounding channels. There are
often descriptions of what the channels are in the
page about your specific sound cards.
Master
and PCM
(and
Wave
or Headphone
if present)
channels are unmuted and have non zero volume.
External
Amplifier
switch.Analog/Digital Output
Jack
. If present, mute/unmute it to switch between
digital and analog sound output.aoss
wrapper to run the
application.dd if=/dev/urandom bs=8000 count=1 | aplay -D DEVNAMEto see if you can hear something. If you dont know which DEVNAME you should specify, use
plughw:0,0
to test sound card 0 in analog mode,
and plughw:1,0
for sound card 1.mmap
mmap
mode, so try disabling it. Viceversa if it
is disabled try to enable it.amixer
, for example with:
amixer cget name='Capture Source'which might return:
; type=ENUMERATED,access=rw---,values=2,items=8 ; Item #0 'Mic' ; Item #1 'CD' ; Item #2 'Video' ; Item #3 'Aux' ; Item #4 'Line' ; Item #5 'Mix' ; Item #6 'Mix Mono' ; Item #7 'Phone' : values=0,5This indicates that there are 8 possible capture channels, and
values=0,5
indicates that both Mic
and Mix
are enabled at the same time. This often
is the result of a bug in alsamixer
.
Mic
in this case
with:
amixer cset name='Capture Source' 0,0
Master
volume is higher than 66%, for some others the threashold is
50%. Reduce all volume setting. If the distortion goes away,
experiment until you determine which are the highest volume
settings that don't trigger distortion.dmix
plugin configuration.
Many cards cannot handle fragment sizes greater than 4096
bytes, and if it is bigger the fragment seems to be truncated
and the sound becomes choppy.plug:
plugin prefix (as in, for example:
plug:default
when playing. If your card can
only play a single fixed frequency you must ensure that
the driver is told that (by the use of driver-specific
option parameters), and the ALSA library is setup up to
output sample only at that frequency. Usually this will
involve using the plug
plugin in
/etc/asound.conf
.acpi=off
to the linux kernel boot
argumentssurround
; the most commonly used are
surround40
and surround51
. To get a
full list of those defined for your card run:
aplay -L 2>&1 | egrep surroundFor some cards, in particular USB based cards, ALSA does not (yet?) define any
surround
style virtual
device names, in part because these cards usually
only work in surround mode, accepting for example
only 5.1 channel samples.
surround
NN device, you will still hear
only the front speakers. This is as it should be.
spreadthe 2 channel sound onto more channels you need to create a special virtual device in the
/etc/asound.conf
file to do that using the route
plugin. There are
several examples of this in this
sample asound.conf
file (additional notes:
1,
2).Line
in
socket is also used for the LFE
output channel and the Mic
socket for the
Center
output channel, or viceversa. If this is
the case you must use the appropriate toggles in the mixer
controls to ensure that those sockets are used for output and
not input.
speaker-test
utility, which has been included in
the alsa-utils
package for a while now.dmix
pluginThis document is the result of many hours spent:
Thanksto Creative in particular for half-assedly designing my SB Live!, despite their immense corporate resources, and thus leading me to investigate the many pointless absurdities of this range of cards.
thanksto them for showing me what are the most common issues and misunderstandings with ALSA.
Thanks to the ALSA authors for writing the software, which is
after all a huge improvement on OSS, and
thanks
to them also for under-documenting
and over-complicating it gleefully probably to
protect their own jobs
and
their employer
from competition (really?), and thus giving me the motivation to
spend a lot of time, that maybe I could have spent more
usefully, trying to collate obscure hints here and there,
reverse engineering the sources, and experimenting, to gather
the information condensed in these notes.
Thanks to <peer>
for the pointer to the
chipset docs of the SB Live!.
Thanks to <hermanro>
for the pointer to the
RoseGarden FAQ on soft sequencers.
Thanks to the fellow sufferers and inmates of the ALSA asylum, those who have scratched on the walls of their cells their horror stories, painful discoveries and hints for those that would come after them.