Skip to main content
Topic: [somehow partially solved] Audio via HDMI (Read 1185 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[somehow partially solved] Audio via HDMI

Hi all :-)

I have the following use-case: I want to attach a TV to the HDMI output of my notebook (Lenovo ThinkPad E480, but I think that doesn't matter), and not only see my desktop, but also have the TV play my audio.

Getting the HDMI output to work was as easy as installing kscreen and activating it in KDE's systemsettings. But the audio part seems to be a bit harder.

aplay -l lists my HDMI output as card 0 device 3:
Code: [Select]
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CX20753/4 Analog [CX20753/4 Analog]
  Subdevices: 1/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
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

After creating /etc/asound.conf with the following content:
Code: [Select]
pcm.!default {
    type hw
    card 0
    device 3
}
restarting alsa and unmuting the HDMI output via alsamixer (in my case, this was "S/PDIF"), the TV plays the sound of e.g. a video played via mplayer. But a browser (e.g. Falkon to play some streamed video) doesn't seem to care about this setting: The sound is still only played by my notebook's speakers.

How can I make also a browser play audio via HDMI?

And is there a way to make this more convenient? Like if a HDMI is plugged, play audio via HDMI, and if not, use the notebook's speakers, or at least always play audio via HDMI if a cable is plugged (in addition to the notebook's speakers)?

Thanks for all hints! Because even after reading all I could find about this (for Arch, Artix, and also Gentoo) I can't get this to work.

EDIT:

At least for some use-cases, I could get it to work.

E.g. for mplayer playback, one can address the ALSA device to use directly (without changing ALSA's configuration), in my case like so:
Code: [Select]
mplayer -ao alsa:device=hw=0.3 ...
For making a browser play audio through HDMI, I had to switch pulseaudio's output profile, in my case:
Code: [Select]
pacmd set-card-profile alsa_card.pci-0000_00_1f.3 output:hdmi-stereo+input:analog-stereo

Not really nice, but it works.

Re: Audio via HDMI

Reply #1
How can I make also a browser play audio via HDMI?
And is there a way to make this more convenient? Like if a HDMI is plugged, play audio via HDMI, and if not, use the notebook's speakers, or at least always play audio via HDMI if a cable is plugged (in addition to the notebook's speakers)?
I nowhere near being an audio expert, but I think you need more than just ALSA for this kind of "automation". I use pulseaudio + pavucontrol for a media box connected to TV and it works reasonably well.

See the Arch wiki on pulseaudio for examples:
https://wiki.archlinux.org/title/PulseAudio/Examples#Automatically_switch_audio_to_HDMI

Re: Audio via HDMI

Reply #2
For now, I would be totally happy if I could make a browser output audio to HDMI as mplayer does …

Re: Audio via HDMI

Reply #3
There are some search results with solved ALSA/HDMI/firefox issues, if you're so against proper audio processors.

Re: Audio via HDMI

Reply #4
I'm not against proper audio processors in any way!

Maybe I have to rephrase my question a bit: What do I have to do/install/setup so that I don't have any hassle with audio output via HDMI, no matter if the source is mplayer, a browser, or anything else?

With my changes to ALSA's config I just wanted to show the effort I did so long to get it to work … I have another machine running Artix, using a TV as it's only monitor. I didn't change anything to any config file, and HDMI audio "just works". So I simply wonder why this is not the case with my notebook …

Re: Audio via HDMI

Reply #5
I'm no expert on audio setup, but this works without any special setup for me. Currently I use Pipewire, but it it also worked before I switched to that.
All I need to do is to select the correct audio profile, as my screen provides 27 of them. By using pavucontrol it's easy to see which ones are actually available.
artist

Re: Audio via HDMI

Reply #6
Maybe, this is actually something hardware-specific to my Lenovo ThinkPad E480.

I played around a lot. With mplayer, I can play audio through HDMI by adding -ao alsa:device=hw=0.3, wthout having changed anything of ALSA's config. No chance for a browser (Falkon, Firefox, Chromium) though.

Maybe because they use Pulseaudio (through ALSA's pulseaudio plugin or whatever)? I never had to mess with that stuff, so I don't know really much about this. At least, I tried to install pavucontrol, and it only lists my internal speakers and the headphone jack as output devices. Not the HDMI output …

So maybe, browsers simply can't even see the HDMI output, but mplayer can?!

Re: Audio via HDMI

Reply #7
Maybe because they use Pulseaudio (through ALSA's pulseaudio plugin or whatever)? I never had to mess with that stuff, so I don't know really much about this. At least, I tried to install pavucontrol, and it only lists my internal speakers and the headphone jack as output devices. Not the HDMI output …

Personally, on several PCs and laptops, I uninstalled all the pulse packages I could and since then I've been quiet and I have sound everywhere. :

Code: [Select]
cat /proc/asound/cards 

 0 [HDMI           ]: HDA-Intel - HDA ATI HDMI
                      HDA ATI HDMI at 0xfce60000 irq 96
 1 [Generic        ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfc900000 irq 98

Code: [Select]
nano ~/.asoundrc

defaults.pcm.card 1
defaults.ctl.card 1

Re: Audio via HDMI

Reply #8
What I don't get is that mplayer can output through HDMI, and the browser stuff doesn't work. After all, this is also handled by ALSA through the pulse plugin, isn't it?!

Re: Audio via HDMI

Reply #9
So, after some further investigation, I could make it work.

By manually setting a pulseaudio output profile, I actually made a browser play audio through HDMI. In my case:
Code: [Select]
pacmd set-card-profile alsa_card.pci-0000_00_1f.3 output:hdmi-stereo+input:analog-stereo

As a Gentoo user, I'm used to grief – but this is really a bit awkward ;-) I never deliberately had to use that pulseaudio stuff before. Is there some nicer way to achieve this`(apart from writing a script)? Maybe even some GUI?

Re: Audio via HDMI

Reply #10
What I don't get is that mplayer can output through HDMI, and the browser stuff doesn't work. After all, this is also handled by ALSA through the pulse plugin, isn't it?!
Here is what is installed for me on Artix OpenRC with XFCE:

jp-artix:[jp]:~$ pacman -Qs | grep alsa
local/alsa-card-profiles 1:0.3.27-1
local/alsa-firmware 1.2.4-2
    Firmware binaries for loader programs in alsa-tools and hotplug firmware loader
local/alsa-lib 1.2.4-3
local/alsa-plugins 1:1.2.2-2
local/alsa-topology-conf 1.2.4-2
local/alsa-ucm-conf 1.2.4-2
local/alsa-utils 1.2.4-2
local/alsa-utils-openrc 20210505-2 (openrc-world)
    OpenRC alsa-utils init script
local/zita-alsa-pcmi 0.3.2-3
    The successor of clalsadrv, provides easy access to ALSA PCM devices.

-----------

jp-artix:[jp]:~$ pacman -Qs | grep pulse
local/libpulse 14.2-3

Re: Audio via HDMI

Reply #11
But none of this is a GUI to switch a pulseaudio output profile, is it?

Re: [somehow partially solved] Audio via HDMI

Reply #12
But none of this is a GUI to switch a pulseaudio output profile, is it?
I use the handy Qastools mixer:
Code: [Select]
pacman -Si qastools
Dépôt                    : community
Nom                      : qastools
Version                  : 0.23.0-1
Description              : A collection of desktop applications for the Linux
                           sound system ALSA.
Architecture             : x86_64
URL                      : https://gitlab.com/sebholt/qastools

Re: [somehow partially solved] Audio via HDMI

Reply #13
That seems very similar to KMix, no? Doesn't seem to be able to switch pulseaudio output profiles?

Re: [somehow partially solved] Audio via HDMI

Reply #14
That seems very similar to KMix, no? Doesn't seem to be able to switch pulseaudio output profiles?
I don't know, because I haven't tried.
Anyway, I have sound in all my applications.

To see the names of loaded modules:
Code: [Select]
$ cat /proc/asound/modules
  0 snd_hda_intel
  1 snd_hda_intel
  2 snd_usb_audio
To set position 2 of snd_usb_audio in all cases:
Code: [Select]
sudo nano /etc/modprobe.d/alsa-base.conf
I put this in there:
Code: [Select]
options snd_usb_audio index=2