#include <sys/audio.h>
#include <fcntl.h>
#include <stdio.h>
#define DD "/dev/audioctl"
int main(int argc, char **argv)
{
int fd;
audio_info_t info;
     extern char *optarg;
     extern int	optind,	opterr,	optopt;
int c;
char *device=0;
int pgain = -1;
int port=-1;
while ((c = getopt(argc, argv, "d:p:P:")) != -1) {
switch(c) {
case 'd':
device=optarg;
break;
case 'p': //playback gain
pgain = atoi(optarg);
break;
case 'P': // port
port = atoi(optarg);
break;
case '?':
exit(1);
break;
} //switch
} //while
if (device == 0) {
device = malloc(strlen(DD)+1);
if (!device) {
perror("malloc");
exit(1);
}
strcpy(device, DD);
}
if ((fd = open(device, O_RDWR, 0)) == -1) {
perror("open");
exit(1);
}
if (ioctl(fd, AUDIO_GETINFO, &info) == -1) {
perror("ioctl");
close(fd);
exit(1);
}
printf("current playback gain is %d\n", info.play.gain);
printf("port %d\n", info.play.port);
if (pgain >= 0) {
printf("setting playback gain to %d\n", pgain);
info.play.gain = pgain;
}
if (port >= 0) {
printf("setting port to %d\n", port);
info.play.port = port;
}
if (port != -1 || pgain != -1) {
if (ioctl(fd, AUDIO_SETINFO, &info) == -1) {
perror("ioctl");
close(fd);
exit(1);
} //ioctl
} // anything set?
close(fd);
return 0;
}
