Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Set the gain of play back, rather than altering the ...



details:   https://anonhg.NetBSD.org/src/rev/9c884184a3fc
branches:  trunk
changeset: 824232:9c884184a3fc
user:      nat <nat%NetBSD.org@localhost>
date:      Sun May 28 21:15:58 2017 +0000

description:
Set the gain of play back, rather than altering the generated wave by a
factor of volume.

diffstat:

 sys/dev/audiobell.c |  14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diffs (60 lines):

diff -r 76ba5b3f0279 -r 9c884184a3fc sys/dev/audiobell.c
--- a/sys/dev/audiobell.c       Sun May 28 21:12:59 2017 +0000
+++ b/sys/dev/audiobell.c       Sun May 28 21:15:58 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiobell.c,v 1.18 2017/05/27 12:04:44 nat Exp $       */
+/*     $NetBSD: audiobell.c,v 1.19 2017/05/28 21:15:58 nat Exp $       */
 
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/types.h>
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.18 2017/05/27 12:04:44 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.19 2017/05/28 21:15:58 nat Exp $");
 
 #include <sys/audioio.h>
 #include <sys/conf.h>
@@ -57,13 +57,12 @@
 #define BELL_SHIFT             19
 
 static inline void
-audiobell_expandwave(int16_t *buf, int volume)
+audiobell_expandwave(int16_t *buf)
 {
        u_int i;
 
-       KASSERT(volume >= 0 && volume <= 100);
        for (i = 0; i < __arraycount(sinewave); i++)
-               buf[i] = (int32_t)sinewave[i] * (int32_t)volume / 100;
+               buf[i] = sinewave[i];
        for (i = __arraycount(sinewave); i < __arraycount(sinewave) * 2; i++)
                 buf[i] = buf[__arraycount(sinewave) * 2 - i - 1];
        for (i = __arraycount(sinewave) * 2; i < __arraycount(sinewave) * 4; i++)
@@ -82,7 +81,7 @@
 
        wave = malloc(sizeof(sinewave) * 4, M_TEMP, M_WAITOK);
        if (wave == NULL) return -1;
-       audiobell_expandwave(wave, volume);
+       audiobell_expandwave(wave);
        pitch = pitch * ((sizeof(sinewave) * 4) << BELL_SHIFT) /
            BELL_SAMPLE_RATE / 2;
        period = period * BELL_SAMPLE_RATE / 1000 / 2;
@@ -107,6 +106,8 @@
        struct file *fp;
        int size, len;
 
+       KASSERT(volume <= 100);
+
        fp = NULL;
        dev_t audio = AUDIO_DEVICE | device_unit((device_t)v);
 
@@ -124,6 +125,7 @@
 
        ai.play.sample_rate = BELL_SAMPLE_RATE;
        ai.play.precision = 16;
+       ai.play.gain = 255 * 100 / volume;
 
 #if BYTE_ORDER == LITTLE_ENDIAN
        ai.play.encoding = AUDIO_ENCODING_SLINEAR_LE;



Home | Main Index | Thread Index | Old Index