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