Friday, October 7, 2011

Enabling HDMI audio-out in Ubuntu 10.04 on GeForce 520GT

Happy Thanksgiving weekend everyone!

Not that long ago, I had a sad day where I booted up my desktop and, despite the whirling of the fan and hard drive, nothing appeared on the screen! Oh noes!

Quickly fearing for my monitor, I plugged in my laptop and was promptly greeting with the laptop's bios booting on the monitor.

No problem with the monitor, then. What else? When turning on the computer, and waiting a few moments, I could clearly hear the Ubuntu start-up noise though the speakers despite having no video.

That would indicate processor, ram, and hard drive were all fine. Only guess remaining was a shot-out video card (or perhaps the PCI slot on the MB). Quite sad really, considering the card was less then a year old.

It also wasn't an easy card to get. Having yet to jump on the High Definition TV band wagon, I was still chucking around with my old, 27 inch, 480i, CRT TV. The only input it had was good old fashioned RCA cables. So, when I went video card shopping, I specifically looked for one with S-video out, having years ago purchased an S-video to RCA adapter for just these occasions.

Alas, I found one! Most cards now-a-days lack S-video, going for the HDMI or DVI connectors instead. But I found one at a local store nonetheless (no having to order on line). Furthermore, it was in fact a 7-pin, S-video cable, meaning that I could use it for not only standard definition S-video, but also for (potentially) high definition component video should I ever decide to upgrade my TV (a 7-pin S-video to component adapter was included with the card).

But I never got the chance to try it. I took my tower down to where I bought the video card and explained the situation. The staff was pretty friendly, they took my tower and let me know what they found. I figured it was either the Video Card (or possibly the MB), so either way I'd probably be getting some new hardware. The called me a short while later.

The video card was toast. Unfortunately, they couldn't tell me much more then that, I figure all they did was either try another card in my tower, or my card in another tower. Good news is, it was still under warranty, so they replaced it for free. Bad news: no more S-video cards.

So I ended up with a new card, a nVidia GeForce 520GX. It had D-Sub, DVI and HDMI outputs. I plugged in the DVI, but alas Ubuntu would only boot in Low-graphics mode. So I went to nVidia's site and downloaded the binary driver for Ubuntu and installed it (a bit of Googling revealed the 520Gx wasn't supported by 10.04 open source driver). My DVI port then worked fine, and I was greeted with the full 1920x1080 Ubuntu desktop on my monitor.

Since my monitor also has HDMI, I tried the HDMI output. It worked! As soon as I plugged it in, nvidia-settings picked it up as another monitor and allowed me to activate it.

But now what? I still couldn't plug it into my TV. So I did the only sane thing a geek would do: upgrade! Yep, I decided it was finally time to get a new TV. I won't bore you with the details, but after a week or two of searching, I ended up with a good deal on a 40-inch Sanyo LCD TV that supported HDMI.

So I plugged in the HDMI and was greeted with yet-another 1920 x 1080 desktop on the TV (I decided to use it as a separate X-session). Alas, I didn't find that resolution was very good for the TV (it looks great on my monitor, but despite the TV's size, things were a little hard to read). So I lowered the resolution to 1280 x 720 (720p) and find it much better and readable.

But what about audio? Sure, I could plug the audio cable from my speakers in, like I used to, but HDMI *is* cable of audio output, was it not? Surely, I could figure out how to activate it!

In fact, nVidia themselves have a guide to do just this. But it's not an easy read and requires some addition steps/research. In the end, it wasn't really that bad. Unfortunately, I was lazy at the time and didn't post any instructions. So when it stopped working the other day (more on that later), I couldn't recall everything I needed to do to get it back! I got everything restored without too much trouble, but decided to turn it into an opportunity to write the steps down and post them.

First, check to see that the audio device is being recognized. Do lspci | grep -i nvidia and you should see:

jason@jason-lucidlynx:~$ lspci | grep -i nvidia
05:00.0 VGA compatible controller: nVidia Corporation Device 1040 (rev a1)
05:00.1 Audio device: nVidia Corporation Device 0e08 (rev a1)

The audio device is what you're looking for. I didn't run into a problem with this, so if you don't see it show up, google-is-your-friend. My thinking though is that it's necessary to install the nVidia binary drivers (at the link I pointed out above) before you can get this far.

Once you confirm the hardware is recognized, you *must* make sure your Alsa is up-to-date. Default Alsa with 10.04 is 1.0.21, which is not sufficient for the GeForce 520GX.

Before you upgrade Alsa, you can note your old version:

jason@jason-lucidlynx:~$ cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.21.

Also, aplay -L won't list your HDMI audio output.

jason@jason-lucidlynx:~$ aplay -L
pulse
Playback/recording through the PulseAudio sound server
front:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
Front speakers
surround40:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

Upgrading Alsa is simple. Just follow the instructions here: https://wiki.ubuntu.com/Audio/InstallingLinuxAlsaDriverModules

