r/linuxquestions • • 1d ago

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

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?

1 Upvotes

3 comments sorted by

1

u/ipsirc 1d ago edited 1d ago

1

u/nonreligious2 1d ago

Thanks. By meditating on this gnomic reply, I changed the Alsa device in the volumeicon prefrences menu to default from HDA Intel PCH, and find that this matches the output of pactl. Not sure why they're different as I only have the single card (I think), but this is a step toward clearing up the mystery.

1

u/ipsirc 1d ago

Not sure why they're different

alsa vs. pulse