I've been unable to piece together a proper solution to get alsamixer to properly manage my sound.
Here's my desired behavior:
- On rebooting, hibernating or sleeping and then waking up, I want all alsamixer levels and mute settings preserved.
- The mute key on my keyboard should toggle mute, the volume-up and volume-down buttons should increase or decrease the volume, and if applicable, remove muting.
- When I plug in headphones, there should be a different volume setting for them and the volume levels should automatically adjust themselves. Doesn't matter to me if master changes or if the headphone / speaker levels change. Just need to make sure that this works with the volume-{up,down} keys.
I use XMonad and xbindkeys to map my volume/mute keys to actions. Currently:
"amixer set Master 2dB+"
XF86AudioRaiseVolume
"amixer set Master 2dB-"
XF86AudioLowerVolume
"/path/to/mute.sh"
XF86AudioMute
where mute.sh is
FILE=$HOME/.mute
if [ -f $FILE ]; then
amixer set Master `cat $FILE`
rm $FILE
else
amixer get Master\
| grep Mono\
| grep -P -o '[\d]{1,3}'\
| head -n 1\
> $FILE
amixer set Master 0
fi
Currently, when I restart my computer, it seems like random channels are muted. And my mute script actually just sets the volume level to zero, which isn't ideal. On the bright side, plugging in headphones does seem to adjust the volume level.
Any ideas how I could make the muting and restart behavior better?
----- EDIT 1 -----
Master toggle mutes speaker channel also:
$ amixer get Speaker | tail -n 1
Front Right: Playback 87 [100%] [0.00dB] [on]
$ amixer set Master toggle
Simple mixer control 'Master',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
Playback channels: Mono
Limits: Playback 0 - 87
Mono: Playback 87 [100%] [0.00dB] [off]
$ amixer set Master unmute
Simple mixer control 'Master',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
Playback channels: Mono
Limits: Playback 0 - 87
Mono: Playback 87 [100%] [0.00dB] [on]
$ amixer get Speaker | tail -n 1
Front Right: Playback 87 [100%] [0.00dB] [off]
----- EDIT 2 -----
Toggling is weird:
$ for x in Master Headphone Speaker; do amixer set $x toggle ;done
Simple mixer control 'Master',0
Mono: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Headphone',0
Front Left: Playback 87 [100%] [0.00dB] [on]
Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Speaker',0
Front Left: Playback 87 [100%] [0.00dB] [off]
Front Right: Playback 87 [100%] [0.00dB] [off]
$ for x in Master Headphone Speaker; do amixer set $x toggle ;done
Simple mixer control 'Master',0
Mono: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Headphone',0
Front Left: Playback 87 [100%] [0.00dB] [on]
Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Speaker',0
Front Left: Playback 87 [100%] [0.00dB] [on]
Front Right: Playback 87 [100%] [0.00dB] [on]
amixer scontrols
to see if there are any useful controls.amixer scontents
.