[nas] scripting volume changes, other misc.

Paul Fox pgf at foxharp.boston.ma.us
Thu Jan 25 06:56:51 MST 2001


since there didn't seem to be any good way of making relative volume
adjustments (without the audiooss shim), i decided to create a way.

here's a patch (for directory clients/audio/auctl) that augments auctl
with  "set device N gain + P" and "set device N gain - P".

it seems to work just fine, and solved my problem nicely.

paul
=---------------------
  paul fox, pgf at foxharp.boston.ma.us (arlington, ma, where it's 27.7 degrees)


--- execute.c.orig	Thu Jan 25 08:26:56 2001
+++ execute.c	Thu Jan 25 08:42:38 2001
@@ -332,7 +332,7 @@
 "The following commands are supported:",
 "",
 "    help                             print this message",
-"    set device ID gain = PERCENT     set the gain on a device",
+"    set device ID gain =/+/- PERCENT set the gain on a device",
 "    set device ID linemode = low     set the device line mode",
 "    set device ID linemode = high    set the device line mode",
 "    list device ID gain              list the gain of a device",
@@ -375,13 +375,24 @@
     int p;
     AuDeviceAttributes attr;
     AuStatus status;
+    int delta = 0;
 
     /*
-     *     ["="] PERCENTAGE
+     *     ["=","+","-" ] PERCENTAGE
      */
     switch (argc) {
       case 2:
-	if (argv[0][0] != '=') {
+	switch (argv[0][0]) {
+	  case '=':
+	    delta = 0;
+	    break;
+	  case '+':
+	    delta = +1;
+	    break;
+	  case '-':
+	    delta = -1;
+	    break;
+	  default:
 	  usage:
 	    fprintf (stderr, "%s: invalid gain syntax\n", ProgramName);
 	    return 1;
@@ -390,10 +401,41 @@
 	/* fall through */
       case 1:
 	p = atoi (argv[0]);
+	if (delta) {
+	    delta *= p;
+	    if (!delta)  /* no change (i.e. +/- 0), so we're done */
+		return 0;
+	}
 	break;
 
       default:
 	goto usage;
+    }
+
+    if (delta) {
+
+	AuDeviceAttributes *d = AuGetDeviceAttributes (aud, id, &status);
+
+	if (!d) {
+	    fprintf (stderr, "%s: unable to get device 0x%lx gain\n",
+		     ProgramName, id);
+	    return 1;
+	}
+	if (!(AuDeviceValueMask(d) & AuCompDeviceGainMask)) {
+	    fprintf (stderr, "%s: device 0x%lx does not provide current gain\n",
+		     ProgramName, id);
+	    return 1;
+	} else {
+	    p = AuFixedPointRoundDown(AuDeviceGain(d));
+	}
+
+	AuFreeDeviceAttributes (aud, 1, d);
+
+	p += delta;
+	if (p < 0)
+	    p = 0;
+	else if (p > 100)
+	    p = 100;
     }
 
     /* okay, we can now set the gain for the specified device */
--- auctl.man.orig	Thu Jan 25 08:37:47 2001
+++ auctl.man	Thu Jan 25 08:44:54 2001
@@ -27,9 +27,11 @@
 .B "help"
 This command prints a list of the commands that may be given.
 .TP 8
-.B "set device \fIid\fP gain = \fIpercent\fP"
-This command sets the gain on the device specified by \fIid\fP to the indicated
-percentage.  If the \fIid\fP is a decimal number \fBn\fP, the \fInth\fP 
+.B "set device \fIid\fP gain [=,+,-] \fIpercent\fP"
+With \fI=\fP, this command sets the gain on the device specified by
+\fIid\fP to the indicated percentage, or alters it by the given number
+of percentage points if \fI+\fP or \fI-\fP is used.
+If the \fIid\fP is a decimal number \fBn\fP, the \fInth\fP 
 device returned by the server (see \fIauinfo\fP) is used.  Otherwise, \fIid\fP
 should be a hexidecimal number specifying the resource identifier of the
 desired device.



More information about the Nas mailing list