1995-02-15 17:33:04 +00:00
|
|
|
/*
|
|
|
|
* This is an example of a mixer program for Linux
|
|
|
|
*
|
|
|
|
* updated 1/1/93 to add stereo, level query, broken
|
1995-05-30 03:57:47 +00:00
|
|
|
* devmask kludge - cmetz@thor.tjhsst.edu
|
1995-02-15 17:33:04 +00:00
|
|
|
*
|
|
|
|
* (C) Craig Metz and Hannu Savolainen 1993.
|
|
|
|
*
|
|
|
|
* You may do anything you wish with this program.
|
1997-09-19 13:38:51 +00:00
|
|
|
*
|
|
|
|
* ditto for my modifications (John-Mark Gurney, 1997)
|
1995-02-15 17:33:04 +00:00
|
|
|
*/
|
|
|
|
|
1997-09-29 06:38:49 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1997-09-29 06:38:49 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
1995-02-15 17:33:04 +00:00
|
|
|
#include <fcntl.h>
|
1997-09-29 06:38:49 +00:00
|
|
|
#include <stdio.h>
|
1995-02-15 17:33:04 +00:00
|
|
|
#include <string.h>
|
1997-09-19 13:38:51 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
1995-02-15 17:33:04 +00:00
|
|
|
#include <sys/soundcard.h>
|
|
|
|
|
|
|
|
char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
|
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
void usage(int devmask, int recmask);
|
|
|
|
int res_name(const char *name, int mask);
|
|
|
|
void print_recsrc(int recsrc);
|
1995-02-15 17:33:04 +00:00
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
void
|
|
|
|
usage(int devmask, int recmask)
|
1995-02-15 17:33:04 +00:00
|
|
|
{
|
1997-09-19 13:38:51 +00:00
|
|
|
int i, n;
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2000-08-15 05:42:39 +00:00
|
|
|
printf("usage: mixer [-f device] [-s] [[dev [voll[:volr]] | recsrc | {^|+|-|=}rec recdev] ... ]\n");
|
1997-09-23 23:24:13 +00:00
|
|
|
printf(" devices: ");
|
1997-09-19 13:38:51 +00:00
|
|
|
for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
1995-02-15 17:33:04 +00:00
|
|
|
if ((1 << i) & devmask) {
|
|
|
|
if (n)
|
1997-09-19 13:38:51 +00:00
|
|
|
printf(", ");
|
2000-11-27 07:57:44 +00:00
|
|
|
printf("%s", names[i]);
|
1997-09-19 13:38:51 +00:00
|
|
|
n = 1;
|
|
|
|
}
|
1997-09-23 23:24:13 +00:00
|
|
|
printf("\n rec devices: ");
|
1997-09-19 13:38:51 +00:00
|
|
|
for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
|
|
|
if ((1 << i) & recmask) {
|
|
|
|
if (n)
|
|
|
|
printf(", ");
|
2000-11-27 07:57:44 +00:00
|
|
|
printf("%s", names[i]);
|
1995-02-15 17:33:04 +00:00
|
|
|
n = 1;
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
printf("\n");
|
1995-02-15 17:33:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
int
|
|
|
|
res_name(const char *name, int mask)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
|
|
|
|
if ((1 << foo) & mask && !strcmp(names[foo], name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
return foo == SOUND_MIXER_NRDEVICES ? -1 : foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_recsrc(int recsrc)
|
1995-02-15 17:33:04 +00:00
|
|
|
{
|
|
|
|
int i, n = 0;
|
|
|
|
fprintf(stderr, "Recording source: ");
|
|
|
|
|
|
|
|
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
|
|
|
if ((1 << i) & recsrc) {
|
|
|
|
if (n)
|
|
|
|
fprintf(stderr, ", ");
|
2000-11-27 07:57:44 +00:00
|
|
|
fprintf(stderr, "%s", names[i]);
|
1995-02-15 17:33:04 +00:00
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
int
|
1995-02-15 17:33:04 +00:00
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, bar, baz, dev;
|
1997-09-19 13:38:51 +00:00
|
|
|
int devmask = 0, recmask = 0, recsrc = 0, orecsrc;
|
2000-05-20 23:25:08 +00:00
|
|
|
int dusage = 0, drecsrc = 0, shortflag = 0;
|
2001-04-09 11:10:34 +00:00
|
|
|
int l = 0, r = 0, t = 0;
|
2000-08-15 05:42:39 +00:00
|
|
|
char ch;
|
1997-09-19 13:38:51 +00:00
|
|
|
|
|
|
|
char *name;
|
1995-02-15 17:33:04 +00:00
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
name = strdup("/dev/mixer");
|
1995-02-15 17:33:04 +00:00
|
|
|
|
|
|
|
if (!strcmp(argv[0], "mixer2"))
|
1997-09-19 13:38:51 +00:00
|
|
|
name = strdup("/dev/mixer1");
|
|
|
|
else if (!strcmp(argv[0], "mixer3"))
|
|
|
|
name = strdup("/dev/mixer2");
|
|
|
|
|
2000-08-15 05:42:39 +00:00
|
|
|
while ((ch = getopt(argc, argv, "f:s")) != -1)
|
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
name = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
shortflag = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dusage = 1;
|
|
|
|
}
|
|
|
|
argc -= (optind - 1);
|
|
|
|
argv += (optind - 1);
|
1995-02-15 17:33:04 +00:00
|
|
|
|
1997-09-29 06:38:49 +00:00
|
|
|
if ((baz = open(name, O_RDWR)) < 0)
|
|
|
|
err(1, "%s", name);
|
1997-09-19 13:38:51 +00:00
|
|
|
free(name);
|
1997-09-29 06:38:49 +00:00
|
|
|
if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
|
1997-10-01 06:34:09 +00:00
|
|
|
err(1, "SOUND_MIXER_READ_DEVMASK");
|
1997-09-29 06:38:49 +00:00
|
|
|
if (ioctl(baz, SOUND_MIXER_READ_RECMASK, &recmask) == -1)
|
1997-10-01 06:34:09 +00:00
|
|
|
err(1, "SOUND_MIXER_READ_RECMASK");
|
1997-09-29 06:38:49 +00:00
|
|
|
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
|
1997-10-01 06:34:09 +00:00
|
|
|
err(1, "SOUND_MIXER_READ_RECSRC");
|
1997-09-19 13:38:51 +00:00
|
|
|
orecsrc = recsrc;
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2000-08-15 05:42:39 +00:00
|
|
|
if ((argc == 1) && (dusage == 0)) {
|
1996-01-31 18:01:22 +00:00
|
|
|
for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++) {
|
|
|
|
if (!((1 << foo) & devmask))
|
|
|
|
continue;
|
|
|
|
if (ioctl(baz, MIXER_READ(foo),&bar)== -1) {
|
1997-09-29 06:38:49 +00:00
|
|
|
warn("MIXER_READ");
|
1996-01-31 18:01:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-05-20 23:25:08 +00:00
|
|
|
if (shortflag)
|
|
|
|
printf("%s %d:%d ", names[foo], bar & 0x7f, (bar >> 8) & 0x7f);
|
|
|
|
else
|
|
|
|
printf("Mixer %-8s is currently set to %3d:%d\n", names[foo], bar & 0x7f, (bar >> 8) & 0x7f);
|
1996-01-31 18:01:22 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
argc--; argv++;
|
|
|
|
|
2001-04-09 11:10:34 +00:00
|
|
|
while ((argc > 0) && (dusage == 0)) {
|
1997-09-19 13:38:51 +00:00
|
|
|
if (!strcmp("recsrc", *argv)) {
|
|
|
|
drecsrc = 1;
|
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
} else if (argc > 1 && !strcmp("rec", *argv + 1)) {
|
|
|
|
if (**argv != '+' && **argv != '-' &&
|
|
|
|
**argv != '=' && **argv != '^') {
|
2000-08-15 05:42:39 +00:00
|
|
|
warnx("unknown modifier: %c", **argv);
|
1997-09-19 13:38:51 +00:00
|
|
|
dusage = 1;
|
2000-08-15 05:42:39 +00:00
|
|
|
break;
|
1996-01-15 09:11:17 +00:00
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
if ((dev = res_name(argv[1], recmask)) == -1) {
|
2000-08-15 05:42:39 +00:00
|
|
|
warnx("unknown recording device: %s", argv[1]);
|
1997-09-19 13:38:51 +00:00
|
|
|
dusage = 1;
|
2000-08-15 05:42:39 +00:00
|
|
|
break;
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
1997-09-19 13:38:51 +00:00
|
|
|
switch(**argv) {
|
|
|
|
case '+':
|
1995-02-15 17:33:04 +00:00
|
|
|
recsrc |= (1 << dev);
|
1997-09-19 13:38:51 +00:00
|
|
|
break;
|
|
|
|
case '-':
|
1995-02-15 17:33:04 +00:00
|
|
|
recsrc &= ~(1 << dev);
|
1997-09-19 13:38:51 +00:00
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
recsrc = (1 << dev);
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
recsrc ^= (1 << dev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
drecsrc = 1;
|
|
|
|
argc -= 2; argv += 2;
|
|
|
|
continue;
|
|
|
|
}
|
1995-02-15 17:33:04 +00:00
|
|
|
|
2001-04-09 11:10:34 +00:00
|
|
|
if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) {
|
|
|
|
dev = 0;
|
|
|
|
}
|
|
|
|
else if((dev = res_name(*argv, devmask)) == -1) {
|
2000-08-15 05:42:39 +00:00
|
|
|
warnx("unknown device: %s", *argv);
|
1997-09-19 13:38:51 +00:00
|
|
|
dusage = 1;
|
2000-08-15 05:42:39 +00:00
|
|
|
break;
|
1997-09-19 13:38:51 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 11:10:34 +00:00
|
|
|
switch(argc > 1 ? sscanf(argv[1], "%d:%d", &l, &r) : t) {
|
1997-09-19 13:38:51 +00:00
|
|
|
case 0:
|
|
|
|
if (ioctl(baz, MIXER_READ(dev),&bar)== -1) {
|
1997-09-29 06:38:49 +00:00
|
|
|
warn("MIXER_READ");
|
1997-09-19 13:38:51 +00:00
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
2000-05-20 23:25:08 +00:00
|
|
|
if (shortflag)
|
|
|
|
printf("%s %d:%d ", names[dev], bar & 0x7f, (bar >> 8) & 0x7f);
|
|
|
|
else
|
|
|
|
printf("Mixer %-8s is currently set to %3d:%d\n",
|
|
|
|
names[dev], bar & 0x7f, (bar >> 8) & 0x7f);
|
1997-09-19 13:38:51 +00:00
|
|
|
|
|
|
|
argc--; argv++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
r = l;
|
|
|
|
case 2:
|
|
|
|
if (l < 0)
|
|
|
|
l = 0;
|
|
|
|
else if (l > 100)
|
|
|
|
l = 100;
|
|
|
|
if (r < 0)
|
|
|
|
r = 0;
|
|
|
|
else if (r > 100)
|
|
|
|
r = 100;
|
|
|
|
|
|
|
|
printf("Setting the mixer %s to %d:%d.\n", names[dev],
|
|
|
|
l, r);
|
|
|
|
|
|
|
|
l |= r << 8;
|
|
|
|
if (ioctl(baz, MIXER_WRITE(dev), &l) == -1)
|
1997-09-29 06:38:49 +00:00
|
|
|
warn("WRITE_MIXER");
|
1997-09-19 13:38:51 +00:00
|
|
|
|
|
|
|
argc -= 2; argv += 2;
|
|
|
|
break;
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 05:42:39 +00:00
|
|
|
if (dusage) {
|
|
|
|
close(baz);
|
|
|
|
usage(devmask, recmask);
|
|
|
|
/* Not reached */
|
|
|
|
}
|
|
|
|
|
1997-09-19 13:38:51 +00:00
|
|
|
if (orecsrc != recsrc)
|
1997-09-29 06:38:49 +00:00
|
|
|
if (ioctl(baz, SOUND_MIXER_WRITE_RECSRC, &recsrc) == -1)
|
1997-10-01 06:34:09 +00:00
|
|
|
err(1, "SOUND_MIXER_WRITE_RECSRC");
|
1997-09-19 13:38:51 +00:00
|
|
|
|
|
|
|
if (drecsrc) {
|
1997-09-29 06:38:49 +00:00
|
|
|
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
|
1997-10-01 06:34:09 +00:00
|
|
|
err(1, "SOUND_MIXER_READ_RECSRC");
|
1997-09-19 13:38:51 +00:00
|
|
|
print_recsrc(recsrc);
|
|
|
|
}
|
|
|
|
|
1995-02-15 17:33:04 +00:00
|
|
|
close(baz);
|
1997-09-19 13:38:51 +00:00
|
|
|
|
|
|
|
exit(0);
|
1995-02-15 17:33:04 +00:00
|
|
|
}
|