Advanced Linux Sound Architecture (ALSA)
Vicente González Ruiz
November 4, 2014
Contents
1 What is ALSA?
2 Installation
- ALSA is included in the default in most Linux kernels as a set of modules,
so manual installation is not necessary.
- Udev will automatically probe your hardware at boot, loading the
corresponding kernel module for your audio card.
- The loaded modules can be displayed with:
$ lsmod | grep ’^snd’ | column -t
snd_hda_codec_realtek 61438 1
snd_hda_intel 52355 6
snd_hda_codec 192906 2 snd_hda_codec_realtek,snd_hda_intel
snd_hwdep 13602 1 snd_hda_codec
snd_pcm 102099 3 snd_hda_codec,snd_hda_intel
snd_page_alloc 18710 2 snd_pcm,snd_hda_intel
snd_seq_midi 13324 0
snd_seq_midi_event 14899 1 snd_seq_midi
snd_rawmidi 30144 1 snd_seq_midi
snd_seq 61560 2 snd_seq_midi_event,snd_seq_midi
snd_seq_device 14497 3 snd_seq,snd_rawmidi,snd_seq_midi
snd_timer 29482 2 snd_pcm,snd_seq
snd 69238 21 snd_hda_codec_realtek,snd_hwdep,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_hda_codec,snd_hda_intel,snd_seq_device,snd_seq_midi
3 Recognized audio hardware
$ cat /proc/asound/card*/id
4 Playback devices
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC889A Analog [ALC889A Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 1: ALC889A Digital [ALC889A Digital]
Subdevices: 1/1
Subdevice #0: subdevice #0
# In this example, there is a sound card named "Nvidia"
# which has two playback devices "ALC889A Analog" and "ALC889A Digital".
# You can extract the sound card names by using:
$ aplay -l | awk -F \: ’/,/{print $2}’ | awk ’{print $1}’ | uniq
5 PCM DAC (playback) device names
$ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
equal
plugequal
default
Playback/recording through the PulseAudio sound server
sysdefault:CARD=NVidia
HDA NVidia, ALC889A Analog
Default Audio Device
front:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Front speakers
surround40:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Digital
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct sample mixing device
dmix:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct sample mixing device
dsnoop:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct sample snooping device
hw:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct hardware device without any conversions
plughw:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Hardware device with all software conversions
6 Capture devices
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC889A Analog [ALC889A Analog] # Line in
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 1: ALC889A Digital [ALC889A Digital] # SPDIF
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 2: ALC889A Alt Analog [ALC889A Alt Analog] # Mic
Subdevices: 2/2
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
7 PCM ADC (capture) device names
$ arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
equal
plugequal
default
Playback/recording through the PulseAudio sound server
sysdefault:CARD=NVidia
HDA NVidia, ALC889A Analog
Default Audio Device
front:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Front speakers
surround40:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Digital
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct sample mixing device
dmix:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct sample mixing device
dmix:CARD=NVidia,DEV=2
HDA NVidia, ALC889A Alt Analog
Direct sample mixing device
dsnoop:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=2
HDA NVidia, ALC889A Alt Analog
Direct sample snooping device
hw:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=2
HDA NVidia, ALC889A Alt Analog
Direct hardware device without any conversions
plughw:CARD=NVidia,DEV=0
HDA NVidia, ALC889A Analog
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=1
HDA NVidia, ALC889A Digital
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=2
HDA NVidia, ALC889A Alt Analog
Hardware device with all software conversions
8 Cards, devices, and subdevices
- A system can host several sound cards.
- Sound cards presents one or more devices, which are divided into one or
more subdevices.
- ALSA works with logical device names, which can be hardware (real)
devices or plugins.
- Hardware devices use the format hw:i,j, where i is the card number and
j is the device on that card. The first device is hw:0.0.
- Plugins are refered by plughw and provides features such as sampling rate
conversion, channel dupplication and sample value conversion.
9 (Very basic) Configuration
10 Permissions
- Users with a local login (at a virtual terminal or a display manager) have
permission to play audio and change mixer levels. To allow this for a
remote login, the user has to be added to the audio group.
- Membership in the audio group also allows direct access to devices.
Therefore, adding a user to the audio group is not recommended, because
the audio hardware can not be used for two or more users at the same
time.
11 alsa: the deamon handler
12 amixer: a command-line mixer
- Location:
$ which amixer
/usr/bin/amixer
- Mixer controls:
$ amixer | grep control # Also works: "amixer scontrols"
Simple mixer control ’Master’,0 <- Master out volume control
Simple mixer control ’Headphone’,0 <- Stereo headphone out volume control
Simple mixer control ’PCM’,0 <- Stereo DAC out volume control
Simple mixer control ’Front’,0 <- Stereo front (5.1) out output volume
Simple mixer control ’Surround’,0 <- Stereo rear out volume control
Simple mixer control ’Center’,0 <- Mono center out volume control
Simple mixer control ’LFE’,0 <- Mono subwoofer out volume control
Simple mixer control ’Line’,0 <- Stereo ADC line in volume control
Simple mixer control ’Line Boost’,0 <- 20dB amplified line in
Simple mixer control ’Mic’,0 <- Stereo ADC microphone input line control
Simple mixer control ’Mic Boost’,0 <- 20dB amplified Mic
Simple mixer control ’IEC958’,0 <- Analog S/PDIF out volume control
Simple mixer control ’IEC958 Default PCM’,0 <- Digital S/PDIF out volume control
Simple mixer control ’Beep’,0 <- PC "speaker" out volume control
Simple mixer control ’Capture’,0 <- Line in gain
Simple mixer control ’Capture’,1 <- S/PDIF gain
Simple mixer control ’Capture’,2 <- Mic gain
Simple mixer control ’Auto-Mute Mode’,0 <- Headphone jack inserted, speaker off
Simple mixer control ’Input Source’,0 <- Line | IEC958 | Mic (you can select one)
Simple mixer control ’Input Source’,1 <- :
Simple mixer control ’Input Source’,2 <- :
13 alsamixer: a ncursed-based mixer
14 speacker-test: a command-line pink noise generator
$ speaker-test -c 2 # Analog (Headphones) stereo
$ speaker-test -Dplug:spdif -c2 # Didital (SPDIF) stereo
$ speaker-test -surround71:HDMI -c 8 # 7.1
15 Sampling parameters
- Sample rate: number of audio samples per second.
- Sample format: signed, unsigned, bit/sample, etc.
- Number of channels and data layout: refers to the number of channels and
the samples interleaving.
- Buffer size: This determines how large the hardware buffer is. It is related
with the latency.
16 Capture limits
- Emulated:
$ arecord --dump-hw-params > /dev/null
Recording WAVE ’stdin’ : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "default": # <- Usually Pulseaudio
--------------------
ACCESS: RW_INTERLEAVED
FORMAT: U8 S16_LE S16_BE S32_LE S32_BE FLOAT_LE FLOAT_BE MU_LAW A_LAW
SUBFORMAT: STD
SAMPLE_BITS: [8 32]
FRAME_BITS: [8 1024]
CHANNELS: [1 32]
RATE: [1 192000]
PERIOD_TIME: (5 4294967295)
PERIOD_SIZE: [1 1398102)
PERIOD_BYTES: [128 1398102)
PERIODS: [3 1024]
BUFFER_TIME: (15 4294967295]
BUFFER_SIZE: [3 4194304]
BUFFER_BYTES: [384 4194304]
TICK_TIME: ALL
--------------------
"Push <CTRL> + <C>"
- Real:
$ arecord -D hw:0,0 --dump-hw-params
Recording WAVE ’stdin’ : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "hw:0,0":
--------------------
ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT: S16_LE S32_LE
SUBFORMAT: STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [32 64]
CHANNELS: 2
RATE: [44100 192000]
PERIOD_TIME: (83 185760)
PERIOD_SIZE: [16 8192]
PERIOD_BYTES: [128 65536]
PERIODS: [2 32]
BUFFER_TIME: (166 371520)
BUFFER_SIZE: [32 16384]
BUFFER_BYTES: [128 65536]
TICK_TIME: ALL
--------------------
arecord: set_params:1233: Sample format non available
Available formats:
- S16_LE
- S32_LE
17 Capture and playback PCM data (basic example)
$ arecord -f cd | aplay -f cd
Recording WAVE ’stdin’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Playing WAVE ’stdin’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
underrun!!! (at least 209,120 ms long)
^CAborted by signal Interrupt...
aplay: pcm_write:1939: write error: Interrupted system call
Aborted by signal Interrupt...