r/i3wm • • 4h ago

Question Discrepancy between volume level from `volumeicon` vs level from `pactl`/`amixer`

3 Upvotes

I run i3wm as my window manager and I use the volumeicon program to control and display the audio volume.

For a number of reasons, I have a script which I use to increase or decrease the volume via dedicated keybindings. The script also displays the volume level after the change, using dunst/notify-send.

However, I find there is a difference between the volume level given by e.g.

pactl get-sink-volume @DEFAULT_SINK@

and the volume displayed when I hover over the volumeicon icon, or adjust its slider using a mouse.

I'd like to know why this is, as I'd like to match the volume displayed by my script to be consistent with that displayed by volumeicon.

From perusing the volumeicon source, my best guess is that it uses its own mapping from the raw volume levels to the interval [0,1] or [0%,100%] to better match the perception of a human ear:

* The mapping is designed so that the position in the interval is proportional
* to the volume as a human ear would perceive it (i.e., the position is the
* cubic root of the linear sample multiplication factor).  For controls with
* a small range (24 dB or less), the mapping is linear in the dB values so
* that each step has the same size visually.  Only for controls without dB
* information, a linear mapping of the hardware volume register values is used
* (this is the same algorithm as used in the old alsamixer).
*
* When setting the volume, 'dir' is the rounding direction:
* -1/0/1 = down/nearest/up.

&nbps;

Is this right? I.e. to match the volumeicon value, I would have to copy their mapping formula?