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 | #define FLOAT_MIXENG
|
---|
29 | /* #define RECIPROCAL */
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <limits.h>
|
---|
33 | #include "mixeng.h"
|
---|
34 |
|
---|
35 | #define qemu_malloc RTMemAlloc
|
---|
36 | #define qemu_mallocz RTMemAllocZ
|
---|
37 | #define qemu_free RTMemFree
|
---|
38 | #define qemu_strdup RTStrDup
|
---|
39 |
|
---|
40 | struct audio_pcm_ops;
|
---|
41 |
|
---|
42 | typedef enum {
|
---|
43 | AUD_OPT_INT,
|
---|
44 | AUD_OPT_FMT,
|
---|
45 | AUD_OPT_STR,
|
---|
46 | AUD_OPT_BOOL
|
---|
47 | } audio_option_tag_e;
|
---|
48 |
|
---|
49 | struct audio_option {
|
---|
50 | const char *name;
|
---|
51 | audio_option_tag_e tag;
|
---|
52 | void *valp;
|
---|
53 | const char *descr;
|
---|
54 | int *overridenp;
|
---|
55 | int overriden;
|
---|
56 | };
|
---|
57 |
|
---|
58 | struct audio_callback {
|
---|
59 | void *opaque;
|
---|
60 | audio_callback_fn_t fn;
|
---|
61 | };
|
---|
62 |
|
---|
63 | struct audio_pcm_info {
|
---|
64 | int bits;
|
---|
65 | int sign;
|
---|
66 | int freq;
|
---|
67 | int nchannels;
|
---|
68 | int align;
|
---|
69 | int shift;
|
---|
70 | int bytes_per_second;
|
---|
71 | int swap_endianness;
|
---|
72 | };
|
---|
73 |
|
---|
74 | typedef struct SWVoiceCap SWVoiceCap;
|
---|
75 |
|
---|
76 | typedef struct HWVoiceOut {
|
---|
77 | int enabled;
|
---|
78 | int pending_disable;
|
---|
79 | struct audio_pcm_info info;
|
---|
80 |
|
---|
81 | f_sample *clip;
|
---|
82 |
|
---|
83 | int rpos;
|
---|
84 | uint64_t ts_helper;
|
---|
85 |
|
---|
86 | st_sample_t *mix_buf;
|
---|
87 |
|
---|
88 | int samples;
|
---|
89 | LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
---|
90 | LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
|
---|
91 | struct audio_pcm_ops *pcm_ops;
|
---|
92 | LIST_ENTRY (HWVoiceOut) entries;
|
---|
93 | } HWVoiceOut;
|
---|
94 |
|
---|
95 | typedef struct HWVoiceIn {
|
---|
96 | int enabled;
|
---|
97 | struct audio_pcm_info info;
|
---|
98 |
|
---|
99 | t_sample *conv;
|
---|
100 |
|
---|
101 | int wpos;
|
---|
102 | int total_samples_captured;
|
---|
103 | uint64_t ts_helper;
|
---|
104 |
|
---|
105 | st_sample_t *conv_buf;
|
---|
106 |
|
---|
107 | int samples;
|
---|
108 | LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
---|
109 | struct audio_pcm_ops *pcm_ops;
|
---|
110 | LIST_ENTRY (HWVoiceIn) entries;
|
---|
111 | } HWVoiceIn;
|
---|
112 |
|
---|
113 | struct SWVoiceOut {
|
---|
114 | struct audio_pcm_info info;
|
---|
115 | t_sample *conv;
|
---|
116 | int64_t ratio;
|
---|
117 | st_sample_t *buf;
|
---|
118 | void *rate;
|
---|
119 | int total_hw_samples_mixed;
|
---|
120 | int active;
|
---|
121 | int empty;
|
---|
122 | HWVoiceOut *hw;
|
---|
123 | char *name;
|
---|
124 | volume_t vol;
|
---|
125 | struct audio_callback callback;
|
---|
126 | LIST_ENTRY (SWVoiceOut) entries;
|
---|
127 | };
|
---|
128 |
|
---|
129 | struct SWVoiceIn {
|
---|
130 | int active;
|
---|
131 | struct audio_pcm_info info;
|
---|
132 | int64_t ratio;
|
---|
133 | void *rate;
|
---|
134 | int total_hw_samples_acquired;
|
---|
135 | st_sample_t *buf;
|
---|
136 | f_sample *clip;
|
---|
137 | HWVoiceIn *hw;
|
---|
138 | char *name;
|
---|
139 | volume_t vol;
|
---|
140 | struct audio_callback callback;
|
---|
141 | LIST_ENTRY (SWVoiceIn) entries;
|
---|
142 | };
|
---|
143 |
|
---|
144 | struct audio_driver {
|
---|
145 | const char *name;
|
---|
146 | const char *descr;
|
---|
147 | struct audio_option *options;
|
---|
148 | void *(*init) (void);
|
---|
149 | void (*fini) (void *);
|
---|
150 | struct audio_pcm_ops *pcm_ops;
|
---|
151 | int can_be_default;
|
---|
152 | int max_voices_out;
|
---|
153 | int max_voices_in;
|
---|
154 | int voice_size_out;
|
---|
155 | int voice_size_in;
|
---|
156 | };
|
---|
157 |
|
---|
158 | struct audio_pcm_ops {
|
---|
159 | int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
|
---|
160 | void (*fini_out)(HWVoiceOut *hw);
|
---|
161 | int (*run_out) (HWVoiceOut *hw);
|
---|
162 | int (*write) (SWVoiceOut *sw, void *buf, int size);
|
---|
163 | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
---|
164 |
|
---|
165 | int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
|
---|
166 | void (*fini_in) (HWVoiceIn *hw);
|
---|
167 | int (*run_in) (HWVoiceIn *hw);
|
---|
168 | int (*read) (SWVoiceIn *sw, void *buf, int size);
|
---|
169 | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
---|
170 | };
|
---|
171 |
|
---|
172 | struct capture_callback {
|
---|
173 | struct audio_capture_ops ops;
|
---|
174 | void *opaque;
|
---|
175 | LIST_ENTRY (capture_callback) entries;
|
---|
176 | };
|
---|
177 |
|
---|
178 | struct CaptureVoiceOut {
|
---|
179 | HWVoiceOut hw;
|
---|
180 | void *buf;
|
---|
181 | LIST_HEAD (cb_listhead, capture_callback) cb_head;
|
---|
182 | LIST_ENTRY (CaptureVoiceOut) entries;
|
---|
183 | };
|
---|
184 |
|
---|
185 | struct SWVoiceCap {
|
---|
186 | SWVoiceOut sw;
|
---|
187 | CaptureVoiceOut *cap;
|
---|
188 | LIST_ENTRY (SWVoiceCap) entries;
|
---|
189 | };
|
---|
190 |
|
---|
191 | struct AudioState {
|
---|
192 | struct audio_driver *drv;
|
---|
193 | void *drv_opaque;
|
---|
194 |
|
---|
195 | QEMUTimer *ts;
|
---|
196 | LIST_HEAD (card_listhead, QEMUSoundCard) card_head;
|
---|
197 | LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
|
---|
198 | LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
|
---|
199 | LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
|
---|
200 | int nb_hw_voices_out;
|
---|
201 | int nb_hw_voices_in;
|
---|
202 | PPDMDRVINS pDrvIns;
|
---|
203 | };
|
---|
204 |
|
---|
205 | extern struct audio_driver no_audio_driver;
|
---|
206 | extern struct audio_driver oss_audio_driver;
|
---|
207 | extern struct audio_driver sdl_audio_driver;
|
---|
208 | extern struct audio_driver wav_audio_driver;
|
---|
209 | extern struct audio_driver fmod_audio_driver;
|
---|
210 | extern struct audio_driver alsa_audio_driver;
|
---|
211 | extern struct audio_driver coreaudio_audio_driver;
|
---|
212 | extern struct audio_driver dsound_audio_driver;
|
---|
213 | extern volume_t nominal_volume;
|
---|
214 |
|
---|
215 | uint64_t audio_get_clock (void);
|
---|
216 | uint64_t audio_get_ticks_per_sec (void);
|
---|
217 |
|
---|
218 | void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
|
---|
219 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
---|
220 |
|
---|
221 | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
---|
222 | int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
---|
223 |
|
---|
224 | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
---|
225 | int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
---|
226 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
|
---|
227 |
|
---|
228 | int audio_bug (const char *funcname, int cond);
|
---|
229 | void *audio_calloc (const char *funcname, int nmemb, size_t size);
|
---|
230 |
|
---|
231 | #define VOICE_ENABLE 1
|
---|
232 | #define VOICE_DISABLE 2
|
---|
233 |
|
---|
234 | static inline int audio_ring_dist (int dst, int src, int len)
|
---|
235 | {
|
---|
236 | return (dst >= src) ? (dst - src) : (len - src + dst);
|
---|
237 | }
|
---|
238 |
|
---|
239 | #if defined __GNUC__
|
---|
240 | #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
|
---|
241 | #if __STDC_VERSION__ > 199901L
|
---|
242 | #define INIT_FIELD(f) . f
|
---|
243 | #else
|
---|
244 | #define INIT_FIELD(f) /**/
|
---|
245 | #endif
|
---|
246 | #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
---|
247 | #else
|
---|
248 | #define GCC_ATTR /**/
|
---|
249 | #define INIT_FIELD(f) /**/
|
---|
250 | #define GCC_FMT_ATTR(n, m)
|
---|
251 | #endif
|
---|
252 |
|
---|
253 | static void GCC_ATTR dolog (const char *fmt, ...)
|
---|
254 | {
|
---|
255 | va_list ap;
|
---|
256 |
|
---|
257 | va_start (ap, fmt);
|
---|
258 | AUD_vlog (AUDIO_CAP, fmt, ap);
|
---|
259 | va_end (ap);
|
---|
260 | }
|
---|
261 |
|
---|
262 | #ifdef DEBUG
|
---|
263 | static void GCC_ATTR ldebug (const char *fmt, ...)
|
---|
264 | {
|
---|
265 | va_list ap;
|
---|
266 |
|
---|
267 | va_start (ap, fmt);
|
---|
268 | AUD_vlog (AUDIO_CAP, fmt, ap);
|
---|
269 | va_end (ap);
|
---|
270 | }
|
---|
271 | #else
|
---|
272 | #if defined NDEBUG && defined __GNUC__
|
---|
273 | #define ldebug(...)
|
---|
274 | #elif defined NDEBUG && defined _MSC_VER
|
---|
275 | #define ldebug __noop
|
---|
276 | #else
|
---|
277 | static void GCC_ATTR ldebug (const char *fmt, ...)
|
---|
278 | {
|
---|
279 | (void) fmt;
|
---|
280 | }
|
---|
281 | #endif
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | #undef GCC_ATTR
|
---|
285 |
|
---|
286 | #define AUDIO_STRINGIFY_(n) #n
|
---|
287 | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
---|
288 |
|
---|
289 | #if defined _MSC_VER || defined __GNUC__
|
---|
290 | #define AUDIO_FUNC __FUNCTION__
|
---|
291 | #else
|
---|
292 | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
|
---|
293 | #endif
|
---|
294 |
|
---|
295 | DECLCALLBACK(bool) sniffer_run_out (HWVoiceOut *hw, void *pvSamples,
|
---|
296 | unsigned cSamples);
|
---|
297 |
|
---|
298 | #endif /* audio_int.h */
|
---|