summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2007-10-19 15:31:02 +0000
committerratchov <ratchov@openbsd.org>2007-10-19 15:31:02 +0000
commit16f555da042dc555dff885e41903fbd449c161ce (patch)
tree33d28f53546294c42cd45664b60cd3bd3b992ed7
parentDon't use "counter-timer" as clock interrupt source on MULTIPROCESSOR kernels (diff)
downloadwireguard-openbsd-16f555da042dc555dff885e41903fbd449c161ce.tar.xz
wireguard-openbsd-16f555da042dc555dff885e41903fbd449c161ce.zip
fix audio_calc_blksize() not to return larger block sizes than
the buffer size ok jakemsr
-rw-r--r--sys/dev/audio.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/sys/dev/audio.c b/sys/dev/audio.c
index 82c4fb09693..5fbc48aa129 100644
--- a/sys/dev/audio.c
+++ b/sys/dev/audio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: audio.c,v 1.81 2007/10/03 21:49:13 jakemsr Exp $ */
+/* $OpenBSD: audio.c,v 1.82 2007/10/19 15:31:02 ratchov Exp $ */
/* $NetBSD: audio.c,v 1.119 1999/11/09 16:50:47 augustss Exp $ */
/*
@@ -1300,7 +1300,7 @@ audio_calc_blksize(struct audio_softc *sc, int mode)
struct audio_hw_if *hw = sc->hw_if;
struct audio_params *parm;
struct audio_ringbuffer *rb;
- int bs;
+ int bs, maxbs, fs;
if (sc->sc_blkset)
return;
@@ -1313,9 +1313,12 @@ audio_calc_blksize(struct audio_softc *sc, int mode)
rb = &sc->sc_rr;
}
- bs = parm->sample_rate * audio_blk_ms / 1000 *
- parm->channels * parm->precision / NBBY *
- parm->factor;
+ fs = parm->channels * parm->precision / NBBY * parm->factor;
+ bs = parm->sample_rate * audio_blk_ms / 1000 * fs;
+ maxbs = rb->bufsize / 2;
+ if (bs > maxbs)
+ bs = (maxbs / fs) * fs;
+
ROUNDSIZE(bs);
if (hw->round_blocksize)
bs = hw->round_blocksize(sc->hw_hdl, bs);