audio_if.h revision 1.2 1 /* $NetBSD: audio_if.h,v 1.2 2019/05/08 13:40:17 isaki Exp $ */
2
3 /*
4 * Copyright (c) 1994 Havard Eidnes.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the Computer Systems
18 * Engineering Group at Lawrence Berkeley Laboratory.
19 * 4. Neither the name of the University nor of the Laboratory may be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #ifndef _SYS_DEV_AUDIO_AUDIO_IF_H_
38 #define _SYS_DEV_AUDIO_AUDIO_IF_H_
39
40 #include <sys/types.h>
41 #include <sys/audioio.h>
42 #include <sys/mutex.h>
43
44 /* check we have an audio(4) configured into kernel */
45 #if defined(_KERNEL_OPT)
46 #include "audio.h"
47
48 #if (NAUDIO == 0) && (NMIDI == 0) && (NMIDIBUS == 0)
49 #error "No 'audio* at audiobus?' or 'midi* at midibus?' or similar configured"
50 #endif
51
52 #endif /* _KERNEL_OPT */
53
54 /*
55 * Interfaces for hardware drivers and MI audio.
56 */
57
58 struct audio_softc;
59
60 /**
61 * audio stream format
62 */
63 typedef struct audio_params {
64 u_int sample_rate; /* sample rate */
65 u_int encoding; /* e.g. mu-law, linear, etc */
66 u_int precision; /* bits/subframe */
67 u_int validbits; /* valid bits in a subframe */
68 u_int channels; /* mono(1), stereo(2) */
69 } audio_params_t;
70
71 #define AUFMT_INVALIDATE(fmt) (fmt)->mode |= 0x80000000
72 #define AUFMT_VALIDATE(fmt) (fmt)->mode &= 0x7fffffff
73 #define AUFMT_IS_VALID(fmt) (((fmt)->mode & 0x80000000) == 0)
74
75 #include <dev/audio/audiofil.h>
76
77 struct audio_hw_if {
78 int (*open)(void *, int); /* open hardware */
79 void (*close)(void *); /* close hardware */
80
81 int (*query_format)(void *, audio_format_query_t *);
82 int (*set_format)(void *, int,
83 const audio_params_t *, const audio_params_t *,
84 audio_filter_reg_t *, audio_filter_reg_t *);
85
86 /* Hardware may have some say in the blocksize to choose */
87 int (*round_blocksize)(void *, int, int, const audio_params_t *);
88
89 /*
90 * Changing settings may require taking device out of "data mode",
91 * which can be quite expensive. Also, audiosetinfo() may
92 * change several settings in quick succession. To avoid
93 * having to take the device in/out of "data mode", we provide
94 * this function which indicates completion of settings
95 * adjustment.
96 */
97 int (*commit_settings)(void *);
98
99 /* Start input/output routines. These usually control DMA. */
100 int (*init_output)(void *, void *, int);
101 int (*init_input)(void *, void *, int);
102 int (*start_output)(void *, void *, int,
103 void (*)(void *), void *);
104 int (*start_input)(void *, void *, int,
105 void (*)(void *), void *);
106 int (*halt_output)(void *);
107 int (*halt_input)(void *);
108
109 int (*speaker_ctl)(void *, int);
110 #define SPKR_ON 1
111 #define SPKR_OFF 0
112
113 int (*getdev)(void *, struct audio_device *);
114
115 /* Mixer (in/out ports) */
116 int (*set_port)(void *, mixer_ctrl_t *);
117 int (*get_port)(void *, mixer_ctrl_t *);
118
119 int (*query_devinfo)(void *, mixer_devinfo_t *);
120
121 /* Allocate/free memory for the ring buffer. Usually malloc/free. */
122 void *(*allocm)(void *, int, size_t);
123 void (*freem)(void *, void *, size_t);
124 size_t (*round_buffersize)(void *, int, size_t);
125
126 int (*get_props)(void *); /* device properties */
127
128 int (*trigger_output)(void *, void *, void *, int,
129 void (*)(void *), void *, const audio_params_t *);
130 int (*trigger_input)(void *, void *, void *, int,
131 void (*)(void *), void *, const audio_params_t *);
132 int (*dev_ioctl)(void *, u_long, void *, int, struct lwp *);
133 void (*get_locks)(void *, kmutex_t **, kmutex_t **);
134 };
135
136 struct audio_attach_args {
137 int type;
138 const void *hwif; /* either audio_hw_if * or midi_hw_if * */
139 void *hdl;
140 };
141 #define AUDIODEV_TYPE_AUDIO 0
142 #define AUDIODEV_TYPE_MIDI 1
143 #define AUDIODEV_TYPE_OPL 2
144 #define AUDIODEV_TYPE_MPU 3
145 #define AUDIODEV_TYPE_AUX 4
146
147 /* Attach the MI driver(s) to the MD driver. */
148 device_t audio_attach_mi(const struct audio_hw_if *, void *, device_t);
149 int audioprint(void *, const char *);
150
151 extern int audio_query_format(const struct audio_format *, int,
152 audio_format_query_t *);
153 extern int audio_indexof_format(const struct audio_format *, int, int,
154 const audio_params_t *);
155 extern const char *audio_encoding_name(int);
156
157 /* Device identity flags */
158 #define SOUND_DEVICE 0
159 #define AUDIO_DEVICE 0x80
160 #define AUDIOCTL_DEVICE 0xc0
161 #define MIXER_DEVICE 0x10
162
163 #define AUDIOUNIT(x) (minor(x)&0x0f)
164 #define AUDIODEV(x) (minor(x)&0xf0)
165
166 #define ISDEVSOUND(x) (AUDIODEV((x)) == SOUND_DEVICE)
167 #define ISDEVAUDIO(x) (AUDIODEV((x)) == AUDIO_DEVICE)
168 #define ISDEVAUDIOCTL(x) (AUDIODEV((x)) == AUDIOCTL_DEVICE)
169 #define ISDEVMIXER(x) (AUDIODEV((x)) == MIXER_DEVICE)
170
171 /*
172 * USB Audio specification defines 12 channels:
173 * L R C LFE Ls Rs Lc Rc S Sl Sr T
174 */
175 #define AUDIO_MAX_CHANNELS 12
176
177 #endif /* _SYS_DEV_AUDIO_AUDIO_IF_H_ */
178
179