Date: 06 Jan 2003 14:35:52 -0500 From: Daren Desjardins <desjardins@canada.com> To: Juli Mallett <jmallett@FreeBSD.ORG> Cc: freebsd-current <freebsd-current@FreeBSD.ORG> Subject: Re: Added volume stepping to mixer Message-ID: <1041881752.294.13.camel@weed.daren.ca> In-Reply-To: <20030106105945.A3364@FreeBSD.org> References: <1041875415.294.7.camel@weed.daren.ca> <20030106105945.A3364@FreeBSD.org>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
Changes made, also added a couple lines of docs here and their and
changed the int variables to more meaningful. Lemme know if their is
anything else you need.
Daren Desjardins
On Mon, 2003-01-06 at 13:59, Juli Mallett wrote:
> * De: Daren Desjardins <desjardins@canada.com> [ Data: 2003-01-06 ]
> [ Subjecte: Added volume stepping to mixer ]
> > 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.
>
> OK, I have some critiques, which if you do them (they were in my TODO
> anyway) I'll be glad to commit:
> Instead of two bool's use one 'int', if it is 0, then act as
> we do now. If it is -1, we're decreasing, if it is +1, we're
> increasing. Thus you do something like:
>
> if (direction != 0)
> newvol = oldvol + (newvol * amount);
> /* Set newval */
>
> Also, don't do what you do with printf. What should be done, just before
> setting newval (I've already done this locally, but you should as part
> of what you're doing anyway) is more like this:
>
> if (newval < oldval)
> printf("Decreasing level to blah blah");
> else if (newval > oldval)
> printf("Increasing level to blah blah");
> else {
> printf("No change in level at blah");
> /* Get on with our lives */
> }
> /* Set newval */
>
> Let me know.
>
> Thanx,
> juli.
[-- Attachment #2 --]
*** mixer_new.c Thu Jan 2 14:58:34 2003
--- mixer.c Mon Jan 6 14:31:58 2003
***************
*** 3,8 ****
--- 3,9 ----
*
* updated 1/1/93 to add stereo, level query, broken
* devmask kludge - cmetz@thor.tjhsst.edu
+ * updated 6/1/03 to add volume stepping - desjardins@canada.com
*
* (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) {
***************
*** 90,96 ****
int foo, bar, baz, dev;
int devmask = 0, recmask = 0, recsrc = 0, orecsrc;
int dusage = 0, drecsrc = 0, shortflag = 0;
! int l = 0, r = 0, t = 0;
char ch;
char *name;
--- 91,98 ----
int foo, bar, baz, dev;
int devmask = 0, recmask = 0, recsrc = 0, orecsrc;
int dusage = 0, drecsrc = 0, shortflag = 0;
! int left = 0, right = 0, temp = 0;
! int direction = 0; // volume stepping indicator
char ch;
char *name;
***************
*** 102,115 ****
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);
break;
case 's':
shortflag = 1;
break;
default:
dusage = 1;
}
--- 104,126 ----
else if (!strcmp(argv[0], "mixer3"))
name = strdup("/dev/mixer2");
! while ((ch = getopt(argc, argv, "f:sid")) != -1)
switch (ch) {
case 'f':
+ // user specifed device
name = strdup(optarg);
break;
case 's':
+ // display levels in short form
shortflag = 1;
break;
+ case 'i':
+ // increase volume flag present
+ direction = 1;
+ break;
+ case 'd':
+ direction = -1;
+ break;
default:
dusage = 1;
}
***************
*** 181,196 ****
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) {
warn("MIXER_READ");
--- 192,209 ----
continue;
}
! // Check if device is specified
! if ((temp = sscanf(*argv, "%d:%d", &left, &right)) > 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", &left, &right) : temp) {
case 0:
if (ioctl(baz, MIXER_READ(dev),&bar)== -1) {
warn("MIXER_READ");
***************
*** 206,233 ****
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;
! 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)
warn("WRITE_MIXER");
argc -= 2; argv += 2;
--- 219,270 ----
argc--; argv++;
break;
case 1:
! // user did not specify left:right levels,
! right = left;
case 2:
! // Read the current volume
! if(ioctl(baz, MIXER_READ(dev), &bar) == -1)
! {
warn("MIXER_READ");
continue;
}
! int leftVolume = bar & 0x7f;
! int rightVolume = (bar >> 8) & 0x7f;
!
! if(0 != direction)
! {
! // Perform volume stepping
! left = leftVolume + (direction * left);
! right = rightVolume + (direction * right);
! }
!
! // Check to see if new volumes are outside boundary
! if (left < 0)
! left = 0;
! else if (left > 100)
! left = 100;
! if (right < 0)
! right = 0;
! else if (right > 100)
! right = 100;
!
! temp= left|right << 8;
!
! if(temp>bar)
! {
! printf("Increasing the mixer %s from %d:%d to %d:%d.\n", names[dev],leftVolume, rightVolume, left,right);
! }
! else if(temp<bar)
! {
! printf("Decreasing the mixer %s from %d:%d to %d:%d.\n", names[dev],leftVolume, rightVolume,left, right);
! }
! else
! printf("No change in mixer %s at %d:%d.\n", names[dev], leftVolume, rightVolume);
! // Set the new volume
! if (ioctl(baz, MIXER_WRITE(dev), &temp) == -1)
warn("WRITE_MIXER");
argc -= 2; argv += 2;
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1041881752.294.13.camel>
