29

Edit: the issue seems to also affect 18.04.

I have this issue since 15.10, but it started to really grind my gears after making an upgrade to 16.04.

Let's say that I have headphones plugged in. I reboot\relog on\boot to ubuntu, and play the music. It comes out of the built in speakers instead of headphones.

I can see that the headphones are detected inside the audio settings menu, but only after I change the device or replug my headphones do they work.

This was easier to ignore on 15.10, because back then, after a startup, everything was muted. Headphones and speakers, if headphones were present before the said startup.

I would add logs to the question, but I don't really know which, or how to get them (I'm open for suggestions). The problem occurs on a Dell Inspiron 3537 laptop, it has a Realtek soundcard inside.

It has one output jack on the side, that acts as both an input and an output.


Output of pacmd listcards

2 card(s) available.
    index: 0
    name: <alsa_card.pci-0000_00_03.0>
    driver: <module-alsa-card.c>
    owner module: 6
    properties:
        alsa.card = "0"
        alsa.card_name = "HDA Intel HDMI"
        alsa.long_card_name = "HDA Intel HDMI at 0xc0810000 irq 49"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:03.0"
        sysfs.path = "/devices/pci0000:00/0000:00:03.0/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "0a0c"
        device.product.name = "Haswell-ULT HD Audio Controller"
        device.form_factor = "internal"
        device.string = "0"
        device.description = "Wbudowany dźwięk"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    profiles:
        output:hdmi-stereo: Wyjście Digital Stereo (HDMI) (priority 5400, available: unknown)
        output:hdmi-surround: Wyjście Digital Surround 5.1 (HDMI) (priority 300, available: unknown)
        output:hdmi-surround71: Wyjście Digital Surround 7.1 (HDMI) (priority 300, available: unknown)
        output:hdmi-stereo-extra1: Wyjście Digital Stereo (HDMI 2) (priority 5200, available: unknown)
        output:hdmi-surround-extra1: Wyjście Digital Surround 5.1 (HDMI 2) (priority 100, available: unknown)
        output:hdmi-surround71-extra1: Wyjście Digital Surround 7.1 (HDMI 2) (priority 100, available: unknown)
        output:hdmi-stereo-extra2: Wyjście Digital Stereo (HDMI 3) (priority 5200, available: unknown)
        output:hdmi-surround-extra2: Wyjście Digital Surround 5.1 (HDMI 3) (priority 100, available: unknown)
        output:hdmi-surround71-extra2: Wyjście Digital Surround 7.1 (HDMI 3) (priority 100, available: unknown)
        off: Wyłączone (priority 0, available: unknown)
    active profile: <output:hdmi-stereo>
    sinks:
        alsa_output.pci-0000_00_03.0.hdmi-stereo/#0: Wbudowany dźwięk Digital Stereo (HDMI)
    sources:
        alsa_output.pci-0000_00_03.0.hdmi-stereo.monitor/#0: Monitor of Wbudowany dźwięk Digital Stereo (HDMI)
    ports:
        hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "video-display"
        hdmi-output-1: HDMI / DisplayPort 2 (priority 5800, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "video-display"
        hdmi-output-2: HDMI / DisplayPort 3 (priority 5700, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "video-display"
    index: 1
    name: <alsa_card.pci-0000_00_1b.0>
    driver: <module-alsa-card.c>
    owner module: 7
    properties:
        alsa.card = "1"
        alsa.card_name = "HDA Intel PCH"
        alsa.long_card_name = "HDA Intel PCH at 0xc0814000 irq 48"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1b.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card1"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "9c20"
        device.product.name = "8 Series HD Audio Controller"
        device.form_factor = "internal"
        device.string = "1"
        device.description = "Wbudowany dźwięk"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    profiles:
        input:analog-stereo: Wejście Analogowe stereo (priority 60, available: unknown)
        output:analog-stereo: Wyjście Analogowe stereo (priority 6000, available: unknown)
        output:analog-stereo+input:analog-stereo: Analogowy dupleks stereo (priority 6060, available: unknown)
        off: Wyłączone (priority 0, available: unknown)
    active profile: <output:analog-stereo+input:analog-stereo>
    sinks:
        alsa_output.pci-0000_00_1b.0.analog-stereo/#1: Wbudowany dźwięk Analogowe stereo
    sources:
        alsa_output.pci-0000_00_1b.0.analog-stereo.monitor/#1: Monitor of Wbudowany dźwięk Analogowe stereo
        alsa_input.pci-0000_00_1b.0.analog-stereo/#2: Wbudowany dźwięk Analogowe stereo
    ports:
        analog-input-internal-mic: Wewnętrzny mikrofon (priority 8900, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-input-microphone"
        analog-input-headphone-mic: Mikrofon (priority 8700, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-input-microphone"
        analog-input-headset-mic: Mikrofon na słuchawkach (priority 8700, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-input-microphone"
        analog-output-speaker: Głośniki (priority 10000, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-speakers"
        analog-output-headphones: Słuchawki (priority 9000, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-headphones"
8
  • 1
    This seems wrong (in the sense of PulseAudio screwing up) - your plugged in headphones should be chosen even on first try. Do a rm -rf ~/.pulse ~/.config/pulse before all else. This makes PA use default settings. Does the problem persist?
    – emk2203
    May 15, 2016 at 9:02
  • Yes, it does. Everything is as it was, headphones still detected. I made sure twice that rm worked - none of the above directories were present. I did a reboot afterwards. May 15, 2016 at 14:16
  • 1
    Could you post pacmd list-cards?
    – emk2203
    May 15, 2016 at 15:20
  • @emk2203 Done. Some keywords are in Polish, so: "wyjście" == "output", "wejście" == "input", "wewnętrzny mikrofon" == "internal microphone". May 16, 2016 at 11:24
  • Which music player are you using ?
    – userDepth
    Jun 22, 2016 at 2:28

5 Answers 5

8

My take on this would be the following taking advantage of PulseAudio. Assuming that when you log in Ubuntu, you always have your headphones connected, then the following will make sure that when you boot to Ubuntu it will automatically set it as the default Input and Output (Assuming you want both).

On Ubuntu go to the terminal and type the following from which you will only gather the Index Number:

For your OUTPUT DEVICES:

pacmd list-sinks - There will be a lot of information but look for the Index Numbers and the corresponding device that will be your new default Output Device.

For your INPUT DEVICES:

pacmd list-sink-inputs OR pacmd list-samples - There will be a lot of information but look for the Index Numbers and the corresponding device that will be your new default Input Device. Use the list-samples in case in the list-sink-inputs it does not show.

Right up to this point, on Ubuntu, with your headphones connected, you should have 2 index numbers. One for your input and output. Now we will go and edit your pulseaudio default configuration:

sudo nano /etc/pulse/default.pa

Go to the last line and simply add the following:

set-default-sink 1 - This corresponds to the Output Source after looking at the index of pacmd list-sinks. The 1 is the index, so change it to the one you got.

set-default-source 5 - This corresponds to the Input Sources after looking at the index of pacmd list-sink-inputs or pacmd list-samples. The number 5 is the index, so change it to the one you got.

Save the file an reboot the computer to test. The testing involves checking if you got the correct index value, since some devices have similar names (Like NVIDIA OR INTEL Audio sources).

If everything is correctly setup, every time you boot your computer, you should see Ubuntu sets the default Input/Output to your headphone. Since you are talking about Headphones, for Noise reduction you can use my other answer to help you with that: Realtime noise-removal with PulseAudio?

NOTE: You can also use pacmd list-sources to see all devices and also instead of using the index number, you can use the name of the assigned device, that look something like this:

alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono.echo-cancel to give you an idea of what names to look for (Super long I know). Names are more accurate to use but harder to remember so you have an option here to use one or the other. The end result using a name, would be like this:

set-default-source alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono.echo-cancel in the default.pa file, just to give you an idea.

For a GUI option, I recommend pavucontrol or PulseAudio Volume Control. It offers an option to set a device as default/fallback for Input and Output devices. Using both techniques might give you what you want.

9
  • I don't think it will work, but you could be onto something. The thing is, that on my machine I have two sound devices: Intel HDMI, and Realtek analog. The indexes are: 0 - HDMI, 1 - analog. The Realtek device has two ports - speakers and headphones (with priorities 10k and 9k respectively - do these numbers have to do with switching priority?). As far as I can see, these ports can't really be indexed in default.pa file in the fashion you have presented. May 15, 2016 at 14:34
  • Hi @BłażejMichalik actually this was tested on my wife's computer and mine before publishing it here. For the index confusion you can use the full name as mentioned at the end with the NOTE. May 15, 2016 at 15:42
  • 2
    Well, ok, it works, but it also makes the speakers off by default, even if headphones are not present. This is the behavior I experienced with 15.10. It's not a fix per-se. May 16, 2016 at 11:36
  • Yes, like I mentioned, you need to have the headphones connected since Ubuntu will not assume that if you connect the headphones it should use them by default. For the speakers turning off I have no idea there since this is only setting the default ones, not disabling others. This typically happens if you use a laptop with one jack connector (Input/Output at the same time). I would ask if your laptop has 2 connections (One for mic, another for Output) or if it has one. If your answer is one, then now you have an idea why the issues are appearing. May 16, 2016 at 13:59
  • Yup, that's exactly the case, didn't knew that is important. May 16, 2016 at 15:07
3

If your sound devices are 0 - HDMI and 1 - analog, you can switch to headphones with

$ pacmd set-sink-port 1 analog-output-headphones

To make it permanent, edit /etc/pulse/default.pa and at the bottom under ### Make some devices default put:

set-default-sink 1
set-sink-port 1 analog-output-headphones

Everything should work now as desired. Make sure that you comment this out again when you are tired of using the headphones.

5
  • 1
    This only makes ubuntu switch to headphones on start, no matter what. There's no sound from speakers now at start, even if headphones are unplugged. This is the behavior I experienced with 15.10. May 16, 2016 at 11:33
  • You won't get better than that, I am afraid. Links: bbs.archlinux.org/viewtopic.php?id=175951 bbs.archlinux.org/viewtopic.php?pid=1250505#p1250505 bbs.archlinux.org/viewtopic.php?id=212010 as the current state of the art. I really hope someone can come up with a better solution...
    – emk2203
    May 16, 2016 at 12:23
  • Meh... I could do a bash workaround. I can cook one up myself - no problem. But it simply messes things up. Every 6 months I have to run through Ubuntu changelogs, and my personal bodgelist, to see where things broke due to my, or someone else's negligence, or simply due to an upgrade to some API or frontend. That's why I don't do these anymore - it makes a mess, and is not worth the time that I will probably lose, after I encounter an inevitable update break to something. May 17, 2016 at 2:01
  • 1
    If you can do a bash workaround which 1) selects headphones only if they are plugged in, else speakers are default and 2) switches automatically to headphones and mutes speakers when you plug the headphones in I would be very interested in it.
    – emk2203
    May 18, 2016 at 9:10
  • This worked for me on Debian Stretch, though I have to use 0 instead of 1, which is the index returned by pacmd list-sinks.
    – Rodrigo
    Apr 1, 2018 at 13:31
2

Do a rm -rf ~/.pulse ~/.config/pulse worked like a charm.

2
  • 1
    Wow! I've been without a mic for over 2 months, and after several hours of googling, this was the only thing that fixed everything. Thank you!
    – Hosh Sadiq
    May 19, 2020 at 22:32
  • 1
    Going from 19.10 to 20.04 left me with broken pulseaudio config, I had no ~/.pulse folder though but for me, running rm -rf ~/.config/pulse and rebooting fixed it, thanks!
    – SidOfc
    May 20, 2020 at 21:20
0

The following should help you workaround the problem until you find a fix to your issue.

The following are a couple of scripts which do not do what you want, but probably contain all the pieces for what you need.

The second one contains a bunch of pulseaudio stuff that works, but which I don't really understand. I apologize in advance. ;)

Here's a script I used to use to turn my speakers back on after boot. It should be easy to modify to set your audio output as desired.

#!/bin/bash
## temporary kludge to turn the speakers back on at login

SOUND=1
if [ "${1}" == "-q" ]
then
  shift
  SOUND=0
fi

amixer set Speaker unmute > /dev/null
amixer set Speaker 100 > /dev/null
(( SOUND )) && mplayer -quiet /usr/lib/libreoffice/basis3.4/share/gallery/sounds/kongas.wav > /dev/null 2>&1

This one automatically switches my sound output between HDMI and analog output depending on whether HDMI is connected or not. Not what you want, but it does detect where the audio output is going and knows how to switch it to somewhere else.

#!/bin/bash
## audio_select
## Copyleft 08/11/2014 - JPmicrosystems
## Last modified 05/14/2015
## Added code to detect ramdass vs halo to handle older pactl version
## Added code to tell if the audio was already selected
## If HDMI is connected, audio output is channelled to HDMI
## Otherwise it's channelled to internal audio

## From: https://askubuntu.com/questions/458194/switching-to-hdmi-audio-when-hdmi-is-plugged-into-a-laptop-14-04
## Script needs to be triggered by a udev rule
## Works manually now

## udevadm monitor produces the following output

## Plug in HDMI udev events
##KERNEL[11363.720327] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
##UDEV  [11363.722979] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)

## Unplug HDMI udev events
##KERNEL[11392.043367] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
##UDEV  [11392.046155] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)

## Make a script name in SCRIPT_NAME
function script_name {
  ## See if the calling script has a name string defined
  if [ -n "${NAME}" ]
  then
    SCRIPT_NAME="${NAME}"
  else
    SCRIPT_NAME="$(basename $0)"
  fi
}

## Get active audio port type
function get_active_audio_port {
  ## first very rough cut
  local ACTIVE_AUDIO_PORT_NAME
  RC=0 ## Success
  ACTIVE_AUDIO_PORT_NAME="$(pactl list | grep 'Active Port:' | awk '{print $3}')"
  case "${ACTIVE_AUDIO_PORT_NAME}" in
    "analog-output-speaker")
      ACTIVE_AUDIO_PORT="Speakers"
      ;;
     "analog-output-headphones")
      ACTIVE_AUDIO_PORT="Headphones"
      ;;
    "hdmi-output-0")
      ACTIVE_AUDIO_PORT="HDMI"
    ;;
    *)
      ACTIVE_AUDIO_PORT="Unknown"
      RC=1 ## Failure
    ;;
  esac

  return $RC
 }

##source "$HOME/bin/bash_trace" ## debug
script_name
HOST="$(hostname)"
HDMI_STATUS=$(cat /sys/class/drm/card0/*HDMI*/status)
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
DSPTIME=10            # yad message persistence time
YOPT="--center --on-top --title ${SCRIPT_NAME}"  # yad common options

get_active_audio_port ## Find out where audio is going now
if ((RC))
then
  yad ${YOPT} --info --button=gtk-ok:0 --text="Failed to detect current audio source" --width 250 --timeout=${DSPTIME}
  exit 1
fi

if [ $HDMI_STATUS = "connected" ]
then
  if [ "${ACTIVE_AUDIO_PORT}" == "HDMI" ]
  then
    yad ${YOPT} --info --button=gtk-ok:0 --text="Audio already set to HDMI" --width 250 --timeout=${DSPTIME}
    exit 1
  fi
  pactl set-card-profile 0 output:hdmi-stereo
  if [ "$HOST" == "ramdass" ]  ## Using newer version of pactl
  then
    pactl set-default-sink alsa_output.pci-0000_00_1b.0.hdmi-stereo
  else
    pactl set-sink-port alsa_output.pci-0000_00_1b.0.hdmi-stereo hdmi-output-0
  fi
  for i in ${INPUTS[*]}
  do
    pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.hdmi-stereo  &> /dev/null
  done

  yad ${YOPT} --info --button=gtk-ok:0 --text="Audio directed to HDMI" --width 250 --timeout=${DSPTIME}
else
  if [ "${ACTIVE_AUDIO_PORT}" == "Speakers" ] || [ "${ACTIVE_AUDIO_PORT}" == "Headphones" ]
  then
    yad ${YOPT} --info --button=gtk-ok:0 --text="Audio already set to Analog Output" --width 250 --timeout=${DSPTIME}
    exit 1
  fi
  pactl set-card-profile 0 output:analog-stereo
  if [ "$HOST" == "ramdass" ]  ## Using newer version of pactl
  then
    pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
  else
    pactl set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo analog-output-speaker                
  fi

  for i in ${INPUTS[*]}
  do
    pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.analog-stereo  &> /dev/null
  done

  yad ${YOPT} --info --button=gtk-ok:0 --text="Audio directed to Analog Output" --width 250 --timeout=${DSPTIME}
fi
6
  • The thing is, that no script that runs of after lightgm (login manager) will be sufficient enough. There are sound effects playing before you log in. Would these be able to run from after init? May 13, 2016 at 10:44
  • If those "initial" sounds are important to you, then, no, these probably wouldn't work. At boot time there's very little available/in your PATH - just what's needed to get things going. The rest - like things these scripts use gets added to the PATH later - when your user logs in. I don't know when pulseaudio is even started. If you need to boot without waking someone up, etc., I don't know how to address that.
    – Joe
    May 14, 2016 at 1:51
  • Another random workaround would be to go looking for the sound files which are played (probably something.ogg) and replace them with silent files. Still doesn't fix the problem, but maybe it helps. Also depends on if anything else wants to use those sound files later. If so, you could save the originals and put them back after boot. But then you have to start messing with systemd to get things right each time.
    – Joe
    May 14, 2016 at 1:56
  • @DavidFoerster - while you are technically correct (any my reply starts with "this is not an answer"), giving someone a place to start looking or tools that might contribute to a solution is way better that silence IMHO. When I posted, there were no other answers. My content would not have fit in a comment or string of comments and the code would have to have been linked or unreadable. If SE comments supported full formatting, I would have put the post in one.
    – Joe
    May 15, 2016 at 19:49
  • @DavidFoerster: Looking at the help page you linked to, this does seem like a partial answer to the question. It may not be a very good answer, but even attempting to provide a partial solution does make it a valid "answer" by the SE definition of the term. May 18, 2016 at 14:12
0

Alright, I think I've got something you can try.
If you search for Multimedia Systems Select on the Dash. Open it and go to the Audio tab, where you can select the default audio Input and Output devices.

This should be installed by default. If it isn't, you can always run sudo apt-get install gnome-media. If it is not shown in the Dash, run:

gksudo gedit /usr/share/applications/gstreamer-properties.desktop. In the resulting text file, go to the line starts with NoDisplay=. Change the NoDisplay=true to NoDisplay=false Hope that helps!

2
  • I had to switch to Ubuntu Gnome few days ago, and on this side the packet gnome-media has no candidate. May 20, 2016 at 17:15
  • Alright. I'll see what I can dig up for you then. Good luck!
    – James
    May 20, 2016 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .