Skip to main content

Exponential/logarithmic adjustment scales for audio and brightness in Linux

·2 mins

In my Human-Machine Interfaces course at university, I learned that humans many times perceive changes better in exponential increments as opposed to linear increments.

Allegedly, Apple is aware of this, although I couldn’t easily find concrete confirmation online, and implements audio and brightness increments exponentially. This perhaps explains why the brightness and volume sliders in macOS don’t have percentages next to them, as the strange steps could freak out more casual users.

Now that I’m returning to Linux, I was getting frustrated with this not being the default behaviour, possibly because the developers are not aware of this phenomenon. Both in brightness and audio, at higher values I needed many steps to perceive changes and at lower values it was always either too high or too low.

Audio volume #

When looking at the documentation for the sound block in i3status-rust, there was this option of natural_mapping, which enabled this logarithmic/exponential behaviour in ALSA. I was not aware that ALSA was capable of that, so it seemed like good news. Now I just needed the same behaviour in PulseAudio/PipeWire, which turned out to not be so easy.

I finally found a thread on Reddit where a user commented that you can change the audio in PulseAudio by dBs instead of percentage points in the linear scale. As decibels have an exponential/logarithmic scale, this solved my problem.

Then, to have this behaviour, I mapped the XF86AudioLowerVolume and XF86AudioRaiseVolume keys in my window manager to the following, respectively:

pactl set-sink-volume @DEFAULT_SINK@ +2dB'";
pactl set-sink-volume @DEFAULT_SINK@ -2dB'";

Backlight brightness #

As for backlight, I’ve had this behaviour for a few years and can’t recall where I originally found it. The trick is to use a program for managing the backlight brightness that can take multipliers as arguments, like light.

Again, I mapped the XF86MonBrightnessDown and XF86MonBrightnessUp keys to:

light -T 0.618";
light -T 1.618";

References #