18.04, 16.04 Headphones detected, but not switched on automatically after startup

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"

Solution 1:

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.

Solution 2:

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.

Solution 3:

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