How to prevent white noise in headphones on Dell XPS 13 9350/9360

Set Headphone Mic Boost gain to 10dB. Any other value seems to cause the irritating background noise in headphones. This can be done with amixer:

amixer -c0 sset 'Headphone Mic Boost' 10dB

To make this happen automatically every time you headphones are connected install acpid.

Start it by running: sudo systemctl start acpid.service

Enable it by running: sudo systemctl enable acpid.service

Create following event script /etc/acpi/headphone-plug

event=jack/headphone HEADPHONE plug
action=/etc/acpi/cancel-white-noise.sh %e

Then create action script /etc/acpi/cancel-white-noise.sh:

#! /bin/bash
amixer -c0 sset 'Headphone Mic Boost' 10dB

Now Headphone Mic Boost will be set to 10dB every time headphones are connected. To make this effective you need to restart your laptop.


How do I prevent it?

This issue was caused by a bug in Linux's HD Audio driver and is now fixed. All kernel versions 5.7 and above will have the fix, and it has additionally been backported into several stable kernels, appearing in versions 5.6.5, 5.5.18, 5.4.33, and 4.19.116 respectively. Upgrading to a kernel with the fix should make the issue disappear without additional configuration or workarounds.

The fix in the kernel is better than the workaround from the other answer in several ways:

  • Audio in headphones is significantly louder and somewhat clearer.
  • There is no longer popping in headphones on codec suspend/resume.
  • The "Headphone Mic Boost" control actually serves its intended purpose—to set the gain when the 3.5mm jack is configured as a microphone input. It no longer has any effect when the jack is configured for headphones or a headset.

What was the problem?

It turns out that some Realtek HD Audio codecs, including the one in the XPS 13 9350 and 9360, can route audio in ways not exposed by the self-documenting "node graph" that is usually used to configure HD Audio codecs. Due to a confluence of several errors, the kernel has been configuring the XPS 13 since at least 2015 to capture the signal from the 3.5mm jack as if a microphone were plugged in, amplify it, and route it back out to the jack.

As you might imagine, this feedback loop caused undesirable effects, most noticeably white noise that varied in character depending on the amount by which the signal was amplified before being fed back (the "Headphone Mic Boost" control). It seems to be a lucky accident that one of the gain levels happened to result in almost no noise. However, because the feedback loop was still there, you'd still hear quieter, lower quality audio than intended as well as popping on codec suspend/resume.

For more information, see my patch series which implemented the fix. The commit messages in that series, along with the reverse-engineered documentation it adds for the Realtek register that controls hidden audio routes, provide a detailed explanation of the issue, its history, and the fix.

Tags:

Audio

Alsa

Jack