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