You are not logged in.

#1 2011-12-28 15:08:22

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

HDMI audio output

I'm having problems trying to get my HDMI audio output to work correctly. By default, with or without and external monitor connected, the audio is heard from my notebook speakers (or from the headphones, when I plug them in). My external speakers are connected to the external HDMI monitor, so they should sound whenever the HDMI audio output is being used.

The controls/levels I get in alsamixer are these:

screenshot-12282011-125113pm.php

I'm not sure if S/PDIF corresponds to the HDMI output, but it doesn't have a level bar (maybe that's normal?).

I found a section in the wiki regarding my problem, but it doesn't look like the proper solution. Running aplay -l returns:

**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: STAC92xx Analog [STAC92xx Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Running the following line, does indeed produce a sound in my external speakers:

aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav

And finally creating a .asoundrc file with the following content in my home directory and restarting alsa does use the HDMI output by default:

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

The thing is that I don't want the sound to go out that way always, but only when the HDMI cable is connected. I'd like to have a practical way to switch between both of them (or maybe, even making it automatic later by writing some script). What do you think is the best way to do it?

A couple more details: muting the S/PDIF channel in alsamixer does indeed affect the output when "aplay -D ..." is run. Also, the info I have on the sound card is that it's a HDA Intel with an Intel IbexPeak HDMI chip (my notebook is an HP).
If some more information is needed, please tell me how can I get it.

Thanks! big_smile

Offline

#2 2011-12-28 22:48:35

ichbinesderelch
Member
Registered: 2008-01-17
Posts: 203

Re: HDMI audio output

i just did this with two little scripts which just move my .asoundrc to .asoundrcoff and force-restarts alsa if i want to deactivate hdmi output and the other way round for activating it again, maybe not the best solution but it works, and hence i'm not too good at bash scripting i feel confortable with that wink

Offline

#3 2011-12-28 23:17:42

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

Re: HDMI audio output

Great, I'll try your solution and use it until I can find a better way, at least...
Do you get to control the level of the digital output, somehow? Thx!

Offline

#4 2011-12-29 10:40:20

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

OP, this is exactly the same query that just popped into my head. It occurs to me that we may be able to use udev to detect hdmi cable (un)plugging. This is on the right track. I plan to look into this more over the next few days, but feel free to get started without me smile


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#5 2011-12-31 10:31:06

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

I've been trying to make some progress on this. I have a udev rule and a script that switches the audio device. The script definitely works fine when I run it manually, but I'm having trouble getting udev to use it.

/etc/udev/rules.d/hdmi.rules

KERNEL=="card0", ACTION=="change", RUN+="bash /etc/alsa/hdmi-switch"

/etc/alsa/hdmi-switch

#! /bin/bash
set -x

hdmi_status=$(cat /sys/class/drm/card0-HDMI-A-1/status)
alsa_dir=/etc/alsa
asound_file=asound.hdmi-$hdmi_status

[[ -n $hdmi_status ]] \
    && [[ -f "$alsa_dir/$asound_file" ]] \
    && ln -svf "$alsa_dir/$asound_file" /etc/asound.conf \
    && /etc/rc.d/alsa force-restart

/etc/alsa/asound.hdmi-connected

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

/etc/alsa/asound.hdmi-disconnected

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

I unplug the cable and plug it back in while running,

$ udevadm monitor --kernel --property

and receive:

monitor will print the received events for:
KERNEL - the kernel uevent

KERNEL[1208.746936] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=1834
SUBSYSTEM=drm
UDEV_LOG=3

KERNEL[1212.096857] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=1835
SUBSYSTEM=drm
UDEV_LOG=3

Running

$ udevadm test --action=CHANGE '/devices/pci0000:00/0000:00:02.0/drm/card0'

gives

run_command: calling: test
adm_test: version 175
This program is for debugging only, it does not run any program,
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

parse_file: reading '/lib/udev/rules.d/10-dm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/11-dm-lvm.rules' as rules file
parse_file: reading '/lib/udev/rules.d/13-dm-disk.rules' as rules file
parse_file: reading '/lib/udev/rules.d/30-kernel-compat.rules' as rules file
parse_file: reading '/lib/udev/rules.d/40-gphoto.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing /lib/udev/rules.d/40-gphoto.rules:11
parse_file: reading '/lib/udev/rules.d/40-hpet-permissions.rules' as rules file
parse_file: reading '/lib/udev/rules.d/42-qemu-usb.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-firmware.rules' as rules file
parse_file: reading '/lib/udev/rules.d/50-udev-default.rules' as rules file
parse_file: reading '/lib/udev/rules.d/52-libmtp.rules' as rules file
parse_file: reading '/lib/udev/rules.d/53-sane.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-cdrom_id.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-pcmcia.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-alsa.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-input.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-serial.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage-tape.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-storage.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-persistent-v4l.rules' as rules file
parse_file: reading '/lib/udev/rules.d/60-rfkill.rules' as rules file
parse_file: reading '/lib/udev/rules.d/61-accelerometer.rules' as rules file
parse_file: reading '/lib/udev/rules.d/64-md-raid.rules' as rules file
parse_file: reading '/lib/udev/rules.d/69-cd-sensors.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing /lib/udev/rules.d/69-cd-sensors.rules:73
parse_file: reading '/lib/udev/rules.d/70-infrared.rules' as rules file
parse_file: reading '/lib/udev/rules.d/70-udev-acl.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-net-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-probe_mtd.rules' as rules file
parse_file: reading '/lib/udev/rules.d/75-tty-description.rules' as rules file
parse_file: reading '/lib/udev/rules.d/78-sound-card.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-drivers.rules' as rules file
parse_file: reading '/lib/udev/rules.d/80-udisks.rules' as rules file
parse_file: reading '/lib/udev/rules.d/81-arch.rules' as rules file
parse_file: reading '/lib/udev/rules.d/85-regulatory.rules' as rules file
parse_file: reading '/lib/udev/rules.d/90-alsa-restore.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-cd-devices.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-dm-notify.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keyboard-force-release.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-keymap.rules' as rules file
parse_file: reading '/lib/udev/rules.d/95-udev-late.rules' as rules file
parse_file: reading '/lib/udev/rules.d/99-laptop-mode.rules' as rules file
parse_file: reading '/etc/udev/rules.d/hdmi.rules' as rules file
parse_file: reading '/etc/udev/rules.d/network-devices.rules' as rules file
udev_rules_new: rules use 202440 bytes tokens (16870 * 12 bytes), 25355 bytes buffer
udev_rules_new: temporary index used 46880 bytes (2344 * 20 bytes)
udev_device_new_from_syspath: device 0x8774740 has devpath '/devices/pci0000:00/0000:00:02.0/drm/card0'
udev_device_new_from_syspath: device 0x8774a50 has devpath '/devices/pci0000:00/0000:00:02.0/drm/card0'
udev_device_read_db: device 0x8774a50 filled with db file data
udev_rules_apply_to_event: GROUP 91 /lib/udev/rules.d/50-udev-default.rules:39
udev_event_execute_rules: no node name set, will use kernel supplied name 'dri/card0'
udev_node_add: creating device node '/dev/dri/card0', devnum=226:0, mode=0660, uid=0, gid=91
udev_node_mknod: preserve file '/dev/dri/card0', because it has correct dev_t
udev_node_mknod: preserve permissions /dev/dri/card0, 020660, uid=0, gid=91
node_symlink: preserve already existing symlink '/dev/char/226:0' to '../dri/card0'
udev_device_update_db: unable to create temporary db file '/run/udev/data/c226:0.tmp': Permission denied
ACTION=CHANGE
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
MAJOR=226
MINOR=0
SUBSYSTEM=drm
TAGS=:udev-acl:
UDEV_LOG=6
USEC_INITIALIZED=23637121

I wonder whether the "Permission denied" error in this latter output is relevant? I tried googling on:

"udev_device_update_db: unable to create temporary db file" "Permission denied"

but did not see anything either helpful or relevant.

Any ideas?


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#6 2011-12-31 21:00:45

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

I have it working!

I modified the udev rule like so:

SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/bash /etc/alsa/hdmi-switch"

and /etc/alsa/hdmi-switch like so:

#! /bin/bash
set -x

udevadm settle --quiet --timeout=16

hdmi_status=$(cat /sys/class/drm/card0-HDMI-A-1/status)
alsa_dir=/etc/alsa
asound_file=asound.hdmi-$hdmi_status

if [[ -n $hdmi_status ]] && [[ -f "$alsa_dir/$asound_file" ]]; then
    ln -sf "$alsa_dir/$asound_file" /etc/asound.conf
    /etc/rc.d/alsa force-restart
fi

OP, would you mind testing whether you can get this working, then maybe we can mark this fella solved ;-)

Last edited by /dev/zero (2011-12-31 21:02:30)


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#7 2012-01-02 16:26:40

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

Re: HDMI audio output

Hey!

I'm sorry I've been out this days... it's awesome all you've put on this! smile I'll certainly check out your solution today or tomorrow at most and let you know.

The good thing is that you already helped me with the other issue I wanted to tackle: detecting HDMI connection/disconnection to update desktop display configuration and resolutions big_smile

I'll try this and give feedback soon. Thanks!

Offline

#8 2012-01-02 16:39:31

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

brAzzi64 wrote:

Hey!

I'm sorry I've been out this days... it's awesome all you've put on this! smile I'll certainly check out your solution today or tomorrow at most and let you know.

The good thing is that you already helped me with the other issue I wanted to tackle: detecting HDMI connection/disconnection to update desktop display configuration and resolutions big_smile

I'll try this and give feedback soon. Thanks!

No worries, I look forward to hearing about how it goes one way or another :-)


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#9 2012-01-03 12:26:59

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

