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