FreeBSD/Linux Kernel Cross Reference
sys/dev/audio_if.h
1 /* $NetBSD: audio_if.h,v 1.53 2003/06/29 22:29:57 fvdl 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_IF_H_
38 #define _SYS_DEV_AUDIO_IF_H_
39
40 /* check we have an audio(4) configured into kernel */
41 #if defined(_KERNEL_OPT)
42 #include "audio.h"
43
44 #if (NAUDIO == 0) && (NMIDI == 0) && (NMIDIBUS == 0)
45 #error "No 'audio* at audiobus?' or 'midi* at midibus?' or similar configured"
46 #endif
47
48 #endif /* _KERNEL_OPT */
49
50 /*
51 * Generic interface to hardware driver.
52 */
53
54 struct audio_softc;
55
56 struct audio_params {
57 u_long sample_rate; /* sample rate */
58 u_int encoding; /* e.g. mu-law, linear, etc */
59 u_int precision; /* bits/sample */
60 u_int channels; /* mono(1), stereo(2) */
61 /* Software en/decode functions, set if SW coding required by HW */
62 void (*sw_code)(void *, u_char *, int);
63 int factor; /* coding space change */
64 int factor_denom; /* denominator of factor */
65 /*
66 * The following four members represent what format is used in a
67 * hardware. If hw_sample_rate != sample_rate || hw_channels !=
68 * channels, the audio framework converts data. Encoding and
69 * precision are converted in sw_code().
70 * set_params() should set correct values to them if no conversion is
71 * needed.
72 */
73 u_long hw_sample_rate;
74 u_int hw_encoding;
75 u_int hw_precision;
76 u_int hw_channels;
77 };
78
79 /* The default audio mode: 8 kHz mono mu-law */
80 extern const struct audio_params audio_default;
81
82 struct malloc_type;
83 struct audio_hw_if {
84 int (*open)(void *, int); /* open hardware */
85 void (*close)(void *); /* close hardware */
86 int (*drain)(void *); /* Optional: drain buffers */
87
88 /* Encoding. */
89 /* XXX should we have separate in/out? */
90 int (*query_encoding)(void *, struct audio_encoding *);
91
92 /* Set the audio encoding parameters (record and play).
93 * Return 0 on success, or an error code if the
94 * requested parameters are impossible.
95 * The values in the params struct may be changed (e.g. rounding
96 * to the nearest sample rate.)
97 */
98 int (*set_params)(void *, int, int, struct audio_params *,
99 struct audio_params *);
100
101 /* Hardware may have some say in the blocksize to choose */
102 int (*round_blocksize)(void *, int);
103
104 /*
105 * Changing settings may require taking device out of "data mode",
106 * which can be quite expensive. Also, audiosetinfo() may
107 * change several settings in quick succession. To avoid
108 * having to take the device in/out of "data mode", we provide
109 * this function which indicates completion of settings
110 * adjustment.
111 */
112 int (*commit_settings)(void *);
113
114 /* Start input/output routines. These usually control DMA. */
115 int (*init_output)(void *, void *, int);
116 int (*init_input)(void *, void *, int);
117 int (*start_output)(void *, void *, int,
118 void (*)(void *), void *);
119 int (*start_input)(void *, void *, int,
120 void (*)(void *), void *);
121 int (*halt_output)(void *);
122 int (*halt_input)(void *);
123
124 int (*speaker_ctl)(void *, int);
125 #define SPKR_ON 1
126 #define SPKR_OFF 0
127
128 int (*getdev)(void *, struct audio_device *);
129 int (*setfd)(void *, int);
130
131 /* Mixer (in/out ports) */
132 int (*set_port)(void *, mixer_ctrl_t *);
133 int (*get_port)(void *, mixer_ctrl_t *);
134
135 int (*query_devinfo)(void *, mixer_devinfo_t *);
136
137 /* Allocate/free memory for the ring buffer. Usually malloc/free. */
138 void *(*allocm)(void *, int, size_t, struct malloc_type *, int);
139 void (*freem)(void *, void *, struct malloc_type *);
140 size_t (*round_buffersize)(void *, int, size_t);
141 paddr_t (*mappage)(void *, void *, off_t, int);
142
143 int (*get_props)(void *); /* device properties */
144
145 int (*trigger_output)(void *, void *, void *, int,
146 void (*)(void *), void *, struct audio_params *);
147 int (*trigger_input)(void *, void *, void *, int,
148 void (*)(void *), void *, struct audio_params *);
149 int (*dev_ioctl)(void *, u_long, caddr_t, int, struct proc *);
150 };
151
152 struct audio_attach_args {
153 int type;
154 void *hwif; /* either audio_hw_if * or midi_hw_if * */
155 void *hdl;
156 };
157 #define AUDIODEV_TYPE_AUDIO 0
158 #define AUDIODEV_TYPE_MIDI 1
159 #define AUDIODEV_TYPE_OPL 2
160 #define AUDIODEV_TYPE_MPU 3
161 #define AUDIODEV_TYPE_AUX 4
162
163 /* Attach the MI driver(s) to the MD driver. */
164 struct device *audio_attach_mi(struct audio_hw_if *, void *, struct device *);
165 int audioprint(void *, const char *);
166
167 /* Device identity flags */
168 #define SOUND_DEVICE 0
169 #define AUDIO_DEVICE 0x80
170 #define AUDIOCTL_DEVICE 0xc0
171 #define MIXER_DEVICE 0x10
172
173 #define AUDIOUNIT(x) (minor(x)&0x0f)
174 #define AUDIODEV(x) (minor(x)&0xf0)
175
176 #define ISDEVSOUND(x) (AUDIODEV((x)) == SOUND_DEVICE)
177 #define ISDEVAUDIO(x) (AUDIODEV((x)) == AUDIO_DEVICE)
178 #define ISDEVAUDIOCTL(x) (AUDIODEV((x)) == AUDIOCTL_DEVICE)
179 #define ISDEVMIXER(x) (AUDIODEV((x)) == MIXER_DEVICE)
180
181 #if !defined(__i386__) && !defined(__arm32__) && !defined(IPL_AUDIO)
182 #define splaudio splbio /* XXX */
183 #define IPL_AUDIO IPL_BIO /* XXX */
184 #endif
185
186 /*
187 * USB Audio specification defines 12 channels:
188 * L R C LFE Ls Rs Lc Rc S Sl Sr T
189 */
190 #define AUDIO_MAX_CHANNELS 12
191
192 #endif /* _SYS_DEV_AUDIO_IF_H_ */
193
Cache object: 3f6f9735a3bc174ab123f046785bfecf
|