Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/dev Pull up following revision(s) (requested by isaki...



details:   https://anonhg.NetBSD.org/src/rev/b3987eb7b279
branches:  netbsd-8
changeset: 851023:b3987eb7b279
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Sep 11 05:29:37 2017 +0000

description:
Pull up following revision(s) (requested by isaki in ticket #273):
        sys/dev/audio.c: 1.368, 1.370
        sys/dev/audiovar.h: revision 1.57
Fix division by zero when precision < 8 in ifdef AUDIO_INTR_TIME.
--
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 73b52c90923b -r b3987eb7b279 sys/dev/audio.c
--- a/sys/dev/audio.c   Mon Sep 11 05:27:19 2017 +0000
+++ b/sys/dev/audio.c   Mon Sep 11 05:29:37 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.357.2.5 2017/08/31 11:10:37 martin Exp $   */
+/*     $NetBSD: audio.c,v 1.357.2.6 2017/09/11 05:29:37 snj 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.357.2.5 2017/08/31 11:10:37 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.357.2.6 2017/09/11 05:29:37 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2059,28 +2059,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.precision / NBBY *
-                            vc->sc_pparams.channels *
-                            vc->sc_pparams.sample_rate)) * 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.precision / NBBY *
-                            vc->sc_rparams.channels *
-                            vc->sc_rparams.sample_rate)) * 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;
@@ -3764,26 +3760,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 */
                                }
@@ -3995,25 +3993,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 73b52c90923b -r b3987eb7b279 sys/dev/audiovar.h
--- a/sys/dev/audiovar.h        Mon Sep 11 05:27:19 2017 +0000
+++ b/sys/dev/audiovar.h        Mon Sep 11 05:29:37 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiovar.h,v 1.55.2.1 2017/06/30 06:43:07 snj Exp $    */
+/*     $NetBSD: audiovar.h,v 1.55.2.2 2017/09/11 05:29:37 snj 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