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>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-1oiRiK5Ulv03ZW9DRmGD
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
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.
--=-1oiRiK5Ulv03ZW9DRmGD
Content-Disposition: attachment; filename=mixer.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=mixer.diff; charset=ISO-8859-1
*** 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 ****
=20
#ifndef lint
static const char rcsid[] =3D
! "$FreeBSD: src/usr.sbin/mixer/mixer.c,v 1.17 2002/12/30 04:23:08 jmalle=
tt Exp $";
#endif /* not lint */
=20
#include <err.h>
--- 14,20 ----
=20
#ifndef lint
static const char rcsid[] =3D
! "$FreeBSD: src/usr.sbin/mixer/mixer.c,v 1.11.2.6 2001/07/30 10:22:58 dd=
Exp $";
#endif /* not lint */
=20
#include <err.h>
***************
*** 35,41 ****
{
int i, n;
=20
! printf("usage: mixer [-f device] [-s] [[dev [voll[:volr]] | recsrc | {^|=
+|-|=3D}rec recdev] ... ]\n");
printf(" devices: ");
for (i =3D 0, n =3D 0; i < SOUND_MIXER_NRDEVICES; i++)
if ((1 << i) & devmask) {
--- 36,42 ----
{
int i, n;
=20
! printf("usage: mixer [-f device] [-s] [-i|-d] [[dev [voll[:volr]] | recs=
rc | {^|+|-|=3D}rec recdev] ... ]\n");
printf(" devices: ");
for (i =3D 0, n =3D 0; i < SOUND_MIXER_NRDEVICES; i++)
if ((1 << i) & devmask) {
***************
*** 90,96 ****
int foo, bar, baz, dev;
int devmask =3D 0, recmask =3D 0, recsrc =3D 0, orecsrc;
int dusage =3D 0, drecsrc =3D 0, shortflag =3D 0;
! int l =3D 0, r =3D 0, t =3D 0;
char ch;
=20
char *name;
--- 91,98 ----
int foo, bar, baz, dev;
int devmask =3D 0, recmask =3D 0, recsrc =3D 0, orecsrc;
int dusage =3D 0, drecsrc =3D 0, shortflag =3D 0;
! int left =3D 0, right =3D 0, temp =3D 0;
! int direction =3D 0; // volume stepping indicator
char ch;
=20
char *name;
***************
*** 102,115 ****
else if (!strcmp(argv[0], "mixer3"))
name =3D strdup("/dev/mixer2");
=20
! while ((ch =3D getopt(argc, argv, "f:s")) !=3D -1)
switch (ch) {
case 'f':
name =3D strdup(optarg);
break;
case 's':
shortflag =3D 1;
break;
default:
dusage =3D 1;
}
--- 104,126 ----
else if (!strcmp(argv[0], "mixer3"))
name =3D strdup("/dev/mixer2");
=20
! while ((ch =3D getopt(argc, argv, "f:sid")) !=3D -1)
switch (ch) {
case 'f':
+ // user specifed device
name =3D strdup(optarg);
break;
case 's':
+ // display levels in short form
shortflag =3D 1;
break;
+ case 'i':
+ // increase volume flag present
+ direction =3D 1;
+ break;
+ case 'd':
+ direction =3D -1;
+ break;
default:
dusage =3D 1;
}
***************
*** 181,196 ****
continue;
}
=20
! if ((t =3D sscanf(*argv, "%d:%d", &l, &r)) > 0) {
dev =3D 0;
}
else if((dev =3D res_name(*argv, devmask)) =3D=3D -1) {
warnx("unknown device: %s", *argv);
dusage =3D 1;
break;
}
!=20
! switch(argc > 1 ? sscanf(argv[1], "%d:%d", &l, &r) : t) {
case 0:
if (ioctl(baz, MIXER_READ(dev),&bar)=3D=3D -1) {
warn("MIXER_READ");
--- 192,209 ----
continue;
}
=20
! // Check if device is specified
! if ((temp =3D sscanf(*argv, "%d:%d", &left, &right)) > 0) {
dev =3D 0;
}
+ // read and verify the device
else if((dev =3D res_name(*argv, devmask)) =3D=3D -1) {
warnx("unknown device: %s", *argv);
dusage =3D 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)=3D=3D -1) {
warn("MIXER_READ");
***************
*** 206,233 ****
argc--; argv++;
break;
case 1:
! r =3D l;
case 2:
- if (l < 0)
- l =3D 0;
- else if (l > 100)
- l =3D 100;
- if (r < 0)
- r =3D 0;
- else if (r > 100)
- r =3D 100;
=20
! if (ioctl(baz, MIXER_READ(dev),&bar)=3D=3D -1) {
warn("MIXER_READ");
- argc--; argv++;
continue;
}
=20
! printf("Setting the mixer %s from %d:%d to %d:%d.\n",
! names[dev], bar & 0x7f, (bar >> 8) & 0x7f, l, r);
=20
! l |=3D r << 8;
! if (ioctl(baz, MIXER_WRITE(dev), &l) =3D=3D -1)
warn("WRITE_MIXER");
=20
argc -=3D 2; argv +=3D 2;
--- 219,270 ----
argc--; argv++;
break;
case 1:
! // user did not specify left:right levels,
! right =3D left;
case 2:
=20
! // Read the current volume
! if(ioctl(baz, MIXER_READ(dev), &bar) =3D=3D -1)
! {
warn("MIXER_READ");
continue;
}
=20
! int leftVolume =3D bar & 0x7f;
! int rightVolume =3D (bar >> 8) & 0x7f;
!=20
! if(0 !=3D direction)
! {
! // Perform volume stepping
! left =3D leftVolume + (direction * left);
! right =3D rightVolume + (direction * right);
! }
!=20
! // Check to see if new volumes are outside boundary
! if (left < 0)
! left =3D 0;
! else if (left > 100)
! left =3D 100;
! if (right < 0)
! right =3D 0;
! else if (right > 100)
! right =3D 100;
!=20
! temp=3D left|right << 8;
!=20
! if(temp>bar)
! {
! printf("Increasing the mixer %s from %d:%d to %d:%d.\n", names[dev],l=
eftVolume, rightVolume, left,right);
! }
! else if(temp<bar)
! {
! printf("Decreasing the mixer %s from %d:%d to %d:%d.\n", names[dev],l=
eftVolume, rightVolume,left, right);
! }
! else
! printf("No change in mixer %s at %d:%d.\n", names[dev], leftVolume, r=
ightVolume);
=20
! // Set the new volume
! if (ioctl(baz, MIXER_WRITE(dev), &temp) =3D=3D -1)
warn("WRITE_MIXER");
=20
argc -=3D 2; argv +=3D 2;
--=-1oiRiK5Ulv03ZW9DRmGD--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1041881752.294.13.camel>
