Mixer volume adjustment

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.