Skip to content

Instantly share code, notes, and snippets.

@junkdeck
Created June 3, 2020 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junkdeck/5b13ea05d4b47e746480d83db7d99a04 to your computer and use it in GitHub Desktop.
Save junkdeck/5b13ea05d4b47e746480d83db7d99a04 to your computer and use it in GitHub Desktop.
PulseAudio sane headphone/lineout switching
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.
Edit:
/usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf
Find:
[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.
Edit:
/usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf
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.
@junkdeck
Copy link
Author

junkdeck commented Jun 3, 2020

this should really be the default behavior of pulseaudio. doesn't make any sense to kill lineout as soon as headphone jack is plugged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment