31

So my setup currently is using a monitor plugged into my laptop via HDMI and using the speakers in that for audio not the inbuilt laptop ones. When the machine boots it uses HDMI by default, but I will often suspend the laptop throughout the day and whenever it resumes it switches the sound device to the inbuilt speakers.

It's not a big problem as you can imagine but is annoying, I wonder if there's a script I could use to force it to reselect HDMI after resume or disable the inbuilt speakers, or set as default some how. FYI both the inbuilt speakers are on the same 'sound card' but are two different devices. I use Ubuntu 16.04.

rubo77
  • 34,024
  • 52
  • 172
  • 299
MattJC
  • 311

9 Answers9

33

If you don't want to reboot, simply restart pulseaudio:

pulseaudio --kill; pulseaudio --start
rubo77
  • 34,024
  • 52
  • 172
  • 299
15

I had the same problem on Ubuntu 17.10. After suspend, or even after dimming the Display, it would always change my audio output from Digital Output (desired) to HDMI even though my Display does not have any speakers. Commenting out the line

load-module module-switch-on-port-available

in /etc/pulse/default.pa did the trick as described in Disable sound through HDMI permanently.

Note that setting default sinks as pointed out above did not change the behavior. Also, the script provided above to set the audio card profile after suspend is user-specific.

sambura
  • 151
  • 1
  • 2
12

This issue may be related to a problem with Pulseaudio, version 8, as outlined in this (long) bug thread on freedesktop.org.

Basically, Pulseaudio reroutes the sound when it loses contact with HDMI and doesn't return it after HDMI is reconnected. It is fixed in version 9.

In order to return version 8 to the behavior of previous versions, follow these directions and reboot.

edit /etc/pulse/default.pa to comment out (add # to the start of) the line:

#load-module module-switch-on-port-available

Then set the sound output in Sound Settings and check that it persists by suspend/resume or blanking the screen. It did work for me.

Paul H.
  • 264
3

I fixed this issue by setting fixed pulse profile to output:hdmi-stereo on resume.

To get a list of pulse profiles: pacmd list-cards. To change pulse profile e.g.: pacmd set-card-profile 0 output:hdmi-stereo.

About running script after suspend: Run Script on Wakeup?

About running pacmd as root: [Solved] Control pulseaudio with shell script via pacmd / Newbie Corner / Arch Linux Forums:

3

Fixing PulseAudio switching off HDMI sound on Suspend

This "undocumented feature" appeared with Ubuntu 16.04 and new version of PulseAudio 8.

Create a new file /lib/systemd/system-sleep/tv-sound and copy in:

#!/bin/sh

case $1/$2 in pre/) echo "Going to $2..." # Place your pre suspend commands here, or exit 0 # if no pre suspend action required sleep 1 ;; post/) echo "Waking up from $2..." # Place your post suspend (resume) commands here, or exit 0 # if no post suspend action required sleep 2 export PULSE_RUNTIME_PATH="/run/user/1000/pulse/" sudo -u rick -E pacmd set-card-profile 0 output:hdmi-stereo ;; esac

NOTE: replace user name rick (third line from the bottom) with your user name.

Then mark it executable with the command:

sudo chmod +x /lib/systemd/system-sleep/tv-sound

An additional step might be required if output:hdmi-stereo (the device for most people) is different on your system.

2

Run:

$ pacmd list-cards

To display the index of your cards. For example, my pci sound card is at index 2. The sound profile for analogue output (again as an example) is called output:analog-stereo.

Then:

$ pacmd set-card-profile 2 output:analog-stereo

To set this as the output (give it a try). To make it permanent, edit /etc/pulse/default.pa and add:

set-card-profile 2  output:analog-stereo
set-default-sink 2

Restart pulseaudio or reboot to check persistence.

Zanna
  • 72,312
1

Same happens for me but only if the HDMI monitor is not "awake" when OS starts or resumes: the list of devices in Settings > Sound doesn't even show HMDI/DisplayPort - Built-in Audio any more.

The fix for me is to suspend the session, ensure HDMI monitor is on, resume the session.

Suspend in Ubuntu 18.04 LTS is somewhat insanely hidden behind the PowerOff button in the drop down menu: hold mouse down on it, or press Alt to convert the PowerOff button into Suspend. Talk about hidden navigation!

Zanna
  • 72,312
mr0
  • 11
1

I have had this problem since Ubuntu 9.04. It never has worked and now that the children who just got HDMI or just got Ubuntu think the problem is something new so people trying to look at the latest changes in the setup are being misled. So let me make this clear: This problem has always been around and nobody is working on it. I've spent at least 20 hours researching this issue. So what I have done in the past:

  1. Reboot
  2. While turning on the TV (HDMI target) if I wiggle the mouse at just the right time it restores the sound maybe 50% of the time. This is a timing related/handshaking issue.
  3. In Ubuntu 14 I would change the screen resolution to something different then back again. This doesn't seem to work with Ubuntu 16
  4. Don't let it hibernate. An alternative is just do a timed shutdown. Later you just boot your computer rather than re-boot. Remember this is a TIMING issue, so I presume any of the ideas here can work if the timing happens to jog your system correctly.
Zanna
  • 72,312
Guest
  • 11
  • 1
0

I solved my problem by disabling pulseuadio entirely and rebooting:

systemctl --user disable pulseaudio.socket
systemctl --user disable pulseaudio.service
systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service

Although I recognize there are a lot of things that get broken by this, for me it is a relief to be able to select a sound device and have it stick between logins.