Date: Wed, 1 Jan 2003 21:11:08 -0500 (EST) From: desjardins@canada.com To: FreeBSD-gnats-submit@FreeBSD.org Cc: desjardins@canada.com Subject: misc/46679: added volume stepping to mixer Message-ID: <200301020211.h022B8L5052578@wee.daren.ca>
next in thread | raw e-mail | index | archive | help
>Number: 46679
>Category: misc
>Synopsis: added volume stepping to mixer
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Wed Jan 01 18:20:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Daren Desjardins
>Release: FreeBSD 4.7-STABLE i386
>Organization:
>Environment:
System: FreeBSD wee.daren.ca 4.7-STABLE FreeBSD 4.7-STABLE #3: Mon Dec 30 17:26:52 EST 2002 daren@wee.daren.ca:/usr/obj/usr/src/sys/WEE i386
Built using mixer.c 1.17 (FreeBSD-current)
>Description:
Patched to include support for volume stepping using two new command line parameters, -i for increase and -d for decrease. They simply tell the mixer to increase/decrease current levels of the device specified by the amount provided.
I have been using this to enable my volume control via Logitech keyboard.
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]$
Attached is the diff of my changes to mixer.c V1.17
>How-To-Repeat:
>Fix:
--- mixer.diff begins here ---
*** 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 ****
#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)
--- mixer.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200301020211.h022B8L5052578>
