0

Problem

I would like to get audio to work with ALSA:

  • with sound mixing (I.e. sound output can be used by multiple applications at once. Otherwise, some applications will immediately reserve audio output for themselves and never give it back.)
  • with microphone
  • with two devices (one internal, one usb). They do not need to operate simultaneously.

With all other laptops (lastly Lenovo X250) I have ever had, this used to work without any problems or any need for additional configuration (no /etc/asound.conf or ~/.asoundrc). With my current Lenovo T14, it does not.

Default setup, no /etc/asound.conf

Microphone works as expected.

However, sound output is restricted to one application at a time. I tested this by running the following twice simultaneously in two shells

mplayer -ao alsa <audio file>

The first instance will play as expected, the second will fail with

Playback open error: Device or resource busy

Attempts to solve this

...with pcm.dsp in /etc/asound.conf

As per the Arch wiki:

pcm.dsp {
    type plug
    slave.pcm "dmix"
}

...has no effect, no change in behavior. This is presumably because /dev/dsp does not exist?

...with pcm.!default in /etc/asound.conf

As per this Unix&Linux thread:

pcm.!default {
    type plug
    slave.pcm "dmix"
}

Sound mixing works. Microphone does not. For instance, the Chromium browser (for either of the two sound devices, i.e. started as either chromium --alsa-output-device='sysdefault:CARD=M459' or chromium --alsa-output-device='sysdefault:CARD=sofhdadsp') will say:

ALSA lib pcm_dmix.c:1008:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
[105089:105089:0211/111341.634020:ERROR:alsa_util.cc(204)] PcmOpen: default,Invalid argument

That is obviously because dmix and sound capture are incompatible. This superuser thread and the ALSA manual suggest using asym. The config file is very complicated and the sound devices are hardcoded in there (hw:0,0). Obviously, this doesn't work for me. I have no idea if this would even in principle be able to solve my problem even if I got all the hardware characteristics right. But I could not use this kind of configuration anyway, because my laptop might detect both the internal and the USB device as either hw=0.0 or hw=1.0 depending on what it feels like on that particular day (and whether the USB device is plugged in or not).

Note

While sound mixing works with the above command mplayer -ao alsa it still throws the same error (Playback open error: Device or resource busy) for the second instance with either of these two commands mplayer -ao alsa:device=hw=1.0 mplayer -ao alsa:device=hw=0.0 I do not know why. If dmix is only used for the default device (i.e. not if I specify a non-default device), I do not understand why it still makes the use of microphones impossible for all devices.

Workaround

A possible workaround is changing /etc/asound.conf every time I want to use the microphone, commenting out the pcm.!default bit and making the change take effect with

alsactl restore

This works (as far as I can tell), but is needlessly complicated and certainly not how the ALSA configureation was supposed to be used.

Hardware and software

Software

Arch Linux

$ uname -srmo
Linux 5.13.4-arch1-1 x86_64 GNU/Linux

$ alsactl -v
alsactl version 1.2.5.1

$ mplayer 
MPlayer SVN-r38157 (C) 2000-2019 MPlayer Team
225 audio & 468 video codecs
(...)

Hardware

Laptop is Lenovi T14

Audio devices

$ lspci|grep Aud
00:1f.3 Audio device: Intel Corporation Comet Lake PCH-LP cAVS

$ ls /dev/snd/by* -l
/dev/snd/by-id:
total 0
lrwxrwxrwx 1 root root 12 Feb 11 10:30 usb-C-Media_Electronics_Inc._Mpow_459_20200813-00 -> ../controlC1

/dev/snd/by-path:
total 0
lrwxrwxrwx 1 root root 12 Feb 11 10:30 pci-0000:00:14.0-usb-0:4:1.0 -> ../controlC1
lrwxrwxrwx 1 root root 12 Feb 10 12:25 pci-0000:00:1f.3-platform-skl_hda_dsp_generic -> ../controlC0
3
  • (1) In all hardware I have used, this never worked out of the box without configuration. (2) Have a look at the plughw "automatic" plugin, and see if it's available (aplay -L, arecord -L). Make it the default if necessary. (3) Under Pulseaudio, all of this works out of the box on all hardware.
    – dirkt
    Feb 11, 2022 at 13:41
  • @dirkt Thanks for the suggestions. (2) Unfortunately plughw is not available according to aplay -L or arecord -L (unless I'd need to install some obscure package first that I do not have). (3) Unfortunately, I have never understood pulseausio. This is why I wanted ALSA. Pulseaudio does indeed do the mixing. But it will also assign an audio output device to each application seemingly at random, including devices that do not exist. (Sometimes it works, sometimes USB, sometimes internal, and sometimes it doesn't and I get Can't open audio device /dev/dsp: No such file or directory.)
    – 0range
    Feb 16, 2022 at 22:53
  • If you don't have plughw by default (which is interesting, I have never seen that), the yes, you need to explicitly configure asym on top of dmix and dsnoop. Pulseaudio keeps track of which sink/source (output/input device) the application used last time, and on startup re-assigns that device to the application. It isn't random, and if you change the device, it remembers the change. I've also never seen it assign a "non-existing" sink (how should that even work?) Real old applications using /dev/dsp will neither work under ALSA, nor under Pulseaudio.
    – dirkt
    Feb 17, 2022 at 5:30

0

You must log in to answer this question.

Browse other questions tagged .