ref: b274842f5cc186ea254fe61f5866fbc4c494b8c7
parent: 86f316987d68dbd92dac0606b8010e9a937f61ce
author: cinap_lenrek <cinap_lenrek@localhost>
date: Sun Jul 3 01:56:53 EDT 2011
audio: cleanup
--- a/sys/src/9/pc/audioac97.c
+++ b/sys/src/9/pc/audioac97.c
@@ -269,15 +269,16 @@
static long
ac97buffered(Audio *adev)
{
- Ctlr *ctlr;
- ctlr = adev->ctlr;
+ Ctlr *ctlr = adev->ctlr;
return buffered(&ctlr->outring);
}
-static void
-ac97kick(Ctlr *ctlr, long reg)
+static long
+ac97status(Audio *adev, void *a, long n, vlong)
{
- csr8w(ctlr, reg+Cr, Ioce | Rpbm);
+ Ctlr *ctlr = adev->ctlr;
+ return snprint((char*)a, n, "bufsize %6d buffered %6ld\n",
+ Blocksize, buffered(&ctlr->outring));
}
static int
@@ -316,7 +317,7 @@
ni = ring->wi / Blocksize;
while(oi != ni){
csr8w(ctlr, Out+Lvi, oi);
- ac97kick(ctlr, Out);
+ csr8w(ctlr, Out+Cr, Ioce | Rpbm);
oi = (oi + 1) % Ndesc;
}
p += n;
@@ -499,6 +500,7 @@
adev->write = ac97write;
adev->buffered = ac97buffered;
+ adev->status = ac97status;
intrenable(irq, ac97interrupt, adev, tbdf, adev->name);
--- a/sys/src/9/pc/audiohda.c
+++ b/sys/src/9/pc/audiohda.c
@@ -1213,9 +1213,9 @@
char *s;
s = a;
- k = snprint(s, n,
- "bufsize %6d buffered %6ud codec %2d pin %3d\n",
- Bufsize, ringused(&ctlr->ring), ctlr->codec.id.codec, ctlr->pin);
+ k = snprint(s, n, "bufsize %6d buffered %6ud\ncodec %2d pin %3d\n",
+ ctlr->ring.blocksize, ringused(&ctlr->ring),
+ ctlr->codec.id.codec, ctlr->pin);
for(fg=ctlr->codec.fgroup; fg; fg=fg->next){
for(w=fg->first; w; w=w->next){
--- a/sys/src/9/pc/audiosb16.c
+++ b/sys/src/9/pc/audiosb16.c
@@ -68,8 +68,6 @@
int active; /* boolean dma running */
int major; /* SB16 major version number (sb 4) */
int minor; /* SB16 minor version number */
- ulong totcount; /* how many bytes processed since open */
- vlong tottime; /* time at which totcount bytes were processed */
Ring ring; /* dma ring buffer */
Blaster blaster;
@@ -288,12 +286,9 @@
blaster = &ctlr->blaster;
ring = &ctlr->ring;
- if(buffered(ring) >= Blocksize){
+ if(buffered(ring) >= Blocksize)
ring->ri = ring->nbuf - dmacount(ctlr->conf.dma);
-
- ctlr->totcount += Blocksize;
- ctlr->tottime = todget(nil);
- }else{
+ else{
dmaend(ctlr->conf.dma);
sbcmd(blaster, 0xd9); /* exit at end of count */
sbcmd(blaster, 0xd5); /* pause */
@@ -493,8 +488,6 @@
ilock(&ctlr->blaster);
ctlr->ring.ri = 0;
ctlr->ring.wi = 0;
- ctlr->totcount = 0;
- ctlr->tottime = 0LL;
iunlock(&ctlr->blaster);
}
@@ -508,12 +501,8 @@
audiostatus(Audio *adev, void *a, long n, vlong)
{
Ctlr *ctlr = adev->ctlr;
-
- return snprint((char*)a, n,
- "bufsize %6d buffered %6ld "
- "offset %10lud time %19lld\n",
- Blocksize, buffered(&ctlr->ring),
- ctlr->totcount, ctlr->tottime);
+ return snprint((char*)a, n, "bufsize %6d buffered %6ld\n",
+ Blocksize, buffered(&ctlr->ring));
}
static int
@@ -520,7 +509,6 @@
inactive(void *arg)
{
Ctlr *ctlr = arg;
-
return !ctlr->active;
}
@@ -528,7 +516,6 @@
anybuf(void *arg)
{
Ctlr *ctlr = arg;
-
return available(&ctlr->ring) || inactive(ctlr);
}
--- a/sys/src/9/port/devaudio.c
+++ b/sys/src/9/port/devaudio.c
@@ -31,7 +31,7 @@
Qdir = 0,
Qaudio,
Qaudioctl,
- Qaudiostatus,
+ Qaudiostat,
Qvolume,
};
@@ -39,7 +39,7 @@
".", {Qdir, 0, QTDIR}, 0, DMDIR|0555,
"audio", {Qaudio}, 0, 0666,
"audioctl", {Qaudioctl}, 0, 0222,
- "audiostat", {Qaudiostatus}, 0, 0444,
+ "audiostat", {Qaudiostat}, 0, 0444,
"volume", {Qvolume}, 0, 0666,
};
@@ -139,7 +139,7 @@
error(Enomem);
i = 1<<adev->ctlrno;
- if((attached & i) == 0 && adev->volwrite){
+ if((attached & i) == 0){
static char *settings[] = {
"speed 44100",
"delay 882", /* 20 ms */
@@ -149,7 +149,7 @@
};
attached |= i;
- for(i=0; i<nelem(settings); i++){
+ for(i=0; i<nelem(settings) && adev->volwrite; i++){
strcpy(ac->buf, settings[i]);
if(!waserror()){
adev->volwrite(adev, ac->buf, strlen(ac->buf), 0);
@@ -169,7 +169,7 @@
ac = c->aux;
adev = ac->adev;
- if(c->qid.path == Qaudio && incref(&adev->audioopen) != 1){
+ if((c->qid.path == Qaudio) && (incref(&adev->audioopen) != 1)){
decref(&adev->audioopen);
error(Ebusy);
}
@@ -189,14 +189,12 @@
fn = nil;
switch((ulong)c->qid.path){
case Qdir:
- /* BUG: race */
- if(adev->buffered)
- audiodir[Qaudio].length = adev->buffered(adev);
+ audiodir[Qaudio].length = adev->buffered ? adev->buffered(adev) : 0;
return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
case Qaudio:
fn = adev->read;
break;
- case Qaudiostatus:
+ case Qaudiostat:
fn = adev->status;
break;
case Qvolume:
@@ -212,7 +210,7 @@
nexterror();
}
switch((ulong)c->qid.path){
- case Qaudiostatus:
+ case Qaudiostat:
case Qvolume:
/* generate the text on first read */
if(ac->data == nil || off == 0){
@@ -294,12 +292,15 @@
ac = c->aux;
adev = ac->adev;
- if(c->qid.path == Qaudio && (c->flag & COPEN)){
- if(adev->close)
- adev->close(adev);
+ if((c->qid.path == Qaudio) && (c->flag & COPEN)){
+ if(adev->close){
+ if(!waserror()){
+ adev->close(adev);
+ poperror();
+ }
+ }
decref(&adev->audioopen);
}
-
if(ac->owner == c){
ac->owner = nil;
c->aux = nil;
@@ -334,11 +335,8 @@
ac = c->aux;
adev = ac->adev;
-
- /* BUG: race */
- if(adev->buffered && (ulong)c->qid.path == Qaudio)
- audiodir[Qaudio].length = adev->buffered(adev);
-
+ if((ulong)c->qid.path == Qaudio)
+ audiodir[Qaudio].length = adev->buffered ? adev->buffered(adev) : 0;
return devstat(c, dp, n, audiodir, nelem(audiodir), devgen);
}