The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 43,741โ€…    Votes:  13โ€…
Tags: sound   alsa   headphones  
Link: ๐Ÿ” See Original Answer on Ask Ubuntu ๐Ÿ”—

Title: How to switch between headphones and speakers without unplugging headphones
ID: /2018/02/14/How-to-switch-between-headphones-and-speakers-without-unplugging-headphones
Created: February 14, 2018    Edited:  April 28, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

Having both speakers and headphones plugged in and switching in software on-the-fly

By design, Pulseaudio automatically turns off Line Out when headphones are plugged in and uses Headphone slider instead. You can observe this behavior in alsamixer. What we want is to have Headphone and Line Out sliders working separately and at the same time. This is extremely useful if you want to remap Realtekโ€™s jacks to have, say, Rear Green for headphones and Blue for speakers (with the help of hdajackretask from alsa-tools).

To achieve this, you should directly edit Pulseaudio mixerโ€™s configuration.

1. We tell pulseaudio that headphones are always plugged in.




[Jack Headphone]
state.plugged = no
state.unplugged = unknown

Change no to yes.

If youโ€™re using the jacks on the front of your computerโ€™s case change [Jack Front Headphone] instead.

2. By default, Line Outโ€™s volume controlled only by Master, and not by Line Out slider itself.

We want to merge Line Out with Master. Add this snippet to the end of the file:

[Element Line Out]
switch = mute
volume = merge

3. We need to completely cut off Line Out when we use headphones.



Add this snippet to the end of the file:

[Element Line Out]
switch = off
volume = off

On some systems you may also need to disable Front by adding this snippet:

[Element Front]
switch = off
volume = off

4. Like Pulseaudio, Alsa itself cuts off speakers when headphones are plugged in.

Open alsamixer: alsamixer -c0 or alsamixer -c1

Use / to Auto-Mute mode. Disable Auto-Mute Mode with . Close alsamixer with Esc.

Save your changes with: alsactl store

5. Restart Pulseaudio

$ pulseaudio -k
$ pulseaudio --start

Now you have two separate ports on the same sink in pulseaudio. They mute each other, so you can switch to headphones and this will mute Line Out, and vice versa. To switch between ports you can use Gnome or Plasma sound mixer, or install appropriate desktop extension.


โ‡ง Install Ubuntu including all drivers from the USB-Live system `sudo reboot` vs `reboot` - what is the difference?  โ‡ฉ