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