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