root / audio / audio_int.h @ c0fe3827
History | View | Annotate | Download (6.6 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 | 1d14ffa9 | bellard | int *overridenp;
|
48 | 1d14ffa9 | bellard | int overriden;
|
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 | 1d14ffa9 | bellard | int swap_endian;
|
65 | 1d14ffa9 | bellard | }; |
66 | fb065187 | bellard | |
67 | 1d14ffa9 | bellard | typedef struct HWVoiceOut { |
68 | fb065187 | bellard | int enabled;
|
69 | fb065187 | bellard | int pending_disable;
|
70 | fb065187 | bellard | int valid;
|
71 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
72 | fb065187 | bellard | |
73 | fb065187 | bellard | f_sample *clip; |
74 | fb065187 | bellard | |
75 | fb065187 | bellard | int rpos;
|
76 | 1d14ffa9 | bellard | uint64_t ts_helper; |
77 | fb065187 | bellard | |
78 | fb065187 | bellard | st_sample_t *mix_buf; |
79 | fb065187 | bellard | |
80 | fb065187 | bellard | int samples;
|
81 | 1d14ffa9 | bellard | LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; |
82 | 1d14ffa9 | bellard | struct audio_pcm_ops *pcm_ops;
|
83 | 1d14ffa9 | bellard | LIST_ENTRY (HWVoiceOut) entries; |
84 | 1d14ffa9 | bellard | } HWVoiceOut; |
85 | fb065187 | bellard | |
86 | 1d14ffa9 | bellard | typedef struct HWVoiceIn { |
87 | 1d14ffa9 | bellard | int enabled;
|
88 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
89 | 1d14ffa9 | bellard | |
90 | 1d14ffa9 | bellard | t_sample *conv; |
91 | 7372f88d | bellard | |
92 | 1d14ffa9 | bellard | int wpos;
|
93 | 1d14ffa9 | bellard | int total_samples_captured;
|
94 | 1d14ffa9 | bellard | uint64_t ts_helper; |
95 | fb065187 | bellard | |
96 | 1d14ffa9 | bellard | st_sample_t *conv_buf; |
97 | fb065187 | bellard | |
98 | 1d14ffa9 | bellard | int samples;
|
99 | 1d14ffa9 | bellard | LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head; |
100 | 1d14ffa9 | bellard | struct audio_pcm_ops *pcm_ops;
|
101 | 1d14ffa9 | bellard | LIST_ENTRY (HWVoiceIn) entries; |
102 | 1d14ffa9 | bellard | } HWVoiceIn; |
103 | fb065187 | bellard | |
104 | 1d14ffa9 | bellard | struct SWVoiceOut {
|
105 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
106 | fb065187 | bellard | t_sample *conv; |
107 | fb065187 | bellard | int64_t ratio; |
108 | fb065187 | bellard | st_sample_t *buf; |
109 | fb065187 | bellard | void *rate;
|
110 | 1d14ffa9 | bellard | int total_hw_samples_mixed;
|
111 | 1d14ffa9 | bellard | int active;
|
112 | 1d14ffa9 | bellard | int empty;
|
113 | 1d14ffa9 | bellard | HWVoiceOut *hw; |
114 | 1d14ffa9 | bellard | char *name;
|
115 | 1d14ffa9 | bellard | volume_t vol; |
116 | 1d14ffa9 | bellard | struct audio_callback callback;
|
117 | 1d14ffa9 | bellard | LIST_ENTRY (SWVoiceOut) entries; |
118 | 1d14ffa9 | bellard | }; |
119 | fb065187 | bellard | |
120 | 1d14ffa9 | bellard | struct SWVoiceIn {
|
121 | fb065187 | bellard | int active;
|
122 | 1d14ffa9 | bellard | struct audio_pcm_info info;
|
123 | 1d14ffa9 | bellard | int64_t ratio; |
124 | 1d14ffa9 | bellard | void *rate;
|
125 | 1d14ffa9 | bellard | int total_hw_samples_acquired;
|
126 | 1d14ffa9 | bellard | st_sample_t *conv_buf; |
127 | 1d14ffa9 | bellard | f_sample *clip; |
128 | 1d14ffa9 | bellard | HWVoiceIn *hw; |
129 | fb065187 | bellard | char *name;
|
130 | 1d14ffa9 | bellard | volume_t vol; |
131 | 1d14ffa9 | bellard | struct audio_callback callback;
|
132 | 1d14ffa9 | bellard | LIST_ENTRY (SWVoiceIn) entries; |
133 | fb065187 | bellard | }; |
134 | fb065187 | bellard | |
135 | c0fe3827 | bellard | struct audio_driver {
|
136 | c0fe3827 | bellard | const char *name; |
137 | c0fe3827 | bellard | const char *descr; |
138 | c0fe3827 | bellard | struct audio_option *options;
|
139 | c0fe3827 | bellard | void *(*init) (void); |
140 | c0fe3827 | bellard | void (*fini) (void *); |
141 | c0fe3827 | bellard | struct audio_pcm_ops *pcm_ops;
|
142 | c0fe3827 | bellard | int can_be_default;
|
143 | c0fe3827 | bellard | int max_voices_out;
|
144 | c0fe3827 | bellard | int max_voices_in;
|
145 | c0fe3827 | bellard | int voice_size_out;
|
146 | c0fe3827 | bellard | int voice_size_in;
|
147 | c0fe3827 | bellard | }; |
148 | c0fe3827 | bellard | |
149 | 1d14ffa9 | bellard | struct audio_pcm_ops {
|
150 | c0fe3827 | bellard | int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
|
151 | 1d14ffa9 | bellard | void (*fini_out)(HWVoiceOut *hw);
|
152 | 1d14ffa9 | bellard | int (*run_out) (HWVoiceOut *hw);
|
153 | 1d14ffa9 | bellard | int (*write) (SWVoiceOut *sw, void *buf, int size); |
154 | 1d14ffa9 | bellard | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); |
155 | 1d14ffa9 | bellard | |
156 | c0fe3827 | bellard | int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
|
157 | 1d14ffa9 | bellard | void (*fini_in) (HWVoiceIn *hw);
|
158 | 1d14ffa9 | bellard | int (*run_in) (HWVoiceIn *hw);
|
159 | 1d14ffa9 | bellard | int (*read) (SWVoiceIn *sw, void *buf, int size); |
160 | 1d14ffa9 | bellard | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); |
161 | fb065187 | bellard | }; |
162 | fb065187 | bellard | |
163 | c0fe3827 | bellard | struct AudioState {
|
164 | c0fe3827 | bellard | struct audio_driver *drv;
|
165 | c0fe3827 | bellard | void *drv_opaque;
|
166 | c0fe3827 | bellard | |
167 | c0fe3827 | bellard | QEMUTimer *ts; |
168 | c0fe3827 | bellard | LIST_HEAD (card_head, QEMUSoundCard) card_head; |
169 | c0fe3827 | bellard | LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; |
170 | c0fe3827 | bellard | LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; |
171 | c0fe3827 | bellard | int nb_hw_voices_out;
|
172 | c0fe3827 | bellard | int nb_hw_voices_in;
|
173 | c0fe3827 | bellard | }; |
174 | c0fe3827 | bellard | |
175 | c0fe3827 | bellard | extern struct audio_driver no_audio_driver; |
176 | c0fe3827 | bellard | extern struct audio_driver oss_audio_driver; |
177 | c0fe3827 | bellard | extern struct audio_driver sdl_audio_driver; |
178 | c0fe3827 | bellard | extern struct audio_driver wav_audio_driver; |
179 | c0fe3827 | bellard | extern struct audio_driver fmod_audio_driver; |
180 | c0fe3827 | bellard | extern struct audio_driver alsa_audio_driver; |
181 | c0fe3827 | bellard | extern struct audio_driver coreaudio_audio_driver; |
182 | c0fe3827 | bellard | extern struct audio_driver dsound_audio_driver; |
183 | c0fe3827 | bellard | extern volume_t nominal_volume;
|
184 | c0fe3827 | bellard | |
185 | c0fe3827 | bellard | void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as, |
186 | c0fe3827 | bellard | int swap_endian);
|
187 | 1d14ffa9 | bellard | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
188 | 1d14ffa9 | bellard | |
189 | 1d14ffa9 | bellard | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); |
190 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
191 | 1d14ffa9 | bellard | |
192 | 1d14ffa9 | bellard | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); |
193 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
194 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live); |
195 | fb065187 | bellard | |
196 | c0fe3827 | bellard | int audio_bug (const char *funcname, int cond); |
197 | c0fe3827 | bellard | void *audio_calloc (const char *funcname, int nmemb, size_t size); |
198 | c0fe3827 | bellard | |
199 | fb065187 | bellard | #define VOICE_ENABLE 1 |
200 | fb065187 | bellard | #define VOICE_DISABLE 2 |
201 | fb065187 | bellard | |
202 | 1d14ffa9 | bellard | static inline int audio_ring_dist (int dst, int src, int len) |
203 | 1d14ffa9 | bellard | { |
204 | 1d14ffa9 | bellard | return (dst >= src) ? (dst - src) : (len - src + dst);
|
205 | 1d14ffa9 | bellard | } |
206 | 1d14ffa9 | bellard | |
207 | 1d14ffa9 | bellard | static inline int audio_need_to_swap_endian (int endianness) |
208 | 1d14ffa9 | bellard | { |
209 | 1d14ffa9 | bellard | #ifdef WORDS_BIGENDIAN
|
210 | 1d14ffa9 | bellard | return endianness != 1; |
211 | 1d14ffa9 | bellard | #else
|
212 | 1d14ffa9 | bellard | return endianness != 0; |
213 | 1d14ffa9 | bellard | #endif
|
214 | 1d14ffa9 | bellard | } |
215 | 1d14ffa9 | bellard | |
216 | 1d14ffa9 | bellard | #if defined __GNUC__
|
217 | 1d14ffa9 | bellard | #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) |
218 | 1d14ffa9 | bellard | #define INIT_FIELD(f) . f
|
219 | 1d14ffa9 | bellard | #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (printf, n, m)))
|
220 | 1d14ffa9 | bellard | #else
|
221 | 1d14ffa9 | bellard | #define GCC_ATTR /**/ |
222 | 1d14ffa9 | bellard | #define INIT_FIELD(f) /**/ |
223 | 1d14ffa9 | bellard | #define GCC_FMT_ATTR(n, m)
|
224 | 1d14ffa9 | bellard | #endif
|
225 | 1d14ffa9 | bellard | |
226 | 1d14ffa9 | bellard | static void GCC_ATTR dolog (const char *fmt, ...) |
227 | 1d14ffa9 | bellard | { |
228 | 1d14ffa9 | bellard | va_list ap; |
229 | 1d14ffa9 | bellard | |
230 | 1d14ffa9 | bellard | va_start (ap, fmt); |
231 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
232 | 1d14ffa9 | bellard | va_end (ap); |
233 | 1d14ffa9 | bellard | } |
234 | 1d14ffa9 | bellard | |
235 | 1d14ffa9 | bellard | #ifdef DEBUG
|
236 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
237 | 1d14ffa9 | bellard | { |
238 | 1d14ffa9 | bellard | va_list ap; |
239 | 1d14ffa9 | bellard | |
240 | 1d14ffa9 | bellard | va_start (ap, fmt); |
241 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
242 | 1d14ffa9 | bellard | va_end (ap); |
243 | 1d14ffa9 | bellard | } |
244 | 1d14ffa9 | bellard | #else
|
245 | 1d14ffa9 | bellard | #if defined NDEBUG && defined __GNUC__
|
246 | 1d14ffa9 | bellard | #define ldebug(...)
|
247 | 1d14ffa9 | bellard | #elif defined NDEBUG && defined _MSC_VER
|
248 | 1d14ffa9 | bellard | #define ldebug __noop
|
249 | 1d14ffa9 | bellard | #else
|
250 | 1d14ffa9 | bellard | static void GCC_ATTR ldebug (const char *fmt, ...) |
251 | 1d14ffa9 | bellard | { |
252 | 1d14ffa9 | bellard | (void) fmt;
|
253 | 1d14ffa9 | bellard | } |
254 | 1d14ffa9 | bellard | #endif
|
255 | 1d14ffa9 | bellard | #endif
|
256 | 1d14ffa9 | bellard | |
257 | 1d14ffa9 | bellard | #undef GCC_ATTR
|
258 | 1d14ffa9 | bellard | |
259 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY_(n) #n |
260 | 1d14ffa9 | bellard | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
261 | 1d14ffa9 | bellard | |
262 | 1d14ffa9 | bellard | #if defined _MSC_VER || defined __GNUC__
|
263 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FUNCTION__
|
264 | 1d14ffa9 | bellard | #else
|
265 | 1d14ffa9 | bellard | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__) |
266 | 1d14ffa9 | bellard | #endif
|
267 | 1d14ffa9 | bellard | |
268 | fb065187 | bellard | #endif /* audio_int.h */ |