root / audio / audio_int.h @ 64e58fe5
History | View | Annotate | Download (7.2 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 | cb4f03e8 | malc | audio_callback_fn 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 | 713a98f8 | malc | int poll_mode;
|
72 | fb065187 | bellard | int pending_disable;
|
73 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
74 | fb065187 | bellard | |
75 | fb065187 | bellard | f_sample *clip; |
76 | fb065187 | bellard | |
77 | fb065187 | bellard | int rpos;
|
78 | 1d14ffa9 | bellard | uint64_t ts_helper; |
79 | fb065187 | bellard | |
80 | 1ea879e5 | malc | struct st_sample *mix_buf;
|
81 | fb065187 | bellard | |
82 | fb065187 | bellard | int samples;
|
83 | 72cf2d4f | Blue Swirl | QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; |
84 | 72cf2d4f | Blue Swirl | QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head; |
85 | 35f4b58c | blueswir1 | struct audio_pcm_ops *pcm_ops;
|
86 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (HWVoiceOut) entries; |
87 | 1d14ffa9 | bellard | } HWVoiceOut; |
88 | fb065187 | bellard | |
89 | 1d14ffa9 | bellard | typedef struct HWVoiceIn { |
90 | 1d14ffa9 | bellard | int enabled;
|
91 | 713a98f8 | malc | int poll_mode;
|
92 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
93 | 1d14ffa9 | bellard | |
94 | 1d14ffa9 | bellard | t_sample *conv; |
95 | 7372f88d | bellard | |
96 | 1d14ffa9 | bellard | int wpos;
|
97 | 1d14ffa9 | bellard | int total_samples_captured;
|
98 | 1d14ffa9 | bellard | uint64_t ts_helper; |
99 | fb065187 | bellard | |
100 | 1ea879e5 | malc | struct st_sample *conv_buf;
|
101 | fb065187 | bellard | |
102 | 1d14ffa9 | bellard | int samples;
|
103 | 72cf2d4f | Blue Swirl | QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head; |
104 | 35f4b58c | blueswir1 | struct audio_pcm_ops *pcm_ops;
|
105 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (HWVoiceIn) entries; |
106 | 1d14ffa9 | bellard | } HWVoiceIn; |
107 | fb065187 | bellard | |
108 | 1d14ffa9 | bellard | struct SWVoiceOut {
|
109 | 1a7dafce | malc | QEMUSoundCard *card; |
110 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
111 | fb065187 | bellard | t_sample *conv; |
112 | fb065187 | bellard | int64_t ratio; |
113 | 1ea879e5 | malc | struct st_sample *buf;
|
114 | fb065187 | bellard | void *rate;
|
115 | 1d14ffa9 | bellard | int total_hw_samples_mixed;
|
116 | 1d14ffa9 | bellard | int active;
|
117 | 1d14ffa9 | bellard | int empty;
|
118 | 1d14ffa9 | bellard | HWVoiceOut *hw; |
119 | 1d14ffa9 | bellard | char *name;
|
120 | 1ea879e5 | malc | struct mixeng_volume vol;
|
121 | 1d14ffa9 | bellard | struct audio_callback callback;
|
122 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (SWVoiceOut) entries; |
123 | 1d14ffa9 | bellard | }; |
124 | fb065187 | bellard | |
125 | 1d14ffa9 | bellard | struct SWVoiceIn {
|
126 | 1a7dafce | malc | QEMUSoundCard *card; |
127 | fb065187 | bellard | int active;
|
128 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
129 | 1d14ffa9 | bellard | int64_t ratio; |
130 | 1d14ffa9 | bellard | void *rate;
|
131 | 1d14ffa9 | bellard | int total_hw_samples_acquired;
|
132 | 1ea879e5 | malc | struct st_sample *buf;
|
133 | 1d14ffa9 | bellard | f_sample *clip; |
134 | 1d14ffa9 | bellard | HWVoiceIn *hw; |
135 | fb065187 | bellard | char *name;
|
136 | 1ea879e5 | malc | struct mixeng_volume vol;
|
137 | 1d14ffa9 | bellard | struct audio_callback callback;
|
138 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (SWVoiceIn) entries; |
139 | fb065187 | bellard | }; |
140 | fb065187 | bellard | |
141 | c0fe3827 | bellard | struct audio_driver {
|
142 | c0fe3827 | bellard | const char *name; |
143 | c0fe3827 | bellard | const char *descr; |
144 | c0fe3827 | bellard | struct audio_option *options;
|
145 | c0fe3827 | bellard | void *(*init) (void); |
146 | c0fe3827 | bellard | void (*fini) (void *); |
147 | 35f4b58c | blueswir1 | struct audio_pcm_ops *pcm_ops;
|
148 | c0fe3827 | bellard | int can_be_default;
|
149 | c0fe3827 | bellard | int max_voices_out;
|
150 | c0fe3827 | bellard | int max_voices_in;
|
151 | c0fe3827 | bellard | int voice_size_out;
|
152 | c0fe3827 | bellard | int voice_size_in;
|
153 | c0fe3827 | bellard | }; |
154 | c0fe3827 | bellard | |
155 | 1d14ffa9 | bellard | struct audio_pcm_ops {
|
156 | 1ea879e5 | malc | int (*init_out)(HWVoiceOut *hw, struct audsettings *as); |
157 | 1d14ffa9 | bellard | void (*fini_out)(HWVoiceOut *hw);
|
158 | bdff253c | malc | int (*run_out) (HWVoiceOut *hw, int live); |
159 | 1d14ffa9 | bellard | int (*write) (SWVoiceOut *sw, void *buf, int size); |
160 | 1d14ffa9 | bellard | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); |
161 | 1d14ffa9 | bellard | |
162 | 1ea879e5 | malc | int (*init_in) (HWVoiceIn *hw, struct audsettings *as); |
163 | 1d14ffa9 | bellard | void (*fini_in) (HWVoiceIn *hw);
|
164 | 1d14ffa9 | bellard | int (*run_in) (HWVoiceIn *hw);
|
165 | 1d14ffa9 | bellard | int (*read) (SWVoiceIn *sw, void *buf, int size); |
166 | 1d14ffa9 | bellard | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); |
167 | fb065187 | bellard | }; |
168 | fb065187 | bellard | |
169 | 8ead62cf | bellard | struct capture_callback {
|
170 | 8ead62cf | bellard | struct audio_capture_ops ops;
|
171 | 8ead62cf | bellard | void *opaque;
|
172 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (capture_callback) entries; |
173 | 8ead62cf | bellard | }; |
174 | 8ead62cf | bellard | |
175 | ec36b695 | bellard | struct CaptureVoiceOut {
|
176 | 8ead62cf | bellard | HWVoiceOut hw; |
177 | 8ead62cf | bellard | void *buf;
|
178 | 72cf2d4f | Blue Swirl | QLIST_HEAD (cb_listhead, capture_callback) cb_head; |
179 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (CaptureVoiceOut) entries; |
180 | ec36b695 | bellard | }; |
181 | ec36b695 | bellard | |
182 | ec36b695 | bellard | struct SWVoiceCap {
|
183 | ec36b695 | bellard | SWVoiceOut sw; |
184 | ec36b695 | bellard | CaptureVoiceOut *cap; |
185 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (SWVoiceCap) entries; |
186 | ec36b695 | bellard | }; |
187 | 8ead62cf | bellard | |
188 | c0fe3827 | bellard | struct AudioState {
|
189 | c0fe3827 | bellard | struct audio_driver *drv;
|
190 | c0fe3827 | bellard | void *drv_opaque;
|
191 | c0fe3827 | bellard | |
192 | c0fe3827 | bellard | QEMUTimer *ts; |
193 | 72cf2d4f | Blue Swirl | QLIST_HEAD (card_listhead, QEMUSoundCard) card_head; |
194 | 72cf2d4f | Blue Swirl | QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; |
195 | 72cf2d4f | Blue Swirl | QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; |
196 | 72cf2d4f | Blue Swirl | QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head; |
197 | c0fe3827 | bellard | int nb_hw_voices_out;
|
198 | c0fe3827 | bellard | int nb_hw_voices_in;
|
199 | 978dd635 | malc | int vm_running;
|
200 | c0fe3827 | bellard | }; |
201 | c0fe3827 | bellard | |
202 | c0fe3827 | bellard | extern struct audio_driver no_audio_driver; |
203 | c0fe3827 | bellard | extern struct audio_driver oss_audio_driver; |
204 | c0fe3827 | bellard | extern struct audio_driver sdl_audio_driver; |
205 | c0fe3827 | bellard | extern struct audio_driver wav_audio_driver; |
206 | c0fe3827 | bellard | extern struct audio_driver fmod_audio_driver; |
207 | c0fe3827 | bellard | extern struct audio_driver alsa_audio_driver; |
208 | c0fe3827 | bellard | extern struct audio_driver coreaudio_audio_driver; |
209 | c0fe3827 | bellard | extern struct audio_driver dsound_audio_driver; |
210 | ca9cc28c | balrog | extern struct audio_driver esd_audio_driver; |
211 | b8e59f18 | malc | extern struct audio_driver pa_audio_driver; |
212 | d5631638 | malc | extern struct audio_driver winwave_audio_driver; |
213 | 1ea879e5 | malc | extern struct mixeng_volume nominal_volume; |
214 | c0fe3827 | bellard | |
215 | 1ea879e5 | malc | void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as); |
216 | 1d14ffa9 | bellard | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
217 | 1d14ffa9 | bellard | |
218 | 1d14ffa9 | bellard | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); |
219 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
220 | 1d14ffa9 | bellard | |
221 | 1d14ffa9 | bellard | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); |
222 | fb065187 | bellard | |
223 | ddabec73 | malc | int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf, |
224 | ddabec73 | malc | int live, int pending); |
225 | ddabec73 | malc | |
226 | c0fe3827 | bellard | int audio_bug (const char *funcname, int cond); |
227 | c0fe3827 | bellard | void *audio_calloc (const char *funcname, int nmemb, size_t size); |
228 | c0fe3827 | bellard | |
229 | 713a98f8 | malc | void audio_run (const char *msg); |
230 | 713a98f8 | malc | |
231 | fb065187 | bellard | #define VOICE_ENABLE 1 |
232 | fb065187 | bellard | #define VOICE_DISABLE 2 |
233 | fb065187 | bellard | |
234 | 1d14ffa9 | bellard | static inline int audio_ring_dist (int dst, int src, int len) |
235 | 1d14ffa9 | bellard | { |
236 | 1d14ffa9 | bellard | return (dst >= src) ? (dst - src) : (len - src + dst);
|
237 | 1d14ffa9 | bellard | } |
238 | 1d14ffa9 | bellard | |
239 | 1d14ffa9 | bellard | #if defined __GNUC__
|
240 | 1d14ffa9 | bellard | #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) |
241 | 4787c71d | bellard | #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
242 | 1d14ffa9 | bellard | #else
|
243 | 1d14ffa9 | bellard | #define GCC_ATTR /**/ |
244 | 1d14ffa9 | bellard | #define GCC_FMT_ATTR(n, m)
|
245 | 1d14ffa9 | bellard | #endif
|
246 | 1d14ffa9 | bellard | |
247 | 1d14ffa9 | bellard | static void GCC_ATTR dolog (const char *fmt, ...) |
248 | 1d14ffa9 | bellard | { |
249 | 1d14ffa9 | bellard | va_list ap; |
250 | 1d14ffa9 | bellard | |
251 | 1d14ffa9 | bellard | va_start (ap, fmt); |
252 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
253 | 1d14ffa9 | bellard | va_end (ap); |
254 | 1d14ffa9 | bellard | } |
255 | 1d14ffa9 | bellard | |
256 | 1d14ffa9 | bellard | #ifdef DEBUG
|
257 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
258 | 1d14ffa9 | bellard | { |
259 | 1d14ffa9 | bellard | va_list ap; |
260 | 1d14ffa9 | bellard | |
261 | 1d14ffa9 | bellard | va_start (ap, fmt); |
262 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
263 | 1d14ffa9 | bellard | va_end (ap); |
264 | 1d14ffa9 | bellard | } |
265 | 1d14ffa9 | bellard | #else
|
266 | 1d14ffa9 | bellard | #if defined NDEBUG && defined __GNUC__
|
267 | 1d14ffa9 | bellard | #define ldebug(...)
|
268 | 1d14ffa9 | bellard | #elif defined NDEBUG && defined _MSC_VER
|
269 | 1d14ffa9 | bellard | #define ldebug __noop
|
270 | 1d14ffa9 | bellard | #else
|
271 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
272 | 1d14ffa9 | bellard | { |
273 | 1d14ffa9 | bellard | (void) fmt;
|
274 | 1d14ffa9 | bellard | } |
275 | 1d14ffa9 | bellard | #endif
|
276 | 1d14ffa9 | bellard | #endif
|
277 | 1d14ffa9 | bellard | |
278 | 1d14ffa9 | bellard | #undef GCC_ATTR
|
279 | 1d14ffa9 | bellard | |
280 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY_(n) #n |
281 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
282 | 1d14ffa9 | bellard | |
283 | 1d14ffa9 | bellard | #if defined _MSC_VER || defined __GNUC__
|
284 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FUNCTION__
|
285 | 1d14ffa9 | bellard | #else
|
286 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__) |
287 | 1d14ffa9 | bellard | #endif
|
288 | 1d14ffa9 | bellard | |
289 | fb065187 | bellard | #endif /* audio_int.h */ |