Sound over HDMI cable

My laptop has an Intel video card and an HDMI port, that I want to use for audio signal output, as well. Unfortunatelly, sound over HDMI does not work out-of-the-box, so I searched for a solution. There are good instructions at the Arch Linux Wiki.

First, I run aplay with the -l option, to list all soundcards and digital audio devices:

aplay -l

From the output, I found my card and device number:

card 0: PCH [HDA Intel PCH], device 0: ALC269VC Analog [ALC269VC Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I created an empty text file, called .asoundrc in my $HOME and put the following in ~/.asoundrc, using the card and device values from the output above:

pcm.!default {
    type hw
    card 0
    device 3
}

Now sound over HDMI cable works. The problem is that once the TV is disconnected, the above settings should be commented out or the file renamed to make it “inactive”. If not, sound will not work from the normal output. I do not have anything else set in .asoundrc, so it is not a big deal for me to just rename it to something like .asoundrc.inactive, and switch it back when needed.

I decided to make things a bit more convenient. I made two simple scripts, called hdmi-sound-off.sh and hdmi-sound-on.sh that will do this.

The first will turn the HDMI sound OFF by renaming the file:

#!/bin/sh
mv ~/.asoundrc ~/.asoundrc.inactive

The second will turn the HDMI sound ON, by reverting the file name back:

#!/bin/sh
mv ~/.asoundrc.inactive ~/.asoundrc

I made them executable and put them in /usr/local/bin. Then I made corresponding desktop entries for each, so I can just point and click:

[Desktop Entry]
Name=HDMI Sound OFF
Comment=Turn off sound over HDMI cable
Exec=hdmi-sound-off.sh
Icon=audio-speakers
StartupNotify=false
Type=Application
Categories=AudioVideo;
[Desktop Entry]
Name=HDMI Sound ON
Comment=Turn on sound over HDMI cable
Exec=hdmi-sound-on.sh
Icon=audio-speakers
StartupNotify=false
Type=Application
Categories=AudioVideo;

I put them in ~/.local/share/applications/ and they appeared in the menu. For convenience, I uploaded the sh and desktop files here.

Things seem to work fine. I found other instructions about HDMI sound in the Wiki of Gentoo Linux, but I have not tried them. The approach described above worked, so I decided to just stick to it.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s