Fixing flaky pulseaudio hdmi audio with nvidia drivers

This post requires no answers, I’m mostly just documenting my notes on fixing flaky audio device issues with hdmi audio out with nvidia drivers.

issue 1: After a restart your audio output device is not what you expect

For example, in my case the “Digital Output (S/PDIF)…” audio output device was selected as the audio output device after running/closing certain programs, after restarts, or after upgrading video drivers. I expected audio output to be HDMI/2

Simple fix:

  1. open ‘Sound’ settings from Gnome Settings
  2. select your HDMI output device
  3. click ‘Test’ and verify audio is working or aplay /usr/share/sounds/alsa/Front_Center.wav

issue 2: Selecting your correct audio device in Gnome Settings still has no audio

for example, if aplay /usr/share/sounds/alsa/Front_Center.wav does not produce any sound

(As all things linux this is not a one size fits all solution, however here’s the steps that work for my setup)

  1. list all devices from aplay, aplay -l
  2. identify the card/device numer from the list of devices that your device should be, for me:
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
  1. verify this is the correct device with aplay, aplay -D plughw:1,7 /usr/share/sounds/alsa/Front_Center.wav
  2. update /etc/pulse/
    4.1. under “### Load audio drivers statically” add line:
    load-module module-alsa-sink device=hw:1,7
    4.2. disable udev detection, comment out this section:
#load-module module-udev-detect
### Use the static hardware detection module (for systems that lack udev support)
#load-module module-detect
  1. restart pulseaudio:
pulseaudio -k
pulseaudio --start

Note, this will now make your sound setup static. Disabling udev detection will make it so that plugging in new HDMI devices, bluetooth audio, etc… will not only not switch to a new audio device, it likely won’t even be detected.

This setup is very inflexible!

See more:

Well… it turns out I didn’t test the second fix (editing /etc/pulse/ very well and it was broken after a machine restart.

Instead, this fix seems to be working better which instead configures the correct default sink for pulse:

$ pactl list short sinks
1	alsa_output.pci-0000_09_00.3.iec958-stereo	module-alsa-card.c	s16le 2ch 48000Hz	SUSPENDED
4	alsa_output.pci-0000_42_00.1.hdmi-stereo-extra1	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
$ pactl set-default-sink 'alsa_output.pci-0000_42_00.1.hdmi-stereo-extra1'

The saga continued here…

For some reason after recently switching to nvidia drivers from the negativo17 repos, sound just isn’t behaving. I’ll probably revert, but for the time being I’ve also needed to add an autostart script to kill/start pulseaudio on login. Otherwise only the “null” pulseaudio sink is available after login.