Mixer volume adjustment
Const char * sound_device_names [] = SOUND_DEVICE_NAMES;
Int fd;
Int devmask, stereodevs;
Char * name;
Void usage ()
{
Int I;
Fprintf (stderr, "usage: % s \ n"
"% S \ n"
"Where is one of: \ n", name, name );
For (I = 0; I <SOUND_MIXER_NRDEVICES; I ++)
If (1 <I) & devmask)
Fprintf (stderr, "% s", sound_device_names [I]);
Fprintf (stderr, "\ n ");
Exit (1 );
}
Int main (int argc, char * argv [])
{
Int left, right, level;
Int status;
Int device;
Char * dev;
Int I;
Name = argv [0];
Fd = open ("/dev/mixer", O_RDONLY );
If (fd =-1 ){
Perror ("unable to open/dev/mixer ");
Exit (1 );
}
Status = ioctl (fd, SOUND_MIXER_READ_DEVMASK, & devmask );
If (status =-1)
Perror ("SOUND_MIXER_READ_DEVMASK ioctl failed ");
Status = ioctl (fd, SOUND_MIXER_READ_STEREODEVS, & stereodevs );
If (status =-1)
Perror ("SOUND_MIXER_READ_STEREODEVS ioctl failed ");
If (argc! = 3 & argc! = 4)
Usage ();
Dev = argv [1];
For (I = 0; I <SOUND_MIXER_NRDEVICES; I ++)
If (1 <I) & devmask )&&! Strcmp (dev, sound_device_names [I])
Break;
If (I = SOUND_MIXER_NRDEVICES ){
Fprintf (stderr, "% s is not a valid mixer device \ n", dev );
Usage ();
}
Device = I;
If (argc = 4 ){
Left = atoi (argv [2]);
Right = atoi (argv [3]);
} Else {
Left = atoi (argv [2]);
Right = atoi (argv [2]);
}
If (left! = Right )&&! (1 <I) & stereodevs )){
Fprintf (stderr, "warning: % s is not a stereo device \ n", dev );
}
Level = (right <8) + left;
Status = ioctl (fd, MIXER_WRITE (device), & level );
If (status =-1 ){
Perror ("MIXER_WRITE ioctl failed ");
Exit (1 );
}
Left = level & 0xff;
Right = (level & 0xff00)> 8;
Fprintf (stderr, "% s gain set to % d %/% d % \ n", dev, left, right );
Close (fd );
Return 0;
}