summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjakemsr <jakemsr@openbsd.org>2009-12-04 20:50:59 +0000
committerjakemsr <jakemsr@openbsd.org>2009-12-04 20:50:59 +0000
commitea4046e892aa7dd076bf5c2ef6a3920492761af6 (patch)
tree5e8326ce6ccb834e9f33632e17e008eaa1e2c373
parentinstead of returning a structure, return the only member of the (diff)
downloadwireguard-openbsd-ea4046e892aa7dd076bf5c2ef6a3920492761af6.tar.xz
wireguard-openbsd-ea4046e892aa7dd076bf5c2ef6a3920492761af6.zip
calculate the number of frames per usb xfer only once, and take into
account possible "fractional samples" which occur when the usb frame rate is not a whole number factor of the audio sample rate, such as with 44.1 kHz audio sample rate and full-speed usb (1 kHz frame rate).
-rw-r--r--sys/dev/usb/uaudio.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/sys/dev/usb/uaudio.c b/sys/dev/usb/uaudio.c
index 038687ee64c..5d64bf555d4 100644
--- a/sys/dev/usb/uaudio.c
+++ b/sys/dev/usb/uaudio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uaudio.c,v 1.72 2009/12/04 20:38:43 jakemsr Exp $ */
+/* $OpenBSD: uaudio.c,v 1.73 2009/12/04 20:50:59 jakemsr Exp $ */
/* $NetBSD: uaudio.c,v 1.90 2004/10/29 17:12:53 kent Exp $ */
/*
@@ -2954,15 +2954,11 @@ uaudio_chan_set_param(struct chan *ch, u_char *start, u_char *end, int blksize)
/*
* Recompute nframes based on blksize, but make sure nframes
- * is not longer in time duration than blksize. Rounding helps.
+ * is not longer in time duration than blksize.
*/
- if (ch->maxpktsize) {
- ch->nframes = ch->blksize / ch->maxpktsize;
- } else {
- ch->nframes = (ch->blksize / ch->sample_size) *
- ch->usb_fps / ch->sample_rate;
- }
- ch->nframes = ch->blksize / ch->bytes_per_frame;
+ ch->nframes = ch->blksize * ch->usb_fps /
+ (ch->bytes_per_frame * ch->usb_fps +
+ ch->sample_size * ch->fraction);
if (ch->nframes > UAUDIO_MAX_FRAMES)
ch->nframes = UAUDIO_MAX_FRAMES;
else if (ch->nframes < 1)