Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jul 2009 00:14:56 +0000 (UTC)
From:      Alfred Perlstein <alfred@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r195961 - head/sys/dev/sound/usb
Message-ID:  <200907300014.n6U0Euos086393@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alfred
Date: Thu Jul 30 00:14:56 2009
New Revision: 195961
URL: http://svn.freebsd.org/changeset/base/195961

Log:
  USB audio:
  - code factoring patch from "Eygene Ryabinkin"
  - P4 ID: 166149
  
  Submitted by:	hps
  Approved by:	re

Modified:
  head/sys/dev/sound/usb/uaudio.c

Modified: head/sys/dev/sound/usb/uaudio.c
==============================================================================
--- head/sys/dev/sound/usb/uaudio.c	Thu Jul 30 00:14:34 2009	(r195960)
+++ head/sys/dev/sound/usb/uaudio.c	Thu Jul 30 00:14:56 2009	(r195961)
@@ -108,6 +108,7 @@ SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, def
 #define	UAUDIO_MINFRAMES       16	/* must be factor of 8 due HS-USB */
 #define	UAUDIO_NCHANBUFS        2	/* number of outstanding request */
 #define	UAUDIO_RECURSE_LIMIT   24	/* rounds */
+#define	UAUDIO_MINFRAMES_ALIGN(x) ((x) & ~(UAUDIO_MINFRAMES - 1))
 
 #define	MAKE_WORD(h,l) (((h) << 8) | (l))
 #define	BIT_TEST(bm,bno) (((bm)[(bno) / 8] >> (7 - ((bno) % 8))) & 1)
@@ -1113,6 +1114,41 @@ done:
 	}
 }
 
+/*
+ * The following function sets up data size and block count for the
+ * next audio transfer.
+ */
+static void
+uaudio_setup_blockcount(struct uaudio_chan *ch, usb_frcount_t max_frames,
+    uint32_t *total, uint32_t *blockcount)
+{
+	uint32_t temp;
+	uint32_t isiz;
+
+	/* allow dynamic sizing of play buffer */
+	isiz = ch->intr_size;
+
+	/* allow dynamic sizing of play buffer */
+	temp = isiz / ch->bytes_per_frame;
+
+	/* align units */
+	temp = UAUDIO_MINFRAMES_ALIGN(temp);
+
+	/* range check - min */
+	if (temp == 0)
+		temp = UAUDIO_MINFRAMES;
+
+	/* range check - max */
+	if (temp > max_frames)
+		temp = max_frames;
+
+	/* store blockcount */
+	*blockcount = temp;
+
+	/* compute the total length */
+	*total = temp * ch->bytes_per_frame;
+}
+
 static void
 uaudio_chan_play_callback(struct usb_xfer *xfer, usb_error_t error)
 {
@@ -1126,25 +1162,8 @@ uaudio_chan_play_callback(struct usb_xfe
 
 	usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
 
-	/* allow dynamic sizing of play buffer */
-	total = ch->intr_size;
-
-	/* allow dynamic sizing of play buffer */
-	blockcount = total / ch->bytes_per_frame;
-
-	/* align units */
-	blockcount -= (blockcount % UAUDIO_MINFRAMES);
-
-	/* range check - min */
-	if (blockcount == 0) {
-		blockcount = UAUDIO_MINFRAMES;
-	}
-	/* range check - max */
-	if (blockcount > usbd_xfer_max_frames(xfer)) {
-		blockcount = usbd_xfer_max_frames(xfer);
-	}
-	/* compute the total length */
-	total = blockcount * ch->bytes_per_frame;
+	uaudio_setup_blockcount(ch, usbd_xfer_max_frames(xfer),
+		&total, &blockcount);
 
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:
@@ -1221,25 +1240,8 @@ uaudio_chan_record_callback(struct usb_x
 
 	usbd_xfer_status(xfer, &actlen, NULL, NULL, &nframes);
 
-	/* allow dynamic sizing of play buffer */
-	total = ch->intr_size;
-
-	/* allow dynamic sizing of play buffer */
-	blockcount = total / ch->bytes_per_frame;
-
-	/* align units */
-	blockcount -= (blockcount % UAUDIO_MINFRAMES);
-
-	/* range check - min */
-	if (blockcount == 0) {
-		blockcount = UAUDIO_MINFRAMES;
-	}
-	/* range check - max */
-	if (blockcount > usbd_xfer_max_frames(xfer)) {
-		blockcount = usbd_xfer_max_frames(xfer);
-	}
-	/* compute the total length */
-	total = blockcount * ch->bytes_per_frame;
+	uaudio_setup_blockcount(ch, usbd_xfer_max_frames(xfer),
+		&total, &blockcount);
 
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_TRANSFERRED:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907300014.n6U0Euos086393>