summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2015-07-24 08:56:45 +0000
committerratchov <ratchov@openbsd.org>2015-07-24 08:56:45 +0000
commitb2c79e46ef92638555e714ab8a364ff1cfb446ae (patch)
treee65e956dabde52d623fced1998d6ad67bb8e2133
parentFix arithmetic mistake causing errors when there are more xruns on the (diff)
downloadwireguard-openbsd-b2c79e46ef92638555e714ab8a364ff1cfb446ae.tar.xz
wireguard-openbsd-b2c79e46ef92638555e714ab8a364ff1cfb446ae.zip
Switch back into counting bytes rather than blocks. We can't just
multiply the block count by the block size to get the bytes count because they won't wrap correctly.
-rw-r--r--sys/dev/audio.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/sys/dev/audio.c b/sys/dev/audio.c
index 07072bfd507..8506f88b0ee 100644
--- a/sys/dev/audio.c
+++ b/sys/dev/audio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: audio.c,v 1.133 2015/07/22 19:06:28 ratchov Exp $ */
+/* $OpenBSD: audio.c,v 1.134 2015/07/24 08:56:45 ratchov Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
@@ -66,7 +66,7 @@ struct audio_buf {
size_t start; /* first byte used in the FIFO */
size_t used; /* bytes used in the FIFO */
size_t blksz; /* DMA block size */
- unsigned long ticks; /* blocks transferred */
+ unsigned long pos; /* bytes transferred */
unsigned long xrun; /* bytes lost by xruns */
struct selinfo sel; /* to record & wakeup poll(2) */
int blocking; /* read/write blocking */
@@ -119,6 +119,8 @@ int audio_match(struct device *, void *, void *);
void audio_attach(struct device *, struct device *, void *);
int audio_activate(struct device *, int);
int audio_detach(struct device *, int);
+void audio_pintr(void *);
+void audio_rintr(void *);
#if NWSKBD > 0
void wskbd_mixer_init(struct audio_softc *);
#endif
@@ -327,12 +329,12 @@ audio_clear(struct audio_softc *sc)
{
if (sc->mode & AUMODE_PLAY) {
sc->play.used = sc->play.start = 0;
- sc->play.ticks = sc->play.xrun = 0;
+ sc->play.pos = sc->play.xrun = 0;
audio_fill_sil(sc, sc->play.data, sc->play.len);
}
if (sc->mode & AUMODE_RECORD) {
sc->rec.used = sc->rec.start = 0;
- sc->rec.ticks = sc->rec.xrun = 0;
+ sc->rec.pos = sc->rec.xrun = 0;
audio_fill_sil(sc, sc->rec.data, sc->rec.len);
}
}
@@ -358,7 +360,7 @@ audio_pintr(void *addr)
return;
}
- sc->play.ticks++;
+ sc->play.pos += sc->play.blksz;
audio_fill_sil(sc, sc->play.data + sc->play.start, sc->play.blksz);
audio_buf_rdiscard(&sc->play, sc->play.blksz);
if (sc->play.used < sc->play.blksz) {
@@ -412,7 +414,7 @@ audio_rintr(void *addr)
return;
}
- sc->rec.ticks++;
+ sc->rec.pos += sc->rec.blksz;
audio_buf_wcommit(&sc->rec, sc->rec.blksz);
if (sc->rec.used == sc->rec.len) {
DPRINTFN(1, "%s: rec overrun\n", DEVNAME(sc));
@@ -525,7 +527,7 @@ int
audio_start(struct audio_softc *sc)
{
sc->active = 1;
- sc->play.xrun = sc->play.ticks = sc->rec.xrun = sc->rec.ticks = 0;
+ sc->play.xrun = sc->play.pos = sc->rec.xrun = sc->rec.pos = 0;
return audio_start_do(sc);
}
@@ -956,8 +958,8 @@ audio_getinfo(struct audio_softc *sc, struct audio_info *ai)
* and the pos counters are more useful
*/
mtx_enter(&audio_lock);
- ai->play.samples = sc->play.ticks * sc->play.blksz - sc->play.xrun;
- ai->record.samples = sc->rec.ticks * sc->rec.blksz - sc->rec.xrun;
+ ai->play.samples = sc->play.pos - sc->play.xrun;
+ ai->record.samples = sc->rec.pos - sc->rec.xrun;
mtx_leave(&audio_lock);
ai->play.pause = ai->record.pause = sc->pause;
@@ -1045,7 +1047,7 @@ audio_attach(struct device *parent, struct device *self, void *aux)
sc->rchan = 2;
sc->round = 960;
sc->nblks = 2;
- sc->play.ticks = sc->play.xrun = sc->rec.ticks = sc->rec.xrun = 0;
+ sc->play.pos = sc->play.xrun = sc->rec.pos = sc->rec.xrun = 0;
}
int
@@ -1507,13 +1509,13 @@ audio_ioctl(struct audio_softc *sc, unsigned long cmd, void *addr)
case AUDIO_GETOOFFS:
mtx_enter(&audio_lock);
ao = (struct audio_offset *)addr;
- ao->samples = sc->play.ticks * sc->play.blksz;
+ ao->samples = sc->play.pos;
mtx_leave(&audio_lock);
break;
case AUDIO_GETIOFFS:
mtx_enter(&audio_lock);
ao = (struct audio_offset *)addr;
- ao->samples = sc->rec.ticks * sc->rec.blksz;
+ ao->samples = sc->rec.pos;
mtx_leave(&audio_lock);
break;
case AUDIO_SETINFO: