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"

5 Answers5

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.

Luis Alvarado
  • 216,643
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.

emk2203
  • 4,393
  • 1
  • 26
  • 52
2

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

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
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
fossfreedom
  • 174,526
Joe
  • 2,012
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!

James
  • 311