LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Outputting to two sound cards with ALSA (https://www.linuxquestions.org/questions/linux-software-2/outputting-to-two-sound-cards-with-alsa-4175550078/)

maples 08-06-2015 05:14 PM

Outputting to two sound cards with ALSA
 
Hi,
I have a Dell Inspiron 15R laptop. It has two sound cards: one for the internal speakers and headphone jack, and one for the HDMI audio. Originally, the default was the HDMI, but I fixed that with the help of this thread: https://www.linuxquestions.org/quest...er-4175506142/

The configuration that set the internal speaker card as default:
/etc/asound.conf
Code:

pcm.!default {
        type hw
        card 1
}

ctl.!default {
        type hw
        card 1
}

~/.asoundrc
Code:

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

pcm.dsp0 {
  type plug
  slave.pcm "dmixer"
}

pcm.dmixer {
  type dmix
  ipc_key 1024
  slave {
    pcm hw:1
  }
}

While that worked, I'd like to be able to use HDMI audio as well, if I connect my laptop to something over HDMI.
Using this guide (http://slack4dummies.blogspot.com/20...ple-sound.html) I came up with this /etc/asound.conf, and no ~/.asoundrc
Code:

# Have output to both normal sound card and HDMI audio
# Based very heavily on this article:
# http://slack4dummies.blogspot.com/2012/02/alsa-multiple-output-multiple-sound.html

pcm.onboard {
        type hw
        card PCH
}
ctl.onboard {
        type hw
        card PCH
}

pcm.hdmi {
        type hw
        card HDMI
}
ctl.hdmi {
        type hw
        card HDMI
}

pcm.internalDmix {
        type dmix
        ipc_key 1024
        slave {
                pcm "internal"
                channels 2
        }
        bindings {
                0 0
                1 1
        }
}

pcm.hdmiDmix {
        type dmix
        ipc_key 2048
        slave {
                pcm "hdmi"
                channels 2
        }
        bindings {
                0 0
                1 1
        }
}

pcm.both {
        type route
        slave.pcm {
                slaves.a.pcm "internalDmix"
                slaves.b.pcm "hdmiDmix"
                slaves.a.channels 2
                slaves.b.channels 2

                bindings.0.slave a
                bindings.0.channel 0
                bindings.1.slave a
                bindings.1.channel 1

                bindings.0.slave b
                bindings.0.channel 0
                bindings.1.slave b
                bindings.1.channel 1
        }

        ttable.0.0 1
        ttable.1.1 1
}

pcm.!default {
        type plug
        slave {
                pcm both
        }
}

ctl.!default {
        type hw
        card PCH
}

However, that isn't working. Not only does HDMI audio not work, but the internal speakers aren't doing anything either. When I try to open alsamixer, I get this error:
Code:

[anthony@newerLaptop ~]$ alsamixer
ALSA lib conf.c:1231:(parse_def) hdmi is not a compound
ALSA lib conf.c:1697:(snd_config_load1) _toplevel_:14:10:Invalid argument
ALSA lib conf.c:3417:(config_file_open) /etc/asound.conf may be old or corrupted: consider to remove or fix it
ALSA lib conf.c:3339:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument
ALSA lib conf.c:3788:(snd_config_update_r) hooks failed, removing configuration
cannot open mixer: Invalid argument

I had to move my asound.conf out of the way and reboot in order to get this output, but I know that you'd ask for it anyway :D
Code:

[anthony@newerLaptop ~]$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3223 Analog [ALC3223 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

When I open alsamixer and go to the HDMI sound card, there are no "slider" bars. Instead, there are three "S/PDIF" options that only have the option to mute/unmute. Could that have anything to do with why it failed?

I apologize if there's some ridiculously stupid mistake in there. I'm still having trouble wrapping my head around the syntax of these files.

Melanie 08-18-2015 02:32 PM

At first glance, there seem to be several things in that asound.conf that reference things not defined anywhere.

First off, there are certain difficulties with merging two sound cards. From my work on jackd I learned that, unless the two cards are sample-synchronized, there is a very good chance it will just not work reliably.

It may work well enough for the desktop pops and clicks, or for watching a movie, but may well fail after a few hours, when one of the dmix buffers underflows.

That said, when using type hw, card must be numeric, not a name. Refer to your aplay -l output for these numbers. In your case, the HDMI audio port is port 0 and the analog is port 1.

This gives you:

pcm.onboard {
type hw
card 1
}
ctl.onboard {
type hw
card 1
}

pcm.hdmi {
type hw
card 0
}
ctl.hdmi {
type hw
card 0
}

Now the names "onboard" and "hdmi" are defined.

The next bit is the DMIXers. You need them to allow different programs to set different sample rates.

Here you had "internal", which wasn't defined. Changing this to "onboard", which _is_ defined, makes it look like this:

pcm.internalDmix {
type dmix
ipc_key 1024
slave {
pcm "onboard"
channels 2
}
bindings {
0 0
1 1
}
}

pcm.hdmiDmix {
type dmix
ipc_key 2048
slave {
pcm "hdmi"
channels 2
}
bindings {
0 0
1 1
}
}

Finally, your router:

pcm.both {
type route
slave.pcm {
slaves.a.pcm "internalDmix"
slaves.b.pcm "hdmiDmix"
slaves.a.channels 2
slaves.b.channels 2

bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1

bindings.0.slave b
bindings.0.channel 0
bindings.1.slave b
bindings.1.channel 1
}

ttable.0.0 1
ttable.1.1 1
}

Nothing seems to be wrong here.

And your output defaults.

pcm.!default {
type plug
slave {
pcm both
}
}

ctl.!default {
type hw
card 1
}

Note how I changed the CTL default to be a number here again?

Now, I have no way to test this, but it should give you a nudge in the right direction.

- Melanie

maples 08-20-2015 05:58 PM

Thanks for the reply!

Unfortunately, your suggestion did not help. Just to double-check, here is the latest asound.conf:
Code:

[anthony@newerLaptop ~]$ cat /etc/asound.conf
# Have output to both normal sound card and hdmi audio
# Based very heavily on this article:
# http://slack4dummies.blogspot.com/2012/02/alsa-multiple-output-multiple-sound.html

pcm.internal {
        type hw
        card 1
}
ctl.internal {
        type hw
        card 1
}

pcm.hdmi {
        type hw
        card 0
        device 3
}

ctl.hdmi {
        type hw
        card 0
        device 3
}

pcm.internalDmix {
        type dmix
        ipc_key 1024
        slave {
                pcm "internal"
                channels 2
        }
        bindings {
                0 0
                1 1
        }
}

pcm.hdmiDmix {
        type dmix
        ipc_key 2048
        slave {
                pcm "hdmi"
                channels 2
        }
        bindings {
                0 0
                1 1
        }
}

pcm.both {
        type route
        slave.pcm {
                slaves.a.pcm "internalDmix"
                slaves.b.pcm "hdmiDmix"
                slaves.a.channels 2
                slaves.b.channels 2

                bindings.0.slave a
                bindings.0.channel 0
                bindings.1.slave a
                bindings.1.channel 1

                bindings.0.slave b
                bindings.0.channel 0
                bindings.1.slave b
                bindings.1.channel 1
        }

        ttable.0.0 1
        ttable.1.1 1
}

pcm.!default {
        type plug
        slave {
                pcm internalDmix
        }
}

ctl.!default {
        type hw
        card 1
}

If it helps, this /etc/asound.conf makes the internal speakers work (no HDMI):
Code:

[anthony@newerLaptop ~]$ cat /etc/asound.conf | grep -v "#"

pcm.internal {
        type hw
        card 1
}
ctl.internal {
        type hw
        card 1
}



pcm.internalDmix {
        type dmix
        ipc_key 1024
        slave {
                pcm "internal"
                channels 2
        }
        bindings {
                0 0
                1 1
        }
}



pcm.!default {
        type plug
        slave {
                pcm internalDmix
        }
}

ctl.!default {
        type hw
        card 1
}


maples 08-28-2015 05:02 PM

I think I'm going to leave good enough alone.

Also, I was directed to a "more correct" method on the debian-user mailing lists: https://lists.debian.org/debian-user.../msg00985.html

Quote:

To select the order of the devices for one particular device (your case):

Code:

options snd-hda-intel index=1,0

This has the added benefit of making my internal microphone work. I don't use it often so I didn't even realize that it wasn't working; but it does now. :)


All times are GMT -5. The time now is 05:56 PM.