HOW-TO : Configure multiple simultaneous audio outputs in linux (hdmi,spdif,analog)
#1
HOW-TO : Configure multiple simultaneous audio outputs in linux (hdmi,spdif,analog)

This is designed around an ION1 board. You may need to change the device names for it to work on your hardware (see bottom of post).

output devices to use:
  • cloned_output if you want simultaneous hdmi, spdif and analog output
  • hdmiout if you want dmix for crossfading support.

caveats :
  • no dmixer (which means crossfading will cause 'unable to initialize audio hardware' errors
  • cant get 7.1 analog output working on my hardware. possibly i have something missconfigured
  • only 2 channel support
  • cannot clone passthrough output. AC3/DTS will not be cloned
  • UI sounds do not seem to use the output device I set. They output via hdmi only

pros :
  • gets multidevice output working without recompiling
  • should work with new audioengine with no modifications

Backup any existing .asoundrc file
Save the following text as /home/xbmc/.asoundrc.
use alsamixer to unmute outputs and set analog output volumes
Code:
#----
# .asoundrc file designed to expand 2 channels through device 'clone_output'
# to output 2 channels to multiple devices
#
# caveats : no mixed output (no crossfading, no multiple applications) also
# sync will drift between the devices (rarely do i see mine drift though)
#
# designed around a nvidia ION1 zotac board. You may need to change
# device names.
# Use aplay -l to find device numbers
#
# questions contact Loto_Bak on forums.xbmc.org
#----

pcm.!default {
    type plug
    slave.pcm "dmixed_hdmi"
    }
#-----
# Single channel dmixed. Crossfade works
#-----
pcm.hdmiout {
    type plug
    slave.pcm "dmixed_hdmi"
}

pcm.dmixed_hdmi {
    type dmix
    ipc_key 2024
    slave {
        pcm "hw:0,3" # hdmi
        }
}
#-----
# multiple output portion begin (3 devices) dmix not supported.
#-----

pcm.clone_output {
    type plug
    slave.pcm "6channel_expander"
        }
        
pcm.multi_pcm_device {
        type multi;
        slaves.a.pcm "hw:0,3"; # hdmi
        slaves.a.channels 2;
        slaves.b.pcm "hw:0,0"; # analog
        slaves.b.channels 2;
    slaves.c.pcm "hw:0,1"; # spdif
    slaves.c.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;
        bindings.4.slave c;
        bindings.4.channel 0;
    bindings.5.slave c;
        bindings.5.channel 1;
}
ctl.multi_pcm_device {
        type hw;
        card 0;
}
pcm.6channel_expander {
        type route;
        slave.pcm "multi_pcm_device";
        slave.channels 6;
        ttable.0.0 1;
        ttable.1.1 1;
        ttable.0.2 1;
        ttable.1.3 1;
        ttable.0.4 1;
        ttable.1.5 1;
}
ctl.6channel_expander {
        type hw;
        card 0;
}

How to find replacement device names

using the command
Code:
aplay -l
**** List of PLAYBACK Hardware Devices ****
[b]card 0[/b]: NVidia [HDA NVidia], [b]device 0[/b]: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 1: ALC662 rev1 Digital [ALC662 rev1 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 3: NVIDIA HDMI [NVIDIA HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

To get device names for your hardware look as the following output.
The first entry is analog output as you can see by its name.
It is card 0, and device 0. This means analog device name is hw:0,0
The second entry is digital output (spdif) again seen by its name.
It is card 0, and device 1. This means spdif device name is hw:0,1
The 3rd entry is HDMI, following the same process we get hw:0,3

Do this on your system and replace the three devices on line 40,42,44 and you should be good to go.
Reply
#2
@Loto_Bak

after work i will give it a try. But before i try two questions. With this settings, is there a downmix from dts possible ? Background is following situation:

AC3 and DTS should play over spif to my av-Receiver when i watch movies over my beamer.
AC3 and DTS should play over hdmi on my TV when my childrens watch movies. My TV couldn´t play DTS sound so there must a downmix.

How must i set my audio settings in xbmc to work with your .asoundrc ?

Greets
Eisi
Reply
#3
Short answer, no.

Alsa cannot downmix DTS on its own.
XBMC can but does not at this time.

There are two possible solutions to this,
a) get xbmc to output 7.1 PCM and have alsa downmix these channels while maintaining 7.1 LPCM over HDMI (no multichannel spdif support for this config though)

b) get xbmc to output passthrough and ALSO downmix to 2ch at the same time allowing two outputs to be active.

The guys working on audio dont seem to be very interested in this configuration. Their biggest concern is sound quality being ruined by the two streams being out of sync.
That being said I have been testing this setup with HDMI and analog speakers in the same room and cannot perceive any sync issues.
Reply
#4
@Loto_Bak

sorry for my question, but my english is not so good. Have i any chance to make it so how i want and if yes could you give me a solution perhaps a homepage with an example ?

I think it´s not a problem for me if the audio over hdmi and spif is not syncron, because i hear only one of them at the moment but i need an ac3 perhaps a dts downmix because my tv could not play DTS audio.

Have you an idea how the asoundrc must be looking ?

Greets
Eisi
Reply
#5
Thank you Loto! I'm on a Revo 1600 with HDMI and analog (no SPDIF) and your solution for simultaneous audio streams is the first I have been able to get working in Dharma with my setup (Zone 1: 5.1, Zone 2: 2.0 through a Marantz sr5002). I've modified your .asoundrc to match my system/setup and to allow 6 channel LPCM via HDMI simultaneously with analog output (8 channel LPCM via HDMI should work as well). For some, channel mapping of 5.1/7.1 setups seems to be a problem in Linux but I have not experienced this (issues are more likely caused by windows vs. linux source creation). I did, however, need to swap the analog channels. For reference, my /etc/asound.conf is empty.

In XBMC, "Audio output device" is "Custom", "Custom audio device" is "clone_output", and "Passthrough output device" is "hdmi".
Code:
#----
# .asoundrc file designed to expand 2 channels through device 'clone_output'
# to output 2 channels to multiple devices
#
# caveats : no mixed output (no crossfading, no multiple applications) also
# sync will drift between the devices (rarely do i see mine drift though)
#
# designed around a nvidia ION1 zotac board. You may need to change
# device names.
# Use aplay -l to find device numbers
#
# questions contact Loto_Bak on forums.xbmc.org
#----

pcm.!default {
    type plug
    slave.pcm "dmixed_hdmi"
    }
#-----
# Single channel dmixed. Crossfade works
#-----
pcm.hdmiout {
    type plug
    slave.pcm "dmixed_hdmi"
}

pcm.dmixed_hdmi {
    type dmix
    ipc_key 2024
    slave {
        pcm "hw:0,3" # hdmi
        }
}
#-----
# multiple output portion begin (2 devices) dmix not supported.
#-----

pcm.clone_output {
    type plug
    slave.pcm "10channel_expander"
        }
        
pcm.multi_pcm_device {
        type multi;
        slaves.a.pcm "hw:0,3"; # hdmi
        slaves.a.channels 8;
        slaves.b.pcm "hw:0,0"; # analog
        slaves.b.channels 2;
        bindings.0.slave a;
        bindings.0.channel 0;
        bindings.1.slave a;
        bindings.1.channel 1;
        bindings.2.slave a;
        bindings.2.channel 2;
        bindings.3.slave a;
        bindings.3.channel 3;
        bindings.4.slave a;
        bindings.4.channel 4;
        bindings.5.slave a;
        bindings.5.channel 5;
        bindings.6.slave a;
        bindings.6.channel 6;
        bindings.7.slave a;
        bindings.7.channel 7;
        bindings.8.slave b;
        bindings.8.channel 0;
        bindings.9.slave b;
        bindings.9.channel 1;
}
ctl.multi_pcm_device {
        type hw;
        card 0;
}
pcm.10channel_expander {
        type route;
        slave.pcm "multi_pcm_device";
        slave.channels 10;
        ttable.0.0 1;
        ttable.1.1 1;
        ttable.2.2 1;
        ttable.3.3 1;
        ttable.4.4 1;
        ttable.5.5 1;
        ttable.6.6 1;
        ttable.7.7 1;
        ttable.1.8 1;
        ttable.0.9 1;
        ttable.2.8 1;
        ttable.2.9 1;
}
ctl.10channel_expander {
        type hw;
        card 0;
}
You can test your multichannel system by using this 8 channel test file.

If you find your channels are not mapped properly, try these remapping them like this:
Code:
ttable.0.0 1;
        ttable.1.1 1;
        ttable.2.4 1;
        ttable.3.5 1;
        ttable.4.2 1;
        ttable.5.3 1;
        ttable.6.6 1;
        ttable.7.7 1;
        ttable.0.8 1;
        ttable.1.9 1;
        ttable.4.8 1;
        ttable.4.9 1;

Thanks again for your work and willingness to share and hopefully others can benefit from these configurations.
Reply
#6
I tried this, but it's sadly not working for me (AsRock ION 330HT).

Can't get that analog out working. I suspect it has something to do with my /etc/asound.conf file also needing an edit but I'm too much of a Linux idiot to be able to mess with that...

Thanks anyway - guess I'll have to try and find another source for my Zone 2 input.
Reply
#7
Eisi2005
No we cant downmix, sorry

Belgium
.asoundrc should override everything for that user. try using the command
Code:
aplay --device=clone_output /path/to/some/wav/file/youhave.wav
to test. It will provide text output that can provide clues.

danofun
Glad to see someone else finds it useful. Alsa configs can be a pain in the ass so i figured I would share.

I might suggest a tweak for you multichannel downmix. if you add
Code:
ttable.5.8 1;
        ttable.5.9 1;
I'm not sure which channel number is the 'center' channel. I used 5 in this example
This would mix center channel into the left/right channel. During movies L/R does not always contain dialog so it could be beneficial.
(sytax for ttable is "ttable.inputchannel.outputchannel volume" you might experiment with other values instead of 1 such as .5 or .75)

Thanks for sharing your changes too.
Reply
#8
@Loto_Bak

not the answer i wan´t to hear but THX Smile

Greets
Eisi
Reply
#9
@Loto_Bak

You rock, and now so do I! Thank you for posting this. I was able to do a minor tweak and get my Arcam rDac and my analog output to work simultaneously.

For anyone else looking to get their Arcam working rDac the key for me was using the alsa "plughw:X,Y" device. Also, here's my hacked .asoundrc:

# .asoundrc file designed to expand 2 channels through device 'clone_output'
# to output 2 channels to multiple devices
#
# caveats : no mixed output (no crossfading, no multiple applications) also
# sync will drift between the devices (rarely do i see mine drift though)
#
# designed around a nvidia ION1 zotac board. You may need to change
# device names.
# Use aplay -l to find device numbers
#
# questions contact Loto_Bak on forums.xbmc.org
#----
pcm.!default {
type plug
slave.pcm "dmixed_hdmi"
}
#-----
# Single channel dmixed. Crossfade works
#-----
pcm.hdmiout {
type plug
slave.pcm "dmixed_hdmi"
}

pcm.dmixed_hdmi {
type dmix
ipc_key 2024
slave {
pcm "hw:0,3" # hdmi
}
}
#-----
# multiple output portion begin (3 devices) dmix not supported.
#-----

# use "clone_output" in XBMC for custom settings.
pcm.clone_output {
type plug
slave.pcm "6channel_expander"
}

pcm.multi_pcm_device {
type multi;
slaves.a.pcm "hw:0,3"; # hdmi
slaves.a.channels 2;
slaves.b.pcm "hw:0,0"; # analog
slaves.b.channels 2;
slaves.c.pcm "plughw:2,0"; # arcam
slaves.c.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;
bindings.4.slave c;
bindings.4.channel 0;
bindings.5.slave c;
bindings.5.channel 1;
}

ctl.multi_pcm_device {
type hw;
card 0;
}
pcm.6channel_expander {
type route;
slave.pcm "multi_pcm_device";
slave.channels 6;
ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1;
ttable.1.3 1;
ttable.0.4 1;
ttable.1.5 1;
}
ctl.6channel_expander {
type hw;
card 0;
}
Reply
#10
Not sure what I have to do here, but this is my scenario/problem.

Using XBMC Live, 10.1 on a Zotac box (don't know exactly which one at the moment). I have an Onkyo 616 that I have configured for a powered zone 2. Zone 2 has to be analog, so it won't take the sound from a digital input and fire it out to the speakers. I figured I'd use the headphone jack on the Zotac, split it to RCA connection and plug it into another input on the Onkyo. I get nothing. So, I just plugged in headphones... still nothing. Must be a config issue. I copied the code from the OP, rebooted, still nothing. I ran aplay -l and my device names are the same as the OP. What should my Audio Output section look like in the settings? There are passthru's and HDMIs and whatnot and I don't quite get what I'm supposed to do.
Reply
#11
bump. Anyone? see my last post.
Reply

Logout Mark Read Team Forum Stats Members Help
HOW-TO : Configure multiple simultaneous audio outputs in linux (hdmi,spdif,analog)0