This diff switches internal sample representation frem 16-bit to
24-bit fixed-point. Resampling is already 24-bit only, so there's
little point in keeping the current 16-bit code.

The default device precision doesn't change, i.e. we still request the
same 16-bit mode (and convert everything to 24-bit when needed), so
there's no risk of exposing driver bugs (yet).

If you've the 24-bit capable hardware, adding "-e s24" to sndiod_flags
will reduce the quantization noise, without the need for rebuilding
with -DADATA_BITS=24 anymore.

objections? OK?

Index: sndiod/dsp.h
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/dsp.h,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 dsp.h
--- sndiod/dsp.h        25 May 2021 08:06:12 -0000      1.10
+++ sndiod/dsp.h        21 Dec 2021 17:53:12 -0000
@@ -25,28 +25,14 @@
  * boundary is excluded. We represent them as signed fixed point numbers
  * of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
  */
-#ifndef ADATA_BITS
-#define ADATA_BITS                     16
-#endif
+#define ADATA_BITS                     24
 #define ADATA_LE                       (BYTE_ORDER == LITTLE_ENDIAN)
 #define ADATA_UNIT                     (1 << (ADATA_BITS - 1))
 
-#if ADATA_BITS == 16
-
-#define ADATA_MUL(x,y)         (((int)(x) * (int)(y)) >> (ADATA_BITS - 1))
-
-typedef short adata_t;
-
-#elif ADATA_BITS == 24
-
 #define ADATA_MUL(x,y)         \
        ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1)))
 
 typedef int adata_t;
-
-#else
-#error "only 16-bit and 24-bit precisions are supported"
-#endif
 
 /*
  * The FIR is sampled and stored in a table of fixed-point numbers
Index: sndiod/sndiod.8
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sndiod.8,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 sndiod.8
--- sndiod/sndiod.8     18 Dec 2021 21:41:49 -0000      1.12
+++ sndiod/sndiod.8     21 Dec 2021 17:53:13 -0000
@@ -564,11 +564,6 @@ $ sndiod -r 48000 -b 480 -z 240
 Resampling is low quality; down-sampling especially should be avoided
 when recording.
 .Pp
-Processing is done using 16-bit arithmetic,
-thus samples with more than 16 bits are rounded.
-16 bits (i.e. 97dB dynamic) are largely enough for most applications though.
-Processing precision can be increased to 24-bit at compilation time though.
-.Pp
 If
 .Fl a Ar off
 is used,
Index: sndiod/sndiod.c
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sndiod.c,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 sndiod.c
--- sndiod/sndiod.c     1 Nov 2021 14:43:25 -0000       1.47
+++ sndiod/sndiod.c     21 Dec 2021 17:53:13 -0000
@@ -85,6 +85,13 @@
 #define DEFAULT_BUFSZ  7680
 #endif
 
+/*
+ * default device precision
+ */
+#ifndef DEFAULT_BITS
+#define DEFAULT_BITS   16
+#endif
+
 void sigint(int);
 void sighup(int);
 void opt_ch(int *, int *);
@@ -486,7 +493,11 @@ main(int argc, char **argv)
        pmax = 1;
        rmin = 0;
        rmax = 1;
-       aparams_init(&par);
+       par.bits = DEFAULT_BITS;
+       par.bps = APARAMS_BPS(par.bits);
+       par.le = ADATA_LE;
+       par.sig = 1;
+       par.msb = 0;
        mode = MODE_PLAY | MODE_REC;
        dev_first = dev_next = NULL;
        port_first = port_next = NULL;
Index: aucat/aucat.1
===================================================================
RCS file: /cvs/src/usr.bin/aucat/aucat.1,v
retrieving revision 1.116
diff -u -p -u -p -r1.116 aucat.1
--- aucat/aucat.1       22 Apr 2020 05:37:00 -0000      1.116
+++ aucat/aucat.1       21 Dec 2021 17:53:13 -0000
@@ -88,7 +88,7 @@ Increase log verbosity.
 .It Fl e Ar enc
 Encoding of the audio file.
 The default is
-.Va s16 .
+.Va s24 .
 Encoding names use the following scheme: signedness
 .Po
 .Va s
Index: aucat/aucat.c
===================================================================
RCS file: /cvs/src/usr.bin/aucat/aucat.c,v
retrieving revision 1.177
diff -u -p -u -p -r1.177 aucat.c
--- aucat/aucat.c       12 Jan 2021 15:46:53 -0000      1.177
+++ aucat/aucat.c       21 Dec 2021 17:53:13 -0000
@@ -1393,7 +1393,11 @@ main(int argc, char **argv)
        rate = DEFAULT_RATE;
        cmin = 0;
        cmax = 1;
-       aparams_init(&par);
+       par.bits = ADATA_BITS;
+       par.bps = APARAMS_BPS(par.bits);
+       par.le = ADATA_LE;
+       par.sig = 1;
+       par.msb = 1;
        hdr = AFILE_HDR_AUTO;
        n_flag = 0;
        port = NULL;
Index: aucat/dsp.h
===================================================================
RCS file: /cvs/src/usr.bin/aucat/dsp.h,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 dsp.h
--- aucat/dsp.h 25 May 2021 08:06:12 -0000      1.8
+++ aucat/dsp.h 21 Dec 2021 17:53:13 -0000
@@ -25,28 +25,14 @@
  * boundary is excluded. We represent them as signed fixed point numbers
  * of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
  */
-#ifndef ADATA_BITS
-#define ADATA_BITS                     16
-#endif
+#define ADATA_BITS                     24
 #define ADATA_LE                       (BYTE_ORDER == LITTLE_ENDIAN)
 #define ADATA_UNIT                     (1 << (ADATA_BITS - 1))
 
-#if ADATA_BITS == 16
-
-#define ADATA_MUL(x,y)         (((int)(x) * (int)(y)) >> (ADATA_BITS - 1))
-
-typedef short adata_t;
-
-#elif ADATA_BITS == 24
-
 #define ADATA_MUL(x,y)         \
        ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1)))
 
 typedef int adata_t;
-
-#else
-#error "only 16-bit and 24-bit precisions are supported"
-#endif
 
 /*
  * The FIR is sampled and stored in a table of fixed-point numbers

Reply via email to