Artix Linux Forum

Artix Linux => Installation / Migration / Configuration => Topic started by: l3u on 23 August 2022, 21:47:12

Title: [somehow partially solved] Audio via HDMI
Post by: l3u on 23 August 2022, 21:47:12
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.
Title: Re: Audio via HDMI
Post by: nous on 23 August 2022, 23:21:47
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
Title: Re: Audio via HDMI
Post by: l3u on 24 August 2022, 22:05:09
For now, I would be totally happy if I could make a browser output audio to HDMI as mplayer does …
Title: Re: Audio via HDMI
Post by: nous on 25 August 2022, 13:55:33
There are some search results with solved ALSA/HDMI/firefox issues, if you're so against proper audio processors.
Title: Re: Audio via HDMI
Post by: l3u on 26 August 2022, 22:06:16
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 …
Title: Re: Audio via HDMI
Post by: Artist on 26 August 2022, 22:15:31
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
Title: Re: Audio via HDMI
Post by: l3u on 27 August 2022, 00:41:57
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?!
Title: Re: Audio via HDMI
Post by: tintin on 27 August 2022, 06:30:42
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
Title: Re: Audio via HDMI
Post by: l3u on 27 August 2022, 09:19:39
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?!
Title: Re: Audio via HDMI
Post by: l3u on 27 August 2022, 10:11:28
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?
Title: Re: Audio via HDMI
Post by: tintin on 27 August 2022, 10:15:11
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
Title: Re: Audio via HDMI
Post by: l3u on 27 August 2022, 10:37:50
But none of this is a GUI to switch a pulseaudio output profile, is it?
Title: Re: [somehow partially solved] Audio via HDMI
Post by: tintin on 27 August 2022, 10:47:19
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
Title: Re: [somehow partially solved] Audio via HDMI
Post by: l3u on 27 August 2022, 11:13:12
That seems very similar to KMix, no? Doesn't seem to be able to switch pulseaudio output profiles?
Title: Re: [somehow partially solved] Audio via HDMI
Post by: tintin on 27 August 2022, 11:51:27
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
Title: Re: [somehow partially solved] Audio via HDMI
Post by: l3u on 30 August 2022, 09:18:28
Okay, that looks like you don't use your mainboard's sound card, but an additional one, no?

However, I think that what I see here is actually a hardware thing. Maybe it's something about the built-in speakers my notbook has. As said, I have another Artix machine with a very similar setup, where HDMI audio worked out of the box. Perhaps, this one sends audio to both the analog and the HDMI output by default?

Well, after all, it works; one only has to take care of two output methods: On the one side, the direct ALSA output (used e.g. by mplayer) and on the other side the PulseAudio stuff (used by e.g. browsers).
Title: Re: [somehow partially solved] Audio via HDMI
Post by: tintin on 30 August 2022, 09:37:08
Okay, that looks like you don't use your mainboard's sound card, but an additional one, no?
No, snd_usb_audio is my webcam mic that I use for my YouTube videos.
My sound card is snd_hda_intel, the sound card on my motherboard.


Quote
However, I think that what I see here is actually a hardware thing. Maybe it's something about the built-in speakers my notbook has.
I have already had the case on a laptop where the sound output was misdirected.

Quote
As said, I have another Artix machine with a very similar setup, where HDMI audio worked out of the box. Perhaps, this one sends audio to both the analog and the HDMI output by default?
I'll let those who know answer.

Quote
Well, after all, it works; one only has to take care of two output methods: On the one side, the direct ALSA output (used e.g. by mplayer) and on the other side the PulseAudio stuff (used by e.g. browsers).
That seems to be it.
Title: Re: [somehow partially solved] Audio via HDMI
Post by: nous on 31 August 2022, 02:23:45
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.
What I don't get is that mplayer can output through HDMI, and the browser stuff doesn't work.
This was your problem.
Title: Re: [somehow partially solved] Audio via HDMI
Post by: l3u on 02 September 2022, 09:20:31
Well, as long as it works … a bit of fiddling around has to stay, this is Linux after all ;-)