Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Improve in #ifdef AUDIO_INTR_TIME.



details:   https://anonhg.NetBSD.org/src/rev/7ca042da06ae
branches:  trunk
changeset: 825659:7ca042da06ae
user:      isaki <isaki%NetBSD.org@localhost>
date:      Thu Jul 27 08:28:18 2017 +0000

description:
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.

diffstat:

 sys/dev/audio.c    |  60 +++++++++++++++++++++++++++---------------------------
 sys/dev/audiovar.h |  14 ++++++------
 2 files changed, 37 insertions(+), 37 deletions(-)

diffs (158 lines):

diff -r 6b58308f7987 -r 7ca042da06ae sys/dev/audio.c
--- a/sys/dev/audio.c   Thu Jul 27 08:10:41 2017 +0000
+++ b/sys/dev/audio.c   Thu Jul 27 08:28:18 2017 +0000
@@ -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 <nathanialsloss%yahoo.com.au@localhost>
@@ -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 @@
                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 @@
 #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 @@
 #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++;
diff -r 6b58308f7987 -r 7ca042da06ae sys/dev/audiovar.h
--- a/sys/dev/audiovar.h        Thu Jul 27 08:10:41 2017 +0000
+++ b/sys/dev/audiovar.h        Thu Jul 27 08:28:18 2017 +0000
@@ -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 @@
        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;



Home | Main Index | Thread Index | Old Index