Sun Solaris 10 operating system comes with several tools to control
audio. For example, you can use sdtaudiocontrol to set the
volume level graphically and mixerctl to control mixer
modes. However, neither of these tools can set volume level from
command line.
Setting the volume level from command line is important for graphical user interfaces which are written in scripting languages such as Tcl/Tk, Python and Lisp. As very few scripting languages have direct access to the hardware, the graphical user interfaces usually depend on external utilities to play mp3 files and get/set audio volume.
I use Hirose Yuuji´s front-end to mpg123 which requires an external utility to set the audio volume. As Solaris 10 did not come with a suitable utility, I decided to write one myself. I hope that the utility is useful for other front-ends too.
Download mixer 1.3 installation package.
Unpack the installation packag as
gunzip -c mixer-1.3.tar.gz | tar xf - cd mixer-1.3
Compile the command line audio mixer in Sun Solaris 10 as
cc -o mixer mixer.c
If no warnings appear, copy the produced mixer file to
somewhere in your search path. For example, directory
/usr/bin will do fine.
In order to use the audio mixer in Emacs, either copy the
mpg123.el file from the installation package
to your Emacs lisp directory. If you are already using mpg123.el, then
overwrite the existing file in your hard disk.
Alternatively, if you want to use the audio mixer with the later
version of mpg123.el, then download the mpg123.el from
Hirose Yuuji´s site and apply a patch file. To apply
the patch file, copy the mpg123.el you downloaded from
Hirose Yuuji´s site and the solaris-mixer.patch file from
the installation package to the very same directory and issue command
patch -i solaris-mixer.patch mpg123.el
Copy the patched mpg123.el file to a directory where Emacs
can find it. If you are already using mpg123.el, then
overwrite the existing file in your hard disk.
In order to use the mpg123.el in Emacs, make sure that your
.emacs file contains the line
(autoload 'mpg123 "mpg123" "A Front-end to mpg123/ogg123" t)
In order to use the audio mixer in Solaris, add the following lines
to your .emacs file
(setq mpg123-mixer-type 'mixer.exe) (setq mpg123-mixer-command "mixer") (setq mpg123-mixer-setvol-target-list (list "-v"))
Restart Emacs and start mpg123.el by pressing M-x and type
mpg123. Press enter and navigate to a directory that contains
some mp3 files. Press enter to load mp3 files to Emacs and start the
playback with space. You should now be able to change the volume level
with + and - keys.
To get the current audio volume for left and right channels, invoke the mixer command without any command line parameters. The volume levels for the left and right channels will be printed to standard output in the form left:right.
To set the audio volume, invoke the mixer with a single numeric argument between 0 and 100. For example, set the master volume level to 75% as
mixer 75
Alternatively, specify the volume level for left and right audio channels as LEFT:RIGHT. For example, set left channel to 50% and right to 80% as
mixer 50:80
Nov 5, 2008: now works for SunRay clients. Thanks to Martin Rehak for the patch.