Annotation of src/sys/dev/audio_if.h, Revision 1.66.14.3
1.66.14.3! jmcneill 1: /* $NetBSD: audio_if.h,v 1.66.14.2 2011/11/20 09:37:04 mrg Exp $ */
1.1 brezak 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:
1.30 augustss 37: #ifndef _SYS_DEV_AUDIO_IF_H_
38: #define _SYS_DEV_AUDIO_IF_H_
1.66.14.1 jmcneill 39:
1.55 kent 40: #include <sys/types.h>
41: #include <sys/audioio.h>
1.66.14.1 jmcneill 42: #include <sys/mutex.h>
1.48 jdolecek 43:
44: /* check we have an audio(4) configured into kernel */
45: #if defined(_KERNEL_OPT)
46: #include "audio.h"
47:
1.49 he 48: #if (NAUDIO == 0) && (NMIDI == 0) && (NMIDIBUS == 0)
49: #error "No 'audio* at audiobus?' or 'midi* at midibus?' or similar configured"
1.48 jdolecek 50: #endif
51:
52: #endif /* _KERNEL_OPT */
1.30 augustss 53:
1.1 brezak 54: /*
1.55 kent 55: * Interfaces for hardware drivers and MI audio.
1.1 brezak 56: */
57:
1.7 christos 58: struct audio_softc;
59:
1.55 kent 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;
1.13 augustss 70:
1.51 wiz 71: /* The default audio mode: 8 kHz mono mu-law */
1.50 jdolecek 72: extern const struct audio_params audio_default;
1.11 augustss 73:
1.55 kent 74: /**
75: * audio stream buffer
76: */
77: typedef struct audio_stream {
78: size_t bufsize; /* allocated memory */
79: uint8_t *start; /* start of buffer area */
80: uint8_t *end; /* end of valid buffer area */
81: uint8_t *inp; /* address to be written next */
82: const uint8_t *outp; /* address to be read next */
83: int used; /* valid data size in this stream */
84: audio_params_t param; /* represents this stream */
1.62 thorpej 85: bool loop;
1.55 kent 86: } audio_stream_t;
87:
1.58 perry 88: static __inline int
1.55 kent 89: audio_stream_get_space(const audio_stream_t *s)
90: {
1.66 sborrill 91: if (s)
92: return (s->end - s->start) - s->used;
93: return 0;
1.55 kent 94: }
95:
1.58 perry 96: static __inline int
1.55 kent 97: audio_stream_get_used(const audio_stream_t *s)
98: {
1.66 sborrill 99: return s ? s->used : 0;
1.55 kent 100: }
101:
1.58 perry 102: static __inline uint8_t *
1.55 kent 103: audio_stream_add_inp(audio_stream_t *s, uint8_t *v, int diff)
104: {
105: s->used += diff;
106: v += diff;
107: if (v >= s->end)
108: v -= s->end - s->start;
109: return v;
110: }
111:
1.58 perry 112: static __inline const uint8_t *
1.55 kent 113: audio_stream_add_outp(audio_stream_t *s, const uint8_t *v, int diff)
114: {
115: s->used -= diff;
116: v += diff;
117: if (v >= s->end)
118: v -= s->end - s->start;
119: return v;
120: }
121:
122: /**
123: * an interface to fill a audio stream buffer
124: */
125: typedef struct stream_fetcher {
1.66.14.1 jmcneill 126: int (*fetch_to)(struct audio_softc *, struct stream_fetcher *,
127: audio_stream_t *, int);
1.55 kent 128: } stream_fetcher_t;
129:
130: /**
131: * audio stream filter.
132: * This must be an extension of stream_fetcher_t.
133: */
134: typedef struct stream_filter {
135: /* public: */
136: stream_fetcher_t base;
137: void (*dtor)(struct stream_filter *);
138: void (*set_fetcher)(struct stream_filter *, stream_fetcher_t *);
139: void (*set_inputbuffer)(struct stream_filter *, audio_stream_t *);
140: /* private: */
141: stream_fetcher_t *prev;
142: audio_stream_t *src;
143: } stream_filter_t;
144:
145: /**
146: * factory method for stream_filter_t
147: */
148: typedef stream_filter_t *stream_filter_factory_t(struct audio_softc *,
149: const audio_params_t *, const audio_params_t *);
150:
151: /**
152: * filter pipeline request
153: *
154: * filters[0] is the first filter for playing or the last filter for recording.
155: * The audio_params_t instance for the hardware is filters[0].param.
156: */
157: #ifndef AUDIO_MAX_FILTERS
158: # define AUDIO_MAX_FILTERS 8
159: #endif
160: typedef struct stream_filter_list {
161: void (*append)(struct stream_filter_list *, stream_filter_factory_t,
162: const audio_params_t *);
163: void (*prepend)(struct stream_filter_list *, stream_filter_factory_t,
164: const audio_params_t *);
165: void (*set)(struct stream_filter_list *, int, stream_filter_factory_t,
166: const audio_params_t *);
167: int req_size;
168: struct stream_filter_req {
169: stream_filter_factory_t *factory;
170: audio_params_t param; /* from-param for recording,
171: to-param for playing */
172: } filters[AUDIO_MAX_FILTERS];
173: } stream_filter_list_t;
174:
1.1 brezak 175: struct audio_hw_if {
1.36 augustss 176: int (*open)(void *, int); /* open hardware */
177: void (*close)(void *); /* close hardware */
178: int (*drain)(void *); /* Optional: drain buffers */
1.40 kent 179:
1.1 brezak 180: /* Encoding. */
181: /* XXX should we have separate in/out? */
1.55 kent 182: int (*query_encoding)(void *, audio_encoding_t *);
1.1 brezak 183:
1.11 augustss 184: /* Set the audio encoding parameters (record and play).
1.40 kent 185: * Return 0 on success, or an error code if the
1.11 augustss 186: * requested parameters are impossible.
187: * The values in the params struct may be changed (e.g. rounding
188: * to the nearest sample rate.)
189: */
1.55 kent 190: int (*set_params)(void *, int, int, audio_params_t *,
191: audio_params_t *, stream_filter_list_t *,
192: stream_filter_list_t *);
1.40 kent 193:
1.1 brezak 194: /* Hardware may have some say in the blocksize to choose */
1.55 kent 195: int (*round_blocksize)(void *, int, int, const audio_params_t *);
1.1 brezak 196:
197: /*
198: * Changing settings may require taking device out of "data mode",
199: * which can be quite expensive. Also, audiosetinfo() may
200: * change several settings in quick succession. To avoid
201: * having to take the device in/out of "data mode", we provide
202: * this function which indicates completion of settings
203: * adjustment.
204: */
1.36 augustss 205: int (*commit_settings)(void *);
1.1 brezak 206:
207: /* Start input/output routines. These usually control DMA. */
1.36 augustss 208: int (*init_output)(void *, void *, int);
209: int (*init_input)(void *, void *, int);
210: int (*start_output)(void *, void *, int,
211: void (*)(void *), void *);
212: int (*start_input)(void *, void *, int,
213: void (*)(void *), void *);
214: int (*halt_output)(void *);
215: int (*halt_input)(void *);
1.1 brezak 216:
1.36 augustss 217: int (*speaker_ctl)(void *, int);
1.1 brezak 218: #define SPKR_ON 1
219: #define SPKR_OFF 0
220:
1.36 augustss 221: int (*getdev)(void *, struct audio_device *);
222: int (*setfd)(void *, int);
1.40 kent 223:
1.1 brezak 224: /* Mixer (in/out ports) */
1.36 augustss 225: int (*set_port)(void *, mixer_ctrl_t *);
226: int (*get_port)(void *, mixer_ctrl_t *);
1.1 brezak 227:
1.36 augustss 228: int (*query_devinfo)(void *, mixer_devinfo_t *);
1.40 kent 229:
1.14 augustss 230: /* Allocate/free memory for the ring buffer. Usually malloc/free. */
1.66.14.1 jmcneill 231: void *(*allocm)(void *, int, size_t);
232: void (*freem)(void *, void *, size_t);
1.36 augustss 233: size_t (*round_buffersize)(void *, int, size_t);
234: paddr_t (*mappage)(void *, void *, off_t, int);
235:
1.40 kent 236: int (*get_props)(void *); /* device properties */
1.36 augustss 237:
238: int (*trigger_output)(void *, void *, void *, int,
1.55 kent 239: void (*)(void *), void *, const audio_params_t *);
1.36 augustss 240: int (*trigger_input)(void *, void *, void *, int,
1.55 kent 241: void (*)(void *), void *, const audio_params_t *);
1.63 christos 242: int (*dev_ioctl)(void *, u_long, void *, int, struct lwp *);
1.66.14.1 jmcneill 243: void (*get_locks)(void *, kmutex_t **, kmutex_t **);
1.1 brezak 244: };
245:
1.21 augustss 246: struct audio_attach_args {
1.23 augustss 247: int type;
1.54 yamt 248: const void *hwif; /* either audio_hw_if * or midi_hw_if * */
1.23 augustss 249: void *hdl;
1.21 augustss 250: };
1.23 augustss 251: #define AUDIODEV_TYPE_AUDIO 0
252: #define AUDIODEV_TYPE_MIDI 1
1.30 augustss 253: #define AUDIODEV_TYPE_OPL 2
254: #define AUDIODEV_TYPE_MPU 3
1.44 kleink 255: #define AUDIODEV_TYPE_AUX 4
1.19 augustss 256:
257: /* Attach the MI driver(s) to the MD driver. */
1.65 cube 258: device_t audio_attach_mi(const struct audio_hw_if *, void *, device_t);
1.36 augustss 259: int audioprint(void *, const char *);
1.1 brezak 260:
261: /* Device identity flags */
262: #define SOUND_DEVICE 0
263: #define AUDIO_DEVICE 0x80
1.18 augustss 264: #define AUDIOCTL_DEVICE 0xc0
1.1 brezak 265: #define MIXER_DEVICE 0x10
266:
267: #define AUDIOUNIT(x) (minor(x)&0x0f)
268: #define AUDIODEV(x) (minor(x)&0xf0)
1.18 augustss 269:
1.24 tv 270: #define ISDEVSOUND(x) (AUDIODEV((x)) == SOUND_DEVICE)
271: #define ISDEVAUDIO(x) (AUDIODEV((x)) == AUDIO_DEVICE)
272: #define ISDEVAUDIOCTL(x) (AUDIODEV((x)) == AUDIOCTL_DEVICE)
273: #define ISDEVMIXER(x) (AUDIODEV((x)) == MIXER_DEVICE)
1.4 brezak 274:
1.43 kent 275: /*
276: * USB Audio specification defines 12 channels:
277: * L R C LFE Ls Rs Lc Rc S Sl Sr T
278: */
279: #define AUDIO_MAX_CHANNELS 12
1.30 augustss 280:
281: #endif /* _SYS_DEV_AUDIO_IF_H_ */
282:
CVSweb <webmaster@jp.NetBSD.org>