Skip site navigation (1)Skip section navigation (2)
Date:      06 Jan 2003 12:50:15 -0500
From:      Daren Desjardins <desjardins@canada.com>
To:        freebsd-current <freebsd-current@FreeBSD.ORG>
Subject:   Added volume stepping to mixer
Message-ID:  <1041875415.294.7.camel@weed.daren.ca>

next in thread | raw e-mail | index | archive | help

--=-9XSpG3U6V0xUqGs1ar7Y
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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]$



--=-9XSpG3U6V0xUqGs1ar7Y
Content-Disposition: attachment; filename=mixer.diff
Content-Type: text/x-patch; name=mixer.diff; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

*** 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 - cmetz@thor.tjhsst.edu
+  *	updated 1/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)  {
***************
*** 91,96 ****
--- 92,99 ----
  	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;
+ 	bool volumeInc =3D false;
+ 	bool volumeDec =3D false;
  	char ch;
 =20
  	char *name;
***************
*** 102,108 ****
  	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);
--- 105,111 ----
  	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':
  				name =3D strdup(optarg);
***************
*** 110,115 ****
--- 113,124 ----
  			case 's':
  				shortflag =3D 1;
  				break;
+ 			case 'i':
+ 				volumeInc =3D true;
+ 				break;
+ 			case 'd':
+ 				volumeDec =3D true;
+ 				break;
  			default:
  				dusage =3D 1;
  		}
***************
*** 181,195 ****
  			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) {
--- 190,206 ----
  			continue;
  		}
 =20
+ 		// Check if device is specified
  		if ((t =3D sscanf(*argv, "%d:%d", &l, &r)) > 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", &l, &r) : t) {
  		case 0:
  			if (ioctl(baz, MIXER_READ(dev),&bar)=3D=3D -1) {
***************
*** 208,213 ****
--- 219,259 ----
  		case 1:
  			r =3D l;
  		case 2:
+=20
+ 			// Read the current volum
+ 			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(volumeInc || volumeDec)
+ 			{
+ 				// Read the current volume for stepping
+ 				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(volumeInc)
+ 				{
+ 					l =3D leftVolume +l;
+ 					r =3D rightVolume +r;
+ 				}
+ 				else
+ 				{
+ 					l =3D leftVolume -l;
+ 					r =3D rightVolume -r;
+ 				}
+ 			}
+=20
  			if (l < 0)
  				l =3D 0;
  			else if (l > 100)
***************
*** 217,230 ****
  			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)
--- 263,278 ----
  			else if (r > 100)
  				r =3D 100;
 =20
! 			if(volumeInc)
! 			{
! 				printf("Increasing the mixer %s from %d:%d to %d:%d.\n", names[dev],l=
eftVolume, rightVolume, l,r);
  			}
! 			else if(volumeDec)
! 			{
! 				printf("Decreasing the mixer %s from %d:%d to %d:%d.\n", names[dev],l=
eftVolume, rightVolume,l, r);
! 			}
! 			else
! 				printf("Setting the mixer %s from %d:%d to %d:%d.\n", names[dev], lef=
tVolume, rightVolume, l, r);
 =20
  			l |=3D r << 8;
  			if (ioctl(baz, MIXER_WRITE(dev), &l) =3D=3D -1)

--=-9XSpG3U6V0xUqGs1ar7Y--

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?1041875415.294.7.camel>