Getting 7.1 HDMI Audio Working Under Ubuntu

permalink         categories: technology         originally posted: 2011-11-19 23:40:01

I run Ubuntu and XBMC on my home theater PC (hereafter HTPC). I connect my HTPC to my receiver and TV via HDMI. The HTPC is an nVidia ION 2 machine, so it's using nVidia's HDMI implementation. I also have a full 7.1 speaker system. But out-of-the-box, Ubuntu refused to recognize my full 7.1 system. All it would let me choose were stereo and 5.1 configurations.

After beating my head against this for a day or two I finally stumbled on the solution. The trick is knowing what to change and where. I had to figure it out for Ubuntu 11.04, and then remember what I did when I upgraded to 11.10, so I thought I'd make a blog post for posterity's sakes—so I'll know where to look when I upgrade to 12.04 ;-)

The problem is that PulseAudio has no way of knowing which speakers you have hooked up. HDMI supports up to 8 channels, but the receiver apparently can't tell the computer how many of them are in use. So what does PulseAudio do? It ships with some hard-coded defaults and calls it a day. Here are its defaults:

Digital Stereo (HDMI)
Digital Stereo (HDMI) nr 2
Digital Stereo (HDMI) nr 3
Digital Stereo (HDMI) nr 4
Digital Surround 5.1 (HDMI)
Digital Surround 5.1 (HDMI) nr 2
Digital Surround 5.1 (HDMI) nr 3
Digital Surround 5.1 (HDMI) nr 4

Notice, no 2.1, and no 7.1 configurations. Let's fix it!

Open up the Ubuntu Sound control panel on your HTPC and go to the Hardware tab. Choose your HDMI sound device in the big chooser. Below that is the "Profile" drop-down box. Click on it, and notice that the only choices you get are the defaults I've listed above.

Your first job: figure out which HDMI channel you're using. That's what those "nr 2" "nr 3" and "nr 4" suffixes mean on the profiles. Just try each of the four 5.1 choices in turn and play some audio to see if you hear anything. One of them should work. For example, on my system I have to use "nr 2".

Now sudo to root, and edit the file:

/usr/share/pulseaudio/alsa-mixer/profile-sets/extra-hdmi.conf

This is an INI-format file. Find the string identifying the profile that worked (in my case, "Digital Surround 5.1 (HDMI) nr 2"). It'll be near the top of an INI "section" that looks something like this:

[Mapping hdmi-surround-extra1]
description = Digital Surround 5.1 (HDMI) nr 2
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 1
direction = output

Copy and paste that entire paragraph of text. Then change the "section title" to some unique string, change the description to another unique string (probably including the string "7.1" in it somewhere), and add the text:

,side-left,side-right

to the end of the "channel-map" line. My resulting INI section looked like this:

[Mapping hdmi-surround-extra-larry]
description = Digital Surround 7.1 (HDMI) nr 2
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
priority = 1
direction = output

Now save the file, and... you're done! Theoretically you only need to restart PulseAudio, but it's easiest to just reboot. After the reboot, you should now see your 7.1 profile on the Hardware tab of the Sound control panel, and once you select it all eight of your speakers should now Just Work.

So why doesn't PulseAudio ship with this configuration? The ever-opinionated Lennart Poettering points out, entirely correctly, that HDMI allows remapping the eight channels to the eight speakers any way you like. So it's possible that a default mapping like this would be incorrect. However, as far as I know, basically everybody enumerates the eight channels of a 7.1 system in this order. (My brother works in the audio processing industry and assures me this is true.) Also, if HDMI is so flexible and unpredictable, then why ship the 5.1 mappings above? Those could be wrong too! This strikes me as a strange, inconsistent, and ultimately unhelpful stance on the part of Mr. Poettering. But it's easily fixed, and in any case I'm grateful to Mr. Poettering for his work over the years on PulseAudio. So I don't want to give him too much grief. Let's just fix it by hand and hope there's a better solution in the future, shall we?

About Momentary Fascinations

RSS

Recent Fascinations

A Eulogy For Bob Bailey

A Quick 2017 Survey Of Rolling Linux Distributions

An Adventure In Buying Home Audio Speakers

The 2014 Lenovo X1 Carbon: Lenovo Giveth, And Lenovo Taketh Away

All Essays

Years

2017

2014

2013

2011

2010

2007

2006

2005

Tags

books

entertainment

eulogies

game jones

general

meta

music

politics

programming

repeat-1 song of the day

tales of the self-indulgent

technology

trampled liberties

video games

Momentary Fascinations is Copyright 2005-2020 Larry Hastings.