ref: 3e58068cc5f07ae3306630aaa1448fa87643c170
parent: f05b00e7be50dfbcf698a0d9c3b1f2fdbea98adc
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Aug 20 13:05:20 EDT 2022
aux/wm8960: relative volume adjustment through the fs interface
--- a/sys/man/8/wm8960
+++ b/sys/man/8/wm8960
@@ -17,6 +17,11 @@
.B -s
.I service
]
+.nf
+.sp 0.3v
+.B /mnt/wm8960/audioctl
+.B /mnt/wm8960/volume
+.fi
.SH DESCRIPTION
.I Aux/imx8pm
presents at
@@ -28,7 +33,7 @@
.I service
is specified, the interface will be posted at
.BI /srv/ service
-as well. In order to only initialize the DAC and immediately exit without
+as well. In order to initialize the DAC and immediately exit, without
running a file system, option
.I -1
can be used.
@@ -57,7 +62,11 @@
.BR reset .
.TP
.B volume
-Provides an interface for volume control (see \fIaudio\fR(3)). Only
+Provides an interface for volume control (see \fIaudio\fR(3)). For ease of use,
+.B volume
+supports relative adjustments by prefixing a number with a sign.
+.IP
+Only
44100Hz (default) and 48000Hz sample rates are supported.
.IP
Enhanced stereo separation can be enabled by writing
--- a/sys/src/cmd/aux/wm8960.c
+++ b/sys/src/cmd/aux/wm8960.c
@@ -240,6 +240,18 @@
respond(r, nil);
}
+static int
+setoradd(int x, char *s)
+{
+ int d;
+
+ d = atoi(s);
+ if(*s == '+' || *s == '-')
+ return x + d;
+
+ return d;
+}
+
static void
fswrite(Req *r)
{
@@ -287,8 +299,8 @@
goto Emsg;
toggle(o, on);
}else if(r->fid->file->aux == (void*)Vol){
- vl = atoi(f[1]);
- vr = nf < 3 ? vl : atoi(f[2]);
+ vl = setoradd(o->vol[0], f[1]);
+ vr = setoradd(o->vol[1], nf < 3 ? f[1] : f[2]);
setvol(o, vl, vr);
}