Re: HDMI audio output

Your solution worked flawlessly in my machine smile

I just changed the "force-restart" to just "restart", so that it doesn't kill the processes currently playing audio. I prefer restarting them manually (at least by now...).
The only thing I'm missing is the ability to change the volume level when the HDMI audio output is selected. Do you think it would be possible to do throught the asound.* files?

This solution will work for me great for now, but I'd like to look into a method that doesn't interrupt the audio outputs when doing the switch... I'm guessing that would need something like Jack or maybe... just PulseAudio? Anyway, I'll open a new post for that at a later time, and mark this as solved as soon as I have your guesses on the volume level thing.

Again, thanks a lot for helping me out, awesome work! big_smile

Offline

#10 2012-01-03 18:24:05

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

Glad to hear it works. I don't know how to set volume in asound.conf, and a quick google doesn't reveal anything either. You could add a call to amixer in the hdmi-switch script?


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#11 2012-01-11 23:53:47

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

Re: HDMI audio output

Actually, I have a volume level control in the speakers connected to my HDMI audio output, so I was thinking I may not need that after all.

However, I noticed both amixer and alsamixer give an error whenever the link /etc/asound.conf exists... could you please check if that happens to you too?

[brazzi@brAzzi-HP-ARCH alsa]$ alsamixer
cannot open mixer: Invalid argument
[brazzi@brAzzi-HP-ARCH alsa]$ amixer
amixer: Mixer attach default error: Invalid argument

