I regularly forget how to muck about with sound settings from the command-line. So I get situations where I have installed something new on a machine and the sound is either muted or very low. Or the sound is working through the headphones but not the laptop speakers.
So I thought I'd write this page as a reference, as much so I'd know where I could find succinct memory joggers as to provide ALSA reference to Eyes Free Linux Ninja for completeness.
Get All Sound Device Details
Get a List of Available Controls
$ amixer controls
The values shown as numid integer values are the controls we can change.
Get Capabilities and Current Settings of One Control
$ amixer cget numid=3
Assuming control numid=3 is an output mixer control, to set the volume of both channels to half-way:
$ amixer cset numid=3 50%
If for some reason you wanted to set the left channel to 50% and the right channel to 100%:
$ amixer cset numid=3 50%,100%
You can also set them with integer values between the maximum and minimum, often 0 and 65536:
$ amixer cset numid=3 32767
Gives about half-volume assuming the maximum is 65536.
Muting and un-muting
To mute the sound you can use control 4, assuming it is the output audio switch control:
$ amixer cset numid=4 off
This will also set the left and right channels of control 3 to 0%.
However, the value of the volumes seem to be stored somewhere because when you unmute it again it restores them.
I have found odd effects when changing the volume while it is muted so best to avoid doing that.
Un-mute the Same Control
$ amixer cset numid=4 on
Saving the ALSA State
The state is stored and restored using this file:
(At least on Debian and derivatives).
Once you have the sound configuration as you want it you can store it there using the alsactl command which you have to run with root permissions as it changes a protected file.
$ sudo alsactl store
To restore from this file back into the current settings:
$ sudo alsactl restore
Note that although it is possible to read the file without root privilages, on Debian and derivatives the path to alsactl is not in the path by default for ordinary users so sudo is necessary to find it.