summaryrefslogtreecommitdiff
path: root/usr.bin/sndiod
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2022-03-07 08:58:34 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2022-03-07 08:58:34 +0000
commit76601a72e89f075c8b7979a2932d94c4f81e6d03 (patch)
tree318e59ec8e5bbf871fa225dd2e318b7c16fde9cb /usr.bin/sndiod
parent931f68501e1b909924fb6f8b5d5e25becad96454 (diff)
Switch internal sample representation to 24-bit fixed-point.
The default device precision doesn't change (yet), i.e. we still request the usual 16-bit mode, when available. Hardware supporting 24-bit samples only gets end-to-end 24-bit processing by default. ok kettenis
Diffstat (limited to 'usr.bin/sndiod')
-rw-r--r--usr.bin/sndiod/dsp.h18
-rw-r--r--usr.bin/sndiod/sndiod.89
-rw-r--r--usr.bin/sndiod/sndiod.c15
3 files changed, 17 insertions, 25 deletions
diff --git a/usr.bin/sndiod/dsp.h b/usr.bin/sndiod/dsp.h
index 539889c7f2e..39e97c63f26 100644
--- a/usr.bin/sndiod/dsp.h
+++ b/usr.bin/sndiod/dsp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsp.h,v 1.10 2021/05/25 08:06:12 ratchov Exp $ */
+/* $OpenBSD: dsp.h,v 1.11 2022/03/07 08:58:33 ratchov Exp $ */
/*
* Copyright (c) 2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -25,29 +25,15 @@
* 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
* with 23 fractional bits. For convenience, we use the same fixed-point
diff --git a/usr.bin/sndiod/sndiod.8 b/usr.bin/sndiod/sndiod.8
index b7a1d86f404..0a161dd04a4 100644
--- a/usr.bin/sndiod/sndiod.8
+++ b/usr.bin/sndiod/sndiod.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sndiod.8,v 1.15 2022/02/18 23:17:16 jsg Exp $
+.\" $OpenBSD: sndiod.8,v 1.16 2022/03/07 08:58:33 ratchov Exp $
.\"
.\" Copyright (c) 2006-2012 Alexandre Ratchov <alex@caoua.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 18 2022 $
+.Dd $Mdocdate: March 7 2022 $
.Dt SNDIOD 8
.Os
.Sh NAME
@@ -579,11 +579,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,
diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c
index 96088e33c04..b1719f1549d 100644
--- a/usr.bin/sndiod/sndiod.c
+++ b/usr.bin/sndiod/sndiod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndiod.c,v 1.47 2021/11/01 14:43:25 ratchov Exp $ */
+/* $OpenBSD: sndiod.c,v 1.48 2022/03/07 08:58:33 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -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;