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