audio: cleanup
This commit is contained in:
parent
86f316987d
commit
b274842f5c
4 changed files with 32 additions and 45 deletions
|
@ -269,15 +269,16 @@ ac97interrupt(Ureg *, void *arg)
|
||||||
static long
|
static long
|
||||||
ac97buffered(Audio *adev)
|
ac97buffered(Audio *adev)
|
||||||
{
|
{
|
||||||
Ctlr *ctlr;
|
Ctlr *ctlr = adev->ctlr;
|
||||||
ctlr = adev->ctlr;
|
|
||||||
return buffered(&ctlr->outring);
|
return buffered(&ctlr->outring);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static long
|
||||||
ac97kick(Ctlr *ctlr, long reg)
|
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
|
static int
|
||||||
|
@ -316,7 +317,7 @@ ac97write(Audio *adev, void *vp, long n, vlong)
|
||||||
ni = ring->wi / Blocksize;
|
ni = ring->wi / Blocksize;
|
||||||
while(oi != ni){
|
while(oi != ni){
|
||||||
csr8w(ctlr, Out+Lvi, oi);
|
csr8w(ctlr, Out+Lvi, oi);
|
||||||
ac97kick(ctlr, Out);
|
csr8w(ctlr, Out+Cr, Ioce | Rpbm);
|
||||||
oi = (oi + 1) % Ndesc;
|
oi = (oi + 1) % Ndesc;
|
||||||
}
|
}
|
||||||
p += n;
|
p += n;
|
||||||
|
@ -499,6 +500,7 @@ Found:
|
||||||
|
|
||||||
adev->write = ac97write;
|
adev->write = ac97write;
|
||||||
adev->buffered = ac97buffered;
|
adev->buffered = ac97buffered;
|
||||||
|
adev->status = ac97status;
|
||||||
|
|
||||||
intrenable(irq, ac97interrupt, adev, tbdf, adev->name);
|
intrenable(irq, ac97interrupt, adev, tbdf, adev->name);
|
||||||
|
|
||||||
|
|
|
@ -1213,9 +1213,9 @@ hdastatus(Audio *adev, void *a, long n, vlong)
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
s = a;
|
s = a;
|
||||||
k = snprint(s, n,
|
k = snprint(s, n, "bufsize %6d buffered %6ud\ncodec %2d pin %3d\n",
|
||||||
"bufsize %6d buffered %6ud codec %2d pin %3d\n",
|
ctlr->ring.blocksize, ringused(&ctlr->ring),
|
||||||
Bufsize, ringused(&ctlr->ring), ctlr->codec.id.codec, ctlr->pin);
|
ctlr->codec.id.codec, ctlr->pin);
|
||||||
|
|
||||||
for(fg=ctlr->codec.fgroup; fg; fg=fg->next){
|
for(fg=ctlr->codec.fgroup; fg; fg=fg->next){
|
||||||
for(w=fg->first; w; w=w->next){
|
for(w=fg->first; w; w=w->next){
|
||||||
|
|
|
@ -68,8 +68,6 @@ struct Ctlr
|
||||||
int active; /* boolean dma running */
|
int active; /* boolean dma running */
|
||||||
int major; /* SB16 major version number (sb 4) */
|
int major; /* SB16 major version number (sb 4) */
|
||||||
int minor; /* SB16 minor version number */
|
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 */
|
Ring ring; /* dma ring buffer */
|
||||||
Blaster blaster;
|
Blaster blaster;
|
||||||
|
|
||||||
|
@ -288,12 +286,9 @@ contindma(Ctlr *ctlr)
|
||||||
|
|
||||||
blaster = &ctlr->blaster;
|
blaster = &ctlr->blaster;
|
||||||
ring = &ctlr->ring;
|
ring = &ctlr->ring;
|
||||||
if(buffered(ring) >= Blocksize){
|
if(buffered(ring) >= Blocksize)
|
||||||
ring->ri = ring->nbuf - dmacount(ctlr->conf.dma);
|
ring->ri = ring->nbuf - dmacount(ctlr->conf.dma);
|
||||||
|
else{
|
||||||
ctlr->totcount += Blocksize;
|
|
||||||
ctlr->tottime = todget(nil);
|
|
||||||
}else{
|
|
||||||
dmaend(ctlr->conf.dma);
|
dmaend(ctlr->conf.dma);
|
||||||
sbcmd(blaster, 0xd9); /* exit at end of count */
|
sbcmd(blaster, 0xd9); /* exit at end of count */
|
||||||
sbcmd(blaster, 0xd5); /* pause */
|
sbcmd(blaster, 0xd5); /* pause */
|
||||||
|
@ -493,8 +488,6 @@ setempty(Ctlr *ctlr)
|
||||||
ilock(&ctlr->blaster);
|
ilock(&ctlr->blaster);
|
||||||
ctlr->ring.ri = 0;
|
ctlr->ring.ri = 0;
|
||||||
ctlr->ring.wi = 0;
|
ctlr->ring.wi = 0;
|
||||||
ctlr->totcount = 0;
|
|
||||||
ctlr->tottime = 0LL;
|
|
||||||
iunlock(&ctlr->blaster);
|
iunlock(&ctlr->blaster);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,19 +501,14 @@ static long
|
||||||
audiostatus(Audio *adev, void *a, long n, vlong)
|
audiostatus(Audio *adev, void *a, long n, vlong)
|
||||||
{
|
{
|
||||||
Ctlr *ctlr = adev->ctlr;
|
Ctlr *ctlr = adev->ctlr;
|
||||||
|
return snprint((char*)a, n, "bufsize %6d buffered %6ld\n",
|
||||||
return snprint((char*)a, n,
|
Blocksize, buffered(&ctlr->ring));
|
||||||
"bufsize %6d buffered %6ld "
|
|
||||||
"offset %10lud time %19lld\n",
|
|
||||||
Blocksize, buffered(&ctlr->ring),
|
|
||||||
ctlr->totcount, ctlr->tottime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
inactive(void *arg)
|
inactive(void *arg)
|
||||||
{
|
{
|
||||||
Ctlr *ctlr = arg;
|
Ctlr *ctlr = arg;
|
||||||
|
|
||||||
return !ctlr->active;
|
return !ctlr->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +516,6 @@ static int
|
||||||
anybuf(void *arg)
|
anybuf(void *arg)
|
||||||
{
|
{
|
||||||
Ctlr *ctlr = arg;
|
Ctlr *ctlr = arg;
|
||||||
|
|
||||||
return available(&ctlr->ring) || inactive(ctlr);
|
return available(&ctlr->ring) || inactive(ctlr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ enum {
|
||||||
Qdir = 0,
|
Qdir = 0,
|
||||||
Qaudio,
|
Qaudio,
|
||||||
Qaudioctl,
|
Qaudioctl,
|
||||||
Qaudiostatus,
|
Qaudiostat,
|
||||||
Qvolume,
|
Qvolume,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ static Dirtab audiodir[] = {
|
||||||
".", {Qdir, 0, QTDIR}, 0, DMDIR|0555,
|
".", {Qdir, 0, QTDIR}, 0, DMDIR|0555,
|
||||||
"audio", {Qaudio}, 0, 0666,
|
"audio", {Qaudio}, 0, 0666,
|
||||||
"audioctl", {Qaudioctl}, 0, 0222,
|
"audioctl", {Qaudioctl}, 0, 0222,
|
||||||
"audiostat", {Qaudiostatus}, 0, 0444,
|
"audiostat", {Qaudiostat}, 0, 0444,
|
||||||
"volume", {Qvolume}, 0, 0666,
|
"volume", {Qvolume}, 0, 0666,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ audioattach(char *spec)
|
||||||
error(Enomem);
|
error(Enomem);
|
||||||
|
|
||||||
i = 1<<adev->ctlrno;
|
i = 1<<adev->ctlrno;
|
||||||
if((attached & i) == 0 && adev->volwrite){
|
if((attached & i) == 0){
|
||||||
static char *settings[] = {
|
static char *settings[] = {
|
||||||
"speed 44100",
|
"speed 44100",
|
||||||
"delay 882", /* 20 ms */
|
"delay 882", /* 20 ms */
|
||||||
|
@ -149,7 +149,7 @@ audioattach(char *spec)
|
||||||
};
|
};
|
||||||
|
|
||||||
attached |= i;
|
attached |= i;
|
||||||
for(i=0; i<nelem(settings); i++){
|
for(i=0; i<nelem(settings) && adev->volwrite; i++){
|
||||||
strcpy(ac->buf, settings[i]);
|
strcpy(ac->buf, settings[i]);
|
||||||
if(!waserror()){
|
if(!waserror()){
|
||||||
adev->volwrite(adev, ac->buf, strlen(ac->buf), 0);
|
adev->volwrite(adev, ac->buf, strlen(ac->buf), 0);
|
||||||
|
@ -169,7 +169,7 @@ audioopen(Chan *c, int omode)
|
||||||
|
|
||||||
ac = c->aux;
|
ac = c->aux;
|
||||||
adev = ac->adev;
|
adev = ac->adev;
|
||||||
if(c->qid.path == Qaudio && incref(&adev->audioopen) != 1){
|
if((c->qid.path == Qaudio) && (incref(&adev->audioopen) != 1)){
|
||||||
decref(&adev->audioopen);
|
decref(&adev->audioopen);
|
||||||
error(Ebusy);
|
error(Ebusy);
|
||||||
}
|
}
|
||||||
|
@ -189,14 +189,12 @@ audioread(Chan *c, void *a, long n, vlong off)
|
||||||
fn = nil;
|
fn = nil;
|
||||||
switch((ulong)c->qid.path){
|
switch((ulong)c->qid.path){
|
||||||
case Qdir:
|
case Qdir:
|
||||||
/* BUG: race */
|
audiodir[Qaudio].length = adev->buffered ? adev->buffered(adev) : 0;
|
||||||
if(adev->buffered)
|
|
||||||
audiodir[Qaudio].length = adev->buffered(adev);
|
|
||||||
return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
|
return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
|
||||||
case Qaudio:
|
case Qaudio:
|
||||||
fn = adev->read;
|
fn = adev->read;
|
||||||
break;
|
break;
|
||||||
case Qaudiostatus:
|
case Qaudiostat:
|
||||||
fn = adev->status;
|
fn = adev->status;
|
||||||
break;
|
break;
|
||||||
case Qvolume:
|
case Qvolume:
|
||||||
|
@ -212,7 +210,7 @@ audioread(Chan *c, void *a, long n, vlong off)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
switch((ulong)c->qid.path){
|
switch((ulong)c->qid.path){
|
||||||
case Qaudiostatus:
|
case Qaudiostat:
|
||||||
case Qvolume:
|
case Qvolume:
|
||||||
/* generate the text on first read */
|
/* generate the text on first read */
|
||||||
if(ac->data == nil || off == 0){
|
if(ac->data == nil || off == 0){
|
||||||
|
@ -294,12 +292,15 @@ audioclose(Chan *c)
|
||||||
|
|
||||||
ac = c->aux;
|
ac = c->aux;
|
||||||
adev = ac->adev;
|
adev = ac->adev;
|
||||||
if(c->qid.path == Qaudio && (c->flag & COPEN)){
|
if((c->qid.path == Qaudio) && (c->flag & COPEN)){
|
||||||
if(adev->close)
|
if(adev->close){
|
||||||
adev->close(adev);
|
if(!waserror()){
|
||||||
|
adev->close(adev);
|
||||||
|
poperror();
|
||||||
|
}
|
||||||
|
}
|
||||||
decref(&adev->audioopen);
|
decref(&adev->audioopen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ac->owner == c){
|
if(ac->owner == c){
|
||||||
ac->owner = nil;
|
ac->owner = nil;
|
||||||
c->aux = nil;
|
c->aux = nil;
|
||||||
|
@ -334,11 +335,8 @@ audiostat(Chan *c, uchar *dp, int n)
|
||||||
|
|
||||||
ac = c->aux;
|
ac = c->aux;
|
||||||
adev = ac->adev;
|
adev = ac->adev;
|
||||||
|
if((ulong)c->qid.path == Qaudio)
|
||||||
/* BUG: race */
|
audiodir[Qaudio].length = adev->buffered ? adev->buffered(adev) : 0;
|
||||||
if(adev->buffered && (ulong)c->qid.path == Qaudio)
|
|
||||||
audiodir[Qaudio].length = adev->buffered(adev);
|
|
||||||
|
|
||||||
return devstat(c, dp, n, audiodir, nelem(audiodir), devgen);
|
return devstat(c, dp, n, audiodir, nelem(audiodir), devgen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue