1/* $NetBSD: auconv.h,v 1.16 2011/11/23 23:07:31 jmcneill Exp $ */
2
3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _SYS_DEV_AUCONV_H_
33#define _SYS_DEV_AUCONV_H_
34#include <dev/audio_if.h>
35
36/* common routines for stream_filter_t */
37extern void stream_filter_set_fetcher(stream_filter_t *, stream_fetcher_t *);
38extern void stream_filter_set_inputbuffer(stream_filter_t *, audio_stream_t *);
39extern stream_filter_t *auconv_nocontext_filter_factory
40 (int (*)(struct audio_softc *, stream_fetcher_t *, audio_stream_t *, int));
41extern void auconv_nocontext_filter_dtor(struct stream_filter *);
42#define FILTER_LOOP_PROLOGUE(SRC, SRCFRAME, DST, DSTFRAME, MAXUSED) \
43do { \
44 const uint8_t *s; \
45 uint8_t *d; \
46 s = (SRC)->outp; \
47 d = (DST)->inp; \
48 for (; audio_stream_get_used(DST) < MAXUSED \
49 && audio_stream_get_used(SRC) >= SRCFRAME; \
50 s = audio_stream_add_outp(SRC, s, SRCFRAME), \
51 d = audio_stream_add_inp(DST, d, DSTFRAME))
52#define FILTER_LOOP_EPILOGUE(SRC, DST) \
53 (SRC)->outp = s; \
54 (DST)->inp = d; \
55} while (/*CONSTCOND*/0)
56
57
58/* Convert between signed and unsigned. */
59extern stream_filter_factory_t change_sign8;
60extern stream_filter_factory_t change_sign16;
61/* Convert between little and big endian. */
62extern stream_filter_factory_t swap_bytes;
63extern stream_filter_factory_t swap_bytes_change_sign16;
64/* Byte expansion/contraction */
65extern stream_filter_factory_t linear8_to_linear16;
66extern stream_filter_factory_t linear16_to_linear8;
67/* sampling rate conversion (aurateconv.c) */
68extern stream_filter_factory_t aurateconv;
69
70struct audio_format {
71 /**
72 * Device-dependent audio drivers may use this field freely.
73 */
74 void *driver_data;
75
76 /**
77 * combination of AUMODE_PLAY and AUMODE_RECORD
78 */
79 int32_t mode;
80
81 /**
82 * Encoding type. AUDIO_ENCODING_*.
83 * Don't use AUDIO_ENCODING_SLINEAR/ULINEAR/LINEAR/LINEAR8
84 */
85 u_int encoding;
86
87 /**
88 * The size of valid bits in one sample.
89 * It must be <= precision.
90 */
91 u_int validbits;
92
93 /**
94 * The bit size of one sample.
95 * It must be >= validbits, and is usualy a multiple of 8.
96 */
97 u_int precision;
98
99 /**
100 * The number of channels. >= 1
101 */
102 u_int channels;
103
104 u_int channel_mask;
105#define AUFMT_UNKNOWN_POSITION 0U
106#define AUFMT_FRONT_LEFT 0x00001U /* USB audio compatible */
107#define AUFMT_FRONT_RIGHT 0x00002U /* USB audio compatible */
108#define AUFMT_FRONT_CENTER 0x00004U /* USB audio compatible */
109#define AUFMT_LOW_FREQUENCY 0x00008U /* USB audio compatible */
110#define AUFMT_BACK_LEFT 0x00010U /* USB audio compatible */
111#define AUFMT_BACK_RIGHT 0x00020U /* USB audio compatible */
112#define AUFMT_FRONT_LEFT_OF_CENTER 0x00040U /* USB audio compatible */
113#define AUFMT_FRONT_RIGHT_OF_CENTER 0x00080U /* USB audio compatible */
114#define AUFMT_BACK_CENTER 0x00100U /* USB audio compatible */
115#define AUFMT_SIDE_LEFT 0x00200U /* USB audio compatible */
116#define AUFMT_SIDE_RIGHT 0x00400U /* USB audio compatible */
117#define AUFMT_TOP_CENTER 0x00800U /* USB audio compatible */
118#define AUFMT_TOP_FRONT_LEFT 0x01000U
119#define AUFMT_TOP_FRONT_CENTER 0x02000U
120#define AUFMT_TOP_FRONT_RIGHT 0x04000U
121#define AUFMT_TOP_BACK_LEFT 0x08000U
122#define AUFMT_TOP_BACK_CENTER 0x10000U
123#define AUFMT_TOP_BACK_RIGHT 0x20000U
124
125#define AUFMT_MONAURAL AUFMT_FRONT_CENTER
126#define AUFMT_STEREO (AUFMT_FRONT_LEFT | AUFMT_FRONT_RIGHT)
127#define AUFMT_SURROUND4 (AUFMT_STEREO | AUFMT_BACK_LEFT \
128 | AUFMT_BACK_RIGHT)
129#define AUFMT_DOLBY_5_1 (AUFMT_SURROUND4 | AUFMT_FRONT_CENTER \
130 | AUFMT_LOW_FREQUENCY)
131
132 /**
133 * 0: frequency[0] is lower limit, and frequency[1] is higher limit.
134 * 1-16: frequency[0] to frequency[frequency_type-1] are valid.
135 */
136 u_int frequency_type;
137
138#define AUFMT_MAX_FREQUENCIES 16
139 /**
140 * sampling rates
141 */
142 u_int frequency[AUFMT_MAX_FREQUENCIES];
143};
144
145#define AUFMT_INVALIDATE(fmt) (fmt)->mode |= 0x80000000
146#define AUFMT_VALIDATE(fmt) (fmt)->mode &= 0x7fffffff
147#define AUFMT_IS_VALID(fmt) (((fmt)->mode & 0x80000000) == 0)
148
149struct audio_encoding_set;
150extern int auconv_set_converter(const struct audio_format *, int,
151 int, const audio_params_t *, int,
152 stream_filter_list_t *);
153extern int auconv_create_encodings(const struct audio_format *, int,
154 struct audio_encoding_set **);
155extern int auconv_delete_encodings(struct audio_encoding_set *);
156extern int auconv_query_encoding(const struct audio_encoding_set *,
157 audio_encoding_t *);
158
159#endif /* !_SYS_DEV_AUCONV_H_ */
160