USB and HDMI audio at the same time

I’ve added a USB audio device to my Vero for my wireless headphones. At this point I need to manually switch from HDMI audio to USB audio when I move from the soundbar to my headphones.

How can I get the Vero to output audio to both HDMI and USB?

Cheers,
Ian

We may add a patch to support dual audio in the future

Sam

Is there not something I can do in the meantime? Will installing ALSA help?

I have alsa working. aplay -l and aplay -L produce the following outputs, respectively:


root@osmc:/etc# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: imxspdif [imx-spdif], device 0: S/PDIF PCM snd-soc-dummy-dai-0
Subdevices: 0/1
Subdevice #0: subdevice #0
card 1: imxhdmisoc [imx-hdmi-soc], device 0: i.MX HDMI Audio Tx hdmi-hifi-0
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0


root@osmc:/etc# aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=imxspdif
imx-spdif,
Default Audio Device
sysdefault:CARD=imxspdif
imx-spdif,
Default Audio Device
iec958:CARD=imxspdif,DEV=0
imx-spdif,
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=imxspdif,DEV=0
imx-spdif,
Direct sample mixing device
dsnoop:CARD=imxspdif,DEV=0
imx-spdif,
Direct sample snooping device
hw:CARD=imxspdif,DEV=0
imx-spdif,
Direct hardware device without any conversions
plughw:CARD=imxspdif,DEV=0
imx-spdif,
Hardware device with all software conversions
default:CARD=imxhdmisoc
imx-hdmi-soc,
Default Audio Device
sysdefault:CARD=imxhdmisoc
imx-hdmi-soc,
Default Audio Device
hdmi:CARD=imxhdmisoc,DEV=0
imx-hdmi-soc,
HDMI Audio Output
dmix:CARD=imxhdmisoc,DEV=0
imx-hdmi-soc,
Direct sample mixing device
dsnoop:CARD=imxhdmisoc,DEV=0
imx-hdmi-soc,
Direct sample snooping device
hw:CARD=imxhdmisoc,DEV=0
imx-hdmi-soc,
Direct hardware device without any conversions
plughw:CARD=imxhdmisoc,DEV=0
imx-hdmi-soc,
Hardware device with all software conversions
default:CARD=Device
USB PnP Sound Device, USB Audio
Default Audio Device
sysdefault:CARD=Device
USB PnP Sound Device, USB Audio
Default Audio Device
front:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Front speakers
surround21:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct sample mixing device
dsnoop:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct sample snooping device
hw:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct hardware device without any conversions
plughw:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Hardware device with all software conversions


I can manipulate the /etc/asound.conf file to default to the USB sound card by modifying it from:

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

to:
defaults.ctl.card 2
defaults.pcm.card 2

But I can’t seem to get OSMC to recognize anything other than the device number for the card. Any hints on how I might be able to change the asound.conf file that OSMC will recognize a card name instead?

Cheers,
Ian

{Crickets}

I’m going to continue to try to figure this out. Would be nice is someone could lend a hand though…

Here’s a really basic test of what I’m talking about…

/etc/asound.conf:


pcm.test {
type hw
card 2
}

defaults.pcm.!card test
defaults.ctl.card 2


But aplay gives me a error…

root@osmc:/etc# aplay /usr/share/sounds/alsa/Front_Center.wav

ALSA lib confmisc.c:768:(parse_card) cannot find card ‘test’
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such device
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such device
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such device
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:722: audio open error: No such device

This is about as simple as I can make it. What am I missing?

Cheers,
Ian

Ok, one of type-writing monkeys managed to come up with an asound.conf that I can use to play audio on both hdmi and USB using “aplay /usr/share/sounds/alsa/Front_Center.wav

The problem is that KODI errors out with a Sad Face on boot.

new asound.conf:


pcm.!default plug:both

ctl.!default {
type hw
card 1
}
pcm.both {
type route;
slave.pcm {
type multi;
slaves.a.pcm “pcmhdmi”;
slaves.b.pcm “pcmusb”;
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.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}
ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1; # front left
ttable.1.3 1; # front right
}
ctl.both {
type hw;
card 1;
}
pcm.pcmusb {
type share
slave.pcm “plughw:2,0”
bindings {
0 0
1 1
}
}
pcm.pcmhdmi {
type share
slave.pcm “plughw:1,0”
bindings {
0 0
1 1
}
}
ctl.pcmusb {
type hw
card 2
}
ctl.pcmhdmi {
type hw
card 1
}


Relevant JournalCtl output:


Jan 02 12:15:34 osmc mediacenter[352]: Starting Kodi…
Jan 02 12:15:34 osmc sudo[455]: root : TTY=unknown ; PWD=/ ; USER=osmc ; COMMAND=/usr/lib/kodi/kodi.bin --standalone -fs --lircdev /var/run/lirc/lircd
Jan 02 12:15:34 osmc sudo[455]: pam_unix(sudo:session): session opened for user osmc by (uid=0)
Jan 02 12:15:34 osmc kernel: cfg80211: Calling CRDA to update world regulatory domain
Jan 02 12:15:34 osmc mediacenter[352]: unknown
Jan 02 12:15:34 osmc mediacenter[352]: *** Error in `/usr/lib/kodi/kodi.bin’: free(): corrupted unsorted chunks: 0x03e0c9d8 ***
Jan 02 12:15:34 osmc sudo[455]: pam_unix(sudo:session): session closed for user osmc


The corrupted unsorted chunks error does not appear on a successful boot so I’m guessing that it’s the next breadcrumb to follow… does anyone know what it means or, more importantly, how to correct it?

More info on a different tangent…

I found this post:

http://forum.kodi.tv/showthread.php?tid=208403

which referred me to this site, which has a sample asound.conf script:

http://ehelion.net/projects/alsa/alsa.html

I modified the asound.conf there to this:


# ~/.asoundrc or /etc/asound.conf
# ALSA configuration file

##### DEVICE NAMES #####
# This configuration file defines four devices for use by the user.
# Those devices are "analog", "mixed-analog", "digital", "mixed-digital", and "xbmc".
# The user may also re-define "default" to be identical to one of the above-named devices
# (i.e. to send all sound output to the digital output unless otherwise specified).
# Use the device names as described below:
#  - "analog" outputs to the analog output directly and (at least on software sound cards)
#  blocks other audio output.  After playback completes, "queued" sounds are output in sequence.
#  - "mixed-analog" mixes audio output from multiple programs into the analog output
#  (so you can hear beeps, alerts, and other noises while playing back an audio stream)
#  - "digital" outputs to the digital output directly.  Since most (all?)
#  digital outputs expect 48kHz PCM audio, this may not work for some playback
#  (i.e. CD's--which are 44.1kHz PCM audio--or 32kHz audio streams from TV recordings, etc.)
#  - "mixed-digital" mixes audio output from multiple programs into the digital output.
#  - "xbmc" outputs 6channels to digital (hdmi) as well as stereo to analog.
#  Set Custom Output Device in XBMC to "xbmc" and Custom Passthrough Device to "digital".

# All other devices created within this file are used only by the configuration
# file itself and should /not/ be used directly.  In other words, do not use
# the devices "analog-hw", "dmix-analog", "digital-hw", or "dmix-digital".


##### IMPORTANT #####
# To make this ALSA configuration file work with your sound card, you will need
# to define the appropriate card and device information for the "analog-hw" and
# "digital-hw" devices below.  You can find the card and device information
# using "aplay -l".


# Make joint analog/HDMI the default
pcm.!default {
    type plug
    slave {
        pcm "multi"
        #rate 48000
    }
    
    # digital mixing
    ttable.0.0 1    # copy front left  to front left  digital @ 100%
    ttable.1.1 1    # copy front right to front right digital @ 100%
    
    # analog mixing
    ttable.0.2 1    # copy front left  to front left  analog  @ 100%
    ttable.1.3 1    # copy front right to front right analog  @ 100%
}
# Default control device (mixer, etc.) for the card
ctl.!default {
    type hw
    card 0
}


# Alias for (converted) analog output on the card
# - This is identical to the device named "default"--which always exists and
# refers to hw:0,0 (unless overridden)
# - Therefore, we can specify "hw:0,0", "default", or "analog" to access analog
# output on the card
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
# "default" to do mixing, meaning this device is different from "default" and
# allows playback while blocking other sound sources (until playback
# completes).
pcm.analog {
    type plug
    slave.pcm "analog-hw"
    hint {
        show on
        description "Analog Output - Use analog outputs, converting samples, format, and rate as necessary."
    }
}
# Control device (mixer, etc.) for the card
ctl.analog {
    type hw
    card 0
}

# Alias for (converted) mixed analog output on the card
# - This will accept audio input--regardless of rate--and convert to the rate
# required for the dmix plugin (in this case 48000Hz)
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
# "default" to do mixing, meaning this device is identical to "default" for
# "software" sound cards.
pcm.mixed-analog {
    type plug
    slave.pcm "dmix-analog"
    hint {
        show on
        description "Mixed Analog Output - Use analog outputs, converting samples, format, and rate as necessary. Allows mixing with system sounds."
    }
}
# Control device (mixer, etc.) for the card
ctl.mixed-analog {
    type hw
    card 0
}


# Alias for (converted) digital (HDMI) output on the card
pcm.digital {
    type plug
    slave.pcm "digital-hw"
    hint {
        show on
        description "Digital Output - Use digital outputs, converting samples, format, and rate as necessary."
    }
}
# Control device (mixer, etc.) for the card
ctl.digital {
    type hw
    card 1
}


# Alias for mixed (converted) digital (HDMI) output on the card
pcm.mixed-digital {
    type plug
    slave.pcm "dmix-digital"
    hint {
        show on
        description "Mixed Digital Output - Use digital outputs, converting samples, format, and rate as necessary. Allows mixing with system sounds."
    }
}
# Control device (mixer, etc.) for the card
ctl.mixed-digital {
    type hw
    card 1
}


# The following devices are not useful by themselves.  They require specific
# rates, channels, and formats.  Therefore, you probably do not want to use
# them directly.  Instead use one of the devices defined above.

# Alias for analog output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.analog-hw {
    type hw
    card 2
    device 0
}
# Control device (mixer, etc.) for the card
ctl.analog-hw {
    type hw
    card 2
}


# Alias for digital (HDMI) output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.digital-hw {
    type hw
    card 1
    device 0
}
# Control device (mixer, etc.) for the card
ctl.digital-hw {
    type hw
    card 1
}


# Direct software mixing plugin for analog output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.dmix-analog {
    type dmix
    ipc_key 1234
    slave {
        pcm "analog-hw"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 48000
    }
}
# Control device (mixer, etc.) for the card
ctl.dmix-analog {
    type hw
    card 0
}

# Direct software mixing plugin for digital (S/PDIF) output on the card
# Do not use this directly--it requires specific rate, channels, and format
pcm.dmix-digital {
    type dmix
    ipc_key 1235
    slave {
        pcm "digital-hw"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 48000
    }
}
# Control device (mixer, etc.) for the card
ctl.dmix-digital {
    type hw
    card 1
}


# XBMC specific plug outputting to both analog (stereo) and hdmi (5.1)
pcm.xbmc {
    type plug
    slave.pcm "8channel_expander"
    hint {
        show on
        description "Multichannel output to both analog and hdmi - for use with XBMC"
    }
}
ctl.xbmc {
    type hw
    card 0
}

pcm.multi {
    type multi
    slaves.a.pcm "digital-hw"
    slaves.a.channels 2
    slaves.b.pcm "analog-hw"
    slaves.b.channels 2
    
    # digital (hdmi) bindings
    bindings.0.slave a
    bindings.0.channel 0    # bind alsa channel 0 to front left
    bindings.1.slave a
    bindings.1.channel 1    # bind alsa channel 1 to front right
    
    # analog bindings
    bindings.2.slave b
    bindings.2.channel 0    # bind alsa channel 2 to front left
    bindings.3.slave b
    bindings.3.channel 1    # bind alsa channel 3 to front right
}
ctl.multi {
    type hw
    card 0
}

pcm.8channel_expander {
    type route
    slave.pcm "multi"
    slave.channels 4
    
    # syntax for ttable is "ttable.inputchannel.outputchannel volume"
    # digital mixing
    ttable.0.0 1    # copy front left  to front left  digital @ 100%
    ttable.1.1 1    # copy front right to front right digital @ 100%
    
    # analog mixing
    ttable.0.2 1    # copy front left  to front left  analog  @ 100%
    ttable.1.3 1    # copy front right to front right analog  @ 100%
}
ctl.8channel_expander {
    type hw
    card 0
}

It works - I get audio output through both channels but the OSMC interface is brutally slow so something’s still wrong.

I also found a reference to the Dual Audio project on the Kodi forums:
http://forum.kodi.tv/showthread.php?tid=208403

I suspect that this is what Sam was referring to when he mentioned the possibility of adding dual audio support.

This may be due to resampling.

Re dual-audio patch: yes, I was referring to that, but the way it works seems to not be ideal for Kodi Jarvis, with new DSP addons coming out.

Sam

Hi,

I’ve found this post having the same request. I’m using an USB Dac but want to use sometimes HDMI output to my TV for videos for example.

I’ve followed successfully this post: [Linux] how to get digital audio output through hdmi and spdif simulaneously the default alsa device appear in osmc audio devices and you only have to select this output to get output on both devices.

Just to be clear, can you post your asound.conf file here?

Hi,

Sure, this is exactly the same as the one in the kodi post. Just changed pcm.digital_1 and pcm.digital_2 to fit my configuration. Perhaps as I understand, this configuration only handle stereo channels ? (channels 2 ?)

I don’t know but this is sufficient for me. My logitech remote handle two scenario to get audio or on my HIFI amp or on my TV for two differents usages.

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

pcm.both_digital {
        type route
        slave {
                pcm multi
                channels 4
        }
        ttable.0.0 1.0
        ttable.1.1 1.0
        ttable.0.2 1.0
        ttable.1.3 1.0
}

# Toslink digital_1 output
pcm.digital_1 {
        type hw
        card 0
        device 1
        channels 2
}

# HDMI digital_2 output
pcm.digital_2 {
        type hw
        card 1
        device 0
        channels 2
}

pcm.multi {
        type multi
        slaves.a {
                pcm "digital_1"
                channels 2
        }

        slaves.b {
                pcm "digital_2"
                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
}

Hum … not so good, some videos don’t play on my hifi amp (audio codec ?). Music play on both usb and hdmi, also youtube video but movies I’ve tried play only on hdmi

Hi
I success to make this configuration (with asound.conf) and i can play on both USB and HDMI using aplay.
But my problem is that OSMC dont list the défault device (with slave on multi) and so i cant set OSMC on it.
I notice that OSMC dont list any device with multi Alsa plugin.
If anyone have similar issue ? Thanks