Skip to content

Instantly share code, notes, and snippets.

@mk-pmb
Last active July 7, 2025 03:50
Show Gist options
  • Save mk-pmb/2296fc95463d332b7c4d0c500be6864d to your computer and use it in GitHub Desktop.
Save mk-pmb/2296fc95463d332b7c4d0c500be6864d to your computer and use it in GitHub Desktop.
Don't clutter the profile selection list with HDMI and surround modes that I don't want anyway.

PulseAudio: Just analog stereo, please!

#:via: hdtw-lib:config-util-pmb/pulseaudio/
#:web: https://gist.github.com/mk-pmb/2296fc95463d332b7c4d0c500be6864d

The problem: User interface clutter.

On Ubuntu focal, I usually use my sound card in one of three modes: "Stereo Output", "Stereo Duplex", or "Off". (The latter to not surprise anyone in case my Bluetooth headphones disconnect unexpectedly.)

I want to be able to switch between these modes quickly in pavucontrol.

However, between the Stereo options and the "off" option, there's a gazillion of HDMI entries wasting my attention, time and effort.

Keyboard to the rescue?

It took a while until I figured out there's a trick for keyboard control: Press "up, up, space" to switch to "Off", and "down, down, space" to switch to "Stereo Output". Still, this is not a good solution, because first I have to activate the profile selection dropdown, which I usually do by clicking it with my cursor. How nice would it be if I could just extend that click to a drag, instead of enduring an input modality switch, then have to locate two different keys, and press them the right amount of times. Not really a complicated task, but annoying enough to take my attention away from what I was originally doing.

Disabling kernel module had bad side effects.

I tried blacklisting the kernel modules snd_hda_codec_hdmi but it doesn't keep snd_hda_intel from loading them. So I sabotaged it by also adding a bogus install instruction:

# /etc/modprobe.d/blacklist-hdmi-audio.conf
blacklist snd_hda_codec_hdmi
install   snd_hda_codec_hdmi    /bin/true

That worked most of the way, with only two HDMI profiles surviving. Unfortunately, it also made all the analog stereo options fully mute.

(I also tried banning snd_hda_codec_realtek to save a bit more RAM while I was there anyway, but it doesn't make any difference on what audio profiles will be available.)

Solution: Disable specific PulseAudio profiles.

At last, I found the place where I could disable individual profiles. Since future Ubuntu versions will replace PulseAudio with PipeWire soon, I won't waste effort for making this clean and pluggable, and instead write just a hotfix script for now.

#!/bin/bash
# -*- coding: utf-8, tab-width: 2 -*-
set -o pipefail -o errexit
cd -- /usr/share/pulseaudio/alsa-mixer/profile-sets
DFC='default.conf'
BAK="$DFC.dist.bak"
sudo cp --no-clobber --no-target-directory -- "$DFC" "$BAK"
sudo grep -qFe '[Mapping ' -- "$BAK"
TMPF="$HOME/tmp.pulseaudio-default-profiles.$$.conf"
echo '
/^\[Mapping /{
/\b(hdmi)\b/s~^~#~
/\b(iec958)\b/s~^~#~ # IEC 958 = S/PDIF = Sony/Philips Digital Interface
/\b(surround)\b/s~^~#~
s~^#+~# ~
}
/^# \[Mapping /,/^$/s~^(#[ #]+|)([A-Za-z])~# \2~
' | sed -rf - -- "$BAK" >"$TMPF"
sudo grep -qFe '[Mapping ' -- "$TMPF"
sudo mv --no-target-directory -- "$TMPF" "$DFC"
sudo chown --reference . -R .
systemctl --user restart pulseaudio.service
echo 'Success! Your PulseAudio should now be analog-stereo-only.'
Copyright (c) 2025 mk-pmb <https://github.com/mk-pmb>
I hereby release the files in this Gist into the public domain.
Since that attempt may be vain in some jurisdictions,
I also grant everyone licenses under the terms of (at your choice)
CC-0, CC-BY-4.0, WTFPL and/or ISC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment