1 |
/* |
/* |
2 |
* QEMU Audio subsystem header |
* QEMU Audio subsystem header |
3 |
* |
* |
4 |
* Copyright (c) 2003-2004 Vassili Karpov (malc) |
* Copyright (c) 2003-2005 Vassili Karpov (malc) |
5 |
* |
* |
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
* 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 |
* of this software and associated documentation files (the "Software"), to deal |
8 |
* in the Software without restriction, including without limitation the rights |
* in the Software without restriction, including without limitation the rights |
24 |
#ifndef QEMU_AUDIO_INT_H |
#ifndef QEMU_AUDIO_INT_H |
25 |
#define QEMU_AUDIO_INT_H |
#define QEMU_AUDIO_INT_H |
26 |
|
|
27 |
#include "vl.h" |
#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 pcm_ops; |
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 HWVoice { |
typedef struct HWVoiceOut { |
72 |
int active; |
int active; |
73 |
int enabled; |
int enabled; |
74 |
int pending_disable; |
int pending_disable; |
75 |
int valid; |
int valid; |
76 |
int freq; |
struct audio_pcm_info info; |
77 |
|
|
78 |
f_sample *clip; |
f_sample *clip; |
|
audfmt_e fmt; |
|
|
int nchannels; |
|
|
|
|
|
int align; |
|
|
int shift; |
|
79 |
|
|
80 |
int rpos; |
int rpos; |
81 |
int bufsize; |
int bufsize; |
82 |
|
uint64_t ts_helper; |
83 |
|
|
|
int bytes_per_second; |
|
84 |
st_sample_t *mix_buf; |
st_sample_t *mix_buf; |
85 |
|
|
86 |
int samples; |
int samples; |
87 |
int64_t old_ticks; |
LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; |
88 |
int nb_voices; |
struct audio_pcm_ops *pcm_ops; |
89 |
struct SWVoice **pvoice; |
LIST_ENTRY (HWVoiceOut) entries; |
90 |
struct pcm_ops *pcm_ops; |
} HWVoiceOut; |
|
} HWVoice; |
|
91 |
|
|
92 |
extern struct pcm_ops no_pcm_ops; |
typedef struct HWVoiceIn { |
93 |
extern struct audio_output_driver no_output_driver; |
int enabled; |
94 |
|
int active; |
95 |
|
struct audio_pcm_info info; |
96 |
|
|
97 |
extern struct pcm_ops oss_pcm_ops; |
t_sample *conv; |
|
extern struct audio_output_driver oss_output_driver; |
|
98 |
|
|
99 |
extern struct pcm_ops sdl_pcm_ops; |
int wpos; |
100 |
extern struct audio_output_driver sdl_output_driver; |
int bufsize; |
101 |
|
int total_samples_captured; |
102 |
|
uint64_t ts_helper; |
103 |
|
|
104 |
extern struct pcm_ops wav_pcm_ops; |
st_sample_t *conv_buf; |
|
extern struct audio_output_driver wav_output_driver; |
|
105 |
|
|
106 |
extern struct pcm_ops fmod_pcm_ops; |
int samples; |
107 |
extern struct audio_output_driver fmod_output_driver; |
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_output_driver { |
struct audio_driver { |
123 |
const char *name; |
const char *name; |
124 |
|
const char *descr; |
125 |
|
struct audio_option *options; |
126 |
void *(*init) (void); |
void *(*init) (void); |
127 |
void (*fini) (void *); |
void (*fini) (void *); |
128 |
struct pcm_ops *pcm_ops; |
struct audio_pcm_ops *pcm_ops; |
129 |
int can_be_default; |
int can_be_default; |
130 |
int max_voices; |
int max_voices_out; |
131 |
int voice_size; |
int max_voices_in; |
132 |
|
int voice_size_out; |
133 |
|
int voice_size_in; |
134 |
}; |
}; |
135 |
|
|
136 |
typedef struct AudioState { |
typedef struct AudioState { |
137 |
int fixed_format; |
int fixed_settings_out; |
138 |
int fixed_freq; |
int fixed_freq_out; |
139 |
int fixed_channels; |
int fixed_channels_out; |
140 |
int fixed_fmt; |
int fixed_fmt_out; |
141 |
int nb_hw_voices; |
int nb_hw_voices_out; |
142 |
int64_t ticks_threshold; |
int greedy_out; |
143 |
int freq_threshold; |
|
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; |
void *opaque; |
152 |
struct audio_output_driver *drv; |
struct audio_driver *drv; |
|
} AudioState; |
|
|
extern AudioState audio_state; |
|
153 |
|
|
154 |
struct SWVoice { |
QEMUTimer *ts; |
155 |
int freq; |
union { |
156 |
audfmt_e fmt; |
int usec; |
157 |
int nchannels; |
int64_t ticks; |
158 |
|
} period; |
159 |
|
|
160 |
int shift; |
int plive; |
161 |
int align; |
} AudioState; |
162 |
|
extern AudioState audio_state; |
163 |
|
|
164 |
|
struct SWVoiceOut { |
165 |
|
struct audio_pcm_info info; |
166 |
t_sample *conv; |
t_sample *conv; |
|
|
|
|
int left; |
|
|
int pos; |
|
|
int bytes_per_second; |
|
167 |
int64_t ratio; |
int64_t ratio; |
168 |
st_sample_t *buf; |
st_sample_t *buf; |
169 |
void *rate; |
void *rate; |
170 |
|
int total_hw_samples_mixed; |
|
int wpos; |
|
|
int live; |
|
171 |
int active; |
int active; |
172 |
int64_t old_ticks; |
int empty; |
173 |
HWVoice *hw; |
HWVoiceOut *hw; |
174 |
char *name; |
char *name; |
175 |
|
volume_t vol; |
176 |
|
struct audio_callback callback; |
177 |
|
LIST_ENTRY (SWVoiceOut) entries; |
178 |
}; |
}; |
179 |
|
|
180 |
struct pcm_ops { |
struct SWVoiceIn { |
181 |
int (*init) (HWVoice *hw, int freq, int nchannels, audfmt_e fmt); |
int active; |
182 |
void (*fini) (HWVoice *hw); |
struct audio_pcm_info info; |
183 |
void (*run) (HWVoice *hw); |
int64_t ratio; |
184 |
int (*write) (SWVoice *sw, void *buf, int size); |
void *rate; |
185 |
int (*ctl) (HWVoice *hw, int cmd, ...); |
int total_hw_samples_acquired; |
186 |
}; |
st_sample_t *conv_buf; |
187 |
|
f_sample *clip; |
188 |
void pcm_sw_free_resources (SWVoice *sw); |
HWVoiceIn *hw; |
189 |
int pcm_sw_alloc_resources (SWVoice *sw); |
char *name; |
190 |
void pcm_sw_fini (SWVoice *sw); |
volume_t vol; |
191 |
int pcm_sw_init (SWVoice *sw, HWVoice *hw, int freq, |
struct audio_callback callback; |
192 |
int nchannels, audfmt_e fmt); |
LIST_ENTRY (SWVoiceIn) entries; |
193 |
|
}; |
|
void pcm_hw_clear (HWVoice *hw, void *buf, int len); |
|
|
HWVoice * pcm_hw_find_any (HWVoice *hw); |
|
|
HWVoice * pcm_hw_find_any_active (HWVoice *hw); |
|
|
HWVoice * pcm_hw_find_any_passive (HWVoice *hw); |
|
|
HWVoice * pcm_hw_find_specific (HWVoice *hw, int freq, |
|
|
int nchannels, audfmt_e fmt); |
|
|
HWVoice * pcm_hw_add (int freq, int nchannels, audfmt_e fmt); |
|
|
int pcm_hw_add_sw (HWVoice *hw, SWVoice *sw); |
|
|
int pcm_hw_del_sw (HWVoice *hw, SWVoice *sw); |
|
|
SWVoice * pcm_create_voice_pair (int freq, int nchannels, audfmt_e fmt); |
|
|
|
|
|
void pcm_hw_free_resources (HWVoice *hw); |
|
|
int pcm_hw_alloc_resources (HWVoice *hw); |
|
|
void pcm_hw_fini (HWVoice *hw); |
|
|
void pcm_hw_gc (HWVoice *hw); |
|
|
int pcm_hw_get_live (HWVoice *hw); |
|
|
int pcm_hw_get_live2 (HWVoice *hw, int *nb_active); |
|
|
void pcm_hw_dec_live (HWVoice *hw, int decr); |
|
|
int pcm_hw_write (SWVoice *sw, void *buf, int len); |
|
194 |
|
|
195 |
int audio_get_conf_int (const char *key, int defval); |
struct audio_pcm_ops { |
196 |
const char *audio_get_conf_str (const char *key, const char *defval); |
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 |
struct audio_output_driver; |
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 |
#define VOICE_ENABLE 1 |
221 |
#define VOICE_DISABLE 2 |
#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 */ |
#endif /* audio_int.h */ |