diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2016-09-06 04:35:04 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2016-09-06 04:35:04 +0000 |
commit | 5a95baaf675f02cc608dbab1f9e7b21a2e567adc (patch) | |
tree | e3a09dd12404e1e520cb47fee1d688e5f38581a5 | |
parent | 1bfbb1341f4733af2fc04e15e80077f779744a4b (diff) |
remove test programs for the audio driver, as we've better
converage with base tools and programs in regress/lib/libsndio
ok deraadt
-rw-r--r-- | regress/sys/dev/Makefile | 3 | ||||
-rw-r--r-- | regress/sys/dev/audio/Makefile | 13 | ||||
-rw-r--r-- | regress/sys/dev/audio/adpcm.c | 259 | ||||
-rw-r--r-- | regress/sys/dev/audio/adpcm.h | 21 | ||||
-rw-r--r-- | regress/sys/dev/audio/autest.1 | 143 | ||||
-rw-r--r-- | regress/sys/dev/audio/autest.c | 813 | ||||
-rw-r--r-- | regress/sys/dev/audio/law.c | 286 | ||||
-rw-r--r-- | regress/sys/dev/audio/law.h | 33 | ||||
-rw-r--r-- | regress/sys/dev/audio_info/Makefile | 11 | ||||
-rw-r--r-- | regress/sys/dev/audio_info/audiotest_gsinfo.1 | 119 | ||||
-rw-r--r-- | regress/sys/dev/audio_info/audiotest_gsinfo.c | 215 | ||||
-rw-r--r-- | regress/sys/dev/audio_rw/Makefile | 122 | ||||
-rw-r--r-- | regress/sys/dev/audio_rw/audiotest_rw.1 | 256 | ||||
-rw-r--r-- | regress/sys/dev/audio_rw/audiotest_rw.c | 666 |
14 files changed, 1 insertions, 2959 deletions
diff --git a/regress/sys/dev/Makefile b/regress/sys/dev/Makefile index d84da9c709e..9ae0ea16109 100644 --- a/regress/sys/dev/Makefile +++ b/regress/sys/dev/Makefile @@ -1,6 +1,5 @@ -# $OpenBSD: Makefile,v 1.3 2005/12/07 01:43:39 pedro Exp $ +# $OpenBSD: Makefile,v 1.4 2016/09/06 04:35:03 ratchov Exp $ -SUBDIR+= audio SUBDIR+= fdesc .include <bsd.subdir.mk> diff --git a/regress/sys/dev/audio/Makefile b/regress/sys/dev/audio/Makefile deleted file mode 100644 index b045b2c9414..00000000000 --- a/regress/sys/dev/audio/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2004/07/09 19:48:02 david Exp $ - -PROG=autest -SRCS=autest.c adpcm.c law.c -CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -MAN1=autest.1 -LDADD=-lm - -.ifndef DO_AUTEST -REGRESS_SKIP= -.endif - -.include <bsd.regress.mk> diff --git a/regress/sys/dev/audio/adpcm.c b/regress/sys/dev/audio/adpcm.c deleted file mode 100644 index 00cfa8947bc..00000000000 --- a/regress/sys/dev/audio/adpcm.c +++ /dev/null @@ -1,259 +0,0 @@ -/* $OpenBSD: adpcm.c,v 1.2 2003/03/19 03:35:57 david Exp $ */ - -/*********************************************************** -Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The -Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, 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. - -******************************************************************/ - -/* -** Intel/DVI ADPCM coder/decoder. -** -** The algorithm for this coder was taken from the IMA Compatibility Project -** proceedings, Vol 2, Number 2; May 1992. -** -** Version 1.2, 18-Dec-92. -** -** Change log: -** - Fixed a stupid bug, where the delta was computed as -** stepsize*code/4 in stead of stepsize*(code+0.5)/4. -** - There was an off-by-one error causing it to pick -** an incorrect delta once in a blue moon. -** - The NODIVMUL define has been removed. Computations are now always done -** using shifts, adds and subtracts. It turned out that, because the standard -** is defined using shift/add/subtract, you needed bits of fixup code -** (because the div/mul simulation using shift/add/sub made some rounding -** errors that real div/mul don't make) and all together the resultant code -** ran slower than just using the shifts all the time. -** - Changed some of the variable names to be more meaningful. -*/ - -#include <sys/types.h> - -#include "adpcm.h" -#include <stdio.h> /*DBG*/ - -#ifndef __STDC__ -#define signed -#endif - -/* Intel ADPCM step variation table */ -static int indexTable[16] = { - -1, -1, -1, -1, 2, 4, 6, 8, - -1, -1, -1, -1, 2, 4, 6, 8, -}; - -static int stepsizeTable[89] = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, - 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, - 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, - 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, - 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, - 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, - 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, - 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, - 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 -}; - -void -adpcm_coder(indata, outdata, len, state) - int16_t indata[]; - char outdata[]; - int len; - struct adpcm_state *state; -{ - int16_t *inp; /* Input buffer pointer */ - signed char *outp; /* output buffer pointer */ - int val; /* Current input sample value */ - int sign; /* Current adpcm sign bit */ - int delta; /* Current adpcm output value */ - int diff; /* Difference between val and valprev */ - int step; /* Stepsize */ - int valpred; /* Predicted output value */ - int vpdiff; /* Current change to valpred */ - int index; /* Current step change index */ - int outputbuffer; /* place to keep previous 4-bit value */ - int bufferstep; /* toggle between outputbuffer/output */ - - outputbuffer = 0; /* XXX gcc */ - - outp = (signed char *)outdata; - inp = indata; - - valpred = state->valprev; - index = state->index; - step = stepsizeTable[index]; - - bufferstep = 1; - - for ( ; len > 0 ; len-- ) { - val = *inp++; - - /* Step 1 - compute difference with previous value */ - diff = val - valpred; - sign = (diff < 0) ? 8 : 0; - if ( sign ) diff = (-diff); - - /* Step 2 - Divide and clamp */ - /* Note: - ** This code *approximately* computes: - ** delta = diff*4/step; - ** vpdiff = (delta+0.5)*step/4; - ** but in shift step bits are dropped. The net result of this is - ** that even if you have fast mul/div hardware you cannot put it to - ** good use since the fixup would be too expensive. - */ - delta = 0; - vpdiff = (step >> 3); - - if ( diff >= step ) { - delta = 4; - diff -= step; - vpdiff += step; - } - step >>= 1; - if ( diff >= step ) { - delta |= 2; - diff -= step; - vpdiff += step; - } - step >>= 1; - if ( diff >= step ) { - delta |= 1; - vpdiff += step; - } - - /* Step 3 - Update previous value */ - if ( sign ) - valpred -= vpdiff; - else - valpred += vpdiff; - - /* Step 4 - Clamp previous value to 16 bits */ - if ( valpred > 32767 ) - valpred = 32767; - else if ( valpred < -32768 ) - valpred = -32768; - - /* Step 5 - Assemble value, update index and step values */ - delta |= sign; - - index += indexTable[delta]; - if ( index < 0 ) index = 0; - if ( index > 88 ) index = 88; - step = stepsizeTable[index]; - - /* Step 6 - Output value */ - if ( bufferstep ) { - outputbuffer = (delta << 4) & 0xf0; - } else { - *outp++ = (delta & 0x0f) | outputbuffer; - } - bufferstep = !bufferstep; - } - - /* Output last step, if needed */ - if ( !bufferstep ) - *outp++ = outputbuffer; - - state->valprev = valpred; - state->index = index; -} - -void -adpcm_decoder(indata, outdata, len, state) - char indata[]; - int16_t outdata[]; - int len; - struct adpcm_state *state; -{ - signed char *inp; /* Input buffer pointer */ - int16_t *outp; /* output buffer pointer */ - int sign; /* Current adpcm sign bit */ - int delta; /* Current adpcm output value */ - int step; /* Stepsize */ - int valpred; /* Predicted value */ - int vpdiff; /* Current change to valpred */ - int index; /* Current step change index */ - int inputbuffer; /* place to keep next 4-bit value */ - int bufferstep; /* toggle between inputbuffer/input */ - - inputbuffer = 0; /* XXX gcc */ - outp = outdata; - inp = (signed char *)indata; - - valpred = state->valprev; - index = state->index; - step = stepsizeTable[index]; - - bufferstep = 0; - - for ( ; len > 0 ; len-- ) { - - /* Step 1 - get the delta value */ - if ( bufferstep ) { - delta = inputbuffer & 0xf; - } else { - inputbuffer = *inp++; - delta = (inputbuffer >> 4) & 0xf; - } - bufferstep = !bufferstep; - - /* Step 2 - Find new index value (for later) */ - index += indexTable[delta]; - if ( index < 0 ) index = 0; - if ( index > 88 ) index = 88; - - /* Step 3 - Separate sign and magnitude */ - sign = delta & 8; - delta = delta & 7; - - /* Step 4 - Compute difference and new predicted value */ - /* - ** Computes 'vpdiff = (delta+0.5)*step/4', but see comment - ** in adpcm_coder. - */ - vpdiff = step >> 3; - if ( delta & 4 ) vpdiff += step; - if ( delta & 2 ) vpdiff += step>>1; - if ( delta & 1 ) vpdiff += step>>2; - - if ( sign ) - valpred -= vpdiff; - else - valpred += vpdiff; - - /* Step 5 - clamp output value */ - if ( valpred > 32767 ) - valpred = 32767; - else if ( valpred < -32768 ) - valpred = -32768; - - /* Step 6 - Update step value */ - step = stepsizeTable[index]; - - /* Step 7 - Output value */ - *outp++ = valpred; - } - - state->valprev = valpred; - state->index = index; -} diff --git a/regress/sys/dev/audio/adpcm.h b/regress/sys/dev/audio/adpcm.h deleted file mode 100644 index ebe7704704a..00000000000 --- a/regress/sys/dev/audio/adpcm.h +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: adpcm.h,v 1.1 2003/02/01 17:58:18 jason Exp $ */ - -/* -** adpcm.h - include file for adpcm coder. -** -** Version 1.0, 7-Jul-92. -*/ - -struct adpcm_state { - int16_t valprev; /* Previous output value */ - char index; /* Index into stepsize table */ -}; - -#ifdef __STDC__ -#define ARGS(x) x -#else -#define ARGS(x) () -#endif - -void adpcm_coder ARGS((int16_t [], char [], int, struct adpcm_state *)); -void adpcm_decoder ARGS((char [], int16_t [], int, struct adpcm_state *)); diff --git a/regress/sys/dev/audio/autest.1 b/regress/sys/dev/audio/autest.1 deleted file mode 100644 index 1c5c30faab4..00000000000 --- a/regress/sys/dev/audio/autest.1 +++ /dev/null @@ -1,143 +0,0 @@ -.\" $OpenBSD: autest.1,v 1.10 2007/05/31 19:19:42 jmc Exp $ -.\" -.\" Copyright (c) 2002 Jason L. Wright (jason@thought.net) -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt AUTEST 1 -.Os -.Sh NAME -.Nm autest -.Nd test audio encoding output -.Sh SYNOPSIS -.Nm autest -.Op Fl f Ar device -.Op Fl r Ar rate -.Op Fl t Ar tone -.Sh DESCRIPTION -The -.Nm -utility opens an -.Xr audio 4 -device and iterates through all of the encodings supported by the device, -playing a tone in the proper format. -The tone should sound identical in each of the formats. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl f Ar device -Specify the audio -.Ar device -to open. -If no device is specified, -.Pa /dev/sound -is used. -.It Fl r Ar rate -Specify the audio -.Ar rate -to test. -It will request the audio subsystem to play that Hz; -however the audio device may return a different speed. -This can be useful to test different speeds, e.g. 8000, 44100, 48000. -.It Fl t Ar tone -Specify the tone to be played (default 440Hz). -.El -.Pp -.Nm -can produce tones in any of the following formats and will skip other -formats if supported by the device: -.Pp -.Bl -tag -width "ulinear_leXX" -offset indent -compact -.It Cm mu-law -8-bit mu-law companded -.It Cm A-law -8-bit A-law companded -.\" .It Cm adpcm -.\" 4 bit adaptive differential pulse code modulation -.It Cm ulinear -8-bit unsigned linear -.It Cm ulinear_le -16-bit unsigned linear little endian -.It Cm ulinear_be -16-bit unsigned linear big endian -.It Cm slinear -8-bit signed linear (twos complement) -.It Cm slinear_le -16-bit signed linear little endian (twos complement) -.It Cm slinear_be -16-bit signed linear big endian (twos complement) -.El -.Sh OUTPUT -Interpreting the output of -.Nm -is a little tricky. -The output below is from an -.Xr auich 4 : -.Bd -literal -ulinear:8...mono(s 44100 c 45167 e 2.4%)...stereo(s 44100 c 45162 e 2.4%) -mulaw:8*...mono(s 44100 c 45166 e 2.4%)...stereo(s 44100 c 45157 e 2.3%) -alaw:8*...mono[Invalid argument]...stereo[Invalid argument] -slinear:8*...mono(s 44100 c 45171 e 2.4%)...stereo(s 44100 c 45170 e 2.4%) -slinear_le:16...mono(s 44100 c 45171 e 2.4%)...stereo(s 44100 c 45170 e 2.4%) -ulinear_le:16*...mono(s 44100 c 45167 e 2.4%)...stereo(s 44100 c 45168 e 2.4%) -slinear_be:16*...mono(s 44100 c 45169 e 2.4%)...stereo(s 44100 c 45167 e 2.4%) -ulinear_be:16*...mono(s 44100 c 45167 e 2.4%)...stereo(s 44100 c 45160 e 2.3%) -.Ed -.Pp -.Nm -loops through each mode claimed to be supported by the chip (emulated or not). -For each emulated mode, an asterisk is appended to the mode name. -If the tone sounds different from all the other tones for the device, -it is likely that either the emulation is wrong, or the mode is not -set on the device correctly. -.Pp -Also, for the mono and stereo versions of each mode, -.Nm -prints the claimed sample rate, -.So s Bo rate Bc Sc , -computed sample rate, -.So c Bo rate Bc Sc , -and the percent error between them, -.So e Bo percent Bc Sc . -If the percent error is high (greater than 10 percent or so), -either the sample rate is not being correctly returned by -the device, or it is not being set correctly on the device. -.Pp -Interestingly, when -.Nm -requests -.Sq alaw -encoding, the device driver returns -.So Invalid argument Sc . -This indicates that the device includes -.Sq alaw -in its mode enumeration, but does not support it for playback. -This is very likely a bug in the driver. -.Sh SEE ALSO -.Xr audio 4 -.Sh BUGS -There is partial support for adaptive differential pulse code modulation -(ADPCM) -but it is not enabled by default -since it does not appear to be correct. diff --git a/regress/sys/dev/audio/autest.c b/regress/sys/dev/audio/autest.c deleted file mode 100644 index a8ce56ceee0..00000000000 --- a/regress/sys/dev/audio/autest.c +++ /dev/null @@ -1,813 +0,0 @@ -/* $OpenBSD: autest.c,v 1.13 2016/08/27 04:32:44 guenther Exp $ */ - -/* - * Copyright (c) 2002 Jason L. Wright (jason@thought.net) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/audioio.h> -#include <sys/time.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -/* XXX ADPCM is currently pretty broken... diagnosis and fix welcome */ -#undef USE_ADPCM - -#include "adpcm.h" -#include "law.h" - -struct ausrate { - struct timeval tv_begin; - struct timeval tv_end; - u_int r_rate; /* requested rate */ - u_int s_rate; /* rate from audio layer */ - u_int c_rate; /* computed rate */ - int bps; /* bytes per sample */ - int bytes; /* number of bytes played */ - float err; -}; - -int main(int, char **); -void check_encoding(int, audio_encoding_t *, int); -void check_encoding_mono(int, audio_encoding_t *, int); -void check_encoding_stereo(int, audio_encoding_t *, int); -void enc_ulaw_8(int, audio_encoding_t *, int, int); -void enc_alaw_8(int, audio_encoding_t *, int, int); -void enc_ulinear_8(int, audio_encoding_t *, int, int); -void enc_ulinear_16(int, audio_encoding_t *, int, int, int); -void enc_slinear_8(int, audio_encoding_t *, int, int); -void enc_slinear_16(int, audio_encoding_t *, int, int, int); -void enc_adpcm_8(int, audio_encoding_t *, int, int); -void audio_wait(int); -void check_srate(struct ausrate *); -void mark_time(struct timeval *); -int get_int(const char *, int *); -int get_double(const char *, double *); - -#define PLAYFREQ 440.0 -#define PLAYSECS 2 -double playfreq = PLAYFREQ; - -#define DEFAULT_DEV "/dev/sound" - -int -get_double(const char *buf, double *d) -{ - char *ep; - long dd; - - errno = 0; - dd = strtod(buf, &ep); - if (buf[0] == '\0' || *ep != '\0') - return (-1); - if (errno == ERANGE && (dd == -HUGE_VAL || dd == HUGE_VAL)) - return (-1); - *d = dd; - return (0); -} - -int -get_int(const char *buf, int *i) -{ - char *ep; - long lv; - - errno = 0; - lv = strtol(buf, &ep, 10); - if (buf[0] == '\0' || *ep != '\0') - return (-1); - if (errno == ERANGE && (lv == LONG_MAX || lv == LONG_MIN)) - return (-1); - if (lv < INT_MIN || lv > INT_MAX) - return (-1); - *i = lv; - return (0); -} - -int -main(int argc, char **argv) -{ - audio_info_t ainfo; - char *fname = NULL; - int fd, i, c; - int rate = 8000; - - while ((c = getopt(argc, argv, "f:r:t:")) != -1) { - switch (c) { - case 'f': - fname = optarg; - break; - case 'r': - if (get_int(optarg, &rate) || rate <= 0) { - fprintf(stderr, "%s bad rate %s\n", - argv[0], optarg); - return (1); - } - break; - case 't': - if (get_double(optarg, &playfreq) || playfreq <= 0.0) { - fprintf(stderr, "%s bad freq %s\n", - argv[0], optarg); - return (1); - } - break; - case '?': - default: - fprintf(stderr, "%s [-f device]\n", argv[0]); - return (1); - } - } - - if (fname == NULL) - fname = DEFAULT_DEV; - - fd = open(fname, O_RDWR, 0); - if (fd == -1) - err(1, "open"); - - - if (ioctl(fd, AUDIO_GETINFO, &ainfo) == -1) - err(1, "%s: audio_getinfo", fname); - - for (i = 0; ; i++) { - audio_encoding_t enc; - - enc.index = i; - if (ioctl(fd, AUDIO_GETENC, &enc) == -1) - break; - check_encoding(fd, &enc, rate); - } - close(fd); - - return (0); -} - -void -check_srate(struct ausrate *rt) -{ - struct timeval t; - float tm, b, r, err; - - timersub(&rt->tv_end, &rt->tv_begin, &t); - tm = (float)t.tv_sec + ((float)t.tv_usec / 1000000.0); - b = (float)rt->bytes / (float)rt->bps; - r = b / tm; - - err = fabs((float)rt->s_rate - r); - err /= r * 0.01; - rt->err = err; - rt->c_rate = rintf(r); - printf("(s %u c %u e %3.1f%%)", - rt->s_rate, rt->c_rate, rt->err); -} - -void -check_encoding(int fd, audio_encoding_t *enc, int rate) -{ - printf("%s:%d%s", - enc->name, - enc->precision, - (enc->flags & AUDIO_ENCODINGFLAG_EMULATED) ? "*" : ""); - fflush(stdout); - check_encoding_mono(fd, enc, rate); - check_encoding_stereo(fd, enc, rate); - printf("\n"); -} - -void -mark_time(struct timeval *tv) -{ - if (gettimeofday(tv, NULL) == -1) - err(1, "gettimeofday"); -} - -void -check_encoding_mono(int fd, audio_encoding_t *enc, int rate) -{ - int skipped = 0; - - printf("...mono"); - fflush(stdout); - - if (enc->precision == 8) { - switch (enc->encoding) { - case AUDIO_ENCODING_ULAW: - enc_ulaw_8(fd, enc, 1, rate); - break; - case AUDIO_ENCODING_ALAW: - enc_alaw_8(fd, enc, 1, rate); - break; - case AUDIO_ENCODING_ULINEAR: - case AUDIO_ENCODING_ULINEAR_LE: - case AUDIO_ENCODING_ULINEAR_BE: - enc_ulinear_8(fd, enc, 1, rate); - break; - case AUDIO_ENCODING_SLINEAR: - case AUDIO_ENCODING_SLINEAR_LE: - case AUDIO_ENCODING_SLINEAR_BE: - enc_slinear_8(fd, enc, 1, rate); - break; - case AUDIO_ENCODING_ADPCM: - enc_adpcm_8(fd, enc, 1, rate); - break; - default: - skipped = 1; - } - } - - if (enc->precision == 16) { - switch (enc->encoding) { - case AUDIO_ENCODING_ULINEAR_LE: - enc_ulinear_16(fd, enc, 1, LITTLE_ENDIAN, rate); - break; - case AUDIO_ENCODING_ULINEAR_BE: - enc_ulinear_16(fd, enc, 1, BIG_ENDIAN, rate); - break; - case AUDIO_ENCODING_SLINEAR_LE: - enc_slinear_16(fd, enc, 1, LITTLE_ENDIAN, rate); - break; - case AUDIO_ENCODING_SLINEAR_BE: - enc_slinear_16(fd, enc, 1, BIG_ENDIAN, rate); - break; - default: - skipped = 1; - } - } - - if (skipped) - printf("[skip]"); -} - -void -check_encoding_stereo(int fd, audio_encoding_t *enc, int rate) -{ - int skipped = 0; - - printf("...stereo"); - fflush(stdout); - - if (enc->precision == 8) { - switch (enc->encoding) { - case AUDIO_ENCODING_ULAW: - enc_ulaw_8(fd, enc, 2, rate); - break; - case AUDIO_ENCODING_ALAW: - enc_alaw_8(fd, enc, 2, rate); - break; - case AUDIO_ENCODING_ULINEAR: - case AUDIO_ENCODING_ULINEAR_LE: - case AUDIO_ENCODING_ULINEAR_BE: - enc_ulinear_8(fd, enc, 2, rate); - break; - case AUDIO_ENCODING_SLINEAR: - case AUDIO_ENCODING_SLINEAR_LE: - case AUDIO_ENCODING_SLINEAR_BE: - enc_slinear_8(fd, enc, 2, rate); - break; - case AUDIO_ENCODING_ADPCM: - enc_adpcm_8(fd, enc, 2, rate); - break; - default: - skipped = 1; - } - } - - if (enc->precision == 16) { - switch (enc->encoding) { - case AUDIO_ENCODING_ULINEAR_LE: - enc_ulinear_16(fd, enc, 2, LITTLE_ENDIAN, rate); - break; - case AUDIO_ENCODING_ULINEAR_BE: - enc_ulinear_16(fd, enc, 2, BIG_ENDIAN, rate); - break; - case AUDIO_ENCODING_SLINEAR_LE: - enc_slinear_16(fd, enc, 2, LITTLE_ENDIAN, rate); - break; - case AUDIO_ENCODING_SLINEAR_BE: - enc_slinear_16(fd, enc, 2, BIG_ENDIAN, rate); - break; - default: - skipped = 1; - } - } - - if (skipped) - printf("[skip]"); -} - -void -enc_ulinear_8(int fd, audio_encoding_t *enc, int chans, int rate) -{ - audio_info_t inf; - struct ausrate rt; - u_int8_t *samples = NULL, *p; - int i, j; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 1 * chans; - rt.bytes = inf.play.sample_rate * chans * PLAYSECS; - - samples = (u_int8_t *)malloc(inf.play.sample_rate * chans); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0, p = samples; i < inf.play.sample_rate; i++) { - float d; - u_int8_t v; - - d = 127.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - d = rintf(d + 127.0); - v = d; - - for (j = 0; j < chans; j++) { - *p = v; - p++; - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) - write(fd, samples, inf.play.sample_rate * chans); - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - -out: - if (samples != NULL) - free(samples); -} - -void -enc_slinear_8(int fd, audio_encoding_t *enc, int chans, int rate) -{ - audio_info_t inf; - struct ausrate rt; - int8_t *samples = NULL, *p; - int i, j; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 1 * chans; - rt.bytes = inf.play.sample_rate * chans * PLAYSECS; - - samples = (int8_t *)malloc(inf.play.sample_rate * chans); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0, p = samples; i < inf.play.sample_rate; i++) { - float d; - int8_t v; - - d = 127.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - d = rintf(d); - v = d; - - for (j = 0; j < chans; j++) { - *p = v; - p++; - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) - write(fd, samples, inf.play.sample_rate * chans); - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - -out: - if (samples != NULL) - free(samples); -} - -void -enc_slinear_16(int fd, audio_encoding_t *enc, int chans, int order, int rate) -{ - audio_info_t inf; - struct ausrate rt; - u_int8_t *samples = NULL, *p; - int i, j; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 2 * chans; - rt.bytes = 2 * inf.play.sample_rate * chans * PLAYSECS; - - samples = (int8_t *)malloc(inf.play.sample_rate * chans * 2); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0, p = samples; i < inf.play.sample_rate; i++) { - float d; - int16_t v; - - d = 32767.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - d = rintf(d); - v = d; - - for (j = 0; j < chans; j++) { - if (order == LITTLE_ENDIAN) { - *p = (v & 0x00ff) >> 0; - p++; - *p = (v & 0xff00) >> 8; - p++; - } else { - *p = (v & 0xff00) >> 8; - p++; - *p = (v & 0x00ff) >> 0; - p++; - } - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) - write(fd, samples, inf.play.sample_rate * chans * 2); - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - -out: - if (samples != NULL) - free(samples); -} - -void -enc_ulinear_16(int fd, audio_encoding_t *enc, int chans, int order, int rate) -{ - audio_info_t inf; - struct ausrate rt; - u_int8_t *samples = NULL, *p; - int i, j; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - - samples = (u_int8_t *)malloc(inf.play.sample_rate * chans * 2); - if (samples == NULL) { - warn("malloc"); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 2 * chans; - rt.bytes = 2 * inf.play.sample_rate * chans * PLAYSECS; - - for (i = 0, p = samples; i < inf.play.sample_rate; i++) { - float d; - u_int16_t v; - - d = 32767.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - d = rintf(d + 32767.0); - v = d; - - for (j = 0; j < chans; j++) { - if (order == LITTLE_ENDIAN) { - *p = (v >> 0) & 0xff; - p++; - *p = (v >> 8) & 0xff; - p++; - } else { - *p = (v >> 8) & 0xff; - p++; - *p = (v >> 0) & 0xff; - p++; - } - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) - write(fd, samples, inf.play.sample_rate * chans * 2); - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - -out: - if (samples != NULL) - free(samples); -} - -void -enc_adpcm_8(int fd, audio_encoding_t *enc, int chans, int rate) -{ - audio_info_t inf; - struct adpcm_state adsts; - int16_t *samples = NULL; - int i, j; - char *outbuf = NULL, *sbuf = NULL, *p; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - - bzero(&adsts, sizeof(adsts)); - - samples = (int16_t *)malloc(inf.play.sample_rate * sizeof(*samples)); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - sbuf = (char *)malloc(inf.play.sample_rate / 2); - if (sbuf == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0; i < inf.play.sample_rate; i++) { - float d; - - d = 32767.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - samples[i] = rintf(d); - } - - outbuf = (char *)malloc((inf.play.sample_rate / 2) * chans); - if (outbuf == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0; i < PLAYSECS; i++) { - adpcm_coder(samples, sbuf, inf.play.sample_rate, &adsts); - - for (i = 0, p = outbuf; i < inf.play.sample_rate / 2; i++) { - for (j = 0; j < chans; j++, p++) { - *p = sbuf[i]; - } - } - - write(fd, outbuf, (inf.play.sample_rate / 2) * chans); - } - audio_wait(fd); - -out: - if (samples != NULL) - free(samples); - if (outbuf != NULL) - free(outbuf); - if (sbuf != NULL) - free(sbuf); -} - -void -enc_ulaw_8(int fd, audio_encoding_t *enc, int chans, int rate) -{ - audio_info_t inf; - int16_t *samples = NULL; - int i, j; - u_int8_t *outbuf = NULL, *p; - struct ausrate rt; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 1 * chans; - rt.bytes = inf.play.sample_rate * chans * PLAYSECS; - - samples = (int16_t *)calloc(inf.play.sample_rate, sizeof(*samples)); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - outbuf = (u_int8_t *)malloc(inf.play.sample_rate * chans); - if (outbuf == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0; i < inf.play.sample_rate; i++) { - float x; - - x = 32765.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - samples[i] = x; - } - - for (i = 0, p = outbuf; i < inf.play.sample_rate; i++) { - for (j = 0; j < chans; j++) { - *p = linear2ulaw(samples[i]); - p++; - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) { - write(fd, outbuf, inf.play.sample_rate * chans); - } - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - -out: - if (samples != NULL) - free(samples); - if (outbuf != NULL) - free(outbuf); -} - -void -enc_alaw_8(int fd, audio_encoding_t *enc, int chans, int rate) -{ - audio_info_t inf; - struct ausrate rt; - int16_t *samples = NULL; - int i, j; - u_int8_t *outbuf = NULL, *p; - - AUDIO_INITINFO(&inf); - inf.play.precision = enc->precision; - inf.play.encoding = enc->encoding; - inf.play.channels = chans; - inf.play.sample_rate = rate;; - - if (ioctl(fd, AUDIO_SETINFO, &inf) == -1) { - printf("[%s]", strerror(errno)); - goto out; - } - - if (ioctl(fd, AUDIO_GETINFO, &inf) == -1) { - printf("[getinfo: %s]", strerror(errno)); - goto out; - } - rt.r_rate = inf.play.sample_rate; - rt.s_rate = inf.play.sample_rate; - rt.bps = 1* chans; - rt.bytes = inf.play.sample_rate * chans * PLAYSECS; - - samples = (int16_t *)calloc(inf.play.sample_rate, sizeof(*samples)); - if (samples == NULL) { - warn("malloc"); - goto out; - } - - outbuf = (u_int8_t *)malloc(inf.play.sample_rate * chans); - if (outbuf == NULL) { - warn("malloc"); - goto out; - } - - for (i = 0; i < inf.play.sample_rate; i++) { - float x; - - x = 32767.0 * sinf(((float)i / (float)inf.play.sample_rate) * - (2 * M_PI * playfreq)); - samples[i] = x; - } - - for (i = 0, p = outbuf; i < inf.play.sample_rate; i++) { - for (j = 0; j < chans; j++) { - *p = linear2alaw(samples[i]); - p++; - } - } - - mark_time(&rt.tv_begin); - for (i = 0; i < PLAYSECS; i++) { - write(fd, outbuf, inf.play.sample_rate * chans); - } - audio_wait(fd); - mark_time(&rt.tv_end); - check_srate(&rt); - - -out: - if (samples != NULL) - free(samples); - if (outbuf != NULL) - free(outbuf); -} - -void -audio_wait(int fd) -{ - if (ioctl(fd, AUDIO_DRAIN, NULL) == -1) - warn("drain"); -} diff --git a/regress/sys/dev/audio/law.c b/regress/sys/dev/audio/law.c deleted file mode 100644 index 988d8b403bd..00000000000 --- a/regress/sys/dev/audio/law.c +++ /dev/null @@ -1,286 +0,0 @@ -/* $OpenBSD: law.c,v 1.1 2003/02/01 17:58:18 jason Exp $ */ - -/* - * This source code is a product of Sun Microsystems, Inc. and is provided - * for unrestricted use. Users may copy or modify this source code without - * charge. - * - * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING - * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun source code is provided with no support and without any obligation on - * the part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 - */ - -#include <sys/types.h> -#include "law.h" - -/* - * g711.c - * - * u-law, A-law and linear PCM conversions. - */ -#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ -#define QUANT_MASK (0xf) /* Quantization field mask. */ -#define NSEGS (8) /* Number of A-law segments. */ -#define SEG_SHIFT (4) /* Left shift for segment number. */ -#define SEG_MASK (0x70) /* Segment field mask. */ - -static short seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF, - 0x1FF, 0x3FF, 0x7FF, 0xFFF}; -static short seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF, - 0x3FF, 0x7FF, 0xFFF, 0x1FFF}; - -/* copy from CCITT G.711 specifications */ -u_int8_t _u2a[128] = { /* u- to A-law conversions */ - 1, 1, 2, 2, 3, 3, 4, 4, - 5, 5, 6, 6, 7, 7, 8, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 27, 29, 31, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, - 46, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, - 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, - 80, 82, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 120, - 121, 122, 123, 124, 125, 126, 127, 128}; - -u_int8_t _a2u[128] = { /* A- to u-law conversions */ - 1, 3, 5, 7, 9, 11, 13, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 32, 33, 33, 34, 34, 35, 35, - 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 48, 49, 49, - 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 64, - 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 80, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127}; - -static int -search(int val, short *table, int size) -{ - int i; - - for (i = 0; i < size; i++) - if (val <= *table++) - return (i); - return (size); -} - -/* - * linear2alaw() - Convert a 16-bit linear PCM value to 8-bit A-law - * - * linear2alaw() accepts an 16-bit integer and encodes it as A-law data. - * - * Linear Input Code Compressed Code - * ------------------------ --------------- - * 0000000wxyza 000wxyz - * 0000001wxyza 001wxyz - * 000001wxyzab 010wxyz - * 00001wxyzabc 011wxyz - * 0001wxyzabcd 100wxyz - * 001wxyzabcde 101wxyz - * 01wxyzabcdef 110wxyz - * 1wxyzabcdefg 111wxyz - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ -u_int8_t -linear2alaw(int pcm_val) /* 2's complement (16-bit range) */ -{ - int mask; - int seg; - u_int8_t aval; - - pcm_val = pcm_val >> 3; - - if (pcm_val >= 0) { - mask = 0xD5; /* sign (7th) bit = 1 */ - } else { - mask = 0x55; /* sign bit = 0 */ - pcm_val = -pcm_val - 1; - } - - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_aend, 8); - - /* Combine the sign, segment, and quantization bits. */ - - if (seg >= 8) /* out of range, return maximum value. */ - return (0x7F ^ mask); - else { - aval = seg << SEG_SHIFT; - if (seg < 2) - aval |= (pcm_val >> 4) & QUANT_MASK; - else - aval |= (pcm_val >> seg) & QUANT_MASK; - return (aval ^ mask); - } -} - -/* - * alaw2linear() - Convert an A-law value to 16-bit linear PCM - * - */ -int -alaw2linear(u_int8_t a_val) -{ - int t; - int seg; - - a_val ^= 0x55; - - t = (a_val & QUANT_MASK) << 4; - seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; - switch (seg) { - case 0: - t += 8; - break; - case 1: - t += 0x108; - break; - default: - t += 0x108; - t <<= seg - 1; - } - return ((a_val & SIGN_BIT) ? t : -t); -} - -#define BIAS (0x84) /* Bias for linear code. */ -#define CLIP 8159 - -/* - * linear2ulaw() - Convert a linear PCM value to u-law - * - * In order to simplify the encoding process, the original linear magnitude - * is biased by adding 33 which shifts the encoding range from (0 - 8158) to - * (33 - 8191). The result can be seen in the following encoding table: - * - * Biased Linear Input Code Compressed Code - * ------------------------ --------------- - * 00000001wxyza 000wxyz - * 0000001wxyzab 001wxyz - * 000001wxyzabc 010wxyz - * 00001wxyzabcd 011wxyz - * 0001wxyzabcde 100wxyz - * 001wxyzabcdef 101wxyz - * 01wxyzabcdefg 110wxyz - * 1wxyzabcdefgh 111wxyz - * - * Each biased linear code has a leading 1 which identifies the segment - * number. The value of the segment number is equal to 7 minus the number - * of leading 0's. The quantization interval is directly available as the - * four bits wxyz. * The trailing bits (a - h) are ignored. - * - * Ordinarily the complement of the resulting code word is used for - * transmission, and so the code word is complemented before it is returned. - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ -u_int8_t -linear2ulaw(int pcm_val) /* 2's complement (16-bit range) */ -{ - int mask; - int seg; - u_int8_t uval; - - /* Get the sign and the magnitude of the value. */ - pcm_val = pcm_val >> 2; - if (pcm_val < 0) { - pcm_val = -pcm_val; - mask = 0x7F; - } else { - mask = 0xFF; - } - if (pcm_val > CLIP) - pcm_val = CLIP; - pcm_val += (BIAS >> 2); - - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_uend, 8); - - /* - * Combine the sign, segment, quantization bits; - * and complement the code word. - */ - if (seg >= 8) /* out of range, return maximum value. */ - return (0x7F ^ mask); - else { - uval = (seg << 4) | ((pcm_val >> (seg + 1)) & 0xF); - return (uval ^ mask); - } - -} - -/* - * ulaw2linear() - Convert a u-law value to 16-bit linear PCM - * - * First, a biased linear code is derived from the code word. An unbiased - * output can then be obtained by subtracting 33 from the biased code. - * - * Note that this function expects to be passed the complement of the - * original code word. This is in keeping with ISDN conventions. - */ -int -ulaw2linear(u_int8_t u_val) -{ - int t; - - /* Complement to obtain normal u-law value. */ - u_val = ~u_val; - - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = ((u_val & QUANT_MASK) << 3) + BIAS; - t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; - - return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); -} - -/* A-law to u-law conversion */ -u_int8_t -alaw2ulaw(u_int8_t aval) -{ - aval &= 0xff; - return ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : - (0x7F ^ _a2u[aval ^ 0x55])); -} - -/* u-law to A-law conversion */ -u_int8_t -ulaw2alaw(u_int8_t uval) -{ - uval &= 0xff; - return ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : - (0x55 ^ (_u2a[0x7F ^ uval] - 1))); -} diff --git a/regress/sys/dev/audio/law.h b/regress/sys/dev/audio/law.h deleted file mode 100644 index 727c05f466e..00000000000 --- a/regress/sys/dev/audio/law.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $OpenBSD: law.h,v 1.2 2003/06/02 19:15:38 jason Exp $ */ - -/* - * Copyright (c) 2003 Jason L. Wright (jason@thought.net) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -u_int8_t linear2alaw(int); -u_int8_t linear2ulaw(int); -int alaw2linear(u_int8_t); -int ulaw2linear(u_int8_t); -u_int8_t alaw2ulaw(u_int8_t); -u_int8_t ulaw2alaw(u_int8_t); diff --git a/regress/sys/dev/audio_info/Makefile b/regress/sys/dev/audio_info/Makefile deleted file mode 100644 index a2b545f5617..00000000000 --- a/regress/sys/dev/audio_info/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $OpenBSD: Makefile,v 1.1 2007/07/06 00:42:12 jakemsr Exp $ - -PROG= audiotest_gsinfo -CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -MAN1= audiotest_gsinfo.1 - -.ifndef DO_AUTEST -REGRESS_SKIP= -.endif - -.include <bsd.regress.mk> diff --git a/regress/sys/dev/audio_info/audiotest_gsinfo.1 b/regress/sys/dev/audio_info/audiotest_gsinfo.1 deleted file mode 100644 index 6b5d438b4f6..00000000000 --- a/regress/sys/dev/audio_info/audiotest_gsinfo.1 +++ /dev/null @@ -1,119 +0,0 @@ -.\" $OpenBSD: audiotest_gsinfo.1,v 1.4 2013/07/16 14:18:39 schwarze Exp $ -.\" -.\" Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org> -.\" -.\" 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. -.\" -.\" -.Dd $Mdocdate: July 16 2013 $ -.Dt AUDIOTEST_GSINFO 1 -.Os -.Sh NAME -.Nm audiotest_gsinfo -.Nd test AUDIO_GETINFO and AUDIO_SETINFO -.Sh SYNOPSIS -.Nm audiotest_gsinfo -.Bk -words -.Op Fl f Ar device -.Ek -.Sh DESCRIPTION -The -.Nm -command performs an -.Ar AUDIO_GETINFO -.Xr ioctl 2 -to get the current -.Xr audio 4 -settings, then uses these settings in an -.Ar AUDIO_SETINFO -.Xr ioctl 2 . -The options are as follows: -.Bl -tag -width Ds -.It Fl f Ar device -The -.Xr audio 4 -device to use. -It defaults to -.Pa /dev/audio . -.El -.Pp -.Nm -first checks that an -.Dv AUDIO_GETINFO -ioctl will succeed. -If it is not successful, it will exit with status 1. -.Pp -If it is successful, -.Nm -will perform an -.Dv AUDIO_SETINFO -ioctl, using the values in its -.Vt audio_info_t -argument that were received in the previous -.Dv AUDIO_GETINFO -ioctl. -If the -.Dv AUDIO_SETINFO -ioctl is successful, -.Nm -will exit with status 0. -.Pp -If the -.Dv AUDIO_SETINFO -ioctl is not successful, -.Nm -will perform an -.Dv AUDIO_SETINFO -ioctl using the default -.Vt audio_info_t -values as given by -.Dv AUDIO_INITINFO . -If this -.Dv AUDIO_SETINFO -is not successful, -.Nm -will exit with status 1. -.Pp -Otherwise, -.Nm -will run a series of -.Dv AUDIO_SETINFO -ioctls where a single field in the -.Vt audio_info_t -structure is set to values from the -.Dv AUDIO_GETINFO -ioctl, the other values being default. -As this series of ioctls is performed, -.Nm -will print the -.Vt audio_info_t -field that is using values from the -.Dv AUDIO_GETINFO -ioctl, as well as the value it is using. -If the ioctl fails, -.Nm -will print -.Dq <- ERROR -immediately following the value. -After all fields of the -.Vt audio_info_t -structure have been used, -.Nm -will exit with status 1. -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr audio 4 -.Sh AUTHORS -.Nm -and this manual page were written by -.An Jacob Meuser Aq Mt jakemsr@sdf.lonestar.org . diff --git a/regress/sys/dev/audio_info/audiotest_gsinfo.c b/regress/sys/dev/audio_info/audiotest_gsinfo.c deleted file mode 100644 index 1acb410878d..00000000000 --- a/regress/sys/dev/audio_info/audiotest_gsinfo.c +++ /dev/null @@ -1,215 +0,0 @@ -/* $OpenBSD: audiotest_gsinfo.c,v 1.2 2007/07/06 01:00:02 jakemsr Exp $ */ - -/* - * Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org> - * - * 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 <sys/types.h> -#include <sys/ioctl.h> -#include <sys/audioio.h> -#include <err.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -extern char *optarg; -extern int optind; - -int audio_info_set(int); -int test_pr_members(int, int); -int test_main_members(int); -void audio_set_init(void); -void audio_set_test(int); - -audio_info_t audio_if_init; -audio_info_t audio_if_get; -audio_info_t audio_if_set; - - - -int -audio_info_set(int audio_fd) -{ - return ioctl(audio_fd, AUDIO_SETINFO, &audio_if_set); -} - - -void -audio_set_init(void) -{ - AUDIO_INITINFO(&audio_if_init); - audio_if_set = audio_if_init; -} - - -void -audio_set_test(int audio_fd) -{ - if (audio_info_set(audio_fd) < 0) - printf(" <- ERROR\n"); - else - printf("\n"); -} - - -int -test_pr_members(int audio_fd, int mode) -{ -struct audio_prinfo *s, *g; - - if (mode) { - g = &audio_if_get.play; - s = &audio_if_set.play; - } else { - g = &audio_if_get.record; - s = &audio_if_set.record; - } - - printf("%s.sample_rate = %u", (mode ? "play" : "record"), g->sample_rate); - audio_set_init(); - s->sample_rate = g->sample_rate; - audio_set_test(audio_fd); - - printf("%s.encoding = %u", (mode ? "play" : "record"), g->encoding); - audio_set_init(); - s->encoding = g->encoding; - audio_set_test(audio_fd); - - printf("%s.precision = %u", (mode ? "play" : "record"), g->precision); - audio_set_init(); - s->precision = g->precision; - audio_set_test(audio_fd); - - printf("%s.channels = %u", (mode ? "play" : "record"), g->channels); - audio_set_init(); - s->channels = g->channels; - audio_set_test(audio_fd); - - printf("%s.port = %u", (mode ? "play" : "record"), g->port); - audio_set_init(); - s->port = g->port; - audio_set_test(audio_fd); - - printf("%s.gain = %u", (mode ? "play" : "record"), g->gain); - audio_set_init(); - s->gain = g->gain; - audio_set_test(audio_fd); - - printf("%s.balance = %u", (mode ? "play" : "record"), g->balance); - audio_set_init(); - s->balance = g->balance; - audio_set_test(audio_fd); - - printf("%s.pause = %u", (mode ? "play" : "record"), g->pause); - audio_set_init(); - s->pause = g->pause; - audio_set_test(audio_fd); - - return 0; -} - -int -test_main_members(int audio_fd) -{ - printf("mode = %d", audio_if_get.mode); - audio_set_init(); - audio_if_set.mode = audio_if_get.mode; - audio_set_test(audio_fd); - - printf("monitor_gain = %d", audio_if_get.monitor_gain); - audio_set_init(); - audio_if_set.monitor_gain = audio_if_get.monitor_gain; - audio_set_test(audio_fd); - - printf("blocksize = %d", audio_if_get.blocksize); - audio_set_init(); - audio_if_set.blocksize = audio_if_get.blocksize; - audio_set_test(audio_fd); - - printf("hiwat = %d", audio_if_get.hiwat); - audio_set_init(); - audio_if_set.hiwat = audio_if_get.hiwat; - audio_set_test(audio_fd); - - printf("lowat = %d", audio_if_get.lowat); - audio_set_init(); - audio_if_set.lowat = audio_if_get.lowat; - audio_set_test(audio_fd); - - return 0; -} - -int -main(int argc, char *argv[]) -{ -char *audio_device; -int audio_fd; -int ch; -int exval; - - audio_device = "/dev/audio"; - - while ((ch = getopt(argc, argv, "f:")) != -1) { - switch (ch) { - case 'f': - audio_device = optarg; - break; - default: - break; - } - } - argc -= optind; - argv += optind; - - audio_fd = -1; - if ((audio_fd = open(audio_device, O_WRONLY)) < 0) - err(1, "could not open %s", audio_device); - - AUDIO_INITINFO(&audio_if_init); - AUDIO_INITINFO(&audio_if_get); - AUDIO_INITINFO(&audio_if_set); - - audio_if_set = audio_if_init; - - if (audio_info_set(audio_fd) < 0) - err(1, "results will be invalid"); - - if (ioctl(audio_fd, AUDIO_GETINFO, &audio_if_get) < 0) - err(1, "AUDIO_GETINFO audio_if_get"); - - exval = 1; - - audio_if_set = audio_if_get; - if (audio_info_set(audio_fd) < 0) - warn("AUDIO_SETINFO audio_if_get"); - else { - exval = 0; - goto done; - } - - test_pr_members(audio_fd, 1); /* play */ - test_pr_members(audio_fd, 0); /* record */ - test_main_members(audio_fd); - -done: - - if (audio_fd != -1) - close(audio_fd); - - exit(exval); -} diff --git a/regress/sys/dev/audio_rw/Makefile b/regress/sys/dev/audio_rw/Makefile deleted file mode 100644 index 441fbe9df00..00000000000 --- a/regress/sys/dev/audio_rw/Makefile +++ /dev/null @@ -1,122 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2007/10/03 21:49:13 jakemsr Exp $ - -PROG= audiotest_rw -CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -MAN1= audiotest_rw.1 - -.ifndef DO_AUTEST -REGRESS_SKIP = -.else -REGRESS_TARGETS = -REGRESS_TARGETS += run-regress-record -REGRESS_TARGETS += run-regress-record-duplex -REGRESS_TARGETS += run-regress-record-poll -REGRESS_TARGETS += run-regress-record-select -REGRESS_TARGETS += run-regress-record-bufinfo -REGRESS_TARGETS += run-regress-record-poll-duplex -REGRESS_TARGETS += run-regress-record-select-duplex -REGRESS_TARGETS += run-regress-record-bufinfo-duplex -REGRESS_TARGETS += run-regress-play -REGRESS_TARGETS += run-regress-play-duplex -REGRESS_TARGETS += run-regress-play-poll -REGRESS_TARGETS += run-regress-play-select -REGRESS_TARGETS += run-regress-play-bufinfo -REGRESS_TARGETS += run-regress-play-poll-duplex -REGRESS_TARGETS += run-regress-play-select-duplex -REGRESS_TARGETS += run-regress-play-bufinfo-duplex -REGRESS_TARGETS += run-regress-duplex -REGRESS_TARGETS += run-regress-duplex-poll -REGRESS_TARGETS += run-regress-duplex-select -REGRESS_TARGETS += run-regress-duplex-bufinfo -.endif - - -# audio data file for playing tests - -master.pcm: ${PROG} - @echo "creating master input file" - ./audiotest_rw -o master.pcm ${OPTS} - - -# recording tests - -run-regress-record: ${PROG} - ./audiotest_rw -o test.pcm ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-duplex: ${PROG} - ./audiotest_rw -o test.pcm -d ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-poll: ${PROG} - ./audiotest_rw -o test.pcm -p ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-select: ${PROG} - ./audiotest_rw -o test.pcm -s ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-bufinfo: ${PROG} - ./audiotest_rw -o test.pcm -n ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-poll-duplex: ${PROG} - ./audiotest_rw -o test.pcm -p -d ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-select-duplex: ${PROG} - ./audiotest_rw -o test.pcm -s -d ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-record-bufinfo-duplex: ${PROG} - ./audiotest_rw -o test.pcm -n -d ${OPTS} - @test -s test.pcm || (echo "no output" && false) - - -# playing tests - -run-regress-play: ${PROG} master.pcm - ./audiotest_rw -i master.pcm ${OPTS} - -run-regress-play-duplex: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -d ${OPTS} - -run-regress-play-poll: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -p ${OPTS} - -run-regress-play-select: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -s ${OPTS} - -run-regress-play-bufinfo: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -n ${OPTS} - -run-regress-play-poll-duplex: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -p -d ${OPTS} - -run-regress-play-select-duplex: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -s -d ${OPTS} - -run-regress-play-bufinfo-duplex: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -n -d ${OPTS} - - -# full-duplex tests - -run-regress-duplex: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -o test.pcm ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-duplex-poll: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -o test.pcm -p ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-duplex-select: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -o test.pcm -s ${OPTS} - @test -s test.pcm || (echo "no output" && false) - -run-regress-duplex-bufinfo: ${PROG} master.pcm - ./audiotest_rw -i master.pcm -o test.pcm -n ${OPTS} - @test -s test.pcm || (echo "no output" && false) - - -.include <bsd.regress.mk> diff --git a/regress/sys/dev/audio_rw/audiotest_rw.1 b/regress/sys/dev/audio_rw/audiotest_rw.1 deleted file mode 100644 index f771042db9d..00000000000 --- a/regress/sys/dev/audio_rw/audiotest_rw.1 +++ /dev/null @@ -1,256 +0,0 @@ -.\" $OpenBSD: audiotest_rw.1,v 1.6 2013/07/16 14:18:39 schwarze Exp $ -.\" -.\" Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org> -.\" -.\" 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. -.\" -.\" -.Dd $Mdocdate: July 16 2013 $ -.Dt AUDIOTEST_RW 1 -.Os -.Sh NAME -.Nm audiotest_rw -.Nd test read and write calls using audio -.Sh SYNOPSIS -.Nm audiotest_rw -.Bk -words -.Op Fl dnpsv -.Op Fl b Ar buffersize -.Op Fl c Ar channels -.Op Fl e Ar encoding -.Op Fl f Ar device -.Op Fl i Ar input -.Op Fl l Ar loops -.Op Fl o Ar output -.Op Fl r Ar samplerate -.Ek -.Sh DESCRIPTION -The -.Nm -command reads data from and writes data to -.Xr audio 4 -device -.Ar device . -The default -.Ar device -is -.Pa /dev/audio . -If the -.Fl i -option is used -.Ar device -will be opened write-only and -.Nm -will -.Xr fread 3 -data from -.Ar input -and -.Xr write 2 -it to -.Ar device . -If the -.Fl o -option is used -.Ar device -will be opened read-only and -.Nm -will -.Xr read 2 -data from -.Ar device -and -.Xr fwrite 3 -it to -.Ar output . -If both -.Fl i -and -.Fl o -are specified and -.Ar device -supports full-duplex operation, -.Ar device -will be opened read-write and -.Nm -will both -.Xr fread 3 -data from -.Ar input -and -.Xr write 2 -it to -.Ar device -and -.Xr read 2 -data from -.Ar device -and -.Xr fwrite 3 -it to -.Ar output . -If neither -.Fl i -nor -.Fl o -are used -.Nm -will exit with an error. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl b Ar buffersize -Buffer size for -.Xr read 2 -and -.Xr write 2 -operations, in bytes. -Valid arguments are 32 to 65536 inclusive. -It defaults to 8192. -.It Fl c Ar channels -Number of audio channels. -Valid arguments are 1 (mono) and 2 (stereo). -It defaults to 2. -.It Fl d -Opens -.Ar device -read-write and sets full-duplex mode, regardless of -.Fl i -and -.Fl o -options. -If -.Ar device -does not support full-duplex operation, -.Nm -will exit with an error. -.It Fl e Ar encoding -The audio encoding to use. -.Ar encoding -is the index of the encoding to use in the list of encodings supported by -.Ar device , -starting at 0. -It defaults to 0. -The list of upported encodings can be viewed with -.Xr audioctl 1 : -.Bd -literal -offset indent -$ audioctl encodings -.Ed -.It Fl f Ar device -The -.Xr audio 4 -device to use. -It defaults to -.Pa /dev/audio . -.It Fl i Ar input -The file from which raw (headerless) audio data will be read. -.It Fl l Ar loops -The number of times to read and/or write. -It defaults to 64. -.It Fl n -Use information about the play and record buffers as reported by the -.Dv AUDIO_GETPRINFO -and -.Dv AUDIO_GETRRINFO -ioctls to wait until data may be read without blocking on each -.Xr read 2 -and to wait until data may be written without blocking on each -.Xr write 2 . -.It Fl o Ar output -The file to which raw (headerless) audio data will be written. -.It Fl p -Use -.Xr poll 2 -to wait until data may be read without blocking on each -.Xr read 2 -and to wait until data may be written without blocking on each -.Xr write 2 . -Using this option also causes -.Ar device -to be opened for non-blocking I/O. -.It Fl r Ar samplerate -The audio data sample rate in samples per second. -It defaults to 48000. -.It Fl s -Use -.Xr select 2 -to wait until data may be read without blocking on each -.Xr read 2 -and to wait until data may be written without blocking on each -.Xr write 2 . -Using this option also causes -.Ar device -to be opened for non-blocking I/O. -.It Fl v -Verbose mode. -.El -.Pp -.Nm -was written as a strict interpretation of -.Xr audio 4 . -Problems encountered while using -.Nm -are likely due to errors in -.Xr audio 4 -documentation, the kernel's audio layer implementation, or audio -device drivers. -.Sh EXAMPLES -The following command will open /dev/audio read-only, set /dev/audio -to record mode with default parameters (channels:2 -encoding:0 sample rate 48000), and read data from /dev/audio and -write it to the file test.pcm: -.Bd -literal -offset indent -$ audiotest_rw -o test.pcm -.Ed -.Pp -The following command will open /dev/audio write-only, set /dev/audio -to play mode with default parameters (channels:2 -encoding:0 sample rate 48000), and read data from the file test.pcm -and write it to /dev/audio: -.Bd -literal -offset indent -$ audiotest_rw -i test.pcm -.Ed -.Pp -The following command will open /dev/audio read-write, set /dev/audio -to full-duplex mode with default parameters (channels:2 -encoding:0 sample rate 48000), read data from the file test.pcm -and write it to /dev/audio, and read data from /dev/audio and -write it to the file test2.pcm: -.Bd -literal -offset indent -$ audiotest_rw -i test.pcm -o test2.pcm -.Ed -.Pp -The following command will open /dev/audio read-only with non-blocking -I/O, set /dev/audio to record mode with default parameters (channels:2 -encoding:0 sample rate 48000), and read data from /dev/audio and -write it to the file test.pcm, using poll() to determine when data -is ready to be read: -.Bd -literal -offset indent -$ audiotest_rw -o test.pcm -p -.Ed -.Pp -The following command will open /dev/audio read-write with non-blocking -I/o, set /dev/audio to full-duplex mode with default parameters (channels:2 -encoding:0 sample rate 48000), read data from the file test.pcm -and write it to /dev/audio, and read data from /dev/audio and -write it to the file test2.pcm, using select() to determine when data -is ready for reading and/or writing on /dev/audio: -.Bd -literal -offset indent -$ audiotest_rw -i test.pcm -o test2.pcm -s -.Ed -.Sh SEE ALSO -.Xr audio 4 -.Sh AUTHORS -.Nm -and this manual page were written by -.An Jacob Meuser Aq Mt jakemsr@sdf.lonestar.org . diff --git a/regress/sys/dev/audio_rw/audiotest_rw.c b/regress/sys/dev/audio_rw/audiotest_rw.c deleted file mode 100644 index b2398fc351d..00000000000 --- a/regress/sys/dev/audio_rw/audiotest_rw.c +++ /dev/null @@ -1,666 +0,0 @@ -/* $OpenBSD: audiotest_rw.c,v 1.10 2009/11/12 05:20:11 jakemsr Exp $ */ - -/* - * Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org> - * - * 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 <sys/ioctl.h> -#include <sys/types.h> -#include <sys/audioio.h> -#include <sys/mman.h> -#include <errno.h> -#include <err.h> -#include <fcntl.h> -#include <poll.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <limits.h> -#include <string.h> - -extern char *__progname; - -void useage(void); -int audio_set_duplex(int, char *, int); -int audio_set_info(int, u_int, u_int, u_int, u_int, size_t *); -int audio_trigger_record(int); -int audio_wait_frame(int, size_t, u_int, int, int, int); -int audio_do_frame(int, size_t , char *, char *, u_int, int, int, int); -int audio_do_test(int, size_t, char *, char *, u_int, int, int, int, int, int); - -void -useage(void) -{ - fprintf(stderr, - "usage: %s [-dpsv] [-b buffersize] [-c channels] [-e encoding]\n" - " [-f device] [-i input] [-l loops] [-o output] [-r samplerate]\n", - __progname); - return; -} - - -int -audio_set_duplex(int audio_fd, char *audio_device, int use_duplex) -{ -int i, has_duplex; - - if (ioctl(audio_fd, AUDIO_GETPROPS, &i) < 0) { - warn("AUDIO_GETPROPS"); - return 1; - } - - has_duplex = i & AUDIO_PROP_FULLDUPLEX ? 1 : 0; - - if (use_duplex && !has_duplex) { - warn("%s doesn't support full-duplex", audio_device); - return 1; - } - - if (ioctl(audio_fd, AUDIO_SETFD, &use_duplex) < 0) { - warn("AUDIO_SETFD"); - return 1; - } - - if (ioctl(audio_fd, AUDIO_GETFD, &i) < 0) { - warn("AUDIO_GETFD"); - return 1; - } - - if (i != use_duplex) - return 1; - - return 0; -} - - -int -audio_set_info(int audio_fd, u_int mode, u_int encoding, u_int sample_rate, - u_int channels, size_t *buffer_size) -{ -audio_info_t audio_if; -audio_encoding_t audio_enc; -u_int precision; - - audio_enc.index = encoding; - if (ioctl(audio_fd, AUDIO_GETENC, &audio_enc) < 0) { - warn("AUDIO_GETENC"); - return 1; - } - - precision = audio_enc.precision; - encoding = audio_enc.encoding; - - if (encoding == AUDIO_ENCODING_ULINEAR) - encoding = (BYTE_ORDER == LITTLE_ENDIAN) ? - AUDIO_ENCODING_ULINEAR_LE : AUDIO_ENCODING_ULINEAR_BE; - - if (encoding == AUDIO_ENCODING_SLINEAR) - encoding = (BYTE_ORDER == LITTLE_ENDIAN) ? - AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; - - AUDIO_INITINFO(&audio_if); - - audio_if.mode = mode; - - if (mode & AUMODE_RECORD) { - audio_if.record.precision = precision; - audio_if.record.channels = channels; - audio_if.record.sample_rate = sample_rate; - audio_if.record.encoding = encoding; - audio_if.record.block_size = *buffer_size; - } - if (mode & AUMODE_PLAY) { - audio_if.play.precision = precision; - audio_if.play.channels = channels; - audio_if.play.sample_rate = sample_rate; - audio_if.play.encoding = encoding; - audio_if.play.block_size = *buffer_size; - } - - if (ioctl(audio_fd, AUDIO_SETINFO, &audio_if) < 0) { - warn("AUDIO_SETINFO"); - return 1; - } - - if (ioctl(audio_fd, AUDIO_GETINFO, &audio_if) < 0) { - warn("AUDIO_GETINFO"); - return 1; - } - - if (mode & AUMODE_RECORD) { - if (audio_if.record.precision != precision) { - warnx("unable to set record precision: tried %u, got %u", - precision, audio_if.record.precision); - return 1; - } - if (audio_if.record.channels != channels){ - warnx("unable to set record channels: tried %u, got %u", - channels, audio_if.record.channels); - return 1; - } - if (audio_if.record.sample_rate != sample_rate) { - warnx("unable to set record sample_rate: tried %u, got %u", - sample_rate, audio_if.record.sample_rate); - return 1; - } - if (audio_if.record.encoding != encoding) { - warnx("unable to set record encoding: tried %u, got %u", - encoding, audio_if.record.encoding); - return 1; - } - *buffer_size = audio_if.record.block_size; - } - - if (mode & AUMODE_PLAY) { - if (audio_if.play.precision != precision) { - warnx("unable to set play precision: tried %u, got %u", - precision, audio_if.play.precision); - return 1; - } - if (audio_if.play.channels != channels) { - warnx("unable to set play channels: tried %u, got %u", - channels, audio_if.play.channels); - return 1; - } - if (audio_if.play.sample_rate != sample_rate) { - warnx("unable to set play sample_rate: tried %u, got %u", - sample_rate, audio_if.play.sample_rate); - return 1; - } - if (audio_if.play.encoding != encoding) { - warnx("unable to set play encoding: tried %u, got %u", - encoding, audio_if.play.encoding); - return 1; - } - *buffer_size = audio_if.play.block_size; - } - - return 0; -} - -int -audio_trigger_record(int audio_fd) -{ -audio_info_t audio_if; - - AUDIO_INITINFO(&audio_if); - audio_if.record.pause = 0; - if (ioctl(audio_fd, AUDIO_SETINFO, &audio_if) < 0) { - warn("AUDIO_SETINFO: audio_if.record.pause = %d", - audio_if.record.pause); - return 1; - } - - return 0; -} - -/* return 0 on error, 1 if read, 2 if write, 3 if both read and write */ -int -audio_wait_frame(int audio_fd, size_t buffer_size, u_int mode, int use_select, - int use_poll, int use_bufinfo) -{ -struct audio_bufinfo ab; -struct pollfd pfd[1]; -fd_set *sfdsr; -fd_set *sfdsw; -struct timeval tv; -int nfds, max; -int ret; - - ret = 0; - - if (use_select) { - tv.tv_sec = 1; - tv.tv_usec = 0; - max = audio_fd; - sfdsr = NULL; - sfdsw = NULL; - if (mode & AUMODE_RECORD) { - if ((sfdsr = calloc(max + 1, sizeof(fd_set))) == NULL) { - warn("fd_set sfdsr"); - return 0; - } - FD_ZERO(sfdsr); - FD_SET(audio_fd, sfdsr); - } - if (mode & AUMODE_PLAY) { - if ((sfdsw = calloc(max + 1, sizeof(fd_set))) == NULL) { - warn("fd_set sfdsw"); - return 0; - } - FD_ZERO(sfdsw); - FD_SET(audio_fd, sfdsw); - } - nfds = select(max + 1, sfdsr, sfdsw, NULL, &tv); - if (nfds == -1) { - warn("select() error"); - return 0; - } - if (nfds == 0) { - warnx("select() timed out"); - return 0; - } - if (mode & AUMODE_RECORD) - if (FD_ISSET(audio_fd, sfdsr)) - ret |= 1; - if (mode & AUMODE_PLAY) - if (FD_ISSET(audio_fd, sfdsw)) - ret |= 2; - if (sfdsr != NULL) - free(sfdsr); - if (sfdsw != NULL) - free(sfdsw); - } else if (use_poll) { - bzero(&pfd[0], sizeof(struct pollfd)); - pfd[0].fd = audio_fd; - if (mode & AUMODE_RECORD) - pfd[0].events |= POLLIN; - if (mode & AUMODE_PLAY) - pfd[0].events |= POLLOUT; - nfds = poll(pfd, 1, 1000); - if (nfds == -1 || (pfd[0].revents & (POLLERR|POLLHUP|POLLNVAL))) { - warn("poll() error"); - return 0; - } - if (nfds == 0) { - warnx("poll() timed out"); - return 0; - } - if (mode & AUMODE_RECORD) - if (pfd[0].revents & POLLIN) - ret |= 1; - if (mode & AUMODE_PLAY) - if (pfd[0].revents & POLLOUT) - ret |= 2; - } else if (use_bufinfo) { -retry: - if (mode & AUMODE_RECORD) { - if (ioctl(audio_fd, AUDIO_GETRRINFO, &ab) < 0) { - warn("AUDIO_GETRRINFO"); - return 0; - } - if (ab.seek >= buffer_size) - ret |= 1; - } - if (mode & AUMODE_PLAY) { - if (ioctl(audio_fd, AUDIO_GETPRINFO, &ab) < 0) { - warn("AUDIO_GETPRINFO"); - return 0; - } - if (ab.hiwat * ab.blksize - ab.seek >= buffer_size) - ret |= 2; - } - if (ret == 0) { - /* 1/100th of a second */ - usleep(100000); - goto retry; - } - } else { - if (mode & AUMODE_RECORD) - ret |= 1; - if (mode & AUMODE_PLAY) - ret |= 2; - } - - return ret; -} - - -/* return 0 on error, 1 if read, 2 if write, 3 if both read and write */ -int -audio_do_frame(int audio_fd, size_t buffer_size, char *rbuffer, char *wbuffer, - u_int mode, int use_poll, int use_select, int use_bufinfo) -{ -size_t offset; -size_t left; -ssize_t retval; -int ret; - - ret = audio_wait_frame(audio_fd, buffer_size, mode, use_select, - use_poll, use_bufinfo); - if (ret == 0) - return 0; - - if (ret & 1) { - for (left = buffer_size, offset = 0; left > 0;) { - retval = read(audio_fd, rbuffer + offset, left); - if (retval == 0) - warnx("read audio device 0 bytes"); - if (retval < 0) { - warn("read audio device"); - return 0; - } - if (retval > left) { - warnx("read returns more than requested: " - "%ld > %ld", retval, left); - return 0; - } - offset += retval; - left -= retval; - } - } - - if (ret & 2) { - for (left = buffer_size, offset = 0; left > 0;) { - retval = write(audio_fd, wbuffer + offset, left); - if (retval == 0) - warnx("write audio device 0 bytes"); - if (retval < 0) { - warn("write audio device"); - return 0; - } - if (retval > left) { - warnx("write returns more than requested: " - "%ld > %ld", retval, left); - return 0; - } - offset += retval; - left -= retval; - } - } - - return ret; -} - - -int -audio_do_test(int audio_fd, size_t buffer_size, char *input_file, - char *output_file, u_int mode, int use_poll, int use_select, - int use_bufinfo, int loops, int verbose) -{ -FILE *fout; -FILE *fin; -char *rbuffer; -char *wbuffer; -int buffs_read, buffs_written; -int i, ret; - - fin = NULL; - fout = NULL; - rbuffer = NULL; - wbuffer = NULL; - - if ((rbuffer = malloc(buffer_size)) == NULL) - err(1, "malloc %lu bytes", (unsigned long)buffer_size); - - if ((wbuffer = malloc(buffer_size)) == NULL) - err(1, "malloc %lu bytes", (unsigned long)buffer_size); - - if (output_file != NULL) { - if ((fout = fopen(output_file, "w")) == NULL) - err(1, "fopen %s", output_file); - } - if (input_file != NULL) { - if ((fin = fopen(input_file, "r")) == NULL) - err(1, "fopen %s", input_file); - } - - buffs_read = 0; - buffs_written = 0; - if (input_file != NULL) { - if (fread(wbuffer, buffer_size, 1, fin) < 1) { - warnx("fread error: %s", input_file); - return 1; - } - } - for (i = 1; mode && i <= loops; i++) { - ret = audio_do_frame(audio_fd, buffer_size, rbuffer, - wbuffer, mode, use_poll, use_select, use_bufinfo); - if (ret == 0) - return 1; - if (ret & 1) { - buffs_read++; - if (verbose) - warnx("loop %03d: read frame: %03d", i, buffs_read); - if (fwrite(rbuffer, buffer_size, 1, fout) < 1) { - warnx("fwrite error: %s", output_file); - return 1; - } - } - if (ret & 2) { - buffs_written++; - if (verbose) - warnx("loop %03d: write frame: %03d", i, buffs_written); - if (fread(wbuffer, buffer_size, 1, fin) < 1) { - if (feof(fin)) { - if (verbose) - warnx("input EOF"); - mode = mode & ~AUMODE_PLAY; - } else { - warnx("fread error: %s", input_file); - return 1; - } - } - } - } - - if (output_file != NULL) - if (fileno(fout) >= 0) - fclose(fout); - if (input_file != NULL) - if (fileno(fin) >= 0) - fclose(fin); - - if (rbuffer != NULL) - free(rbuffer); - if (wbuffer != NULL) - free(wbuffer); - - return 0; -} - - -int -main(int argc, char *argv[]) -{ -char *audio_device; -char *output_file; -char *input_file; -int audio_fd; -size_t buffer_size; - -audio_device_t audio_dev; -audio_info_t audio_if; -u_int sample_rate; -u_int channels; -u_int mode; -u_int encoding; - -int flags; -int use_duplex; -int use_nonblock; -int use_poll; -int use_select; -int use_bufinfo; -int verbose; - -int loops; - -const char *errstr; - -int ch; -extern char *optarg; -extern int optind; - - - audio_device = "/dev/audio"; - input_file = NULL; - output_file = NULL; - - audio_fd = -1; - - buffer_size = 8192; - sample_rate = 48000; - channels = 2; - - encoding = 0; - - loops = 64; - use_nonblock = 0; - use_select = 0; - use_poll = 0; - use_bufinfo = 0; - use_duplex = 0; - verbose = 0; - - while ((ch = getopt(argc, argv, "b:c:e:f:i:l:o:r:dnpsv")) != -1) { - switch (ch) { - case 'b': - buffer_size = (size_t)strtonum(optarg, 32, 65536, &errstr); - if (errstr != NULL) - errx(1, "could not grok buffer_size: %s", errstr); - break; - case 'c': - channels = (u_int)strtonum(optarg, 1, 2, &errstr); - if (errstr != NULL) - errx(1, "could not grok channels: %s", errstr); - break; - case 'd': - use_duplex = 1; - break; - case 'e': - encoding = (u_int)strtonum(optarg, 0, 24, &errstr); - if (errstr != NULL) - errx(1, "could not grok encoding: %s", errstr); - break; - case 'f': - audio_device = optarg; - break; - case 'i': - input_file = optarg; - break; - case 'l': - loops = (int)strtonum(optarg, 0, INT_MAX, &errstr); - if (errstr != NULL) - errx(1, "could not grok loops: %s", errstr); - break; - case 'n': - use_bufinfo = 1; - break; - case 'o': - output_file = optarg; - break; - case 'p': - use_poll = 1; - use_nonblock = 1; - break; - case 'r': - sample_rate = (u_int)strtonum(optarg, 0, INT_MAX, &errstr); - if (errstr != NULL) - errx(1, "could not grok sample_rate: %s", errstr); - break; - case 's': - use_select = 1; - use_nonblock = 1; - break; - case 'v': - verbose = 1; - break; - default: - useage(); - exit(1); - break; - } - } - argc -= optind; - argv += optind; - - if (use_select + use_poll + use_bufinfo > 1) - errx(1, "can only use one of select, poll or buffer info"); - - if ((input_file == NULL) && (output_file == NULL)) - errx(1, "no input or output file specified"); - - if ((input_file != NULL) && (output_file != NULL)) - use_duplex = 1; - - mode = 0; - flags = 0; - - if (output_file != NULL) { - mode |= AUMODE_RECORD; - flags = O_RDONLY; - } - - if (input_file != NULL) { - mode |= AUMODE_PLAY; - flags = O_WRONLY; - } - - if (use_duplex) - flags = O_RDWR; - - if (use_nonblock) - flags |= O_NONBLOCK; - - if ((audio_fd = open(audio_device, flags)) < 0) - err(1, "open %s", audio_device); - - if (audio_set_duplex(audio_fd, audio_device, use_duplex)) - errx(1, "could not set duplex mode"); - - if (audio_set_info(audio_fd, mode, encoding, sample_rate, channels, - &buffer_size)) - errx(1, "could not initialize audio device"); - - if (verbose) { - AUDIO_INITINFO(&audio_if); - if (ioctl(audio_fd, AUDIO_GETINFO, &audio_if) < 0) - err(1, "AUDIO_GETINFO"); - - if (ioctl(audio_fd, AUDIO_GETDEV, &audio_dev) < 0) - err(1, "AUDIO_GETDEV"); - - warnx("audio device: %s: %s ver %s, config: %s", audio_device, - audio_dev.name, audio_dev.version, audio_dev.config); - warnx("blocksize: %u", audio_if.blocksize); - warnx("lowat: %u", audio_if.lowat); - warnx("hiwat: %u", audio_if.hiwat); - warnx("play.buffer_size: %u", audio_if.play.buffer_size); - warnx("record.buffer_size: %u", audio_if.record.buffer_size); - if (output_file != NULL) - warnx("output file: %s", output_file); - if (input_file != NULL) - warnx("input file: %s", input_file); - warnx("flags: %d", flags); - warnx("mode: %u", mode); - warnx("encoding: %u", encoding); - warnx("sample_rate: %u", sample_rate); - warnx("channels: %u", channels); - warnx("use_select: %d", use_select); - warnx("use_poll: %d", use_poll); - warnx("use_bufinfo: %d", use_bufinfo); - warnx("use_duplex: %d", use_duplex); - warnx("buffer_size: %lu", (unsigned long)buffer_size); - } - - /* need to trigger recording in duplex mode */ - if (use_duplex && (mode & AUMODE_RECORD)) - if (audio_trigger_record(audio_fd)) - exit(1); - - if (audio_do_test(audio_fd, buffer_size, input_file, output_file, - mode, use_poll, use_select, use_bufinfo, loops, verbose)) - exit(1); - - if (verbose) - warnx("test completed"); - - if (audio_fd >= 0) - close(audio_fd); - - exit(0); -} |