ref: c1cb685a327b180cce47a453b221e050ebff4f9e
parent: 866ee3ab5d0818194cca8c04d1f3ec2ff1d148c9
author: cinap_lenrek <[email protected]>
date: Sun Jan 27 12:20:42 EST 2013
audioac97: fix inverted recgain control, init to zero recgain some controls are inverted. we reflect this by specifying negative range in the volume table now and let genaudiovolread() and genaudiovolwrite() do the conversion.
--- a/sys/src/9/pc/audioac97mix.c
+++ b/sys/src/9/pc/audioac97mix.c
@@ -114,18 +114,18 @@
};
static Volume voltab[] = {
- [Vmaster] "master", 0x02, 63, Stereo, 0,
- [Vaudio] "audio", 0x18, 31, Stereo, 0,
- [Vhead] "head", 0x04, 31, Stereo, Capheadphones,
+ [Vmaster] "master", 0x02, -63, Stereo, 0,
+ [Vaudio] "audio", 0x18, -31, Stereo, 0,
+ [Vhead] "head", 0x04, -31, Stereo, Capheadphones,
[Vbass] "bass", 0x08, 15, Left, Captonectl,
[Vtreb] "treb", 0x08, 15, Right, Captonectl,
- [Vbeep] "beep", 0x0a, 31, Right, 0,
- [Vphone] "phone", 0x0c, 31, Right, 0,
- [Vmic] "mic", 0x0e, 31, Right, Capmic,
- [Vline] "line", 0x10, 31, Stereo, 0,
- [Vcd] "cd", 0x12, 31, Stereo, 0,
- [Vvideo] "video", 0x14, 31, Stereo, 0,
- [Vaux] "aux", 0x16, 63, Stereo, 0,
+ [Vbeep] "beep", 0x0a, -31, Right, 0,
+ [Vphone] "phone", 0x0c, -31, Right, 0,
+ [Vmic] "mic", 0x0e, -31, Right, Capmic,
+ [Vline] "line", 0x10, -31, Stereo, 0,
+ [Vcd] "cd", 0x12, -31, Stereo, 0,
+ [Vvideo] "video", 0x14, -31, Stereo, 0,
+ [Vaux] "aux", 0x16, -63, Stereo, 0,
[Vrecgain] "recgain", 0x1c, 15, Stereo, 0,
[Vmicgain] "micgain", 0x1e, 15, Right, Capmic,
[Vspeed] "speed", 0x2c, 0, Absolute, 0,
@@ -160,11 +160,10 @@
default:
v = m->rr(adev, vol->reg);
if(v & 0x8000){
- a[0] = 0;
- a[1] = 0;
+ a[0] = a[1] = vol->range < 0 ? 0x7f : 0;
} else {
- a[0] = vol->range - ((v>>8) & 0x7f);
- a[1] = vol->range - (v & 0x7f);
+ a[0] = ((v>>8) & 0x7f);
+ a[1] = (v & 0x7f);
}
}
return 0;
@@ -191,18 +190,18 @@
}
break;
case Left:
- v = (vol->range - a[0]) & 0x7f;
+ v = a[0] & 0x7f;
w = m->rr(adev, vol->reg) & 0x7f;
m->wr(adev, vol->reg, (v<<8)|w);
break;
case Right:
v = m->rr(adev, vol->reg) & 0x7f00;
- w = (vol->range - a[1]) & 0x7f;
+ w = a[1] & 0x7f;
m->wr(adev, vol->reg, v|w);
break;
case Stereo:
- v = (vol->range - a[0]) & 0x7f;
- w = (vol->range - a[1]) & 0x7f;
+ v = a[0] & 0x7f;
+ w = a[1] & 0x7f;
m->wr(adev, vol->reg, (v<<8)|w);
break;
}
--- a/sys/src/9/pc/audiohda.c
+++ b/sys/src/9/pc/audiohda.c
@@ -1321,7 +1321,7 @@
static Volume voltab[] = {
[Vmaster] "master", 0, 0x7f, Stereo, 0,
- [Vrecord] "record", 0, 0x7f, Stereo, 0,
+ [Vrecord] "recgain", 0, 0x7f, Stereo, 0,
[Vspeed] "speed", 0, 0, Absolute, 0,
[Vdelay] "delay", 0, 0, Absolute, 0,
0
--- a/sys/src/9/port/devaudio.c
+++ b/sys/src/9/port/devaudio.c
@@ -150,6 +150,7 @@
"master 100",
"audio 100",
"head 100",
+ "recgain 0",
};
attached |= i;
@@ -367,7 +368,7 @@
genaudiovolread(Audio *adev, void *a, long n, vlong,
Volume *vol, int (*volget)(Audio *, int, int *), ulong caps)
{
- int i, j, v[2];
+ int i, j, r, v[2];
char *p, *e;
p = a;
@@ -382,14 +383,17 @@
if(vol[i].type == Absolute)
p += snprint(p, e - p, "%s %d\n", vol[i].name, v[0]);
else {
- if(vol[i].range == 0)
+ r = abs(vol[i].range);
+ if(r == 0)
continue;
for(j=0; j<2; j++){
if(v[j] < 0)
v[j] = 0;
- if(v[j] > vol[i].range)
- v[j] = vol[i].range;
- v[j] = (v[j]*100)/vol[i].range;
+ if(v[j] > r)
+ v[j] = r;
+ if(vol[i].range < 0)
+ v[j] = r - v[j];
+ v[j] = (v[j]*100)/r;
}
switch(vol[i].type){
case Left:
@@ -418,7 +422,7 @@
genaudiovolwrite(Audio *adev, void *a, long n, vlong,
Volume *vol, int (*volset)(Audio *, int, int *), ulong caps)
{
- int ntok, i, j, v[2];
+ int ntok, i, j, r, v[2];
char *p, *e, *x, *tok[4];
p = a;
@@ -455,12 +459,15 @@
if(vol[i].type == Absolute)
(*volset)(adev, i, v);
else {
+ r = abs(vol[i].range);
for(j=0; j<2; j++){
- v[j] = (50+(v[j]*vol[i].range))/100;
+ v[j] = (50+(v[j]*r))/100;
if(v[j] < 0)
v[j] = 0;
- if(v[j] > vol[i].range)
- v[j] = vol[i].range;
+ if(v[j] > r)
+ v[j] = r;
+ if(vol[i].range < 0)
+ v[j] = r - v[j];
}
(*volset)(adev, i, v);
}