VirtualBox

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

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

Solaris audio driver, work in progress.

  • 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 coreaudio_audio_driver;
216extern struct audio_driver dsound_audio_driver;
217extern struct audio_driver solaudio_audio_driver;
218extern volume_t nominal_volume;
219#ifdef VBOX
220extern volume_t pcm_out_volume;
221extern volume_t pcm_in_volume;
222#endif
223
224uint64_t audio_get_clock (void);
225uint64_t audio_get_ticks_per_sec (void);
226
227void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
228void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
229
230int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
231int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
232
233int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
234int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
235int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
236
237int audio_bug (const char *funcname, int cond);
238void *audio_calloc (const char *funcname, int nmemb, size_t size);
239
240#define VOICE_ENABLE 1
241#define VOICE_DISABLE 2
242
243static inline int audio_ring_dist (int dst, int src, int len)
244{
245 return (dst >= src) ? (dst - src) : (len - src + dst);
246}
247
248#if defined __GNUC__ && !defined VBOX /* VBox: oh, please, just shut up. */
249#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
250#if __STDC_VERSION__ > 199901L
251#define INIT_FIELD(f) . f
252#else
253#define INIT_FIELD(f) /**/
254#endif
255#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
256#else
257#define GCC_ATTR /**/
258#define INIT_FIELD(f) /**/
259#define GCC_FMT_ATTR(n, m)
260#endif
261
262#ifndef VBOX
263static void GCC_ATTR dolog (const char *fmt, ...)
264#else
265DECLINLINE(void) GCC_ATTR dolog (const char *fmt, ...) /* shuts up unused warnings. */
266#endif
267{
268 va_list ap;
269
270 va_start (ap, fmt);
271 AUD_vlog (AUDIO_CAP, fmt, ap);
272 va_end (ap);
273}
274
275#ifdef DEBUG
276static void GCC_ATTR ldebug (const char *fmt, ...)
277{
278 va_list ap;
279
280 va_start (ap, fmt);
281 AUD_vlog (AUDIO_CAP, fmt, ap);
282 va_end (ap);
283}
284#else
285#if defined NDEBUG && defined __GNUC__
286#define ldebug(...)
287#elif defined NDEBUG && defined _MSC_VER
288#define ldebug __noop
289#else
290#ifndef VBOX
291static void GCC_ATTR ldebug (const char *fmt, ...)
292#else
293DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...) /* shuts up unused warnings. */
294#endif
295{
296 (void) fmt;
297}
298#endif
299#endif
300
301#undef GCC_ATTR
302
303#define AUDIO_STRINGIFY_(n) #n
304#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
305
306#if defined _MSC_VER || defined __GNUC__
307#define AUDIO_FUNC __FUNCTION__
308#else
309#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
310#endif
311
312DECLCALLBACK(bool) sniffer_run_out (HWVoiceOut *hw, void *pvSamples,
313 unsigned cSamples);
314
315#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