audiofil.h revision 1.2.2.2 1 1.2.2.2 christos /* $NetBSD: audiofil.h,v 1.2.2.2 2019/06/10 22:07:06 christos Exp $ */
2 1.2.2.2 christos
3 1.2.2.2 christos /*
4 1.2.2.2 christos * Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
5 1.2.2.2 christos * Copyright (C) 2017 Y.Sugahara (moveccr). All rights reserved.
6 1.2.2.2 christos *
7 1.2.2.2 christos * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 christos * modification, are permitted provided that the following conditions
9 1.2.2.2 christos * are met:
10 1.2.2.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 christos * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 christos * documentation and/or other materials provided with the distribution.
15 1.2.2.2 christos *
16 1.2.2.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.2.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.2.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2.2.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.2.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.2.2.2 christos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.2.2.2 christos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.2.2.2 christos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.2.2.2 christos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2.2.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2.2.2 christos * SUCH DAMAGE.
27 1.2.2.2 christos */
28 1.2.2.2 christos
29 1.2.2.2 christos #ifndef _SYS_DEV_AUDIO_AUDIOFIL_H_
30 1.2.2.2 christos #define _SYS_DEV_AUDIO_AUDIOFIL_H_
31 1.2.2.2 christos
32 1.2.2.2 christos /*
33 1.2.2.2 christos * Number of bits for internal format.
34 1.2.2.2 christos * XXX 32bit mode is not completed.
35 1.2.2.2 christos * XXX Is this necessary?
36 1.2.2.2 christos */
37 1.2.2.2 christos #define AUDIO_INTERNAL_BITS 16
38 1.2.2.2 christos /*#define AUDIO_INTERNAL_BITS 32 */
39 1.2.2.2 christos
40 1.2.2.2 christos #if AUDIO_INTERNAL_BITS == 16
41 1.2.2.2 christos
42 1.2.2.2 christos typedef int16_t aint_t; /* audio integer */
43 1.2.2.2 christos typedef uint16_t auint_t; /* audio unsigned integer */
44 1.2.2.2 christos typedef int32_t aint2_t; /* audio wide integer */
45 1.2.2.2 christos typedef uint32_t auint2_t; /* audio unsigned wide integer */
46 1.2.2.2 christos #define AINT_T_MAX ((aint_t)0x7fff)
47 1.2.2.2 christos #define AINT_T_MIN ((aint_t)0x8000)
48 1.2.2.2 christos
49 1.2.2.2 christos #elif AUDIO_INTERNAL_BITS == 32
50 1.2.2.2 christos
51 1.2.2.2 christos typedef int32_t aint_t;
52 1.2.2.2 christos typedef uint32_t auint_t;
53 1.2.2.2 christos typedef int64_t aint2_t;
54 1.2.2.2 christos typedef uint64_t auint2_t;
55 1.2.2.2 christos #define AINT_T_MAX ((aint_t)0x7fffffff)
56 1.2.2.2 christos #define AINT_T_MIN ((aint_t)0x80000000)
57 1.2.2.2 christos
58 1.2.2.2 christos #else
59 1.2.2.2 christos #error Invalid AUDIO_INTERNAL_BITS
60 1.2.2.2 christos #endif
61 1.2.2.2 christos
62 1.2.2.2 christos /*
63 1.2.2.2 christos * audio format.
64 1.2.2.2 christos *
65 1.2.2.2 christos * precision <= stride always holds.
66 1.2.2.2 christos */
67 1.2.2.2 christos typedef struct {
68 1.2.2.2 christos u_int sample_rate; /* sample rate in Hz */
69 1.2.2.2 christos u_int encoding; /* AUDIO_ENCODING_* */
70 1.2.2.2 christos u_int stride; /* container bits of a sample */
71 1.2.2.2 christos u_int precision; /* valid bits of a sample */
72 1.2.2.2 christos u_int channels; /* 1..AUDIO_MAX_CHANNELS */
73 1.2.2.2 christos } audio_format2_t;
74 1.2.2.2 christos
75 1.2.2.2 christos /* Parameters for conversion filters */
76 1.2.2.2 christos typedef struct {
77 1.2.2.2 christos /* Pointer to source samples. */
78 1.2.2.2 christos const void *src;
79 1.2.2.2 christos /* Input format */
80 1.2.2.2 christos const audio_format2_t *srcfmt;
81 1.2.2.2 christos
82 1.2.2.2 christos /* Pointer to destination buffer. */
83 1.2.2.2 christos void *dst;
84 1.2.2.2 christos /* Output format */
85 1.2.2.2 christos const audio_format2_t *dstfmt;
86 1.2.2.2 christos
87 1.2.2.2 christos /*
88 1.2.2.2 christos * Number of frames to be converted.
89 1.2.2.2 christos * The conversion filter must output 'count' frames. src and dst
90 1.2.2.2 christos * are guaranteed that at least 'count' frames are contiguous.
91 1.2.2.2 christos * The caller does not reference this count after calling, so
92 1.2.2.2 christos * that the conversion filter can use passed this variable.
93 1.2.2.2 christos * For example, decrementing it directly.
94 1.2.2.2 christos */
95 1.2.2.2 christos u_int count;
96 1.2.2.2 christos
97 1.2.2.2 christos /* The conversion filters can use this pointer. */
98 1.2.2.2 christos void *context;
99 1.2.2.2 christos } audio_filter_arg_t;
100 1.2.2.2 christos
101 1.2.2.2 christos typedef void(*audio_filter_t)(audio_filter_arg_t *arg);
102 1.2.2.2 christos
103 1.2.2.2 christos /* Filter registration structure */
104 1.2.2.2 christos typedef struct {
105 1.2.2.2 christos audio_filter_t codec; /* conversion function */
106 1.2.2.2 christos void *context; /* optional codec's argument */
107 1.2.2.2 christos } audio_filter_reg_t;
108 1.2.2.2 christos
109 1.2.2.2 christos #endif /* !_SYS_DEV_AUDIO_AUDIOFIL_H_ */
110