After that (don't forget to restart after installing alsa!), you should get:

jason@jason-lucidlynx:~$ cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.24.
Compiled on Oct 6 2011 for kernel 2.6.32-34-generic (SMP).

and

jason@jason-lucidlynx:~$ aplay -L
pulse
Playback/recording through the PulseAudio sound server
front:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
Front speakers
surround40:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=SB,DEV=0
HDA ATI SB, VT1818S Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=SB,DEV=0
HDA ATI SB, VT1818S Digital
IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=NVidia
HDA NVidia, HDMI 0
HDMI Audio Output

which will make the HDMI Audio output show up! Cool, eh?

Next thing to do is see if you can get sound out of it, and figure out what hardware audio device it's enumerated as.

This is where the speaker-test utility comes in handy:

speaker-test -c 2 -r 48000 -D hw:0,0

This should cause some static to come out of your left and right main speakers.

After that, I just tried different values for the hw device.

Each audio card you have is numbered. 0 is typically your main one...I happen to have a USB audio device which shows up as device 1.

But eventually, I found it:

speaker-test -c 2 -r 48000 -D hw:2,7

This caused static to come out of my TV's speakers over the HDMI. Horray!

You might not have 2,7. In fact, 2,3 appeared to work for me, but didn't produce any sound. However, 2.3 *might* work for you.

At this point, you can go into your Gnome audio configuration (or whatever the equivalent might be in KDE/xfce/etc) and under output, you might be lucky enough to see "HDA NVidia..." in addition to your Internal Audio Analog Stereo. Great!

Play a sound file and try it out. If it works, you're done! If not, read on....

This unfortunately did *not* work for me. But I was closer then I realized.

The problem is called under-enumeration. It's pretty simply really, the video card (for whatever reason) made two devices available to the system: (2,3) and (2,7). But only the second mapped to the HDMI audio output. However, the Linux audio utils, by default, pick the first one (2.3). As far as I know, there's no way to change this.

But, you can add more audio devices, and select among those. To do this, open up the following file:

/etc/pulse/default.pa

and add the following line at the end:

load-module module-alsa-sink device=hw:2,7.

Restart. Now, you'll actually get three output devices. The regular internal stereo one, the HDA NVidia one, and a second HDA NVidia one (the text might look a little different).

So now, trying playing some audio and selecting the new audio device and voilà! Hopefully, you should have audio coming through your TV. To be fair, I believe this is only stereo sound, I haven't done any research on getting a digital, surround-sound signal through, but I imagine it's possible.

Strangely, when I booted up a few days ago after doing a system update, Ubuntu once again kicked me into Low-graphics mode.

Investigating, I found that my nVidia binary driver was no longer being loaded. I was going to reinstall the driver, when I decided to check nVidia's site. Even stranger, nVidia *just* released a new driver for my card yesterday! Not sure if they two things are related or not, but hey, I got a new driver.

Installing the new driver restored all my video functionality. But my HDMI audio wasn't working again. It seemed my Alsa had kicked back to 1.0.21, so the device was no longer being picked. So I started doing the motions necessary to restore it and decided to write them down this time (which you've just finished reading). Afterwards, my HDMI audio is working fine again!

References:

http://www.nvidia.com/Download/index.aspx?lang=en-us
https://wiki.ubuntu.com/Audio/InstallingLinuxAlsaDriverModules
ftp://download.nvidia.com/XFree86/gpu-hdmi-audio-document/gpu-hdmi-audio.html

6 comments:

  1. This was tremendously helpful. Messing with linux audio/display drivers is my least favorite thing in the world.

    ReplyDelete
  2. FYI, there should be a way to determine what device is what: in a terminal, cd to /proc/asound, go to the directory for your card (mine are all helpfully symlinked, so I just had to cd NVidia), and look through the contents of the subdirectories. Each should have a file called info which lists the hardware address and the description of the device.

    ReplyDelete
  3. Thank you for your "HAPPY THANKSGIVING"
    I am so deeply warmed.

    Does the USA have thanxgiving in March?

    In any event I have A HDMI monitor I just hooked up to my Ubuntu 11.10 system, and I have NO SOUND.
    Your long SELF-INDULGENT explanation is a "tad too long" for me to... uhh, indulge in.

    I just want a simple answer as to why my HDMI MONITOR DOES NOT HAVE SOUND IN UBUNTU 11.10 !!
    Got it?
    BTW, the sound works quite well (out of the box) with Win-7.
    Unless you can provide a 4-sentence explanation, please stop being so self-indulgent,

    ReplyDelete
  4. Bunny HDMI-lady,

    Thank you very much for your comment, however, since this is my blog and not yours, I will be precisely as self indulgent or not self indulgent as I wish to be. Although I'm always happy to hear someone found the information in my blog useful, the purpose of my blog is to document my thoughts, experiences, and things I generally find interesting, not to provide "stream-lined" technical support.

    If you cannot be bothered to read the entire post, or at least skim it for the relevant portions (I'll give you a hint, they start near the terminal commands), then you are most welcome to seek advice from another source.

    I am not an American, but as far as I know, Americans celebrate Thanksgiving in November, and not March. This post was made in October. Have a great day!

    ReplyDelete
  5. lol Bunny HDMI-lady, you make me laugh ;=)

    Jay,
    big thanks for this post, specially the lines talking about /etc/pulse/default.pa, The sound works for me now.

    you make my day!

    ReplyDelete
  6. Thank you! I had looked a literally dozens of web pages with all sorts of nonsensical (and sensible) suggestions. I had almost given up before I somehow stumbled on your page. It made sense and best of all - it worked.

    ReplyDelete