Offline

#12 2012-01-12 00:04:13

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

I am getting those errors at the moment, but I think that's because I'm using the commands over ssh. I'll take another look when I get home tonight.


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#13 2012-01-17 00:12:40

brAzzi64
Member
From: Montevideo, Uruguay
Registered: 2011-12-08
Posts: 18
Website

Re: HDMI audio output

I noticed that also, my microphone doesn't work whenever I'm using the HDMI output... :-/ does that happen to you too?

Offline

#14 2012-01-18 22:46:45

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

Sorry I haven't gotten back to you on this. I've been having troubles with my desktop since I started trying to replace Debian with a geli-encrypted FreeBSD install :-)

Once I get those problems figured out, I'll do some more tests on my laptop's HDMI audio.


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#15 2012-01-23 11:06:21

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

Okay, I tested alsamixer, amixer and arecord. I could get the first two to work (partially?) by adding the flag "--card 0":

alsamixer --card 0
amixer --card 0

I say "partially" because in alsamixer, the only control that seems to affect HDMI audio is S/PDIF, and that only permits toggling mute/unmute - no volume control here; meanwhile, none of the controls offered by amixer seem to affect volume.

It's true, I wasn't able to get arecord to work at all. I think it's tied to the first device, since when I run "arecord -l", I obtain:

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VB Analog [ALC269VB Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I anticipate that a more sophisticated asound.conf file could be used to always make recording go through 0,0, even when the output is going through 0,3. However, recording isn't such a high priority for me, especially when the HDMI's plugged in, so I'll leave such explorations as an exercise ;-)


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#16 2012-03-25 16:25:33

kleim
Member
From: Lyon, France
Registered: 2011-12-14
Posts: 12

Re: HDMI audio output

/dev/zero wrote:

I modified the udev rule like so:

SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/bash /etc/alsa/hdmi-switch"

On my system it makes udev events hanging then failing at boot. Removing this rule get the booting process back to normal.
I found something that looks relevant on udev changelogs but I don't understand how udev rules should be created now...

udev 178
========
.../...
The RUN+="socket:.." option is deprecated and should not be used. A warning
during rules parsing is printed now. Services which listen to udev events,
need to subscribe to the netlink messages with libudev and not let udev block
in the rules execution until the message is delivered.

Offline

#17 2012-03-25 18:48:45

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,176
Website

Re: HDMI audio output

kleim wrote:

On my system it makes udev events hanging then failing at boot. Removing this rule get the booting process back to normal.
I found something that looks relevant on udev changelogs but I don't understand how udev rules should be created now...

udev 178
========
.../...
The RUN+="socket:.." option is deprecated and should not be used.

That udev news seems specific to situations where you're specifying a socket in your rule? - at least, I'm receiving neither warnings nor slow-down.

In the past, I have experienced udev slow-down due to having an unnecessary module specified in the rc.conf (if I recall correctly).

I agree it seems odd you get udev slow-down only when using this specific udev rule. However, I would only be in a position to come up with an answer if I could reproduce the problem. I'm sure if you came up with answer, it would make a welcome addition or modification to the wiki wink.


Linux is NOT Windows | The Rootless Root
Toshiba Satellite i5-3230M 2.6GHz CPUs, 4Gb RAM, ArchLinux, wmii, nVidia GeForce GT 740M.

Offline

#18 2014-08-04 10:35:44

rhadzh
Member
Registered: 2014-08-04
Posts: 1

Re: HDMI audio output

If I understood correctly your (brAzzi64) question, you want to play sound on your external speakers instead of your computers. One very important thing you should know about alsa it has application specific sound output or something like that, basically each application can output sound on different sound cards at the same time. That being said, go to your applications audio settings and select the HDMI sound card. For example I'm watching a film with vlc on my tv via hdmi so I go to audio ->  audio device -> look for anything that says hdmi output.

Offline

#19 2015-07-07 15:56:44

cebonet
Member
Registered: 2015-07-07
Posts: 4

Re: HDMI audio output

I know this is a old thread, but instead of dealing with udev rules you can install pavucontrol. It comes with an GUI, so it is fairly easy to switch between outputs.

Offline

#20 2015-07-07 17:56:27

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,761
Website

Re: HDMI audio output


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB