From e58fe89d0c67d628ecfa84274cd7f4d26bb40ddb Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 13 Oct 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-10-13 --- pc/devusb.c | 5 ++++- port/devaudio.c | 32 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/pc/devusb.c b/pc/devusb.c index a89e18722e34822d8eaf519ee7f32bf364ea515d..3e9a6f6853ac1dba56965eff369b2a39f47b9ffb 100644 --- a/pc/devusb.c +++ b/pc/devusb.c @@ -1440,6 +1440,7 @@ usbgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp) Udev *d; Dirtab *tab; Endpt *e; + vlong len; /* * Top level directory contains the name of the device. @@ -1489,6 +1490,7 @@ usbgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp) /* * Third level. */ + len = 0; path = c->qid.path & ~QMASK; /* slot component */ if(s == DEVDOTDOT){ mkqid(&q, Q2nd, c->qid.vers, QTDIR); @@ -1513,7 +1515,8 @@ usbgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp) return 0; sprint(up->genbuf, "ep%ddata", s); mkqid(&q, path | (Qep0+s), c->qid.vers, QTFILE); - devdir(c, q, up->genbuf, 0, eve, e->mode==OREAD? 0444: e->mode==OWRITE? 0222: 0666, dp); + len = e->buffered; + devdir(c, q, up->genbuf, len, eve, e->mode==OREAD? 0444: e->mode==OWRITE? 0222: 0666, dp); return 1; } diff --git a/port/devaudio.c b/port/devaudio.c index 027d129bb52f4d17d94b4d62cf839bfd2b4a9cb8..c6b63f28300c0dd92f9495fe8d206648af347e32 100644 --- a/port/devaudio.c +++ b/port/devaudio.c @@ -68,12 +68,12 @@ static struct { QLock; Rendez vous; - int bufinit; /* boolean if buffers allocated */ - int curcount; /* how much data in current buffer */ + int bufinit; /* boolean if buffers allocated */ + int curcount; /* how much data in current buffer */ int active; /* boolean dma running */ - int intr; /* boolean an interrupt has happened */ + int intr; /* boolean an interrupt has happened */ int amode; /* Aclosed/Aread/Awrite for /audio */ - int rivol[Nvol]; /* right/left input/output volumes */ + int rivol[Nvol]; /* right/left input/output volumes */ int livol[Nvol]; int rovol[Nvol]; int lovol[Nvol]; @@ -81,8 +81,9 @@ static struct int minor; /* SB16 minor version number */ ulong totcount; /* how many bytes processed since open */ vlong tottime; /* time at which totcount bytes were processed */ + int buffered; /* number of bytes en route */ - Buf buf[Nbuf]; /* buffers and queues */ + Buf buf[Nbuf]; /* buffers and queues */ AQueue empty; AQueue full; Buf* current; @@ -97,11 +98,11 @@ static struct int irval; } volumes[] = { -[Vaudio] "audio", Fout, 50, 50, -[Vsynth] "synth", Fin|Fout, 0, 0, +[Vaudio] "audio", Fout, 50, 50, +[Vsynth] "synth", Fin|Fout, 0, 0, [Vcd] "cd", Fin|Fout, 0, 0, -[Vline] "line", Fin|Fout, 0, 0, -[Vmic] "mic", Fin|Fout|Fmono, 0, 0, +[Vline] "line", Fin|Fout, 0, 0, +[Vmic] "mic", Fin|Fout|Fmono, 0, 0, [Vspeaker] "speaker", Fout|Fmono, 0, 0, [Vtreb] "treb", Fout, 50, 50, @@ -347,12 +348,16 @@ contindma(void) b = audio.current; if(audio.amode == Aread) { - if(b) /* shouldn't happen */ + if(b){ putbuf(&audio.full, b); + audio.buffered += Bufsize; + } b = getbuf(&audio.empty); } else { - if(b) /* shouldn't happen */ + if(b){ putbuf(&audio.empty, b); + audio.buffered -= Bufsize; + } b = getbuf(&audio.full); } audio.current = b; @@ -634,6 +639,7 @@ setempty(void) audio.full.last = 0; audio.current = 0; audio.filling = 0; + audio.buffered = 0; for(i=0; ivirt+audio.curcount, 0, Bufsize-audio.curcount); + audio.buffered += Bufsize-audio.curcount; swab(b->virt); putbuf(&audio.full, b); } @@ -996,6 +1004,7 @@ audioread(Chan *c, void *v, long n, vlong off) audio.curcount += m; n -= m; a += m; + audio.buffered -= m; if(audio.curcount >= Bufsize) { audio.filling = 0; putbuf(&audio.empty, b); @@ -1171,6 +1180,7 @@ audiowrite(Chan *c, void *vp, long n, vlong) audio.curcount += m; n -= m; a += m; + audio.buffered += m; if(audio.curcount >= Bufsize) { audio.filling = 0; swab(b->virt);