root / audio / audio_int.h @ 3d575329
History | View | Annotate | Download (6.9 kB)
1 | fb065187 | bellard | /*
|
---|---|---|---|
2 | fb065187 | bellard | * QEMU Audio subsystem header
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | fb065187 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | fb065187 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | fb065187 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | fb065187 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | fb065187 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | fb065187 | bellard | * furnished to do so, subject to the following conditions:
|
12 | fb065187 | bellard | *
|
13 | fb065187 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | fb065187 | bellard | * all copies or substantial portions of the Software.
|
15 | fb065187 | bellard | *
|
16 | fb065187 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | fb065187 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | fb065187 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | fb065187 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | fb065187 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | fb065187 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | fb065187 | bellard | * THE SOFTWARE.
|
23 | fb065187 | bellard | */
|
24 | fb065187 | bellard | #ifndef QEMU_AUDIO_INT_H
|
25 | fb065187 | bellard | #define QEMU_AUDIO_INT_H
|
26 | fb065187 | bellard | |
27 | 1d14ffa9 | bellard | #ifdef CONFIG_COREAUDIO
|
28 | 1d14ffa9 | bellard | #define FLOAT_MIXENG
|
29 | 1d14ffa9 | bellard | /* #define RECIPROCAL */
|
30 | 1d14ffa9 | bellard | #endif
|
31 | 1d14ffa9 | bellard | #include "mixeng.h" |
32 | 1d14ffa9 | bellard | |
33 | 1d14ffa9 | bellard | struct audio_pcm_ops;
|
34 | 1d14ffa9 | bellard | |
35 | 1d14ffa9 | bellard | typedef enum { |
36 | 1d14ffa9 | bellard | AUD_OPT_INT, |
37 | 1d14ffa9 | bellard | AUD_OPT_FMT, |
38 | 1d14ffa9 | bellard | AUD_OPT_STR, |
39 | 1d14ffa9 | bellard | AUD_OPT_BOOL |
40 | 1d14ffa9 | bellard | } audio_option_tag_e; |
41 | 1d14ffa9 | bellard | |
42 | 1d14ffa9 | bellard | struct audio_option {
|
43 | 1d14ffa9 | bellard | const char *name; |
44 | 1d14ffa9 | bellard | audio_option_tag_e tag; |
45 | 1d14ffa9 | bellard | void *valp;
|
46 | 1d14ffa9 | bellard | const char *descr; |
47 | fe8f096b | ths | int *overriddenp;
|
48 | fe8f096b | ths | int overridden;
|
49 | 1d14ffa9 | bellard | }; |
50 | 1d14ffa9 | bellard | |
51 | 1d14ffa9 | bellard | struct audio_callback {
|
52 | 1d14ffa9 | bellard | void *opaque;
|
53 | 1d14ffa9 | bellard | audio_callback_fn_t fn; |
54 | 1d14ffa9 | bellard | }; |
55 | fb065187 | bellard | |
56 | 1d14ffa9 | bellard | struct audio_pcm_info {
|
57 | 1d14ffa9 | bellard | int bits;
|
58 | 1d14ffa9 | bellard | int sign;
|
59 | 1d14ffa9 | bellard | int freq;
|
60 | 1d14ffa9 | bellard | int nchannels;
|
61 | 1d14ffa9 | bellard | int align;
|
62 | 1d14ffa9 | bellard | int shift;
|
63 | 1d14ffa9 | bellard | int bytes_per_second;
|
64 | d929eba5 | bellard | int swap_endianness;
|
65 | 1d14ffa9 | bellard | }; |
66 | fb065187 | bellard | |
67 | ec36b695 | bellard | typedef struct SWVoiceCap SWVoiceCap; |
68 | ec36b695 | bellard | |
69 | 1d14ffa9 | bellard | typedef struct HWVoiceOut { |
70 | fb065187 | bellard | int enabled;
|
71 | fb065187 | bellard | int pending_disable;
|
72 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
73 | fb065187 | bellard | |
74 | fb065187 | bellard | f_sample *clip; |
75 | fb065187 | bellard | |
76 | fb065187 | bellard | int rpos;
|
77 | 1d14ffa9 | bellard | uint64_t ts_helper; |
78 | fb065187 | bellard | |
79 | fb065187 | bellard | st_sample_t *mix_buf; |
80 | fb065187 | bellard | |
81 | fb065187 | bellard | int samples;
|
82 | 1d14ffa9 | bellard | LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; |
83 | ec36b695 | bellard | LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head; |
84 | 1d14ffa9 | bellard | struct audio_pcm_ops *pcm_ops;
|
85 | 1d14ffa9 | bellard | LIST_ENTRY (HWVoiceOut) entries; |
86 | 1d14ffa9 | bellard | } HWVoiceOut; |
87 | fb065187 | bellard | |
88 | 1d14ffa9 | bellard | typedef struct HWVoiceIn { |
89 | 1d14ffa9 | bellard | int enabled;
|
90 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
91 | 1d14ffa9 | bellard | |
92 | 1d14ffa9 | bellard | t_sample *conv; |
93 | 7372f88d | bellard | |
94 | 1d14ffa9 | bellard | int wpos;
|
95 | 1d14ffa9 | bellard | int total_samples_captured;
|
96 | 1d14ffa9 | bellard | uint64_t ts_helper; |
97 | fb065187 | bellard | |
98 | 1d14ffa9 | bellard | st_sample_t *conv_buf; |
99 | fb065187 | bellard | |
100 | 1d14ffa9 | bellard | int samples;
|
101 | 1d14ffa9 | bellard | LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head; |
102 | 1d14ffa9 | bellard | struct audio_pcm_ops *pcm_ops;
|
103 | 1d14ffa9 | bellard | LIST_ENTRY (HWVoiceIn) entries; |
104 | 1d14ffa9 | bellard | } HWVoiceIn; |
105 | fb065187 | bellard | |
106 | 1d14ffa9 | bellard | struct SWVoiceOut {
|
107 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
108 | fb065187 | bellard | t_sample *conv; |
109 | fb065187 | bellard | int64_t ratio; |
110 | fb065187 | bellard | st_sample_t *buf; |
111 | fb065187 | bellard | void *rate;
|
112 | 1d14ffa9 | bellard | int total_hw_samples_mixed;
|
113 | 1d14ffa9 | bellard | int active;
|
114 | 1d14ffa9 | bellard | int empty;
|
115 | 1d14ffa9 | bellard | HWVoiceOut *hw; |
116 | 1d14ffa9 | bellard | char *name;
|
117 | 1d14ffa9 | bellard | volume_t vol; |
118 | 1d14ffa9 | bellard | struct audio_callback callback;
|
119 | 1d14ffa9 | bellard | LIST_ENTRY (SWVoiceOut) entries; |
120 | 1d14ffa9 | bellard | }; |
121 | fb065187 | bellard | |
122 | 1d14ffa9 | bellard | struct SWVoiceIn {
|
123 | fb065187 | bellard | int active;
|
124 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
125 | 1d14ffa9 | bellard | int64_t ratio; |
126 | 1d14ffa9 | bellard | void *rate;
|
127 | 1d14ffa9 | bellard | int total_hw_samples_acquired;
|
128 | 571ec3d6 | bellard | st_sample_t *buf; |
129 | 1d14ffa9 | bellard | f_sample *clip; |
130 | 1d14ffa9 | bellard | HWVoiceIn *hw; |
131 | fb065187 | bellard | char *name;
|
132 | 1d14ffa9 | bellard | volume_t vol; |
133 | 1d14ffa9 | bellard | struct audio_callback callback;
|
134 | 1d14ffa9 | bellard | LIST_ENTRY (SWVoiceIn) entries; |
135 | fb065187 | bellard | }; |
136 | fb065187 | bellard | |
137 | c0fe3827 | bellard | struct audio_driver {
|
138 | c0fe3827 | bellard | const char *name; |
139 | c0fe3827 | bellard | const char *descr; |
140 | c0fe3827 | bellard | struct audio_option *options;
|
141 | c0fe3827 | bellard | void *(*init) (void); |
142 | c0fe3827 | bellard | void (*fini) (void *); |
143 | c0fe3827 | bellard | struct audio_pcm_ops *pcm_ops;
|
144 | c0fe3827 | bellard | int can_be_default;
|
145 | c0fe3827 | bellard | int max_voices_out;
|
146 | c0fe3827 | bellard | int max_voices_in;
|
147 | c0fe3827 | bellard | int voice_size_out;
|
148 | c0fe3827 | bellard | int voice_size_in;
|
149 | c0fe3827 | bellard | }; |
150 | c0fe3827 | bellard | |
151 | 1d14ffa9 | bellard | struct audio_pcm_ops {
|
152 | c0fe3827 | bellard | int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
|
153 | 1d14ffa9 | bellard | void (*fini_out)(HWVoiceOut *hw);
|
154 | 1d14ffa9 | bellard | int (*run_out) (HWVoiceOut *hw);
|
155 | 1d14ffa9 | bellard | int (*write) (SWVoiceOut *sw, void *buf, int size); |
156 | 1d14ffa9 | bellard | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); |
157 | 1d14ffa9 | bellard | |
158 | c0fe3827 | bellard | int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
|
159 | 1d14ffa9 | bellard | void (*fini_in) (HWVoiceIn *hw);
|
160 | 1d14ffa9 | bellard | int (*run_in) (HWVoiceIn *hw);
|
161 | 1d14ffa9 | bellard | int (*read) (SWVoiceIn *sw, void *buf, int size); |
162 | 1d14ffa9 | bellard | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); |
163 | fb065187 | bellard | }; |
164 | fb065187 | bellard | |
165 | 8ead62cf | bellard | struct capture_callback {
|
166 | 8ead62cf | bellard | struct audio_capture_ops ops;
|
167 | 8ead62cf | bellard | void *opaque;
|
168 | 8ead62cf | bellard | LIST_ENTRY (capture_callback) entries; |
169 | 8ead62cf | bellard | }; |
170 | 8ead62cf | bellard | |
171 | ec36b695 | bellard | struct CaptureVoiceOut {
|
172 | 8ead62cf | bellard | HWVoiceOut hw; |
173 | 8ead62cf | bellard | void *buf;
|
174 | 8ead62cf | bellard | LIST_HEAD (cb_listhead, capture_callback) cb_head; |
175 | 8ead62cf | bellard | LIST_ENTRY (CaptureVoiceOut) entries; |
176 | ec36b695 | bellard | }; |
177 | ec36b695 | bellard | |
178 | ec36b695 | bellard | struct SWVoiceCap {
|
179 | ec36b695 | bellard | SWVoiceOut sw; |
180 | ec36b695 | bellard | CaptureVoiceOut *cap; |
181 | ec36b695 | bellard | LIST_ENTRY (SWVoiceCap) entries; |
182 | ec36b695 | bellard | }; |
183 | 8ead62cf | bellard | |
184 | c0fe3827 | bellard | struct AudioState {
|
185 | c0fe3827 | bellard | struct audio_driver *drv;
|
186 | c0fe3827 | bellard | void *drv_opaque;
|
187 | c0fe3827 | bellard | |
188 | c0fe3827 | bellard | QEMUTimer *ts; |
189 | 8ead62cf | bellard | LIST_HEAD (card_listhead, QEMUSoundCard) card_head; |
190 | c0fe3827 | bellard | LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; |
191 | c0fe3827 | bellard | LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; |
192 | 8ead62cf | bellard | LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head; |
193 | c0fe3827 | bellard | int nb_hw_voices_out;
|
194 | c0fe3827 | bellard | int nb_hw_voices_in;
|
195 | c0fe3827 | bellard | }; |
196 | c0fe3827 | bellard | |
197 | c0fe3827 | bellard | extern struct audio_driver no_audio_driver; |
198 | c0fe3827 | bellard | extern struct audio_driver oss_audio_driver; |
199 | c0fe3827 | bellard | extern struct audio_driver sdl_audio_driver; |
200 | c0fe3827 | bellard | extern struct audio_driver wav_audio_driver; |
201 | c0fe3827 | bellard | extern struct audio_driver fmod_audio_driver; |
202 | c0fe3827 | bellard | extern struct audio_driver alsa_audio_driver; |
203 | c0fe3827 | bellard | extern struct audio_driver coreaudio_audio_driver; |
204 | c0fe3827 | bellard | extern struct audio_driver dsound_audio_driver; |
205 | ca9cc28c | balrog | extern struct audio_driver esd_audio_driver; |
206 | c0fe3827 | bellard | extern volume_t nominal_volume;
|
207 | c0fe3827 | bellard | |
208 | d929eba5 | bellard | void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as); |
209 | 1d14ffa9 | bellard | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
210 | 1d14ffa9 | bellard | |
211 | 1d14ffa9 | bellard | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); |
212 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
213 | 1d14ffa9 | bellard | |
214 | 1d14ffa9 | bellard | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); |
215 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
216 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live); |
217 | fb065187 | bellard | |
218 | c0fe3827 | bellard | int audio_bug (const char *funcname, int cond); |
219 | c0fe3827 | bellard | void *audio_calloc (const char *funcname, int nmemb, size_t size); |
220 | c0fe3827 | bellard | |
221 | fb065187 | bellard | #define VOICE_ENABLE 1 |
222 | fb065187 | bellard | #define VOICE_DISABLE 2 |
223 | fb065187 | bellard | |
224 | 1d14ffa9 | bellard | static inline int audio_ring_dist (int dst, int src, int len) |
225 | 1d14ffa9 | bellard | { |
226 | 1d14ffa9 | bellard | return (dst >= src) ? (dst - src) : (len - src + dst);
|
227 | 1d14ffa9 | bellard | } |
228 | 1d14ffa9 | bellard | |
229 | 1d14ffa9 | bellard | #if defined __GNUC__
|
230 | 1d14ffa9 | bellard | #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) |
231 | 1d14ffa9 | bellard | #define INIT_FIELD(f) . f
|
232 | 4787c71d | bellard | #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
233 | 1d14ffa9 | bellard | #else
|
234 | 1d14ffa9 | bellard | #define GCC_ATTR /**/ |
235 | 1d14ffa9 | bellard | #define INIT_FIELD(f) /**/ |
236 | 1d14ffa9 | bellard | #define GCC_FMT_ATTR(n, m)
|
237 | 1d14ffa9 | bellard | #endif
|
238 | 1d14ffa9 | bellard | |
239 | 1d14ffa9 | bellard | static void GCC_ATTR dolog (const char *fmt, ...) |
240 | 1d14ffa9 | bellard | { |
241 | 1d14ffa9 | bellard | va_list ap; |
242 | 1d14ffa9 | bellard | |
243 | 1d14ffa9 | bellard | va_start (ap, fmt); |
244 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
245 | 1d14ffa9 | bellard | va_end (ap); |
246 | 1d14ffa9 | bellard | } |
247 | 1d14ffa9 | bellard | |
248 | 1d14ffa9 | bellard | #ifdef DEBUG
|
249 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
250 | 1d14ffa9 | bellard | { |
251 | 1d14ffa9 | bellard | va_list ap; |
252 | 1d14ffa9 | bellard | |
253 | 1d14ffa9 | bellard | va_start (ap, fmt); |
254 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
255 | 1d14ffa9 | bellard | va_end (ap); |
256 | 1d14ffa9 | bellard | } |
257 | 1d14ffa9 | bellard | #else
|
258 | 1d14ffa9 | bellard | #if defined NDEBUG && defined __GNUC__
|
259 | 1d14ffa9 | bellard | #define ldebug(...)
|
260 | 1d14ffa9 | bellard | #elif defined NDEBUG && defined _MSC_VER
|
261 | 1d14ffa9 | bellard | #define ldebug __noop
|
262 | 1d14ffa9 | bellard | #else
|
263 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
264 | 1d14ffa9 | bellard | { |
265 | 1d14ffa9 | bellard | (void) fmt;
|
266 | 1d14ffa9 | bellard | } |
267 | 1d14ffa9 | bellard | #endif
|
268 | 1d14ffa9 | bellard | #endif
|
269 | 1d14ffa9 | bellard | |
270 | 1d14ffa9 | bellard | #undef GCC_ATTR
|
271 | 1d14ffa9 | bellard | |
272 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY_(n) #n |
273 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
274 | 1d14ffa9 | bellard | |
275 | 1d14ffa9 | bellard | #if defined _MSC_VER || defined __GNUC__
|
276 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FUNCTION__
|
277 | 1d14ffa9 | bellard | #else
|
278 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__) |
279 | 1d14ffa9 | bellard | #endif
|
280 | 1d14ffa9 | bellard | |
281 | fb065187 | bellard | #endif /* audio_int.h */ |