ALSA doesn't work when multiple applications are opened
I am writing some python program that is related to sounds, so I used the SoundDevice python module which used PortAudio library. I am on arch linux with deepin desktop.
If I just opened the computer and printed the available devices I get:
0 HDA Intel PCH: ALC887-VD Analog (hw:0,0), ALSA (2 in, 2 out)
1 HDA Intel PCH: ALC887-VD Digital (hw:0,1), ALSA (0 in, 2 out)
2 HDA Intel PCH: ALC887-VD Alt Analog (hw:0,2), ALSA (2 in, 0 out)
3 HDA ATI HDMI: 0 (hw:1,3), ALSA (0 in, 8 out)
4 sysdefault, ALSA (128 in, 128 out)
5 front, ALSA (0 in, 2 out)
6 surround40, ALSA (0 in, 2 out)
7 surround51, ALSA (0 in, 2 out)
8 surround71, ALSA (0 in, 2 out)
9 iec958, ALSA (0 in, 2 out)
10 spdif, ALSA (0 in, 2 out)
11 pulse, ALSA (32 in, 32 out)
12 dmixed, ALSA (0 in, 2 out)
13 dsnooped, ALSA (2 in, 0 out)
14 duplex, ALSA (2 in, 2 out)
15 dmix, ALSA (0 in, 2 out)
* 16 default, ALSA (128 in, 128 out)
It says that I am using the ALSA (128 in, 128 out). Now I will open an app–lets say Chromium–and played some music then went on to browse the internet. If I now print the available devices I would get:
0 HDA Intel PCH: ALC887-VD Analog (hw:0,0), ALSA (2 in, 0 out)
< 1 HDA Intel PCH: ALC887-VD Digital (hw:0,1), ALSA (0 in, 2 out)
2 HDA Intel PCH: ALC887-VD Alt Analog (hw:0,2), ALSA (2 in, 0 out)
3 HDA ATI HDMI: 0 (hw:1,3), ALSA (0 in, 8 out)
4 sysdefault, ALSA (128 in, 0 out)
5 iec958, ALSA (0 in, 2 out)
6 spdif, ALSA (0 in, 2 out)
7 pulse, ALSA (32 in, 32 out)
8 dsnooped, ALSA (2 in, 0 out)
9 duplex, ALSA (2 in, 0 out)
> 10 default, ALSA (128 in, 0 out)
It tells me I am using the Intel as my output and ALSA (128 in, 0) as my input. Why isn’t there ALSA input and output as before?
This happens in all the applications that uses sound including Audacity.
I am currently using pluse as an alternative, but It is said that ALSA is better so I want to use it even if multiple applications are opened at the same time.
Edit
Here is the list after editing the configuration:
> 0 HDA Intel PCH: ALC887-VD Analog (hw:0,0), ALSA (2 in, 2 out)
1 HDA Intel PCH: ALC887-VD Digital (hw:0,1), ALSA (0 in, 2 out)
2 HDA Intel PCH: ALC887-VD Alt Analog (hw:0,2), ALSA (2 in, 0 out)
3 HDA ATI HDMI: 0 (hw:1,3), ALSA (0 in, 8 out)
4 sysdefault, ALSA (128 in, 128 out)
5 front, ALSA (0 in, 2 out)
6 surround40, ALSA (0 in, 2 out)
7 surround51, ALSA (0 in, 2 out)
8 surround71, ALSA (0 in, 2 out)
9 iec958, ALSA (0 in, 2 out)
10 spdif, ALSA (0 in, 2 out)
11 pulse, ALSA (32 in, 32 out)
12 dmix, ALSA (0 in, 2 out)
< 13 default, ALSA (0 in, 128 out)
You need to output to the dmix
ALSA device instead of the default device; that allows multiple streams to be mixed and output to the sound card. It is set up automatically on sound devices which don’t support hardware mixing; as you can see, it’s set up on your system.
You’ll find more information on the ALSA wiki.
You can configure dmix
to be the default with a configuration such as
pcm.!default {
type plug
slave.pcm "dmix"
}
You’ll still need to configure all your applications to use ALSA. Note too that dmix
is only an output device; if you want to manage multiple inputs you’ll need to use dsnoop
. The ALSA wiki has detailed configuration examples for both that you can adapt to your particular settings (in particular, the default underlying hardware device).