root / audio / audio.c @ ea785922
History | View | Annotate | Download (46.2 kB)
1 | 85571bc7 | bellard | /*
|
---|---|---|---|
2 | 85571bc7 | bellard | * QEMU Audio subsystem
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | 85571bc7 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 85571bc7 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 85571bc7 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 85571bc7 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 85571bc7 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 85571bc7 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 85571bc7 | bellard | *
|
13 | 85571bc7 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 85571bc7 | bellard | * all copies or substantial portions of the Software.
|
15 | 85571bc7 | bellard | *
|
16 | 85571bc7 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 85571bc7 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 85571bc7 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 85571bc7 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 85571bc7 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 85571bc7 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 85571bc7 | bellard | * THE SOFTWARE.
|
23 | 85571bc7 | bellard | */
|
24 | 85571bc7 | bellard | #include "vl.h" |
25 | 85571bc7 | bellard | |
26 | 1d14ffa9 | bellard | #define AUDIO_CAP "audio" |
27 | 1d14ffa9 | bellard | #include "audio_int.h" |
28 | 85571bc7 | bellard | |
29 | 1d14ffa9 | bellard | /* #define DEBUG_PLIVE */
|
30 | 1d14ffa9 | bellard | /* #define DEBUG_LIVE */
|
31 | 1d14ffa9 | bellard | /* #define DEBUG_OUT */
|
32 | 8ead62cf | bellard | /* #define DEBUG_CAPTURE */
|
33 | 85571bc7 | bellard | |
34 | c0fe3827 | bellard | #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown" |
35 | c0fe3827 | bellard | |
36 | 1d14ffa9 | bellard | static struct audio_driver *drvtab[] = { |
37 | 1d14ffa9 | bellard | #ifdef CONFIG_OSS
|
38 | 1d14ffa9 | bellard | &oss_audio_driver, |
39 | 1d14ffa9 | bellard | #endif
|
40 | 1d14ffa9 | bellard | #ifdef CONFIG_ALSA
|
41 | 1d14ffa9 | bellard | &alsa_audio_driver, |
42 | 1d14ffa9 | bellard | #endif
|
43 | 1d14ffa9 | bellard | #ifdef CONFIG_COREAUDIO
|
44 | 1d14ffa9 | bellard | &coreaudio_audio_driver, |
45 | 1d14ffa9 | bellard | #endif
|
46 | 1d14ffa9 | bellard | #ifdef CONFIG_DSOUND
|
47 | 1d14ffa9 | bellard | &dsound_audio_driver, |
48 | 1d14ffa9 | bellard | #endif
|
49 | 1d14ffa9 | bellard | #ifdef CONFIG_FMOD
|
50 | 1d14ffa9 | bellard | &fmod_audio_driver, |
51 | 1d14ffa9 | bellard | #endif
|
52 | 1d14ffa9 | bellard | #ifdef CONFIG_SDL
|
53 | 1d14ffa9 | bellard | &sdl_audio_driver, |
54 | 1d14ffa9 | bellard | #endif
|
55 | 1d14ffa9 | bellard | &no_audio_driver, |
56 | 1d14ffa9 | bellard | &wav_audio_driver |
57 | 1d14ffa9 | bellard | }; |
58 | 85571bc7 | bellard | |
59 | c0fe3827 | bellard | struct fixed_settings {
|
60 | c0fe3827 | bellard | int enabled;
|
61 | c0fe3827 | bellard | int nb_voices;
|
62 | c0fe3827 | bellard | int greedy;
|
63 | c0fe3827 | bellard | audsettings_t settings; |
64 | c0fe3827 | bellard | }; |
65 | c0fe3827 | bellard | |
66 | c0fe3827 | bellard | static struct { |
67 | c0fe3827 | bellard | struct fixed_settings fixed_out;
|
68 | c0fe3827 | bellard | struct fixed_settings fixed_in;
|
69 | c0fe3827 | bellard | union {
|
70 | c0fe3827 | bellard | int hz;
|
71 | c0fe3827 | bellard | int64_t ticks; |
72 | c0fe3827 | bellard | } period; |
73 | c0fe3827 | bellard | int plive;
|
74 | 541e0844 | bellard | int log_to_monitor;
|
75 | c0fe3827 | bellard | } conf = { |
76 | c0fe3827 | bellard | { /* DAC fixed settings */
|
77 | c0fe3827 | bellard | 1, /* enabled */ |
78 | c0fe3827 | bellard | 1, /* nb_voices */ |
79 | c0fe3827 | bellard | 1, /* greedy */ |
80 | c0fe3827 | bellard | { |
81 | c0fe3827 | bellard | 44100, /* freq */ |
82 | c0fe3827 | bellard | 2, /* nchannels */ |
83 | c0fe3827 | bellard | AUD_FMT_S16 /* fmt */
|
84 | c0fe3827 | bellard | } |
85 | c0fe3827 | bellard | }, |
86 | c0fe3827 | bellard | |
87 | c0fe3827 | bellard | { /* ADC fixed settings */
|
88 | c0fe3827 | bellard | 1, /* enabled */ |
89 | c0fe3827 | bellard | 1, /* nb_voices */ |
90 | c0fe3827 | bellard | 1, /* greedy */ |
91 | c0fe3827 | bellard | { |
92 | c0fe3827 | bellard | 44100, /* freq */ |
93 | c0fe3827 | bellard | 2, /* nchannels */ |
94 | c0fe3827 | bellard | AUD_FMT_S16 /* fmt */
|
95 | c0fe3827 | bellard | } |
96 | c0fe3827 | bellard | }, |
97 | c0fe3827 | bellard | |
98 | 1d14ffa9 | bellard | { 0 }, /* period */ |
99 | 541e0844 | bellard | 0, /* plive */ |
100 | 571ec3d6 | bellard | 0 /* log_to_monitor */ |
101 | 1d14ffa9 | bellard | }; |
102 | 1d14ffa9 | bellard | |
103 | c0fe3827 | bellard | static AudioState glob_audio_state;
|
104 | c0fe3827 | bellard | |
105 | 1d14ffa9 | bellard | volume_t nominal_volume = { |
106 | 1d14ffa9 | bellard | 0,
|
107 | 1d14ffa9 | bellard | #ifdef FLOAT_MIXENG
|
108 | 1d14ffa9 | bellard | 1.0, |
109 | 1d14ffa9 | bellard | 1.0 |
110 | 1d14ffa9 | bellard | #else
|
111 | 1d14ffa9 | bellard | UINT_MAX, |
112 | 1d14ffa9 | bellard | UINT_MAX |
113 | 1d14ffa9 | bellard | #endif
|
114 | 85571bc7 | bellard | }; |
115 | 85571bc7 | bellard | |
116 | 85571bc7 | bellard | /* http://www.df.lth.se/~john_e/gems/gem002d.html */
|
117 | 85571bc7 | bellard | /* http://www.multi-platforms.com/Tips/PopCount.htm */
|
118 | 85571bc7 | bellard | uint32_t popcount (uint32_t u) |
119 | 85571bc7 | bellard | { |
120 | 85571bc7 | bellard | u = ((u&0x55555555) + ((u>>1)&0x55555555)); |
121 | 85571bc7 | bellard | u = ((u&0x33333333) + ((u>>2)&0x33333333)); |
122 | 85571bc7 | bellard | u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f)); |
123 | 85571bc7 | bellard | u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff)); |
124 | 85571bc7 | bellard | u = ( u&0x0000ffff) + (u>>16); |
125 | 85571bc7 | bellard | return u;
|
126 | 85571bc7 | bellard | } |
127 | 85571bc7 | bellard | |
128 | 85571bc7 | bellard | inline uint32_t lsbindex (uint32_t u)
|
129 | 85571bc7 | bellard | { |
130 | 85571bc7 | bellard | return popcount ((u&-u)-1); |
131 | 85571bc7 | bellard | } |
132 | 85571bc7 | bellard | |
133 | 1d14ffa9 | bellard | #ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
|
134 | 1d14ffa9 | bellard | #error No its not
|
135 | 1d14ffa9 | bellard | #else
|
136 | 1d14ffa9 | bellard | int audio_bug (const char *funcname, int cond) |
137 | 85571bc7 | bellard | { |
138 | 1d14ffa9 | bellard | if (cond) {
|
139 | 1d14ffa9 | bellard | static int shown; |
140 | 1d14ffa9 | bellard | |
141 | 8ead62cf | bellard | AUD_log (NULL, "A bug was just triggered in %s\n", funcname); |
142 | 1d14ffa9 | bellard | if (!shown) {
|
143 | 1d14ffa9 | bellard | shown = 1;
|
144 | 1d14ffa9 | bellard | AUD_log (NULL, "Save all your work and restart without audio\n"); |
145 | 1d14ffa9 | bellard | AUD_log (NULL, "Please send bug report to malc@pulsesoft.com\n"); |
146 | 1d14ffa9 | bellard | AUD_log (NULL, "I am sorry\n"); |
147 | 1d14ffa9 | bellard | } |
148 | 1d14ffa9 | bellard | AUD_log (NULL, "Context:\n"); |
149 | 1d14ffa9 | bellard | |
150 | 1d14ffa9 | bellard | #if defined AUDIO_BREAKPOINT_ON_BUG
|
151 | 1d14ffa9 | bellard | # if defined HOST_I386
|
152 | 1d14ffa9 | bellard | # if defined __GNUC__
|
153 | 1d14ffa9 | bellard | __asm__ ("int3");
|
154 | 1d14ffa9 | bellard | # elif defined _MSC_VER
|
155 | 1d14ffa9 | bellard | _asm _emit 0xcc;
|
156 | 1d14ffa9 | bellard | # else
|
157 | 1d14ffa9 | bellard | abort (); |
158 | 1d14ffa9 | bellard | # endif
|
159 | 1d14ffa9 | bellard | # else
|
160 | 1d14ffa9 | bellard | abort (); |
161 | 1d14ffa9 | bellard | # endif
|
162 | 1d14ffa9 | bellard | #endif
|
163 | 85571bc7 | bellard | } |
164 | 85571bc7 | bellard | |
165 | 1d14ffa9 | bellard | return cond;
|
166 | 85571bc7 | bellard | } |
167 | 1d14ffa9 | bellard | #endif
|
168 | 85571bc7 | bellard | |
169 | c0fe3827 | bellard | void *audio_calloc (const char *funcname, int nmemb, size_t size) |
170 | c0fe3827 | bellard | { |
171 | c0fe3827 | bellard | int cond;
|
172 | c0fe3827 | bellard | size_t len; |
173 | c0fe3827 | bellard | |
174 | c0fe3827 | bellard | len = nmemb * size; |
175 | c0fe3827 | bellard | cond = !nmemb || !size; |
176 | c0fe3827 | bellard | cond |= nmemb < 0;
|
177 | c0fe3827 | bellard | cond |= len < size; |
178 | c0fe3827 | bellard | |
179 | c0fe3827 | bellard | if (audio_bug ("audio_calloc", cond)) { |
180 | c0fe3827 | bellard | AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n", |
181 | c0fe3827 | bellard | funcname); |
182 | 541e0844 | bellard | AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len); |
183 | c0fe3827 | bellard | return NULL; |
184 | c0fe3827 | bellard | } |
185 | c0fe3827 | bellard | |
186 | c0fe3827 | bellard | return qemu_mallocz (len);
|
187 | c0fe3827 | bellard | } |
188 | c0fe3827 | bellard | |
189 | 1d14ffa9 | bellard | static char *audio_alloc_prefix (const char *s) |
190 | 85571bc7 | bellard | { |
191 | 1d14ffa9 | bellard | const char qemu_prefix[] = "QEMU_"; |
192 | 1d14ffa9 | bellard | size_t len; |
193 | 1d14ffa9 | bellard | char *r;
|
194 | 85571bc7 | bellard | |
195 | 1d14ffa9 | bellard | if (!s) {
|
196 | 1d14ffa9 | bellard | return NULL; |
197 | 1d14ffa9 | bellard | } |
198 | 85571bc7 | bellard | |
199 | 1d14ffa9 | bellard | len = strlen (s); |
200 | 1d14ffa9 | bellard | r = qemu_malloc (len + sizeof (qemu_prefix));
|
201 | 85571bc7 | bellard | |
202 | 1d14ffa9 | bellard | if (r) {
|
203 | 1d14ffa9 | bellard | size_t i; |
204 | 1d14ffa9 | bellard | char *u = r + sizeof (qemu_prefix) - 1; |
205 | 85571bc7 | bellard | |
206 | 1d14ffa9 | bellard | strcpy (r, qemu_prefix); |
207 | 1d14ffa9 | bellard | strcat (r, s); |
208 | 1d14ffa9 | bellard | |
209 | 1d14ffa9 | bellard | for (i = 0; i < len; ++i) { |
210 | 1d14ffa9 | bellard | u[i] = toupper (u[i]); |
211 | 1d14ffa9 | bellard | } |
212 | 85571bc7 | bellard | } |
213 | 1d14ffa9 | bellard | return r;
|
214 | 85571bc7 | bellard | } |
215 | 85571bc7 | bellard | |
216 | 1d14ffa9 | bellard | const char *audio_audfmt_to_string (audfmt_e fmt) |
217 | 85571bc7 | bellard | { |
218 | 1d14ffa9 | bellard | switch (fmt) {
|
219 | 1d14ffa9 | bellard | case AUD_FMT_U8:
|
220 | 1d14ffa9 | bellard | return "U8"; |
221 | 85571bc7 | bellard | |
222 | 1d14ffa9 | bellard | case AUD_FMT_U16:
|
223 | 1d14ffa9 | bellard | return "U16"; |
224 | 85571bc7 | bellard | |
225 | 85571bc7 | bellard | case AUD_FMT_S8:
|
226 | 1d14ffa9 | bellard | return "S8"; |
227 | 85571bc7 | bellard | |
228 | 85571bc7 | bellard | case AUD_FMT_S16:
|
229 | 1d14ffa9 | bellard | return "S16"; |
230 | 85571bc7 | bellard | } |
231 | 85571bc7 | bellard | |
232 | 1d14ffa9 | bellard | dolog ("Bogus audfmt %d returning S16\n", fmt);
|
233 | 1d14ffa9 | bellard | return "S16"; |
234 | 85571bc7 | bellard | } |
235 | 85571bc7 | bellard | |
236 | 1d14ffa9 | bellard | audfmt_e audio_string_to_audfmt (const char *s, audfmt_e defval, int *defaultp) |
237 | 85571bc7 | bellard | { |
238 | 1d14ffa9 | bellard | if (!strcasecmp (s, "u8")) { |
239 | 1d14ffa9 | bellard | *defaultp = 0;
|
240 | 1d14ffa9 | bellard | return AUD_FMT_U8;
|
241 | 1d14ffa9 | bellard | } |
242 | 1d14ffa9 | bellard | else if (!strcasecmp (s, "u16")) { |
243 | 1d14ffa9 | bellard | *defaultp = 0;
|
244 | 1d14ffa9 | bellard | return AUD_FMT_U16;
|
245 | 1d14ffa9 | bellard | } |
246 | 1d14ffa9 | bellard | else if (!strcasecmp (s, "s8")) { |
247 | 1d14ffa9 | bellard | *defaultp = 0;
|
248 | 1d14ffa9 | bellard | return AUD_FMT_S8;
|
249 | 1d14ffa9 | bellard | } |
250 | 1d14ffa9 | bellard | else if (!strcasecmp (s, "s16")) { |
251 | 1d14ffa9 | bellard | *defaultp = 0;
|
252 | 1d14ffa9 | bellard | return AUD_FMT_S16;
|
253 | 1d14ffa9 | bellard | } |
254 | 1d14ffa9 | bellard | else {
|
255 | 1d14ffa9 | bellard | dolog ("Bogus audio format `%s' using %s\n",
|
256 | 1d14ffa9 | bellard | s, audio_audfmt_to_string (defval)); |
257 | 1d14ffa9 | bellard | *defaultp = 1;
|
258 | 1d14ffa9 | bellard | return defval;
|
259 | 1d14ffa9 | bellard | } |
260 | 85571bc7 | bellard | } |
261 | 85571bc7 | bellard | |
262 | 1d14ffa9 | bellard | static audfmt_e audio_get_conf_fmt (const char *envname, |
263 | 1d14ffa9 | bellard | audfmt_e defval, |
264 | 1d14ffa9 | bellard | int *defaultp)
|
265 | 85571bc7 | bellard | { |
266 | 1d14ffa9 | bellard | const char *var = getenv (envname); |
267 | 1d14ffa9 | bellard | if (!var) {
|
268 | 1d14ffa9 | bellard | *defaultp = 1;
|
269 | 1d14ffa9 | bellard | return defval;
|
270 | 85571bc7 | bellard | } |
271 | 1d14ffa9 | bellard | return audio_string_to_audfmt (var, defval, defaultp);
|
272 | 85571bc7 | bellard | } |
273 | 85571bc7 | bellard | |
274 | 1d14ffa9 | bellard | static int audio_get_conf_int (const char *key, int defval, int *defaultp) |
275 | 85571bc7 | bellard | { |
276 | 1d14ffa9 | bellard | int val;
|
277 | 1d14ffa9 | bellard | char *strval;
|
278 | 85571bc7 | bellard | |
279 | 1d14ffa9 | bellard | strval = getenv (key); |
280 | 1d14ffa9 | bellard | if (strval) {
|
281 | 1d14ffa9 | bellard | *defaultp = 0;
|
282 | 1d14ffa9 | bellard | val = atoi (strval); |
283 | 1d14ffa9 | bellard | return val;
|
284 | 1d14ffa9 | bellard | } |
285 | 1d14ffa9 | bellard | else {
|
286 | 1d14ffa9 | bellard | *defaultp = 1;
|
287 | 1d14ffa9 | bellard | return defval;
|
288 | 1d14ffa9 | bellard | } |
289 | 85571bc7 | bellard | } |
290 | 85571bc7 | bellard | |
291 | 1d14ffa9 | bellard | static const char *audio_get_conf_str (const char *key, |
292 | 1d14ffa9 | bellard | const char *defval, |
293 | 1d14ffa9 | bellard | int *defaultp)
|
294 | 85571bc7 | bellard | { |
295 | 1d14ffa9 | bellard | const char *val = getenv (key); |
296 | 1d14ffa9 | bellard | if (!val) {
|
297 | 1d14ffa9 | bellard | *defaultp = 1;
|
298 | 1d14ffa9 | bellard | return defval;
|
299 | 1d14ffa9 | bellard | } |
300 | 1d14ffa9 | bellard | else {
|
301 | 1d14ffa9 | bellard | *defaultp = 0;
|
302 | 1d14ffa9 | bellard | return val;
|
303 | 85571bc7 | bellard | } |
304 | 85571bc7 | bellard | } |
305 | 85571bc7 | bellard | |
306 | 541e0844 | bellard | void AUD_vlog (const char *cap, const char *fmt, va_list ap) |
307 | 85571bc7 | bellard | { |
308 | 541e0844 | bellard | if (conf.log_to_monitor) {
|
309 | 541e0844 | bellard | if (cap) {
|
310 | 541e0844 | bellard | term_printf ("%s: ", cap);
|
311 | 541e0844 | bellard | } |
312 | 541e0844 | bellard | |
313 | 541e0844 | bellard | term_vprintf (fmt, ap); |
314 | 541e0844 | bellard | } |
315 | 541e0844 | bellard | else {
|
316 | 541e0844 | bellard | if (cap) {
|
317 | 541e0844 | bellard | fprintf (stderr, "%s: ", cap);
|
318 | 541e0844 | bellard | } |
319 | 541e0844 | bellard | |
320 | 541e0844 | bellard | vfprintf (stderr, fmt, ap); |
321 | 85571bc7 | bellard | } |
322 | 85571bc7 | bellard | } |
323 | 85571bc7 | bellard | |
324 | 541e0844 | bellard | void AUD_log (const char *cap, const char *fmt, ...) |
325 | 85571bc7 | bellard | { |
326 | 541e0844 | bellard | va_list ap; |
327 | 541e0844 | bellard | |
328 | 541e0844 | bellard | va_start (ap, fmt); |
329 | 541e0844 | bellard | AUD_vlog (cap, fmt, ap); |
330 | 541e0844 | bellard | va_end (ap); |
331 | 85571bc7 | bellard | } |
332 | 85571bc7 | bellard | |
333 | 1d14ffa9 | bellard | static void audio_print_options (const char *prefix, |
334 | 1d14ffa9 | bellard | struct audio_option *opt)
|
335 | 85571bc7 | bellard | { |
336 | 1d14ffa9 | bellard | char *uprefix;
|
337 | 1d14ffa9 | bellard | |
338 | 1d14ffa9 | bellard | if (!prefix) {
|
339 | 1d14ffa9 | bellard | dolog ("No prefix specified\n");
|
340 | 1d14ffa9 | bellard | return;
|
341 | 1d14ffa9 | bellard | } |
342 | 1d14ffa9 | bellard | |
343 | 1d14ffa9 | bellard | if (!opt) {
|
344 | 1d14ffa9 | bellard | dolog ("No options\n");
|
345 | 85571bc7 | bellard | return;
|
346 | 1d14ffa9 | bellard | } |
347 | 85571bc7 | bellard | |
348 | 1d14ffa9 | bellard | uprefix = audio_alloc_prefix (prefix); |
349 | 85571bc7 | bellard | |
350 | 1d14ffa9 | bellard | for (; opt->name; opt++) {
|
351 | 1d14ffa9 | bellard | const char *state = "default"; |
352 | 1d14ffa9 | bellard | printf (" %s_%s: ", uprefix, opt->name);
|
353 | 85571bc7 | bellard | |
354 | 1d14ffa9 | bellard | if (opt->overridenp && *opt->overridenp) {
|
355 | 1d14ffa9 | bellard | state = "current";
|
356 | 1d14ffa9 | bellard | } |
357 | 85571bc7 | bellard | |
358 | 1d14ffa9 | bellard | switch (opt->tag) {
|
359 | 1d14ffa9 | bellard | case AUD_OPT_BOOL:
|
360 | 1d14ffa9 | bellard | { |
361 | 1d14ffa9 | bellard | int *intp = opt->valp;
|
362 | 1d14ffa9 | bellard | printf ("boolean, %s = %d\n", state, *intp ? 1 : 0); |
363 | 1d14ffa9 | bellard | } |
364 | 1d14ffa9 | bellard | break;
|
365 | 1d14ffa9 | bellard | |
366 | 1d14ffa9 | bellard | case AUD_OPT_INT:
|
367 | 1d14ffa9 | bellard | { |
368 | 1d14ffa9 | bellard | int *intp = opt->valp;
|
369 | 1d14ffa9 | bellard | printf ("integer, %s = %d\n", state, *intp);
|
370 | 1d14ffa9 | bellard | } |
371 | 1d14ffa9 | bellard | break;
|
372 | 1d14ffa9 | bellard | |
373 | 1d14ffa9 | bellard | case AUD_OPT_FMT:
|
374 | 1d14ffa9 | bellard | { |
375 | 1d14ffa9 | bellard | audfmt_e *fmtp = opt->valp; |
376 | 1d14ffa9 | bellard | printf ( |
377 | 1d14ffa9 | bellard | "format, %s = %s, (one of: U8 S8 U16 S16)\n",
|
378 | 1d14ffa9 | bellard | state, |
379 | 1d14ffa9 | bellard | audio_audfmt_to_string (*fmtp) |
380 | 1d14ffa9 | bellard | ); |
381 | 1d14ffa9 | bellard | } |
382 | 1d14ffa9 | bellard | break;
|
383 | 1d14ffa9 | bellard | |
384 | 1d14ffa9 | bellard | case AUD_OPT_STR:
|
385 | 1d14ffa9 | bellard | { |
386 | 1d14ffa9 | bellard | const char **strp = opt->valp; |
387 | 1d14ffa9 | bellard | printf ("string, %s = %s\n",
|
388 | 1d14ffa9 | bellard | state, |
389 | 1d14ffa9 | bellard | *strp ? *strp : "(not set)");
|
390 | 85571bc7 | bellard | } |
391 | 1d14ffa9 | bellard | break;
|
392 | 1d14ffa9 | bellard | |
393 | 1d14ffa9 | bellard | default:
|
394 | 1d14ffa9 | bellard | printf ("???\n");
|
395 | 1d14ffa9 | bellard | dolog ("Bad value tag for option %s_%s %d\n",
|
396 | 1d14ffa9 | bellard | uprefix, opt->name, opt->tag); |
397 | 1d14ffa9 | bellard | break;
|
398 | 85571bc7 | bellard | } |
399 | 1d14ffa9 | bellard | printf (" %s\n", opt->descr);
|
400 | 85571bc7 | bellard | } |
401 | 1d14ffa9 | bellard | |
402 | 1d14ffa9 | bellard | qemu_free (uprefix); |
403 | 85571bc7 | bellard | } |
404 | 85571bc7 | bellard | |
405 | 1d14ffa9 | bellard | static void audio_process_options (const char *prefix, |
406 | 1d14ffa9 | bellard | struct audio_option *opt)
|
407 | 85571bc7 | bellard | { |
408 | 1d14ffa9 | bellard | char *optname;
|
409 | 1d14ffa9 | bellard | const char qemu_prefix[] = "QEMU_"; |
410 | 1d14ffa9 | bellard | size_t preflen; |
411 | 85571bc7 | bellard | |
412 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, !prefix)) {
|
413 | 1d14ffa9 | bellard | dolog ("prefix = NULL\n");
|
414 | 1d14ffa9 | bellard | return;
|
415 | 1d14ffa9 | bellard | } |
416 | 85571bc7 | bellard | |
417 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, !opt)) {
|
418 | 1d14ffa9 | bellard | dolog ("opt = NULL\n");
|
419 | 1d14ffa9 | bellard | return;
|
420 | 85571bc7 | bellard | } |
421 | 85571bc7 | bellard | |
422 | 1d14ffa9 | bellard | preflen = strlen (prefix); |
423 | 85571bc7 | bellard | |
424 | 1d14ffa9 | bellard | for (; opt->name; opt++) {
|
425 | 1d14ffa9 | bellard | size_t len, i; |
426 | 1d14ffa9 | bellard | int def;
|
427 | 1d14ffa9 | bellard | |
428 | 1d14ffa9 | bellard | if (!opt->valp) {
|
429 | 1d14ffa9 | bellard | dolog ("Option value pointer for `%s' is not set\n",
|
430 | 1d14ffa9 | bellard | opt->name); |
431 | 1d14ffa9 | bellard | continue;
|
432 | 1d14ffa9 | bellard | } |
433 | 1d14ffa9 | bellard | |
434 | 1d14ffa9 | bellard | len = strlen (opt->name); |
435 | c0fe3827 | bellard | /* len of opt->name + len of prefix + size of qemu_prefix
|
436 | c0fe3827 | bellard | * (includes trailing zero) + zero + underscore (on behalf of
|
437 | c0fe3827 | bellard | * sizeof) */
|
438 | 1d14ffa9 | bellard | optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1); |
439 | 1d14ffa9 | bellard | if (!optname) {
|
440 | c0fe3827 | bellard | dolog ("Could not allocate memory for option name `%s'\n",
|
441 | 1d14ffa9 | bellard | opt->name); |
442 | 1d14ffa9 | bellard | continue;
|
443 | 1d14ffa9 | bellard | } |
444 | 1d14ffa9 | bellard | |
445 | 1d14ffa9 | bellard | strcpy (optname, qemu_prefix); |
446 | c0fe3827 | bellard | |
447 | c0fe3827 | bellard | /* copy while upper-casing, including trailing zero */
|
448 | 1d14ffa9 | bellard | for (i = 0; i <= preflen; ++i) { |
449 | 1d14ffa9 | bellard | optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); |
450 | 1d14ffa9 | bellard | } |
451 | 1d14ffa9 | bellard | strcat (optname, "_");
|
452 | 1d14ffa9 | bellard | strcat (optname, opt->name); |
453 | 1d14ffa9 | bellard | |
454 | 1d14ffa9 | bellard | def = 1;
|
455 | 1d14ffa9 | bellard | switch (opt->tag) {
|
456 | 1d14ffa9 | bellard | case AUD_OPT_BOOL:
|
457 | 1d14ffa9 | bellard | case AUD_OPT_INT:
|
458 | 1d14ffa9 | bellard | { |
459 | 1d14ffa9 | bellard | int *intp = opt->valp;
|
460 | 1d14ffa9 | bellard | *intp = audio_get_conf_int (optname, *intp, &def); |
461 | 1d14ffa9 | bellard | } |
462 | 1d14ffa9 | bellard | break;
|
463 | 1d14ffa9 | bellard | |
464 | 1d14ffa9 | bellard | case AUD_OPT_FMT:
|
465 | 1d14ffa9 | bellard | { |
466 | 1d14ffa9 | bellard | audfmt_e *fmtp = opt->valp; |
467 | 1d14ffa9 | bellard | *fmtp = audio_get_conf_fmt (optname, *fmtp, &def); |
468 | 1d14ffa9 | bellard | } |
469 | 1d14ffa9 | bellard | break;
|
470 | 1d14ffa9 | bellard | |
471 | 1d14ffa9 | bellard | case AUD_OPT_STR:
|
472 | 1d14ffa9 | bellard | { |
473 | 1d14ffa9 | bellard | const char **strp = opt->valp; |
474 | 1d14ffa9 | bellard | *strp = audio_get_conf_str (optname, *strp, &def); |
475 | 1d14ffa9 | bellard | } |
476 | 1d14ffa9 | bellard | break;
|
477 | 1d14ffa9 | bellard | |
478 | 1d14ffa9 | bellard | default:
|
479 | 1d14ffa9 | bellard | dolog ("Bad value tag for option `%s' - %d\n",
|
480 | 1d14ffa9 | bellard | optname, opt->tag); |
481 | 85571bc7 | bellard | break;
|
482 | 85571bc7 | bellard | } |
483 | 85571bc7 | bellard | |
484 | 1d14ffa9 | bellard | if (!opt->overridenp) {
|
485 | 1d14ffa9 | bellard | opt->overridenp = &opt->overriden; |
486 | 1d14ffa9 | bellard | } |
487 | 1d14ffa9 | bellard | *opt->overridenp = !def; |
488 | 1d14ffa9 | bellard | qemu_free (optname); |
489 | 1d14ffa9 | bellard | } |
490 | 85571bc7 | bellard | } |
491 | 85571bc7 | bellard | |
492 | c0fe3827 | bellard | static void audio_print_settings (audsettings_t *as) |
493 | c0fe3827 | bellard | { |
494 | c0fe3827 | bellard | dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels);
|
495 | c0fe3827 | bellard | |
496 | c0fe3827 | bellard | switch (as->fmt) {
|
497 | c0fe3827 | bellard | case AUD_FMT_S8:
|
498 | c0fe3827 | bellard | AUD_log (NULL, "S8"); |
499 | c0fe3827 | bellard | break;
|
500 | c0fe3827 | bellard | case AUD_FMT_U8:
|
501 | c0fe3827 | bellard | AUD_log (NULL, "U8"); |
502 | c0fe3827 | bellard | break;
|
503 | c0fe3827 | bellard | case AUD_FMT_S16:
|
504 | c0fe3827 | bellard | AUD_log (NULL, "S16"); |
505 | c0fe3827 | bellard | break;
|
506 | c0fe3827 | bellard | case AUD_FMT_U16:
|
507 | c0fe3827 | bellard | AUD_log (NULL, "U16"); |
508 | c0fe3827 | bellard | break;
|
509 | c0fe3827 | bellard | default:
|
510 | c0fe3827 | bellard | AUD_log (NULL, "invalid(%d)", as->fmt); |
511 | c0fe3827 | bellard | break;
|
512 | c0fe3827 | bellard | } |
513 | ec36b695 | bellard | |
514 | ec36b695 | bellard | AUD_log (NULL, " endianness="); |
515 | d929eba5 | bellard | switch (as->endianness) {
|
516 | d929eba5 | bellard | case 0: |
517 | d929eba5 | bellard | AUD_log (NULL, "little"); |
518 | d929eba5 | bellard | break;
|
519 | d929eba5 | bellard | case 1: |
520 | d929eba5 | bellard | AUD_log (NULL, "big"); |
521 | d929eba5 | bellard | break;
|
522 | d929eba5 | bellard | default:
|
523 | d929eba5 | bellard | AUD_log (NULL, "invalid"); |
524 | d929eba5 | bellard | break;
|
525 | d929eba5 | bellard | } |
526 | c0fe3827 | bellard | AUD_log (NULL, "\n"); |
527 | c0fe3827 | bellard | } |
528 | c0fe3827 | bellard | |
529 | ec36b695 | bellard | static int audio_validate_settings (audsettings_t *as) |
530 | c0fe3827 | bellard | { |
531 | c0fe3827 | bellard | int invalid;
|
532 | c0fe3827 | bellard | |
533 | c0fe3827 | bellard | invalid = as->nchannels != 1 && as->nchannels != 2; |
534 | d929eba5 | bellard | invalid |= as->endianness != 0 && as->endianness != 1; |
535 | c0fe3827 | bellard | |
536 | c0fe3827 | bellard | switch (as->fmt) {
|
537 | c0fe3827 | bellard | case AUD_FMT_S8:
|
538 | c0fe3827 | bellard | case AUD_FMT_U8:
|
539 | c0fe3827 | bellard | case AUD_FMT_S16:
|
540 | c0fe3827 | bellard | case AUD_FMT_U16:
|
541 | c0fe3827 | bellard | break;
|
542 | c0fe3827 | bellard | default:
|
543 | c0fe3827 | bellard | invalid = 1;
|
544 | c0fe3827 | bellard | break;
|
545 | c0fe3827 | bellard | } |
546 | c0fe3827 | bellard | |
547 | c0fe3827 | bellard | invalid |= as->freq <= 0;
|
548 | d929eba5 | bellard | return invalid ? -1 : 0; |
549 | c0fe3827 | bellard | } |
550 | c0fe3827 | bellard | |
551 | c0fe3827 | bellard | static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as) |
552 | 85571bc7 | bellard | { |
553 | 1d14ffa9 | bellard | int bits = 8, sign = 0; |
554 | 85571bc7 | bellard | |
555 | c0fe3827 | bellard | switch (as->fmt) {
|
556 | 1d14ffa9 | bellard | case AUD_FMT_S8:
|
557 | 1d14ffa9 | bellard | sign = 1;
|
558 | 1d14ffa9 | bellard | case AUD_FMT_U8:
|
559 | 1d14ffa9 | bellard | break;
|
560 | 1d14ffa9 | bellard | |
561 | 1d14ffa9 | bellard | case AUD_FMT_S16:
|
562 | 1d14ffa9 | bellard | sign = 1;
|
563 | 1d14ffa9 | bellard | case AUD_FMT_U16:
|
564 | 1d14ffa9 | bellard | bits = 16;
|
565 | 1d14ffa9 | bellard | break;
|
566 | 85571bc7 | bellard | } |
567 | c0fe3827 | bellard | return info->freq == as->freq
|
568 | c0fe3827 | bellard | && info->nchannels == as->nchannels |
569 | 1d14ffa9 | bellard | && info->sign == sign |
570 | d929eba5 | bellard | && info->bits == bits |
571 | d929eba5 | bellard | && info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS); |
572 | 1d14ffa9 | bellard | } |
573 | 85571bc7 | bellard | |
574 | d929eba5 | bellard | void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as) |
575 | 1d14ffa9 | bellard | { |
576 | 1d14ffa9 | bellard | int bits = 8, sign = 0; |
577 | 1d14ffa9 | bellard | |
578 | c0fe3827 | bellard | switch (as->fmt) {
|
579 | 85571bc7 | bellard | case AUD_FMT_S8:
|
580 | 85571bc7 | bellard | sign = 1;
|
581 | 85571bc7 | bellard | case AUD_FMT_U8:
|
582 | 85571bc7 | bellard | break;
|
583 | 85571bc7 | bellard | |
584 | 85571bc7 | bellard | case AUD_FMT_S16:
|
585 | 85571bc7 | bellard | sign = 1;
|
586 | 85571bc7 | bellard | case AUD_FMT_U16:
|
587 | 85571bc7 | bellard | bits = 16;
|
588 | 85571bc7 | bellard | break;
|
589 | 85571bc7 | bellard | } |
590 | 85571bc7 | bellard | |
591 | c0fe3827 | bellard | info->freq = as->freq; |
592 | 1d14ffa9 | bellard | info->bits = bits; |
593 | 1d14ffa9 | bellard | info->sign = sign; |
594 | c0fe3827 | bellard | info->nchannels = as->nchannels; |
595 | c0fe3827 | bellard | info->shift = (as->nchannels == 2) + (bits == 16); |
596 | 1d14ffa9 | bellard | info->align = (1 << info->shift) - 1; |
597 | 1d14ffa9 | bellard | info->bytes_per_second = info->freq << info->shift; |
598 | d929eba5 | bellard | info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS); |
599 | 85571bc7 | bellard | } |
600 | 85571bc7 | bellard | |
601 | 1d14ffa9 | bellard | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len) |
602 | 85571bc7 | bellard | { |
603 | 1d14ffa9 | bellard | if (!len) {
|
604 | 1d14ffa9 | bellard | return;
|
605 | 1d14ffa9 | bellard | } |
606 | 1d14ffa9 | bellard | |
607 | 1d14ffa9 | bellard | if (info->sign) {
|
608 | e2f909be | bellard | memset (buf, 0x00, len << info->shift);
|
609 | 85571bc7 | bellard | } |
610 | 85571bc7 | bellard | else {
|
611 | 1d14ffa9 | bellard | if (info->bits == 8) { |
612 | e2f909be | bellard | memset (buf, 0x80, len << info->shift);
|
613 | 1d14ffa9 | bellard | } |
614 | 1d14ffa9 | bellard | else {
|
615 | 1d14ffa9 | bellard | int i;
|
616 | 1d14ffa9 | bellard | uint16_t *p = buf; |
617 | 1d14ffa9 | bellard | int shift = info->nchannels - 1; |
618 | 1d14ffa9 | bellard | short s = INT16_MAX;
|
619 | 1d14ffa9 | bellard | |
620 | d929eba5 | bellard | if (info->swap_endianness) {
|
621 | 1d14ffa9 | bellard | s = bswap16 (s); |
622 | 1d14ffa9 | bellard | } |
623 | 1d14ffa9 | bellard | |
624 | 1d14ffa9 | bellard | for (i = 0; i < len << shift; i++) { |
625 | 1d14ffa9 | bellard | p[i] = s; |
626 | 1d14ffa9 | bellard | } |
627 | 1d14ffa9 | bellard | } |
628 | 85571bc7 | bellard | } |
629 | 85571bc7 | bellard | } |
630 | 85571bc7 | bellard | |
631 | 1d14ffa9 | bellard | /*
|
632 | 8ead62cf | bellard | * Capture
|
633 | 8ead62cf | bellard | */
|
634 | 8ead62cf | bellard | static void noop_conv (st_sample_t *dst, const void *src, |
635 | 8ead62cf | bellard | int samples, volume_t *vol)
|
636 | 8ead62cf | bellard | { |
637 | 8ead62cf | bellard | (void) src;
|
638 | 8ead62cf | bellard | (void) dst;
|
639 | 8ead62cf | bellard | (void) samples;
|
640 | 8ead62cf | bellard | (void) vol;
|
641 | 8ead62cf | bellard | } |
642 | 8ead62cf | bellard | |
643 | 8ead62cf | bellard | static CaptureVoiceOut *audio_pcm_capture_find_specific (
|
644 | 8ead62cf | bellard | AudioState *s, |
645 | d929eba5 | bellard | audsettings_t *as |
646 | 8ead62cf | bellard | ) |
647 | 8ead62cf | bellard | { |
648 | 8ead62cf | bellard | CaptureVoiceOut *cap; |
649 | 8ead62cf | bellard | |
650 | 8ead62cf | bellard | for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
|
651 | d929eba5 | bellard | if (audio_pcm_info_eq (&cap->hw.info, as)) {
|
652 | 8ead62cf | bellard | return cap;
|
653 | 8ead62cf | bellard | } |
654 | 8ead62cf | bellard | } |
655 | 8ead62cf | bellard | return NULL; |
656 | 8ead62cf | bellard | } |
657 | 8ead62cf | bellard | |
658 | ec36b695 | bellard | static void audio_notify_capture (CaptureVoiceOut *cap, audcnotification_e cmd) |
659 | 8ead62cf | bellard | { |
660 | ec36b695 | bellard | struct capture_callback *cb;
|
661 | ec36b695 | bellard | |
662 | ec36b695 | bellard | #ifdef DEBUG_CAPTURE
|
663 | ec36b695 | bellard | dolog ("notification %d sent\n", cmd);
|
664 | ec36b695 | bellard | #endif
|
665 | ec36b695 | bellard | for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
|
666 | ec36b695 | bellard | cb->ops.notify (cb->opaque, cmd); |
667 | ec36b695 | bellard | } |
668 | ec36b695 | bellard | } |
669 | 8ead62cf | bellard | |
670 | ec36b695 | bellard | static void audio_capture_maybe_changed (CaptureVoiceOut *cap, int enabled) |
671 | ec36b695 | bellard | { |
672 | ec36b695 | bellard | if (cap->hw.enabled != enabled) {
|
673 | ec36b695 | bellard | audcnotification_e cmd; |
674 | 8ead62cf | bellard | cap->hw.enabled = enabled; |
675 | ec36b695 | bellard | cmd = enabled ? AUD_CNOTIFY_ENABLE : AUD_CNOTIFY_DISABLE; |
676 | ec36b695 | bellard | audio_notify_capture (cap, cmd); |
677 | 8ead62cf | bellard | } |
678 | 8ead62cf | bellard | } |
679 | 8ead62cf | bellard | |
680 | 8ead62cf | bellard | static void audio_recalc_and_notify_capture (CaptureVoiceOut *cap) |
681 | 8ead62cf | bellard | { |
682 | 8ead62cf | bellard | HWVoiceOut *hw = &cap->hw; |
683 | 8ead62cf | bellard | SWVoiceOut *sw; |
684 | 8ead62cf | bellard | int enabled = 0; |
685 | 8ead62cf | bellard | |
686 | ec36b695 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
687 | 8ead62cf | bellard | if (sw->active) {
|
688 | 8ead62cf | bellard | enabled = 1;
|
689 | 8ead62cf | bellard | break;
|
690 | 8ead62cf | bellard | } |
691 | 8ead62cf | bellard | } |
692 | ec36b695 | bellard | audio_capture_maybe_changed (cap, enabled); |
693 | 8ead62cf | bellard | } |
694 | 8ead62cf | bellard | |
695 | 8ead62cf | bellard | static void audio_detach_capture (HWVoiceOut *hw) |
696 | 8ead62cf | bellard | { |
697 | ec36b695 | bellard | SWVoiceCap *sc = hw->cap_head.lh_first; |
698 | ec36b695 | bellard | |
699 | ec36b695 | bellard | while (sc) {
|
700 | ec36b695 | bellard | SWVoiceCap *sc1 = sc->entries.le_next; |
701 | ec36b695 | bellard | SWVoiceOut *sw = &sc->sw; |
702 | ec36b695 | bellard | CaptureVoiceOut *cap = sc->cap; |
703 | ec36b695 | bellard | int was_active = sw->active;
|
704 | 8ead62cf | bellard | |
705 | 8ead62cf | bellard | if (sw->rate) {
|
706 | 8ead62cf | bellard | st_rate_stop (sw->rate); |
707 | 8ead62cf | bellard | sw->rate = NULL;
|
708 | 8ead62cf | bellard | } |
709 | 8ead62cf | bellard | |
710 | 8ead62cf | bellard | LIST_REMOVE (sw, entries); |
711 | ec36b695 | bellard | LIST_REMOVE (sc, entries); |
712 | ec36b695 | bellard | qemu_free (sc); |
713 | ec36b695 | bellard | if (was_active) {
|
714 | ec36b695 | bellard | /* We have removed soft voice from the capture:
|
715 | ec36b695 | bellard | this might have changed the overall status of the capture
|
716 | ec36b695 | bellard | since this might have been the only active voice */
|
717 | ec36b695 | bellard | audio_recalc_and_notify_capture (cap); |
718 | ec36b695 | bellard | } |
719 | ec36b695 | bellard | sc = sc1; |
720 | 8ead62cf | bellard | } |
721 | 8ead62cf | bellard | } |
722 | 8ead62cf | bellard | |
723 | 8ead62cf | bellard | static int audio_attach_capture (AudioState *s, HWVoiceOut *hw) |
724 | 8ead62cf | bellard | { |
725 | 8ead62cf | bellard | CaptureVoiceOut *cap; |
726 | 8ead62cf | bellard | |
727 | 8ead62cf | bellard | audio_detach_capture (hw); |
728 | 8ead62cf | bellard | for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
|
729 | ec36b695 | bellard | SWVoiceCap *sc; |
730 | 8ead62cf | bellard | SWVoiceOut *sw; |
731 | ec36b695 | bellard | HWVoiceOut *hw_cap = &cap->hw; |
732 | 8ead62cf | bellard | |
733 | ec36b695 | bellard | sc = audio_calloc (AUDIO_FUNC, 1, sizeof (*sc)); |
734 | ec36b695 | bellard | if (!sc) {
|
735 | 8ead62cf | bellard | dolog ("Could not allocate soft capture voice (%zu bytes)\n",
|
736 | ec36b695 | bellard | sizeof (*sc));
|
737 | 8ead62cf | bellard | return -1; |
738 | 8ead62cf | bellard | } |
739 | 8ead62cf | bellard | |
740 | ec36b695 | bellard | sc->cap = cap; |
741 | ec36b695 | bellard | sw = &sc->sw; |
742 | 8ead62cf | bellard | sw->hw = hw_cap; |
743 | ec36b695 | bellard | sw->info = hw->info; |
744 | 8ead62cf | bellard | sw->empty = 1;
|
745 | 8ead62cf | bellard | sw->active = hw->enabled; |
746 | 8ead62cf | bellard | sw->conv = noop_conv; |
747 | 8ead62cf | bellard | sw->ratio = ((int64_t) hw_cap->info.freq << 32) / sw->info.freq;
|
748 | 8ead62cf | bellard | sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq); |
749 | 8ead62cf | bellard | if (!sw->rate) {
|
750 | 8ead62cf | bellard | dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw));
|
751 | 8ead62cf | bellard | qemu_free (sw); |
752 | 8ead62cf | bellard | return -1; |
753 | 8ead62cf | bellard | } |
754 | 8ead62cf | bellard | LIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries); |
755 | ec36b695 | bellard | LIST_INSERT_HEAD (&hw->cap_head, sc, entries); |
756 | ec36b695 | bellard | #ifdef DEBUG_CAPTURE
|
757 | ec36b695 | bellard | asprintf (&sw->name, "for %p %d,%d,%d",
|
758 | ec36b695 | bellard | hw, sw->info.freq, sw->info.bits, sw->info.nchannels); |
759 | ec36b695 | bellard | dolog ("Added %s active = %d\n", sw->name, sw->active);
|
760 | ec36b695 | bellard | #endif
|
761 | 8ead62cf | bellard | if (sw->active) {
|
762 | ec36b695 | bellard | audio_capture_maybe_changed (cap, 1);
|
763 | 8ead62cf | bellard | } |
764 | 8ead62cf | bellard | } |
765 | 8ead62cf | bellard | return 0; |
766 | 8ead62cf | bellard | } |
767 | 8ead62cf | bellard | |
768 | 8ead62cf | bellard | /*
|
769 | 1d14ffa9 | bellard | * Hard voice (capture)
|
770 | 1d14ffa9 | bellard | */
|
771 | c0fe3827 | bellard | static int audio_pcm_hw_find_min_in (HWVoiceIn *hw) |
772 | 85571bc7 | bellard | { |
773 | 1d14ffa9 | bellard | SWVoiceIn *sw; |
774 | 1d14ffa9 | bellard | int m = hw->total_samples_captured;
|
775 | 1d14ffa9 | bellard | |
776 | 1d14ffa9 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
777 | 1d14ffa9 | bellard | if (sw->active) {
|
778 | 1d14ffa9 | bellard | m = audio_MIN (m, sw->total_hw_samples_acquired); |
779 | 1d14ffa9 | bellard | } |
780 | 85571bc7 | bellard | } |
781 | 1d14ffa9 | bellard | return m;
|
782 | 85571bc7 | bellard | } |
783 | 85571bc7 | bellard | |
784 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_in (HWVoiceIn *hw)
|
785 | 85571bc7 | bellard | { |
786 | 1d14ffa9 | bellard | int live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
|
787 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
788 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hw->samples);
|
789 | 1d14ffa9 | bellard | return 0; |
790 | 85571bc7 | bellard | } |
791 | 1d14ffa9 | bellard | return live;
|
792 | 85571bc7 | bellard | } |
793 | 85571bc7 | bellard | |
794 | 1d14ffa9 | bellard | /*
|
795 | 1d14ffa9 | bellard | * Soft voice (capture)
|
796 | 1d14ffa9 | bellard | */
|
797 | 1d14ffa9 | bellard | static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw) |
798 | 1d14ffa9 | bellard | { |
799 | 1d14ffa9 | bellard | HWVoiceIn *hw = sw->hw; |
800 | 1d14ffa9 | bellard | int live = hw->total_samples_captured - sw->total_hw_samples_acquired;
|
801 | 1d14ffa9 | bellard | int rpos;
|
802 | 1d14ffa9 | bellard | |
803 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
804 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hw->samples);
|
805 | 1d14ffa9 | bellard | return 0; |
806 | 1d14ffa9 | bellard | } |
807 | 1d14ffa9 | bellard | |
808 | 1d14ffa9 | bellard | rpos = hw->wpos - live; |
809 | 1d14ffa9 | bellard | if (rpos >= 0) { |
810 | 1d14ffa9 | bellard | return rpos;
|
811 | 85571bc7 | bellard | } |
812 | 85571bc7 | bellard | else {
|
813 | 1d14ffa9 | bellard | return hw->samples + rpos;
|
814 | 85571bc7 | bellard | } |
815 | 85571bc7 | bellard | } |
816 | 85571bc7 | bellard | |
817 | 1d14ffa9 | bellard | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) |
818 | 85571bc7 | bellard | { |
819 | 1d14ffa9 | bellard | HWVoiceIn *hw = sw->hw; |
820 | 1d14ffa9 | bellard | int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0; |
821 | 571ec3d6 | bellard | st_sample_t *src, *dst = sw->buf; |
822 | 1d14ffa9 | bellard | |
823 | 1d14ffa9 | bellard | rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples; |
824 | 1d14ffa9 | bellard | |
825 | 1d14ffa9 | bellard | live = hw->total_samples_captured - sw->total_hw_samples_acquired; |
826 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
827 | 1d14ffa9 | bellard | dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);
|
828 | 1d14ffa9 | bellard | return 0; |
829 | 1d14ffa9 | bellard | } |
830 | 1d14ffa9 | bellard | |
831 | 1d14ffa9 | bellard | samples = size >> sw->info.shift; |
832 | 1d14ffa9 | bellard | if (!live) {
|
833 | 1d14ffa9 | bellard | return 0; |
834 | 1d14ffa9 | bellard | } |
835 | 85571bc7 | bellard | |
836 | 1d14ffa9 | bellard | swlim = (live * sw->ratio) >> 32;
|
837 | 1d14ffa9 | bellard | swlim = audio_MIN (swlim, samples); |
838 | 85571bc7 | bellard | |
839 | 1d14ffa9 | bellard | while (swlim) {
|
840 | 1d14ffa9 | bellard | src = hw->conv_buf + rpos; |
841 | 1d14ffa9 | bellard | isamp = hw->wpos - rpos; |
842 | 1d14ffa9 | bellard | /* XXX: <= ? */
|
843 | 1d14ffa9 | bellard | if (isamp <= 0) { |
844 | 1d14ffa9 | bellard | isamp = hw->samples - rpos; |
845 | 1d14ffa9 | bellard | } |
846 | 85571bc7 | bellard | |
847 | 1d14ffa9 | bellard | if (!isamp) {
|
848 | 1d14ffa9 | bellard | break;
|
849 | 1d14ffa9 | bellard | } |
850 | 1d14ffa9 | bellard | osamp = swlim; |
851 | 85571bc7 | bellard | |
852 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, osamp < 0)) { |
853 | 1d14ffa9 | bellard | dolog ("osamp=%d\n", osamp);
|
854 | c0fe3827 | bellard | return 0; |
855 | 1d14ffa9 | bellard | } |
856 | 85571bc7 | bellard | |
857 | 1d14ffa9 | bellard | st_rate_flow (sw->rate, src, dst, &isamp, &osamp); |
858 | 1d14ffa9 | bellard | swlim -= osamp; |
859 | 1d14ffa9 | bellard | rpos = (rpos + isamp) % hw->samples; |
860 | 1d14ffa9 | bellard | dst += osamp; |
861 | 1d14ffa9 | bellard | ret += osamp; |
862 | 1d14ffa9 | bellard | total += isamp; |
863 | 1d14ffa9 | bellard | } |
864 | 85571bc7 | bellard | |
865 | 571ec3d6 | bellard | sw->clip (buf, sw->buf, ret); |
866 | 1d14ffa9 | bellard | sw->total_hw_samples_acquired += total; |
867 | 1d14ffa9 | bellard | return ret << sw->info.shift;
|
868 | 85571bc7 | bellard | } |
869 | 85571bc7 | bellard | |
870 | 1d14ffa9 | bellard | /*
|
871 | 1d14ffa9 | bellard | * Hard voice (playback)
|
872 | 1d14ffa9 | bellard | */
|
873 | c0fe3827 | bellard | static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep) |
874 | 1d14ffa9 | bellard | { |
875 | c0fe3827 | bellard | SWVoiceOut *sw; |
876 | c0fe3827 | bellard | int m = INT_MAX;
|
877 | c0fe3827 | bellard | int nb_live = 0; |
878 | 85571bc7 | bellard | |
879 | c0fe3827 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
880 | c0fe3827 | bellard | if (sw->active || !sw->empty) {
|
881 | c0fe3827 | bellard | m = audio_MIN (m, sw->total_hw_samples_mixed); |
882 | c0fe3827 | bellard | nb_live += 1;
|
883 | c0fe3827 | bellard | } |
884 | 85571bc7 | bellard | } |
885 | c0fe3827 | bellard | |
886 | c0fe3827 | bellard | *nb_livep = nb_live; |
887 | c0fe3827 | bellard | return m;
|
888 | 1d14ffa9 | bellard | } |
889 | 85571bc7 | bellard | |
890 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live) |
891 | 1d14ffa9 | bellard | { |
892 | 1d14ffa9 | bellard | int smin;
|
893 | 85571bc7 | bellard | |
894 | 1d14ffa9 | bellard | smin = audio_pcm_hw_find_min_out (hw, nb_live); |
895 | 1d14ffa9 | bellard | |
896 | 1d14ffa9 | bellard | if (!*nb_live) {
|
897 | 1d14ffa9 | bellard | return 0; |
898 | 85571bc7 | bellard | } |
899 | 85571bc7 | bellard | else {
|
900 | 1d14ffa9 | bellard | int live = smin;
|
901 | 1d14ffa9 | bellard | |
902 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
903 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hw->samples);
|
904 | 1d14ffa9 | bellard | return 0; |
905 | 85571bc7 | bellard | } |
906 | 1d14ffa9 | bellard | return live;
|
907 | 85571bc7 | bellard | } |
908 | 1d14ffa9 | bellard | } |
909 | 1d14ffa9 | bellard | |
910 | 1d14ffa9 | bellard | int audio_pcm_hw_get_live_out (HWVoiceOut *hw)
|
911 | 1d14ffa9 | bellard | { |
912 | 1d14ffa9 | bellard | int nb_live;
|
913 | 1d14ffa9 | bellard | int live;
|
914 | 85571bc7 | bellard | |
915 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_out2 (hw, &nb_live); |
916 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
917 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hw->samples);
|
918 | 1d14ffa9 | bellard | return 0; |
919 | 85571bc7 | bellard | } |
920 | 1d14ffa9 | bellard | return live;
|
921 | 85571bc7 | bellard | } |
922 | 85571bc7 | bellard | |
923 | 1d14ffa9 | bellard | /*
|
924 | 1d14ffa9 | bellard | * Soft voice (playback)
|
925 | 1d14ffa9 | bellard | */
|
926 | 1d14ffa9 | bellard | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) |
927 | 85571bc7 | bellard | { |
928 | 1d14ffa9 | bellard | int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
|
929 | 1d14ffa9 | bellard | int ret = 0, pos = 0, total = 0; |
930 | 85571bc7 | bellard | |
931 | 1d14ffa9 | bellard | if (!sw) {
|
932 | 1d14ffa9 | bellard | return size;
|
933 | 1d14ffa9 | bellard | } |
934 | 85571bc7 | bellard | |
935 | 1d14ffa9 | bellard | hwsamples = sw->hw->samples; |
936 | 85571bc7 | bellard | |
937 | 1d14ffa9 | bellard | live = sw->total_hw_samples_mixed; |
938 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hwsamples)){ |
939 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hwsamples);
|
940 | 1d14ffa9 | bellard | return 0; |
941 | 1d14ffa9 | bellard | } |
942 | 85571bc7 | bellard | |
943 | 1d14ffa9 | bellard | if (live == hwsamples) {
|
944 | ec36b695 | bellard | #ifdef DEBUG_OUT
|
945 | ec36b695 | bellard | dolog ("%s is full %d\n", sw->name, live);
|
946 | ec36b695 | bellard | #endif
|
947 | 1d14ffa9 | bellard | return 0; |
948 | 1d14ffa9 | bellard | } |
949 | 85571bc7 | bellard | |
950 | 1d14ffa9 | bellard | wpos = (sw->hw->rpos + live) % hwsamples; |
951 | 1d14ffa9 | bellard | samples = size >> sw->info.shift; |
952 | 85571bc7 | bellard | |
953 | 1d14ffa9 | bellard | dead = hwsamples - live; |
954 | 1d14ffa9 | bellard | swlim = ((int64_t) dead << 32) / sw->ratio;
|
955 | 1d14ffa9 | bellard | swlim = audio_MIN (swlim, samples); |
956 | 1d14ffa9 | bellard | if (swlim) {
|
957 | 1d14ffa9 | bellard | sw->conv (sw->buf, buf, swlim, &sw->vol); |
958 | 1d14ffa9 | bellard | } |
959 | 1d14ffa9 | bellard | |
960 | 1d14ffa9 | bellard | while (swlim) {
|
961 | 1d14ffa9 | bellard | dead = hwsamples - live; |
962 | 1d14ffa9 | bellard | left = hwsamples - wpos; |
963 | 1d14ffa9 | bellard | blck = audio_MIN (dead, left); |
964 | 1d14ffa9 | bellard | if (!blck) {
|
965 | 1d14ffa9 | bellard | break;
|
966 | 1d14ffa9 | bellard | } |
967 | 1d14ffa9 | bellard | isamp = swlim; |
968 | 1d14ffa9 | bellard | osamp = blck; |
969 | 1d14ffa9 | bellard | st_rate_flow_mix ( |
970 | 1d14ffa9 | bellard | sw->rate, |
971 | 1d14ffa9 | bellard | sw->buf + pos, |
972 | 1d14ffa9 | bellard | sw->hw->mix_buf + wpos, |
973 | 1d14ffa9 | bellard | &isamp, |
974 | 1d14ffa9 | bellard | &osamp |
975 | 1d14ffa9 | bellard | ); |
976 | 1d14ffa9 | bellard | ret += isamp; |
977 | 1d14ffa9 | bellard | swlim -= isamp; |
978 | 1d14ffa9 | bellard | pos += isamp; |
979 | 1d14ffa9 | bellard | live += osamp; |
980 | 1d14ffa9 | bellard | wpos = (wpos + osamp) % hwsamples; |
981 | 1d14ffa9 | bellard | total += osamp; |
982 | 1d14ffa9 | bellard | } |
983 | 1d14ffa9 | bellard | |
984 | 1d14ffa9 | bellard | sw->total_hw_samples_mixed += total; |
985 | 1d14ffa9 | bellard | sw->empty = sw->total_hw_samples_mixed == 0;
|
986 | 1d14ffa9 | bellard | |
987 | 1d14ffa9 | bellard | #ifdef DEBUG_OUT
|
988 | 1d14ffa9 | bellard | dolog ( |
989 | c0fe3827 | bellard | "%s: write size %d ret %d total sw %d\n",
|
990 | c0fe3827 | bellard | SW_NAME (sw), |
991 | 1d14ffa9 | bellard | size >> sw->info.shift, |
992 | 1d14ffa9 | bellard | ret, |
993 | c0fe3827 | bellard | sw->total_hw_samples_mixed |
994 | 1d14ffa9 | bellard | ); |
995 | 1d14ffa9 | bellard | #endif
|
996 | 1d14ffa9 | bellard | |
997 | 1d14ffa9 | bellard | return ret << sw->info.shift;
|
998 | 85571bc7 | bellard | } |
999 | 85571bc7 | bellard | |
1000 | 1d14ffa9 | bellard | #ifdef DEBUG_AUDIO
|
1001 | 1d14ffa9 | bellard | static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info) |
1002 | 85571bc7 | bellard | { |
1003 | 1d14ffa9 | bellard | dolog ("%s: bits %d, sign %d, freq %d, nchan %d\n",
|
1004 | 1d14ffa9 | bellard | cap, info->bits, info->sign, info->freq, info->nchannels); |
1005 | 85571bc7 | bellard | } |
1006 | 1d14ffa9 | bellard | #endif
|
1007 | 85571bc7 | bellard | |
1008 | 1d14ffa9 | bellard | #define DAC
|
1009 | 1d14ffa9 | bellard | #include "audio_template.h" |
1010 | 1d14ffa9 | bellard | #undef DAC
|
1011 | 1d14ffa9 | bellard | #include "audio_template.h" |
1012 | 1d14ffa9 | bellard | |
1013 | 1d14ffa9 | bellard | int AUD_write (SWVoiceOut *sw, void *buf, int size) |
1014 | 85571bc7 | bellard | { |
1015 | 1d14ffa9 | bellard | int bytes;
|
1016 | 85571bc7 | bellard | |
1017 | 1d14ffa9 | bellard | if (!sw) {
|
1018 | 1d14ffa9 | bellard | /* XXX: Consider options */
|
1019 | 1d14ffa9 | bellard | return size;
|
1020 | 1d14ffa9 | bellard | } |
1021 | 85571bc7 | bellard | |
1022 | 1d14ffa9 | bellard | if (!sw->hw->enabled) {
|
1023 | c0fe3827 | bellard | dolog ("Writing to disabled voice %s\n", SW_NAME (sw));
|
1024 | 85571bc7 | bellard | return 0; |
1025 | 85571bc7 | bellard | } |
1026 | 85571bc7 | bellard | |
1027 | 1d14ffa9 | bellard | bytes = sw->hw->pcm_ops->write (sw, buf, size); |
1028 | 1d14ffa9 | bellard | return bytes;
|
1029 | 1d14ffa9 | bellard | } |
1030 | 1d14ffa9 | bellard | |
1031 | 1d14ffa9 | bellard | int AUD_read (SWVoiceIn *sw, void *buf, int size) |
1032 | 1d14ffa9 | bellard | { |
1033 | 1d14ffa9 | bellard | int bytes;
|
1034 | 85571bc7 | bellard | |
1035 | 1d14ffa9 | bellard | if (!sw) {
|
1036 | 1d14ffa9 | bellard | /* XXX: Consider options */
|
1037 | 1d14ffa9 | bellard | return size;
|
1038 | 85571bc7 | bellard | } |
1039 | 1d14ffa9 | bellard | |
1040 | 1d14ffa9 | bellard | if (!sw->hw->enabled) {
|
1041 | c0fe3827 | bellard | dolog ("Reading from disabled voice %s\n", SW_NAME (sw));
|
1042 | 1d14ffa9 | bellard | return 0; |
1043 | 85571bc7 | bellard | } |
1044 | 1d14ffa9 | bellard | |
1045 | 1d14ffa9 | bellard | bytes = sw->hw->pcm_ops->read (sw, buf, size); |
1046 | 1d14ffa9 | bellard | return bytes;
|
1047 | 85571bc7 | bellard | } |
1048 | 85571bc7 | bellard | |
1049 | 1d14ffa9 | bellard | int AUD_get_buffer_size_out (SWVoiceOut *sw)
|
1050 | 85571bc7 | bellard | { |
1051 | c0fe3827 | bellard | return sw->hw->samples << sw->hw->info.shift;
|
1052 | 1d14ffa9 | bellard | } |
1053 | 1d14ffa9 | bellard | |
1054 | 1d14ffa9 | bellard | void AUD_set_active_out (SWVoiceOut *sw, int on) |
1055 | 1d14ffa9 | bellard | { |
1056 | 1d14ffa9 | bellard | HWVoiceOut *hw; |
1057 | 85571bc7 | bellard | |
1058 | 1d14ffa9 | bellard | if (!sw) {
|
1059 | 85571bc7 | bellard | return;
|
1060 | 1d14ffa9 | bellard | } |
1061 | 85571bc7 | bellard | |
1062 | 85571bc7 | bellard | hw = sw->hw; |
1063 | 1d14ffa9 | bellard | if (sw->active != on) {
|
1064 | 1d14ffa9 | bellard | SWVoiceOut *temp_sw; |
1065 | ec36b695 | bellard | SWVoiceCap *sc; |
1066 | 1d14ffa9 | bellard | |
1067 | 1d14ffa9 | bellard | if (on) {
|
1068 | 1d14ffa9 | bellard | hw->pending_disable = 0;
|
1069 | 1d14ffa9 | bellard | if (!hw->enabled) {
|
1070 | 1d14ffa9 | bellard | hw->enabled = 1;
|
1071 | 1d14ffa9 | bellard | hw->pcm_ops->ctl_out (hw, VOICE_ENABLE); |
1072 | 1d14ffa9 | bellard | } |
1073 | 1d14ffa9 | bellard | } |
1074 | 1d14ffa9 | bellard | else {
|
1075 | 1d14ffa9 | bellard | if (hw->enabled) {
|
1076 | 1d14ffa9 | bellard | int nb_active = 0; |
1077 | 1d14ffa9 | bellard | |
1078 | 1d14ffa9 | bellard | for (temp_sw = hw->sw_head.lh_first; temp_sw;
|
1079 | 1d14ffa9 | bellard | temp_sw = temp_sw->entries.le_next) { |
1080 | 1d14ffa9 | bellard | nb_active += temp_sw->active != 0;
|
1081 | 1d14ffa9 | bellard | } |
1082 | 1d14ffa9 | bellard | |
1083 | 1d14ffa9 | bellard | hw->pending_disable = nb_active == 1;
|
1084 | 1d14ffa9 | bellard | } |
1085 | 85571bc7 | bellard | } |
1086 | ec36b695 | bellard | |
1087 | ec36b695 | bellard | for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
|
1088 | ec36b695 | bellard | sc->sw.active = hw->enabled; |
1089 | 8ead62cf | bellard | if (hw->enabled) {
|
1090 | ec36b695 | bellard | audio_capture_maybe_changed (sc->cap, 1);
|
1091 | 8ead62cf | bellard | } |
1092 | 8ead62cf | bellard | } |
1093 | 1d14ffa9 | bellard | sw->active = on; |
1094 | 1d14ffa9 | bellard | } |
1095 | 1d14ffa9 | bellard | } |
1096 | 1d14ffa9 | bellard | |
1097 | 1d14ffa9 | bellard | void AUD_set_active_in (SWVoiceIn *sw, int on) |
1098 | 1d14ffa9 | bellard | { |
1099 | 1d14ffa9 | bellard | HWVoiceIn *hw; |
1100 | 1d14ffa9 | bellard | |
1101 | 1d14ffa9 | bellard | if (!sw) {
|
1102 | 1d14ffa9 | bellard | return;
|
1103 | 85571bc7 | bellard | } |
1104 | 85571bc7 | bellard | |
1105 | 1d14ffa9 | bellard | hw = sw->hw; |
1106 | 85571bc7 | bellard | if (sw->active != on) {
|
1107 | 1d14ffa9 | bellard | SWVoiceIn *temp_sw; |
1108 | 1d14ffa9 | bellard | |
1109 | 85571bc7 | bellard | if (on) {
|
1110 | 85571bc7 | bellard | if (!hw->enabled) {
|
1111 | 85571bc7 | bellard | hw->enabled = 1;
|
1112 | 1d14ffa9 | bellard | hw->pcm_ops->ctl_in (hw, VOICE_ENABLE); |
1113 | 85571bc7 | bellard | } |
1114 | 1d14ffa9 | bellard | sw->total_hw_samples_acquired = hw->total_samples_captured; |
1115 | 85571bc7 | bellard | } |
1116 | 85571bc7 | bellard | else {
|
1117 | 1d14ffa9 | bellard | if (hw->enabled) {
|
1118 | 85571bc7 | bellard | int nb_active = 0; |
1119 | 1d14ffa9 | bellard | |
1120 | 1d14ffa9 | bellard | for (temp_sw = hw->sw_head.lh_first; temp_sw;
|
1121 | 1d14ffa9 | bellard | temp_sw = temp_sw->entries.le_next) { |
1122 | 1d14ffa9 | bellard | nb_active += temp_sw->active != 0;
|
1123 | 85571bc7 | bellard | } |
1124 | 85571bc7 | bellard | |
1125 | 85571bc7 | bellard | if (nb_active == 1) { |
1126 | 1d14ffa9 | bellard | hw->enabled = 0;
|
1127 | 1d14ffa9 | bellard | hw->pcm_ops->ctl_in (hw, VOICE_DISABLE); |
1128 | 85571bc7 | bellard | } |
1129 | 85571bc7 | bellard | } |
1130 | 85571bc7 | bellard | } |
1131 | 85571bc7 | bellard | sw->active = on; |
1132 | 85571bc7 | bellard | } |
1133 | 85571bc7 | bellard | } |
1134 | 85571bc7 | bellard | |
1135 | 1d14ffa9 | bellard | static int audio_get_avail (SWVoiceIn *sw) |
1136 | 1d14ffa9 | bellard | { |
1137 | 1d14ffa9 | bellard | int live;
|
1138 | 1d14ffa9 | bellard | |
1139 | 1d14ffa9 | bellard | if (!sw) {
|
1140 | 1d14ffa9 | bellard | return 0; |
1141 | 1d14ffa9 | bellard | } |
1142 | 1d14ffa9 | bellard | |
1143 | 1d14ffa9 | bellard | live = sw->hw->total_samples_captured - sw->total_hw_samples_acquired; |
1144 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) { |
1145 | 1d14ffa9 | bellard | dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
|
1146 | 1d14ffa9 | bellard | return 0; |
1147 | 1d14ffa9 | bellard | } |
1148 | 1d14ffa9 | bellard | |
1149 | 1d14ffa9 | bellard | ldebug ( |
1150 | 26a76461 | bellard | "%s: get_avail live %d ret %" PRId64 "\n", |
1151 | c0fe3827 | bellard | SW_NAME (sw), |
1152 | 1d14ffa9 | bellard | live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift
|
1153 | 1d14ffa9 | bellard | ); |
1154 | 1d14ffa9 | bellard | |
1155 | 1d14ffa9 | bellard | return (((int64_t) live << 32) / sw->ratio) << sw->info.shift; |
1156 | 1d14ffa9 | bellard | } |
1157 | 1d14ffa9 | bellard | |
1158 | 1d14ffa9 | bellard | static int audio_get_free (SWVoiceOut *sw) |
1159 | 1d14ffa9 | bellard | { |
1160 | 1d14ffa9 | bellard | int live, dead;
|
1161 | 1d14ffa9 | bellard | |
1162 | 1d14ffa9 | bellard | if (!sw) {
|
1163 | 1d14ffa9 | bellard | return 0; |
1164 | 1d14ffa9 | bellard | } |
1165 | 1d14ffa9 | bellard | |
1166 | 1d14ffa9 | bellard | live = sw->total_hw_samples_mixed; |
1167 | 1d14ffa9 | bellard | |
1168 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) { |
1169 | 1d14ffa9 | bellard | dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
|
1170 | c0fe3827 | bellard | return 0; |
1171 | 1d14ffa9 | bellard | } |
1172 | 1d14ffa9 | bellard | |
1173 | 1d14ffa9 | bellard | dead = sw->hw->samples - live; |
1174 | 1d14ffa9 | bellard | |
1175 | 1d14ffa9 | bellard | #ifdef DEBUG_OUT
|
1176 | 26a76461 | bellard | dolog ("%s: get_free live %d dead %d ret %" PRId64 "\n", |
1177 | c0fe3827 | bellard | SW_NAME (sw), |
1178 | 1d14ffa9 | bellard | live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift);
|
1179 | 85571bc7 | bellard | #endif
|
1180 | 1d14ffa9 | bellard | |
1181 | 1d14ffa9 | bellard | return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift; |
1182 | 1d14ffa9 | bellard | } |
1183 | 1d14ffa9 | bellard | |
1184 | 8ead62cf | bellard | static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples) |
1185 | 8ead62cf | bellard | { |
1186 | 8ead62cf | bellard | int n;
|
1187 | 8ead62cf | bellard | |
1188 | 8ead62cf | bellard | if (hw->enabled) {
|
1189 | ec36b695 | bellard | SWVoiceCap *sc; |
1190 | 8ead62cf | bellard | |
1191 | ec36b695 | bellard | for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
|
1192 | ec36b695 | bellard | SWVoiceOut *sw = &sc->sw; |
1193 | 8ead62cf | bellard | int rpos2 = rpos;
|
1194 | 8ead62cf | bellard | |
1195 | 8ead62cf | bellard | n = samples; |
1196 | 8ead62cf | bellard | while (n) {
|
1197 | 8ead62cf | bellard | int till_end_of_hw = hw->samples - rpos2;
|
1198 | 8ead62cf | bellard | int to_write = audio_MIN (till_end_of_hw, n);
|
1199 | 8ead62cf | bellard | int bytes = to_write << hw->info.shift;
|
1200 | 8ead62cf | bellard | int written;
|
1201 | 8ead62cf | bellard | |
1202 | 8ead62cf | bellard | sw->buf = hw->mix_buf + rpos2; |
1203 | 8ead62cf | bellard | written = audio_pcm_sw_write (sw, NULL, bytes);
|
1204 | 8ead62cf | bellard | if (written - bytes) {
|
1205 | ec36b695 | bellard | dolog ("Could not mix %d bytes into a capture "
|
1206 | ec36b695 | bellard | "buffer, mixed %d\n",
|
1207 | ec36b695 | bellard | bytes, written); |
1208 | 8ead62cf | bellard | break;
|
1209 | 8ead62cf | bellard | } |
1210 | 8ead62cf | bellard | n -= to_write; |
1211 | 8ead62cf | bellard | rpos2 = (rpos2 + to_write) % hw->samples; |
1212 | 8ead62cf | bellard | } |
1213 | 8ead62cf | bellard | } |
1214 | 8ead62cf | bellard | } |
1215 | 8ead62cf | bellard | |
1216 | 8ead62cf | bellard | n = audio_MIN (samples, hw->samples - rpos); |
1217 | 8ead62cf | bellard | mixeng_clear (hw->mix_buf + rpos, n); |
1218 | 8ead62cf | bellard | mixeng_clear (hw->mix_buf, samples - n); |
1219 | 8ead62cf | bellard | } |
1220 | 8ead62cf | bellard | |
1221 | c0fe3827 | bellard | static void audio_run_out (AudioState *s) |
1222 | 1d14ffa9 | bellard | { |
1223 | 1d14ffa9 | bellard | HWVoiceOut *hw = NULL;
|
1224 | 1d14ffa9 | bellard | SWVoiceOut *sw; |
1225 | 1d14ffa9 | bellard | |
1226 | c0fe3827 | bellard | while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
|
1227 | 1d14ffa9 | bellard | int played;
|
1228 | 8ead62cf | bellard | int live, free, nb_live, cleanup_required, prev_rpos;
|
1229 | 1d14ffa9 | bellard | |
1230 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_out2 (hw, &nb_live); |
1231 | 1d14ffa9 | bellard | if (!nb_live) {
|
1232 | 1d14ffa9 | bellard | live = 0;
|
1233 | 1d14ffa9 | bellard | } |
1234 | c0fe3827 | bellard | |
1235 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
1236 | 1d14ffa9 | bellard | dolog ("live=%d hw->samples=%d\n", live, hw->samples);
|
1237 | c0fe3827 | bellard | continue;
|
1238 | 1d14ffa9 | bellard | } |
1239 | 1d14ffa9 | bellard | |
1240 | 1d14ffa9 | bellard | if (hw->pending_disable && !nb_live) {
|
1241 | ec36b695 | bellard | SWVoiceCap *sc; |
1242 | 1d14ffa9 | bellard | #ifdef DEBUG_OUT
|
1243 | 1d14ffa9 | bellard | dolog ("Disabling voice\n");
|
1244 | 85571bc7 | bellard | #endif
|
1245 | 1d14ffa9 | bellard | hw->enabled = 0;
|
1246 | 1d14ffa9 | bellard | hw->pending_disable = 0;
|
1247 | 1d14ffa9 | bellard | hw->pcm_ops->ctl_out (hw, VOICE_DISABLE); |
1248 | ec36b695 | bellard | for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
|
1249 | ec36b695 | bellard | sc->sw.active = 0;
|
1250 | ec36b695 | bellard | audio_recalc_and_notify_capture (sc->cap); |
1251 | 8ead62cf | bellard | } |
1252 | 1d14ffa9 | bellard | continue;
|
1253 | 1d14ffa9 | bellard | } |
1254 | 1d14ffa9 | bellard | |
1255 | 1d14ffa9 | bellard | if (!live) {
|
1256 | 1d14ffa9 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
1257 | 1d14ffa9 | bellard | if (sw->active) {
|
1258 | 1d14ffa9 | bellard | free = audio_get_free (sw); |
1259 | 1d14ffa9 | bellard | if (free > 0) { |
1260 | 1d14ffa9 | bellard | sw->callback.fn (sw->callback.opaque, free); |
1261 | 1d14ffa9 | bellard | } |
1262 | 1d14ffa9 | bellard | } |
1263 | 1d14ffa9 | bellard | } |
1264 | 1d14ffa9 | bellard | continue;
|
1265 | 1d14ffa9 | bellard | } |
1266 | 1d14ffa9 | bellard | |
1267 | 8ead62cf | bellard | prev_rpos = hw->rpos; |
1268 | 1d14ffa9 | bellard | played = hw->pcm_ops->run_out (hw); |
1269 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, hw->rpos >= hw->samples)) {
|
1270 | 1d14ffa9 | bellard | dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
|
1271 | 1d14ffa9 | bellard | hw->rpos, hw->samples, played); |
1272 | 1d14ffa9 | bellard | hw->rpos = 0;
|
1273 | 1d14ffa9 | bellard | } |
1274 | 1d14ffa9 | bellard | |
1275 | 1d14ffa9 | bellard | #ifdef DEBUG_OUT
|
1276 | c0fe3827 | bellard | dolog ("played=%d\n", played);
|
1277 | 85571bc7 | bellard | #endif
|
1278 | 1d14ffa9 | bellard | |
1279 | 1d14ffa9 | bellard | if (played) {
|
1280 | 1d14ffa9 | bellard | hw->ts_helper += played; |
1281 | 8ead62cf | bellard | audio_capture_mix_and_clear (hw, prev_rpos, played); |
1282 | 1d14ffa9 | bellard | } |
1283 | 1d14ffa9 | bellard | |
1284 | c0fe3827 | bellard | cleanup_required = 0;
|
1285 | 1d14ffa9 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
1286 | 1d14ffa9 | bellard | if (!sw->active && sw->empty) {
|
1287 | 1d14ffa9 | bellard | continue;
|
1288 | 1d14ffa9 | bellard | } |
1289 | 1d14ffa9 | bellard | |
1290 | 1d14ffa9 | bellard | if (audio_bug (AUDIO_FUNC, played > sw->total_hw_samples_mixed)) {
|
1291 | 1d14ffa9 | bellard | dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
|
1292 | 1d14ffa9 | bellard | played, sw->total_hw_samples_mixed); |
1293 | 1d14ffa9 | bellard | played = sw->total_hw_samples_mixed; |
1294 | 1d14ffa9 | bellard | } |
1295 | 1d14ffa9 | bellard | |
1296 | 1d14ffa9 | bellard | sw->total_hw_samples_mixed -= played; |
1297 | 1d14ffa9 | bellard | |
1298 | 1d14ffa9 | bellard | if (!sw->total_hw_samples_mixed) {
|
1299 | 1d14ffa9 | bellard | sw->empty = 1;
|
1300 | c0fe3827 | bellard | cleanup_required |= !sw->active && !sw->callback.fn; |
1301 | 1d14ffa9 | bellard | } |
1302 | 1d14ffa9 | bellard | |
1303 | 1d14ffa9 | bellard | if (sw->active) {
|
1304 | 1d14ffa9 | bellard | free = audio_get_free (sw); |
1305 | 1d14ffa9 | bellard | if (free > 0) { |
1306 | 1d14ffa9 | bellard | sw->callback.fn (sw->callback.opaque, free); |
1307 | 1d14ffa9 | bellard | } |
1308 | 1d14ffa9 | bellard | } |
1309 | 1d14ffa9 | bellard | } |
1310 | c0fe3827 | bellard | |
1311 | c0fe3827 | bellard | if (cleanup_required) {
|
1312 | ec36b695 | bellard | SWVoiceOut *sw1; |
1313 | ec36b695 | bellard | |
1314 | ec36b695 | bellard | sw = hw->sw_head.lh_first; |
1315 | ec36b695 | bellard | while (sw) {
|
1316 | ec36b695 | bellard | sw1 = sw->entries.le_next; |
1317 | c0fe3827 | bellard | if (!sw->active && !sw->callback.fn) {
|
1318 | c0fe3827 | bellard | #ifdef DEBUG_PLIVE
|
1319 | c0fe3827 | bellard | dolog ("Finishing with old voice\n");
|
1320 | c0fe3827 | bellard | #endif
|
1321 | c0fe3827 | bellard | audio_close_out (s, sw); |
1322 | c0fe3827 | bellard | } |
1323 | ec36b695 | bellard | sw = sw1; |
1324 | c0fe3827 | bellard | } |
1325 | c0fe3827 | bellard | } |
1326 | 1d14ffa9 | bellard | } |
1327 | 1d14ffa9 | bellard | } |
1328 | 1d14ffa9 | bellard | |
1329 | c0fe3827 | bellard | static void audio_run_in (AudioState *s) |
1330 | 1d14ffa9 | bellard | { |
1331 | 1d14ffa9 | bellard | HWVoiceIn *hw = NULL;
|
1332 | 1d14ffa9 | bellard | |
1333 | c0fe3827 | bellard | while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
|
1334 | 1d14ffa9 | bellard | SWVoiceIn *sw; |
1335 | 1d14ffa9 | bellard | int captured, min;
|
1336 | 1d14ffa9 | bellard | |
1337 | 1d14ffa9 | bellard | captured = hw->pcm_ops->run_in (hw); |
1338 | 1d14ffa9 | bellard | |
1339 | 1d14ffa9 | bellard | min = audio_pcm_hw_find_min_in (hw); |
1340 | 1d14ffa9 | bellard | hw->total_samples_captured += captured - min; |
1341 | 1d14ffa9 | bellard | hw->ts_helper += captured; |
1342 | 1d14ffa9 | bellard | |
1343 | 1d14ffa9 | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
1344 | 1d14ffa9 | bellard | sw->total_hw_samples_acquired -= min; |
1345 | 1d14ffa9 | bellard | |
1346 | 1d14ffa9 | bellard | if (sw->active) {
|
1347 | 1d14ffa9 | bellard | int avail;
|
1348 | 1d14ffa9 | bellard | |
1349 | 1d14ffa9 | bellard | avail = audio_get_avail (sw); |
1350 | 1d14ffa9 | bellard | if (avail > 0) { |
1351 | 1d14ffa9 | bellard | sw->callback.fn (sw->callback.opaque, avail); |
1352 | 1d14ffa9 | bellard | } |
1353 | 1d14ffa9 | bellard | } |
1354 | 1d14ffa9 | bellard | } |
1355 | 1d14ffa9 | bellard | } |
1356 | 1d14ffa9 | bellard | } |
1357 | 1d14ffa9 | bellard | |
1358 | 8ead62cf | bellard | static void audio_run_capture (AudioState *s) |
1359 | 8ead62cf | bellard | { |
1360 | 8ead62cf | bellard | CaptureVoiceOut *cap; |
1361 | 8ead62cf | bellard | |
1362 | 8ead62cf | bellard | for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
|
1363 | 8ead62cf | bellard | int live, rpos, captured;
|
1364 | 8ead62cf | bellard | HWVoiceOut *hw = &cap->hw; |
1365 | 8ead62cf | bellard | SWVoiceOut *sw; |
1366 | 8ead62cf | bellard | |
1367 | 8ead62cf | bellard | captured = live = audio_pcm_hw_get_live_out (hw); |
1368 | 8ead62cf | bellard | rpos = hw->rpos; |
1369 | 8ead62cf | bellard | while (live) {
|
1370 | 8ead62cf | bellard | int left = hw->samples - rpos;
|
1371 | 8ead62cf | bellard | int to_capture = audio_MIN (live, left);
|
1372 | 8ead62cf | bellard | st_sample_t *src; |
1373 | 8ead62cf | bellard | struct capture_callback *cb;
|
1374 | 8ead62cf | bellard | |
1375 | 8ead62cf | bellard | src = hw->mix_buf + rpos; |
1376 | 8ead62cf | bellard | hw->clip (cap->buf, src, to_capture); |
1377 | 8ead62cf | bellard | mixeng_clear (src, to_capture); |
1378 | 8ead62cf | bellard | |
1379 | 8ead62cf | bellard | for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
|
1380 | 8ead62cf | bellard | cb->ops.capture (cb->opaque, cap->buf, |
1381 | 8ead62cf | bellard | to_capture << hw->info.shift); |
1382 | 8ead62cf | bellard | } |
1383 | 8ead62cf | bellard | rpos = (rpos + to_capture) % hw->samples; |
1384 | 8ead62cf | bellard | live -= to_capture; |
1385 | 8ead62cf | bellard | } |
1386 | 8ead62cf | bellard | hw->rpos = rpos; |
1387 | 8ead62cf | bellard | |
1388 | 8ead62cf | bellard | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
|
1389 | 8ead62cf | bellard | if (!sw->active && sw->empty) {
|
1390 | 8ead62cf | bellard | continue;
|
1391 | 8ead62cf | bellard | } |
1392 | 8ead62cf | bellard | |
1393 | 8ead62cf | bellard | if (audio_bug (AUDIO_FUNC, captured > sw->total_hw_samples_mixed)) {
|
1394 | 8ead62cf | bellard | dolog ("captured=%d sw->total_hw_samples_mixed=%d\n",
|
1395 | 8ead62cf | bellard | captured, sw->total_hw_samples_mixed); |
1396 | 8ead62cf | bellard | captured = sw->total_hw_samples_mixed; |
1397 | 8ead62cf | bellard | } |
1398 | 8ead62cf | bellard | |
1399 | 8ead62cf | bellard | sw->total_hw_samples_mixed -= captured; |
1400 | 8ead62cf | bellard | sw->empty = sw->total_hw_samples_mixed == 0;
|
1401 | 8ead62cf | bellard | } |
1402 | 8ead62cf | bellard | } |
1403 | 8ead62cf | bellard | } |
1404 | 8ead62cf | bellard | |
1405 | 571ec3d6 | bellard | static void audio_timer (void *opaque) |
1406 | 571ec3d6 | bellard | { |
1407 | 571ec3d6 | bellard | AudioState *s = opaque; |
1408 | 571ec3d6 | bellard | |
1409 | 571ec3d6 | bellard | audio_run_out (s); |
1410 | 571ec3d6 | bellard | audio_run_in (s); |
1411 | 8ead62cf | bellard | audio_run_capture (s); |
1412 | 571ec3d6 | bellard | |
1413 | 571ec3d6 | bellard | qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks); |
1414 | 571ec3d6 | bellard | } |
1415 | 571ec3d6 | bellard | |
1416 | 1d14ffa9 | bellard | static struct audio_option audio_options[] = { |
1417 | 1d14ffa9 | bellard | /* DAC */
|
1418 | c0fe3827 | bellard | {"DAC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_out.enabled,
|
1419 | 1d14ffa9 | bellard | "Use fixed settings for host DAC", NULL, 0}, |
1420 | 1d14ffa9 | bellard | |
1421 | c0fe3827 | bellard | {"DAC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_out.settings.freq,
|
1422 | 1d14ffa9 | bellard | "Frequency for fixed host DAC", NULL, 0}, |
1423 | 1d14ffa9 | bellard | |
1424 | c0fe3827 | bellard | {"DAC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_out.settings.fmt,
|
1425 | 1d14ffa9 | bellard | "Format for fixed host DAC", NULL, 0}, |
1426 | 1d14ffa9 | bellard | |
1427 | c0fe3827 | bellard | {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_out.settings.nchannels,
|
1428 | 1d14ffa9 | bellard | "Number of channels for fixed DAC (1 - mono, 2 - stereo)", NULL, 0}, |
1429 | 1d14ffa9 | bellard | |
1430 | c0fe3827 | bellard | {"DAC_VOICES", AUD_OPT_INT, &conf.fixed_out.nb_voices,
|
1431 | 1d14ffa9 | bellard | "Number of voices for DAC", NULL, 0}, |
1432 | 1d14ffa9 | bellard | |
1433 | 1d14ffa9 | bellard | /* ADC */
|
1434 | c0fe3827 | bellard | {"ADC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_in.enabled,
|
1435 | 1d14ffa9 | bellard | "Use fixed settings for host ADC", NULL, 0}, |
1436 | 1d14ffa9 | bellard | |
1437 | c0fe3827 | bellard | {"ADC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_in.settings.freq,
|
1438 | c0fe3827 | bellard | "Frequency for fixed host ADC", NULL, 0}, |
1439 | 1d14ffa9 | bellard | |
1440 | c0fe3827 | bellard | {"ADC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_in.settings.fmt,
|
1441 | c0fe3827 | bellard | "Format for fixed host ADC", NULL, 0}, |
1442 | 1d14ffa9 | bellard | |
1443 | c0fe3827 | bellard | {"ADC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_in.settings.nchannels,
|
1444 | 1d14ffa9 | bellard | "Number of channels for fixed ADC (1 - mono, 2 - stereo)", NULL, 0}, |
1445 | 1d14ffa9 | bellard | |
1446 | c0fe3827 | bellard | {"ADC_VOICES", AUD_OPT_INT, &conf.fixed_in.nb_voices,
|
1447 | 1d14ffa9 | bellard | "Number of voices for ADC", NULL, 0}, |
1448 | 1d14ffa9 | bellard | |
1449 | 1d14ffa9 | bellard | /* Misc */
|
1450 | c0fe3827 | bellard | {"TIMER_PERIOD", AUD_OPT_INT, &conf.period.hz,
|
1451 | c0fe3827 | bellard | "Timer period in HZ (0 - use lowest possible)", NULL, 0}, |
1452 | 1d14ffa9 | bellard | |
1453 | c0fe3827 | bellard | {"PLIVE", AUD_OPT_BOOL, &conf.plive,
|
1454 | 1d14ffa9 | bellard | "(undocumented)", NULL, 0}, |
1455 | 1d14ffa9 | bellard | |
1456 | 541e0844 | bellard | {"LOG_TO_MONITOR", AUD_OPT_BOOL, &conf.log_to_monitor,
|
1457 | 541e0844 | bellard | "print logging messages to montior instead of stderr", NULL, 0}, |
1458 | 541e0844 | bellard | |
1459 | 1d14ffa9 | bellard | {NULL, 0, NULL, NULL, NULL, 0} |
1460 | 85571bc7 | bellard | }; |
1461 | 85571bc7 | bellard | |
1462 | 571ec3d6 | bellard | static void audio_pp_nb_voices (const char *typ, int nb) |
1463 | 571ec3d6 | bellard | { |
1464 | 571ec3d6 | bellard | switch (nb) {
|
1465 | 571ec3d6 | bellard | case 0: |
1466 | 571ec3d6 | bellard | printf ("Does not support %s\n", typ);
|
1467 | 571ec3d6 | bellard | break;
|
1468 | 571ec3d6 | bellard | case 1: |
1469 | 571ec3d6 | bellard | printf ("One %s voice\n", typ);
|
1470 | 571ec3d6 | bellard | break;
|
1471 | 571ec3d6 | bellard | case INT_MAX:
|
1472 | 571ec3d6 | bellard | printf ("Theoretically supports many %s voices\n", typ);
|
1473 | 571ec3d6 | bellard | break;
|
1474 | 571ec3d6 | bellard | default:
|
1475 | 571ec3d6 | bellard | printf ("Theoretically supports upto %d %s voices\n", nb, typ);
|
1476 | 571ec3d6 | bellard | break;
|
1477 | 571ec3d6 | bellard | } |
1478 | 571ec3d6 | bellard | |
1479 | 571ec3d6 | bellard | } |
1480 | 571ec3d6 | bellard | |
1481 | 1d14ffa9 | bellard | void AUD_help (void) |
1482 | 1d14ffa9 | bellard | { |
1483 | 1d14ffa9 | bellard | size_t i; |
1484 | 1d14ffa9 | bellard | |
1485 | 1d14ffa9 | bellard | audio_process_options ("AUDIO", audio_options);
|
1486 | 1d14ffa9 | bellard | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1487 | 1d14ffa9 | bellard | struct audio_driver *d = drvtab[i];
|
1488 | 1d14ffa9 | bellard | if (d->options) {
|
1489 | 1d14ffa9 | bellard | audio_process_options (d->name, d->options); |
1490 | 1d14ffa9 | bellard | } |
1491 | 1d14ffa9 | bellard | } |
1492 | 1d14ffa9 | bellard | |
1493 | 1d14ffa9 | bellard | printf ("Audio options:\n");
|
1494 | 1d14ffa9 | bellard | audio_print_options ("AUDIO", audio_options);
|
1495 | 1d14ffa9 | bellard | printf ("\n");
|
1496 | 1d14ffa9 | bellard | |
1497 | 1d14ffa9 | bellard | printf ("Available drivers:\n");
|
1498 | 1d14ffa9 | bellard | |
1499 | 1d14ffa9 | bellard | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1500 | 1d14ffa9 | bellard | struct audio_driver *d = drvtab[i];
|
1501 | 1d14ffa9 | bellard | |
1502 | 1d14ffa9 | bellard | printf ("Name: %s\n", d->name);
|
1503 | 1d14ffa9 | bellard | printf ("Description: %s\n", d->descr);
|
1504 | 1d14ffa9 | bellard | |
1505 | 571ec3d6 | bellard | audio_pp_nb_voices ("playback", d->max_voices_out);
|
1506 | 571ec3d6 | bellard | audio_pp_nb_voices ("capture", d->max_voices_in);
|
1507 | 1d14ffa9 | bellard | |
1508 | 1d14ffa9 | bellard | if (d->options) {
|
1509 | 1d14ffa9 | bellard | printf ("Options:\n");
|
1510 | 1d14ffa9 | bellard | audio_print_options (d->name, d->options); |
1511 | 1d14ffa9 | bellard | } |
1512 | 1d14ffa9 | bellard | else {
|
1513 | 1d14ffa9 | bellard | printf ("No options\n");
|
1514 | 1d14ffa9 | bellard | } |
1515 | 1d14ffa9 | bellard | printf ("\n");
|
1516 | 1d14ffa9 | bellard | } |
1517 | 1d14ffa9 | bellard | |
1518 | 1d14ffa9 | bellard | printf ( |
1519 | 1d14ffa9 | bellard | "Options are settable through environment variables.\n"
|
1520 | 1d14ffa9 | bellard | "Example:\n"
|
1521 | 1d14ffa9 | bellard | #ifdef _WIN32
|
1522 | 1d14ffa9 | bellard | " set QEMU_AUDIO_DRV=wav\n"
|
1523 | 571ec3d6 | bellard | " set QEMU_WAV_PATH=c:\\tune.wav\n"
|
1524 | 1d14ffa9 | bellard | #else
|
1525 | 1d14ffa9 | bellard | " export QEMU_AUDIO_DRV=wav\n"
|
1526 | 1d14ffa9 | bellard | " export QEMU_WAV_PATH=$HOME/tune.wav\n"
|
1527 | 1d14ffa9 | bellard | "(for csh replace export with setenv in the above)\n"
|
1528 | 1d14ffa9 | bellard | #endif
|
1529 | 1d14ffa9 | bellard | " qemu ...\n\n"
|
1530 | 1d14ffa9 | bellard | ); |
1531 | 1d14ffa9 | bellard | } |
1532 | 1d14ffa9 | bellard | |
1533 | c0fe3827 | bellard | static int audio_driver_init (AudioState *s, struct audio_driver *drv) |
1534 | 85571bc7 | bellard | { |
1535 | 1d14ffa9 | bellard | if (drv->options) {
|
1536 | 1d14ffa9 | bellard | audio_process_options (drv->name, drv->options); |
1537 | 1d14ffa9 | bellard | } |
1538 | c0fe3827 | bellard | s->drv_opaque = drv->init (); |
1539 | 1d14ffa9 | bellard | |
1540 | c0fe3827 | bellard | if (s->drv_opaque) {
|
1541 | 571ec3d6 | bellard | audio_init_nb_voices_out (s, drv); |
1542 | 571ec3d6 | bellard | audio_init_nb_voices_in (s, drv); |
1543 | c0fe3827 | bellard | s->drv = drv; |
1544 | 1d14ffa9 | bellard | return 0; |
1545 | 85571bc7 | bellard | } |
1546 | 85571bc7 | bellard | else {
|
1547 | 1d14ffa9 | bellard | dolog ("Could not init `%s' audio driver\n", drv->name);
|
1548 | 1d14ffa9 | bellard | return -1; |
1549 | 85571bc7 | bellard | } |
1550 | 85571bc7 | bellard | } |
1551 | 85571bc7 | bellard | |
1552 | 541e0844 | bellard | static void audio_vm_change_state_handler (void *opaque, int running) |
1553 | 85571bc7 | bellard | { |
1554 | c0fe3827 | bellard | AudioState *s = opaque; |
1555 | 1d14ffa9 | bellard | HWVoiceOut *hwo = NULL;
|
1556 | 1d14ffa9 | bellard | HWVoiceIn *hwi = NULL;
|
1557 | 541e0844 | bellard | int op = running ? VOICE_ENABLE : VOICE_DISABLE;
|
1558 | 1d14ffa9 | bellard | |
1559 | 541e0844 | bellard | while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
|
1560 | 541e0844 | bellard | hwo->pcm_ops->ctl_out (hwo, op); |
1561 | 1d14ffa9 | bellard | } |
1562 | 85571bc7 | bellard | |
1563 | 541e0844 | bellard | while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
|
1564 | 541e0844 | bellard | hwi->pcm_ops->ctl_in (hwi, op); |
1565 | 85571bc7 | bellard | } |
1566 | 85571bc7 | bellard | } |
1567 | 85571bc7 | bellard | |
1568 | 85571bc7 | bellard | static void audio_atexit (void) |
1569 | 85571bc7 | bellard | { |
1570 | c0fe3827 | bellard | AudioState *s = &glob_audio_state; |
1571 | 1d14ffa9 | bellard | HWVoiceOut *hwo = NULL;
|
1572 | 1d14ffa9 | bellard | HWVoiceIn *hwi = NULL;
|
1573 | 1d14ffa9 | bellard | |
1574 | 571ec3d6 | bellard | while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
|
1575 | ec36b695 | bellard | SWVoiceCap *sc; |
1576 | 8ead62cf | bellard | |
1577 | 571ec3d6 | bellard | hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE); |
1578 | 1d14ffa9 | bellard | hwo->pcm_ops->fini_out (hwo); |
1579 | 8ead62cf | bellard | |
1580 | ec36b695 | bellard | for (sc = hwo->cap_head.lh_first; sc; sc = sc->entries.le_next) {
|
1581 | ec36b695 | bellard | CaptureVoiceOut *cap = sc->cap; |
1582 | ec36b695 | bellard | struct capture_callback *cb;
|
1583 | ec36b695 | bellard | |
1584 | ec36b695 | bellard | for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
|
1585 | ec36b695 | bellard | cb->ops.destroy (cb->opaque); |
1586 | ec36b695 | bellard | } |
1587 | 8ead62cf | bellard | } |
1588 | 1d14ffa9 | bellard | } |
1589 | 85571bc7 | bellard | |
1590 | 571ec3d6 | bellard | while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
|
1591 | 571ec3d6 | bellard | hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE); |
1592 | 1d14ffa9 | bellard | hwi->pcm_ops->fini_in (hwi); |
1593 | 85571bc7 | bellard | } |
1594 | c0fe3827 | bellard | |
1595 | c0fe3827 | bellard | if (s->drv) {
|
1596 | c0fe3827 | bellard | s->drv->fini (s->drv_opaque); |
1597 | c0fe3827 | bellard | } |
1598 | 85571bc7 | bellard | } |
1599 | 85571bc7 | bellard | |
1600 | 85571bc7 | bellard | static void audio_save (QEMUFile *f, void *opaque) |
1601 | 85571bc7 | bellard | { |
1602 | 1d14ffa9 | bellard | (void) f;
|
1603 | 1d14ffa9 | bellard | (void) opaque;
|
1604 | 85571bc7 | bellard | } |
1605 | 85571bc7 | bellard | |
1606 | 85571bc7 | bellard | static int audio_load (QEMUFile *f, void *opaque, int version_id) |
1607 | 85571bc7 | bellard | { |
1608 | 1d14ffa9 | bellard | (void) f;
|
1609 | 1d14ffa9 | bellard | (void) opaque;
|
1610 | 1d14ffa9 | bellard | |
1611 | 1d14ffa9 | bellard | if (version_id != 1) { |
1612 | 85571bc7 | bellard | return -EINVAL;
|
1613 | 1d14ffa9 | bellard | } |
1614 | 85571bc7 | bellard | |
1615 | 85571bc7 | bellard | return 0; |
1616 | 85571bc7 | bellard | } |
1617 | 85571bc7 | bellard | |
1618 | c0fe3827 | bellard | void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card) |
1619 | c0fe3827 | bellard | { |
1620 | c0fe3827 | bellard | card->audio = s; |
1621 | c0fe3827 | bellard | card->name = qemu_strdup (name); |
1622 | c0fe3827 | bellard | memset (&card->entries, 0, sizeof (card->entries)); |
1623 | c0fe3827 | bellard | LIST_INSERT_HEAD (&s->card_head, card, entries); |
1624 | c0fe3827 | bellard | } |
1625 | c0fe3827 | bellard | |
1626 | c0fe3827 | bellard | void AUD_remove_card (QEMUSoundCard *card)
|
1627 | c0fe3827 | bellard | { |
1628 | c0fe3827 | bellard | LIST_REMOVE (card, entries); |
1629 | c0fe3827 | bellard | card->audio = NULL;
|
1630 | c0fe3827 | bellard | qemu_free (card->name); |
1631 | c0fe3827 | bellard | } |
1632 | c0fe3827 | bellard | |
1633 | c0fe3827 | bellard | AudioState *AUD_init (void)
|
1634 | 85571bc7 | bellard | { |
1635 | 1d14ffa9 | bellard | size_t i; |
1636 | 85571bc7 | bellard | int done = 0; |
1637 | 85571bc7 | bellard | const char *drvname; |
1638 | c0fe3827 | bellard | AudioState *s = &glob_audio_state; |
1639 | 1d14ffa9 | bellard | |
1640 | 571ec3d6 | bellard | LIST_INIT (&s->hw_head_out); |
1641 | 571ec3d6 | bellard | LIST_INIT (&s->hw_head_in); |
1642 | 8ead62cf | bellard | LIST_INIT (&s->cap_head); |
1643 | 571ec3d6 | bellard | atexit (audio_atexit); |
1644 | 571ec3d6 | bellard | |
1645 | 571ec3d6 | bellard | s->ts = qemu_new_timer (vm_clock, audio_timer, s); |
1646 | 571ec3d6 | bellard | if (!s->ts) {
|
1647 | 571ec3d6 | bellard | dolog ("Could not create audio timer\n");
|
1648 | 571ec3d6 | bellard | return NULL; |
1649 | 571ec3d6 | bellard | } |
1650 | 571ec3d6 | bellard | |
1651 | 1d14ffa9 | bellard | audio_process_options ("AUDIO", audio_options);
|
1652 | 1d14ffa9 | bellard | |
1653 | c0fe3827 | bellard | s->nb_hw_voices_out = conf.fixed_out.nb_voices; |
1654 | c0fe3827 | bellard | s->nb_hw_voices_in = conf.fixed_in.nb_voices; |
1655 | c0fe3827 | bellard | |
1656 | 1d14ffa9 | bellard | if (s->nb_hw_voices_out <= 0) { |
1657 | 571ec3d6 | bellard | dolog ("Bogus number of playback voices %d, setting to 1\n",
|
1658 | 1d14ffa9 | bellard | s->nb_hw_voices_out); |
1659 | 1d14ffa9 | bellard | s->nb_hw_voices_out = 1;
|
1660 | 1d14ffa9 | bellard | } |
1661 | 1d14ffa9 | bellard | |
1662 | 1d14ffa9 | bellard | if (s->nb_hw_voices_in <= 0) { |
1663 | 571ec3d6 | bellard | dolog ("Bogus number of capture voices %d, setting to 0\n",
|
1664 | 1d14ffa9 | bellard | s->nb_hw_voices_in); |
1665 | 571ec3d6 | bellard | s->nb_hw_voices_in = 0;
|
1666 | 1d14ffa9 | bellard | } |
1667 | 85571bc7 | bellard | |
1668 | 1d14ffa9 | bellard | { |
1669 | 1d14ffa9 | bellard | int def;
|
1670 | 1d14ffa9 | bellard | drvname = audio_get_conf_str ("QEMU_AUDIO_DRV", NULL, &def); |
1671 | 1d14ffa9 | bellard | } |
1672 | 85571bc7 | bellard | |
1673 | 85571bc7 | bellard | if (drvname) {
|
1674 | 85571bc7 | bellard | int found = 0; |
1675 | 1d14ffa9 | bellard | |
1676 | 85571bc7 | bellard | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1677 | 85571bc7 | bellard | if (!strcmp (drvname, drvtab[i]->name)) {
|
1678 | c0fe3827 | bellard | done = !audio_driver_init (s, drvtab[i]); |
1679 | 85571bc7 | bellard | found = 1;
|
1680 | 85571bc7 | bellard | break;
|
1681 | 85571bc7 | bellard | } |
1682 | 85571bc7 | bellard | } |
1683 | 1d14ffa9 | bellard | |
1684 | 85571bc7 | bellard | if (!found) {
|
1685 | 85571bc7 | bellard | dolog ("Unknown audio driver `%s'\n", drvname);
|
1686 | 1d14ffa9 | bellard | dolog ("Run with -audio-help to list available drivers\n");
|
1687 | 85571bc7 | bellard | } |
1688 | 85571bc7 | bellard | } |
1689 | 85571bc7 | bellard | |
1690 | 85571bc7 | bellard | if (!done) {
|
1691 | 85571bc7 | bellard | for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1692 | 1d14ffa9 | bellard | if (drvtab[i]->can_be_default) {
|
1693 | c0fe3827 | bellard | done = !audio_driver_init (s, drvtab[i]); |
1694 | 1d14ffa9 | bellard | } |
1695 | 85571bc7 | bellard | } |
1696 | 85571bc7 | bellard | } |
1697 | 85571bc7 | bellard | |
1698 | 85571bc7 | bellard | if (!done) {
|
1699 | c0fe3827 | bellard | done = !audio_driver_init (s, &no_audio_driver); |
1700 | c0fe3827 | bellard | if (!done) {
|
1701 | c0fe3827 | bellard | dolog ("Could not initialize audio subsystem\n");
|
1702 | 1d14ffa9 | bellard | } |
1703 | 1d14ffa9 | bellard | else {
|
1704 | c0fe3827 | bellard | dolog ("warning: Using timer based audio emulation\n");
|
1705 | 1d14ffa9 | bellard | } |
1706 | 85571bc7 | bellard | } |
1707 | 1d14ffa9 | bellard | |
1708 | c0fe3827 | bellard | if (done) {
|
1709 | 571ec3d6 | bellard | VMChangeStateEntry *e; |
1710 | 571ec3d6 | bellard | |
1711 | c0fe3827 | bellard | if (conf.period.hz <= 0) { |
1712 | c0fe3827 | bellard | if (conf.period.hz < 0) { |
1713 | c0fe3827 | bellard | dolog ("warning: Timer period is negative - %d "
|
1714 | c0fe3827 | bellard | "treating as zero\n",
|
1715 | c0fe3827 | bellard | conf.period.hz); |
1716 | c0fe3827 | bellard | } |
1717 | c0fe3827 | bellard | conf.period.ticks = 1;
|
1718 | 1d14ffa9 | bellard | } |
1719 | c0fe3827 | bellard | else {
|
1720 | c0fe3827 | bellard | conf.period.ticks = ticks_per_sec / conf.period.hz; |
1721 | c0fe3827 | bellard | } |
1722 | c0fe3827 | bellard | |
1723 | 571ec3d6 | bellard | e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s); |
1724 | 571ec3d6 | bellard | if (!e) {
|
1725 | 571ec3d6 | bellard | dolog ("warning: Could not register change state handler\n"
|
1726 | 571ec3d6 | bellard | "(Audio can continue looping even after stopping the VM)\n");
|
1727 | 571ec3d6 | bellard | } |
1728 | 1d14ffa9 | bellard | } |
1729 | 1d14ffa9 | bellard | else {
|
1730 | c0fe3827 | bellard | qemu_del_timer (s->ts); |
1731 | c0fe3827 | bellard | return NULL; |
1732 | 1d14ffa9 | bellard | } |
1733 | 1d14ffa9 | bellard | |
1734 | c0fe3827 | bellard | LIST_INIT (&s->card_head); |
1735 | c0fe3827 | bellard | register_savevm ("audio", 0, 1, audio_save, audio_load, s); |
1736 | c0fe3827 | bellard | qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks); |
1737 | c0fe3827 | bellard | return s;
|
1738 | 85571bc7 | bellard | } |
1739 | 8ead62cf | bellard | |
1740 | ec36b695 | bellard | CaptureVoiceOut *AUD_add_capture ( |
1741 | 8ead62cf | bellard | AudioState *s, |
1742 | 8ead62cf | bellard | audsettings_t *as, |
1743 | 8ead62cf | bellard | struct audio_capture_ops *ops,
|
1744 | 8ead62cf | bellard | void *cb_opaque
|
1745 | 8ead62cf | bellard | ) |
1746 | 8ead62cf | bellard | { |
1747 | 8ead62cf | bellard | CaptureVoiceOut *cap; |
1748 | 8ead62cf | bellard | struct capture_callback *cb;
|
1749 | 8ead62cf | bellard | |
1750 | 8ead62cf | bellard | if (!s) {
|
1751 | 8ead62cf | bellard | /* XXX suppress */
|
1752 | 8ead62cf | bellard | s = &glob_audio_state; |
1753 | 8ead62cf | bellard | } |
1754 | 8ead62cf | bellard | |
1755 | ec36b695 | bellard | if (audio_validate_settings (as)) {
|
1756 | 8ead62cf | bellard | dolog ("Invalid settings were passed when trying to add capture\n");
|
1757 | 8ead62cf | bellard | audio_print_settings (as); |
1758 | ec36b695 | bellard | goto err0;
|
1759 | 8ead62cf | bellard | } |
1760 | 8ead62cf | bellard | |
1761 | 8ead62cf | bellard | cb = audio_calloc (AUDIO_FUNC, 1, sizeof (*cb)); |
1762 | 8ead62cf | bellard | if (!cb) {
|
1763 | 8ead62cf | bellard | dolog ("Could not allocate capture callback information, size %zu\n",
|
1764 | 8ead62cf | bellard | sizeof (*cb));
|
1765 | 8ead62cf | bellard | goto err0;
|
1766 | 8ead62cf | bellard | } |
1767 | 8ead62cf | bellard | cb->ops = *ops; |
1768 | 8ead62cf | bellard | cb->opaque = cb_opaque; |
1769 | 8ead62cf | bellard | |
1770 | d929eba5 | bellard | cap = audio_pcm_capture_find_specific (s, as); |
1771 | 8ead62cf | bellard | if (cap) {
|
1772 | 8ead62cf | bellard | LIST_INSERT_HEAD (&cap->cb_head, cb, entries); |
1773 | ec36b695 | bellard | return cap;
|
1774 | 8ead62cf | bellard | } |
1775 | 8ead62cf | bellard | else {
|
1776 | 8ead62cf | bellard | HWVoiceOut *hw; |
1777 | 8ead62cf | bellard | CaptureVoiceOut *cap; |
1778 | 8ead62cf | bellard | |
1779 | 8ead62cf | bellard | cap = audio_calloc (AUDIO_FUNC, 1, sizeof (*cap)); |
1780 | 8ead62cf | bellard | if (!cap) {
|
1781 | 8ead62cf | bellard | dolog ("Could not allocate capture voice, size %zu\n",
|
1782 | 8ead62cf | bellard | sizeof (*cap));
|
1783 | 8ead62cf | bellard | goto err1;
|
1784 | 8ead62cf | bellard | } |
1785 | 8ead62cf | bellard | |
1786 | 8ead62cf | bellard | hw = &cap->hw; |
1787 | 8ead62cf | bellard | LIST_INIT (&hw->sw_head); |
1788 | 8ead62cf | bellard | LIST_INIT (&cap->cb_head); |
1789 | 8ead62cf | bellard | |
1790 | 8ead62cf | bellard | /* XXX find a more elegant way */
|
1791 | 8ead62cf | bellard | hw->samples = 4096 * 4; |
1792 | 8ead62cf | bellard | hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples, |
1793 | 8ead62cf | bellard | sizeof (st_sample_t));
|
1794 | 8ead62cf | bellard | if (!hw->mix_buf) {
|
1795 | 8ead62cf | bellard | dolog ("Could not allocate capture mix buffer (%d samples)\n",
|
1796 | 8ead62cf | bellard | hw->samples); |
1797 | 8ead62cf | bellard | goto err2;
|
1798 | 8ead62cf | bellard | } |
1799 | 8ead62cf | bellard | |
1800 | d929eba5 | bellard | audio_pcm_init_info (&hw->info, as); |
1801 | 8ead62cf | bellard | |
1802 | 8ead62cf | bellard | cap->buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
1803 | 8ead62cf | bellard | if (!cap->buf) {
|
1804 | 8ead62cf | bellard | dolog ("Could not allocate capture buffer "
|
1805 | 8ead62cf | bellard | "(%d samples, each %d bytes)\n",
|
1806 | 8ead62cf | bellard | hw->samples, 1 << hw->info.shift);
|
1807 | 8ead62cf | bellard | goto err3;
|
1808 | 8ead62cf | bellard | } |
1809 | 8ead62cf | bellard | |
1810 | 8ead62cf | bellard | hw->clip = mixeng_clip |
1811 | 8ead62cf | bellard | [hw->info.nchannels == 2]
|
1812 | 8ead62cf | bellard | [hw->info.sign] |
1813 | d929eba5 | bellard | [hw->info.swap_endianness] |
1814 | 8ead62cf | bellard | [hw->info.bits == 16];
|
1815 | 8ead62cf | bellard | |
1816 | 8ead62cf | bellard | LIST_INSERT_HEAD (&s->cap_head, cap, entries); |
1817 | 8ead62cf | bellard | LIST_INSERT_HEAD (&cap->cb_head, cb, entries); |
1818 | 8ead62cf | bellard | |
1819 | 8ead62cf | bellard | hw = NULL;
|
1820 | 8ead62cf | bellard | while ((hw = audio_pcm_hw_find_any_out (s, hw))) {
|
1821 | 8ead62cf | bellard | audio_attach_capture (s, hw); |
1822 | 8ead62cf | bellard | } |
1823 | ec36b695 | bellard | return cap;
|
1824 | 8ead62cf | bellard | |
1825 | 8ead62cf | bellard | err3:
|
1826 | 8ead62cf | bellard | qemu_free (cap->hw.mix_buf); |
1827 | 8ead62cf | bellard | err2:
|
1828 | 8ead62cf | bellard | qemu_free (cap); |
1829 | 8ead62cf | bellard | err1:
|
1830 | 8ead62cf | bellard | qemu_free (cb); |
1831 | 8ead62cf | bellard | err0:
|
1832 | ec36b695 | bellard | return NULL; |
1833 | ec36b695 | bellard | } |
1834 | ec36b695 | bellard | } |
1835 | ec36b695 | bellard | |
1836 | ec36b695 | bellard | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque) |
1837 | ec36b695 | bellard | { |
1838 | ec36b695 | bellard | struct capture_callback *cb;
|
1839 | ec36b695 | bellard | |
1840 | ec36b695 | bellard | for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
|
1841 | ec36b695 | bellard | if (cb->opaque == cb_opaque) {
|
1842 | ec36b695 | bellard | cb->ops.destroy (cb_opaque); |
1843 | ec36b695 | bellard | LIST_REMOVE (cb, entries); |
1844 | ec36b695 | bellard | qemu_free (cb); |
1845 | ec36b695 | bellard | |
1846 | ec36b695 | bellard | if (!cap->cb_head.lh_first) {
|
1847 | ec36b695 | bellard | SWVoiceOut *sw = cap->hw.sw_head.lh_first, *sw1; |
1848 | a3c25997 | bellard | |
1849 | ec36b695 | bellard | while (sw) {
|
1850 | a3c25997 | bellard | SWVoiceCap *sc = (SWVoiceCap *) sw; |
1851 | ec36b695 | bellard | #ifdef DEBUG_CAPTURE
|
1852 | ec36b695 | bellard | dolog ("freeing %s\n", sw->name);
|
1853 | ec36b695 | bellard | #endif
|
1854 | a3c25997 | bellard | |
1855 | ec36b695 | bellard | sw1 = sw->entries.le_next; |
1856 | ec36b695 | bellard | if (sw->rate) {
|
1857 | ec36b695 | bellard | st_rate_stop (sw->rate); |
1858 | ec36b695 | bellard | sw->rate = NULL;
|
1859 | ec36b695 | bellard | } |
1860 | ec36b695 | bellard | LIST_REMOVE (sw, entries); |
1861 | a3c25997 | bellard | LIST_REMOVE (sc, entries); |
1862 | a3c25997 | bellard | qemu_free (sc); |
1863 | ec36b695 | bellard | sw = sw1; |
1864 | ec36b695 | bellard | } |
1865 | ec36b695 | bellard | LIST_REMOVE (cap, entries); |
1866 | ec36b695 | bellard | qemu_free (cap); |
1867 | ec36b695 | bellard | } |
1868 | ec36b695 | bellard | return;
|
1869 | ec36b695 | bellard | } |
1870 | 8ead62cf | bellard | } |
1871 | 8ead62cf | bellard | } |