VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/audio_int.h@ 31713

Last change on this file since 31713 was 12977, checked in by vboxsync, 16 years ago

#1865: Updated PDMDEVREG with pfnSoftReset, u32VersionEnd and some flag/name cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
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
44struct audio_pcm_ops;
45
46typedef enum {
47 AUD_OPT_INT,
48 AUD_OPT_FMT,
49 AUD_OPT_STR,
50 AUD_OPT_BOOL
51} audio_option_tag_e;
52
53struct 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
62struct audio_callback {
63 void *opaque;
64 audio_callback_fn_t fn;
65};
66
67struct 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
78typedef struct SWVoiceCap SWVoiceCap;
79
80typedef 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
99typedef 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
117struct 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
133struct 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
148struct 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
162struct 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
176struct capture_callback {
177 struct audio_capture_ops ops;
178 void *opaque;
179 LIST_ENTRY (capture_callback) entries;
180};
181
182struct CaptureVoiceOut {
183 HWVoiceOut hw;
184 void *buf;
185 LIST_HEAD (cb_listhead, capture_callback) cb_head;
186 LIST_ENTRY (CaptureVoiceOut) entries;
187};
188
189struct SWVoiceCap {
190 SWVoiceOut sw;
191 CaptureVoiceOut *cap;
192 LIST_ENTRY (SWVoiceCap) entries;
193};
194
195struct 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
209extern struct audio_driver no_audio_driver;
210extern struct audio_driver oss_audio_driver;
211extern struct audio_driver sdl_audio_driver;
212extern struct audio_driver wav_audio_driver;
213extern struct audio_driver fmod_audio_driver;
214extern struct audio_driver alsa_audio_driver;
215extern struct audio_driver pulse_audio_driver;
216extern struct audio_driver coreaudio_audio_driver;
217extern struct audio_driver dsound_audio_driver;
218extern struct audio_driver solaudio_audio_driver;
219extern volume_t nominal_volume;
220#ifdef VBOX
221extern volume_t pcm_out_volume;
222extern volume_t pcm_in_volume;
223#endif
224
225uint64_t audio_get_clock (void);
226uint64_t audio_get_ticks_per_sec (void);
227
228void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
229void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
230
231int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
232int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
233
234int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
235int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
236int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
237
238int audio_bug (const char *funcname, int cond);
239void *audio_calloc (const char *funcname, int nmemb, size_t size);
240
241#define VOICE_ENABLE 1
242#define VOICE_DISABLE 2
243
244static inline int audio_ring_dist (int dst, int src, int len)
245{
246 return (dst >= src) ? (dst - src) : (len - src + dst);
247}
248
249#if defined __GNUC__ && !defined VBOX /* VBox: oh, please, just shut up. */
250#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
251#if __STDC_VERSION__ > 199901L
252#define INIT_FIELD(f) . f
253#else
254#define INIT_FIELD(f) /**/
255#endif
256#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
257#else
258#define GCC_ATTR /**/
259#define INIT_FIELD(f) /**/
260#define GCC_FMT_ATTR(n, m)
261#endif
262
263#ifndef VBOX
264static void GCC_ATTR dolog (const char *fmt, ...)
265#else
266DECLINLINE(void) GCC_ATTR dolog (const char *fmt, ...) /* shuts up unused warnings. */
267#endif
268{
269 va_list ap;
270
271 va_start (ap, fmt);
272 AUD_vlog (AUDIO_CAP, fmt, ap);
273 va_end (ap);
274}
275
276#ifdef DEBUG
277DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...)
278{
279 va_list ap;
280
281 va_start (ap, fmt);
282 AUD_vlog (AUDIO_CAP, fmt, ap);
283 va_end (ap);
284}
285#else
286#if defined NDEBUG && defined __GNUC__
287#define ldebug(...)
288#elif defined NDEBUG && defined _MSC_VER
289#define ldebug __noop
290#else
291#ifndef VBOX
292static void GCC_ATTR ldebug (const char *fmt, ...)
293#else
294DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...) /* shuts up unused warnings. */
295#endif
296{
297 (void) fmt;
298}
299#endif
300#endif
301
302#undef GCC_ATTR
303
304#define AUDIO_STRINGIFY_(n) #n
305#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
306
307#if defined _MSC_VER || defined __GNUC__
308#define AUDIO_FUNC __FUNCTION__
309#else
310#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
311#endif
312
313DECLCALLBACK(bool) sniffer_run_out (HWVoiceOut *hw, void *pvSamples,
314 unsigned cSamples);
315
316#endif /* audio_int.h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette