Linux HOW-TO: S/PDIF from Asus Xonar U7
#1
Introduction
Have you bought an Asus Xonar U7 with the intent to use its S/PDIF interface on a Linux-based Kodi install? Congrats, you're in for some manual labour. After serveral late nights of research, trial, error, moments of doubt and dispair where I thought I would just go ahead and buy a different interface for this task, I think I have cracked it now.

While it may be entirely possible that my struggle was due to my own ignorance and poor search skills, this HOW-TO is to consolidate my own findings for future reference, as well as a service to you who might be contemplating on buying this device but wondering whether it'll work or have already bought it and, like me, have hit one of the obstacles of getting this thing to work.

Test system specs
-Intel i3-Haswell NUC D34010WYK
-Asus Xonar U7 connected to Arcam AV8 (Coaxial)
-Kodibuntu (Ubuntu 14.04 LTS i386)
-Kodi 16.0 beta 4

Objective
Enable Kodi audio including AC3/DTS passthrough via S/PDIF to AVR without any kind of resampling or transcoding.

About the Asus Xonar U7 and Linux
The Xonar U7 is based on the CM6632A chip. In principle it's supported by ALSA using the snd-usb-audio module, however there are a two caveats using its S/PDIF channel:
-by default S/PDIF channels are muted in ALSA. It can be unmuted by using amixer, however upon selecting the U7 card, amixer crashes with a 'Broken pipe' error.
-by default, the snd-usb-audio module assumes that the iec958 (S/PDIF) interface is on the first device of a given card, however on the CM6632A chip it's the second. This causes Kodi to output the S/PDIF stream to the analogue output, obviously to no avail.

Assumptions
This How-To assumes that you're running the Asus Xonar U7 on a Debian based system using ALSA directly and have PulseAudio removed. If you need PulseAudio maybe this How-To contains a few useful pointers to get the underlying stuff in urder, but as I don't use it myself you're on your own in adapting these into a working PulseAudio setup. If you have PulseAudio installed and you wish to remove this, (assuming you run a Debian-based distro) run:
Code:
sudo apt-get autoremove pulseaudio


Prerequisites
-Working Kodi installation (i.e. can play audio/video without errors using other audio hardware)
-alsa-utils installed
-mplayer installed (optional)


Step-by-step Instructions
Job description
So we've got a couple of things to do here:
1. Fix broken pipe error in amixer
2. Unmute S/PDIF channel
3. Fix IEC958 device index in snd-usb-audio module
4. Configure Kodi Audio Output

Step 1. Fix broken pipe error in amixer
The problem occurs when trying to use amixer or alsamixer with the U7 card, e.g.:
Code:
~$ amixer -c2
amixer: Mixer hw:2 load error: Broken pipe
~$ alsamixer -c2
cannot load mixer controls: Broken pipe

To fix the error, we have to add a small line to the /etc/modprobe.d/alsa-base.conf file. To just append from the commandline, run:
Code:
~$ echo -e '\n#fix broken pipe in alsamixer for Xonar U7\noptions snd-usb-audio ignore_ctl_error=1' | sudo tee -a /etc/modprobe.d/alsa-base.conf

or use your favourite editor to manualy edit the file and add this to the end:

Code:
...

#fix broken pipe in alsamixer for Xonar U7
options snd-usb-audio ignore_ctl_error=1

Once sorted, reload ALSA:

Code:
~$ sudo alsa force-reload


Step 2. Unmute S/PDIF channel
Now that we've fixed the broken pipe error, we can unmute the S/PDIF channel so we can actualy hear some output. First find the card index of the U7. For this we use aplay -l (annotated U7 device):

Code:
~$ 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 1: PCH [HDA Intel PCH], device 0: ALC283 Analog [ALC283 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: U7 [Xonar U7], device 0: USB Audio [USB Audio]      <== 7.1 analogue output
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: U7 [Xonar U7], device 1: USB Audio [USB Audio #1]   <== S/PDIF output
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: U7 [Xonar U7], device 2: USB Audio [USB Audio #2]   <== Headphone output
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Using the card index "2" from this list (depending your hardware configuration this may be a different integer for you), we can unmute the S/PDIF channel using amixer like so:

Code:
~$ amixer -c2 sset 'IEC958 In' on
Simple mixer control 'IEC958 In',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]

Alternatively, use alsamixer to navigate to the proper channel with the arrow keys and use 'm' to unmute.

Test the output to your AVR, DAC or whatever you've connected to the U7 using the speaker-test utility:

Code:
~$ speaker-test -Dhw:2,1 -c2

speaker-test 1.0.27.2

Playback device is hw:CARD=U7,DEV=1
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 32 to 262144
Period size range from 16 to 131072
Using max buffer size 262144
Periods = 4
was set period_size = 65536
was set buffer_size = 262144
0 - Front Left
1 - Front Right
...

If you hear the pink noise coming from your speakers it means that you can now succesfully playback audio using the S/PDIF interface. Use ctrl-c to exit the speaker-test.
Remember that S/PDIF is a two-channel LPCM protocol, so without further AC3 or DTS encoding (i.e.: compression) we're still just using two channels. To test surround encoding, we can use mplayer with a proper AC3 or DTS encoded file (or alternatively skip the rest of this step and wait for testing within Kodi).

Code:
mplayer -afm hwac3 -ao alsa:device=hw=2.1 [yourfileac3ordtsaudiovideofile]

NOTE: where in aplay et al there was a comma in between the card and device index, this is now a decimal.

For testing purposes, you can download one of the Dolby, DTS or THX trailers from e.g. http://thedigitaltheater.com/index.php/dolby-trailers/ , or you can just use any video file in your collection that has a proper AC3 or DTS layer encoded.

Step 3. Fix IEC958 device index in snd-usb-audio module
The problem with snd-usb-audio module is that it 'assumes' the S/PDIF interface to be located at the first device (DEV=0) on the card while as mentioned before the S/PDIF interface of the CM6632A chip is the second (DEV=1):

Code:
~$ aplay -L | grep -A 2 iec958
iec958:CARD=U7,DEV=0
    Xonar U7, USB Audio
    IEC958 (S/PDIF) Digital Audio Output

This is a problem because it is this interface that Kodi will want to use for Passthrough and it is sending the S/PDIF signal to the analogue output.

The snd-usb-audio module depends on a couple of definitions in the /usr/share/alsa/cards/USB-Audio.conf. Although 'not the Linux way' to make any change here, using the method as suggested in said file doesn't have the desired outcome for me. I welcome any working suggestion to do this in better fashion, but until then I suggest applying the fix by directly patching this file:

Code:
~$ sudo nano /usr/share/alsa/cards/USB-Audio.conf

Find and the 'USB-Audio.pcm.iec958_device' clause and add '"Xonar U7" 1' between the curly braces:

Code:
...
# If a device does not use the first PCM device for digital data, the device
# number for the iec958 device can be changed here.
USB-Audio.pcm.iec958_device {
        # "NoiseBlaster 3000" 42
        "Xonar U7" 1
...

}

...

Reload ALSA and check our work:

Code:
~$ sudo alsa force-reload

Code:
~$ aplay -L | grep -A 2 iec958
iec958:CARD=U7,DEV=0
    Xonar U7, USB Audio #1
    IEC958 (S/PDIF) Digital Audio Output

Note that while the first line still mentioned "DEV=0", the second line now includes the [b]"#1"[b] suffix.

You can check the audio coming from the speakers again by using speaker-test:

Code:
~$ speaker-test -Diec958:CARD=U7,DEV=0 -c2

speaker-test 1.0.27.2

Playback device is iec958:CARD=U7,DEV=0
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 32 to 262144
Period size range from 16 to 131072
Using max buffer size 262144
Periods = 4
was set period_size = 65536
was set buffer_size = 262144
0 - Front Left
1 - Front Right
...

4. Configure Kodi Audio Output
Now that we have sorted out the difficulties, we can configure the Audio and any specifics depening your AVR through the System/System/Audio Output as described on http://kodi.wiki/view/Settings/System#Audio_output. Make sure you have the settings level at least up to Advanced to be able to seperately configure the Audio output and Passthrough devices.

Enjoy a working S/PDIF output from Kodi!

Edit: fixed formatting
Reply

Logout Mark Read Team Forum Stats Members Help
HOW-TO: S/PDIF from Asus Xonar U70