(defgroup amixer nil
"Interface to the command line alsa mixer."
:group 'external)
(defcustom amixer-mixer-program "amixer"
"External mixer program (to adjust volume)."
:type 'string
:group 'amixer)
(defcustom amixer-master-volume 40
"Volume in percent."
:type 'integer
:group 'amixer)
(defcustom amixer-volume-increment 10
"Volume increment value."
:type 'integer
:group 'amixer)
(defcustom amixer-master-volume-id 40
"Identifer of the master volume control.
Call 'amixer controls' and take the number of an entry that looks like:
numid=40,iface=MIXER,name='Master Playback Volume'
The master volume id in this example is 40.
"
:type 'integer
:group 'amixer)
(defcustom amixer-card-id 0
"Alsa Id of the sound card. Use 0 for the first card."
:type 'integer
:group 'amixer)
(defun amixer-set-volume (num)
"Set volume using 'amixer-mixer-program' to num percent."
(interactive "nVolume: ")
(setq amixer-master-volume (max 0 (min 100 num)))
(message "Volume: %d%%" amixer-master-volume)
(amixer-set-volume-internal amixer-master-volume))
(defun amixer-set-volume-internal (volume)
(start-process "mixer-process" nil
amixer-mixer-program "-c" (int-to-string amixer-card-id)
"cset" (concat "numid=" (int-to-string amixer-master-volume-id))
(concat (int-to-string volume) "%")))
(defun amixer-increment-volume ()
"Ajust volume up by default increment."
(interactive)
(amixer-set-volume (+ amixer-master-volume amixer-volume-increment)))
(defun amixer-decrement-volume ()
"Ajust volume down by default increment."
(interactive)
(amixer-set-volume (- amixer-master-volume amixer-volume-increment)))
(defvar *amixer-muted* nil)
(defun amixer-mute ()
"Mute audio. Toggles volume between 0 and `amixer-master-volume'."
(interactive)
(if (null *amixer-muted*)
(progn
(setq *amixer-muted* t)
(amixer-set-volume-internal 0)
(message "Muted"))
(setq *amixer-muted* nil)
(amixer-set-volume-internal amixer-master-volume)
(message "Unmuted")))
(defun amixer-init ()
(interactive)
(amixer-set-volume-internal amixer-master-volume))
(provide 'amixer)