A Weird Imagination

PulseAudio headphone jack troubles

Posted in

The problem#

Since I got a new motherboard (and therefore new audio hardware as I'm using the basic one built into the motherboard) sometimes after I unplugged my headphones, my speakers would not output any sound.

pavucontrol showed the only available output as "Built-in Audio Digital Stereo" with a port of "S/PDIF", which does not describe any audio device I had ever used. If I plugged my headphones back in, they would work fine, and usually after unplugging and plugging back in my headphones enough times, my computer would eventually acknowledge that my speakers were connected by showing the expected "Built-in Audio Analog Stereo" with a port of "Line Out".

The solution#

In /usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf change

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

to

[Jack Front Headphone]
state.plugged = no
state.unplugged = yes       # changed from unknown

This forces PulseAudio to consider there to be speakers plugged into the "Line Out" port, so it may cause strange behavior if that is not the case.

To apply the change, run

pulseaudio --kill
pulseaudio --start

to restart PulseAudio.

The details#

A simpler workaround#

In pavucontrol on "Configuration" tab (it's the last one, so you may have to make the window bigger or scroll over to see it), under "Built-in Audio", there's a "Profile" drop-down. Selecting "Analog Stereo Output" from the list made sound come out of my speakers. Unfortunately, this solution requires doing it every time I unplug the headphone jack.

What is that file?#

The files in the /usr/share/pulseaudio/alsa-mixer/paths/ directory control how PulseAudio interacts with ALSA devices. The full documentation can be found in analog-output.conf.common, but for our purposes, the part we care about is that the [Jack] sections control how PulseAudio reacts to an audio jack being plugged or unplugged. The [Jack Front Headphone] section controls what happens when the state of the front headphone jack changes, and since the file we edited was analog-output-lineout.conf, we're specifically changes what happens to the "Line Out" device. The

state.unplugged = unknown

line that was there before means that when the headphones are unplugged, the state of the "Line Out" device is unknown, defaulting to whatever it's known to be from other information. This should be fine, but wasn't for my setup for whatever reason. Changing it to

state.unplugged = yes

means that whenever the headphones are unplugged, PulseAudio should assume that the speakers are plugged in.

The other line,

state.plugged = no

ensures that when headphones are plugged in, PulseAudio will not output sound to the speakers because it will see the speakers as not being plugged in.

How did I get there?#

I generated a PulseAudio log and plugged and unplugged my headphones while logging. Searching through the verbose log for references to the headphone jack eventually lead me to the configuration file mentioned above.

I found sections on the headphones being plugged in:

module-alsa-card.c: Jack 'Front Headphone Jack' is now plugged in
device-port.c: Setting port analog-output-headphones to status yes

And on the headphones being unplugged:

module-alsa-card.c: Jack 'Front Headphone Jack' is now unplugged
device-port.c: Setting port analog-output-headphones to status no

Looking for other references to Front Headphone Jack, I found

alsa-mixer.c: Jack Line Out, alsa_name='Line Out Jack', detection unavailable
alsa-mixer.c: Jack Line Out Phantom, alsa_name='Line Out Phantom Jack', detection unavailable
alsa-mixer.c: Jack Headphone, alsa_name='Headphone Jack', detection unavailable
alsa-mixer.c: Jack Front Headphone, alsa_name='Front Headphone Jack', detection possible

which says that while the "Front Headphone" jack supports detecting when it is plugged in, the "Line Out" jack does not, which is probably why PulseAudio was getting confused about which output to use.

Searching for "analog-output-headphones" in the log (which was mentioned in the log messages about the headphones being plugged in), I found a reference to configuration files:

conf-parser.c: Parsing configuration file '/usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf'
conf-parser.c: Parsing configuration file '/usr/share/pulseaudio/alsa-mixer/paths/analog-output.conf.common'
conf-parser.c: Parsing configuration file '/usr/share/pulseaudio/alsa-mixer/paths/analog-output-speaker.conf'
conf-parser.c: Parsing configuration file '/usr/share/pulseaudio/alsa-mixer/paths/analog-output.conf.common'
conf-parser.c: parsing configuration file '/usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf'

That lead me to the documentation in analog-output.conf.common, and with some experimentation I was able to figure out enough of how they worked to come up with the change suggested above.

Not a permanent solution#

That configuration file gets reset regularly, presumably each time PulseAudio is updated, so I have to reapply the change. This StackExchange answer provides a mechanism for using a different copy of those configuration files that won't get overwritten by updates.

Comments

Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.

There are no comments yet.