Automatic switching between speakers and headphones

I am having trouble with my onboard sound card, which i believe is from Intel. While both the speakers and the headphones work, i have to switch between them using Pulse Audio Volume Control. I cannot figure out a way to do this automatically. To add to that, it reacts badly to the power saving sleep mode. Upon wake up it switches automatically to “headphone unplugged”, without headphones in and if i plug them no sound comes out. switching back to speakers is also not possible. I should add that i tried a long list of other distributions / Ububtu 18.04, 18.10, 19.04, Manjaro, Debian, Fedora, Mint, etc. with the same issues. This computer is near identical to one i had until recently, which worked flawlessly, it is the same model but a slightly newer subversion, which i imagine includes minor updates to components, including the audio and maybe the new version is not yet fully supported.
Is there anything i can do besides waiting for Linux hardware support to catch up or installing windows, which i am determined to avoid.
Thank you very much in advance!

You can use pacmd to control and set defaults for pulseaudio from the command line. IE:

pacmd list | grep -e 'index:' -e device.string -e 'name:' -e 'driver' -e 'headphones'
pacmd set-default-sink alsa_output.Headphones

The default “sink” or output will need to be changed according to your system. You can also just change the defaults using Settings->Sound->Output device.

As far as the problem with suspend, can you run:

pactl list sinks

while you are having the issue to see if the driver is coming back up or not.

2 Likes

Thank you for your help @CaptSilver! First with the pactl list sinks output.

this is after fresh reboot:

Sink #0
State: SUSPENDED
Name: alsa_output.pci-0000_00_0e.0.analog-stereo
Description: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 6
Mute: no
Volume: front-left: 29899 / 46% / -20.45 dB, front-right: 29899 / 46% / -20.45 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.pci-0000_00_0e.0.analog-stereo.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = “16”
device.api = “alsa”
device.class = “sound”
alsa.class = “generic”
alsa.subclass = “generic-mix”
alsa.name = “ALC256 Analog”
alsa.id = “ALC256 Analog”
alsa.subdevice = “0”
alsa.subdevice_name = “subdevice #0
alsa.device = “0”
alsa.card = “0”
alsa.card_name = “HDA Intel PCH”
alsa.long_card_name = “HDA Intel PCH at 0xa1110000 irq 133”
alsa.driver_name = “snd_hda_intel”
device.bus_path = “pci-0000:00:0e.0”
sysfs.path = “/devices/pci0000:00/0000:00:0e.0/sound/card0”
device.bus = “pci”
device.vendor.id = “8086”
device.product.id = “3198”
device.form_factor = “internal”
device.string = “front:0”
device.buffering.buffer_size = “65536”
device.buffering.fragment_size = “32768”
device.access_mode = “mmap+timer”
device.profile.name = “analog-stereo”
device.profile.description = “Analog Stereo”
device.description = “Built-in Audio Analog Stereo”
alsa.mixer_name = “Realtek ALC256”
alsa.components = “HDA:10ec0256,10ec118c,00100002 HDA:8086280d,80860101,00100000”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card-pci”
Ports:
analog-output-speaker: Speakers (priority: 10000)
analog-output-headphones: Headphones (priority: 9000, not available)
Active Port: analog-output-speaker
Formats:
pcm

and this is after waking up from sleep (the difference is at the end):

Sink #0
State: SUSPENDED
Name: alsa_output.pci-0000_00_0e.0.analog-stereo
Description: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 6
Mute: no
Volume: front-left: 34172 / 52% / -16.97 dB, front-right: 34172 / 52% / -16.97 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.pci-0000_00_0e.0.analog-stereo.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = “16”
device.api = “alsa”
device.class = “sound”
alsa.class = “generic”
alsa.subclass = “generic-mix”
alsa.name = “ALC256 Analog”
alsa.id = “ALC256 Analog”
alsa.subdevice = “0”
alsa.subdevice_name = “subdevice #0
alsa.device = “0”
alsa.card = “0”
alsa.card_name = “HDA Intel PCH”
alsa.long_card_name = “HDA Intel PCH at 0xa1110000 irq 133”
alsa.driver_name = “snd_hda_intel”
device.bus_path = “pci-0000:00:0e.0”
sysfs.path = “/devices/pci0000:00/0000:00:0e.0/sound/card0”
device.bus = “pci”
device.vendor.id = “8086”
device.product.id = “3198”
device.form_factor = “internal”
device.string = “front:0”
device.buffering.buffer_size = “65536”
device.buffering.fragment_size = “32768”
device.access_mode = “mmap+timer”
device.profile.name = “analog-stereo”
device.profile.description = “Analog Stereo”
device.description = “Built-in Audio Analog Stereo”
alsa.mixer_name = “Realtek ALC256”
alsa.components = “HDA:10ec0256,10ec118c,00100002 HDA:8086280d,80860101,00100000”
module-udev-detect.discovered = “1”
device.icon_name = “audio-card-pci”
Ports:
analog-output-speaker: Speakers (priority: 10000, not available)
analog-output-headphones: Headphones (priority: 9000, available)
Active Port: analog-output-headphones
Formats:
pcm

Thanks again @CaptSilver, regarding the setting of a default output device, this isn’t really the problem. I can change that from Pulse Audio. The normal behavior would be that it changes automatically. Since this is a laptop, not a desktop machine, I change frequently between speakers and headphones and I expect the headphones to be recognized when i plug the jack in, and when i unplug them to go to speakers.
in Settings->Sound->Output device there is only one device - speakers after fresh start and headphones after wake up from sleep and I cannot change them or set defaults. From Pulse Audio however I can see both of them and change them, but after sleep none of them works (they both work after fresh start). Perhaps a solution here would be to prevent the audio device from going to sleep, I saw this in another forum, but haven’t tried it yet.

maybe a hint here, when i start the alsamixer this is the output, the card is shown as ‘pulseaudio’, i can change it with F6 from ‘default’ to ‘0 HDA Intel PCH’ and then i see what i set in pulse audio - speaker or headphones mutted respectively

Weirdness, I will check into this later today… you might want to try to restart pulseaudio to see if that fixes the issue:

pulseaudio --kill; pulseaudio --start

If it fixes it, then all we have to do is write a short script to activate upon resuming.

running pulseaudio --kill; pulseaudio --start did not change anything - no sound from the speakers or the headphones. changing settings in the alsa mixer also did not help

I am not finding much info about this issue. I might have to dust off an older laptop of mine with this card to see if I can get this issue to pop up. :confused: I suggest something similar to what we have already tried but also reloading alsa:

pulseaudio --kill; sudo alsactl kill rescan; pulseaudio --start

i don’t think it’s a new or rare problem as i found quite a few similar posts in the forums, but unfortunately none of the solutions worked.
it’s a rather new laptop, from this spring, the particular submodel, i suspect it’s an updated card that is not properly recognised. I think i am going to try windows now, just to see if it works there and what is the device name it is recognised as there.
Thank you for you help @CaptSilver

Ok, update. We learned something. The clean install of Win 10 initially had the same problem - the speakers were recognised, but not the headphones. plugging them in would do nothing. However, windows found and installed “Realtek audio control” automatically and things started working normally. my guess is the linux driver is just out of date now. I am going to have to wait until the ALSA guys get that sorted out, as the realtek drivers are for kernel 3.18 or something, years behind :frowning: