Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] How to use HDMI sound w/ alsa and alsamixer?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6281

PostPosted: Tue Mar 26, 2019 7:07 am    Post subject: [Solved] How to use HDMI sound w/ alsa and alsamixer? Reply with quote

My monitor is connected to the PC via a HDMI cable.
I would like to use this cable to transfer sound. I know that in principle, this is possible: Ubuntu does it this way.
However, for various reasons, I do not want to use pulseaudio but alsa.
The kernel seems to be prepared for it:
Code:
CONFIG_HDMI=y
CONFIG_SND_HDA_CODEC_HDMI=m

and the module is loaded:
Code:
 # rmmod snd-hda-codec-hdmi
rmmod: ERROR: Module snd_hda_codec_hdmi is in use


In fact, I am able to produce some sound through the cable: I observed this information
Code:
 # aplay -l               
**** List of PLAYBACK Hardware Devices ****
card 0: hdmi [HDA Intel PCH], device 0: ALC887-VD Analog [ALC887-VD Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: hdmi [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: hdmi [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: hdmi [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: hdmi [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: hdmi [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
[A further card is listed which stems from the pcsp driver and should not be relevant here.]

And by trial-and-error I detected that device 8 seems to be the hdmi cable:
Code:
# speaker-test -D plughw:0,8 -c 2

can produce sound over the cable in the left and right speaker, respectively, and
Code:
# mplayer -ao alsa:device=hw=0.8 filename

does output the sound.

However, it does so always with full volume: The only control of alsamixer which has any
recognizable effect is S/PDIF 2 which I can mute or unmute (in the muted case there is no sound
produced by the above commands).

Even worse: I cannot run e.g. two mplayer commands simultaneously: Only the first one "gets"
the sound, the other remains silent. Without hdmi there is no such problem, that is, there
hardware has the capability to mix.

I have attempted the following
/etc/asound.conf wrote:
pcm.!default {
type hw
card 0
device 8
}

This works in the sense that afterwards, mplayer will output the sound over cable without any
extra alsa options.

However, there is still no mixer: Neither can I change any sound settings with alsamixer,
nor am I able to let e.g. 2 mplayers run simultaneously. So what I want is to first run
"through the standard mixer" and only afterwards redirect the sound to S/PDIF-2

With Ubuntu (pulseaudio), I can control the volume of the sound with alsamixer and
also output several channels simultaneously.
Sure, I am aware that this happens somehow by the alsa plugin of pulseaudio.
and the second might even happen purely by software.

But maybe there is some alsa expert here who might help me to produce some /etc/asound.conf
which uses the hardware mixer and outputs the result over hdmi cable!?

(Note: This is an off-split of a previous question where I did not
understand that this is actually a problem with the hdmi output selection...)

Edit: removed ctl.!default section of /etc/asound.conf and corresponding misleading
comments about alsamixer not starting.


Last edited by mv on Tue Mar 26, 2019 4:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43223
Location: 56N 3W

PostPosted: Tue Mar 26, 2019 10:19 am    Post subject: Reply with quote

mv,

I'm not sure why I have a PCM volume slider for my HDMI sound output. Here's what I have.
You will need to change the card number from 1 to 0.
/etc/asound.conf
/etc/asound.conf:
pcm_slave.slave_rate48000Hz {
        pcm "hw:1,8"
#       This is the rate the sond card does.
#       Any random input rates are resampled to this.
        rate 48000
}
pcm.rate44100Hz {
        type plug
        slave slave_rate48000Hz
}

defaults.pcm.card 1
defaults.pcm.device 8
defaults.ctl.card 1

The sample rate conversion in required for my ripped CD collection.

There is a wart you need to know about. It takes a few seconds for the stream to open, so the first few seconds of audio are lost.
Thats annoying for CD. So you play silence all the time, which keeps the stream open. For that I use

/etc/local.d/play_silence.start:
#!/bin/bash

# due to a kernel bug, alsa takes a few seconds to open a
# stream to HDMI (all digital?) outputs, so the first
# few seconds of everything are lost.

# the work around is to continuously play silence
# so that the sound stream is never closed.
aplay -c2 -r48000 -fS16_LE < /dev/zero & 


Maybe that will put you on the right path?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6281

PostPosted: Tue Mar 26, 2019 11:17 am    Post subject: Reply with quote

Thank you very much, NeddySeagoon!

As always, your help is great!

I took your configuration by only replacing "1" by "0" everywhere.
I have not the slightest idea what it does, but everything works fine now:

The PCM slider in alsamixer (which previously did not move at all) now controls
the volume of the HDMI sound. Also mplayer & co send their sound over hdmi.
And also there is no problem to start 2 mplayers with sound output simultaneously.

So far, I did not observe any problem you mention: The sound output (at least from
mplayer) starts immediately.

Thanks a lot!

Edit: Fixed typo: s/alsaconf/alsamixer
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum