Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/4b32e92e9186
branches:  netbsd-9
changeset: 954370:4b32e92e9186
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Apr 06 17:44:29 2021 +0000

description:
Pull up following revision(s) (requested by isaki in ticket #1241):

        sys/dev/audio/audiobell.c: revision 1.4

Fix and improve the buffer length calculation to avoid zero length
even if blk_ms is small.

This fixes PR kern/56059.

diffstat:

 sys/dev/audio/audiobell.c |  36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)

diffs (90 lines):

diff -r 24f1b9d8b05e -r 4b32e92e9186 sys/dev/audio/audiobell.c
--- a/sys/dev/audio/audiobell.c Wed Mar 31 13:52:02 2021 +0000
+++ b/sys/dev/audio/audiobell.c Tue Apr 06 17:44:29 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $      */
+/*     $NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $ */
 
 /*
  * Copyright (c) 1999 Richard Earnshaw
@@ -31,7 +31,7 @@
  */
 
 #include <sys/types.h>
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $");
 
 #include <sys/audioio.h>
 #include <sys/conf.h>
@@ -81,6 +81,13 @@
 #undef A
 
 /*
+ * The minimum and the maximum buffer sizes must be a multiple of 32
+ * (32 = countof(sinewave) * sizeof(uint16_t)).
+ */
+#define MINBUFSIZE     (1024)
+#define MAXBUFSIZE     (4096)
+
+/*
  * dev is a device_t for the audio device to use.
  * pitch is the pitch of the bell in Hz,
  * period is the length in ms,
@@ -102,7 +109,7 @@
        u_int remainbytes;
        u_int wave1count;
        u_int wave1bytes;
-       u_int blkbytes;
+       u_int bufbytes;
        u_int len;
        u_int step;
        u_int offset;
@@ -111,6 +118,10 @@
 
        KASSERT(volume <= 100);
 
+       /* Playing for 0msec does nothing. */
+       if (period == 0)
+               return;
+
        /* The audio system isn't built for polling. */
        if (poll)
                return;
@@ -158,16 +169,23 @@
        remainbytes = remaincount * sizeof(int16_t);
        wave1bytes = wave1count * sizeof(int16_t);
 
-       blkbytes = ptrack->usrbuf_blksize;
-       blkbytes = rounddown(blkbytes, wave1bytes);
-       blkbytes = uimin(blkbytes, remainbytes);
-       buf = malloc(blkbytes, M_TEMP, M_WAITOK);
+       /* Based on 3*usrbuf_blksize, but not too small or too large */
+       bufbytes = ptrack->usrbuf_blksize * NBLKHW;
+       if (bufbytes < MINBUFSIZE)
+               bufbytes = MINBUFSIZE;
+       else if (bufbytes > MAXBUFSIZE)
+               bufbytes = MAXBUFSIZE;
+       else
+               bufbytes = roundup(bufbytes, wave1bytes);
+       bufbytes = uimin(bufbytes, remainbytes);
+       KASSERT(bufbytes != 0);
+       buf = malloc(bufbytes, M_TEMP, M_WAITOK);
        if (buf == NULL)
                goto out;
 
        /* Generate sinewave with specified volume */
        j = offset;
-       for (i = 0; i < blkbytes / sizeof(int16_t); i++) {
+       for (i = 0; i < bufbytes / sizeof(int16_t); i++) {
                /* XXX audio already has track volume feature though #if 0 */
                buf[i] = AUDIO_SCALEDOWN(sinewave[j] * (int)volume, 16);
                j += step;
@@ -177,7 +195,7 @@
        /* Write while paused to avoid inserting silence. */
        ptrack->is_pause = true;
        for (; remainbytes > 0; remainbytes -= len) {
-               len = uimin(remainbytes, blkbytes);
+               len = uimin(remainbytes, bufbytes);
                aiov.iov_base = (void *)buf;
                aiov.iov_len = len;
                auio.uio_iov = &aiov;



Home | Main Index | Thread Index | Old Index