ALSA/troubleshooting
ALSA troubleshooting
For in-depth information about a program's usage of ALSA, such as its PID (owner_pid) and sample rate (rate), use the /proc interface. This can be done by substituting the relevant card/device details into the following command. Note that the /proc interface only lists physical devices, not virtual devices[1].
user $cat /proc/asound/card2/pcm0p/sub0/*access: RW_INTERLEAVED format: S16_LE subformat: STD channels: 2 rate: 44100 (44100/1) period_size: 5513 buffer_size: 22050 card: 2 device: 0 subdevice: 0 stream: PLAYBACK id: USB Audio name: USB Audio subname: subdevice #0 class: 0 subclass: 0 subdevices_count: 1 subdevices_avail: 0 state: RUNNING owner_pid : 934 trigger_time: 86393.193574796 tstamp : 86540.250594985 delay : 17714 avail : 4602 avail_max : 7379 ----- hw_ptr : 6485052 appl_ptr : 6502500 tstamp_mode: NONE period_step: 1 avail_min: 5513 start_threshold: 2147483647 stop_threshold: 22050 silence_threshold: 0 silence_size: 0 boundary: 6206523236469964800
No sound
If there's no sound, output channels may be muted. Unmute the channels, either by using the GUI environment's mixer, or by using alsamixer (from the media-audio/alsa-utils package), selecting the appropriate channels and pressing the M key to mute or unmute:
user $alsamixer
Custom ALSA config results in no sound in browsers
Try explicitly specifying defaults in the configuration:
~/.asoundrcdefaults.pcm.card <number of default sound card>
defaults.ctl.card <default sound card>
Note that, since Firefox 52 (released in 2017), support for direct output to ALSA has been dropped, and PulseAudio has been made a hard requirement. To address this, enable Firefox's pulseaudio flag and install apulse, which provides Pulse emulation for ALSA
Sound card only available for one application
Sometimes one app essentially takes over all sound devices, e.g. for performance reasons.
To force the use of dmix instead of direct audio output (which is what most things, such as Wine, use by default), when the device is card 1 device 7:
~/.asoundrcpcm.dmixed {
type asym
playback.pcm {
type dmix
ipc_key 5678293
ipc_perm 0660
ipc_gid audio
slave {
channels 2
pcm {
format S16_LE # S32_LE
rate 48000 # Can also be 44100
type hw
card 1 # Specify card number as appropriate
device 7 # Specify device number as appropriate
subdevice 0
}
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
# Uncomment below if using 6 channel
# 2 2
# 3 3
# 4 4
# 5 5
}
}
capture.pcm "hw:0"
}
pcm.!default {
type plug
slave.pcm "dmixed"
}
Use of ~/.asoundrc is immediate: as long as use of a specific device is not being forced by any applications, applications will either begin to produce audio output immediately, or will require a restart. One of the best tests is to open a browser, go to YouTube, open a terminal, and use an audio or video player to try to play an audio or video file: success is indicated by an absence of errors (e.g. "Device or resource busy").
Missing dialogue/sound with 4.0 speakers
If using a 4.0 sound card (like an old SB Live), or 4.0 speakers in general, the dialogue in some games or movies might be very quiet or even missing. This is because most applications and movies support only either 2.0 (stereo) or 5.1 output. In order to achieve surround sound, the 5.1 audio track is used, but two channels are discarded: the center channel (which usually carries dialogue), and the subwoofer channel.
This issue can be circumvented by creating a virtual device which downmixes 5.1 to 4.0, mixing the center and subwoofer channels with other audio channels.
~/.asoundrcpcm.downmix {
type route
slave {
# The sound card output to be used
pcm surround40
# Real number of output channels
channels 4
}
# ttable.A.B G
# where A - input channel
# B - output channel
# G - volume gain (1.0 = original)
# Copy channels 0-3
ttable.0.0 1
ttable.1.1 1
ttable.2.2 1
ttable.3.3 1
# Mix channel 4 (center) into front speakers, and a bit (0.3) into rear ones
ttable.4.0 1.0
ttable.4.1 1.0
ttable.4.2 0.3
ttable.4.3 0.3
# Mix channel 5 (subwoofer) mostly (0.6) into rear speakers, and a bit (0.3) into front ones
ttable.5.0 0.3
ttable.5.1 0.3
ttable.5.2 0.6
ttable.5.3 0.6
}
ctl.downmix {
type hw
card 0
}
HDMI output from aplay has incorrect speaker channels
If MPlayer or VLC correctly plays a file in a 5.1 or 7.1 configuration over HDMI, but aplay doesn't, this might be caused by the snd_hda_intel HDMI audio module/driver, which is used by vendors other than Intel (e.g. Nvidia). Additionally, aplay might refuse to play the file if its format is 24-bit PCM 2.0/5.1 WAV.
To address these issues with minimal alterations to the PCM streams, remap the speaker channels. The following configuration is for both 5.1 and 7.1 audio. (If audio from a 7.1 stream should not be omitted, further map/copy the two extra channels to the 5.1 channels.) Additionally, as most HDMI-to Stereo-receiver connections only stream 16- and 32- bit formats, skipping 24-bit, the configuration up-mixes any PCM stream using the pcm.myHDMI profile to 32 bits.
/etc/asound.confpcm.myHDMI {
type plug
slave {
pcm "hw:1,7"
format S32_LE
channels 6
}
ttable {
0.0= 1
1.1= 1
2.4= 1
3.5= 1
4.2= 1
5.3= 1
6.6= 1
7.7= 1
}
}
Weak center channel on PCM 5.1 live music
If a multi-channel soundtrack or piece of music has an apparently weak center channel, and the sound track is a live recording, it might be possible to map the center channel to the rear channels, e.g. when using mplayer:
user $mplayer -ao alsa:device=hw=1.7 Music/MyAlbum/PCM51-24bit/01.MyMusic.wav -channels 6 -format s32le -af channels=6:6:0:0:1:1:4:2:4:3:4:4:5:5The above incantation of mplayer specifies:
- an HDMI device of
hw:1.7; - the PCM 5.1 audio file;
- the number of channels;
- the format (not needed if the receiver can natively handle 24 bit; receivers that can only natively handle 16- or 32-bit audio need to be upmixed); and
- the mapping.
The mapping specifies:
- a 6 channel audio stream, with 6 mappings immediately following, then to copy:
- the left front channel to left speaker;
- the right channel to right speaker;
- the center channel to left rear speaker;
- the center channel to right rear speaker;
- the center channel to center speaker; and
- the subwoofer channel to the subwoofer speaker.
Note that the rear channels on live recordings usually contain only the audience screaming, with very little music.
For further details, refer to the mplayer(1) man page.
Laptops with HDMI audio output
Some laptops with HDMI audio output will map HDMI as /proc/asound/card0, making it the default output device for applications. To change the device order, refer to the "Kernel modules" section.
Headset jack not working
Sometimes, to get a headset jack working, additional model information needs to be passed to the audio driver. For example, in case of a Dell Latitude E7470 laptop with snd-hda-intel driver, the following needs to be added to /etc/modprobe.d/alsa.conf:
/etc/modprobe.d/alsa.confoptions snd-hda-intel model=headset-mic
More information can be found in this section of the Linux kernel documentation.
udev/alsactl errors on boot
Due to partitioning, encryption, or having a split /usr system, these errors may appear on boot:
root #journalctl -b | grep alsa(udev-worker)[2594]: controlC2: Process '/usr/sbin/alsactl restore 2' failed with exit code 2. (udev-worker)[2611]: controlC0: Process '/usr/sbin/alsactl restore 0' failed with exit code 2. (udev-worker)[2579]: controlC1: Process '/usr/sbin/alsactl restore 1' failed with exit code 2.
To fix the issue, add TEST=="@sbindir@/alsactl" to /lib/udev/rules.d/90-alsa-restore.rules:
/lib/udev/rules.d/90-alsa-restore.rulesTEST!="/etc/alsa/state-daemon.conf", TEST=="@sbindir@/alsactl", RUN+="/usr/sbin/alsactl restore $attr{device/number}"
TEST=="/etc/alsa/state-daemon.conf", TEST=="@sbindir@/alsactl", RUN+="/usr/sbin/alsactl nrestore $attr{device/number}"
For further details and discussion, refer to this discussion on alsa-devel and this discussion on bugs.debian.org.
No sound after rebooting following a system update
If, after a system update followed by a reboot, sound is not working, resulting in e.g. speaker-test(1) producing an error like:
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.2.14/work/alsa-lib-1.2.14/src/pcm/pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave Playback open error: -2,No such file or directory
and alsaplayer(1) producing an error like:
/usr/lib64/alsaplayer/output/libalsa_out.so failed to load NOTE: THIS IS THE NULL PLUGIN. YOU WILL NOT HEAR SOUND!!
It might be that a stale /var/lib/alsa/asound.state file is present (e.g. due to the format of that file changing between kernel versions). Remove that file and reboot.