From 0b50a4099fc32fd37a510bd1f34b71199d9373d4 Mon Sep 17 00:00:00 2001 From: Jacob Meuser Date: Fri, 4 Dec 2009 20:51:00 +0000 Subject: 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). --- sys/dev/usb/uaudio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'sys/dev/usb/uaudio.c') 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) -- cgit v1.2.3