You are not logged in.

#1 2021-12-08 00:13:39

computernoob
Member
Registered: 2021-12-07
Posts: 10

Alsa how to add default output and input (2 cards)

Hi!

I've been stuck with configuring audio for the past 2 days and don't know what to change/add to my /etc/asound.conf. I have speakers and headphones connected to the back/and front audio and 1 usb microphone. I can set the default to a specific card and it will work, the problem is that the USB microphone acts as a card and is therefore not recognized as my default microphone and vice versa.

With the following audio works but not microphone, and if I change it to"2" microphone works but not audio:

defaults.pcm.card 1
defaults.ctl.card 1 

I did find a post about setting up a default input and output on different cards with this as a solution:

pcm.!default {
    type asym
    playback.pcm "hw:1"
    capture.pcm  "hw:2"
}


ctl.!default {
        type hw
        card 1
}

It worked for me when playing files with aplay or mpv, and recording with arecord. However audio from applications e.g web browser would no longer work.

I'm afraid this is because specifying "hw"? The arch wiki says "Simply setting a type hw as default card is equivalent to addressing hardware directly, which leaves the device unavailable to other applications.".
What can I do to make this work with all applications? My attempt was to remove hw and just having the numbers, but that didn't work. Thanks for reading!

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 0: ALCS1200A Analog [ALCS1200A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 1: ALCS1200A Digital [ALCS1200A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ lsmod | grep snd
snd_usb_audio         380928  0
snd_usbmidi_lib        45056  1 snd_usb_audio
snd_rawmidi            53248  1 snd_usbmidi_lib
snd_hda_codec_realtek   159744  1
snd_seq_device         16384  1 snd_rawmidi
mc                     65536  1 snd_usb_audio
snd_hda_codec_generic    98304  1 snd_hda_codec_realtek
ledtrig_audio          16384  1 snd_hda_codec_generic
snd_hda_codec_hdmi     81920  1
snd_hda_intel          61440  0
snd_intel_dspcfg       32768  1 snd_hda_intel
snd_intel_sdw_acpi     20480  1 snd_intel_dspcfg
snd_hda_codec         184320  4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec_realtek
snd_hda_core          118784  5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek
snd_hwdep              16384  2 snd_usb_audio,snd_hda_codec
snd_pcm               163840  5 snd_hda_codec_hdmi,snd_hda_intel,snd_usb_audio,snd_hda_codec,snd_hda_core
snd_timer              49152  1 snd_pcm
snd                   126976  12 snd_hda_codec_generic,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_usb_audio,snd_usbmidi_lib,snd_hda_codec,snd_hda_codec_realtek,snd_timer,snd_pcm,snd_rawmidi
soundcore              16384  1 snd

$ cat /proc/asound/modules
 0 snd_hda_intel
 1 snd_hda_intel
 2 snd_usb_audio

Offline

#2 2021-12-08 07:55:36

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,857

Re: Alsa how to add default output and input (2 cards)

It doesn't work because you "forcibly" override the normal default pcm (which uses dmix) and thus go back to direct HW access. "Standard" ALSA works by a possibly complex chain of plugins that adjust the signal in various ways. You either need to setup fairly complex custom configurations or know how the defaults are setup to minimally manipulate them to what you want to do. In this case doing.

defaults.pcm.card 1
defaults.ctl.card 1 
defaults.pcm.dsnoop.card 2

should be "the fix". You'll know these little shorthands by checking the default conf in /usr/share/alsa/alsa.conf

That said there are a few possible gotchas that you'll potentially run into with this. Right of the bat, unless you nail down all the indices in use here by following the section about manipulating the index via modprobe there's a chance on every boot that the mic is detected before the actual card which will swap the indices around. There will also be programs and tools that look for the wrong listing for available devices and will be confused there.

FWIW if you "need" them to be a combined asym then you can override the default using the information above

defaults.pcm.card 1
defaults.ctl.card 1 
defaults.pcm.dsnoop.card 2

pcm.!default {
     type asym
     playback.pcm "dmix"
     capture.pcm "dsnoop"
     # Make sure we show up in aplay -L and the like, some programs (*cough* firefox *cough*) throw a fit if the default node isn't there
     #
     hint {
         show {
                on 
                   }
      description "Combined playback/capture default device"
      }
      
}

Even so there might still be tools that have an issue with this, and I'd generally reccommend you set up pipewire/pulseaudio which have their own and more guaranteed ways of properly selecting default devices. But from an ALSA perspective the above should get you started (if you were to opt for one of these other daemons you need to remove everything we've discussed here and opt for pulseaudio-alsa/pipewire-alsa respectively)

Last edited by V1del (2021-12-08 07:59:06)

Offline

#3 2021-12-08 21:52:35

computernoob
Member
Registered: 2021-12-07
Posts: 10

Re: Alsa how to add default output and input (2 cards)

V1del wrote:

It doesn't work because you "forcibly" override the normal default pcm (which uses dmix) and thus go back to direct HW access. "Standard" ALSA works by a possibly complex chain of plugins that adjust the signal in various ways. You either need to setup fairly complex custom configurations or know how the defaults are setup to minimally manipulate them to what you want to do. In this case doing.

defaults.pcm.card 1
defaults.ctl.card 1 
defaults.pcm.dsnoop.card 2

should be "the fix". You'll know these little shorthands by checking the default conf in /usr/share/alsa/alsa.conf

That said there are a few possible gotchas that you'll potentially run into with this. Right of the bat, unless you nail down all the indices in use here by following the section about manipulating the index via modprobe there's a chance on every boot that the mic is detected before the actual card which will swap the indices around. There will also be programs and tools that look for the wrong listing for available devices and will be confused there.

FWIW if you "need" them to be a combined asym then you can override the default using the information above

defaults.pcm.card 1
defaults.ctl.card 1 
defaults.pcm.dsnoop.card 2

pcm.!default {
     type asym
     playback.pcm "dmix"
     capture.pcm "dsnoop"
     # Make sure we show up in aplay -L and the like, some programs (*cough* firefox *cough*) throw a fit if the default node isn't there
     #
     hint {
         show {
                on 
                   }
      description "Combined playback/capture default device"
      }
      
}

Even so there might still be tools that have an issue with this, and I'd generally reccommend you set up pipewire/pulseaudio which have their own and more guaranteed ways of properly selecting default devices. But from an ALSA perspective the above should get you started (if you were to opt for one of these other daemons you need to remove everything we've discussed here and opt for pulseaudio-alsa/pipewire-alsa respectively)

Hi thanks for the reply!

I tried replacing the contents of /etc/alsa.conf with what you suggested and I received the same error for both.

$ aplay test-mic.wav
ALSA lib conf.c:1994:(_snd_config_load_with_include) _toplevel_:8:0:Unexpected char
ALSA lib conf.c:4040:(config_file_open) /etc/asound.conf may be old or corrupted: consider to remove or fix it
ALSA lib conf.c:3962:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument
ALSA lib conf.c:4569:(snd_config_update_r) hooks failed, removing configuration
aplay: main:831: audio open error: Invalid argument

I did also tried to replace 1 with 2 if it was that the indices had been switched from rebooting.
Let me know If there anything else I can try to make this work, or if you need more information. I appreciate the help!

I wanted to setup audio with what I already have (alsa) without installing anything else to see how it would workout without a sound server. I'd like to troubleshoot this out of curiosity, but for now I'll try my luck with pipewire or pulse. Don't have experience with setting those up, but from what I've heard it shouldn't be to hard.

Last edited by computernoob (2021-12-08 21:53:17)

Offline

#4 2021-12-08 22:17:17

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,857

Re: Alsa how to add default output and input (2 cards)

Hmm, maybe remove the comment (the lines with the #) and maybe use

hint {
show on
description "Default device"
}

for the hint block instead, the other things should work.

Last edited by V1del (2021-12-08 22:18:51)

Offline

#5 2021-12-09 23:57:43

computernoob
Member
Registered: 2021-12-07
Posts: 10

Re: Alsa how to add default output and input (2 cards)

V1del wrote:

Hmm, maybe remove the comment (the lines with the #) and maybe use

hint {
show on
description "Default device"
}

for the hint block instead, the other things should work.

With this my /etc/asound.conf currently looks like this, still same errors given:

defaults.pcm.card 1
defaults.ctl.card 1
defaults.pcm.dsnoop.card 2

pcm.!default {
     type asym
     playback.pcm "dmix"
     capture.pcm "dsnoop"
hint {
show on
description "Default device"
}

I would think it has something to do with line 3, since that's when the errors first occurred, but I can't say for sure.
Been testing out pipewire meanwhile, default audio devices was correct after the install without editing any configs. Will try to be using this for the time being if the alsa method wont work.

Offline

#6 2021-12-10 10:45:59

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,857

Re: Alsa how to add default output and input (2 cards)

You lack a closing brace for the default pcm at the minimum. maybe drop the hint node alrogether, but seriously I'd reccommend pipewire/pulse anyway and their relevant handling should be less reliant on a changing "static" setup

Last edited by V1del (2021-12-10 10:47:02)

Offline

Board footer

Powered by FluxBB