VirtualBox

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

Last change on this file since 5050 was 5050, checked in by vboxsync, 17 years ago

Moved the ALSA code into a separate shared object loaded at runtime

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