Module Name:    src
Committed By:   isaki
Date:           Thu Jul 27 08:28:18 UTC 2017

Modified Files:
        src/sys/dev: audio.c audiovar.h

Log Message:
Improve in #ifdef AUDIO_INTR_TIME.
Stop 19 years old weird #define, stop signed/unsigned mixing,
use int64_t instead of (u_)long to avoid integer overflow,
rearrange definitions in header, and fix indent.


To generate a diff of this commit:
cvs rdiff -u -r1.369 -r1.370 src/sys/dev/audio.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/audiovar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.369 src/sys/dev/audio.c:1.370
--- src/sys/dev/audio.c:1.369	Tue Jul 25 13:29:16 2017
+++ src/sys/dev/audio.c	Thu Jul 27 08:28:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.369 2017/07/25 13:29:16 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.370 2017/07/27 08:28:18 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <[email protected]>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.369 2017/07/25 13:29:16 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.370 2017/07/27 08:28:18 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2063,28 +2063,24 @@ audio_initbufs(struct audio_softc *sc, s
 		sc->sc_pr.blksize = vc->sc_mpr.blksize;
 
 #ifdef AUDIO_INTR_TIME
-#define double u_long
 	if (audio_can_playback(sc)) {
 		sc->sc_pnintr = 0;
-		sc->sc_pblktime = (u_long)(
-		    (double)vc->sc_mpr.blksize * 100000 /
-		    (double)(vc->sc_pparams.channels *
-		             vc->sc_pparams.sample_rate *
-		             vc->sc_pparams.precision / NBBY)) * 10;
-		DPRINTF(("audio: play blktime = %lu for %d\n",
+		sc->sc_pblktime = (int64_t)vc->sc_mpr.blksize * 1000000 /
+		    (vc->sc_pparams.channels *
+		     vc->sc_pparams.sample_rate *
+		     vc->sc_pparams.precision / NBBY);
+		DPRINTF(("audio: play blktime = %" PRId64 " for %d\n",
 			 sc->sc_pblktime, vc->sc_mpr.blksize));
 	}
 	if (audio_can_capture(sc)) {
 		sc->sc_rnintr = 0;
-		sc->sc_rblktime = (u_long)(
-		    (double)vc->sc_mrr.blksize * 100000 /
-		    (double)(vc->sc_rparams.channels *
-		             vc->sc_rparams.sample_rate *
-		             vc->sc_rparams.precision / NBBY)) * 10;
-		DPRINTF(("audio: record blktime = %lu for %d\n",
+		sc->sc_rblktime = (int64_t)vc->sc_mrr.blksize * 1000000 /
+		    (vc->sc_rparams.channels *
+		     vc->sc_rparams.sample_rate *
+		     vc->sc_rparams.precision / NBBY);
+		DPRINTF(("audio: record blktime = %" PRId64 " for %d\n",
 			 sc->sc_rblktime, vc->sc_mrr.blksize));
 	}
-#undef double
 #endif
 
 	return 0;
@@ -3773,26 +3769,28 @@ audio_mix(void *v)
 #ifdef AUDIO_INTR_TIME
 		{
 			struct timeval tv;
-			u_long t;
+			int64_t t;
 			microtime(&tv);
-			t = tv.tv_usec + 1000000 * tv.tv_sec;
+			t = (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
 			if (sc->sc_pnintr) {
-				long lastdelta, totdelta;
+				int64_t lastdelta, totdelta;
 				lastdelta = t - sc->sc_plastintr -
 				    sc->sc_pblktime;
 				if (lastdelta > sc->sc_pblktime / 3) {
 					printf("audio: play interrupt(%d) off "
-				       "relative by %ld us (%lu)\n",
+					       "relative by %" PRId64 " us "
+					       "(%" PRId64 ")\n",
 					       sc->sc_pnintr, lastdelta,
 					       sc->sc_pblktime);
 				}
 				totdelta = t - sc->sc_pfirstintr -
-					sc->sc_pblktime * sc->sc_pnintr;
+				    sc->sc_pblktime * sc->sc_pnintr;
 				if (totdelta > sc->sc_pblktime) {
 					printf("audio: play interrupt(%d) "
-					       "off absolute by %ld us (%lu) "
-					       "(LOST)\n", sc->sc_pnintr,
-					       totdelta, sc->sc_pblktime);
+					       "off absolute by %" PRId64 " us "
+					       "(%" PRId64 ") (LOST)\n",
+					       sc->sc_pnintr, totdelta,
+					       sc->sc_pblktime);
 					sc->sc_pnintr++;
 					/* avoid repeated messages */
 				}
@@ -4004,25 +4002,27 @@ audio_upmix(void *v)
 #ifdef AUDIO_INTR_TIME
 		{
 			struct timeval tv;
-			u_long t;
+			int64_t t;
 			microtime(&tv);
-			t = tv.tv_usec + 1000000 * tv.tv_sec;
+			t = (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
 			if (sc->sc_rnintr) {
-				long lastdelta, totdelta;
+				int64_t lastdelta, totdelta;
 				lastdelta = t - sc->sc_rlastintr -
 				    sc->sc_rblktime;
 				if (lastdelta > sc->sc_rblktime / 5) {
 					printf("audio: record interrupt(%d) "
-					       "off relative by %ld us (%lu)\n",
+					       "off relative by %" PRId64 " us "
+					       "(%" PRId64 ")\n",
 					       sc->sc_rnintr, lastdelta,
 					       sc->sc_rblktime);
 				}
 				totdelta = t - sc->sc_rfirstintr -
-					sc->sc_rblktime * sc->sc_rnintr;
+				    sc->sc_rblktime * sc->sc_rnintr;
 				if (totdelta > sc->sc_rblktime / 2) {
 					sc->sc_rnintr++;
 					printf("audio: record interrupt(%d) "
-					       "off absolute by %ld us (%lu)\n",
+					       "off absolute by %" PRId64 " us "
+					       "(%" PRId64 ")\n",
 					       sc->sc_rnintr, totdelta,
 					       sc->sc_rblktime);
 					sc->sc_rnintr++;

Index: src/sys/dev/audiovar.h
diff -u src/sys/dev/audiovar.h:1.56 src/sys/dev/audiovar.h:1.57
--- src/sys/dev/audiovar.h:1.56	Tue Jun 20 07:45:01 2017
+++ src/sys/dev/audiovar.h	Thu Jul 27 08:28:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.56 2017/06/20 07:45:01 nat Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.57 2017/07/27 08:28:18 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -263,14 +263,14 @@ struct audio_softc {
 	int		sc_monitor_port;
 
 #ifdef AUDIO_INTR_TIME
-	u_long	sc_pfirstintr;	/* first time we saw a play interrupt */
 	int	sc_pnintr;	/* number of interrupts */
-	u_long	sc_plastintr;	/* last time we saw a play interrupt */
-	long	sc_pblktime;	/* nominal time between interrupts */
-	u_long	sc_rfirstintr;	/* first time we saw a rec interrupt */
+	int64_t	sc_pfirstintr;	/* first time we saw a play interrupt */
+	int64_t	sc_plastintr;	/* last time we saw a play interrupt */
+	int64_t	sc_pblktime;	/* nominal time between interrupts */
 	int	sc_rnintr;	/* number of interrupts */
-	u_long	sc_rlastintr;	/* last time we saw a rec interrupt */
-	long	sc_rblktime;	/* nominal time between interrupts */
+	int64_t	sc_rfirstintr;	/* first time we saw a rec interrupt */
+	int64_t	sc_rlastintr;	/* last time we saw a rec interrupt */
+	int64_t	sc_rblktime;	/* nominal time between interrupts */
 #endif
 
 	u_int	sc_lastgain;

Reply via email to