From dae71a31376ac2f8fff6b5a1f86744dde7cb55ae Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Sat, 6 Nov 2010 20:25:43 +0000 Subject: make sio_onvol(3) return a integer exposing whether a volume knob is available for the stream. As we're at it, remove macros and functions that are neither used nor documented. --- regress/lib/libsndio/fd/Makefile | 5 +- regress/lib/libsndio/play/Makefile | 5 +- regress/lib/libsndio/rec/Makefile | 5 +- regress/lib/libsndio/tools.c | 138 +++++++++++++++++++++++++++++++++++++ regress/lib/libsndio/vol/Makefile | 5 +- regress/lib/libsndio/vol/vol.c | 3 +- 6 files changed, 152 insertions(+), 9 deletions(-) create mode 100644 regress/lib/libsndio/tools.c (limited to 'regress') diff --git a/regress/lib/libsndio/fd/Makefile b/regress/lib/libsndio/fd/Makefile index 431850655cd..ca36f9006ea 100644 --- a/regress/lib/libsndio/fd/Makefile +++ b/regress/lib/libsndio/fd/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $ +# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $ PROG= fd LDADD= -lsndio +SRCS = fd.c tools.c REGRESS_SKIP= - +.PATH: ${.CURDIR}/.. .include diff --git a/regress/lib/libsndio/play/Makefile b/regress/lib/libsndio/play/Makefile index 5e2f2020ea0..3ea4d99d94b 100644 --- a/regress/lib/libsndio/play/Makefile +++ b/regress/lib/libsndio/play/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $ +# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $ PROG= play LDADD= -lsndio +SRCS = play.c tools.c REGRESS_SKIP= - +.PATH: ${.CURDIR}/.. .include diff --git a/regress/lib/libsndio/rec/Makefile b/regress/lib/libsndio/rec/Makefile index 773e9789f26..2a5738e024e 100644 --- a/regress/lib/libsndio/rec/Makefile +++ b/regress/lib/libsndio/rec/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2008/10/27 00:26:33 ratchov Exp $ +# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $ PROG= rec LDADD= -lsndio +SRCS = rec.c tools.c REGRESS_SKIP= - +.PATH: ${.CURDIR}/.. .include diff --git a/regress/lib/libsndio/tools.c b/regress/lib/libsndio/tools.c new file mode 100644 index 00000000000..6d8cb3f62ff --- /dev/null +++ b/regress/lib/libsndio/tools.c @@ -0,0 +1,138 @@ +/* $OpenBSD: tools.c,v 1.1 2010/11/06 20:25:42 ratchov Exp $ */ +/* + * Copyright (c) 2008 Alexandre Ratchov + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include +#include "tools.h" + +/* + * Generate a string corresponding to the encoding in par, + * return the length of the resulting string + */ +int +sio_enctostr(struct sio_par *par, char *ostr) +{ + char *p = ostr; + + *p++ = par->sig ? 's' : 'u'; + if (par->bits > 9) + *p++ = '0' + par->bits / 10; + *p++ = '0' + par->bits % 10; + if (par->bps > 1) { + *p++ = par->le ? 'l' : 'b'; + *p++ = 'e'; + if (par->bps != SIO_BPS(par->bits) || + par->bits < par->bps * 8) { + *p++ = par->bps + '0'; + if (par->bits < par->bps * 8) { + *p++ = par->msb ? 'm' : 'l'; + *p++ = 's'; + *p++ = 'b'; + } + } + } + *p++ = '\0'; + return p - ostr - 1; +} + +/* + * Parse an encoding string, examples: s8, u8, s16, s16le, s24be ... + * Return the number of bytes consumed + */ +int +sio_strtoenc(struct sio_par *par, char *istr) +{ + char *p = istr; + int i, sig, bits, le, bps, msb; + +#define IS_SEP(c) \ + (((c) < 'a' || (c) > 'z') && \ + ((c) < 'A' || (c) > 'Z') && \ + ((c) < '0' || (c) > '9')) + + /* + * get signedness + */ + if (*p == 's') { + sig = 1; + } else if (*p == 'u') { + sig = 0; + } else + return 0; + p++; + + /* + * get number of bits per sample + */ + bits = 0; + for (i = 0; i < 2; i++) { + if (*p < '0' || *p > '9') + break; + bits = (bits * 10) + *p - '0'; + p++; + } + if (bits < 1 || bits > 32) + return 0; + bps = SIO_BPS(bits); + le = SIO_LE_NATIVE; + msb = 1; + + /* + * get (optional) endianness + */ + if (p[0] == 'l' && p[1] == 'e') { + le = 1; + p += 2; + } else if (p[0] == 'b' && p[1] == 'e') { + le = 0; + p += 2; + } else if (IS_SEP(*p)) { + goto done; + } else + return 0; + + /* + * get (optional) number of bytes + */ + if (*p >= '1' && *p <= '4') { + bps = *p - '0'; + if (bps * 8 < bits) + return 0; + p++; + + /* + * get (optional) alignment + */ + if (p[0] == 'm' && p[1] == 's' && p[2] == 'b') { + msb = 1; + p += 3; + } else if (p[0] == 'l' && p[1] == 's' && p[2] == 'b') { + msb = 0; + p += 3; + } else if (IS_SEP(*p)) { + goto done; + } else + return 0; + } else if (!IS_SEP(*p)) + return 0; + +done: + par->msb = msb; + par->sig = sig; + par->bits = bits; + par->bps = bps; + par->le = le; + return p - istr; +} diff --git a/regress/lib/libsndio/vol/Makefile b/regress/lib/libsndio/vol/Makefile index 7e1f32bec17..06bd08fd561 100644 --- a/regress/lib/libsndio/vol/Makefile +++ b/regress/lib/libsndio/vol/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2008/11/11 19:39:35 ratchov Exp $ +# $OpenBSD: Makefile,v 1.2 2010/11/06 20:25:42 ratchov Exp $ PROG= vol LDADD= -lsndio +SRCS = vol.c tools.c REGRESS_SKIP= - +.PATH: ${.CURDIR}/.. .include diff --git a/regress/lib/libsndio/vol/vol.c b/regress/lib/libsndio/vol/vol.c index 2ee08e35c7a..8173af547b6 100644 --- a/regress/lib/libsndio/vol/vol.c +++ b/regress/lib/libsndio/vol/vol.c @@ -103,7 +103,8 @@ main(int argc, char **argv) { fprintf(stderr, "sio_setpar() failed\n"); exit(1); } - sio_onvol(hdl, onvol, NULL); + if (!sio_onvol(hdl, onvol, NULL)) + fprintf(stderr, "warning: no volume knob on this device\n"); fprintf(stderr, "use ``+'' and ``-'' to adjust the volume\n"); if (!sio_start(hdl)) { fprintf(stderr, "sio_start() failed\n"); -- cgit v1.2.3