mixerctl

by Rob Mayoff
My primary computer is an IBM Thinkpad 770Z running Linux. If I put the system to sleep and then wake it up, the sound stops working until I unload and reload the sound drivers. This resets the mixer settings. I needed a way to save and restore the mixer settings.

Note that adjusting the mixer settings interactively is not a problem - there are many programs that let me do that already. I normally use kmix, part of KDE to do that.

I looked at a few programs out there that had command line interfaces but didn't really find anything I liked. They all either had curses or graphical user interfaces, or else they weren't trivial to use for my purpose. So I wrote mixerctl to do exactly what I want.

Code

The source code. This program does not use stdio; I wanted it to use nigh-zero memory and run nigh-instantaneously. (The stripped executable on my system is 3880 bytes.) So if something goes wrong, all you get is a non-zero exit code. Run it under strace to see what is wrong.

I compile it like this:

cc -s -o mixerctl mixerctl.c

Reference

mixerctl r /dev/mixer >statefile
Reads the volumes of every channel of /dev/mixer and writes them to statefile.

mixerctl w /dev/mixer <statefile
Reads statefile and sets the volumes of every channel of /dev/mixer.

Usage

I call mixerctl from /etc/modules.conf whenever I load or unload the sound drivers. I have my apmd script call modprobe -r audio on a suspend and modprobe audio on a resume. Here are my audio settings in /etc/modules.conf:
alias audio cs4232 options sound dmabuf=1 options cs4232 io=0x530 irq=5 dma=1 dma2=0 mpuio=0x330 mpuirq=9 pre-remove cs4232 /usr/local/bin/mixerctl r /dev/mixer >/var/state/mixer post-install cs4232 /usr/local/bin/mixerctl w /dev/mixer </var/state/mixer

mayoff@dqd.com
$Id: index.html,v 1.2 2001/03/15 08:38:20 mayoff Exp $