From owner-freebsd-current Mon Jan 6 9:50:31 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 38B7937B401 for ; Mon, 6 Jan 2003 09:50:25 -0800 (PST) Received: from weed.daren.ca (CPE014320028330.cpe.net.cable.rogers.com [24.102.94.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id AA10E43EB2 for ; Mon, 6 Jan 2003 09:50:18 -0800 (PST) (envelope-from desjardins@canada.com) Received: from weed.daren.ca (localhost [127.0.0.1]) by weed.daren.ca (8.12.6/8.12.6) with ESMTP id h06HoG8k000436 for ; Mon, 6 Jan 2003 12:50:16 -0500 (EST) (envelope-from desjardins@canada.com) Received: (from daren@localhost) by weed.daren.ca (8.12.6/8.12.6/Submit) id h06HoGkb000435 for freebsd-current@FreeBSD.ORG; Mon, 6 Jan 2003 12:50:16 -0500 (EST) X-Authentication-Warning: weed.daren.ca: daren set sender to desjardins@canada.com using -f Subject: Added volume stepping to mixer From: Daren Desjardins Reply-To: desjardins@canada.com To: freebsd-current Content-Type: multipart/mixed; boundary="=-9XSpG3U6V0xUqGs1ar7Y" Organization: Message-Id: <1041875415.294.7.camel@weed.daren.ca> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.0 Date: 06 Jan 2003 12:50:15 -0500 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --=-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 --- 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 *************** *** 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