From owner-freebsd-current Tue Jan 7 2:38:47 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 03B2E37B401 for ; Tue, 7 Jan 2003 02:38:40 -0800 (PST) Received: from smtp2.vol.cz (smtp2.vol.cz [195.250.128.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F94A43EB2 for ; Tue, 7 Jan 2003 02:38:38 -0800 (PST) (envelope-from dan@obluda.cz) Received: from obluda.cz (xkulesh.vol.cz [195.250.154.106]) by smtp2.vol.cz (8.12.6/8.12.6) with ESMTP id h07AcZc6039491 for ; Tue, 7 Jan 2003 11:38:36 +0100 (CET) (envelope-from dan@obluda.cz) Message-ID: <3E1AAE29.2050209@obluda.cz> Date: Tue, 07 Jan 2003 11:38:33 +0100 From: Dan Lukes User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3a) Gecko/20021227 X-Accept-Language: en, cs MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Re: Added volume stepping to mixer References: <1041875415.294.7.camel_weed.daren.ca@ns.sol.net> In-Reply-To: <1041875415.294.7.camel_weed.daren.ca@ns.sol.net> Content-Type: multipart/mixed; boundary="------------090607080706070007080704" 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 This is a multi-part message in MIME format. --------------090607080706070007080704 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit desjardins@canada.com wrote, On 01/06/03 18:53: > Last week I modified the mixer to support volume stepping. Having a > 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]$ Mixer can change volume for more than one device within one invocation. So, what about more generic way to implement stepping ? You may want to increase volume on one input simultaneously decreasing the volume on another input. Your can't do it in one step. Let's implement stepping according to followint example: [dan@~]$mixer vol 40:40 line1 +15:+15 line2 -10 Set volume for 'vol' to absolute value 40:40, increase line1's volume by 15 and decreasing line2's volume by 10 (both channel). It seems to be more generic way to me ... The change is backward compatible with current command line format. The patch for manual page should be reviewed by someone with better knowledge of english. The patch can be applied to stable also. Dan -- Dan Lukes tel: +420 2 21914205, fax: +420 2 21914206 root of FIONet, KolejNET, webmaster of www.freebsd.cz AKA: dan@obluda.cz, dan@freebsd.cz,dan@kolej.mff.cuni.cz --------------090607080706070007080704 Content-Type: text/plain; name="mixer.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mixer.diff" *** mixer.c.ORIG Tue Aug 7 20:15:10 2001 --- mixer.c Tue Jan 7 10:48:06 2003 *************** *** 23,41 **** #include #include #include const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; void usage(int devmask, int recmask); int res_name(const char *name, int mask); void print_recsrc(int recsrc); void usage(int devmask, int recmask) { 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) { --- 23,43 ---- #include #include #include + #include const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; void usage(int devmask, int recmask); int res_name(const char *name, int mask); void print_recsrc(int recsrc); + int get_vol(char *string, int *l, int *r, int *dl, int *dr); void usage(int devmask, int recmask) { 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) { *************** *** 84,96 **** fprintf(stderr, "\n"); } int main(int argc, char *argv[]) { 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; --- 86,158 ---- fprintf(stderr, "\n"); } + #define PLUSSIGN '+' + #define MINUSSIGN '-' + #define DELIMITER ':' + int + get_vol(char *string, int *l, int *r, int *dl, int *dr) + { + char *sptr = string; + char *endptr; + long int value; + + while(isspace(*sptr)) + sptr++; + + /* if dl==NULL revert to old (non [+|-]) syntax */ + if (dl != NULL) { + if (*sptr == PLUSSIGN) { + *dl = 1; + sptr++; + } else if (*sptr == MINUSSIGN) { + *dl = -1; + sptr++; + } else + *dl = 0; + } + /* catch strings like '+-10' '++3' or '+ 2'*/ + if (!isdigit(*sptr)) + return(0); + value=strtol(sptr, &endptr, 10); + if (*endptr != '\0' && *endptr != DELIMITER && !isspace(*endptr)) + return(0); + + *l=(int)value; + sptr=endptr; + + if (*sptr!=DELIMITER) + return(1); + + sptr++; + if (dr != NULL) { + if (*sptr == PLUSSIGN) { + *dr = 1; + sptr++; + } else if (*sptr == MINUSSIGN) { + *dr = -1; + sptr++; + } else + *dr = 0; + } + /* catch strings like '+-10' '++3' or '+ 2'*/ + if (!isdigit(*sptr)) + return(1); + value=strtol(sptr, &endptr, 10); + if (*endptr != '\0' && !isspace(*endptr)) + return(1); + + *r=(int)value; + + return(2); + } + int main(int argc, char *argv[]) { 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, dl = 0, dr = 0; char ch; char *name; *************** *** 181,187 **** continue; } ! if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) { dev = 0; } else if((dev = res_name(*argv, devmask)) == -1) { --- 243,249 ---- continue; } ! if ((t = get_vol(*argv, &l, &r, &dl, &dr)) > 0) { dev = 0; } else if((dev = res_name(*argv, devmask)) == -1) { *************** *** 190,196 **** 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"); --- 252,258 ---- break; } ! switch(argc > 1 ? get_vol(argv[1], &l, &r, &dl, &dr) : t) { case 0: if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { warn("MIXER_READ"); *************** *** 207,213 **** --- 269,290 ---- break; case 1: r = l; + dr = dl; case 2: + if ( dl != 0 || dr != 0 ) + if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { + warn("MIXER_READ"); + argc--; argv++; + continue; + } + if ( dl == 1 ) + l = (bar & 0x7f) + l; + else if ( dl == -1 ) + l = (bar & 0x7f) - l; + if ( dr == 1 ) + r = ((bar >> 8) & 0x7f) + r; + else if ( dr == -1 ) + r = ((bar >> 8) & 0x7f) - r; if (l < 0) l = 0; else if (l > 100) *** mixer.8.ORIG Tue Aug 7 20:15:10 2001 --- mixer.8 Tue Jan 7 11:20:57 2003 *************** *** 39,45 **** .Op Fl s .Oo .Oo Ar dev ! .Op Ar lvol Ns Op : Ns Ar rvol .Cm | recsrc | .Sm off .Eo \&{ --- 39,54 ---- .Op Fl s .Oo .Oo Ar dev ! .Oo ! .Sm off ! .Op Cm + | - ! .Ar lvol Ns ! .Oo : Ns ! .Op Cm + | - ! .Ar rvol ! .Sm on ! .Oc ! .Oc .Cm | recsrc | .Sm off .Eo \&{ *************** *** 78,89 **** To modify the mixer value .Ar dev , the optional left and right channel settings of ! .Ar lvol Ns Op : Ns Ar rvol may be specified. The .Ar lvol and .Ar rvol ! arguments may be from 0 - 100. Omitting .Ar dev and including only the channel settings will change the main volume level. .Pp --- 87,106 ---- To modify the mixer value .Ar dev , the optional left and right channel settings of ! .Sm off ! .Op Cm + | - ! .Ar lvol Ns ! .Oo : Ns ! .Op Cm + | - ! .Ar rvol ! .Oc ! .Sm on may be specified. The .Ar lvol and .Ar rvol ! arguments may be from 0 - 100. Without a sign it set volume to absolute ! value otherwise it increment or decrement current volume. Omitting .Ar dev and including only the channel settings will change the main volume level. .Pp --------------090607080706070007080704-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message