ALSA doesn't work when multiple applications are opened

5,357

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).

Share:
5,357

Related videos on Youtube

Omar Emara
Author by

Omar Emara

A Computer Science student. Open source developer. Interested in the Blender ecosystem.

Updated on September 18, 2022

Comments

  • Omar Emara
    Omar Emara over 1 year

    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)
    
    • CL.
      CL. about 7 years
      Use either PulseAudio or dmix, but all application must use the same.
    • Omar Emara
      Omar Emara about 7 years
      @CL. Is there is a way to set either of them as the default for all the apps on my computer?
    • CL.
      CL. about 7 years
      No; that depends on the apps.
  • Omar Emara
    Omar Emara about 7 years
    But dmix isn't available as well when 2 applications are opened, you can see it in the first list yes, but not in the second one.
  • Stephen Kitt
    Stephen Kitt about 7 years
    If you change the first application to open dmix, you’ll see it remains available. It disappears in the second list because it can’t work if another application has opened default (by default).
  • Omar Emara
    Omar Emara about 7 years
    I see, this may be a problem because I am using a python interpreter that is inside an app, so as soon as I open the program, I won't be able to change it in its python. Thanks.
  • Stephen Kitt
    Stephen Kitt about 7 years
    You probably need to adjust it, in particular you probably need to determine what sysdefault corresponds to.
  • Omar Emara
    Omar Emara about 7 years
    Not sure what I should adjust, can you point me? I edited the question for the list after the configuration.
  • Stephen Kitt
    Stephen Kitt about 7 years
    The output looks OK, but it will only work for output. See my update.