1

I'm trying to write a bash script to find the percentage of the sound volume. I used this:

amixer get Master | awk '/Mono.+/ {print $6=="[off]"?$6:$4}'

This command prints the volume percentage of Master channel, or prints [off] if it's muted.

However, as you can see from screenshot below, the percentage that amixer get Master outputs is different from the percentage that alsamixer shows in the Master channel.

enter image description here

What's the difference? Which one is the real percentage of my Master channel? How can I get the percentage that alsamixer shows (if it's the real one)?

| improve this question | | | | |
1

From man 1 alsamixer:

Volume Mapping

In alsamixer, the volume is mapped to a value that is more natural for 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).

Then from man 1 amixer:

-R
Use the raw value for evaluating the percentage representation. This is the default mode.

-M
Use the mapped volume for evaluating the percentage representation like alsamixer, to be more natural for human ear.

Therefore use amixer -M get Master.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.