Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Oct 2016 12:43:49 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r308032 - stable/11/sys/dev/sound/usb
Message-ID:  <201610281243.u9SChnx3031383@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Fri Oct 28 12:43:49 2016
New Revision: 308032
URL: https://svnweb.freebsd.org/changeset/base/308032

Log:
  MFC r307651:
  Add support for adjusting the hardware buffering delay for USB audio.
  
  Requested by:	Goran Mekic <meka@tilda.center>

Modified:
  stable/11/sys/dev/sound/usb/uaudio.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/sound/usb/uaudio.c
==============================================================================
--- stable/11/sys/dev/sound/usb/uaudio.c	Fri Oct 28 12:36:59 2016	(r308031)
+++ stable/11/sys/dev/sound/usb/uaudio.c	Fri Oct 28 12:43:49 2016	(r308032)
@@ -95,6 +95,7 @@ __FBSDID("$FreeBSD$");
 static int uaudio_default_rate = 0;		/* use rate list */
 static int uaudio_default_bits = 32;
 static int uaudio_default_channels = 0;		/* use default */
+static int uaudio_buffer_ms = 8;
 
 #ifdef USB_DEBUG
 static int uaudio_debug = 0;
@@ -109,9 +110,32 @@ SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, def
     &uaudio_default_bits, 0, "uaudio default sample bits");
 SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_channels, CTLFLAG_RWTUN,
     &uaudio_default_channels, 0, "uaudio default sample channels");
+
+static int
+uaudio_buffer_ms_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	int err, val;
+
+	val = uaudio_buffer_ms;
+	err = sysctl_handle_int(oidp, &val, 0, req);
+
+	if (err != 0 || req->newptr == NULL || val == uaudio_buffer_ms)
+		return (err);
+
+	if (val > 8)
+		val = 8;
+	else if (val < 2)
+		val = 2;
+
+	uaudio_buffer_ms = val;
+
+	return (0);
+}
+SYSCTL_PROC(_hw_usb_uaudio, OID_AUTO, buffer_ms, CTLTYPE_INT | CTLFLAG_RWTUN,
+    0, sizeof(int), uaudio_buffer_ms_sysctl, "I",
+    "uaudio buffering delay from 2ms to 8ms");
 #endif
 
-#define	UAUDIO_IRQS	(8000 / UAUDIO_NFRAMES)	/* interrupts per second */
 #define	UAUDIO_NFRAMES		64	/* must be factor of 8 due HS-USB */
 #define	UAUDIO_NCHANBUFS	2	/* number of outstanding request */
 #define	UAUDIO_RECURSE_LIMIT	255	/* rounds */
@@ -1278,10 +1302,10 @@ uaudio_configure_msg_sub(struct uaudio_s
 
 	if (fps < 8000) {
 		/* FULL speed USB */
-		frames = 8;
+		frames = uaudio_buffer_ms;
 	} else {
 		/* HIGH speed USB */
-		frames = UAUDIO_NFRAMES;
+		frames = uaudio_buffer_ms * 8;
 	}
 
 	fps_shift = usbd_xfer_get_fps_shift(chan->xfer[0]);
@@ -2158,8 +2182,9 @@ tr_setup:
 		}
 
 		/* start the SYNC transfer one time per second, if any */
-		if (++(ch->intr_counter) >= UAUDIO_IRQS) {
-			ch->intr_counter = 0;
+		ch->intr_counter += ch->intr_frames;
+		if (ch->intr_counter >= ch->frames_per_second) {
+			ch->intr_counter -= ch->frames_per_second;
 			usbd_transfer_start(ch->xfer[UAUDIO_NCHANBUFS]);
 		}
 



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