Why is there values mismatch between amixer and alsamixer?

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: MattKingUSA, khz

Post Reply
Nachei
Established Member
Posts: 235
Joined: Fri Feb 17, 2012 3:32 am
Has thanked: 6 times
Been thanked: 27 times
Contact:

Why is there values mismatch between amixer and alsamixer?

Post by Nachei »

I'd like to set a keyboard-driven volume control (+ key for volume up, - for volume down) that is coherent with the volume levels used by alsamixer. My Internet research shows that the command to use for that would be amixer sset. However, if I open alsamixer, and in a different terminal I send amixer sset commands, the numbers don't match! Examples:

amixer sset Master 80 ----> In AlsaMixer Master reaches 100
amixer sset Master 50 ----> In AlsaMixer Master reaches 36

I've tried using PCM instead of Master and the mismatch happens the same. The AlsaMixer version is 1.0.26, fwiw. Could someone explain this to me or provide a clarifying link? Thank you.
Luc
Established Member
Posts: 741
Joined: Fri Mar 27, 2015 1:04 pm
Been thanked: 1 time

Re: Why is there values mismatch between amixer and alsamixe

Post by Luc »

I don't know why, but why should this matter so much? Just raise or lower the volume, that's all you need. And it helps to know that the maximum volume in amixer is 64.

~/.config/openbox/lxde-rc.xml

Code: Select all

    <!-- Keybinding for Volume management -->
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>~/xxxx/volumechange.fish up</command>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <command>~/xxxx/volumechange.fish down</command>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <command>amixer -q sset Master toggle</command>
      </action>
    </keybind>
~/.config/fish/functions/volumechange.fish

Code: Select all

#!/usr/bin/env fish
function volumechange
	set _choice $argv[1]
	
	if	test $_choice = "up"
		amixer -q sset Master unmute
		amixer -q sset Master 2+
		set _currVolume (amixer sget Master | sed -r '/%/!d;s/.*\[([0-9]+)%.*/\1/')
		echo $_currVolume
		osdctl -b "vol $_currVolume",$_currVolume
	end
	if	test $_choice = "down"
		amixer -q sset Master unmute
		amixer -q sset Master 2-
		set _currVolume (amixer sget Master | sed -r '/%/!d;s/.*\[([0-9]+)%.*/\1/')
		osdctl -b "vol $_currVolume",$_currVolume
	end
	if	test $_choice = "max"
		amixer -q sset Master unmute
		amixer -q sset Master 64
		set _currVolume (amixer sget Master | sed -r '/%/!d;s/.*\[([0-9]+)%.*/\1/')
		osdctl -b "vol $_currVolume",$_currVolume
	end
	if	test $_choice = "mute"
		amixer -q sset Master mute
		osdctl -b MUTE,0
	end
end
You may want to install osdsh for the full package.
Post Reply