Last week I modified the mixer to support volume stepping. Having a keyboard with volume control on it, it has come in very handy to be able to use the mixer to increase/decrease the volume. I submitted the changes to send-pr and have an open ticket. For those that are interested, Im including the diff against mixer.c v1.17.
http://www.freebsd.org/cgi/query-pr.cgi?pr=46679 Sample usage: Increasing: [daren@wee mixer]$mixer -i 5:5 Increasing the mixer vol from 40:40 to 45:45. [daren@wee mixer]$ Decreasing: [daren@wee mixer]$mixer -d vol 10 Decreasing the mixer vol from 45:45 to 35:35. [daren@wee mixer]$
*** mixer_new.c Wed Jan 1 13:26:23 2003 --- mixer.c Wed Jan 1 13:32:41 2003 *************** *** 3,8 **** --- 3,9 ---- * * updated 1/1/93 to add stereo, level query, broken * devmask kludge - [EMAIL PROTECTED] + * updated 1/1/03 to add volume stepping - [EMAIL PROTECTED] * * (C) Craig Metz and Hannu Savolainen 1993. * *************** *** 13,19 **** #ifndef lint static const char rcsid[] = ! "$FreeBSD: src/usr.sbin/mixer/mixer.c,v 1.17 2002/12/30 04:23:08 jmallett Exp $"; #endif /* not lint */ #include <err.h> --- 14,20 ---- #ifndef lint static const char rcsid[] = ! "$FreeBSD: src/usr.sbin/mixer/mixer.c,v 1.11.2.6 2001/07/30 10:22:58 dd Exp $"; #endif /* not lint */ #include <err.h> *************** *** 35,41 **** { int i, n; ! printf("usage: mixer [-f device] [-s] [[dev [voll[:volr]] | recsrc | {^|+|-|=}rec recdev] ... ]\n"); printf(" devices: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & devmask) { --- 36,42 ---- { int i, n; ! printf("usage: mixer [-f device] [-s] [-i|-d] [[dev [voll[:volr]] | recsrc | {^|+|-|=}rec recdev] ... ]\n"); printf(" devices: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & devmask) { *************** *** 91,96 **** --- 92,99 ---- int devmask = 0, recmask = 0, recsrc = 0, orecsrc; int dusage = 0, drecsrc = 0, shortflag = 0; int l = 0, r = 0, t = 0; + bool volumeInc = false; + bool volumeDec = false; char ch; char *name; *************** *** 102,108 **** else if (!strcmp(argv[0], "mixer3")) name = strdup("/dev/mixer2"); ! while ((ch = getopt(argc, argv, "f:s")) != -1) switch (ch) { case 'f': name = strdup(optarg); --- 105,111 ---- else if (!strcmp(argv[0], "mixer3")) name = strdup("/dev/mixer2"); ! while ((ch = getopt(argc, argv, "f:sid")) != -1) switch (ch) { case 'f': name = strdup(optarg); *************** *** 110,115 **** --- 113,124 ---- case 's': shortflag = 1; break; + case 'i': + volumeInc = true; + break; + case 'd': + volumeDec = true; + break; default: dusage = 1; } *************** *** 181,195 **** continue; } if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) { dev = 0; } else if((dev = res_name(*argv, devmask)) == -1) { warnx("unknown device: %s", *argv); dusage = 1; break; } ! switch(argc > 1 ? sscanf(argv[1], "%d:%d", &l, &r) : t) { case 0: if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { --- 190,206 ---- continue; } + // Check if device is specified if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) { dev = 0; } + // read and verify the device else if((dev = res_name(*argv, devmask)) == -1) { warnx("unknown device: %s", *argv); dusage = 1; break; } ! // Read in the volume changes switch(argc > 1 ? sscanf(argv[1], "%d:%d", &l, &r) : t) { case 0: if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { *************** *** 208,213 **** --- 219,259 ---- case 1: r = l; case 2: + + // Read the current volum + if(ioctl(baz, MIXER_READ(dev), &bar) == -1) + { + warn("MIXER_READ"); + continue; + } + + int leftVolume = bar & 0x7f; + int rightVolume = (bar >> 8) & 0x7f; + + if(volumeInc || volumeDec) + { + // Read the current volume for stepping + if(ioctl(baz, MIXER_READ(dev), &bar) == -1) + { + warn("MIXER_READ"); + continue; + } + + int leftVolume = bar & 0x7f; + int rightVolume = (bar >> 8) & 0x7f; + + if(volumeInc) + { + l = leftVolume +l; + r = rightVolume +r; + } + else + { + l = leftVolume -l; + r = rightVolume -r; + } + } + if (l < 0) l = 0; else if (l > 100) *************** *** 217,230 **** else if (r > 100) r = 100; ! if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { ! warn("MIXER_READ"); ! argc--; argv++; ! continue; } ! ! printf("Setting the mixer %s from %d:%d to %d:%d.\n", ! names[dev], bar & 0x7f, (bar >> 8) & 0x7f, l, r); l |= r << 8; if (ioctl(baz, MIXER_WRITE(dev), &l) == -1) --- 263,278 ---- else if (r > 100) r = 100; ! if(volumeInc) ! { ! printf("Increasing the mixer %s from %d:%d to %d:%d.\n", names[dev],leftVolume, rightVolume, l,r); } ! else if(volumeDec) ! { ! printf("Decreasing the mixer %s from %d:%d to %d:%d.\n", names[dev],leftVolume, rightVolume,l, r); ! } ! else ! printf("Setting the mixer %s from %d:%d to %d:%d.\n", names[dev], leftVolume, rightVolume, l, r); l |= r << 8; if (ioctl(baz, MIXER_WRITE(dev), &l) == -1)