Outputting sound on multiple interfaces at the same time

My HTPC is connected with an HDMI cable to my receiver and TV. Because I have an extra set of speakers which I use when listening to music, I wanted to connect them to my HTPC too. The problem is that those speakers don’t have an HDMI input, so analog is the only way to go. It turns out that when you’re using Alsa, you can combine multiple audio-interfaces in Ubuntu very easily and your music even plays synchronised over all the selected outputs.

List all audio interfaces

sudo aplay -l
[sudo] password for thomas:
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: SB [HDA ATI SB], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: SB [HDA ATI SB], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

In this case I wanted to use card0,3 and card1,0 (HDMI and analog interface).

The configfile

/etc/asound.conf

pcm.2asone_ATISB_dmix {
    type dmix
    ipc_key 170300
    # "hw:1,0" is HDMI
    slave.pcm "hw:1,0"
}

pcm.2asone_ATIHDMI_dmix {
    type dmix
    ipc_key 170310
    # "hw:0,3 is analog
    slave.pcm "hw:0,3"
}

pcm.2sndcardas1 {
    type multi
    slaves.a.pcm "2asone_ATISB_dmix"
    slaves.a.channels 2
    slaves.b.pcm "2asone_ATIHDMI_dmix"
    slaves.b.channels 2

    bindings.0.slave a
    bindings.0.channel 0
    bindings.1.slave a
    bindings.1.channel 1
    bindings.2.slave b
    bindings.2.channel 0
    bindings.3.slave b
    bindings.3.channel 1
}

pcm.2asone {
    type route
    slave.pcm "2sndcardas1"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}

# duplex device combining our PCM devices defined above
pcm.2asone_asym {
    type asym
    playback.pcm "2asone"
    capture.pcm "mic_dsnoop"
}

Make the dual output interface system default

When you append the following snippet to your Alsa-config file. The dual output interface will be set as system default. I’ve been using this for 2 hours, but my music was being interrupted with a lot of plops. Removing theses lines and manually selecting the 2asone_asym-interface gave me the same functionality without the plops.

# Uncomment this to make the output
# to both sound card as system default
pcm.!default {
   type plug
   slave.pcm "2asone_asym"
}

Got no sound after these changes?

Apparently Alsa creates new interfaces muted as default. Open alsamixer in your terminal, choose the correct interface and type M to unmute.

comments powered by Disqus