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?

Previous Essays


Quick One-Positional-Argument Function Currying In Python
originally posted: 2011-11-01 14:48:12

Function "currying" in Python means pre-adding arguments to a function. If you have a function that takes two arguments, you can create a new function from it that only takes one, if you can somehow automatically set the second parameter. (My understanding is that the term "curry" isn't totally correct here; the correct mathematical term would be "partial application". Calling this "currying" is but one of the Python...

Continue reading Quick One-Positional-Argument Function Currying In Python


Rise From Your Grave
originally posted: 2011-11-01 14:44:23

It's been three years since I last posted. I have an excuse: in April of 2007 I got me a Internet Job! And sadly it's left me no time for essay-writing.

But I'm gonna try and revive my blog. To that end, I've finally added a reStructuredText renderer to my homegrown blogging tool PySa. Previously I had to write blog entries in HTML; precise but laborious. Now that I can write in ReST perhaps I can knock out essays a bit faster.

Also, my blog is now...

Continue reading Rise From Your Grave


Floating-Point Numbers Are Precise!
originally posted: 2010-05-22 09:47:31

(What they lack is accuracy!)

There's a great deal of misunderstanding about floating-point numbers. Better men than I have tried to dispell the haze of confusion that surrounds them. But let me make a start.

One source of confusion is when people think of floating-point numbers as approximations. That's muddy thinking. A floating-point number is not approximately anything; it's an exact value. The problem is that it may not be the value you wanted.

If I...

Continue reading Floating-Point Numbers Are Precise!


The Lost Monty Python Cartoon
originally posted: 2007-03-18 07:58:57

Last summer I was showing my oldest nephew some Monty Python. Specifically, I showed him episode 24: How Not To Be Seen. It's a corker of an episode, full of great sketches—a playwright who is fascinated by train timetables (and his commenter), Conquistador Coffee, a movie director with gigantic teeth, a survey of ludicrous religions, and of course the eponymous sketch.

At the very end of the episode, just after the end credits, an announcer (played by Eric Idle)...

Continue reading The Lost Monty Python Cartoon


Older essays...

About Momentary Fascinations

RSS

Recent Fascinations

Quick One-Positional-Argument Function Currying In Python

Rise From Your Grave

Floating-Point Numbers Are Precise!

The Lost Monty Python Cartoon

All Essays

Years

2012

2011

2010

2009

2008

2007

2006

2005

Tags

books

entertainment

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-2012 Larry Hastings.