Commit c0fe3827ea18f7d29550f2ff2495cec2fe7a3d94
1 parent
f04308e4
audio merge (malc)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1601 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
23 changed files
with
981 additions
and
798 deletions
Makefile.target
... | ... | @@ -453,8 +453,8 @@ ifneq ($(wildcard .depend),) |
453 | 453 | include .depend |
454 | 454 | endif |
455 | 455 | |
456 | -ifeq (0, 1) | |
456 | +ifeq (1, 0) | |
457 | 457 | audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \ |
458 | -fmodaudio.o alsaaudio.o mixeng.o: \ | |
458 | +fmodaudio.o alsaaudio.o mixeng.o sb16.o es1370.o gus.o adlib.o: \ | |
459 | 459 | CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare |
460 | 460 | endif | ... | ... |
audio/alsaaudio.c
... | ... | @@ -98,7 +98,7 @@ struct alsa_params_obt { |
98 | 98 | audfmt_e fmt; |
99 | 99 | int nchannels; |
100 | 100 | int can_pause; |
101 | - snd_pcm_uframes_t buffer_size; | |
101 | + snd_pcm_uframes_t samples; | |
102 | 102 | }; |
103 | 103 | |
104 | 104 | static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...) |
... | ... | @@ -121,7 +121,7 @@ static void GCC_FMT_ATTR (3, 4) alsa_logerr2 ( |
121 | 121 | { |
122 | 122 | va_list ap; |
123 | 123 | |
124 | - AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); | |
124 | + AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); | |
125 | 125 | |
126 | 126 | va_start (ap, fmt); |
127 | 127 | AUD_vlog (AUDIO_CAP, fmt, ap); |
... | ... | @@ -209,7 +209,7 @@ static int alsa_to_audfmt (int alsafmt, audfmt_e *fmt, int *endianness) |
209 | 209 | return 0; |
210 | 210 | } |
211 | 211 | |
212 | -#ifdef DEBUG_MISMATCHES | |
212 | +#if defined DEBUG_MISMATCHES || defined DEBUG | |
213 | 213 | static void alsa_dump_info (struct alsa_params_req *req, |
214 | 214 | struct alsa_params_obt *obt) |
215 | 215 | { |
... | ... | @@ -221,7 +221,7 @@ static void alsa_dump_info (struct alsa_params_req *req, |
221 | 221 | dolog ("============================================\n"); |
222 | 222 | dolog ("requested: buffer size %d period size %d\n", |
223 | 223 | req->buffer_size, req->period_size); |
224 | - dolog ("obtained: buffer size %ld\n", obt->buffer_size); | |
224 | + dolog ("obtained: samples %ld\n", obt->samples); | |
225 | 225 | } |
226 | 226 | #endif |
227 | 227 | |
... | ... | @@ -234,14 +234,14 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) |
234 | 234 | |
235 | 235 | err = snd_pcm_sw_params_current (handle, sw_params); |
236 | 236 | if (err < 0) { |
237 | - dolog ("Can not fully initialize DAC\n"); | |
237 | + dolog ("Could not fully initialize DAC\n"); | |
238 | 238 | alsa_logerr (err, "Failed to get current software parameters\n"); |
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | 242 | err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold); |
243 | 243 | if (err < 0) { |
244 | - dolog ("Can not fully initialize DAC\n"); | |
244 | + dolog ("Could not fully initialize DAC\n"); | |
245 | 245 | alsa_logerr (err, "Failed to set software threshold to %ld\n", |
246 | 246 | threshold); |
247 | 247 | return; |
... | ... | @@ -249,7 +249,7 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) |
249 | 249 | |
250 | 250 | err = snd_pcm_sw_params (handle, sw_params); |
251 | 251 | if (err < 0) { |
252 | - dolog ("Can not fully initialize DAC\n"); | |
252 | + dolog ("Could not fully initialize DAC\n"); | |
253 | 253 | alsa_logerr (err, "Failed to set software parameters\n"); |
254 | 254 | return; |
255 | 255 | } |
... | ... | @@ -344,7 +344,8 @@ static int alsa_open (int in, struct alsa_params_req *req, |
344 | 344 | handle, |
345 | 345 | hw_params, |
346 | 346 | &period_size, |
347 | - 0); | |
347 | + 0 | |
348 | + ); | |
348 | 349 | if (err < 0) { |
349 | 350 | alsa_logerr2 (err, typ, |
350 | 351 | "Failed to set period time %d\n", |
... | ... | @@ -357,7 +358,8 @@ static int alsa_open (int in, struct alsa_params_req *req, |
357 | 358 | handle, |
358 | 359 | hw_params, |
359 | 360 | &buffer_size, |
360 | - 0); | |
361 | + 0 | |
362 | + ); | |
361 | 363 | |
362 | 364 | if (err < 0) { |
363 | 365 | alsa_logerr2 (err, typ, |
... | ... | @@ -382,7 +384,7 @@ static int alsa_open (int in, struct alsa_params_req *req, |
382 | 384 | if (err < 0) { |
383 | 385 | alsa_logerr ( |
384 | 386 | err, |
385 | - "Can not get minmal period size for %s\n", | |
387 | + "Could not get minmal period size for %s\n", | |
386 | 388 | typ |
387 | 389 | ); |
388 | 390 | } |
... | ... | @@ -419,7 +421,7 @@ static int alsa_open (int in, struct alsa_params_req *req, |
419 | 421 | &minval |
420 | 422 | ); |
421 | 423 | if (err < 0) { |
422 | - alsa_logerr (err, "Can not get minmal buffer size for %s\n", | |
424 | + alsa_logerr (err, "Could not get minmal buffer size for %s\n", | |
423 | 425 | typ); |
424 | 426 | } |
425 | 427 | else { |
... | ... | @@ -451,7 +453,7 @@ static int alsa_open (int in, struct alsa_params_req *req, |
451 | 453 | } |
452 | 454 | } |
453 | 455 | else { |
454 | - dolog ("warning: buffer size is not set\n"); | |
456 | + dolog ("warning: Buffer size is not set\n"); | |
455 | 457 | } |
456 | 458 | |
457 | 459 | err = snd_pcm_hw_params (handle, hw_params); |
... | ... | @@ -468,13 +470,13 @@ static int alsa_open (int in, struct alsa_params_req *req, |
468 | 470 | |
469 | 471 | err = snd_pcm_prepare (handle); |
470 | 472 | if (err < 0) { |
471 | - alsa_logerr2 (err, typ, "Can not prepare handle %p\n", handle); | |
473 | + alsa_logerr2 (err, typ, "Could not prepare handle %p\n", handle); | |
472 | 474 | goto err; |
473 | 475 | } |
474 | 476 | |
475 | 477 | obt->can_pause = snd_pcm_hw_params_can_pause (hw_params); |
476 | 478 | if (obt->can_pause < 0) { |
477 | - alsa_logerr (err, "Can not get pause capability for %s\n", typ); | |
479 | + alsa_logerr (err, "Could not get pause capability for %s\n", typ); | |
478 | 480 | obt->can_pause = 0; |
479 | 481 | } |
480 | 482 | |
... | ... | @@ -493,17 +495,17 @@ static int alsa_open (int in, struct alsa_params_req *req, |
493 | 495 | obt->fmt = req->fmt; |
494 | 496 | obt->nchannels = nchannels; |
495 | 497 | obt->freq = freq; |
496 | - obt->buffer_size = snd_pcm_frames_to_bytes (handle, obt_buffer_size); | |
498 | + obt->samples = obt_buffer_size; | |
497 | 499 | *handlep = handle; |
498 | 500 | |
501 | +#if defined DEBUG_MISMATCHES || defined DEBUG | |
499 | 502 | if (obt->fmt != req->fmt || |
500 | 503 | obt->nchannels != req->nchannels || |
501 | 504 | obt->freq != req->freq) { |
502 | -#ifdef DEBUG_MISMATCHES | |
503 | 505 | dolog ("Audio paramters mismatch for %s\n", typ); |
504 | 506 | alsa_dump_info (req, obt); |
505 | -#endif | |
506 | 507 | } |
508 | +#endif | |
507 | 509 | |
508 | 510 | #ifdef DEBUG |
509 | 511 | alsa_dump_info (req, obt); |
... | ... | @@ -550,7 +552,7 @@ static int alsa_run_out (HWVoiceOut *hw) |
550 | 552 | } |
551 | 553 | } |
552 | 554 | |
553 | - alsa_logerr (avail, "Can not get amount free space\n"); | |
555 | + alsa_logerr (avail, "Could not get amount free space\n"); | |
554 | 556 | return 0; |
555 | 557 | } |
556 | 558 | |
... | ... | @@ -618,7 +620,7 @@ static void alsa_fini_out (HWVoiceOut *hw) |
618 | 620 | } |
619 | 621 | } |
620 | 622 | |
621 | -static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | |
623 | +static int alsa_init_out (HWVoiceOut *hw, audsettings_t *as) | |
622 | 624 | { |
623 | 625 | ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; |
624 | 626 | struct alsa_params_req req; |
... | ... | @@ -627,10 +629,11 @@ static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
627 | 629 | int endianness; |
628 | 630 | int err; |
629 | 631 | snd_pcm_t *handle; |
632 | + audsettings_t obt_as; | |
630 | 633 | |
631 | - req.fmt = aud_to_alsafmt (fmt); | |
632 | - req.freq = freq; | |
633 | - req.nchannels = nchannels; | |
634 | + req.fmt = aud_to_alsafmt (as->fmt); | |
635 | + req.freq = as->freq; | |
636 | + req.nchannels = as->nchannels; | |
634 | 637 | req.period_size = conf.period_size_out; |
635 | 638 | req.buffer_size = conf.buffer_size_out; |
636 | 639 | |
... | ... | @@ -644,18 +647,22 @@ static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
644 | 647 | return -1; |
645 | 648 | } |
646 | 649 | |
650 | + obt_as.freq = obt.freq; | |
651 | + obt_as.nchannels = obt.nchannels; | |
652 | + obt_as.fmt = effective_fmt; | |
653 | + | |
647 | 654 | audio_pcm_init_info ( |
648 | 655 | &hw->info, |
649 | - obt.freq, | |
650 | - obt.nchannels, | |
651 | - effective_fmt, | |
656 | + &obt_as, | |
652 | 657 | audio_need_to_swap_endian (endianness) |
653 | 658 | ); |
654 | 659 | alsa->can_pause = obt.can_pause; |
655 | - hw->bufsize = obt.buffer_size; | |
660 | + hw->samples = obt.samples; | |
656 | 661 | |
657 | - alsa->pcm_buf = qemu_mallocz (hw->bufsize); | |
662 | + alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift); | |
658 | 663 | if (!alsa->pcm_buf) { |
664 | + dolog ("Could not allocate DAC buffer (%d bytes)\n", | |
665 | + hw->samples << hw->info.shift); | |
659 | 666 | alsa_anal_close (&handle); |
660 | 667 | return -1; |
661 | 668 | } |
... | ... | @@ -703,8 +710,7 @@ static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...) |
703 | 710 | return 0; |
704 | 711 | } |
705 | 712 | |
706 | -static int alsa_init_in (HWVoiceIn *hw, | |
707 | - int freq, int nchannels, audfmt_e fmt) | |
713 | +static int alsa_init_in (HWVoiceIn *hw, audsettings_t *as) | |
708 | 714 | { |
709 | 715 | ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; |
710 | 716 | struct alsa_params_req req; |
... | ... | @@ -713,10 +719,11 @@ static int alsa_init_in (HWVoiceIn *hw, |
713 | 719 | int err; |
714 | 720 | audfmt_e effective_fmt; |
715 | 721 | snd_pcm_t *handle; |
722 | + audsettings_t obt_as; | |
716 | 723 | |
717 | - req.fmt = aud_to_alsafmt (fmt); | |
718 | - req.freq = freq; | |
719 | - req.nchannels = nchannels; | |
724 | + req.fmt = aud_to_alsafmt (as->fmt); | |
725 | + req.freq = as->freq; | |
726 | + req.nchannels = as->nchannels; | |
720 | 727 | req.period_size = conf.period_size_in; |
721 | 728 | req.buffer_size = conf.buffer_size_in; |
722 | 729 | |
... | ... | @@ -730,17 +737,22 @@ static int alsa_init_in (HWVoiceIn *hw, |
730 | 737 | return -1; |
731 | 738 | } |
732 | 739 | |
740 | + obt_as.freq = obt.freq; | |
741 | + obt_as.nchannels = obt.nchannels; | |
742 | + obt_as.fmt = effective_fmt; | |
743 | + | |
733 | 744 | audio_pcm_init_info ( |
734 | 745 | &hw->info, |
735 | - obt.freq, | |
736 | - obt.nchannels, | |
737 | - effective_fmt, | |
746 | + &obt_as, | |
738 | 747 | audio_need_to_swap_endian (endianness) |
739 | 748 | ); |
740 | 749 | alsa->can_pause = obt.can_pause; |
741 | - hw->bufsize = obt.buffer_size; | |
742 | - alsa->pcm_buf = qemu_mallocz (hw->bufsize); | |
750 | + hw->samples = obt.samples; | |
751 | + | |
752 | + alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); | |
743 | 753 | if (!alsa->pcm_buf) { |
754 | + dolog ("Could not allocate ADC buffer (%d bytes)\n", | |
755 | + hw->samples << hw->info.shift); | |
744 | 756 | alsa_anal_close (&handle); |
745 | 757 | return -1; |
746 | 758 | } | ... | ... |
audio/audio.c
... | ... | @@ -26,16 +26,12 @@ |
26 | 26 | #define AUDIO_CAP "audio" |
27 | 27 | #include "audio_int.h" |
28 | 28 | |
29 | -static void audio_pcm_hw_fini_in (HWVoiceIn *hw); | |
30 | -static void audio_pcm_hw_fini_out (HWVoiceOut *hw); | |
31 | - | |
32 | -static LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; | |
33 | -static LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; | |
34 | - | |
35 | 29 | /* #define DEBUG_PLIVE */ |
36 | 30 | /* #define DEBUG_LIVE */ |
37 | 31 | /* #define DEBUG_OUT */ |
38 | 32 | |
33 | +#define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown" | |
34 | + | |
39 | 35 | static struct audio_driver *drvtab[] = { |
40 | 36 | #ifdef CONFIG_OSS |
41 | 37 | &oss_audio_driver, |
... | ... | @@ -59,31 +55,50 @@ static struct audio_driver *drvtab[] = { |
59 | 55 | &wav_audio_driver |
60 | 56 | }; |
61 | 57 | |
62 | -AudioState audio_state = { | |
63 | - /* Out */ | |
64 | - 1, /* use fixed settings */ | |
65 | - 44100, /* fixed frequency */ | |
66 | - 2, /* fixed channels */ | |
67 | - AUD_FMT_S16, /* fixed format */ | |
68 | - 1, /* number of hw voices */ | |
69 | - 1, /* greedy */ | |
70 | - | |
71 | - /* In */ | |
72 | - 1, /* use fixed settings */ | |
73 | - 44100, /* fixed frequency */ | |
74 | - 2, /* fixed channels */ | |
75 | - AUD_FMT_S16, /* fixed format */ | |
76 | - 1, /* number of hw voices */ | |
77 | - 1, /* greedy */ | |
78 | - | |
79 | - NULL, /* driver opaque */ | |
80 | - NULL, /* driver */ | |
81 | - | |
82 | - NULL, /* timer handle */ | |
58 | +struct fixed_settings { | |
59 | + int enabled; | |
60 | + int nb_voices; | |
61 | + int greedy; | |
62 | + audsettings_t settings; | |
63 | +}; | |
64 | + | |
65 | +static struct { | |
66 | + struct fixed_settings fixed_out; | |
67 | + struct fixed_settings fixed_in; | |
68 | + union { | |
69 | + int hz; | |
70 | + int64_t ticks; | |
71 | + } period; | |
72 | + int plive; | |
73 | +} conf = { | |
74 | + { /* DAC fixed settings */ | |
75 | + 1, /* enabled */ | |
76 | + 1, /* nb_voices */ | |
77 | + 1, /* greedy */ | |
78 | + { | |
79 | + 44100, /* freq */ | |
80 | + 2, /* nchannels */ | |
81 | + AUD_FMT_S16 /* fmt */ | |
82 | + } | |
83 | + }, | |
84 | + | |
85 | + { /* ADC fixed settings */ | |
86 | + 1, /* enabled */ | |
87 | + 1, /* nb_voices */ | |
88 | + 1, /* greedy */ | |
89 | + { | |
90 | + 44100, /* freq */ | |
91 | + 2, /* nchannels */ | |
92 | + AUD_FMT_S16 /* fmt */ | |
93 | + } | |
94 | + }, | |
95 | + | |
83 | 96 | { 0 }, /* period */ |
84 | 97 | 0 /* plive */ |
85 | 98 | }; |
86 | 99 | |
100 | +static AudioState glob_audio_state; | |
101 | + | |
87 | 102 | volume_t nominal_volume = { |
88 | 103 | 0, |
89 | 104 | #ifdef FLOAT_MIXENG |
... | ... | @@ -148,6 +163,26 @@ int audio_bug (const char *funcname, int cond) |
148 | 163 | } |
149 | 164 | #endif |
150 | 165 | |
166 | +void *audio_calloc (const char *funcname, int nmemb, size_t size) | |
167 | +{ | |
168 | + int cond; | |
169 | + size_t len; | |
170 | + | |
171 | + len = nmemb * size; | |
172 | + cond = !nmemb || !size; | |
173 | + cond |= nmemb < 0; | |
174 | + cond |= len < size; | |
175 | + | |
176 | + if (audio_bug ("audio_calloc", cond)) { | |
177 | + AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n", | |
178 | + funcname); | |
179 | + AUD_log (NULL, "nmemb=%d size=%d (len=%d)\n", nmemb, size, len); | |
180 | + return NULL; | |
181 | + } | |
182 | + | |
183 | + return qemu_mallocz (len); | |
184 | +} | |
185 | + | |
151 | 186 | static char *audio_alloc_prefix (const char *s) |
152 | 187 | { |
153 | 188 | const char qemu_prefix[] = "QEMU_"; |
... | ... | @@ -386,14 +421,19 @@ static void audio_process_options (const char *prefix, |
386 | 421 | } |
387 | 422 | |
388 | 423 | len = strlen (opt->name); |
424 | + /* len of opt->name + len of prefix + size of qemu_prefix | |
425 | + * (includes trailing zero) + zero + underscore (on behalf of | |
426 | + * sizeof) */ | |
389 | 427 | optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1); |
390 | 428 | if (!optname) { |
391 | - dolog ("Can not allocate memory for option name `%s'\n", | |
429 | + dolog ("Could not allocate memory for option name `%s'\n", | |
392 | 430 | opt->name); |
393 | 431 | continue; |
394 | 432 | } |
395 | 433 | |
396 | 434 | strcpy (optname, qemu_prefix); |
435 | + | |
436 | + /* copy while upper-casing, including trailing zero */ | |
397 | 437 | for (i = 0; i <= preflen; ++i) { |
398 | 438 | optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); |
399 | 439 | } |
... | ... | @@ -438,12 +478,60 @@ static void audio_process_options (const char *prefix, |
438 | 478 | } |
439 | 479 | } |
440 | 480 | |
441 | -static int audio_pcm_info_eq (struct audio_pcm_info *info, int freq, | |
442 | - int nchannels, audfmt_e fmt) | |
481 | +static void audio_print_settings (audsettings_t *as) | |
482 | +{ | |
483 | + dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels); | |
484 | + | |
485 | + switch (as->fmt) { | |
486 | + case AUD_FMT_S8: | |
487 | + AUD_log (NULL, "S8"); | |
488 | + break; | |
489 | + case AUD_FMT_U8: | |
490 | + AUD_log (NULL, "U8"); | |
491 | + break; | |
492 | + case AUD_FMT_S16: | |
493 | + AUD_log (NULL, "S16"); | |
494 | + break; | |
495 | + case AUD_FMT_U16: | |
496 | + AUD_log (NULL, "U16"); | |
497 | + break; | |
498 | + default: | |
499 | + AUD_log (NULL, "invalid(%d)", as->fmt); | |
500 | + break; | |
501 | + } | |
502 | + AUD_log (NULL, "\n"); | |
503 | +} | |
504 | + | |
505 | +static int audio_validate_settigs (audsettings_t *as) | |
506 | +{ | |
507 | + int invalid; | |
508 | + | |
509 | + invalid = as->nchannels != 1 && as->nchannels != 2; | |
510 | + | |
511 | + switch (as->fmt) { | |
512 | + case AUD_FMT_S8: | |
513 | + case AUD_FMT_U8: | |
514 | + case AUD_FMT_S16: | |
515 | + case AUD_FMT_U16: | |
516 | + break; | |
517 | + default: | |
518 | + invalid = 1; | |
519 | + break; | |
520 | + } | |
521 | + | |
522 | + invalid |= as->freq <= 0; | |
523 | + | |
524 | + if (invalid) { | |
525 | + return -1; | |
526 | + } | |
527 | + return 0; | |
528 | +} | |
529 | + | |
530 | +static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as) | |
443 | 531 | { |
444 | 532 | int bits = 8, sign = 0; |
445 | 533 | |
446 | - switch (fmt) { | |
534 | + switch (as->fmt) { | |
447 | 535 | case AUD_FMT_S8: |
448 | 536 | sign = 1; |
449 | 537 | case AUD_FMT_U8: |
... | ... | @@ -455,18 +543,21 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, int freq, |
455 | 543 | bits = 16; |
456 | 544 | break; |
457 | 545 | } |
458 | - return info->freq == freq | |
459 | - && info->nchannels == nchannels | |
546 | + return info->freq == as->freq | |
547 | + && info->nchannels == as->nchannels | |
460 | 548 | && info->sign == sign |
461 | 549 | && info->bits == bits; |
462 | 550 | } |
463 | 551 | |
464 | -void audio_pcm_init_info (struct audio_pcm_info *info, int freq, | |
465 | - int nchannels, audfmt_e fmt, int swap_endian) | |
552 | +void audio_pcm_init_info ( | |
553 | + struct audio_pcm_info *info, | |
554 | + audsettings_t *as, | |
555 | + int swap_endian | |
556 | + ) | |
466 | 557 | { |
467 | 558 | int bits = 8, sign = 0; |
468 | 559 | |
469 | - switch (fmt) { | |
560 | + switch (as->fmt) { | |
470 | 561 | case AUD_FMT_S8: |
471 | 562 | sign = 1; |
472 | 563 | case AUD_FMT_U8: |
... | ... | @@ -479,11 +570,11 @@ void audio_pcm_init_info (struct audio_pcm_info *info, int freq, |
479 | 570 | break; |
480 | 571 | } |
481 | 572 | |
482 | - info->freq = freq; | |
573 | + info->freq = as->freq; | |
483 | 574 | info->bits = bits; |
484 | 575 | info->sign = sign; |
485 | - info->nchannels = nchannels; | |
486 | - info->shift = (nchannels == 2) + (bits == 16); | |
576 | + info->nchannels = as->nchannels; | |
577 | + info->shift = (as->nchannels == 2) + (bits == 16); | |
487 | 578 | info->align = (1 << info->shift) - 1; |
488 | 579 | info->bytes_per_second = info->freq << info->shift; |
489 | 580 | info->swap_endian = swap_endian; |
... | ... | @@ -532,38 +623,16 @@ static void audio_pcm_hw_free_resources_in (HWVoiceIn *hw) |
532 | 623 | |
533 | 624 | static int audio_pcm_hw_alloc_resources_in (HWVoiceIn *hw) |
534 | 625 | { |
535 | - hw->conv_buf = qemu_mallocz (hw->samples * sizeof (st_sample_t)); | |
626 | + hw->conv_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t)); | |
536 | 627 | if (!hw->conv_buf) { |
628 | + dolog ("Could not allocate ADC conversion buffer (%d bytes)\n", | |
629 | + hw->samples * sizeof (st_sample_t)); | |
537 | 630 | return -1; |
538 | 631 | } |
539 | 632 | return 0; |
540 | 633 | } |
541 | 634 | |
542 | -static int audio_pcm_hw_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | |
543 | -{ | |
544 | - audio_pcm_hw_fini_in (hw); | |
545 | - | |
546 | - if (hw->pcm_ops->init_in (hw, freq, nchannels, fmt)) { | |
547 | - memset (hw, 0, audio_state.drv->voice_size_in); | |
548 | - return -1; | |
549 | - } | |
550 | - LIST_INIT (&hw->sw_head); | |
551 | - hw->active = 1; | |
552 | - hw->samples = hw->bufsize >> hw->info.shift; | |
553 | - hw->conv = | |
554 | - mixeng_conv | |
555 | - [nchannels == 2] | |
556 | - [hw->info.sign] | |
557 | - [hw->info.swap_endian] | |
558 | - [hw->info.bits == 16]; | |
559 | - if (audio_pcm_hw_alloc_resources_in (hw)) { | |
560 | - audio_pcm_hw_free_resources_in (hw); | |
561 | - return -1; | |
562 | - } | |
563 | - return 0; | |
564 | -} | |
565 | - | |
566 | -static uint64_t audio_pcm_hw_find_min_in (HWVoiceIn *hw) | |
635 | +static int audio_pcm_hw_find_min_in (HWVoiceIn *hw) | |
567 | 636 | { |
568 | 637 | SWVoiceIn *sw; |
569 | 638 | int m = hw->total_samples_captured; |
... | ... | @@ -606,8 +675,10 @@ static void audio_pcm_sw_free_resources_in (SWVoiceIn *sw) |
606 | 675 | static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) |
607 | 676 | { |
608 | 677 | int samples = ((int64_t) sw->hw->samples << 32) / sw->ratio; |
609 | - sw->conv_buf = qemu_mallocz (samples * sizeof (st_sample_t)); | |
678 | + sw->conv_buf = audio_calloc (AUDIO_FUNC, samples, sizeof (st_sample_t)); | |
610 | 679 | if (!sw->conv_buf) { |
680 | + dolog ("Could not allocate buffer for `%s' (%d bytes)\n", | |
681 | + SW_NAME (sw), samples * sizeof (st_sample_t)); | |
611 | 682 | return -1; |
612 | 683 | } |
613 | 684 | |
... | ... | @@ -620,19 +691,22 @@ static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) |
620 | 691 | return 0; |
621 | 692 | } |
622 | 693 | |
623 | -static int audio_pcm_sw_init_in (SWVoiceIn *sw, HWVoiceIn *hw, const char *name, | |
624 | - int freq, int nchannels, audfmt_e fmt) | |
694 | +static int audio_pcm_sw_init_in ( | |
695 | + SWVoiceIn *sw, | |
696 | + HWVoiceIn *hw, | |
697 | + const char *name, | |
698 | + audsettings_t *as | |
699 | + ) | |
625 | 700 | { |
626 | - audio_pcm_init_info (&sw->info, freq, nchannels, fmt, | |
627 | - /* None of the cards emulated by QEMU are big-endian | |
628 | - hence following shortcut */ | |
629 | - audio_need_to_swap_endian (0)); | |
701 | + /* None of the cards emulated by QEMU are big-endian | |
702 | + hence following shortcut */ | |
703 | + audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (0)); | |
630 | 704 | sw->hw = hw; |
631 | 705 | sw->ratio = ((int64_t) sw->info.freq << 32) / sw->hw->info.freq; |
632 | 706 | |
633 | 707 | sw->clip = |
634 | 708 | mixeng_clip |
635 | - [nchannels == 2] | |
709 | + [sw->info.nchannels == 2] | |
636 | 710 | [sw->info.sign] |
637 | 711 | [sw->info.swap_endian] |
638 | 712 | [sw->info.bits == 16]; |
... | ... | @@ -699,6 +773,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) |
699 | 773 | |
700 | 774 | if (audio_bug (AUDIO_FUNC, osamp < 0)) { |
701 | 775 | dolog ("osamp=%d\n", osamp); |
776 | + return 0; | |
702 | 777 | } |
703 | 778 | |
704 | 779 | st_rate_flow (sw->rate, src, dst, &isamp, &osamp); |
... | ... | @@ -717,23 +792,6 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) |
717 | 792 | /* |
718 | 793 | * Hard voice (playback) |
719 | 794 | */ |
720 | -static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep) | |
721 | -{ | |
722 | - SWVoiceOut *sw; | |
723 | - int m = INT_MAX; | |
724 | - int nb_live = 0; | |
725 | - | |
726 | - for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { | |
727 | - if (sw->active || !sw->empty) { | |
728 | - m = audio_MIN (m, sw->total_hw_samples_mixed); | |
729 | - nb_live += 1; | |
730 | - } | |
731 | - } | |
732 | - | |
733 | - *nb_livep = nb_live; | |
734 | - return m; | |
735 | -} | |
736 | - | |
737 | 795 | static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) |
738 | 796 | { |
739 | 797 | if (hw->mix_buf) { |
... | ... | @@ -745,37 +803,31 @@ static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) |
745 | 803 | |
746 | 804 | static int audio_pcm_hw_alloc_resources_out (HWVoiceOut *hw) |
747 | 805 | { |
748 | - hw->mix_buf = qemu_mallocz (hw->samples * sizeof (st_sample_t)); | |
806 | + hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t)); | |
749 | 807 | if (!hw->mix_buf) { |
808 | + dolog ("Could not allocate DAC mixing buffer (%d bytes)\n", | |
809 | + hw->samples * sizeof (st_sample_t)); | |
750 | 810 | return -1; |
751 | 811 | } |
752 | 812 | |
753 | 813 | return 0; |
754 | 814 | } |
755 | 815 | |
756 | -static int audio_pcm_hw_init_out (HWVoiceOut *hw, int freq, | |
757 | - int nchannels, audfmt_e fmt) | |
816 | +static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep) | |
758 | 817 | { |
759 | - audio_pcm_hw_fini_out (hw); | |
760 | - if (hw->pcm_ops->init_out (hw, freq, nchannels, fmt)) { | |
761 | - memset (hw, 0, audio_state.drv->voice_size_out); | |
762 | - return -1; | |
763 | - } | |
818 | + SWVoiceOut *sw; | |
819 | + int m = INT_MAX; | |
820 | + int nb_live = 0; | |
764 | 821 | |
765 | - LIST_INIT (&hw->sw_head); | |
766 | - hw->active = 1; | |
767 | - hw->samples = hw->bufsize >> hw->info.shift; | |
768 | - hw->clip = | |
769 | - mixeng_clip | |
770 | - [nchannels == 2] | |
771 | - [hw->info.sign] | |
772 | - [hw->info.swap_endian] | |
773 | - [hw->info.bits == 16]; | |
774 | - if (audio_pcm_hw_alloc_resources_out (hw)) { | |
775 | - audio_pcm_hw_fini_out (hw); | |
776 | - return -1; | |
822 | + for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { | |
823 | + if (sw->active || !sw->empty) { | |
824 | + m = audio_MIN (m, sw->total_hw_samples_mixed); | |
825 | + nb_live += 1; | |
826 | + } | |
777 | 827 | } |
778 | - return 0; | |
828 | + | |
829 | + *nb_livep = nb_live; | |
830 | + return m; | |
779 | 831 | } |
780 | 832 | |
781 | 833 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live) |
... | ... | @@ -830,8 +882,10 @@ static void audio_pcm_sw_free_resources_out (SWVoiceOut *sw) |
830 | 882 | |
831 | 883 | static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw) |
832 | 884 | { |
833 | - sw->buf = qemu_mallocz (sw->hw->samples * sizeof (st_sample_t)); | |
885 | + sw->buf = audio_calloc (AUDIO_FUNC, sw->hw->samples, sizeof (st_sample_t)); | |
834 | 886 | if (!sw->buf) { |
887 | + dolog ("Could not allocate buffer for `%s' (%d bytes)\n", | |
888 | + SW_NAME (sw), sw->hw->samples * sizeof (st_sample_t)); | |
835 | 889 | return -1; |
836 | 890 | } |
837 | 891 | |
... | ... | @@ -844,14 +898,16 @@ static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw) |
844 | 898 | return 0; |
845 | 899 | } |
846 | 900 | |
847 | -static int audio_pcm_sw_init_out (SWVoiceOut *sw, HWVoiceOut *hw, | |
848 | - const char *name, int freq, | |
849 | - int nchannels, audfmt_e fmt) | |
901 | +static int audio_pcm_sw_init_out ( | |
902 | + SWVoiceOut *sw, | |
903 | + HWVoiceOut *hw, | |
904 | + const char *name, | |
905 | + audsettings_t *as | |
906 | + ) | |
850 | 907 | { |
851 | - audio_pcm_init_info (&sw->info, freq, nchannels, fmt, | |
852 | - /* None of the cards emulated by QEMU are big-endian | |
853 | - hence following shortcut */ | |
854 | - audio_need_to_swap_endian (0)); | |
908 | + /* None of the cards emulated by QEMU are big-endian | |
909 | + hence following shortcut */ | |
910 | + audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (0)); | |
855 | 911 | sw->hw = hw; |
856 | 912 | sw->empty = 1; |
857 | 913 | sw->active = 0; |
... | ... | @@ -860,7 +916,7 @@ static int audio_pcm_sw_init_out (SWVoiceOut *sw, HWVoiceOut *hw, |
860 | 916 | |
861 | 917 | sw->conv = |
862 | 918 | mixeng_conv |
863 | - [nchannels == 2] | |
919 | + [sw->info.nchannels == 2] | |
864 | 920 | [sw->info.sign] |
865 | 921 | [sw->info.swap_endian] |
866 | 922 | [sw->info.bits == 16]; |
... | ... | @@ -930,12 +986,11 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) |
930 | 986 | |
931 | 987 | #ifdef DEBUG_OUT |
932 | 988 | dolog ( |
933 | - "%s: write size %d ret %d total sw %d, hw %d\n", | |
934 | - sw->name, | |
989 | + "%s: write size %d ret %d total sw %d\n", | |
990 | + SW_NAME (sw), | |
935 | 991 | size >> sw->info.shift, |
936 | 992 | ret, |
937 | - sw->total_hw_samples_mixed, | |
938 | - sw->hw->total_samples_played | |
993 | + sw->total_hw_samples_mixed | |
939 | 994 | ); |
940 | 995 | #endif |
941 | 996 | |
... | ... | @@ -965,7 +1020,7 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size) |
965 | 1020 | } |
966 | 1021 | |
967 | 1022 | if (!sw->hw->enabled) { |
968 | - dolog ("Writing to disabled voice %s\n", sw->name); | |
1023 | + dolog ("Writing to disabled voice %s\n", SW_NAME (sw)); | |
969 | 1024 | return 0; |
970 | 1025 | } |
971 | 1026 | |
... | ... | @@ -983,7 +1038,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) |
983 | 1038 | } |
984 | 1039 | |
985 | 1040 | if (!sw->hw->enabled) { |
986 | - dolog ("Reading from disabled voice %s\n", sw->name); | |
1041 | + dolog ("Reading from disabled voice %s\n", SW_NAME (sw)); | |
987 | 1042 | return 0; |
988 | 1043 | } |
989 | 1044 | |
... | ... | @@ -993,7 +1048,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) |
993 | 1048 | |
994 | 1049 | int AUD_get_buffer_size_out (SWVoiceOut *sw) |
995 | 1050 | { |
996 | - return sw->hw->bufsize; | |
1051 | + return sw->hw->samples << sw->hw->info.shift; | |
997 | 1052 | } |
998 | 1053 | |
999 | 1054 | void AUD_set_active_out (SWVoiceOut *sw, int on) |
... | ... | @@ -1091,7 +1146,7 @@ static int audio_get_avail (SWVoiceIn *sw) |
1091 | 1146 | |
1092 | 1147 | ldebug ( |
1093 | 1148 | "%s: get_avail live %d ret %lld\n", |
1094 | - sw->name, | |
1149 | + SW_NAME (sw), | |
1095 | 1150 | live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift |
1096 | 1151 | ); |
1097 | 1152 | |
... | ... | @@ -1110,34 +1165,37 @@ static int audio_get_free (SWVoiceOut *sw) |
1110 | 1165 | |
1111 | 1166 | if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) { |
1112 | 1167 | dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples); |
1168 | + return 0; | |
1113 | 1169 | } |
1114 | 1170 | |
1115 | 1171 | dead = sw->hw->samples - live; |
1116 | 1172 | |
1117 | 1173 | #ifdef DEBUG_OUT |
1118 | 1174 | dolog ("%s: get_free live %d dead %d ret %lld\n", |
1119 | - sw->name, | |
1175 | + SW_NAME (sw), | |
1120 | 1176 | live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift); |
1121 | 1177 | #endif |
1122 | 1178 | |
1123 | 1179 | return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift; |
1124 | 1180 | } |
1125 | 1181 | |
1126 | -static void audio_run_out (void) | |
1182 | +static void audio_run_out (AudioState *s) | |
1127 | 1183 | { |
1128 | 1184 | HWVoiceOut *hw = NULL; |
1129 | 1185 | SWVoiceOut *sw; |
1130 | 1186 | |
1131 | - while ((hw = audio_pcm_hw_find_any_active_enabled_out (hw))) { | |
1187 | + while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) { | |
1132 | 1188 | int played; |
1133 | - int live, free, nb_live; | |
1189 | + int live, free, nb_live, cleanup_required; | |
1134 | 1190 | |
1135 | 1191 | live = audio_pcm_hw_get_live_out2 (hw, &nb_live); |
1136 | 1192 | if (!nb_live) { |
1137 | 1193 | live = 0; |
1138 | 1194 | } |
1195 | + | |
1139 | 1196 | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
1140 | 1197 | dolog ("live=%d hw->samples=%d\n", live, hw->samples); |
1198 | + continue; | |
1141 | 1199 | } |
1142 | 1200 | |
1143 | 1201 | if (hw->pending_disable && !nb_live) { |
... | ... | @@ -1170,15 +1228,15 @@ static void audio_run_out (void) |
1170 | 1228 | } |
1171 | 1229 | |
1172 | 1230 | #ifdef DEBUG_OUT |
1173 | - dolog ("played = %d total %d\n", played, hw->total_samples_played); | |
1231 | + dolog ("played=%d\n", played); | |
1174 | 1232 | #endif |
1175 | 1233 | |
1176 | 1234 | if (played) { |
1177 | 1235 | hw->ts_helper += played; |
1178 | 1236 | } |
1179 | 1237 | |
1238 | + cleanup_required = 0; | |
1180 | 1239 | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { |
1181 | - again: | |
1182 | 1240 | if (!sw->active && sw->empty) { |
1183 | 1241 | continue; |
1184 | 1242 | } |
... | ... | @@ -1193,22 +1251,7 @@ static void audio_run_out (void) |
1193 | 1251 | |
1194 | 1252 | if (!sw->total_hw_samples_mixed) { |
1195 | 1253 | sw->empty = 1; |
1196 | - | |
1197 | - if (!sw->active && !sw->callback.fn) { | |
1198 | - SWVoiceOut *temp = sw->entries.le_next; | |
1199 | - | |
1200 | -#ifdef DEBUG_PLIVE | |
1201 | - dolog ("Finishing with old voice\n"); | |
1202 | -#endif | |
1203 | - AUD_close_out (sw); | |
1204 | - sw = temp; | |
1205 | - if (sw) { | |
1206 | - goto again; | |
1207 | - } | |
1208 | - else { | |
1209 | - break; | |
1210 | - } | |
1211 | - } | |
1254 | + cleanup_required |= !sw->active && !sw->callback.fn; | |
1212 | 1255 | } |
1213 | 1256 | |
1214 | 1257 | if (sw->active) { |
... | ... | @@ -1218,14 +1261,27 @@ static void audio_run_out (void) |
1218 | 1261 | } |
1219 | 1262 | } |
1220 | 1263 | } |
1264 | + | |
1265 | + if (cleanup_required) { | |
1266 | + restart: | |
1267 | + for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { | |
1268 | + if (!sw->active && !sw->callback.fn) { | |
1269 | +#ifdef DEBUG_PLIVE | |
1270 | + dolog ("Finishing with old voice\n"); | |
1271 | +#endif | |
1272 | + audio_close_out (s, sw); | |
1273 | + goto restart; /* play it safe */ | |
1274 | + } | |
1275 | + } | |
1276 | + } | |
1221 | 1277 | } |
1222 | 1278 | } |
1223 | 1279 | |
1224 | -static void audio_run_in (void) | |
1280 | +static void audio_run_in (AudioState *s) | |
1225 | 1281 | { |
1226 | 1282 | HWVoiceIn *hw = NULL; |
1227 | 1283 | |
1228 | - while ((hw = audio_pcm_hw_find_any_active_enabled_in (hw))) { | |
1284 | + while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) { | |
1229 | 1285 | SWVoiceIn *sw; |
1230 | 1286 | int captured, min; |
1231 | 1287 | |
... | ... | @@ -1252,42 +1308,42 @@ static void audio_run_in (void) |
1252 | 1308 | |
1253 | 1309 | static struct audio_option audio_options[] = { |
1254 | 1310 | /* DAC */ |
1255 | - {"DAC_FIXED_SETTINGS", AUD_OPT_BOOL, &audio_state.fixed_settings_out, | |
1311 | + {"DAC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_out.enabled, | |
1256 | 1312 | "Use fixed settings for host DAC", NULL, 0}, |
1257 | 1313 | |
1258 | - {"DAC_FIXED_FREQ", AUD_OPT_INT, &audio_state.fixed_freq_out, | |
1314 | + {"DAC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_out.settings.freq, | |
1259 | 1315 | "Frequency for fixed host DAC", NULL, 0}, |
1260 | 1316 | |
1261 | - {"DAC_FIXED_FMT", AUD_OPT_FMT, &audio_state.fixed_fmt_out, | |
1317 | + {"DAC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_out.settings.fmt, | |
1262 | 1318 | "Format for fixed host DAC", NULL, 0}, |
1263 | 1319 | |
1264 | - {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &audio_state.fixed_channels_out, | |
1320 | + {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_out.settings.nchannels, | |
1265 | 1321 | "Number of channels for fixed DAC (1 - mono, 2 - stereo)", NULL, 0}, |
1266 | 1322 | |
1267 | - {"DAC_VOICES", AUD_OPT_INT, &audio_state.nb_hw_voices_out, | |
1323 | + {"DAC_VOICES", AUD_OPT_INT, &conf.fixed_out.nb_voices, | |
1268 | 1324 | "Number of voices for DAC", NULL, 0}, |
1269 | 1325 | |
1270 | 1326 | /* ADC */ |
1271 | - {"ADC_FIXED_SETTINGS", AUD_OPT_BOOL, &audio_state.fixed_settings_out, | |
1327 | + {"ADC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_in.enabled, | |
1272 | 1328 | "Use fixed settings for host ADC", NULL, 0}, |
1273 | 1329 | |
1274 | - {"ADC_FIXED_FREQ", AUD_OPT_INT, &audio_state.fixed_freq_out, | |
1275 | - "Frequency for fixed ADC", NULL, 0}, | |
1330 | + {"ADC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_in.settings.freq, | |
1331 | + "Frequency for fixed host ADC", NULL, 0}, | |
1276 | 1332 | |
1277 | - {"ADC_FIXED_FMT", AUD_OPT_FMT, &audio_state.fixed_fmt_out, | |
1278 | - "Format for fixed ADC", NULL, 0}, | |
1333 | + {"ADC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_in.settings.fmt, | |
1334 | + "Format for fixed host ADC", NULL, 0}, | |
1279 | 1335 | |
1280 | - {"ADC_FIXED_CHANNELS", AUD_OPT_INT, &audio_state.fixed_channels_in, | |
1336 | + {"ADC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_in.settings.nchannels, | |
1281 | 1337 | "Number of channels for fixed ADC (1 - mono, 2 - stereo)", NULL, 0}, |
1282 | 1338 | |
1283 | - {"ADC_VOICES", AUD_OPT_INT, &audio_state.nb_hw_voices_out, | |
1339 | + {"ADC_VOICES", AUD_OPT_INT, &conf.fixed_in.nb_voices, | |
1284 | 1340 | "Number of voices for ADC", NULL, 0}, |
1285 | 1341 | |
1286 | 1342 | /* Misc */ |
1287 | - {"TIMER_PERIOD", AUD_OPT_INT, &audio_state.period.usec, | |
1288 | - "Timer period in microseconds (0 - try lowest possible)", NULL, 0}, | |
1343 | + {"TIMER_PERIOD", AUD_OPT_INT, &conf.period.hz, | |
1344 | + "Timer period in HZ (0 - use lowest possible)", NULL, 0}, | |
1289 | 1345 | |
1290 | - {"PLIVE", AUD_OPT_BOOL, &audio_state.plive, | |
1346 | + {"PLIVE", AUD_OPT_BOOL, &conf.plive, | |
1291 | 1347 | "(undocumented)", NULL, 0}, |
1292 | 1348 | |
1293 | 1349 | {NULL, 0, NULL, NULL, NULL, 0} |
... | ... | @@ -1378,25 +1434,21 @@ void audio_timer (void *opaque) |
1378 | 1434 | { |
1379 | 1435 | AudioState *s = opaque; |
1380 | 1436 | |
1381 | - audio_run_out (); | |
1382 | - audio_run_in (); | |
1437 | + audio_run_out (s); | |
1438 | + audio_run_in (s); | |
1383 | 1439 | |
1384 | - qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + s->period.ticks); | |
1440 | + qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks); | |
1385 | 1441 | } |
1386 | 1442 | |
1387 | -static int audio_driver_init (struct audio_driver *drv) | |
1443 | +static int audio_driver_init (AudioState *s, struct audio_driver *drv) | |
1388 | 1444 | { |
1389 | 1445 | if (drv->options) { |
1390 | 1446 | audio_process_options (drv->name, drv->options); |
1391 | 1447 | } |
1392 | - audio_state.opaque = drv->init (); | |
1448 | + s->drv_opaque = drv->init (); | |
1393 | 1449 | |
1394 | - if (audio_state.opaque) { | |
1395 | - int i; | |
1396 | - HWVoiceOut *hwo; | |
1397 | - HWVoiceIn *hwi; | |
1398 | - | |
1399 | - if (audio_state.nb_hw_voices_out > drv->max_voices_out) { | |
1450 | + if (s->drv_opaque) { | |
1451 | + if (s->nb_hw_voices_out > drv->max_voices_out) { | |
1400 | 1452 | if (!drv->max_voices_out) { |
1401 | 1453 | dolog ("`%s' does not support DAC\n", drv->name); |
1402 | 1454 | } |
... | ... | @@ -1405,30 +1457,13 @@ static int audio_driver_init (struct audio_driver *drv) |
1405 | 1457 | "`%s' does not support %d multiple DAC voicess\n" |
1406 | 1458 | "Resetting to %d\n", |
1407 | 1459 | drv->name, |
1408 | - audio_state.nb_hw_voices_out, | |
1460 | + s->nb_hw_voices_out, | |
1409 | 1461 | drv->max_voices_out |
1410 | 1462 | ); |
1411 | 1463 | } |
1412 | - audio_state.nb_hw_voices_out = drv->max_voices_out; | |
1413 | - } | |
1414 | - | |
1415 | - LIST_INIT (&hw_head_out); | |
1416 | - hwo = qemu_mallocz (audio_state.nb_hw_voices_out * drv->voice_size_out); | |
1417 | - if (!hwo) { | |
1418 | - dolog ( | |
1419 | - "Not enough memory for %d `%s' DAC voices (each %d bytes)\n", | |
1420 | - audio_state.nb_hw_voices_out, | |
1421 | - drv->name, | |
1422 | - drv->voice_size_out | |
1423 | - ); | |
1424 | - drv->fini (audio_state.opaque); | |
1425 | - return -1; | |
1464 | + s->nb_hw_voices_out = drv->max_voices_out; | |
1426 | 1465 | } |
1427 | 1466 | |
1428 | - for (i = 0; i < audio_state.nb_hw_voices_out; ++i) { | |
1429 | - LIST_INSERT_HEAD (&hw_head_out, hwo, entries); | |
1430 | - hwo = advance (hwo, drv->voice_size_out); | |
1431 | - } | |
1432 | 1467 | |
1433 | 1468 | if (!drv->voice_size_in && drv->max_voices_in) { |
1434 | 1469 | ldebug ("warning: No ADC voice size defined for `%s'\n", |
... | ... | @@ -1442,16 +1477,16 @@ static int audio_driver_init (struct audio_driver *drv) |
1442 | 1477 | } |
1443 | 1478 | |
1444 | 1479 | if (drv->voice_size_in && !drv->max_voices_in) { |
1445 | - ldebug ("warning: ADC voice size is %d for ADC less driver `%s'\n", | |
1446 | - drv->voice_size_out, drv->name); | |
1480 | + ldebug ("warning: `%s' ADC voice size %d, zero voices \n", | |
1481 | + drv->name, drv->voice_size_out); | |
1447 | 1482 | } |
1448 | 1483 | |
1449 | 1484 | if (drv->voice_size_out && !drv->max_voices_out) { |
1450 | - ldebug ("warning: DAC voice size is %d for DAC less driver `%s'\n", | |
1451 | - drv->voice_size_in, drv->name); | |
1485 | + ldebug ("warning: `%s' DAC voice size %d, zero voices \n", | |
1486 | + drv->name, drv->voice_size_in); | |
1452 | 1487 | } |
1453 | 1488 | |
1454 | - if (audio_state.nb_hw_voices_in > drv->max_voices_in) { | |
1489 | + if (s->nb_hw_voices_in > drv->max_voices_in) { | |
1455 | 1490 | if (!drv->max_voices_in) { |
1456 | 1491 | ldebug ("`%s' does not support ADC\n", drv->name); |
1457 | 1492 | } |
... | ... | @@ -1460,33 +1495,16 @@ static int audio_driver_init (struct audio_driver *drv) |
1460 | 1495 | "`%s' does not support %d multiple ADC voices\n" |
1461 | 1496 | "Resetting to %d\n", |
1462 | 1497 | drv->name, |
1463 | - audio_state.nb_hw_voices_in, | |
1498 | + s->nb_hw_voices_in, | |
1464 | 1499 | drv->max_voices_in |
1465 | 1500 | ); |
1466 | 1501 | } |
1467 | - audio_state.nb_hw_voices_in = drv->max_voices_in; | |
1502 | + s->nb_hw_voices_in = drv->max_voices_in; | |
1468 | 1503 | } |
1469 | 1504 | |
1470 | - LIST_INIT (&hw_head_in); | |
1471 | - hwi = qemu_mallocz (audio_state.nb_hw_voices_in * drv->voice_size_in); | |
1472 | - if (!hwi) { | |
1473 | - dolog ( | |
1474 | - "Not enough memory for %d `%s' ADC voices (each %d bytes)\n", | |
1475 | - audio_state.nb_hw_voices_in, | |
1476 | - drv->name, | |
1477 | - drv->voice_size_in | |
1478 | - ); | |
1479 | - qemu_free (hwo); | |
1480 | - drv->fini (audio_state.opaque); | |
1481 | - return -1; | |
1482 | - } | |
1483 | - | |
1484 | - for (i = 0; i < audio_state.nb_hw_voices_in; ++i) { | |
1485 | - LIST_INSERT_HEAD (&hw_head_in, hwi, entries); | |
1486 | - hwi = advance (hwi, drv->voice_size_in); | |
1487 | - } | |
1488 | - | |
1489 | - audio_state.drv = drv; | |
1505 | + LIST_INIT (&s->hw_head_out); | |
1506 | + LIST_INIT (&s->hw_head_in); | |
1507 | + s->drv = drv; | |
1490 | 1508 | return 0; |
1491 | 1509 | } |
1492 | 1510 | else { |
... | ... | @@ -1497,12 +1515,12 @@ static int audio_driver_init (struct audio_driver *drv) |
1497 | 1515 | |
1498 | 1516 | static void audio_vm_stop_handler (void *opaque, int reason) |
1499 | 1517 | { |
1518 | + AudioState *s = opaque; | |
1500 | 1519 | HWVoiceOut *hwo = NULL; |
1501 | 1520 | HWVoiceIn *hwi = NULL; |
1502 | 1521 | int op = reason ? VOICE_ENABLE : VOICE_DISABLE; |
1503 | 1522 | |
1504 | - (void) opaque; | |
1505 | - while ((hwo = audio_pcm_hw_find_any_out (hwo))) { | |
1523 | + while ((hwo = audio_pcm_hw_find_any_out (s, hwo))) { | |
1506 | 1524 | if (!hwo->pcm_ops) { |
1507 | 1525 | continue; |
1508 | 1526 | } |
... | ... | @@ -1512,7 +1530,7 @@ static void audio_vm_stop_handler (void *opaque, int reason) |
1512 | 1530 | } |
1513 | 1531 | } |
1514 | 1532 | |
1515 | - while ((hwi = audio_pcm_hw_find_any_in (hwi))) { | |
1533 | + while ((hwi = audio_pcm_hw_find_any_in (s, hwi))) { | |
1516 | 1534 | if (!hwi->pcm_ops) { |
1517 | 1535 | continue; |
1518 | 1536 | } |
... | ... | @@ -1525,10 +1543,11 @@ static void audio_vm_stop_handler (void *opaque, int reason) |
1525 | 1543 | |
1526 | 1544 | static void audio_atexit (void) |
1527 | 1545 | { |
1546 | + AudioState *s = &glob_audio_state; | |
1528 | 1547 | HWVoiceOut *hwo = NULL; |
1529 | 1548 | HWVoiceIn *hwi = NULL; |
1530 | 1549 | |
1531 | - while ((hwo = audio_pcm_hw_find_any_out (hwo))) { | |
1550 | + while ((hwo = audio_pcm_hw_find_any_out (s, hwo))) { | |
1532 | 1551 | if (!hwo->pcm_ops) { |
1533 | 1552 | continue; |
1534 | 1553 | } |
... | ... | @@ -1539,7 +1558,7 @@ static void audio_atexit (void) |
1539 | 1558 | hwo->pcm_ops->fini_out (hwo); |
1540 | 1559 | } |
1541 | 1560 | |
1542 | - while ((hwi = audio_pcm_hw_find_any_in (hwi))) { | |
1561 | + while ((hwi = audio_pcm_hw_find_any_in (s, hwi))) { | |
1543 | 1562 | if (!hwi->pcm_ops) { |
1544 | 1563 | continue; |
1545 | 1564 | } |
... | ... | @@ -1549,7 +1568,10 @@ static void audio_atexit (void) |
1549 | 1568 | } |
1550 | 1569 | hwi->pcm_ops->fini_in (hwi); |
1551 | 1570 | } |
1552 | - audio_state.drv->fini (audio_state.opaque); | |
1571 | + | |
1572 | + if (s->drv) { | |
1573 | + s->drv->fini (s->drv_opaque); | |
1574 | + } | |
1553 | 1575 | } |
1554 | 1576 | |
1555 | 1577 | static void audio_save (QEMUFile *f, void *opaque) |
... | ... | @@ -1570,15 +1592,33 @@ static int audio_load (QEMUFile *f, void *opaque, int version_id) |
1570 | 1592 | return 0; |
1571 | 1593 | } |
1572 | 1594 | |
1573 | -void AUD_init (void) | |
1595 | +void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card) | |
1596 | +{ | |
1597 | + card->audio = s; | |
1598 | + card->name = qemu_strdup (name); | |
1599 | + memset (&card->entries, 0, sizeof (card->entries)); | |
1600 | + LIST_INSERT_HEAD (&s->card_head, card, entries); | |
1601 | +} | |
1602 | + | |
1603 | +void AUD_remove_card (QEMUSoundCard *card) | |
1604 | +{ | |
1605 | + LIST_REMOVE (card, entries); | |
1606 | + card->audio = NULL; | |
1607 | + qemu_free (card->name); | |
1608 | +} | |
1609 | + | |
1610 | +AudioState *AUD_init (void) | |
1574 | 1611 | { |
1575 | 1612 | size_t i; |
1576 | 1613 | int done = 0; |
1577 | 1614 | const char *drvname; |
1578 | - AudioState *s = &audio_state; | |
1615 | + AudioState *s = &glob_audio_state; | |
1579 | 1616 | |
1580 | 1617 | audio_process_options ("AUDIO", audio_options); |
1581 | 1618 | |
1619 | + s->nb_hw_voices_out = conf.fixed_out.nb_voices; | |
1620 | + s->nb_hw_voices_in = conf.fixed_in.nb_voices; | |
1621 | + | |
1582 | 1622 | if (s->nb_hw_voices_out <= 0) { |
1583 | 1623 | dolog ("Bogus number of DAC voices %d\n", |
1584 | 1624 | s->nb_hw_voices_out); |
... | ... | @@ -1598,8 +1638,8 @@ void AUD_init (void) |
1598 | 1638 | |
1599 | 1639 | s->ts = qemu_new_timer (vm_clock, audio_timer, s); |
1600 | 1640 | if (!s->ts) { |
1601 | - dolog ("Can not create audio timer\n"); | |
1602 | - return; | |
1641 | + dolog ("Could not create audio timer\n"); | |
1642 | + return NULL; | |
1603 | 1643 | } |
1604 | 1644 | |
1605 | 1645 | if (drvname) { |
... | ... | @@ -1607,7 +1647,7 @@ void AUD_init (void) |
1607 | 1647 | |
1608 | 1648 | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1609 | 1649 | if (!strcmp (drvname, drvtab[i]->name)) { |
1610 | - done = !audio_driver_init (drvtab[i]); | |
1650 | + done = !audio_driver_init (s, drvtab[i]); | |
1611 | 1651 | found = 1; |
1612 | 1652 | break; |
1613 | 1653 | } |
... | ... | @@ -1619,37 +1659,47 @@ void AUD_init (void) |
1619 | 1659 | } |
1620 | 1660 | } |
1621 | 1661 | |
1622 | - qemu_add_vm_stop_handler (audio_vm_stop_handler, NULL); | |
1623 | - atexit (audio_atexit); | |
1624 | - | |
1625 | 1662 | if (!done) { |
1626 | 1663 | for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
1627 | 1664 | if (drvtab[i]->can_be_default) { |
1628 | - done = !audio_driver_init (drvtab[i]); | |
1665 | + done = !audio_driver_init (s, drvtab[i]); | |
1629 | 1666 | } |
1630 | 1667 | } |
1631 | 1668 | } |
1632 | 1669 | |
1633 | - register_savevm ("audio", 0, 1, audio_save, audio_load, NULL); | |
1634 | 1670 | if (!done) { |
1635 | - if (audio_driver_init (&no_audio_driver)) { | |
1636 | - dolog ("Can not initialize audio subsystem\n"); | |
1671 | + done = !audio_driver_init (s, &no_audio_driver); | |
1672 | + if (!done) { | |
1673 | + dolog ("Could not initialize audio subsystem\n"); | |
1637 | 1674 | } |
1638 | 1675 | else { |
1639 | - dolog ("warning: using timer based audio emulation\n"); | |
1676 | + dolog ("warning: Using timer based audio emulation\n"); | |
1640 | 1677 | } |
1641 | 1678 | } |
1642 | 1679 | |
1643 | - if (s->period.usec <= 0) { | |
1644 | - if (s->period.usec < 0) { | |
1645 | - dolog ("warning: timer period is negative - %d treating as zero\n", | |
1646 | - s->period.usec); | |
1680 | + if (done) { | |
1681 | + if (conf.period.hz <= 0) { | |
1682 | + if (conf.period.hz < 0) { | |
1683 | + dolog ("warning: Timer period is negative - %d " | |
1684 | + "treating as zero\n", | |
1685 | + conf.period.hz); | |
1686 | + } | |
1687 | + conf.period.ticks = 1; | |
1647 | 1688 | } |
1648 | - s->period.ticks = 1; | |
1689 | + else { | |
1690 | + conf.period.ticks = ticks_per_sec / conf.period.hz; | |
1691 | + } | |
1692 | + | |
1693 | + qemu_add_vm_stop_handler (audio_vm_stop_handler, NULL); | |
1649 | 1694 | } |
1650 | 1695 | else { |
1651 | - s->period.ticks = (ticks_per_sec * s->period.usec) / 1000000; | |
1696 | + qemu_del_timer (s->ts); | |
1697 | + return NULL; | |
1652 | 1698 | } |
1653 | 1699 | |
1654 | - qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + s->period.ticks); | |
1700 | + LIST_INIT (&s->card_head); | |
1701 | + register_savevm ("audio", 0, 1, audio_save, audio_load, s); | |
1702 | + atexit (audio_atexit); | |
1703 | + qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks); | |
1704 | + return s; | |
1655 | 1705 | } | ... | ... |
audio/audio.h
... | ... | @@ -24,18 +24,33 @@ |
24 | 24 | #ifndef QEMU_AUDIO_H |
25 | 25 | #define QEMU_AUDIO_H |
26 | 26 | |
27 | +#include "sys-queue.h" | |
28 | + | |
27 | 29 | typedef void (*audio_callback_fn_t) (void *opaque, int avail); |
28 | 30 | |
29 | 31 | typedef enum { |
30 | - AUD_FMT_U8, | |
31 | - AUD_FMT_S8, | |
32 | - AUD_FMT_U16, | |
33 | - AUD_FMT_S16 | |
32 | + AUD_FMT_U8, | |
33 | + AUD_FMT_S8, | |
34 | + AUD_FMT_U16, | |
35 | + AUD_FMT_S16 | |
34 | 36 | } audfmt_e; |
35 | 37 | |
38 | +typedef struct { | |
39 | + int freq; | |
40 | + int nchannels; | |
41 | + audfmt_e fmt; | |
42 | +} audsettings_t; | |
43 | + | |
44 | +typedef struct AudioState AudioState; | |
36 | 45 | typedef struct SWVoiceOut SWVoiceOut; |
37 | 46 | typedef struct SWVoiceIn SWVoiceIn; |
38 | 47 | |
48 | +typedef struct QEMUSoundCard { | |
49 | + AudioState *audio; | |
50 | + char *name; | |
51 | + LIST_ENTRY (QEMUSoundCard) entries; | |
52 | +} QEMUSoundCard; | |
53 | + | |
39 | 54 | typedef struct QEMUAudioTimeStamp { |
40 | 55 | uint64_t old_ts; |
41 | 56 | } QEMUAudioTimeStamp; |
... | ... | @@ -47,46 +62,45 @@ void AUD_log (const char *cap, const char *fmt, ...) |
47 | 62 | #endif |
48 | 63 | ; |
49 | 64 | |
50 | -void AUD_init (void); | |
65 | +AudioState *AUD_init (void); | |
51 | 66 | void AUD_help (void); |
67 | +void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card); | |
68 | +void AUD_remove_card (QEMUSoundCard *card); | |
52 | 69 | |
53 | -SWVoiceOut *AUD_open_out ( | |
70 | +SWVoiceOut *AUD_open_out ( | |
71 | + QEMUSoundCard *card, | |
54 | 72 | SWVoiceOut *sw, |
55 | 73 | const char *name, |
56 | 74 | void *callback_opaque, |
57 | 75 | audio_callback_fn_t callback_fn, |
58 | - int freq, | |
59 | - int nchannels, | |
60 | - audfmt_e fmt | |
76 | + audsettings_t *settings | |
61 | 77 | ); |
62 | -void AUD_close_out (SWVoiceOut *sw); | |
63 | -int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); | |
64 | -int AUD_get_buffer_size_out (SWVoiceOut *sw); | |
65 | -void AUD_set_active_out (SWVoiceOut *sw, int on); | |
66 | -int AUD_is_active_out (SWVoiceOut *sw); | |
67 | -void AUD_init_time_stamp_out (SWVoiceOut *sw, | |
68 | - QEMUAudioTimeStamp *ts); | |
69 | -uint64_t AUD_time_stamp_get_elapsed_usec_out (SWVoiceOut *sw, | |
70 | - QEMUAudioTimeStamp *ts); | |
71 | - | |
72 | -SWVoiceIn *AUD_open_in ( | |
78 | + | |
79 | +void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); | |
80 | +int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); | |
81 | +int AUD_get_buffer_size_out (SWVoiceOut *sw); | |
82 | +void AUD_set_active_out (SWVoiceOut *sw, int on); | |
83 | +int AUD_is_active_out (SWVoiceOut *sw); | |
84 | + | |
85 | +void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
86 | +uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
87 | + | |
88 | +SWVoiceIn *AUD_open_in ( | |
89 | + QEMUSoundCard *card, | |
73 | 90 | SWVoiceIn *sw, |
74 | 91 | const char *name, |
75 | 92 | void *callback_opaque, |
76 | 93 | audio_callback_fn_t callback_fn, |
77 | - int freq, | |
78 | - int nchannels, | |
79 | - audfmt_e fmt | |
94 | + audsettings_t *settings | |
80 | 95 | ); |
81 | -void AUD_close_in (SWVoiceIn *sw); | |
82 | -int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); | |
83 | -void AUD_adjust_in (SWVoiceIn *sw, int leftover); | |
84 | -void AUD_set_active_in (SWVoiceIn *sw, int on); | |
85 | -int AUD_is_active_in (SWVoiceIn *sw); | |
86 | -void AUD_init_time_stamp_in (SWVoiceIn *sw, | |
87 | - QEMUAudioTimeStamp *ts); | |
88 | -uint64_t AUD_time_stamp_get_elapsed_usec_in (SWVoiceIn *sw, | |
89 | - QEMUAudioTimeStamp *ts); | |
96 | + | |
97 | +void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); | |
98 | +int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); | |
99 | +void AUD_set_active_in (SWVoiceIn *sw, int on); | |
100 | +int AUD_is_active_in (SWVoiceIn *sw); | |
101 | + | |
102 | +void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
103 | +uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
90 | 104 | |
91 | 105 | static inline void *advance (void *p, int incr) |
92 | 106 | { | ... | ... |
audio/audio_int.h
... | ... | @@ -24,16 +24,12 @@ |
24 | 24 | #ifndef QEMU_AUDIO_INT_H |
25 | 25 | #define QEMU_AUDIO_INT_H |
26 | 26 | |
27 | -#include "sys-queue.h" | |
28 | - | |
29 | 27 | #ifdef CONFIG_COREAUDIO |
30 | 28 | #define FLOAT_MIXENG |
31 | 29 | /* #define RECIPROCAL */ |
32 | 30 | #endif |
33 | 31 | #include "mixeng.h" |
34 | 32 | |
35 | -int audio_bug (const char *funcname, int cond); | |
36 | - | |
37 | 33 | struct audio_pcm_ops; |
38 | 34 | |
39 | 35 | typedef enum { |
... | ... | @@ -69,7 +65,6 @@ struct audio_pcm_info { |
69 | 65 | }; |
70 | 66 | |
71 | 67 | typedef struct HWVoiceOut { |
72 | - int active; | |
73 | 68 | int enabled; |
74 | 69 | int pending_disable; |
75 | 70 | int valid; |
... | ... | @@ -78,7 +73,6 @@ typedef struct HWVoiceOut { |
78 | 73 | f_sample *clip; |
79 | 74 | |
80 | 75 | int rpos; |
81 | - int bufsize; | |
82 | 76 | uint64_t ts_helper; |
83 | 77 | |
84 | 78 | st_sample_t *mix_buf; |
... | ... | @@ -91,13 +85,11 @@ typedef struct HWVoiceOut { |
91 | 85 | |
92 | 86 | typedef struct HWVoiceIn { |
93 | 87 | int enabled; |
94 | - int active; | |
95 | 88 | struct audio_pcm_info info; |
96 | 89 | |
97 | 90 | t_sample *conv; |
98 | 91 | |
99 | 92 | int wpos; |
100 | - int bufsize; | |
101 | 93 | int total_samples_captured; |
102 | 94 | uint64_t ts_helper; |
103 | 95 | |
... | ... | @@ -109,58 +101,6 @@ typedef struct HWVoiceIn { |
109 | 101 | LIST_ENTRY (HWVoiceIn) entries; |
110 | 102 | } HWVoiceIn; |
111 | 103 | |
112 | -extern struct audio_driver no_audio_driver; | |
113 | -extern struct audio_driver oss_audio_driver; | |
114 | -extern struct audio_driver sdl_audio_driver; | |
115 | -extern struct audio_driver wav_audio_driver; | |
116 | -extern struct audio_driver fmod_audio_driver; | |
117 | -extern struct audio_driver alsa_audio_driver; | |
118 | -extern struct audio_driver coreaudio_audio_driver; | |
119 | -extern struct audio_driver dsound_audio_driver; | |
120 | -extern volume_t nominal_volume; | |
121 | - | |
122 | -struct audio_driver { | |
123 | - const char *name; | |
124 | - const char *descr; | |
125 | - struct audio_option *options; | |
126 | - void *(*init) (void); | |
127 | - void (*fini) (void *); | |
128 | - struct audio_pcm_ops *pcm_ops; | |
129 | - int can_be_default; | |
130 | - int max_voices_out; | |
131 | - int max_voices_in; | |
132 | - int voice_size_out; | |
133 | - int voice_size_in; | |
134 | -}; | |
135 | - | |
136 | -typedef struct AudioState { | |
137 | - int fixed_settings_out; | |
138 | - int fixed_freq_out; | |
139 | - int fixed_channels_out; | |
140 | - int fixed_fmt_out; | |
141 | - int nb_hw_voices_out; | |
142 | - int greedy_out; | |
143 | - | |
144 | - int fixed_settings_in; | |
145 | - int fixed_freq_in; | |
146 | - int fixed_channels_in; | |
147 | - int fixed_fmt_in; | |
148 | - int nb_hw_voices_in; | |
149 | - int greedy_in; | |
150 | - | |
151 | - void *opaque; | |
152 | - struct audio_driver *drv; | |
153 | - | |
154 | - QEMUTimer *ts; | |
155 | - union { | |
156 | - int usec; | |
157 | - int64_t ticks; | |
158 | - } period; | |
159 | - | |
160 | - int plive; | |
161 | -} AudioState; | |
162 | -extern AudioState audio_state; | |
163 | - | |
164 | 104 | struct SWVoiceOut { |
165 | 105 | struct audio_pcm_info info; |
166 | 106 | t_sample *conv; |
... | ... | @@ -192,22 +132,58 @@ struct SWVoiceIn { |
192 | 132 | LIST_ENTRY (SWVoiceIn) entries; |
193 | 133 | }; |
194 | 134 | |
135 | +struct audio_driver { | |
136 | + const char *name; | |
137 | + const char *descr; | |
138 | + struct audio_option *options; | |
139 | + void *(*init) (void); | |
140 | + void (*fini) (void *); | |
141 | + struct audio_pcm_ops *pcm_ops; | |
142 | + int can_be_default; | |
143 | + int max_voices_out; | |
144 | + int max_voices_in; | |
145 | + int voice_size_out; | |
146 | + int voice_size_in; | |
147 | +}; | |
148 | + | |
195 | 149 | struct audio_pcm_ops { |
196 | - int (*init_out)(HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt); | |
150 | + int (*init_out)(HWVoiceOut *hw, audsettings_t *as); | |
197 | 151 | void (*fini_out)(HWVoiceOut *hw); |
198 | 152 | int (*run_out) (HWVoiceOut *hw); |
199 | 153 | int (*write) (SWVoiceOut *sw, void *buf, int size); |
200 | 154 | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); |
201 | 155 | |
202 | - int (*init_in) (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt); | |
156 | + int (*init_in) (HWVoiceIn *hw, audsettings_t *as); | |
203 | 157 | void (*fini_in) (HWVoiceIn *hw); |
204 | 158 | int (*run_in) (HWVoiceIn *hw); |
205 | 159 | int (*read) (SWVoiceIn *sw, void *buf, int size); |
206 | 160 | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); |
207 | 161 | }; |
208 | 162 | |
209 | -void audio_pcm_init_info (struct audio_pcm_info *info, int freq, | |
210 | - int nchannels, audfmt_e fmt, int swap_endian); | |
163 | +struct AudioState { | |
164 | + struct audio_driver *drv; | |
165 | + void *drv_opaque; | |
166 | + | |
167 | + QEMUTimer *ts; | |
168 | + LIST_HEAD (card_head, QEMUSoundCard) card_head; | |
169 | + LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; | |
170 | + LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; | |
171 | + int nb_hw_voices_out; | |
172 | + int nb_hw_voices_in; | |
173 | +}; | |
174 | + | |
175 | +extern struct audio_driver no_audio_driver; | |
176 | +extern struct audio_driver oss_audio_driver; | |
177 | +extern struct audio_driver sdl_audio_driver; | |
178 | +extern struct audio_driver wav_audio_driver; | |
179 | +extern struct audio_driver fmod_audio_driver; | |
180 | +extern struct audio_driver alsa_audio_driver; | |
181 | +extern struct audio_driver coreaudio_audio_driver; | |
182 | +extern struct audio_driver dsound_audio_driver; | |
183 | +extern volume_t nominal_volume; | |
184 | + | |
185 | +void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as, | |
186 | + int swap_endian); | |
211 | 187 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
212 | 188 | |
213 | 189 | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); |
... | ... | @@ -217,6 +193,9 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); |
217 | 193 | int audio_pcm_hw_get_live_out (HWVoiceOut *hw); |
218 | 194 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live); |
219 | 195 | |
196 | +int audio_bug (const char *funcname, int cond); | |
197 | +void *audio_calloc (const char *funcname, int nmemb, size_t size); | |
198 | + | |
220 | 199 | #define VOICE_ENABLE 1 |
221 | 200 | #define VOICE_DISABLE 2 |
222 | 201 | ... | ... |
audio/audio_template.h
... | ... | @@ -32,6 +32,43 @@ |
32 | 32 | #define SW glue (SWVoice, In) |
33 | 33 | #endif |
34 | 34 | |
35 | +static int glue (audio_pcm_hw_init_, TYPE) ( | |
36 | + HW *hw, | |
37 | + audsettings_t *as | |
38 | + ) | |
39 | +{ | |
40 | + glue (audio_pcm_hw_free_resources_, TYPE) (hw); | |
41 | + | |
42 | + if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) { | |
43 | + return -1; | |
44 | + } | |
45 | + | |
46 | + if (audio_bug (AUDIO_FUNC, hw->samples <= 0)) { | |
47 | + dolog ("hw->samples=%d\n", hw->samples); | |
48 | + return -1; | |
49 | + } | |
50 | + | |
51 | + LIST_INIT (&hw->sw_head); | |
52 | +#ifdef DAC | |
53 | + hw->clip = | |
54 | + mixeng_clip | |
55 | +#else | |
56 | + hw->conv = | |
57 | + mixeng_conv | |
58 | +#endif | |
59 | + [hw->info.nchannels == 2] | |
60 | + [hw->info.sign] | |
61 | + [hw->info.swap_endian] | |
62 | + [hw->info.bits == 16]; | |
63 | + | |
64 | + if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) { | |
65 | + glue (hw->pcm_ops->fini_, TYPE) (hw); | |
66 | + return -1; | |
67 | + } | |
68 | + | |
69 | + return 0; | |
70 | +} | |
71 | + | |
35 | 72 | static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw) |
36 | 73 | { |
37 | 74 | glue (audio_pcm_sw_free_resources_, TYPE) (sw); |
... | ... | @@ -51,89 +88,86 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw) |
51 | 88 | LIST_REMOVE (sw, entries); |
52 | 89 | } |
53 | 90 | |
54 | -static void glue (audio_pcm_hw_fini_, TYPE) (HW *hw) | |
91 | +static void glue (audio_pcm_hw_gc_, TYPE) (AudioState *s, HW **hwp) | |
55 | 92 | { |
56 | - if (hw->active) { | |
57 | - glue (audio_pcm_hw_free_resources_ ,TYPE) (hw); | |
58 | - glue (hw->pcm_ops->fini_, TYPE) (hw); | |
59 | - memset (hw, 0, glue (audio_state.drv->voice_size_, TYPE)); | |
60 | - } | |
61 | -} | |
93 | + HW *hw = *hwp; | |
62 | 94 | |
63 | -static void glue (audio_pcm_hw_gc_, TYPE) (HW *hw) | |
64 | -{ | |
65 | 95 | if (!hw->sw_head.lh_first) { |
66 | - glue (audio_pcm_hw_fini_, TYPE) (hw); | |
96 | + LIST_REMOVE (hw, entries); | |
97 | + glue (s->nb_hw_voices_, TYPE) += 1; | |
98 | + glue (audio_pcm_hw_free_resources_ ,TYPE) (hw); | |
99 | + glue (hw->pcm_ops->fini_, TYPE) (hw); | |
100 | + qemu_free (hw); | |
101 | + *hwp = NULL; | |
67 | 102 | } |
68 | 103 | } |
69 | 104 | |
70 | -static HW *glue (audio_pcm_hw_find_any_, TYPE) (HW *hw) | |
105 | +static HW *glue (audio_pcm_hw_find_any_, TYPE) (AudioState *s, HW *hw) | |
71 | 106 | { |
72 | - return hw ? hw->entries.le_next : glue (hw_head_, TYPE).lh_first; | |
107 | + return hw ? hw->entries.le_next : s->glue (hw_head_, TYPE).lh_first; | |
73 | 108 | } |
74 | 109 | |
75 | -static HW *glue (audio_pcm_hw_find_any_active_, TYPE) (HW *hw) | |
110 | +static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (AudioState *s, HW *hw) | |
76 | 111 | { |
77 | - while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) { | |
78 | - if (hw->active) { | |
112 | + while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) { | |
113 | + if (hw->enabled) { | |
79 | 114 | return hw; |
80 | 115 | } |
81 | 116 | } |
82 | 117 | return NULL; |
83 | 118 | } |
84 | 119 | |
85 | -static HW *glue (audio_pcm_hw_find_any_active_enabled_, TYPE) (HW *hw) | |
120 | +static HW *glue (audio_pcm_hw_find_any_passive_, TYPE) (AudioState *s) | |
86 | 121 | { |
87 | - while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) { | |
88 | - if (hw->active && hw->enabled) { | |
89 | - return hw; | |
122 | + if (glue (s->nb_hw_voices_, TYPE)) { | |
123 | + struct audio_driver *drv = s->drv; | |
124 | + | |
125 | + if (audio_bug (AUDIO_FUNC, !drv)) { | |
126 | + dolog ("No host audio driver\n"); | |
127 | + return NULL; | |
90 | 128 | } |
91 | - } | |
92 | - return NULL; | |
93 | -} | |
94 | 129 | |
95 | -static HW *glue (audio_pcm_hw_find_any_passive_, TYPE) (HW *hw) | |
96 | -{ | |
97 | - while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) { | |
98 | - if (!hw->active) { | |
99 | - return hw; | |
130 | + HW *hw = audio_calloc (AUDIO_FUNC, 1, glue (drv->voice_size_, TYPE)); | |
131 | + if (!hw) { | |
132 | + dolog ("Can not allocate voice `%s' size %d\n", | |
133 | + drv->name, glue (drv->voice_size_, TYPE)); | |
100 | 134 | } |
135 | + | |
136 | + LIST_INSERT_HEAD (&s->glue (hw_head_, TYPE), hw, entries); | |
137 | + glue (s->nb_hw_voices_, TYPE) -= 1; | |
138 | + return hw; | |
101 | 139 | } |
140 | + | |
102 | 141 | return NULL; |
103 | 142 | } |
104 | 143 | |
105 | 144 | static HW *glue (audio_pcm_hw_find_specific_, TYPE) ( |
145 | + AudioState *s, | |
106 | 146 | HW *hw, |
107 | - int freq, | |
108 | - int nchannels, | |
109 | - audfmt_e fmt | |
147 | + audsettings_t *as | |
110 | 148 | ) |
111 | 149 | { |
112 | - while ((hw = glue (audio_pcm_hw_find_any_active_, TYPE) (hw))) { | |
113 | - if (audio_pcm_info_eq (&hw->info, freq, nchannels, fmt)) { | |
150 | + while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) { | |
151 | + if (audio_pcm_info_eq (&hw->info, as)) { | |
114 | 152 | return hw; |
115 | 153 | } |
116 | 154 | } |
117 | 155 | return NULL; |
118 | 156 | } |
119 | 157 | |
120 | -static HW *glue (audio_pcm_hw_add_new_, TYPE) ( | |
121 | - int freq, | |
122 | - int nchannels, | |
123 | - audfmt_e fmt | |
124 | - ) | |
158 | +static HW *glue (audio_pcm_hw_add_new_, TYPE) (AudioState *s, audsettings_t *as) | |
125 | 159 | { |
126 | 160 | HW *hw; |
127 | 161 | |
128 | - hw = glue (audio_pcm_hw_find_any_passive_, TYPE) (NULL); | |
162 | + hw = glue (audio_pcm_hw_find_any_passive_, TYPE) (s); | |
129 | 163 | if (hw) { |
130 | - hw->pcm_ops = audio_state.drv->pcm_ops; | |
164 | + hw->pcm_ops = s->drv->pcm_ops; | |
131 | 165 | if (!hw->pcm_ops) { |
132 | 166 | return NULL; |
133 | 167 | } |
134 | 168 | |
135 | - if (glue (audio_pcm_hw_init_, TYPE) (hw, freq, nchannels, fmt)) { | |
136 | - glue (audio_pcm_hw_gc_, TYPE) (hw); | |
169 | + if (glue (audio_pcm_hw_init_, TYPE) (hw, as)) { | |
170 | + glue (audio_pcm_hw_gc_, TYPE) (s, &hw); | |
137 | 171 | return NULL; |
138 | 172 | } |
139 | 173 | else { |
... | ... | @@ -144,66 +178,62 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) ( |
144 | 178 | return NULL; |
145 | 179 | } |
146 | 180 | |
147 | -static HW *glue (audio_pcm_hw_add_, TYPE) ( | |
148 | - int freq, | |
149 | - int nchannels, | |
150 | - audfmt_e fmt | |
151 | - ) | |
181 | +static HW *glue (audio_pcm_hw_add_, TYPE) (AudioState *s, audsettings_t *as) | |
152 | 182 | { |
153 | 183 | HW *hw; |
154 | 184 | |
155 | - if (glue (audio_state.greedy_, TYPE)) { | |
156 | - hw = glue (audio_pcm_hw_add_new_, TYPE) (freq, nchannels, fmt); | |
185 | + if (glue (conf.fixed_, TYPE).enabled && glue (conf.fixed_, TYPE).greedy) { | |
186 | + hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as); | |
157 | 187 | if (hw) { |
158 | 188 | return hw; |
159 | 189 | } |
160 | 190 | } |
161 | 191 | |
162 | - hw = glue (audio_pcm_hw_find_specific_, TYPE) (NULL, freq, nchannels, fmt); | |
192 | + hw = glue (audio_pcm_hw_find_specific_, TYPE) (s, NULL, as); | |
163 | 193 | if (hw) { |
164 | 194 | return hw; |
165 | 195 | } |
166 | 196 | |
167 | - hw = glue (audio_pcm_hw_add_new_, TYPE) (freq, nchannels, fmt); | |
197 | + hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as); | |
168 | 198 | if (hw) { |
169 | 199 | return hw; |
170 | 200 | } |
171 | 201 | |
172 | - return glue (audio_pcm_hw_find_any_active_, TYPE) (NULL); | |
202 | + return glue (audio_pcm_hw_find_any_, TYPE) (s, NULL); | |
173 | 203 | } |
174 | 204 | |
175 | 205 | static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( |
176 | - const char *name, | |
177 | - int freq, | |
178 | - int nchannels, | |
179 | - audfmt_e fmt | |
206 | + AudioState *s, | |
207 | + const char *sw_name, | |
208 | + audsettings_t *as | |
180 | 209 | ) |
181 | 210 | { |
182 | 211 | SW *sw; |
183 | 212 | HW *hw; |
184 | - int hw_freq = freq; | |
185 | - int hw_nchannels = nchannels; | |
186 | - int hw_fmt = fmt; | |
213 | + audsettings_t hw_as; | |
187 | 214 | |
188 | - if (glue (audio_state.fixed_settings_, TYPE)) { | |
189 | - hw_freq = glue (audio_state.fixed_freq_, TYPE); | |
190 | - hw_nchannels = glue (audio_state.fixed_channels_, TYPE); | |
191 | - hw_fmt = glue (audio_state.fixed_fmt_, TYPE); | |
215 | + if (glue (conf.fixed_, TYPE).enabled) { | |
216 | + hw_as = glue (conf.fixed_, TYPE).settings; | |
217 | + } | |
218 | + else { | |
219 | + hw_as = *as; | |
192 | 220 | } |
193 | 221 | |
194 | - sw = qemu_mallocz (sizeof (*sw)); | |
222 | + sw = audio_calloc (AUDIO_FUNC, 1, sizeof (*sw)); | |
195 | 223 | if (!sw) { |
224 | + dolog ("Could not allocate soft voice `%s' (%d bytes)\n", | |
225 | + sw_name ? sw_name : "unknown", sizeof (*sw)); | |
196 | 226 | goto err1; |
197 | 227 | } |
198 | 228 | |
199 | - hw = glue (audio_pcm_hw_add_, TYPE) (hw_freq, hw_nchannels, hw_fmt); | |
229 | + hw = glue (audio_pcm_hw_add_, TYPE) (s, &hw_as); | |
200 | 230 | if (!hw) { |
201 | 231 | goto err2; |
202 | 232 | } |
203 | 233 | |
204 | 234 | glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw); |
205 | 235 | |
206 | - if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, freq, nchannels, fmt)) { | |
236 | + if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as)) { | |
207 | 237 | goto err3; |
208 | 238 | } |
209 | 239 | |
... | ... | @@ -211,67 +241,86 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( |
211 | 241 | |
212 | 242 | err3: |
213 | 243 | glue (audio_pcm_hw_del_sw_, TYPE) (sw); |
214 | - glue (audio_pcm_hw_gc_, TYPE) (hw); | |
244 | + glue (audio_pcm_hw_gc_, TYPE) (s, &hw); | |
215 | 245 | err2: |
216 | 246 | qemu_free (sw); |
217 | 247 | err1: |
218 | 248 | return NULL; |
219 | 249 | } |
220 | 250 | |
221 | -void glue (AUD_close_, TYPE) (SW *sw) | |
251 | +static void glue (audio_close_, TYPE) (AudioState *s, SW *sw) | |
252 | +{ | |
253 | + glue (audio_pcm_sw_fini_, TYPE) (sw); | |
254 | + glue (audio_pcm_hw_del_sw_, TYPE) (sw); | |
255 | + glue (audio_pcm_hw_gc_, TYPE) (s, &sw->hw); | |
256 | + qemu_free (sw); | |
257 | +} | |
258 | +void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw) | |
222 | 259 | { |
223 | 260 | if (sw) { |
224 | - glue (audio_pcm_sw_fini_, TYPE) (sw); | |
225 | - glue (audio_pcm_hw_del_sw_, TYPE) (sw); | |
226 | - glue (audio_pcm_hw_gc_, TYPE) (sw->hw); | |
227 | - qemu_free (sw); | |
261 | + if (audio_bug (AUDIO_FUNC, !card || !card->audio)) { | |
262 | + dolog ("card=%p card->audio=%p\n", | |
263 | + card, card ? card->audio : NULL); | |
264 | + return; | |
265 | + } | |
266 | + | |
267 | + glue (audio_close_, TYPE) (card->audio, sw); | |
228 | 268 | } |
229 | 269 | } |
230 | 270 | |
231 | 271 | SW *glue (AUD_open_, TYPE) ( |
272 | + QEMUSoundCard *card, | |
232 | 273 | SW *sw, |
233 | 274 | const char *name, |
234 | 275 | void *callback_opaque , |
235 | 276 | audio_callback_fn_t callback_fn, |
236 | - int freq, | |
237 | - int nchannels, | |
238 | - audfmt_e fmt | |
277 | + audsettings_t *as | |
239 | 278 | ) |
240 | 279 | { |
280 | + AudioState *s; | |
241 | 281 | #ifdef DAC |
242 | 282 | int live = 0; |
243 | 283 | SW *old_sw = NULL; |
244 | 284 | #endif |
245 | 285 | |
246 | - if (!callback_fn) { | |
247 | - dolog ("No callback specifed for voice `%s'\n", name); | |
286 | + ldebug ("open %s, freq %d, nchannels %d, fmt %d\n", | |
287 | + name, as->freq, as->nchannels, as->fmt); | |
288 | + | |
289 | + if (audio_bug (AUDIO_FUNC, | |
290 | + !card || !card->audio || !name || !callback_fn || !as)) { | |
291 | + dolog ("card=%p card->audio=%p name=%p callback_fn=%p as=%p\n", | |
292 | + card, card ? card->audio : NULL, name, callback_fn, as); | |
248 | 293 | goto fail; |
249 | 294 | } |
250 | 295 | |
251 | - if (nchannels != 1 && nchannels != 2) { | |
252 | - dolog ("Bogus channel count %d for voice `%s'\n", nchannels, name); | |
296 | + s = card->audio; | |
297 | + | |
298 | + if (audio_bug (AUDIO_FUNC, audio_validate_settigs (as))) { | |
299 | + audio_print_settings (as); | |
253 | 300 | goto fail; |
254 | 301 | } |
255 | 302 | |
256 | - if (!audio_state.drv) { | |
257 | - dolog ("No audio driver defined\n"); | |
303 | + if (audio_bug (AUDIO_FUNC, !s->drv)) { | |
304 | + dolog ("Can not open `%s' (no host audio driver)\n", name); | |
258 | 305 | goto fail; |
259 | 306 | } |
260 | 307 | |
261 | - if (sw && audio_pcm_info_eq (&sw->info, freq, nchannels, fmt)) { | |
308 | + if (sw && audio_pcm_info_eq (&sw->info, as)) { | |
262 | 309 | return sw; |
263 | 310 | } |
264 | 311 | |
265 | 312 | #ifdef DAC |
266 | - if (audio_state.plive && sw && (!sw->active && !sw->empty)) { | |
313 | + if (conf.plive && sw && (!sw->active && !sw->empty)) { | |
267 | 314 | live = sw->total_hw_samples_mixed; |
268 | 315 | |
269 | 316 | #ifdef DEBUG_PLIVE |
270 | - dolog ("Replacing voice %s with %d live samples\n", sw->name, live); | |
317 | + dolog ("Replacing voice %s with %d live samples\n", SW_NAME (sw), live); | |
271 | 318 | dolog ("Old %s freq %d, bits %d, channels %d\n", |
272 | - sw->name, sw->info.freq, sw->info.bits, sw->info.nchannels); | |
319 | + SW_NAME (sw), sw->info.freq, sw->info.bits, sw->info.nchannels); | |
273 | 320 | dolog ("New %s freq %d, bits %d, channels %d\n", |
274 | - name, freq, (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8, | |
321 | + name, | |
322 | + freq, | |
323 | + (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8, | |
275 | 324 | nchannels); |
276 | 325 | #endif |
277 | 326 | |
... | ... | @@ -283,8 +332,8 @@ SW *glue (AUD_open_, TYPE) ( |
283 | 332 | } |
284 | 333 | #endif |
285 | 334 | |
286 | - if (!glue (audio_state.fixed_settings_, TYPE) && sw) { | |
287 | - glue (AUD_close_, TYPE) (sw); | |
335 | + if (!glue (conf.fixed_, TYPE).enabled && sw) { | |
336 | + glue (AUD_close_, TYPE) (card, sw); | |
288 | 337 | sw = NULL; |
289 | 338 | } |
290 | 339 | |
... | ... | @@ -292,30 +341,19 @@ SW *glue (AUD_open_, TYPE) ( |
292 | 341 | HW *hw = sw->hw; |
293 | 342 | |
294 | 343 | if (!hw) { |
295 | - dolog ("Internal logic error voice %s has no hardware store\n", | |
296 | - name); | |
344 | + dolog ("Internal logic error voice `%s' has no hardware store\n", | |
345 | + SW_NAME (sw)); | |
297 | 346 | goto fail; |
298 | 347 | } |
299 | 348 | |
300 | - if (glue (audio_pcm_sw_init_, TYPE) ( | |
301 | - sw, | |
302 | - hw, | |
303 | - name, | |
304 | - freq, | |
305 | - nchannels, | |
306 | - fmt | |
307 | - )) { | |
349 | + if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as)) { | |
308 | 350 | goto fail; |
309 | 351 | } |
310 | 352 | } |
311 | 353 | else { |
312 | - sw = glue (audio_pcm_create_voice_pair_, TYPE) ( | |
313 | - name, | |
314 | - freq, | |
315 | - nchannels, | |
316 | - fmt); | |
354 | + sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as); | |
317 | 355 | if (!sw) { |
318 | - dolog ("Failed to create voice %s\n", name); | |
356 | + dolog ("Failed to create voice `%s'\n", name); | |
319 | 357 | goto fail; |
320 | 358 | } |
321 | 359 | } |
... | ... | @@ -349,7 +387,7 @@ SW *glue (AUD_open_, TYPE) ( |
349 | 387 | return sw; |
350 | 388 | |
351 | 389 | fail: |
352 | - glue (AUD_close_, TYPE) (sw); | |
390 | + glue (AUD_close_, TYPE) (card, sw); | |
353 | 391 | return NULL; |
354 | 392 | } |
355 | 393 | |
... | ... | @@ -367,10 +405,7 @@ void glue (AUD_init_time_stamp_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts) |
367 | 405 | ts->old_ts = sw->hw->ts_helper; |
368 | 406 | } |
369 | 407 | |
370 | -uint64_t glue (AUD_time_stamp_get_elapsed_usec_, TYPE) ( | |
371 | - SW *sw, | |
372 | - QEMUAudioTimeStamp *ts | |
373 | - ) | |
408 | +uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts) | |
374 | 409 | { |
375 | 410 | uint64_t delta, cur_ts, old_ts; |
376 | 411 | ... | ... |
audio/coreaudio.c
... | ... | @@ -31,8 +31,6 @@ |
31 | 31 | #define AUDIO_CAP "coreaudio" |
32 | 32 | #include "audio_int.h" |
33 | 33 | |
34 | -#define DEVICE_BUFFER_FRAMES (512) | |
35 | - | |
36 | 34 | struct { |
37 | 35 | int buffer_frames; |
38 | 36 | } conf = { |
... | ... | @@ -132,7 +130,7 @@ static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 ( |
132 | 130 | { |
133 | 131 | va_list ap; |
134 | 132 | |
135 | - AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); | |
133 | + AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); | |
136 | 134 | |
137 | 135 | va_start (ap, fmt); |
138 | 136 | AUD_vlog (AUDIO_CAP, fmt, ap); |
... | ... | @@ -147,7 +145,7 @@ static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name) |
147 | 145 | |
148 | 146 | err = pthread_mutex_lock (&core->mutex); |
149 | 147 | if (err) { |
150 | - dolog ("Can not lock voice for %s\nReason: %s\n", | |
148 | + dolog ("Could not lock voice for %s\nReason: %s\n", | |
151 | 149 | fn_name, strerror (err)); |
152 | 150 | return -1; |
153 | 151 | } |
... | ... | @@ -160,7 +158,7 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name) |
160 | 158 | |
161 | 159 | err = pthread_mutex_unlock (&core->mutex); |
162 | 160 | if (err) { |
163 | - dolog ("Can not unlock voice for %s\nReason: %s\n", | |
161 | + dolog ("Could not unlock voice for %s\nReason: %s\n", | |
164 | 162 | fn_name, strerror (err)); |
165 | 163 | return -1; |
166 | 164 | } |
... | ... | @@ -268,8 +266,7 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len) |
268 | 266 | return audio_pcm_sw_write (sw, buf, len); |
269 | 267 | } |
270 | 268 | |
271 | -static int coreaudio_init_out (HWVoiceOut *hw, int freq, | |
272 | - int nchannels, audfmt_e fmt) | |
269 | +static int coreaudio_init_out (HWVoiceOut *hw, audsettings_t *as) | |
273 | 270 | { |
274 | 271 | OSStatus status; |
275 | 272 | coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; |
... | ... | @@ -282,25 +279,22 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
282 | 279 | /* create mutex */ |
283 | 280 | err = pthread_mutex_init(&core->mutex, NULL); |
284 | 281 | if (err) { |
285 | - dolog("Can not create mutex\nReason: %s\n", strerror (err)); | |
282 | + dolog("Could not create mutex\nReason: %s\n", strerror (err)); | |
286 | 283 | return -1; |
287 | 284 | } |
288 | 285 | |
289 | - if (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) { | |
286 | + if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) { | |
290 | 287 | bits = 16; |
291 | 288 | endianess = 1; |
292 | 289 | } |
293 | 290 | |
294 | 291 | audio_pcm_init_info ( |
295 | 292 | &hw->info, |
296 | - freq, | |
297 | - nchannels, | |
298 | - fmt, | |
293 | + as, | |
299 | 294 | /* Following is irrelevant actually since we do not use |
300 | 295 | mixengs clipping routines */ |
301 | 296 | audio_need_to_swap_endian (endianess) |
302 | 297 | ); |
303 | - hw->bufsize = 4 * conf.buffer_frames * nchannels * bits; | |
304 | 298 | |
305 | 299 | /* open default output device */ |
306 | 300 | propertySize = sizeof(core->outputDeviceID); |
... | ... | @@ -310,18 +304,18 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
310 | 304 | &core->outputDeviceID); |
311 | 305 | if (status != kAudioHardwareNoError) { |
312 | 306 | coreaudio_logerr2 (status, typ, |
313 | - "Can not get default output Device\n"); | |
307 | + "Could not get default output Device\n"); | |
314 | 308 | return -1; |
315 | 309 | } |
316 | 310 | if (core->outputDeviceID == kAudioDeviceUnknown) { |
317 | - dolog ("Can not initialize %s - Unknown Audiodevice\n", typ); | |
311 | + dolog ("Could not initialize %s - Unknown Audiodevice\n", typ); | |
318 | 312 | return -1; |
319 | 313 | } |
320 | 314 | |
321 | 315 | /* set Buffersize to conf.buffer_frames frames */ |
322 | 316 | propertySize = sizeof(core->audioDevicePropertyBufferSize); |
323 | 317 | core->audioDevicePropertyBufferSize = |
324 | - conf.buffer_frames * sizeof(float) * 2; | |
318 | + conf.buffer_frames * sizeof(float) << (as->nchannels == 2); | |
325 | 319 | status = AudioDeviceSetProperty( |
326 | 320 | core->outputDeviceID, |
327 | 321 | NULL, |
... | ... | @@ -332,7 +326,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
332 | 326 | &core->audioDevicePropertyBufferSize); |
333 | 327 | if (status != kAudioHardwareNoError) { |
334 | 328 | coreaudio_logerr2 (status, typ, |
335 | - "Can not set device buffer size %d\n", | |
329 | + "Could not set device buffer size %d\n", | |
336 | 330 | kAudioDevicePropertyBufferSize); |
337 | 331 | return -1; |
338 | 332 | } |
... | ... | @@ -347,9 +341,11 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
347 | 341 | &propertySize, |
348 | 342 | &core->audioDevicePropertyBufferSize); |
349 | 343 | if (status != kAudioHardwareNoError) { |
350 | - coreaudio_logerr2 (status, typ, "Can not get device buffer size\n"); | |
344 | + coreaudio_logerr2 (status, typ, "Could not get device buffer size\n"); | |
351 | 345 | return -1; |
352 | 346 | } |
347 | + hw->samples = (core->audioDevicePropertyBufferSize / sizeof (float)) | |
348 | + >> (as->nchannels == 2); | |
353 | 349 | |
354 | 350 | /* get StreamFormat */ |
355 | 351 | propertySize = sizeof(core->outputStreamBasicDescription); |
... | ... | @@ -362,13 +358,13 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
362 | 358 | &core->outputStreamBasicDescription); |
363 | 359 | if (status != kAudioHardwareNoError) { |
364 | 360 | coreaudio_logerr2 (status, typ, |
365 | - "Can not get Device Stream properties\n"); | |
361 | + "Could not get Device Stream properties\n"); | |
366 | 362 | core->outputDeviceID = kAudioDeviceUnknown; |
367 | 363 | return -1; |
368 | 364 | } |
369 | 365 | |
370 | 366 | /* set Samplerate */ |
371 | - core->outputStreamBasicDescription.mSampleRate = (Float64)freq; | |
367 | + core->outputStreamBasicDescription.mSampleRate = (Float64)as->freq; | |
372 | 368 | propertySize = sizeof(core->outputStreamBasicDescription); |
373 | 369 | status = AudioDeviceSetProperty( |
374 | 370 | core->outputDeviceID, |
... | ... | @@ -379,7 +375,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
379 | 375 | propertySize, |
380 | 376 | &core->outputStreamBasicDescription); |
381 | 377 | if (status != kAudioHardwareNoError) { |
382 | - coreaudio_logerr2 (status, typ, "Can not set samplerate %d\n", freq); | |
378 | + coreaudio_logerr2 (status, typ, "Could not set samplerate %d\n", freq); | |
383 | 379 | core->outputDeviceID = kAudioDeviceUnknown; |
384 | 380 | return -1; |
385 | 381 | } |
... | ... | @@ -387,7 +383,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
387 | 383 | /* set Callback */ |
388 | 384 | status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw); |
389 | 385 | if (status != kAudioHardwareNoError) { |
390 | - coreaudio_logerr2 (status, typ, "Can not set IOProc\n"); | |
386 | + coreaudio_logerr2 (status, typ, "Could not set IOProc\n"); | |
391 | 387 | core->outputDeviceID = kAudioDeviceUnknown; |
392 | 388 | return -1; |
393 | 389 | } |
... | ... | @@ -396,7 +392,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, |
396 | 392 | if (!core->isPlaying) { |
397 | 393 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); |
398 | 394 | if (status != kAudioHardwareNoError) { |
399 | - coreaudio_logerr2 (status, typ, "Can not start playback\n"); | |
395 | + coreaudio_logerr2 (status, typ, "Could not start playback\n"); | |
400 | 396 | AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); |
401 | 397 | core->outputDeviceID = kAudioDeviceUnknown; |
402 | 398 | return -1; |
... | ... | @@ -417,7 +413,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) |
417 | 413 | if (core->isPlaying) { |
418 | 414 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); |
419 | 415 | if (status != kAudioHardwareNoError) { |
420 | - coreaudio_logerr (status, "Can not stop playback\n"); | |
416 | + coreaudio_logerr (status, "Could not stop playback\n"); | |
421 | 417 | } |
422 | 418 | core->isPlaying = 0; |
423 | 419 | } |
... | ... | @@ -425,14 +421,14 @@ static void coreaudio_fini_out (HWVoiceOut *hw) |
425 | 421 | /* remove callback */ |
426 | 422 | status = AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); |
427 | 423 | if (status != kAudioHardwareNoError) { |
428 | - coreaudio_logerr (status, "Can not remove IOProc\n"); | |
424 | + coreaudio_logerr (status, "Could not remove IOProc\n"); | |
429 | 425 | } |
430 | 426 | core->outputDeviceID = kAudioDeviceUnknown; |
431 | 427 | |
432 | 428 | /* destroy mutex */ |
433 | 429 | err = pthread_mutex_destroy(&core->mutex); |
434 | 430 | if (err) { |
435 | - dolog("Can not destroy mutex\nReason: %s\n", strerror (err)); | |
431 | + dolog("Could not destroy mutex\nReason: %s\n", strerror (err)); | |
436 | 432 | } |
437 | 433 | } |
438 | 434 | |
... | ... | @@ -447,7 +443,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) |
447 | 443 | if (!core->isPlaying) { |
448 | 444 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); |
449 | 445 | if (status != kAudioHardwareNoError) { |
450 | - coreaudio_logerr (status, "Can not unpause playback\n"); | |
446 | + coreaudio_logerr (status, "Could not unpause playback\n"); | |
451 | 447 | } |
452 | 448 | core->isPlaying = 1; |
453 | 449 | } |
... | ... | @@ -458,7 +454,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) |
458 | 454 | if (core->isPlaying) { |
459 | 455 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); |
460 | 456 | if (status != kAudioHardwareNoError) { |
461 | - coreaudio_logerr (status, "Can not pause playback\n"); | |
457 | + coreaudio_logerr (status, "Could not pause playback\n"); | |
462 | 458 | } |
463 | 459 | core->isPlaying = 0; |
464 | 460 | } | ... | ... |
audio/dsound_template.h
... | ... | @@ -47,7 +47,7 @@ static int glue (dsound_unlock_, TYPE) ( |
47 | 47 | |
48 | 48 | hr = glue (IFACE, _Unlock) (buf, p1, blen1, p2, blen2); |
49 | 49 | if (FAILED (hr)) { |
50 | - dsound_logerr (hr, "Can not unlock " NAME "\n"); | |
50 | + dsound_logerr (hr, "Could not unlock " NAME "\n"); | |
51 | 51 | return -1; |
52 | 52 | } |
53 | 53 | |
... | ... | @@ -93,13 +93,13 @@ static int glue (dsound_lock_, TYPE) ( |
93 | 93 | #ifndef DSBTYPE_IN |
94 | 94 | if (hr == DSERR_BUFFERLOST) { |
95 | 95 | if (glue (dsound_restore_, TYPE) (buf)) { |
96 | - dsound_logerr (hr, "Can not lock " NAME "\n"); | |
96 | + dsound_logerr (hr, "Could not lock " NAME "\n"); | |
97 | 97 | goto fail; |
98 | 98 | } |
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | #endif |
102 | - dsound_logerr (hr, "Can not lock " NAME "\n"); | |
102 | + dsound_logerr (hr, "Could not lock " NAME "\n"); | |
103 | 103 | goto fail; |
104 | 104 | } |
105 | 105 | |
... | ... | @@ -158,38 +158,28 @@ static void dsound_fini_out (HWVoiceOut *hw) |
158 | 158 | if (ds->FIELD) { |
159 | 159 | hr = glue (IFACE, _Stop) (ds->FIELD); |
160 | 160 | if (FAILED (hr)) { |
161 | - dsound_logerr (hr, "Can not stop " NAME "\n"); | |
161 | + dsound_logerr (hr, "Could not stop " NAME "\n"); | |
162 | 162 | } |
163 | 163 | |
164 | 164 | hr = glue (IFACE, _Release) (ds->FIELD); |
165 | 165 | if (FAILED (hr)) { |
166 | - dsound_logerr (hr, "Can not release " NAME "\n"); | |
166 | + dsound_logerr (hr, "Could not release " NAME "\n"); | |
167 | 167 | } |
168 | 168 | ds->FIELD = NULL; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | #ifdef DSBTYPE_IN |
173 | -static int dsound_init_in ( | |
174 | - HWVoiceIn *hw, | |
175 | - int freq, | |
176 | - int nchannels, | |
177 | - audfmt_e fmt | |
178 | - ) | |
173 | +static int dsound_init_in (HWVoiceIn *hw, audsettings_t *as) | |
179 | 174 | #else |
180 | -static int dsound_init_out ( | |
181 | - HWVoiceOut *hw, | |
182 | - int freq, | |
183 | - int nchannels, | |
184 | - audfmt_e fmt | |
185 | - ) | |
175 | +static int dsound_init_out (HWVoiceOut *hw, audsettings_t *as) | |
186 | 176 | #endif |
187 | 177 | { |
188 | 178 | int err; |
189 | 179 | HRESULT hr; |
190 | 180 | dsound *s = &glob_dsound; |
191 | 181 | WAVEFORMATEX wfx; |
192 | - struct full_fmt full_fmt; | |
182 | + audsettings_t obt_as; | |
193 | 183 | #ifdef DSBTYPE_IN |
194 | 184 | const char *typ = "ADC"; |
195 | 185 | DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; |
... | ... | @@ -202,10 +192,7 @@ static int dsound_init_out ( |
202 | 192 | DSBCAPS bc; |
203 | 193 | #endif |
204 | 194 | |
205 | - full_fmt.freq = freq; | |
206 | - full_fmt.nchannels = nchannels; | |
207 | - full_fmt.fmt = fmt; | |
208 | - err = waveformat_from_full_fmt (&wfx, &full_fmt); | |
195 | + err = waveformat_from_audio_settings (&wfx, as); | |
209 | 196 | if (err) { |
210 | 197 | return -1; |
211 | 198 | } |
... | ... | @@ -233,18 +220,13 @@ static int dsound_init_out ( |
233 | 220 | #endif |
234 | 221 | |
235 | 222 | if (FAILED (hr)) { |
236 | - dsound_logerr2 (hr, typ, "Can not create " NAME "\n"); | |
223 | + dsound_logerr2 (hr, typ, "Could not create " NAME "\n"); | |
237 | 224 | return -1; |
238 | 225 | } |
239 | 226 | |
240 | - hr = glue (IFACE, _GetFormat) ( | |
241 | - ds->FIELD, | |
242 | - &wfx, | |
243 | - sizeof (wfx), | |
244 | - NULL | |
245 | - ); | |
227 | + hr = glue (IFACE, _GetFormat) (ds->FIELD, &wfx, sizeof (wfx), NULL); | |
246 | 228 | if (FAILED (hr)) { |
247 | - dsound_logerr2 (hr, typ, "Can not get " NAME " format\n"); | |
229 | + dsound_logerr2 (hr, typ, "Could not get " NAME " format\n"); | |
248 | 230 | goto fail0; |
249 | 231 | } |
250 | 232 | |
... | ... | @@ -258,31 +240,33 @@ static int dsound_init_out ( |
258 | 240 | |
259 | 241 | hr = glue (IFACE, _GetCaps) (ds->FIELD, &bc); |
260 | 242 | if (FAILED (hr)) { |
261 | - dsound_logerr2 (hr, typ, "Can not get " NAME " format\n"); | |
243 | + dsound_logerr2 (hr, typ, "Could not get " NAME " format\n"); | |
262 | 244 | goto fail0; |
263 | 245 | } |
264 | 246 | |
265 | - err = waveformat_to_full_fmt (&wfx, &full_fmt); | |
247 | + err = waveformat_to_audio_settings (&wfx, &obt_as); | |
266 | 248 | if (err) { |
267 | 249 | goto fail0; |
268 | 250 | } |
269 | 251 | |
270 | 252 | ds->first_time = 1; |
271 | - hw->bufsize = bc.dwBufferBytes; | |
272 | - audio_pcm_init_info ( | |
273 | - &hw->info, | |
274 | - full_fmt.freq, | |
275 | - full_fmt.nchannels, | |
276 | - full_fmt.fmt, | |
277 | - audio_need_to_swap_endian (0) | |
278 | - ); | |
253 | + | |
254 | + audio_pcm_init_info (&hw->info, &obt_as, audio_need_to_swap_endian (0)); | |
255 | + | |
256 | + if (bc.dwBufferBytes & hw->info.align) { | |
257 | + dolog ( | |
258 | + "GetCaps returned misaligned buffer size %ld, alignment %d\n", | |
259 | + bc.dwBufferBytes, hw->info.align + 1 | |
260 | + ); | |
261 | + } | |
262 | + hw->samples = bc.dwBufferBytes >> hw->info.shift; | |
279 | 263 | |
280 | 264 | #ifdef DEBUG_DSOUND |
281 | 265 | dolog ("caps %ld, desc %ld\n", |
282 | 266 | bc.dwBufferBytes, bd.dwBufferBytes); |
283 | 267 | |
284 | 268 | dolog ("bufsize %d, freq %d, chan %d, fmt %d\n", |
285 | - hw->bufsize, full_fmt.freq, full_fmt.nchannels, full_fmt.fmt); | |
269 | + hw->bufsize, settings.freq, settings.nchannels, settings.fmt); | |
286 | 270 | #endif |
287 | 271 | return 0; |
288 | 272 | ... | ... |
audio/dsoundaudio.c
... | ... | @@ -37,12 +37,6 @@ |
37 | 37 | |
38 | 38 | /* #define DEBUG_DSOUND */ |
39 | 39 | |
40 | -struct full_fmt { | |
41 | - int freq; | |
42 | - int nchannels; | |
43 | - audfmt_e fmt; | |
44 | -}; | |
45 | - | |
46 | 40 | static struct { |
47 | 41 | int lock_retries; |
48 | 42 | int restore_retries; |
... | ... | @@ -50,7 +44,7 @@ static struct { |
50 | 44 | int set_primary; |
51 | 45 | int bufsize_in; |
52 | 46 | int bufsize_out; |
53 | - struct full_fmt full_fmt; | |
47 | + audsettings_t settings; | |
54 | 48 | int latency_millis; |
55 | 49 | } conf = { |
56 | 50 | 1, |
... | ... | @@ -71,7 +65,7 @@ typedef struct { |
71 | 65 | LPDIRECTSOUND dsound; |
72 | 66 | LPDIRECTSOUNDCAPTURE dsound_capture; |
73 | 67 | LPDIRECTSOUNDBUFFER dsound_primary_buffer; |
74 | - struct full_fmt fmt; | |
68 | + audsettings_t settings; | |
75 | 69 | } dsound; |
76 | 70 | |
77 | 71 | static dsound glob_dsound; |
... | ... | @@ -259,7 +253,7 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( |
259 | 253 | { |
260 | 254 | va_list ap; |
261 | 255 | |
262 | - AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); | |
256 | + AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); | |
263 | 257 | va_start (ap, fmt); |
264 | 258 | AUD_vlog (AUDIO_CAP, fmt, ap); |
265 | 259 | va_end (ap); |
... | ... | @@ -301,7 +295,7 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) |
301 | 295 | continue; |
302 | 296 | |
303 | 297 | default: |
304 | - dsound_logerr (hr, "Can not restore playback buffer\n"); | |
298 | + dsound_logerr (hr, "Could not restore playback buffer\n"); | |
305 | 299 | return -1; |
306 | 300 | } |
307 | 301 | } |
... | ... | @@ -310,19 +304,18 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) |
310 | 304 | return -1; |
311 | 305 | } |
312 | 306 | |
313 | -static int waveformat_from_full_fmt (WAVEFORMATEX *wfx, | |
314 | - struct full_fmt *full_fmt) | |
307 | +static int waveformat_from_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as) | |
315 | 308 | { |
316 | 309 | memset (wfx, 0, sizeof (*wfx)); |
317 | 310 | |
318 | 311 | wfx->wFormatTag = WAVE_FORMAT_PCM; |
319 | - wfx->nChannels = full_fmt->nchannels; | |
320 | - wfx->nSamplesPerSec = full_fmt->freq; | |
321 | - wfx->nAvgBytesPerSec = full_fmt->freq << (full_fmt->nchannels == 2); | |
322 | - wfx->nBlockAlign = 1 << (full_fmt->nchannels == 2); | |
312 | + wfx->nChannels = as->nchannels; | |
313 | + wfx->nSamplesPerSec = as->freq; | |
314 | + wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2); | |
315 | + wfx->nBlockAlign = 1 << (as->nchannels == 2); | |
323 | 316 | wfx->cbSize = 0; |
324 | 317 | |
325 | - switch (full_fmt->fmt) { | |
318 | + switch (as->fmt) { | |
326 | 319 | case AUD_FMT_S8: |
327 | 320 | wfx->wBitsPerSample = 8; |
328 | 321 | break; |
... | ... | @@ -344,16 +337,14 @@ static int waveformat_from_full_fmt (WAVEFORMATEX *wfx, |
344 | 337 | break; |
345 | 338 | |
346 | 339 | default: |
347 | - dolog ("Internal logic error: Bad audio format %d\n", | |
348 | - full_fmt->freq); | |
340 | + dolog ("Internal logic error: Bad audio format %d\n", as->freq); | |
349 | 341 | return -1; |
350 | 342 | } |
351 | 343 | |
352 | 344 | return 0; |
353 | 345 | } |
354 | 346 | |
355 | -static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, | |
356 | - struct full_fmt *full_fmt) | |
347 | +static int waveformat_to_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as) | |
357 | 348 | { |
358 | 349 | if (wfx->wFormatTag != WAVE_FORMAT_PCM) { |
359 | 350 | dolog ("Invalid wave format, tag is not PCM, but %d\n", |
... | ... | @@ -365,15 +356,15 @@ static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, |
365 | 356 | dolog ("Invalid wave format, frequency is zero\n"); |
366 | 357 | return -1; |
367 | 358 | } |
368 | - full_fmt->freq = wfx->nSamplesPerSec; | |
359 | + as->freq = wfx->nSamplesPerSec; | |
369 | 360 | |
370 | 361 | switch (wfx->nChannels) { |
371 | 362 | case 1: |
372 | - full_fmt->nchannels = 1; | |
363 | + as->nchannels = 1; | |
373 | 364 | break; |
374 | 365 | |
375 | 366 | case 2: |
376 | - full_fmt->nchannels = 2; | |
367 | + as->nchannels = 2; | |
377 | 368 | break; |
378 | 369 | |
379 | 370 | default: |
... | ... | @@ -386,11 +377,11 @@ static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, |
386 | 377 | |
387 | 378 | switch (wfx->wBitsPerSample) { |
388 | 379 | case 8: |
389 | - full_fmt->fmt = AUD_FMT_U8; | |
380 | + as->fmt = AUD_FMT_U8; | |
390 | 381 | break; |
391 | 382 | |
392 | 383 | case 16: |
393 | - full_fmt->fmt = AUD_FMT_S16; | |
384 | + as->fmt = AUD_FMT_S16; | |
394 | 385 | break; |
395 | 386 | |
396 | 387 | default: |
... | ... | @@ -415,7 +406,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp) |
415 | 406 | for (i = 0; i < conf.getstatus_retries; ++i) { |
416 | 407 | hr = IDirectSoundBuffer_GetStatus (dsb, statusp); |
417 | 408 | if (FAILED (hr)) { |
418 | - dsound_logerr (hr, "Can not get playback buffer status\n"); | |
409 | + dsound_logerr (hr, "Could not get playback buffer status\n"); | |
419 | 410 | return -1; |
420 | 411 | } |
421 | 412 | |
... | ... | @@ -438,7 +429,7 @@ static int dsound_get_status_in (LPDIRECTSOUNDCAPTUREBUFFER dscb, |
438 | 429 | |
439 | 430 | hr = IDirectSoundCaptureBuffer_GetStatus (dscb, statusp); |
440 | 431 | if (FAILED (hr)) { |
441 | - dsound_logerr (hr, "Can not get capture buffer status\n"); | |
432 | + dsound_logerr (hr, "Could not get capture buffer status\n"); | |
442 | 433 | return -1; |
443 | 434 | } |
444 | 435 | |
... | ... | @@ -520,7 +511,7 @@ static void dsound_close (dsound *s) |
520 | 511 | if (s->dsound_primary_buffer) { |
521 | 512 | hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer); |
522 | 513 | if (FAILED (hr)) { |
523 | - dsound_logerr (hr, "Can not release primary buffer\n"); | |
514 | + dsound_logerr (hr, "Could not release primary buffer\n"); | |
524 | 515 | } |
525 | 516 | s->dsound_primary_buffer = NULL; |
526 | 517 | } |
... | ... | @@ -542,7 +533,7 @@ static int dsound_open (dsound *s) |
542 | 533 | ); |
543 | 534 | |
544 | 535 | if (FAILED (hr)) { |
545 | - dsound_logerr (hr, "Can not set cooperative level for window %p\n", | |
536 | + dsound_logerr (hr, "Could not set cooperative level for window %p\n", | |
546 | 537 | hwnd); |
547 | 538 | return -1; |
548 | 539 | } |
... | ... | @@ -551,7 +542,7 @@ static int dsound_open (dsound *s) |
551 | 542 | return 0; |
552 | 543 | } |
553 | 544 | |
554 | - err = waveformat_from_full_fmt (&wfx, &conf.full_fmt); | |
545 | + err = waveformat_from_audio_settings (&wfx, &conf.settings); | |
555 | 546 | if (err) { |
556 | 547 | return -1; |
557 | 548 | } |
... | ... | @@ -569,13 +560,13 @@ static int dsound_open (dsound *s) |
569 | 560 | NULL |
570 | 561 | ); |
571 | 562 | if (FAILED (hr)) { |
572 | - dsound_logerr (hr, "Can not create primary playback buffer\n"); | |
563 | + dsound_logerr (hr, "Could not create primary playback buffer\n"); | |
573 | 564 | return -1; |
574 | 565 | } |
575 | 566 | |
576 | 567 | hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx); |
577 | 568 | if (FAILED (hr)) { |
578 | - dsound_logerr (hr, "Can not set primary playback buffer format\n"); | |
569 | + dsound_logerr (hr, "Could not set primary playback buffer format\n"); | |
579 | 570 | } |
580 | 571 | |
581 | 572 | hr = IDirectSoundBuffer_GetFormat ( |
... | ... | @@ -585,7 +576,7 @@ static int dsound_open (dsound *s) |
585 | 576 | NULL |
586 | 577 | ); |
587 | 578 | if (FAILED (hr)) { |
588 | - dsound_logerr (hr, "Can not get primary playback buffer format\n"); | |
579 | + dsound_logerr (hr, "Could not get primary playback buffer format\n"); | |
589 | 580 | goto fail0; |
590 | 581 | } |
591 | 582 | |
... | ... | @@ -594,7 +585,7 @@ static int dsound_open (dsound *s) |
594 | 585 | print_wave_format (&wfx); |
595 | 586 | #endif |
596 | 587 | |
597 | - err = waveformat_to_full_fmt (&wfx, &s->fmt); | |
588 | + err = waveformat_to_audio_settings (&wfx, &s->settings); | |
598 | 589 | if (err) { |
599 | 590 | goto fail0; |
600 | 591 | } |
... | ... | @@ -625,7 +616,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) |
625 | 616 | } |
626 | 617 | |
627 | 618 | if (status & DSBSTATUS_PLAYING) { |
628 | - dolog ("warning: voice is already playing\n"); | |
619 | + dolog ("warning: Voice is already playing\n"); | |
629 | 620 | return 0; |
630 | 621 | } |
631 | 622 | |
... | ... | @@ -633,7 +624,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) |
633 | 624 | |
634 | 625 | hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING); |
635 | 626 | if (FAILED (hr)) { |
636 | - dsound_logerr (hr, "Can not start playing buffer\n"); | |
627 | + dsound_logerr (hr, "Could not start playing buffer\n"); | |
637 | 628 | return -1; |
638 | 629 | } |
639 | 630 | break; |
... | ... | @@ -646,12 +637,12 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) |
646 | 637 | if (status & DSBSTATUS_PLAYING) { |
647 | 638 | hr = IDirectSoundBuffer_Stop (dsb); |
648 | 639 | if (FAILED (hr)) { |
649 | - dsound_logerr (hr, "Can not stop playing buffer\n"); | |
640 | + dsound_logerr (hr, "Could not stop playing buffer\n"); | |
650 | 641 | return -1; |
651 | 642 | } |
652 | 643 | } |
653 | 644 | else { |
654 | - dolog ("warning: voice is not playing\n"); | |
645 | + dolog ("warning: Voice is not playing\n"); | |
655 | 646 | } |
656 | 647 | break; |
657 | 648 | } |
... | ... | @@ -675,6 +666,7 @@ static int dsound_run_out (HWVoiceOut *hw) |
675 | 666 | DWORD decr; |
676 | 667 | DWORD wpos, ppos, old_pos; |
677 | 668 | LPVOID p1, p2; |
669 | + int bufsize; | |
678 | 670 | |
679 | 671 | if (!dsb) { |
680 | 672 | dolog ("Attempt to run empty with playback buffer\n"); |
... | ... | @@ -682,6 +674,7 @@ static int dsound_run_out (HWVoiceOut *hw) |
682 | 674 | } |
683 | 675 | |
684 | 676 | hwshift = hw->info.shift; |
677 | + bufsize = hw->samples << hwshift; | |
685 | 678 | |
686 | 679 | live = audio_pcm_hw_get_live_out (hw); |
687 | 680 | |
... | ... | @@ -691,7 +684,7 @@ static int dsound_run_out (HWVoiceOut *hw) |
691 | 684 | ds->first_time ? &wpos : NULL |
692 | 685 | ); |
693 | 686 | if (FAILED (hr)) { |
694 | - dsound_logerr (hr, "Can not get playback buffer position\n"); | |
687 | + dsound_logerr (hr, "Could not get playback buffer position\n"); | |
695 | 688 | return 0; |
696 | 689 | } |
697 | 690 | |
... | ... | @@ -699,13 +692,14 @@ static int dsound_run_out (HWVoiceOut *hw) |
699 | 692 | |
700 | 693 | if (ds->first_time) { |
701 | 694 | if (conf.latency_millis) { |
702 | - DWORD cur_blat = audio_ring_dist (wpos, ppos, hw->bufsize); | |
695 | + DWORD cur_blat; | |
703 | 696 | |
697 | + cur_blat = audio_ring_dist (wpos, ppos, bufsize); | |
704 | 698 | ds->first_time = 0; |
705 | 699 | old_pos = wpos; |
706 | 700 | old_pos += |
707 | 701 | millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat; |
708 | - old_pos %= hw->bufsize; | |
702 | + old_pos %= bufsize; | |
709 | 703 | old_pos &= ~hw->info.align; |
710 | 704 | } |
711 | 705 | else { |
... | ... | @@ -734,14 +728,14 @@ static int dsound_run_out (HWVoiceOut *hw) |
734 | 728 | len = ppos - old_pos; |
735 | 729 | } |
736 | 730 | else { |
737 | - if ((old_pos > ppos) && ((old_pos + len) > (ppos + hw->bufsize))) { | |
738 | - len = hw->bufsize - old_pos + ppos; | |
731 | + if ((old_pos > ppos) && ((old_pos + len) > (ppos + bufsize))) { | |
732 | + len = bufsize - old_pos + ppos; | |
739 | 733 | } |
740 | 734 | } |
741 | 735 | |
742 | - if (audio_bug (AUDIO_FUNC, len < 0 || len > hw->bufsize)) { | |
743 | - dolog ("len=%d hw->bufsize=%d old_pos=%ld ppos=%ld\n", | |
744 | - len, hw->bufsize, old_pos, ppos); | |
736 | + if (audio_bug (AUDIO_FUNC, len < 0 || len > bufsize)) { | |
737 | + dolog ("len=%d bufsize=%d old_pos=%ld ppos=%ld\n", | |
738 | + len, bufsize, old_pos, ppos); | |
745 | 739 | return 0; |
746 | 740 | } |
747 | 741 | |
... | ... | @@ -779,7 +773,7 @@ static int dsound_run_out (HWVoiceOut *hw) |
779 | 773 | } |
780 | 774 | |
781 | 775 | dsound_unlock_out (dsb, p1, p2, blen1, blen2); |
782 | - ds->old_pos = (old_pos + (decr << hwshift)) % hw->bufsize; | |
776 | + ds->old_pos = (old_pos + (decr << hwshift)) % bufsize; | |
783 | 777 | |
784 | 778 | #ifdef DEBUG_DSOUND |
785 | 779 | ds->mixed += decr << hwshift; |
... | ... | @@ -812,7 +806,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) |
812 | 806 | } |
813 | 807 | |
814 | 808 | if (status & DSCBSTATUS_CAPTURING) { |
815 | - dolog ("warning: voice is already capturing\n"); | |
809 | + dolog ("warning: Voice is already capturing\n"); | |
816 | 810 | return 0; |
817 | 811 | } |
818 | 812 | |
... | ... | @@ -820,7 +814,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) |
820 | 814 | |
821 | 815 | hr = IDirectSoundCaptureBuffer_Start (dscb, DSCBSTART_LOOPING); |
822 | 816 | if (FAILED (hr)) { |
823 | - dsound_logerr (hr, "Can not start capturing\n"); | |
817 | + dsound_logerr (hr, "Could not start capturing\n"); | |
824 | 818 | return -1; |
825 | 819 | } |
826 | 820 | break; |
... | ... | @@ -833,12 +827,12 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) |
833 | 827 | if (status & DSCBSTATUS_CAPTURING) { |
834 | 828 | hr = IDirectSoundCaptureBuffer_Stop (dscb); |
835 | 829 | if (FAILED (hr)) { |
836 | - dsound_logerr (hr, "Can not stop capturing\n"); | |
830 | + dsound_logerr (hr, "Could not stop capturing\n"); | |
837 | 831 | return -1; |
838 | 832 | } |
839 | 833 | } |
840 | 834 | else { |
841 | - dolog ("warning: voice is not capturing\n"); | |
835 | + dolog ("warning: Voice is not capturing\n"); | |
842 | 836 | } |
843 | 837 | break; |
844 | 838 | } |
... | ... | @@ -883,21 +877,21 @@ static int dsound_run_in (HWVoiceIn *hw) |
883 | 877 | ds->first_time ? &rpos : NULL |
884 | 878 | ); |
885 | 879 | if (FAILED (hr)) { |
886 | - dsound_logerr (hr, "Can not get capture buffer position\n"); | |
880 | + dsound_logerr (hr, "Could not get capture buffer position\n"); | |
887 | 881 | return 0; |
888 | 882 | } |
889 | 883 | |
890 | 884 | if (ds->first_time) { |
891 | 885 | ds->first_time = 0; |
892 | 886 | if (rpos & hw->info.align) { |
893 | - ldebug ("warning: misaligned capture read position %ld(%d)\n", | |
887 | + ldebug ("warning: Misaligned capture read position %ld(%d)\n", | |
894 | 888 | rpos, hw->info.align); |
895 | 889 | } |
896 | 890 | hw->wpos = rpos >> hwshift; |
897 | 891 | } |
898 | 892 | |
899 | 893 | if (cpos & hw->info.align) { |
900 | - ldebug ("warning: misaligned capture position %ld(%d)\n", | |
894 | + ldebug ("warning: Misaligned capture position %ld(%d)\n", | |
901 | 895 | cpos, hw->info.align); |
902 | 896 | } |
903 | 897 | cpos >>= hwshift; |
... | ... | @@ -951,7 +945,7 @@ static void dsound_audio_fini (void *opaque) |
951 | 945 | |
952 | 946 | hr = IDirectSound_Release (s->dsound); |
953 | 947 | if (FAILED (hr)) { |
954 | - dsound_logerr (hr, "Can not release DirectSound\n"); | |
948 | + dsound_logerr (hr, "Could not release DirectSound\n"); | |
955 | 949 | } |
956 | 950 | s->dsound = NULL; |
957 | 951 | |
... | ... | @@ -961,7 +955,7 @@ static void dsound_audio_fini (void *opaque) |
961 | 955 | |
962 | 956 | hr = IDirectSoundCapture_Release (s->dsound_capture); |
963 | 957 | if (FAILED (hr)) { |
964 | - dsound_logerr (hr, "Can not release DirectSoundCapture\n"); | |
958 | + dsound_logerr (hr, "Could not release DirectSoundCapture\n"); | |
965 | 959 | } |
966 | 960 | s->dsound_capture = NULL; |
967 | 961 | } |
... | ... | @@ -974,7 +968,7 @@ static void *dsound_audio_init (void) |
974 | 968 | |
975 | 969 | hr = CoInitialize (NULL); |
976 | 970 | if (FAILED (hr)) { |
977 | - dsound_logerr (hr, "Can not initialize COM\n"); | |
971 | + dsound_logerr (hr, "Could not initialize COM\n"); | |
978 | 972 | return NULL; |
979 | 973 | } |
980 | 974 | |
... | ... | @@ -986,13 +980,13 @@ static void *dsound_audio_init (void) |
986 | 980 | (void **) &s->dsound |
987 | 981 | ); |
988 | 982 | if (FAILED (hr)) { |
989 | - dsound_logerr (hr, "Can not create DirectSound instance\n"); | |
983 | + dsound_logerr (hr, "Could not create DirectSound instance\n"); | |
990 | 984 | return NULL; |
991 | 985 | } |
992 | 986 | |
993 | 987 | hr = IDirectSound_Initialize (s->dsound, NULL); |
994 | 988 | if (FAILED (hr)) { |
995 | - dsound_logerr (hr, "Can not initialize DirectSound\n"); | |
989 | + dsound_logerr (hr, "Could not initialize DirectSound\n"); | |
996 | 990 | return NULL; |
997 | 991 | } |
998 | 992 | |
... | ... | @@ -1004,16 +998,16 @@ static void *dsound_audio_init (void) |
1004 | 998 | (void **) &s->dsound_capture |
1005 | 999 | ); |
1006 | 1000 | if (FAILED (hr)) { |
1007 | - dsound_logerr (hr, "Can not create DirectSoundCapture instance\n"); | |
1001 | + dsound_logerr (hr, "Could not create DirectSoundCapture instance\n"); | |
1008 | 1002 | } |
1009 | 1003 | else { |
1010 | 1004 | hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL); |
1011 | 1005 | if (FAILED (hr)) { |
1012 | - dsound_logerr (hr, "Can not initialize DirectSoundCapture\n"); | |
1006 | + dsound_logerr (hr, "Could not initialize DirectSoundCapture\n"); | |
1013 | 1007 | |
1014 | 1008 | hr = IDirectSoundCapture_Release (s->dsound_capture); |
1015 | 1009 | if (FAILED (hr)) { |
1016 | - dsound_logerr (hr, "Can not release DirectSoundCapture\n"); | |
1010 | + dsound_logerr (hr, "Could not release DirectSoundCapture\n"); | |
1017 | 1011 | } |
1018 | 1012 | s->dsound_capture = NULL; |
1019 | 1013 | } |
... | ... | @@ -1039,11 +1033,11 @@ static struct audio_option dsound_options[] = { |
1039 | 1033 | "Set the parameters of primary buffer", NULL, 0}, |
1040 | 1034 | {"LATENCY_MILLIS", AUD_OPT_INT, &conf.latency_millis, |
1041 | 1035 | "(undocumented)", NULL, 0}, |
1042 | - {"PRIMARY_FREQ", AUD_OPT_INT, &conf.full_fmt.freq, | |
1036 | + {"PRIMARY_FREQ", AUD_OPT_INT, &conf.settings.freq, | |
1043 | 1037 | "Primary buffer frequency", NULL, 0}, |
1044 | - {"PRIMARY_CHANNELS", AUD_OPT_INT, &conf.full_fmt.nchannels, | |
1038 | + {"PRIMARY_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels, | |
1045 | 1039 | "Primary buffer number of channels (1 - mono, 2 - stereo)", NULL, 0}, |
1046 | - {"PRIMARY_FMT", AUD_OPT_FMT, &conf.full_fmt.fmt, | |
1040 | + {"PRIMARY_FMT", AUD_OPT_FMT, &conf.settings.fmt, | |
1047 | 1041 | "Primary buffer format", NULL, 0}, |
1048 | 1042 | {"BUFSIZE_OUT", AUD_OPT_INT, &conf.bufsize_out, |
1049 | 1043 | "(undocumented)", NULL, 0}, | ... | ... |
audio/fmodaudio.c
... | ... | @@ -78,7 +78,7 @@ static void GCC_FMT_ATTR (2, 3) fmod_logerr2 ( |
78 | 78 | { |
79 | 79 | va_list ap; |
80 | 80 | |
81 | - AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); | |
81 | + AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); | |
82 | 82 | |
83 | 83 | va_start (ap, fmt); |
84 | 84 | AUD_vlog (AUDIO_CAP, fmt, ap); |
... | ... | @@ -356,17 +356,17 @@ static void fmod_fini_out (HWVoiceOut *hw) |
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
359 | -static int fmod_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | |
359 | +static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as) | |
360 | 360 | { |
361 | 361 | int bits16, mode, channel; |
362 | 362 | FMODVoiceOut *fmd = (FMODVoiceOut *) hw; |
363 | 363 | |
364 | - mode = aud_to_fmodfmt (fmt, nchannels == 2 ? 1 : 0); | |
364 | + mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0); | |
365 | 365 | fmd->fmod_sample = FSOUND_Sample_Alloc ( |
366 | 366 | FSOUND_FREE, /* index */ |
367 | 367 | conf.nb_samples, /* length */ |
368 | 368 | mode, /* mode */ |
369 | - freq, /* freq */ | |
369 | + as->freq, /* freq */ | |
370 | 370 | 255, /* volume */ |
371 | 371 | 128, /* pan */ |
372 | 372 | 255 /* priority */ |
... | ... | @@ -386,10 +386,9 @@ static int fmod_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
386 | 386 | fmd->channel = channel; |
387 | 387 | |
388 | 388 | /* FMOD always operates on little endian frames? */ |
389 | - audio_pcm_init_info (&hw->info, freq, nchannels, fmt, | |
390 | - audio_need_to_swap_endian (0)); | |
389 | + audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0)); | |
391 | 390 | bits16 = (mode & FSOUND_16BITS) != 0; |
392 | - hw->bufsize = conf.nb_samples << (nchannels == 2) << bits16; | |
391 | + hw->samples = conf.nb_samples; | |
393 | 392 | return 0; |
394 | 393 | } |
395 | 394 | |
... | ... | @@ -417,7 +416,7 @@ static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...) |
417 | 416 | return 0; |
418 | 417 | } |
419 | 418 | |
420 | -static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | |
419 | +static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as) | |
421 | 420 | { |
422 | 421 | int bits16, mode; |
423 | 422 | FMODVoiceIn *fmd = (FMODVoiceIn *) hw; |
... | ... | @@ -426,12 +425,12 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) |
426 | 425 | return -1; |
427 | 426 | } |
428 | 427 | |
429 | - mode = aud_to_fmodfmt (fmt, nchannels == 2 ? 1 : 0); | |
428 | + mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0); | |
430 | 429 | fmd->fmod_sample = FSOUND_Sample_Alloc ( |
431 | 430 | FSOUND_FREE, /* index */ |
432 | 431 | conf.nb_samples, /* length */ |
433 | 432 | mode, /* mode */ |
434 | - freq, /* freq */ | |
433 | + as->freq, /* freq */ | |
435 | 434 | 255, /* volume */ |
436 | 435 | 128, /* pan */ |
437 | 436 | 255 /* priority */ |
... | ... | @@ -443,10 +442,9 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) |
443 | 442 | } |
444 | 443 | |
445 | 444 | /* FMOD always operates on little endian frames? */ |
446 | - audio_pcm_init_info (&hw->info, freq, nchannels, fmt, | |
447 | - audio_need_to_swap_endian (0)); | |
445 | + audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0)); | |
448 | 446 | bits16 = (mode & FSOUND_16BITS) != 0; |
449 | - hw->bufsize = conf.nb_samples << (nchannels == 2) << bits16; | |
447 | + hw->samples = conf.nb_samples; | |
450 | 448 | return 0; |
451 | 449 | } |
452 | 450 | |
... | ... | @@ -479,7 +477,7 @@ static int fmod_run_in (HWVoiceIn *hw) |
479 | 477 | |
480 | 478 | new_pos = FSOUND_Record_GetPosition (); |
481 | 479 | if (new_pos < 0) { |
482 | - fmod_logerr ("Can not get recording position\n"); | |
480 | + fmod_logerr ("Could not get recording position\n"); | |
483 | 481 | return 0; |
484 | 482 | } |
485 | 483 | ... | ... |
audio/mixeng.c
... | ... | @@ -228,21 +228,22 @@ f_sample *mixeng_clip[2][2][2][2] = { |
228 | 228 | */ |
229 | 229 | |
230 | 230 | /* Private data */ |
231 | -typedef struct ratestuff { | |
231 | +struct rate { | |
232 | 232 | uint64_t opos; |
233 | 233 | uint64_t opos_inc; |
234 | 234 | uint32_t ipos; /* position in the input stream (integer) */ |
235 | 235 | st_sample_t ilast; /* last sample in the input stream */ |
236 | -} *rate_t; | |
236 | +}; | |
237 | 237 | |
238 | 238 | /* |
239 | 239 | * Prepare processing. |
240 | 240 | */ |
241 | 241 | void *st_rate_start (int inrate, int outrate) |
242 | 242 | { |
243 | - rate_t rate = (rate_t) qemu_mallocz (sizeof (struct ratestuff)); | |
243 | + struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate)); | |
244 | 244 | |
245 | 245 | if (!rate) { |
246 | + dolog ("Could not allocate resampler (%d bytes)\n", sizeof (*rate)); | |
246 | 247 | return NULL; |
247 | 248 | } |
248 | 249 | ... | ... |
audio/noaudio.c
... | ... | @@ -67,11 +67,10 @@ static int no_write (SWVoiceOut *sw, void *buf, int len) |
67 | 67 | return audio_pcm_sw_write (sw, buf, len); |
68 | 68 | } |
69 | 69 | |
70 | -static int no_init_out (HWVoiceOut *hw, int freq, | |
71 | - int nchannels, audfmt_e fmt) | |
70 | +static int no_init_out (HWVoiceOut *hw, audsettings_t *as) | |
72 | 71 | { |
73 | - audio_pcm_init_info (&hw->info, freq, nchannels, fmt, 0); | |
74 | - hw->bufsize = 4096; | |
72 | + audio_pcm_init_info (&hw->info, as, 0); | |
73 | + hw->samples = 1024; | |
75 | 74 | return 0; |
76 | 75 | } |
77 | 76 | |
... | ... | @@ -87,11 +86,10 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) |
87 | 86 | return 0; |
88 | 87 | } |
89 | 88 | |
90 | -static int no_init_in (HWVoiceIn *hw, int freq, | |
91 | - int nchannels, audfmt_e fmt) | |
89 | +static int no_init_in (HWVoiceIn *hw, audsettings_t *as) | |
92 | 90 | { |
93 | - audio_pcm_init_info (&hw->info, freq, nchannels, fmt, 0); | |
94 | - hw->bufsize = 4096; | |
91 | + audio_pcm_init_info (&hw->info, as, 0); | |
92 | + hw->samples = 1024; | |
95 | 93 | return 0; |
96 | 94 | } |
97 | 95 | ... | ... |
audio/ossaudio.c
... | ... | @@ -91,7 +91,7 @@ static void GCC_FMT_ATTR (3, 4) oss_logerr2 ( |
91 | 91 | { |
92 | 92 | va_list ap; |
93 | 93 | |
94 | - AUD_log (AUDIO_CAP, "Can not initialize %s\n", typ); | |
94 | + AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ); | |
95 | 95 | |
96 | 96 | va_start (ap, fmt); |
97 | 97 | AUD_vlog (AUDIO_CAP, fmt, ap); |
... | ... | @@ -179,7 +179,7 @@ static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness) |
179 | 179 | return 0; |
180 | 180 | } |
181 | 181 | |
182 | -#ifdef DEBUG_MISMATCHES | |
182 | +#if defined DEBUG_MISMATCHES || defined DEBUG | |
183 | 183 | static void oss_dump_info (struct oss_params *req, struct oss_params *obt) |
184 | 184 | { |
185 | 185 | dolog ("parameter | requested value | obtained value\n"); |
... | ... | @@ -253,16 +253,16 @@ static int oss_open (int in, struct oss_params *req, |
253 | 253 | obt->fragsize = abinfo.fragsize; |
254 | 254 | *pfd = fd; |
255 | 255 | |
256 | +#ifdef DEBUG_MISMATCHES | |
256 | 257 | if ((req->fmt != obt->fmt) || |
257 | 258 | (req->nchannels != obt->nchannels) || |
258 | 259 | (req->freq != obt->freq) || |
259 | 260 | (req->fragsize != obt->fragsize) || |
260 | 261 | (req->nfrags != obt->nfrags)) { |
261 | -#ifdef DEBUG_MISMATCHES | |
262 | 262 | dolog ("Audio parameters mismatch\n"); |
263 | 263 | oss_dump_info (req, obt); |
264 | -#endif | |
265 | 264 | } |
265 | +#endif | |
266 | 266 | |
267 | 267 | #ifdef DEBUG |
268 | 268 | oss_dump_info (req, obt); |
... | ... | @@ -283,12 +283,15 @@ static int oss_run_out (HWVoiceOut *hw) |
283 | 283 | st_sample_t *src; |
284 | 284 | struct audio_buf_info abinfo; |
285 | 285 | struct count_info cntinfo; |
286 | + int bufsize; | |
286 | 287 | |
287 | 288 | live = audio_pcm_hw_get_live_out (hw); |
288 | 289 | if (!live) { |
289 | 290 | return 0; |
290 | 291 | } |
291 | 292 | |
293 | + bufsize = hw->samples << hw->info.shift; | |
294 | + | |
292 | 295 | if (oss->mmapped) { |
293 | 296 | int bytes; |
294 | 297 | |
... | ... | @@ -300,7 +303,7 @@ static int oss_run_out (HWVoiceOut *hw) |
300 | 303 | |
301 | 304 | if (cntinfo.ptr == oss->old_optr) { |
302 | 305 | if (abs (hw->samples - live) < 64) { |
303 | - dolog ("warning: overrun\n"); | |
306 | + dolog ("warning: Overrun\n"); | |
304 | 307 | } |
305 | 308 | return 0; |
306 | 309 | } |
... | ... | @@ -309,7 +312,7 @@ static int oss_run_out (HWVoiceOut *hw) |
309 | 312 | bytes = cntinfo.ptr - oss->old_optr; |
310 | 313 | } |
311 | 314 | else { |
312 | - bytes = hw->bufsize + cntinfo.ptr - oss->old_optr; | |
315 | + bytes = bufsize + cntinfo.ptr - oss->old_optr; | |
313 | 316 | } |
314 | 317 | |
315 | 318 | decr = audio_MIN (bytes >> hw->info.shift, live); |
... | ... | @@ -321,9 +324,9 @@ static int oss_run_out (HWVoiceOut *hw) |
321 | 324 | return 0; |
322 | 325 | } |
323 | 326 | |
324 | - if (abinfo.bytes < 0 || abinfo.bytes > hw->bufsize) { | |
325 | - ldebug ("warning: invalid available size, size=%d bufsize=%d\n", | |
326 | - abinfo.bytes, hw->bufsize); | |
327 | + if (abinfo.bytes < 0 || abinfo.bytes > bufsize) { | |
328 | + ldebug ("warning: Invalid available size, size=%d bufsize=%d\n", | |
329 | + abinfo.bytes, bufsize); | |
327 | 330 | return 0; |
328 | 331 | } |
329 | 332 | |
... | ... | @@ -362,7 +365,7 @@ static int oss_run_out (HWVoiceOut *hw) |
362 | 365 | int wsamples = written >> hw->info.shift; |
363 | 366 | int wbytes = wsamples << hw->info.shift; |
364 | 367 | if (wbytes != written) { |
365 | - dolog ("warning: misaligned write %d (requested %d), " | |
368 | + dolog ("warning: Misaligned write %d (requested %d), " | |
366 | 369 | "alignment %d\n", |
367 | 370 | wbytes, written, hw->info.align + 1); |
368 | 371 | } |
... | ... | @@ -396,10 +399,10 @@ static void oss_fini_out (HWVoiceOut *hw) |
396 | 399 | |
397 | 400 | if (oss->pcm_buf) { |
398 | 401 | if (oss->mmapped) { |
399 | - err = munmap (oss->pcm_buf, hw->bufsize); | |
402 | + err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); | |
400 | 403 | if (err) { |
401 | 404 | oss_logerr (errno, "Failed to unmap buffer %p, size %d\n", |
402 | - oss->pcm_buf, hw->bufsize); | |
405 | + oss->pcm_buf, hw->samples << hw->info.shift); | |
403 | 406 | } |
404 | 407 | } |
405 | 408 | else { |
... | ... | @@ -409,7 +412,7 @@ static void oss_fini_out (HWVoiceOut *hw) |
409 | 412 | } |
410 | 413 | } |
411 | 414 | |
412 | -static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | |
415 | +static int oss_init_out (HWVoiceOut *hw, audsettings_t *as) | |
413 | 416 | { |
414 | 417 | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
415 | 418 | struct oss_params req, obt; |
... | ... | @@ -417,10 +420,11 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
417 | 420 | int err; |
418 | 421 | int fd; |
419 | 422 | audfmt_e effective_fmt; |
423 | + audsettings_t obt_as; | |
420 | 424 | |
421 | - req.fmt = aud_to_ossfmt (fmt); | |
422 | - req.freq = freq; | |
423 | - req.nchannels = nchannels; | |
425 | + req.fmt = aud_to_ossfmt (as->fmt); | |
426 | + req.freq = as->freq; | |
427 | + req.nchannels = as->nchannels; | |
424 | 428 | req.fragsize = conf.fragsize; |
425 | 429 | req.nfrags = conf.nfrags; |
426 | 430 | |
... | ... | @@ -434,24 +438,38 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
434 | 438 | return -1; |
435 | 439 | } |
436 | 440 | |
441 | + obt_as.freq = obt.freq; | |
442 | + obt_as.nchannels = obt.nchannels; | |
443 | + obt_as.fmt = effective_fmt; | |
444 | + | |
437 | 445 | audio_pcm_init_info ( |
438 | 446 | &hw->info, |
439 | - obt.freq, | |
440 | - obt.nchannels, | |
441 | - effective_fmt, | |
447 | + &obt_as, | |
442 | 448 | audio_need_to_swap_endian (endianness) |
443 | 449 | ); |
444 | 450 | oss->nfrags = obt.nfrags; |
445 | 451 | oss->fragsize = obt.fragsize; |
446 | - hw->bufsize = obt.nfrags * obt.fragsize; | |
452 | + | |
453 | + if (obt.nfrags * obt.fragsize & hw->info.align) { | |
454 | + dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n", | |
455 | + obt.nfrags * obt.fragsize, hw->info.align + 1); | |
456 | + } | |
457 | + | |
458 | + hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; | |
447 | 459 | |
448 | 460 | oss->mmapped = 0; |
449 | 461 | if (conf.try_mmap) { |
450 | - oss->pcm_buf = mmap (0, hw->bufsize, PROT_READ | PROT_WRITE, | |
451 | - MAP_SHARED, fd, 0); | |
462 | + oss->pcm_buf = mmap ( | |
463 | + 0, | |
464 | + hw->samples << hw->info.shift, | |
465 | + PROT_READ | PROT_WRITE, | |
466 | + MAP_SHARED, | |
467 | + fd, | |
468 | + 0 | |
469 | + ); | |
452 | 470 | if (oss->pcm_buf == MAP_FAILED) { |
453 | 471 | oss_logerr (errno, "Failed to map %d bytes of DAC\n", |
454 | - hw->bufsize); | |
472 | + hw->samples << hw->info.shift); | |
455 | 473 | } else { |
456 | 474 | int err; |
457 | 475 | int trig = 0; |
... | ... | @@ -472,18 +490,24 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
472 | 490 | } |
473 | 491 | |
474 | 492 | if (!oss->mmapped) { |
475 | - err = munmap (oss->pcm_buf, hw->bufsize); | |
493 | + err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); | |
476 | 494 | if (err) { |
477 | 495 | oss_logerr (errno, "Failed to unmap buffer %p size %d\n", |
478 | - oss->pcm_buf, hw->bufsize); | |
496 | + oss->pcm_buf, hw->samples << hw->info.shift); | |
479 | 497 | } |
480 | 498 | } |
481 | 499 | } |
482 | 500 | } |
483 | 501 | |
484 | 502 | if (!oss->mmapped) { |
485 | - oss->pcm_buf = qemu_mallocz (hw->bufsize); | |
503 | + oss->pcm_buf = audio_calloc ( | |
504 | + AUDIO_FUNC, | |
505 | + hw->samples, | |
506 | + 1 << hw->info.shift | |
507 | + ); | |
486 | 508 | if (!oss->pcm_buf) { |
509 | + dolog ("Could not allocate DAC buffer (%d bytes)\n", | |
510 | + hw->samples << hw->info.shift); | |
487 | 511 | oss_anal_close (&fd); |
488 | 512 | return -1; |
489 | 513 | } |
... | ... | @@ -528,8 +552,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) |
528 | 552 | return 0; |
529 | 553 | } |
530 | 554 | |
531 | -static int oss_init_in (HWVoiceIn *hw, | |
532 | - int freq, int nchannels, audfmt_e fmt) | |
555 | +static int oss_init_in (HWVoiceIn *hw, audsettings_t *as) | |
533 | 556 | { |
534 | 557 | OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
535 | 558 | struct oss_params req, obt; |
... | ... | @@ -537,10 +560,11 @@ static int oss_init_in (HWVoiceIn *hw, |
537 | 560 | int err; |
538 | 561 | int fd; |
539 | 562 | audfmt_e effective_fmt; |
563 | + audsettings_t obt_as; | |
540 | 564 | |
541 | - req.fmt = aud_to_ossfmt (fmt); | |
542 | - req.freq = freq; | |
543 | - req.nchannels = nchannels; | |
565 | + req.fmt = aud_to_ossfmt (as->fmt); | |
566 | + req.freq = as->freq; | |
567 | + req.nchannels = as->nchannels; | |
544 | 568 | req.fragsize = conf.fragsize; |
545 | 569 | req.nfrags = conf.nfrags; |
546 | 570 | if (oss_open (1, &req, &obt, &fd)) { |
... | ... | @@ -553,18 +577,28 @@ static int oss_init_in (HWVoiceIn *hw, |
553 | 577 | return -1; |
554 | 578 | } |
555 | 579 | |
580 | + obt_as.freq = obt.freq; | |
581 | + obt_as.nchannels = obt.nchannels; | |
582 | + obt_as.fmt = effective_fmt; | |
583 | + | |
556 | 584 | audio_pcm_init_info ( |
557 | 585 | &hw->info, |
558 | - obt.freq, | |
559 | - obt.nchannels, | |
560 | - effective_fmt, | |
586 | + &obt_as, | |
561 | 587 | audio_need_to_swap_endian (endianness) |
562 | 588 | ); |
563 | 589 | oss->nfrags = obt.nfrags; |
564 | 590 | oss->fragsize = obt.fragsize; |
565 | - hw->bufsize = obt.nfrags * obt.fragsize; | |
566 | - oss->pcm_buf = qemu_mallocz (hw->bufsize); | |
591 | + | |
592 | + if (obt.nfrags * obt.fragsize & hw->info.align) { | |
593 | + dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n", | |
594 | + obt.nfrags * obt.fragsize, hw->info.align + 1); | |
595 | + } | |
596 | + | |
597 | + hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; | |
598 | + oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); | |
567 | 599 | if (!oss->pcm_buf) { |
600 | + dolog ("Could not allocate ADC buffer (%d bytes)\n", | |
601 | + hw->samples << hw->info.shift); | |
568 | 602 | oss_anal_close (&fd); |
569 | 603 | return -1; |
570 | 604 | } |
... | ... | @@ -623,7 +657,7 @@ static int oss_run_in (HWVoiceIn *hw) |
623 | 657 | |
624 | 658 | if (nread > 0) { |
625 | 659 | if (nread & hw->info.align) { |
626 | - dolog ("warning: misaligned read %d (requested %d), " | |
660 | + dolog ("warning: Misaligned read %d (requested %d), " | |
627 | 661 | "alignment %d\n", nread, bufs[i].add << hwshift, |
628 | 662 | hw->info.align + 1); |
629 | 663 | } | ... | ... |
audio/rate_template.h
... | ... | @@ -30,7 +30,7 @@ |
30 | 30 | void NAME (void *opaque, st_sample_t *ibuf, st_sample_t *obuf, |
31 | 31 | int *isamp, int *osamp) |
32 | 32 | { |
33 | - rate_t rate = (rate_t) opaque; | |
33 | + struct rate *rate = opaque; | |
34 | 34 | st_sample_t *istart, *iend; |
35 | 35 | st_sample_t *ostart, *oend; |
36 | 36 | st_sample_t ilast, icur, out; | ... | ... |
audio/sdlaudio.c
... | ... | @@ -303,7 +303,7 @@ static void sdl_fini_out (HWVoiceOut *hw) |
303 | 303 | sdl_close (&glob_sdl); |
304 | 304 | } |
305 | 305 | |
306 | -static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | |
306 | +static int sdl_init_out (HWVoiceOut *hw, audsettings_t *as) | |
307 | 307 | { |
308 | 308 | SDLVoiceOut *sdl = (SDLVoiceOut *) hw; |
309 | 309 | SDLAudioState *s = &glob_sdl; |
... | ... | @@ -312,18 +312,14 @@ static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
312 | 312 | int endianess; |
313 | 313 | int err; |
314 | 314 | audfmt_e effective_fmt; |
315 | + audsettings_t obt_as; | |
315 | 316 | |
316 | - if (nchannels != 2) { | |
317 | - dolog ("Can not init DAC. Bogus channel count %d\n", nchannels); | |
318 | - return -1; | |
319 | - } | |
317 | + shift <<= as->nchannels == 2; | |
320 | 318 | |
321 | - req.freq = freq; | |
322 | - req.format = aud_to_sdlfmt (fmt, &shift); | |
323 | - req.channels = nchannels; | |
319 | + req.freq = as->freq; | |
320 | + req.format = aud_to_sdlfmt (as->fmt, &shift); | |
321 | + req.channels = as->nchannels; | |
324 | 322 | req.samples = conf.nb_samples; |
325 | - shift <<= nchannels == 2; | |
326 | - | |
327 | 323 | req.callback = sdl_callback; |
328 | 324 | req.userdata = sdl; |
329 | 325 | |
... | ... | @@ -337,14 +333,16 @@ static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
337 | 333 | return -1; |
338 | 334 | } |
339 | 335 | |
336 | + obt_as.freq = obt.freq; | |
337 | + obt_as.nchannels = obt.channels; | |
338 | + obt_as.fmt = effective_fmt; | |
339 | + | |
340 | 340 | audio_pcm_init_info ( |
341 | 341 | &hw->info, |
342 | - obt.freq, | |
343 | - obt.channels, | |
344 | - effective_fmt, | |
342 | + &obt_as, | |
345 | 343 | audio_need_to_swap_endian (endianess) |
346 | 344 | ); |
347 | - hw->bufsize = obt.samples << shift; | |
345 | + hw->samples = obt.samples; | |
348 | 346 | |
349 | 347 | s->initialized = 1; |
350 | 348 | s->exit = 0; | ... | ... |
audio/wavaudio.c
... | ... | @@ -35,9 +35,15 @@ typedef struct WAVVoiceOut { |
35 | 35 | } WAVVoiceOut; |
36 | 36 | |
37 | 37 | static struct { |
38 | + audsettings_t settings; | |
38 | 39 | const char *wav_path; |
39 | 40 | } conf = { |
40 | - .wav_path = "qemu.wav" | |
41 | + { | |
42 | + 44100, | |
43 | + 2, | |
44 | + AUD_FMT_S16 | |
45 | + }, | |
46 | + "qemu.wav" | |
41 | 47 | }; |
42 | 48 | |
43 | 49 | static int wav_run_out (HWVoiceOut *hw) |
... | ... | @@ -101,22 +107,22 @@ static void le_store (uint8_t *buf, uint32_t val, int len) |
101 | 107 | } |
102 | 108 | } |
103 | 109 | |
104 | -static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | |
110 | +static int wav_init_out (HWVoiceOut *hw, audsettings_t *as) | |
105 | 111 | { |
106 | 112 | WAVVoiceOut *wav = (WAVVoiceOut *) hw; |
107 | - int bits16; | |
113 | + int bits16 = 0, stereo = 0; | |
108 | 114 | uint8_t hdr[] = { |
109 | 115 | 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, |
110 | 116 | 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
111 | 117 | 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, |
112 | 118 | 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 |
113 | 119 | }; |
120 | + audsettings_t wav_as = conf.settings; | |
114 | 121 | |
115 | - freq = audio_state.fixed_freq_out; | |
116 | - fmt = audio_state.fixed_fmt_out; | |
117 | - nchannels = audio_state.fixed_channels_out; | |
122 | + (void) as; | |
118 | 123 | |
119 | - switch (fmt) { | |
124 | + stereo = wav_as.nchannels == 2; | |
125 | + switch (wav_as.fmt) { | |
120 | 126 | case AUD_FMT_S8: |
121 | 127 | case AUD_FMT_U8: |
122 | 128 | bits16 = 0; |
... | ... | @@ -126,32 +132,24 @@ static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) |
126 | 132 | case AUD_FMT_U16: |
127 | 133 | bits16 = 1; |
128 | 134 | break; |
129 | - | |
130 | - default: | |
131 | - dolog ("Internal logic error bad format %d\n", fmt); | |
132 | - return -1; | |
133 | 135 | } |
134 | 136 | |
135 | 137 | hdr[34] = bits16 ? 0x10 : 0x08; |
136 | - audio_pcm_init_info ( | |
137 | - &hw->info, | |
138 | - freq, | |
139 | - nchannels, | |
140 | - bits16 ? AUD_FMT_S16 : AUD_FMT_U8, | |
141 | - audio_need_to_swap_endian (0) | |
142 | - ); | |
143 | - hw->bufsize = 4096; | |
144 | - wav->pcm_buf = qemu_mallocz (hw->bufsize); | |
138 | + | |
139 | + audio_pcm_init_info (&hw->info, &wav_as, audio_need_to_swap_endian (0)); | |
140 | + | |
141 | + hw->samples = 1024; | |
142 | + wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); | |
145 | 143 | if (!wav->pcm_buf) { |
146 | - dolog ("Can not initialize WAV buffer of %d bytes\n", | |
147 | - hw->bufsize); | |
144 | + dolog ("Could not allocate buffer (%d bytes)\n", | |
145 | + hw->samples << hw->info.shift); | |
148 | 146 | return -1; |
149 | 147 | } |
150 | 148 | |
151 | 149 | le_store (hdr + 22, hw->info.nchannels, 2); |
152 | 150 | le_store (hdr + 24, hw->info.freq, 4); |
153 | - le_store (hdr + 28, hw->info.freq << (bits16 + (nchannels == 2)), 4); | |
154 | - le_store (hdr + 32, 1 << (bits16 + (nchannels == 2)), 2); | |
151 | + le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4); | |
152 | + le_store (hdr + 32, 1 << (bits16 + stereo), 2); | |
155 | 153 | |
156 | 154 | wav->f = fopen (conf.wav_path, "wb"); |
157 | 155 | if (!wav->f) { |
... | ... | @@ -175,7 +173,7 @@ static void wav_fini_out (HWVoiceOut *hw) |
175 | 173 | uint32_t rifflen = (wav->total_samples << stereo) + 36; |
176 | 174 | uint32_t datalen = wav->total_samples << stereo; |
177 | 175 | |
178 | - if (!wav->f || !hw->active) { | |
176 | + if (!wav->f) { | |
179 | 177 | return; |
180 | 178 | } |
181 | 179 | |
... | ... | @@ -214,6 +212,15 @@ static void wav_audio_fini (void *opaque) |
214 | 212 | } |
215 | 213 | |
216 | 214 | struct audio_option wav_options[] = { |
215 | + {"FREQUENCY", AUD_OPT_INT, &conf.settings.freq, | |
216 | + "Frequency", NULL, 0}, | |
217 | + | |
218 | + {"FORMAT", AUD_OPT_FMT, &conf.settings.fmt, | |
219 | + "Format", NULL, 0}, | |
220 | + | |
221 | + {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.settings.nchannels, | |
222 | + "Number of channels (1 - mono, 2 - stereo)", NULL, 0}, | |
223 | + | |
217 | 224 | {"PATH", AUD_OPT_STR, &conf.wav_path, |
218 | 225 | "Path to wave file", NULL, 0}, |
219 | 226 | {NULL, 0, NULL, NULL, NULL, 0} | ... | ... |
hw/adlib.c
... | ... | @@ -53,6 +53,7 @@ static struct { |
53 | 53 | } conf = {0x220, 44100}; |
54 | 54 | |
55 | 55 | typedef struct { |
56 | + QEMUSoundCard card; | |
56 | 57 | int ticking[2]; |
57 | 58 | int enabled; |
58 | 59 | int active; |
... | ... | @@ -70,7 +71,7 @@ typedef struct { |
70 | 71 | #endif |
71 | 72 | } AdlibState; |
72 | 73 | |
73 | -static AdlibState adlib; | |
74 | +static AdlibState glob_adlib; | |
74 | 75 | |
75 | 76 | static void adlib_stop_opl_timer (AdlibState *s, size_t n) |
76 | 77 | { |
... | ... | @@ -90,7 +91,7 @@ static void adlib_kill_timers (AdlibState *s) |
90 | 91 | if (s->ticking[i]) { |
91 | 92 | uint64_t delta; |
92 | 93 | |
93 | - delta = AUD_time_stamp_get_elapsed_usec_out (s->voice, &s->ats); | |
94 | + delta = AUD_get_elapsed_usec_out (s->voice, &s->ats); | |
94 | 95 | ldebug ( |
95 | 96 | "delta = %f dexp = %f expired => %d\n", |
96 | 97 | delta / 1000000.0, |
... | ... | @@ -141,10 +142,11 @@ static IO_READ_PROTO(adlib_read) |
141 | 142 | |
142 | 143 | static void timer_handler (int c, double interval_Sec) |
143 | 144 | { |
144 | - AdlibState *s = &adlib; | |
145 | + AdlibState *s = &glob_adlib; | |
145 | 146 | unsigned n = c & 1; |
146 | 147 | #ifdef DEBUG |
147 | 148 | double interval; |
149 | + int64_t exp; | |
148 | 150 | #endif |
149 | 151 | |
150 | 152 | if (interval_Sec == 0.0) { |
... | ... | @@ -262,16 +264,23 @@ static void Adlib_fini (AdlibState *s) |
262 | 264 | |
263 | 265 | s->active = 0; |
264 | 266 | s->enabled = 0; |
267 | + AUD_remove_card (&s->card); | |
265 | 268 | } |
266 | 269 | |
267 | -void Adlib_init (void) | |
270 | +int Adlib_init (AudioState *audio) | |
268 | 271 | { |
269 | - AdlibState *s = &adlib; | |
272 | + AdlibState *s = &glob_adlib; | |
273 | + audsettings_t as; | |
274 | + | |
275 | + if (!audio) { | |
276 | + dolog ("No audio state\n"); | |
277 | + return -1; | |
278 | + } | |
270 | 279 | |
271 | 280 | #ifdef HAS_YMF262 |
272 | 281 | if (YMF262Init (1, 14318180, conf.freq)) { |
273 | 282 | dolog ("YMF262Init %d failed\n", conf.freq); |
274 | - return; | |
283 | + return -1; | |
275 | 284 | } |
276 | 285 | else { |
277 | 286 | YMF262SetTimerHandler (0, timer_handler, 0); |
... | ... | @@ -281,7 +290,7 @@ void Adlib_init (void) |
281 | 290 | s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq); |
282 | 291 | if (!s->opl) { |
283 | 292 | dolog ("OPLCreate %d failed\n", conf.freq); |
284 | - return; | |
293 | + return -1; | |
285 | 294 | } |
286 | 295 | else { |
287 | 296 | OPLSetTimerHandler (s->opl, timer_handler, 0); |
... | ... | @@ -289,18 +298,23 @@ void Adlib_init (void) |
289 | 298 | } |
290 | 299 | #endif |
291 | 300 | |
301 | + as.freq = conf.freq; | |
302 | + as.nchannels = SHIFT; | |
303 | + as.fmt = AUD_FMT_S16; | |
304 | + | |
305 | + AUD_register_card (audio, "adlib", &s->card); | |
306 | + | |
292 | 307 | s->voice = AUD_open_out ( |
308 | + &s->card, | |
293 | 309 | s->voice, |
294 | 310 | "adlib", |
295 | 311 | s, |
296 | 312 | adlib_callback, |
297 | - conf.freq, | |
298 | - SHIFT, | |
299 | - AUD_FMT_S16 | |
313 | + &as | |
300 | 314 | ); |
301 | 315 | if (!s->voice) { |
302 | 316 | Adlib_fini (s); |
303 | - return; | |
317 | + return -1; | |
304 | 318 | } |
305 | 319 | |
306 | 320 | s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; |
... | ... | @@ -310,7 +324,7 @@ void Adlib_init (void) |
310 | 324 | dolog ("not enough memory for adlib mixing buffer (%d)\n", |
311 | 325 | s->samples << SHIFT); |
312 | 326 | Adlib_fini (s); |
313 | - return; | |
327 | + return -1; | |
314 | 328 | } |
315 | 329 | |
316 | 330 | register_ioport_read (0x388, 4, 1, adlib_read, s); |
... | ... | @@ -321,4 +335,6 @@ void Adlib_init (void) |
321 | 335 | |
322 | 336 | register_ioport_read (conf.port + 8, 2, 1, adlib_read, s); |
323 | 337 | register_ioport_write (conf.port + 8, 2, 1, adlib_write, s); |
338 | + | |
339 | + return 0; | |
324 | 340 | } | ... | ... |
hw/es1370.c
... | ... | @@ -265,6 +265,7 @@ struct chan { |
265 | 265 | typedef struct ES1370State { |
266 | 266 | PCIDevice *pci_dev; |
267 | 267 | |
268 | + QEMUSoundCard card; | |
268 | 269 | struct chan chan[NB_CHANNELS]; |
269 | 270 | SWVoiceOut *dac_voice[2]; |
270 | 271 | SWVoiceIn *adc_voice; |
... | ... | @@ -341,11 +342,11 @@ static void es1370_reset (ES1370State *s) |
341 | 342 | d->scount = 0; |
342 | 343 | d->leftover = 0; |
343 | 344 | if (i == ADC_CHANNEL) { |
344 | - AUD_close_in (s->adc_voice); | |
345 | + AUD_close_in (&s->card, s->adc_voice); | |
345 | 346 | s->adc_voice = NULL; |
346 | 347 | } |
347 | 348 | else { |
348 | - AUD_close_out (s->dac_voice[i]); | |
349 | + AUD_close_out (&s->card, s->dac_voice[i]); | |
349 | 350 | s->dac_voice[i] = NULL; |
350 | 351 | } |
351 | 352 | } |
... | ... | @@ -417,28 +418,32 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl) |
417 | 418 | (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8, |
418 | 419 | d->shift); |
419 | 420 | if (new_freq) { |
421 | + audsettings_t as; | |
422 | + | |
423 | + as.freq = new_freq; | |
424 | + as.nchannels = 1 << (new_fmt & 1); | |
425 | + as.fmt = (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8; | |
426 | + | |
420 | 427 | if (i == ADC_CHANNEL) { |
421 | 428 | s->adc_voice = |
422 | 429 | AUD_open_in ( |
430 | + &s->card, | |
423 | 431 | s->adc_voice, |
424 | 432 | "es1370.adc", |
425 | 433 | s, |
426 | 434 | es1370_adc_callback, |
427 | - new_freq, | |
428 | - 1 << (new_fmt & 1), | |
429 | - (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8 | |
435 | + &as | |
430 | 436 | ); |
431 | 437 | } |
432 | 438 | else { |
433 | 439 | s->dac_voice[i] = |
434 | 440 | AUD_open_out ( |
441 | + &s->card, | |
435 | 442 | s->dac_voice[i], |
436 | 443 | i ? "es1370.dac2" : "es1370.dac1", |
437 | 444 | s, |
438 | 445 | i ? es1370_dac2_callback : es1370_dac1_callback, |
439 | - new_freq, | |
440 | - 1 << (new_fmt & 1), | |
441 | - (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8 | |
446 | + &as | |
442 | 447 | ); |
443 | 448 | } |
444 | 449 | } |
... | ... | @@ -761,7 +766,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, |
761 | 766 | while (temp) { |
762 | 767 | int acquired, to_copy; |
763 | 768 | |
764 | - to_copy = audio_MIN (temp, sizeof (tmpbuf)); | |
769 | + to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf)); | |
765 | 770 | acquired = AUD_read (s->adc_voice, tmpbuf, to_copy); |
766 | 771 | if (!acquired) |
767 | 772 | break; |
... | ... | @@ -779,7 +784,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, |
779 | 784 | while (temp) { |
780 | 785 | int copied, to_copy; |
781 | 786 | |
782 | - to_copy = audio_MIN (temp, sizeof (tmpbuf)); | |
787 | + to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf)); | |
783 | 788 | cpu_physical_memory_read (addr, tmpbuf, to_copy); |
784 | 789 | copied = AUD_write (voice, tmpbuf, to_copy); |
785 | 790 | if (!copied) |
... | ... | @@ -812,7 +817,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, |
812 | 817 | else { |
813 | 818 | d->frame_cnt = size; |
814 | 819 | |
815 | - if (cnt <= d->frame_cnt) | |
820 | + if ((uint32_t) cnt <= d->frame_cnt) | |
816 | 821 | d->frame_cnt |= cnt << 16; |
817 | 822 | } |
818 | 823 | |
... | ... | @@ -876,6 +881,10 @@ static void es1370_map (PCIDevice *pci_dev, int region_num, |
876 | 881 | PCIES1370State *d = (PCIES1370State *) pci_dev; |
877 | 882 | ES1370State *s = &d->es1370; |
878 | 883 | |
884 | + (void) region_num; | |
885 | + (void) size; | |
886 | + (void) type; | |
887 | + | |
879 | 888 | register_ioport_write (addr, 0x40 * 4, 1, es1370_writeb, s); |
880 | 889 | register_ioport_write (addr, 0x40 * 2, 2, es1370_writew, s); |
881 | 890 | register_ioport_write (addr, 0x40, 4, es1370_writel, s); |
... | ... | @@ -923,13 +932,13 @@ static int es1370_load (QEMUFile *f, void *opaque, int version_id) |
923 | 932 | qemu_get_be32s (f, &d->frame_cnt); |
924 | 933 | if (i == ADC_CHANNEL) { |
925 | 934 | if (s->adc_voice) { |
926 | - AUD_close_in (s->adc_voice); | |
935 | + AUD_close_in (&s->card, s->adc_voice); | |
927 | 936 | s->adc_voice = NULL; |
928 | 937 | } |
929 | 938 | } |
930 | 939 | else { |
931 | 940 | if (s->dac_voice[i]) { |
932 | - AUD_close_out (s->dac_voice[i]); | |
941 | + AUD_close_out (&s->card, s->dac_voice[i]); | |
933 | 942 | s->dac_voice[i] = NULL; |
934 | 943 | } |
935 | 944 | } |
... | ... | @@ -953,12 +962,22 @@ static void es1370_on_reset (void *opaque) |
953 | 962 | es1370_reset (s); |
954 | 963 | } |
955 | 964 | |
956 | -int es1370_init (PCIBus *bus) | |
965 | +int es1370_init (PCIBus *bus, AudioState *audio) | |
957 | 966 | { |
958 | 967 | PCIES1370State *d; |
959 | 968 | ES1370State *s; |
960 | 969 | uint8_t *c; |
961 | 970 | |
971 | + if (!bus) { | |
972 | + dolog ("No PCI bus\n"); | |
973 | + return -1; | |
974 | + } | |
975 | + | |
976 | + if (!audio) { | |
977 | + dolog ("No audio state\n"); | |
978 | + return -1; | |
979 | + } | |
980 | + | |
962 | 981 | d = (PCIES1370State *) pci_register_device (bus, "ES1370", |
963 | 982 | sizeof (PCIES1370State), |
964 | 983 | -1, NULL, NULL); |
... | ... | @@ -1002,6 +1021,8 @@ int es1370_init (PCIBus *bus) |
1002 | 1021 | pci_register_io_region (&d->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map); |
1003 | 1022 | register_savevm ("es1370", 0, 1, es1370_save, es1370_load, s); |
1004 | 1023 | qemu_register_reset (es1370_on_reset, s); |
1024 | + | |
1025 | + AUD_register_card (audio, "es1370", &s->card); | |
1005 | 1026 | es1370_reset (s); |
1006 | 1027 | return 0; |
1007 | 1028 | } | ... | ... |
hw/pc.c
... | ... | @@ -601,19 +601,23 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, |
601 | 601 | DMA_init(0); |
602 | 602 | |
603 | 603 | if (audio_enabled) { |
604 | - AUD_init(); | |
605 | - if (sb16_enabled) | |
606 | - SB16_init (); | |
604 | + AudioState *audio; | |
605 | + | |
606 | + audio = AUD_init(); | |
607 | + if (audio) { | |
608 | + if (sb16_enabled) | |
609 | + SB16_init (audio); | |
607 | 610 | #ifdef CONFIG_ADLIB |
608 | - if (adlib_enabled) | |
609 | - Adlib_init (); | |
611 | + if (adlib_enabled) | |
612 | + Adlib_init (audio); | |
610 | 613 | #endif |
611 | 614 | #ifdef CONFIG_GUS |
612 | - if (gus_enabled) | |
613 | - GUS_init (); | |
615 | + if (gus_enabled) | |
616 | + GUS_init (audio); | |
614 | 617 | #endif |
615 | - if (pci_enabled && es1370_enabled) | |
616 | - es1370_init (pci_bus); | |
618 | + if (pci_enabled && es1370_enabled) | |
619 | + es1370_init (pci_bus, audio); | |
620 | + } | |
617 | 621 | } |
618 | 622 | |
619 | 623 | floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table); | ... | ... |
hw/sb16.c
... | ... | @@ -53,6 +53,7 @@ static struct { |
53 | 53 | } conf = {5, 4, 5, 1, 5, 0x220}; |
54 | 54 | |
55 | 55 | typedef struct SB16State { |
56 | + QEMUSoundCard card; | |
56 | 57 | int irq; |
57 | 58 | int dma; |
58 | 59 | int hdma; |
... | ... | @@ -108,9 +109,6 @@ typedef struct SB16State { |
108 | 109 | uint8_t mixer_regs[256]; |
109 | 110 | } SB16State; |
110 | 111 | |
111 | -/* XXX: suppress that and use a context */ | |
112 | -static struct SB16State dsp; | |
113 | - | |
114 | 112 | static void SB_audio_callback (void *opaque, int free); |
115 | 113 | |
116 | 114 | static int magic_of_irq (int irq) |
... | ... | @@ -242,15 +240,21 @@ static void dma_cmd8 (SB16State *s, int mask, int dma_len) |
242 | 240 | s->block_size, s->dma_auto, s->fifo, s->highspeed); |
243 | 241 | |
244 | 242 | if (s->freq) { |
243 | + audsettings_t as; | |
244 | + | |
245 | 245 | s->audio_free = 0; |
246 | + | |
247 | + as.freq = s->freq; | |
248 | + as.nchannels = 1 << s->fmt_stereo; | |
249 | + as.fmt = s->fmt; | |
250 | + | |
246 | 251 | s->voice = AUD_open_out ( |
252 | + &s->card, | |
247 | 253 | s->voice, |
248 | 254 | "sb16", |
249 | 255 | s, |
250 | 256 | SB_audio_callback, |
251 | - s->freq, | |
252 | - 1 << s->fmt_stereo, | |
253 | - s->fmt | |
257 | + &as | |
254 | 258 | ); |
255 | 259 | } |
256 | 260 | |
... | ... | @@ -330,15 +334,21 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len) |
330 | 334 | } |
331 | 335 | |
332 | 336 | if (s->freq) { |
337 | + audsettings_t as; | |
338 | + | |
333 | 339 | s->audio_free = 0; |
340 | + | |
341 | + as.freq = s->freq; | |
342 | + as.nchannels = 1 << s->fmt_stereo; | |
343 | + as.fmt = s->fmt; | |
344 | + | |
334 | 345 | s->voice = AUD_open_out ( |
346 | + &s->card, | |
335 | 347 | s->voice, |
336 | 348 | "sb16", |
337 | 349 | s, |
338 | 350 | SB_audio_callback, |
339 | - s->freq, | |
340 | - 1 << s->fmt_stereo, | |
341 | - s->fmt | |
351 | + &as | |
342 | 352 | ); |
343 | 353 | } |
344 | 354 | |
... | ... | @@ -349,7 +359,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len) |
349 | 359 | static inline void dsp_out_data (SB16State *s, uint8_t val) |
350 | 360 | { |
351 | 361 | ldebug ("outdata %#x\n", val); |
352 | - if (s->out_data_len < sizeof (s->out_data)) { | |
362 | + if ((size_t) s->out_data_len < sizeof (s->out_data)) { | |
353 | 363 | s->out_data[s->out_data_len++] = val; |
354 | 364 | } |
355 | 365 | } |
... | ... | @@ -1018,6 +1028,7 @@ static void reset_mixer (SB16State *s) |
1018 | 1028 | static IO_WRITE_PROTO(mixer_write_indexb) |
1019 | 1029 | { |
1020 | 1030 | SB16State *s = opaque; |
1031 | + (void) nport; | |
1021 | 1032 | s->mixer_nreg = val; |
1022 | 1033 | } |
1023 | 1034 | |
... | ... | @@ -1025,10 +1036,8 @@ static IO_WRITE_PROTO(mixer_write_datab) |
1025 | 1036 | { |
1026 | 1037 | SB16State *s = opaque; |
1027 | 1038 | |
1039 | + (void) nport; | |
1028 | 1040 | ldebug ("mixer_write [%#x] <- %#x\n", s->mixer_nreg, val); |
1029 | - if (s->mixer_nreg > sizeof (s->mixer_regs)) { | |
1030 | - return; | |
1031 | - } | |
1032 | 1041 | |
1033 | 1042 | switch (s->mixer_nreg) { |
1034 | 1043 | case 0x00: |
... | ... | @@ -1088,6 +1097,8 @@ static IO_WRITE_PROTO(mixer_write_indexw) |
1088 | 1097 | static IO_READ_PROTO(mixer_read) |
1089 | 1098 | { |
1090 | 1099 | SB16State *s = opaque; |
1100 | + | |
1101 | + (void) nport; | |
1091 | 1102 | #ifndef DEBUG_SB16_MOST |
1092 | 1103 | if (s->mixer_nreg != 0x82) { |
1093 | 1104 | ldebug ("mixer_read[%#x] -> %#x\n", |
... | ... | @@ -1111,11 +1122,12 @@ static int write_audio (SB16State *s, int nchan, int dma_pos, |
1111 | 1122 | |
1112 | 1123 | while (temp) { |
1113 | 1124 | int left = dma_len - dma_pos; |
1114 | - int to_copy, copied; | |
1125 | + int copied; | |
1126 | + size_t to_copy; | |
1115 | 1127 | |
1116 | 1128 | to_copy = audio_MIN (temp, left); |
1117 | - if (to_copy > sizeof(tmpbuf)) { | |
1118 | - to_copy = sizeof(tmpbuf); | |
1129 | + if (to_copy > sizeof (tmpbuf)) { | |
1130 | + to_copy = sizeof (tmpbuf); | |
1119 | 1131 | } |
1120 | 1132 | |
1121 | 1133 | copied = DMA_read_memory (nchan, tmpbuf, dma_pos, to_copy); |
... | ... | @@ -1308,21 +1320,27 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id) |
1308 | 1320 | qemu_get_buffer (f, s->mixer_regs, 256); |
1309 | 1321 | |
1310 | 1322 | if (s->voice) { |
1311 | - AUD_close_out (s->voice); | |
1323 | + AUD_close_out (&s->card, s->voice); | |
1312 | 1324 | s->voice = NULL; |
1313 | 1325 | } |
1314 | 1326 | |
1315 | 1327 | if (s->dma_running) { |
1316 | 1328 | if (s->freq) { |
1329 | + audsettings_t as; | |
1330 | + | |
1317 | 1331 | s->audio_free = 0; |
1332 | + | |
1333 | + as.freq = s->freq; | |
1334 | + as.nchannels = 1 << s->fmt_stereo; | |
1335 | + as.fmt = s->fmt; | |
1336 | + | |
1318 | 1337 | s->voice = AUD_open_out ( |
1338 | + &s->card, | |
1319 | 1339 | s->voice, |
1320 | 1340 | "sb16", |
1321 | 1341 | s, |
1322 | 1342 | SB_audio_callback, |
1323 | - s->freq, | |
1324 | - 1 << s->fmt_stereo, | |
1325 | - s->fmt | |
1343 | + &as | |
1326 | 1344 | ); |
1327 | 1345 | } |
1328 | 1346 | |
... | ... | @@ -1332,13 +1350,25 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id) |
1332 | 1350 | return 0; |
1333 | 1351 | } |
1334 | 1352 | |
1335 | -void SB16_init (void) | |
1353 | +int SB16_init (AudioState *audio) | |
1336 | 1354 | { |
1337 | - SB16State *s = &dsp; | |
1355 | + SB16State *s; | |
1338 | 1356 | int i; |
1339 | 1357 | static const uint8_t dsp_write_ports[] = {0x6, 0xc}; |
1340 | 1358 | static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf}; |
1341 | 1359 | |
1360 | + if (!audio) { | |
1361 | + dolog ("No audio state\n"); | |
1362 | + return -1; | |
1363 | + } | |
1364 | + | |
1365 | + s = qemu_mallocz (sizeof (*s)); | |
1366 | + if (!s) { | |
1367 | + dolog ("Could not allocate memory for SB16 (%d bytes)\n", | |
1368 | + sizeof (*s)); | |
1369 | + return -1; | |
1370 | + } | |
1371 | + | |
1342 | 1372 | s->cmd = -1; |
1343 | 1373 | s->irq = conf.irq; |
1344 | 1374 | s->dma = conf.dma; |
... | ... | @@ -1356,7 +1386,7 @@ void SB16_init (void) |
1356 | 1386 | reset_mixer (s); |
1357 | 1387 | s->aux_ts = qemu_new_timer (vm_clock, aux_timer, s); |
1358 | 1388 | if (!s->aux_ts) { |
1359 | - dolog ("Can not create auxiliary timer\n"); | |
1389 | + dolog ("warning: Could not create auxiliary timer\n"); | |
1360 | 1390 | } |
1361 | 1391 | |
1362 | 1392 | for (i = 0; i < LENOFA (dsp_write_ports); i++) { |
... | ... | @@ -1377,4 +1407,6 @@ void SB16_init (void) |
1377 | 1407 | s->can_write = 1; |
1378 | 1408 | |
1379 | 1409 | register_savevm ("sb16", 0, 1, SB_save, SB_load, s); |
1410 | + AUD_register_card (audio, "sb16", &s->card); | |
1411 | + return 0; | |
1380 | 1412 | } | ... | ... |
qemu-doc.texi
... | ... | @@ -95,12 +95,21 @@ NE2000 PCI network adapters |
95 | 95 | @item |
96 | 96 | Serial ports |
97 | 97 | @item |
98 | -Soundblaster 16 card | |
98 | +Creative SoundBlaster 16 sound card | |
99 | +@item | |
100 | +ENSONIQ AudioPCI ES1370 sound card | |
101 | +@item | |
102 | +Adlib(OPL2) - Yamaha YM3812 compatible chip | |
99 | 103 | @end itemize |
100 | 104 | |
105 | +Note that adlib is only available when QEMU was configured with | |
106 | +-enable-adlib | |
107 | + | |
101 | 108 | QEMU uses the PC BIOS from the Bochs project and the Plex86/Bochs LGPL |
102 | 109 | VGA BIOS. |
103 | 110 | |
111 | +QEMU uses YM3812 emulation by Tatsuyuki Satoh. | |
112 | + | |
104 | 113 | @c man end |
105 | 114 | |
106 | 115 | @section Quick Start | ... | ... |
vl.c
... | ... | @@ -2842,10 +2842,11 @@ void help(void) |
2842 | 2842 | "-k language use keyboard layout (for example \"fr\" for French)\n" |
2843 | 2843 | #endif |
2844 | 2844 | #ifdef HAS_AUDIO |
2845 | - "-enable-audio enable audio support\n" | |
2845 | + "-enable-audio enable audio support, and all the sound cars\n" | |
2846 | 2846 | "-audio-help print list of audio drivers and their options\n" |
2847 | - "-soundhw c1,... comma separated list of sound card names\n" | |
2848 | - " use -soundhw ? to get the list of supported sound cards\n" | |
2847 | + "-soundhw c1,... enable audio support\n" | |
2848 | + " and only specified sound cards (comma separated list)\n" | |
2849 | + " use -soundhw ? to get the list of supported cards\n" | |
2849 | 2850 | #endif |
2850 | 2851 | "-localtime set the real time clock to local time [default=utc]\n" |
2851 | 2852 | "-full-screen start in full screen\n" |
... | ... | @@ -3145,9 +3146,9 @@ static void select_soundhw (const char *optarg) |
3145 | 3146 | printf ("sb16 Creative Sound Blaster 16\n"); |
3146 | 3147 | #ifdef CONFIG_ADLIB |
3147 | 3148 | #ifdef HAS_YMF262 |
3148 | - printf ("adlib Ymaha YMF262 (OPL3)\n"); | |
3149 | + printf ("adlib Yamaha YMF262 (OPL3)\n"); | |
3149 | 3150 | #else |
3150 | - printf ("adlib Ymaha YM3812 (OPL2)\n"); | |
3151 | + printf ("adlib Yamaha YM3812 (OPL2)\n"); | |
3151 | 3152 | #endif |
3152 | 3153 | #endif |
3153 | 3154 | #ifdef CONFIG_GUS | ... | ... |
vl.h
... | ... | @@ -631,16 +631,16 @@ int pmac_ide_init (BlockDriverState **hd_table, |
631 | 631 | SetIRQFunc *set_irq, void *irq_opaque, int irq); |
632 | 632 | |
633 | 633 | /* es1370.c */ |
634 | -int es1370_init (PCIBus *bus); | |
634 | +int es1370_init (PCIBus *bus, AudioState *s); | |
635 | 635 | |
636 | 636 | /* sb16.c */ |
637 | -void SB16_init (void); | |
637 | +int SB16_init (AudioState *s); | |
638 | 638 | |
639 | 639 | /* adlib.c */ |
640 | -void Adlib_init (void); | |
640 | +int Adlib_init (AudioState *s); | |
641 | 641 | |
642 | 642 | /* gus.c */ |
643 | -void GUS_init (void); | |
643 | +int GUS_init (AudioState *s); | |
644 | 644 | |
645 | 645 | /* dma.c */ |
646 | 646 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); | ... | ... |