Source-Changes-HG archive

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

[src/trunk]: src Use record field for recording even on



details:   https://anonhg.NetBSD.org/src/rev/76b862f49655
branches:  trunk
changeset: 966543:76b862f49655
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sun Nov 03 11:13:45 2019 +0000

description:
Use record field for recording even on
SNDCTL_DSP_STEREO, SNDCTL_DSP_SETFMT, and SNDCTL_DSP_CHANNELS.

diffstat:

 lib/libossaudio/ossaudio.c     |  39 ++++++++++++++++++++++-----------------
 sys/compat/ossaudio/ossaudio.c |  31 ++++++++++++++++++-------------
 2 files changed, 40 insertions(+), 30 deletions(-)

diffs (230 lines):

diff -r 93e178038564 -r 76b862f49655 lib/libossaudio/ossaudio.c
--- a/lib/libossaudio/ossaudio.c        Sun Nov 03 10:09:04 2019 +0000
+++ b/lib/libossaudio/ossaudio.c        Sun Nov 03 11:13:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $      */
+/*     $NetBSD: ossaudio.c,v 1.38 2019/11/03 11:13:45 isaki Exp $      */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: ossaudio.c,v 1.37 2019/11/02 11:48:23 isaki Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.38 2019/11/03 11:13:45 isaki Exp $");
 
 /*
  * This is an OSS (Linux) sound API emulator.
@@ -57,6 +57,10 @@
 #define TO_OSSVOL(x)   (((x) * 100 + 127) / 255)
 #define FROM_OSSVOL(x) ((((x) > 100 ? 100 : (x)) * 255 + 50) / 100)
 
+#define GETPRINFO(info, name)  \
+       (((info)->mode == AUMODE_RECORD) \
+           ? (info)->record.name : (info)->play.name)
+
 static struct audiodevinfo *getdevinfo(int);
 
 static void setblocksize(int, struct audio_info *);
@@ -104,6 +108,8 @@
        char version[32] = "4.01";
        char license[16] = "NetBSD";
        u_int u;
+       u_int encoding;
+       u_int precision;
        int idat, idata;
        int retval;
        int i;
@@ -134,10 +140,7 @@
                retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
                if (retval < 0)
                        return retval;
-               if (tmpinfo.mode == AUMODE_RECORD)
-                       INTARG = tmpinfo.record.sample_rate;
-               else
-                       INTARG = tmpinfo.play.sample_rate;
+               INTARG = GETPRINFO(&tmpinfo, sample_rate);
                break;
        case SNDCTL_DSP_STEREO:
                AUDIO_INITINFO(&tmpinfo);
@@ -147,7 +150,7 @@
                retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
                if (retval < 0)
                        return retval;
-               INTARG = tmpinfo.play.channels - 1;
+               INTARG = GETPRINFO(&tmpinfo, channels) - 1;
                break;
        case SNDCTL_DSP_GETBLKSIZE:
                retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
@@ -246,7 +249,9 @@
                retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
                if (retval < 0)
                        return retval;
-               switch (tmpinfo.play.encoding) {
+               encoding = GETPRINFO(&tmpinfo, encoding);
+               precision = GETPRINFO(&tmpinfo, precision);
+               switch (encoding) {
                case AUDIO_ENCODING_ULAW:
                        idat = AFMT_MU_LAW;
                        break;
@@ -254,33 +259,33 @@
                        idat = AFMT_A_LAW;
                        break;
                case AUDIO_ENCODING_SLINEAR_LE:
-                       if (tmpinfo.play.precision == 32)
+                       if (precision == 32)
                                idat = AFMT_S32_LE;
-                       else if (tmpinfo.play.precision == 24)
+                       else if (precision == 24)
                                idat = AFMT_S24_LE;
-                       else if (tmpinfo.play.precision == 16)
+                       else if (precision == 16)
                                idat = AFMT_S16_LE;
                        else
                                idat = AFMT_S8;
                        break;
                case AUDIO_ENCODING_SLINEAR_BE:
-                       if (tmpinfo.play.precision == 32)
+                       if (precision == 32)
                                idat = AFMT_S32_BE;
-                       else if (tmpinfo.play.precision == 24)
+                       else if (precision == 24)
                                idat = AFMT_S24_BE;
-                       else if (tmpinfo.play.precision == 16)
+                       else if (precision == 16)
                                idat = AFMT_S16_BE;
                        else
                                idat = AFMT_S8;
                        break;
                case AUDIO_ENCODING_ULINEAR_LE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = AFMT_U16_LE;
                        else
                                idat = AFMT_U8;
                        break;
                case AUDIO_ENCODING_ULINEAR_BE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = AFMT_U16_BE;
                        else
                                idat = AFMT_U8;
@@ -306,7 +311,7 @@
                retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
                if (retval < 0)
                        return retval;
-               INTARG = tmpinfo.play.channels;
+               INTARG = GETPRINFO(&tmpinfo, channels);
                break;
        case SOUND_PCM_WRITE_FILTER:
        case SOUND_PCM_READ_FILTER:
diff -r 93e178038564 -r 76b862f49655 sys/compat/ossaudio/ossaudio.c
--- a/sys/compat/ossaudio/ossaudio.c    Sun Nov 03 10:09:04 2019 +0000
+++ b/sys/compat/ossaudio/ossaudio.c    Sun Nov 03 11:13:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $      */
+/*     $NetBSD: ossaudio.c,v 1.78 2019/11/03 11:13:46 isaki Exp $      */
 
 /*-
  * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.77 2019/11/02 11:56:34 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.78 2019/11/03 11:13:46 isaki Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -59,6 +59,10 @@
 #define TO_OSSVOL(x)   (((x) * 100 + 127) / 255)
 #define FROM_OSSVOL(x) ((((x) > 100 ? 100 : (x)) * 255 + 50) / 100)
 
+#define GETPRINFO(info, name)  \
+       (((info)->mode == AUMODE_RECORD) \
+           ? (info)->record.name : (info)->play.name)
+
 static struct audiodevinfo *getdevinfo(file_t *);
 static int opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, int opq);
 static int enum_to_ord(struct audiodevinfo *di, int enm);
@@ -177,6 +181,8 @@
        struct oss_count_info cntinfo;
        struct audio_encoding tmpenc;
        u_int u;
+       u_int encoding;
+       u_int precision;
        int idat, idata;
        int error = 0;
        int (*ioctlf)(file_t *, u_long, void *);
@@ -238,10 +244,7 @@
                         __func__, error));
                        goto out;
                }
-               if (tmpinfo.mode == AUMODE_RECORD)
-                       idat = tmpinfo.record.sample_rate;
-               else
-                       idat = tmpinfo.play.sample_rate;
+               idat = GETPRINFO(&tmpinfo, sample_rate);
                DPRINTF(("%s: SNDCTL_PCM_READ_RATE < %d\n", __func__, idat));
                error = copyout(&idat, SCARG(uap, data), sizeof idat);
                if (error) {
@@ -272,7 +275,7 @@
                             __func__, error));
                        goto out;
                }
-               idat = tmpinfo.play.channels - 1;
+               idat = GETPRINFO(&tmpinfo, channels) - 1;
                error = copyout(&idat, SCARG(uap, data), sizeof idat);
                if (error) {
                        DPRINTF(("%s: SNDCTL_DSP_STEREO %d = %d\n",
@@ -383,7 +386,9 @@
                             __func__, error));
                        goto out;
                }
-               switch (tmpinfo.play.encoding) {
+               encoding = GETPRINFO(&tmpinfo, encoding);
+               precision = GETPRINFO(&tmpinfo, precision);
+               switch (encoding) {
                case AUDIO_ENCODING_ULAW:
                        idat = OSS_AFMT_MU_LAW;
                        break;
@@ -391,25 +396,25 @@
                        idat = OSS_AFMT_A_LAW;
                        break;
                case AUDIO_ENCODING_SLINEAR_LE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = OSS_AFMT_S16_LE;
                        else
                                idat = OSS_AFMT_S8;
                        break;
                case AUDIO_ENCODING_SLINEAR_BE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = OSS_AFMT_S16_BE;
                        else
                                idat = OSS_AFMT_S8;
                        break;
                case AUDIO_ENCODING_ULINEAR_LE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = OSS_AFMT_U16_LE;
                        else
                                idat = OSS_AFMT_U8;
                        break;
                case AUDIO_ENCODING_ULINEAR_BE:
-                       if (tmpinfo.play.precision == 16)
+                       if (precision == 16)
                                idat = OSS_AFMT_U16_BE;
                        else
                                idat = OSS_AFMT_U8;
@@ -460,7 +465,7 @@
                             __func__, error));
                        goto out;
                }
-               idat = tmpinfo.play.channels;
+               idat = GETPRINFO(&tmpinfo, channels);
                DPRINTF(("%s: SOUND_PCM_READ_CHANNELS < %d\n", __func__, idat));
                error = copyout(&idat, SCARG(uap, data), sizeof idat);
                if (error) {



Home | Main Index | Thread Index | Old Index