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,8 +453,8 @@ ifneq ($(wildcard .depend),) | ||
| 453 | include .depend | 453 | include .depend |
| 454 | endif | 454 | endif |
| 455 | 455 | ||
| 456 | -ifeq (0, 1) | 456 | +ifeq (1, 0) |
| 457 | audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \ | 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 | CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare | 459 | CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare |
| 460 | endif | 460 | endif |
audio/alsaaudio.c
| @@ -98,7 +98,7 @@ struct alsa_params_obt { | @@ -98,7 +98,7 @@ struct alsa_params_obt { | ||
| 98 | audfmt_e fmt; | 98 | audfmt_e fmt; |
| 99 | int nchannels; | 99 | int nchannels; |
| 100 | int can_pause; | 100 | int can_pause; |
| 101 | - snd_pcm_uframes_t buffer_size; | 101 | + snd_pcm_uframes_t samples; |
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...) | 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,7 +121,7 @@ static void GCC_FMT_ATTR (3, 4) alsa_logerr2 ( | ||
| 121 | { | 121 | { |
| 122 | va_list ap; | 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 | va_start (ap, fmt); | 126 | va_start (ap, fmt); |
| 127 | AUD_vlog (AUDIO_CAP, fmt, ap); | 127 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| @@ -209,7 +209,7 @@ static int alsa_to_audfmt (int alsafmt, audfmt_e *fmt, int *endianness) | @@ -209,7 +209,7 @@ static int alsa_to_audfmt (int alsafmt, audfmt_e *fmt, int *endianness) | ||
| 209 | return 0; | 209 | return 0; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | -#ifdef DEBUG_MISMATCHES | 212 | +#if defined DEBUG_MISMATCHES || defined DEBUG |
| 213 | static void alsa_dump_info (struct alsa_params_req *req, | 213 | static void alsa_dump_info (struct alsa_params_req *req, |
| 214 | struct alsa_params_obt *obt) | 214 | struct alsa_params_obt *obt) |
| 215 | { | 215 | { |
| @@ -221,7 +221,7 @@ static void alsa_dump_info (struct alsa_params_req *req, | @@ -221,7 +221,7 @@ static void alsa_dump_info (struct alsa_params_req *req, | ||
| 221 | dolog ("============================================\n"); | 221 | dolog ("============================================\n"); |
| 222 | dolog ("requested: buffer size %d period size %d\n", | 222 | dolog ("requested: buffer size %d period size %d\n", |
| 223 | req->buffer_size, req->period_size); | 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 | #endif | 226 | #endif |
| 227 | 227 | ||
| @@ -234,14 +234,14 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) | @@ -234,14 +234,14 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) | ||
| 234 | 234 | ||
| 235 | err = snd_pcm_sw_params_current (handle, sw_params); | 235 | err = snd_pcm_sw_params_current (handle, sw_params); |
| 236 | if (err < 0) { | 236 | if (err < 0) { |
| 237 | - dolog ("Can not fully initialize DAC\n"); | 237 | + dolog ("Could not fully initialize DAC\n"); |
| 238 | alsa_logerr (err, "Failed to get current software parameters\n"); | 238 | alsa_logerr (err, "Failed to get current software parameters\n"); |
| 239 | return; | 239 | return; |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold); | 242 | err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold); |
| 243 | if (err < 0) { | 243 | if (err < 0) { |
| 244 | - dolog ("Can not fully initialize DAC\n"); | 244 | + dolog ("Could not fully initialize DAC\n"); |
| 245 | alsa_logerr (err, "Failed to set software threshold to %ld\n", | 245 | alsa_logerr (err, "Failed to set software threshold to %ld\n", |
| 246 | threshold); | 246 | threshold); |
| 247 | return; | 247 | return; |
| @@ -249,7 +249,7 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) | @@ -249,7 +249,7 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) | ||
| 249 | 249 | ||
| 250 | err = snd_pcm_sw_params (handle, sw_params); | 250 | err = snd_pcm_sw_params (handle, sw_params); |
| 251 | if (err < 0) { | 251 | if (err < 0) { |
| 252 | - dolog ("Can not fully initialize DAC\n"); | 252 | + dolog ("Could not fully initialize DAC\n"); |
| 253 | alsa_logerr (err, "Failed to set software parameters\n"); | 253 | alsa_logerr (err, "Failed to set software parameters\n"); |
| 254 | return; | 254 | return; |
| 255 | } | 255 | } |
| @@ -344,7 +344,8 @@ static int alsa_open (int in, struct alsa_params_req *req, | @@ -344,7 +344,8 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 344 | handle, | 344 | handle, |
| 345 | hw_params, | 345 | hw_params, |
| 346 | &period_size, | 346 | &period_size, |
| 347 | - 0); | 347 | + 0 |
| 348 | + ); | ||
| 348 | if (err < 0) { | 349 | if (err < 0) { |
| 349 | alsa_logerr2 (err, typ, | 350 | alsa_logerr2 (err, typ, |
| 350 | "Failed to set period time %d\n", | 351 | "Failed to set period time %d\n", |
| @@ -357,7 +358,8 @@ static int alsa_open (int in, struct alsa_params_req *req, | @@ -357,7 +358,8 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 357 | handle, | 358 | handle, |
| 358 | hw_params, | 359 | hw_params, |
| 359 | &buffer_size, | 360 | &buffer_size, |
| 360 | - 0); | 361 | + 0 |
| 362 | + ); | ||
| 361 | 363 | ||
| 362 | if (err < 0) { | 364 | if (err < 0) { |
| 363 | alsa_logerr2 (err, typ, | 365 | alsa_logerr2 (err, typ, |
| @@ -382,7 +384,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | @@ -382,7 +384,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 382 | if (err < 0) { | 384 | if (err < 0) { |
| 383 | alsa_logerr ( | 385 | alsa_logerr ( |
| 384 | err, | 386 | err, |
| 385 | - "Can not get minmal period size for %s\n", | 387 | + "Could not get minmal period size for %s\n", |
| 386 | typ | 388 | typ |
| 387 | ); | 389 | ); |
| 388 | } | 390 | } |
| @@ -419,7 +421,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | @@ -419,7 +421,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 419 | &minval | 421 | &minval |
| 420 | ); | 422 | ); |
| 421 | if (err < 0) { | 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 | typ); | 425 | typ); |
| 424 | } | 426 | } |
| 425 | else { | 427 | else { |
| @@ -451,7 +453,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | @@ -451,7 +453,7 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 451 | } | 453 | } |
| 452 | } | 454 | } |
| 453 | else { | 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 | err = snd_pcm_hw_params (handle, hw_params); | 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,13 +470,13 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 468 | 470 | ||
| 469 | err = snd_pcm_prepare (handle); | 471 | err = snd_pcm_prepare (handle); |
| 470 | if (err < 0) { | 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 | goto err; | 474 | goto err; |
| 473 | } | 475 | } |
| 474 | 476 | ||
| 475 | obt->can_pause = snd_pcm_hw_params_can_pause (hw_params); | 477 | obt->can_pause = snd_pcm_hw_params_can_pause (hw_params); |
| 476 | if (obt->can_pause < 0) { | 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 | obt->can_pause = 0; | 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,17 +495,17 @@ static int alsa_open (int in, struct alsa_params_req *req, | ||
| 493 | obt->fmt = req->fmt; | 495 | obt->fmt = req->fmt; |
| 494 | obt->nchannels = nchannels; | 496 | obt->nchannels = nchannels; |
| 495 | obt->freq = freq; | 497 | obt->freq = freq; |
| 496 | - obt->buffer_size = snd_pcm_frames_to_bytes (handle, obt_buffer_size); | 498 | + obt->samples = obt_buffer_size; |
| 497 | *handlep = handle; | 499 | *handlep = handle; |
| 498 | 500 | ||
| 501 | +#if defined DEBUG_MISMATCHES || defined DEBUG | ||
| 499 | if (obt->fmt != req->fmt || | 502 | if (obt->fmt != req->fmt || |
| 500 | obt->nchannels != req->nchannels || | 503 | obt->nchannels != req->nchannels || |
| 501 | obt->freq != req->freq) { | 504 | obt->freq != req->freq) { |
| 502 | -#ifdef DEBUG_MISMATCHES | ||
| 503 | dolog ("Audio paramters mismatch for %s\n", typ); | 505 | dolog ("Audio paramters mismatch for %s\n", typ); |
| 504 | alsa_dump_info (req, obt); | 506 | alsa_dump_info (req, obt); |
| 505 | -#endif | ||
| 506 | } | 507 | } |
| 508 | +#endif | ||
| 507 | 509 | ||
| 508 | #ifdef DEBUG | 510 | #ifdef DEBUG |
| 509 | alsa_dump_info (req, obt); | 511 | alsa_dump_info (req, obt); |
| @@ -550,7 +552,7 @@ static int alsa_run_out (HWVoiceOut *hw) | @@ -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 | return 0; | 556 | return 0; |
| 555 | } | 557 | } |
| 556 | 558 | ||
| @@ -618,7 +620,7 @@ static void alsa_fini_out (HWVoiceOut *hw) | @@ -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 | ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; | 625 | ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; |
| 624 | struct alsa_params_req req; | 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,10 +629,11 @@ static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 627 | int endianness; | 629 | int endianness; |
| 628 | int err; | 630 | int err; |
| 629 | snd_pcm_t *handle; | 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 | req.period_size = conf.period_size_out; | 637 | req.period_size = conf.period_size_out; |
| 635 | req.buffer_size = conf.buffer_size_out; | 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,18 +647,22 @@ static int alsa_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 644 | return -1; | 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 | audio_pcm_init_info ( | 654 | audio_pcm_init_info ( |
| 648 | &hw->info, | 655 | &hw->info, |
| 649 | - obt.freq, | ||
| 650 | - obt.nchannels, | ||
| 651 | - effective_fmt, | 656 | + &obt_as, |
| 652 | audio_need_to_swap_endian (endianness) | 657 | audio_need_to_swap_endian (endianness) |
| 653 | ); | 658 | ); |
| 654 | alsa->can_pause = obt.can_pause; | 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 | if (!alsa->pcm_buf) { | 663 | if (!alsa->pcm_buf) { |
| 664 | + dolog ("Could not allocate DAC buffer (%d bytes)\n", | ||
| 665 | + hw->samples << hw->info.shift); | ||
| 659 | alsa_anal_close (&handle); | 666 | alsa_anal_close (&handle); |
| 660 | return -1; | 667 | return -1; |
| 661 | } | 668 | } |
| @@ -703,8 +710,7 @@ static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -703,8 +710,7 @@ static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 703 | return 0; | 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 | ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; | 715 | ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; |
| 710 | struct alsa_params_req req; | 716 | struct alsa_params_req req; |
| @@ -713,10 +719,11 @@ static int alsa_init_in (HWVoiceIn *hw, | @@ -713,10 +719,11 @@ static int alsa_init_in (HWVoiceIn *hw, | ||
| 713 | int err; | 719 | int err; |
| 714 | audfmt_e effective_fmt; | 720 | audfmt_e effective_fmt; |
| 715 | snd_pcm_t *handle; | 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 | req.period_size = conf.period_size_in; | 727 | req.period_size = conf.period_size_in; |
| 721 | req.buffer_size = conf.buffer_size_in; | 728 | req.buffer_size = conf.buffer_size_in; |
| 722 | 729 | ||
| @@ -730,17 +737,22 @@ static int alsa_init_in (HWVoiceIn *hw, | @@ -730,17 +737,22 @@ static int alsa_init_in (HWVoiceIn *hw, | ||
| 730 | return -1; | 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 | audio_pcm_init_info ( | 744 | audio_pcm_init_info ( |
| 734 | &hw->info, | 745 | &hw->info, |
| 735 | - obt.freq, | ||
| 736 | - obt.nchannels, | ||
| 737 | - effective_fmt, | 746 | + &obt_as, |
| 738 | audio_need_to_swap_endian (endianness) | 747 | audio_need_to_swap_endian (endianness) |
| 739 | ); | 748 | ); |
| 740 | alsa->can_pause = obt.can_pause; | 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 | if (!alsa->pcm_buf) { | 753 | if (!alsa->pcm_buf) { |
| 754 | + dolog ("Could not allocate ADC buffer (%d bytes)\n", | ||
| 755 | + hw->samples << hw->info.shift); | ||
| 744 | alsa_anal_close (&handle); | 756 | alsa_anal_close (&handle); |
| 745 | return -1; | 757 | return -1; |
| 746 | } | 758 | } |
audio/audio.c
| @@ -26,16 +26,12 @@ | @@ -26,16 +26,12 @@ | ||
| 26 | #define AUDIO_CAP "audio" | 26 | #define AUDIO_CAP "audio" |
| 27 | #include "audio_int.h" | 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 | /* #define DEBUG_PLIVE */ | 29 | /* #define DEBUG_PLIVE */ |
| 36 | /* #define DEBUG_LIVE */ | 30 | /* #define DEBUG_LIVE */ |
| 37 | /* #define DEBUG_OUT */ | 31 | /* #define DEBUG_OUT */ |
| 38 | 32 | ||
| 33 | +#define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown" | ||
| 34 | + | ||
| 39 | static struct audio_driver *drvtab[] = { | 35 | static struct audio_driver *drvtab[] = { |
| 40 | #ifdef CONFIG_OSS | 36 | #ifdef CONFIG_OSS |
| 41 | &oss_audio_driver, | 37 | &oss_audio_driver, |
| @@ -59,31 +55,50 @@ static struct audio_driver *drvtab[] = { | @@ -59,31 +55,50 @@ static struct audio_driver *drvtab[] = { | ||
| 59 | &wav_audio_driver | 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 | { 0 }, /* period */ | 96 | { 0 }, /* period */ |
| 84 | 0 /* plive */ | 97 | 0 /* plive */ |
| 85 | }; | 98 | }; |
| 86 | 99 | ||
| 100 | +static AudioState glob_audio_state; | ||
| 101 | + | ||
| 87 | volume_t nominal_volume = { | 102 | volume_t nominal_volume = { |
| 88 | 0, | 103 | 0, |
| 89 | #ifdef FLOAT_MIXENG | 104 | #ifdef FLOAT_MIXENG |
| @@ -148,6 +163,26 @@ int audio_bug (const char *funcname, int cond) | @@ -148,6 +163,26 @@ int audio_bug (const char *funcname, int cond) | ||
| 148 | } | 163 | } |
| 149 | #endif | 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 | static char *audio_alloc_prefix (const char *s) | 186 | static char *audio_alloc_prefix (const char *s) |
| 152 | { | 187 | { |
| 153 | const char qemu_prefix[] = "QEMU_"; | 188 | const char qemu_prefix[] = "QEMU_"; |
| @@ -386,14 +421,19 @@ static void audio_process_options (const char *prefix, | @@ -386,14 +421,19 @@ static void audio_process_options (const char *prefix, | ||
| 386 | } | 421 | } |
| 387 | 422 | ||
| 388 | len = strlen (opt->name); | 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 | optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1); | 427 | optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1); |
| 390 | if (!optname) { | 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 | opt->name); | 430 | opt->name); |
| 393 | continue; | 431 | continue; |
| 394 | } | 432 | } |
| 395 | 433 | ||
| 396 | strcpy (optname, qemu_prefix); | 434 | strcpy (optname, qemu_prefix); |
| 435 | + | ||
| 436 | + /* copy while upper-casing, including trailing zero */ | ||
| 397 | for (i = 0; i <= preflen; ++i) { | 437 | for (i = 0; i <= preflen; ++i) { |
| 398 | optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); | 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,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 | int bits = 8, sign = 0; | 532 | int bits = 8, sign = 0; |
| 445 | 533 | ||
| 446 | - switch (fmt) { | 534 | + switch (as->fmt) { |
| 447 | case AUD_FMT_S8: | 535 | case AUD_FMT_S8: |
| 448 | sign = 1; | 536 | sign = 1; |
| 449 | case AUD_FMT_U8: | 537 | case AUD_FMT_U8: |
| @@ -455,18 +543,21 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, int freq, | @@ -455,18 +543,21 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, int freq, | ||
| 455 | bits = 16; | 543 | bits = 16; |
| 456 | break; | 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 | && info->sign == sign | 548 | && info->sign == sign |
| 461 | && info->bits == bits; | 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 | int bits = 8, sign = 0; | 558 | int bits = 8, sign = 0; |
| 468 | 559 | ||
| 469 | - switch (fmt) { | 560 | + switch (as->fmt) { |
| 470 | case AUD_FMT_S8: | 561 | case AUD_FMT_S8: |
| 471 | sign = 1; | 562 | sign = 1; |
| 472 | case AUD_FMT_U8: | 563 | case AUD_FMT_U8: |
| @@ -479,11 +570,11 @@ void audio_pcm_init_info (struct audio_pcm_info *info, int freq, | @@ -479,11 +570,11 @@ void audio_pcm_init_info (struct audio_pcm_info *info, int freq, | ||
| 479 | break; | 570 | break; |
| 480 | } | 571 | } |
| 481 | 572 | ||
| 482 | - info->freq = freq; | 573 | + info->freq = as->freq; |
| 483 | info->bits = bits; | 574 | info->bits = bits; |
| 484 | info->sign = sign; | 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 | info->align = (1 << info->shift) - 1; | 578 | info->align = (1 << info->shift) - 1; |
| 488 | info->bytes_per_second = info->freq << info->shift; | 579 | info->bytes_per_second = info->freq << info->shift; |
| 489 | info->swap_endian = swap_endian; | 580 | info->swap_endian = swap_endian; |
| @@ -532,38 +623,16 @@ static void audio_pcm_hw_free_resources_in (HWVoiceIn *hw) | @@ -532,38 +623,16 @@ static void audio_pcm_hw_free_resources_in (HWVoiceIn *hw) | ||
| 532 | 623 | ||
| 533 | static int audio_pcm_hw_alloc_resources_in (HWVoiceIn *hw) | 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 | if (!hw->conv_buf) { | 627 | if (!hw->conv_buf) { |
| 628 | + dolog ("Could not allocate ADC conversion buffer (%d bytes)\n", | ||
| 629 | + hw->samples * sizeof (st_sample_t)); | ||
| 537 | return -1; | 630 | return -1; |
| 538 | } | 631 | } |
| 539 | return 0; | 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 | SWVoiceIn *sw; | 637 | SWVoiceIn *sw; |
| 569 | int m = hw->total_samples_captured; | 638 | int m = hw->total_samples_captured; |
| @@ -606,8 +675,10 @@ static void audio_pcm_sw_free_resources_in (SWVoiceIn *sw) | @@ -606,8 +675,10 @@ static void audio_pcm_sw_free_resources_in (SWVoiceIn *sw) | ||
| 606 | static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) | 675 | static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) |
| 607 | { | 676 | { |
| 608 | int samples = ((int64_t) sw->hw->samples << 32) / sw->ratio; | 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 | if (!sw->conv_buf) { | 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 | return -1; | 682 | return -1; |
| 612 | } | 683 | } |
| 613 | 684 | ||
| @@ -620,19 +691,22 @@ static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) | @@ -620,19 +691,22 @@ static int audio_pcm_sw_alloc_resources_in (SWVoiceIn *sw) | ||
| 620 | return 0; | 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 | sw->hw = hw; | 704 | sw->hw = hw; |
| 631 | sw->ratio = ((int64_t) sw->info.freq << 32) / sw->hw->info.freq; | 705 | sw->ratio = ((int64_t) sw->info.freq << 32) / sw->hw->info.freq; |
| 632 | 706 | ||
| 633 | sw->clip = | 707 | sw->clip = |
| 634 | mixeng_clip | 708 | mixeng_clip |
| 635 | - [nchannels == 2] | 709 | + [sw->info.nchannels == 2] |
| 636 | [sw->info.sign] | 710 | [sw->info.sign] |
| 637 | [sw->info.swap_endian] | 711 | [sw->info.swap_endian] |
| 638 | [sw->info.bits == 16]; | 712 | [sw->info.bits == 16]; |
| @@ -699,6 +773,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) | @@ -699,6 +773,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) | ||
| 699 | 773 | ||
| 700 | if (audio_bug (AUDIO_FUNC, osamp < 0)) { | 774 | if (audio_bug (AUDIO_FUNC, osamp < 0)) { |
| 701 | dolog ("osamp=%d\n", osamp); | 775 | dolog ("osamp=%d\n", osamp); |
| 776 | + return 0; | ||
| 702 | } | 777 | } |
| 703 | 778 | ||
| 704 | st_rate_flow (sw->rate, src, dst, &isamp, &osamp); | 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,23 +792,6 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) | ||
| 717 | /* | 792 | /* |
| 718 | * Hard voice (playback) | 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 | static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) | 795 | static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) |
| 738 | { | 796 | { |
| 739 | if (hw->mix_buf) { | 797 | if (hw->mix_buf) { |
| @@ -745,37 +803,31 @@ static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) | @@ -745,37 +803,31 @@ static void audio_pcm_hw_free_resources_out (HWVoiceOut *hw) | ||
| 745 | 803 | ||
| 746 | static int audio_pcm_hw_alloc_resources_out (HWVoiceOut *hw) | 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 | if (!hw->mix_buf) { | 807 | if (!hw->mix_buf) { |
| 808 | + dolog ("Could not allocate DAC mixing buffer (%d bytes)\n", | ||
| 809 | + hw->samples * sizeof (st_sample_t)); | ||
| 750 | return -1; | 810 | return -1; |
| 751 | } | 811 | } |
| 752 | 812 | ||
| 753 | return 0; | 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 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live) | 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,8 +882,10 @@ static void audio_pcm_sw_free_resources_out (SWVoiceOut *sw) | ||
| 830 | 882 | ||
| 831 | static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw) | 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 | if (!sw->buf) { | 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 | return -1; | 889 | return -1; |
| 836 | } | 890 | } |
| 837 | 891 | ||
| @@ -844,14 +898,16 @@ static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw) | @@ -844,14 +898,16 @@ static int audio_pcm_sw_alloc_resources_out (SWVoiceOut *sw) | ||
| 844 | return 0; | 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 | sw->hw = hw; | 911 | sw->hw = hw; |
| 856 | sw->empty = 1; | 912 | sw->empty = 1; |
| 857 | sw->active = 0; | 913 | sw->active = 0; |
| @@ -860,7 +916,7 @@ static int audio_pcm_sw_init_out (SWVoiceOut *sw, HWVoiceOut *hw, | @@ -860,7 +916,7 @@ static int audio_pcm_sw_init_out (SWVoiceOut *sw, HWVoiceOut *hw, | ||
| 860 | 916 | ||
| 861 | sw->conv = | 917 | sw->conv = |
| 862 | mixeng_conv | 918 | mixeng_conv |
| 863 | - [nchannels == 2] | 919 | + [sw->info.nchannels == 2] |
| 864 | [sw->info.sign] | 920 | [sw->info.sign] |
| 865 | [sw->info.swap_endian] | 921 | [sw->info.swap_endian] |
| 866 | [sw->info.bits == 16]; | 922 | [sw->info.bits == 16]; |
| @@ -930,12 +986,11 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) | @@ -930,12 +986,11 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) | ||
| 930 | 986 | ||
| 931 | #ifdef DEBUG_OUT | 987 | #ifdef DEBUG_OUT |
| 932 | dolog ( | 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 | size >> sw->info.shift, | 991 | size >> sw->info.shift, |
| 936 | ret, | 992 | ret, |
| 937 | - sw->total_hw_samples_mixed, | ||
| 938 | - sw->hw->total_samples_played | 993 | + sw->total_hw_samples_mixed |
| 939 | ); | 994 | ); |
| 940 | #endif | 995 | #endif |
| 941 | 996 | ||
| @@ -965,7 +1020,7 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size) | @@ -965,7 +1020,7 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size) | ||
| 965 | } | 1020 | } |
| 966 | 1021 | ||
| 967 | if (!sw->hw->enabled) { | 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 | return 0; | 1024 | return 0; |
| 970 | } | 1025 | } |
| 971 | 1026 | ||
| @@ -983,7 +1038,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) | @@ -983,7 +1038,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) | ||
| 983 | } | 1038 | } |
| 984 | 1039 | ||
| 985 | if (!sw->hw->enabled) { | 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 | return 0; | 1042 | return 0; |
| 988 | } | 1043 | } |
| 989 | 1044 | ||
| @@ -993,7 +1048,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) | @@ -993,7 +1048,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) | ||
| 993 | 1048 | ||
| 994 | int AUD_get_buffer_size_out (SWVoiceOut *sw) | 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 | void AUD_set_active_out (SWVoiceOut *sw, int on) | 1054 | void AUD_set_active_out (SWVoiceOut *sw, int on) |
| @@ -1091,7 +1146,7 @@ static int audio_get_avail (SWVoiceIn *sw) | @@ -1091,7 +1146,7 @@ static int audio_get_avail (SWVoiceIn *sw) | ||
| 1091 | 1146 | ||
| 1092 | ldebug ( | 1147 | ldebug ( |
| 1093 | "%s: get_avail live %d ret %lld\n", | 1148 | "%s: get_avail live %d ret %lld\n", |
| 1094 | - sw->name, | 1149 | + SW_NAME (sw), |
| 1095 | live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift | 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,34 +1165,37 @@ static int audio_get_free (SWVoiceOut *sw) | ||
| 1110 | 1165 | ||
| 1111 | if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) { | 1166 | if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) { |
| 1112 | dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples); | 1167 | dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples); |
| 1168 | + return 0; | ||
| 1113 | } | 1169 | } |
| 1114 | 1170 | ||
| 1115 | dead = sw->hw->samples - live; | 1171 | dead = sw->hw->samples - live; |
| 1116 | 1172 | ||
| 1117 | #ifdef DEBUG_OUT | 1173 | #ifdef DEBUG_OUT |
| 1118 | dolog ("%s: get_free live %d dead %d ret %lld\n", | 1174 | dolog ("%s: get_free live %d dead %d ret %lld\n", |
| 1119 | - sw->name, | 1175 | + SW_NAME (sw), |
| 1120 | live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift); | 1176 | live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift); |
| 1121 | #endif | 1177 | #endif |
| 1122 | 1178 | ||
| 1123 | return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift; | 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 | HWVoiceOut *hw = NULL; | 1184 | HWVoiceOut *hw = NULL; |
| 1129 | SWVoiceOut *sw; | 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 | int played; | 1188 | int played; |
| 1133 | - int live, free, nb_live; | 1189 | + int live, free, nb_live, cleanup_required; |
| 1134 | 1190 | ||
| 1135 | live = audio_pcm_hw_get_live_out2 (hw, &nb_live); | 1191 | live = audio_pcm_hw_get_live_out2 (hw, &nb_live); |
| 1136 | if (!nb_live) { | 1192 | if (!nb_live) { |
| 1137 | live = 0; | 1193 | live = 0; |
| 1138 | } | 1194 | } |
| 1195 | + | ||
| 1139 | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { | 1196 | if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) { |
| 1140 | dolog ("live=%d hw->samples=%d\n", live, hw->samples); | 1197 | dolog ("live=%d hw->samples=%d\n", live, hw->samples); |
| 1198 | + continue; | ||
| 1141 | } | 1199 | } |
| 1142 | 1200 | ||
| 1143 | if (hw->pending_disable && !nb_live) { | 1201 | if (hw->pending_disable && !nb_live) { |
| @@ -1170,15 +1228,15 @@ static void audio_run_out (void) | @@ -1170,15 +1228,15 @@ static void audio_run_out (void) | ||
| 1170 | } | 1228 | } |
| 1171 | 1229 | ||
| 1172 | #ifdef DEBUG_OUT | 1230 | #ifdef DEBUG_OUT |
| 1173 | - dolog ("played = %d total %d\n", played, hw->total_samples_played); | 1231 | + dolog ("played=%d\n", played); |
| 1174 | #endif | 1232 | #endif |
| 1175 | 1233 | ||
| 1176 | if (played) { | 1234 | if (played) { |
| 1177 | hw->ts_helper += played; | 1235 | hw->ts_helper += played; |
| 1178 | } | 1236 | } |
| 1179 | 1237 | ||
| 1238 | + cleanup_required = 0; | ||
| 1180 | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { | 1239 | for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) { |
| 1181 | - again: | ||
| 1182 | if (!sw->active && sw->empty) { | 1240 | if (!sw->active && sw->empty) { |
| 1183 | continue; | 1241 | continue; |
| 1184 | } | 1242 | } |
| @@ -1193,22 +1251,7 @@ static void audio_run_out (void) | @@ -1193,22 +1251,7 @@ static void audio_run_out (void) | ||
| 1193 | 1251 | ||
| 1194 | if (!sw->total_hw_samples_mixed) { | 1252 | if (!sw->total_hw_samples_mixed) { |
| 1195 | sw->empty = 1; | 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 | if (sw->active) { | 1257 | if (sw->active) { |
| @@ -1218,14 +1261,27 @@ static void audio_run_out (void) | @@ -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 | HWVoiceIn *hw = NULL; | 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 | SWVoiceIn *sw; | 1285 | SWVoiceIn *sw; |
| 1230 | int captured, min; | 1286 | int captured, min; |
| 1231 | 1287 | ||
| @@ -1252,42 +1308,42 @@ static void audio_run_in (void) | @@ -1252,42 +1308,42 @@ static void audio_run_in (void) | ||
| 1252 | 1308 | ||
| 1253 | static struct audio_option audio_options[] = { | 1309 | static struct audio_option audio_options[] = { |
| 1254 | /* DAC */ | 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 | "Use fixed settings for host DAC", NULL, 0}, | 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 | "Frequency for fixed host DAC", NULL, 0}, | 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 | "Format for fixed host DAC", NULL, 0}, | 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 | "Number of channels for fixed DAC (1 - mono, 2 - stereo)", NULL, 0}, | 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 | "Number of voices for DAC", NULL, 0}, | 1324 | "Number of voices for DAC", NULL, 0}, |
| 1269 | 1325 | ||
| 1270 | /* ADC */ | 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 | "Use fixed settings for host ADC", NULL, 0}, | 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 | "Number of channels for fixed ADC (1 - mono, 2 - stereo)", NULL, 0}, | 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 | "Number of voices for ADC", NULL, 0}, | 1340 | "Number of voices for ADC", NULL, 0}, |
| 1285 | 1341 | ||
| 1286 | /* Misc */ | 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 | "(undocumented)", NULL, 0}, | 1347 | "(undocumented)", NULL, 0}, |
| 1292 | 1348 | ||
| 1293 | {NULL, 0, NULL, NULL, NULL, 0} | 1349 | {NULL, 0, NULL, NULL, NULL, 0} |
| @@ -1378,25 +1434,21 @@ void audio_timer (void *opaque) | @@ -1378,25 +1434,21 @@ void audio_timer (void *opaque) | ||
| 1378 | { | 1434 | { |
| 1379 | AudioState *s = opaque; | 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 | if (drv->options) { | 1445 | if (drv->options) { |
| 1390 | audio_process_options (drv->name, drv->options); | 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 | if (!drv->max_voices_out) { | 1452 | if (!drv->max_voices_out) { |
| 1401 | dolog ("`%s' does not support DAC\n", drv->name); | 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,30 +1457,13 @@ static int audio_driver_init (struct audio_driver *drv) | ||
| 1405 | "`%s' does not support %d multiple DAC voicess\n" | 1457 | "`%s' does not support %d multiple DAC voicess\n" |
| 1406 | "Resetting to %d\n", | 1458 | "Resetting to %d\n", |
| 1407 | drv->name, | 1459 | drv->name, |
| 1408 | - audio_state.nb_hw_voices_out, | 1460 | + s->nb_hw_voices_out, |
| 1409 | drv->max_voices_out | 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 | if (!drv->voice_size_in && drv->max_voices_in) { | 1468 | if (!drv->voice_size_in && drv->max_voices_in) { |
| 1434 | ldebug ("warning: No ADC voice size defined for `%s'\n", | 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,16 +1477,16 @@ static int audio_driver_init (struct audio_driver *drv) | ||
| 1442 | } | 1477 | } |
| 1443 | 1478 | ||
| 1444 | if (drv->voice_size_in && !drv->max_voices_in) { | 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 | if (drv->voice_size_out && !drv->max_voices_out) { | 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 | if (!drv->max_voices_in) { | 1490 | if (!drv->max_voices_in) { |
| 1456 | ldebug ("`%s' does not support ADC\n", drv->name); | 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,33 +1495,16 @@ static int audio_driver_init (struct audio_driver *drv) | ||
| 1460 | "`%s' does not support %d multiple ADC voices\n" | 1495 | "`%s' does not support %d multiple ADC voices\n" |
| 1461 | "Resetting to %d\n", | 1496 | "Resetting to %d\n", |
| 1462 | drv->name, | 1497 | drv->name, |
| 1463 | - audio_state.nb_hw_voices_in, | 1498 | + s->nb_hw_voices_in, |
| 1464 | drv->max_voices_in | 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 | return 0; | 1508 | return 0; |
| 1491 | } | 1509 | } |
| 1492 | else { | 1510 | else { |
| @@ -1497,12 +1515,12 @@ static int audio_driver_init (struct audio_driver *drv) | @@ -1497,12 +1515,12 @@ static int audio_driver_init (struct audio_driver *drv) | ||
| 1497 | 1515 | ||
| 1498 | static void audio_vm_stop_handler (void *opaque, int reason) | 1516 | static void audio_vm_stop_handler (void *opaque, int reason) |
| 1499 | { | 1517 | { |
| 1518 | + AudioState *s = opaque; | ||
| 1500 | HWVoiceOut *hwo = NULL; | 1519 | HWVoiceOut *hwo = NULL; |
| 1501 | HWVoiceIn *hwi = NULL; | 1520 | HWVoiceIn *hwi = NULL; |
| 1502 | int op = reason ? VOICE_ENABLE : VOICE_DISABLE; | 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 | if (!hwo->pcm_ops) { | 1524 | if (!hwo->pcm_ops) { |
| 1507 | continue; | 1525 | continue; |
| 1508 | } | 1526 | } |
| @@ -1512,7 +1530,7 @@ static void audio_vm_stop_handler (void *opaque, int reason) | @@ -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 | if (!hwi->pcm_ops) { | 1534 | if (!hwi->pcm_ops) { |
| 1517 | continue; | 1535 | continue; |
| 1518 | } | 1536 | } |
| @@ -1525,10 +1543,11 @@ static void audio_vm_stop_handler (void *opaque, int reason) | @@ -1525,10 +1543,11 @@ static void audio_vm_stop_handler (void *opaque, int reason) | ||
| 1525 | 1543 | ||
| 1526 | static void audio_atexit (void) | 1544 | static void audio_atexit (void) |
| 1527 | { | 1545 | { |
| 1546 | + AudioState *s = &glob_audio_state; | ||
| 1528 | HWVoiceOut *hwo = NULL; | 1547 | HWVoiceOut *hwo = NULL; |
| 1529 | HWVoiceIn *hwi = NULL; | 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 | if (!hwo->pcm_ops) { | 1551 | if (!hwo->pcm_ops) { |
| 1533 | continue; | 1552 | continue; |
| 1534 | } | 1553 | } |
| @@ -1539,7 +1558,7 @@ static void audio_atexit (void) | @@ -1539,7 +1558,7 @@ static void audio_atexit (void) | ||
| 1539 | hwo->pcm_ops->fini_out (hwo); | 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 | if (!hwi->pcm_ops) { | 1562 | if (!hwi->pcm_ops) { |
| 1544 | continue; | 1563 | continue; |
| 1545 | } | 1564 | } |
| @@ -1549,7 +1568,10 @@ static void audio_atexit (void) | @@ -1549,7 +1568,10 @@ static void audio_atexit (void) | ||
| 1549 | } | 1568 | } |
| 1550 | hwi->pcm_ops->fini_in (hwi); | 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 | static void audio_save (QEMUFile *f, void *opaque) | 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,15 +1592,33 @@ static int audio_load (QEMUFile *f, void *opaque, int version_id) | ||
| 1570 | return 0; | 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 | size_t i; | 1612 | size_t i; |
| 1576 | int done = 0; | 1613 | int done = 0; |
| 1577 | const char *drvname; | 1614 | const char *drvname; |
| 1578 | - AudioState *s = &audio_state; | 1615 | + AudioState *s = &glob_audio_state; |
| 1579 | 1616 | ||
| 1580 | audio_process_options ("AUDIO", audio_options); | 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 | if (s->nb_hw_voices_out <= 0) { | 1622 | if (s->nb_hw_voices_out <= 0) { |
| 1583 | dolog ("Bogus number of DAC voices %d\n", | 1623 | dolog ("Bogus number of DAC voices %d\n", |
| 1584 | s->nb_hw_voices_out); | 1624 | s->nb_hw_voices_out); |
| @@ -1598,8 +1638,8 @@ void AUD_init (void) | @@ -1598,8 +1638,8 @@ void AUD_init (void) | ||
| 1598 | 1638 | ||
| 1599 | s->ts = qemu_new_timer (vm_clock, audio_timer, s); | 1639 | s->ts = qemu_new_timer (vm_clock, audio_timer, s); |
| 1600 | if (!s->ts) { | 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 | if (drvname) { | 1645 | if (drvname) { |
| @@ -1607,7 +1647,7 @@ void AUD_init (void) | @@ -1607,7 +1647,7 @@ void AUD_init (void) | ||
| 1607 | 1647 | ||
| 1608 | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { | 1648 | for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
| 1609 | if (!strcmp (drvname, drvtab[i]->name)) { | 1649 | if (!strcmp (drvname, drvtab[i]->name)) { |
| 1610 | - done = !audio_driver_init (drvtab[i]); | 1650 | + done = !audio_driver_init (s, drvtab[i]); |
| 1611 | found = 1; | 1651 | found = 1; |
| 1612 | break; | 1652 | break; |
| 1613 | } | 1653 | } |
| @@ -1619,37 +1659,47 @@ void AUD_init (void) | @@ -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 | if (!done) { | 1662 | if (!done) { |
| 1626 | for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { | 1663 | for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) { |
| 1627 | if (drvtab[i]->can_be_default) { | 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 | if (!done) { | 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 | else { | 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 | else { | 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,18 +24,33 @@ | ||
| 24 | #ifndef QEMU_AUDIO_H | 24 | #ifndef QEMU_AUDIO_H |
| 25 | #define QEMU_AUDIO_H | 25 | #define QEMU_AUDIO_H |
| 26 | 26 | ||
| 27 | +#include "sys-queue.h" | ||
| 28 | + | ||
| 27 | typedef void (*audio_callback_fn_t) (void *opaque, int avail); | 29 | typedef void (*audio_callback_fn_t) (void *opaque, int avail); |
| 28 | 30 | ||
| 29 | typedef enum { | 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 | } audfmt_e; | 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 | typedef struct SWVoiceOut SWVoiceOut; | 45 | typedef struct SWVoiceOut SWVoiceOut; |
| 37 | typedef struct SWVoiceIn SWVoiceIn; | 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 | typedef struct QEMUAudioTimeStamp { | 54 | typedef struct QEMUAudioTimeStamp { |
| 40 | uint64_t old_ts; | 55 | uint64_t old_ts; |
| 41 | } QEMUAudioTimeStamp; | 56 | } QEMUAudioTimeStamp; |
| @@ -47,46 +62,45 @@ void AUD_log (const char *cap, const char *fmt, ...) | @@ -47,46 +62,45 @@ void AUD_log (const char *cap, const char *fmt, ...) | ||
| 47 | #endif | 62 | #endif |
| 48 | ; | 63 | ; |
| 49 | 64 | ||
| 50 | -void AUD_init (void); | 65 | +AudioState *AUD_init (void); |
| 51 | void AUD_help (void); | 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 | SWVoiceOut *sw, | 72 | SWVoiceOut *sw, |
| 55 | const char *name, | 73 | const char *name, |
| 56 | void *callback_opaque, | 74 | void *callback_opaque, |
| 57 | audio_callback_fn_t callback_fn, | 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 | SWVoiceIn *sw, | 90 | SWVoiceIn *sw, |
| 74 | const char *name, | 91 | const char *name, |
| 75 | void *callback_opaque, | 92 | void *callback_opaque, |
| 76 | audio_callback_fn_t callback_fn, | 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 | static inline void *advance (void *p, int incr) | 105 | static inline void *advance (void *p, int incr) |
| 92 | { | 106 | { |
audio/audio_int.h
| @@ -24,16 +24,12 @@ | @@ -24,16 +24,12 @@ | ||
| 24 | #ifndef QEMU_AUDIO_INT_H | 24 | #ifndef QEMU_AUDIO_INT_H |
| 25 | #define QEMU_AUDIO_INT_H | 25 | #define QEMU_AUDIO_INT_H |
| 26 | 26 | ||
| 27 | -#include "sys-queue.h" | ||
| 28 | - | ||
| 29 | #ifdef CONFIG_COREAUDIO | 27 | #ifdef CONFIG_COREAUDIO |
| 30 | #define FLOAT_MIXENG | 28 | #define FLOAT_MIXENG |
| 31 | /* #define RECIPROCAL */ | 29 | /* #define RECIPROCAL */ |
| 32 | #endif | 30 | #endif |
| 33 | #include "mixeng.h" | 31 | #include "mixeng.h" |
| 34 | 32 | ||
| 35 | -int audio_bug (const char *funcname, int cond); | ||
| 36 | - | ||
| 37 | struct audio_pcm_ops; | 33 | struct audio_pcm_ops; |
| 38 | 34 | ||
| 39 | typedef enum { | 35 | typedef enum { |
| @@ -69,7 +65,6 @@ struct audio_pcm_info { | @@ -69,7 +65,6 @@ struct audio_pcm_info { | ||
| 69 | }; | 65 | }; |
| 70 | 66 | ||
| 71 | typedef struct HWVoiceOut { | 67 | typedef struct HWVoiceOut { |
| 72 | - int active; | ||
| 73 | int enabled; | 68 | int enabled; |
| 74 | int pending_disable; | 69 | int pending_disable; |
| 75 | int valid; | 70 | int valid; |
| @@ -78,7 +73,6 @@ typedef struct HWVoiceOut { | @@ -78,7 +73,6 @@ typedef struct HWVoiceOut { | ||
| 78 | f_sample *clip; | 73 | f_sample *clip; |
| 79 | 74 | ||
| 80 | int rpos; | 75 | int rpos; |
| 81 | - int bufsize; | ||
| 82 | uint64_t ts_helper; | 76 | uint64_t ts_helper; |
| 83 | 77 | ||
| 84 | st_sample_t *mix_buf; | 78 | st_sample_t *mix_buf; |
| @@ -91,13 +85,11 @@ typedef struct HWVoiceOut { | @@ -91,13 +85,11 @@ typedef struct HWVoiceOut { | ||
| 91 | 85 | ||
| 92 | typedef struct HWVoiceIn { | 86 | typedef struct HWVoiceIn { |
| 93 | int enabled; | 87 | int enabled; |
| 94 | - int active; | ||
| 95 | struct audio_pcm_info info; | 88 | struct audio_pcm_info info; |
| 96 | 89 | ||
| 97 | t_sample *conv; | 90 | t_sample *conv; |
| 98 | 91 | ||
| 99 | int wpos; | 92 | int wpos; |
| 100 | - int bufsize; | ||
| 101 | int total_samples_captured; | 93 | int total_samples_captured; |
| 102 | uint64_t ts_helper; | 94 | uint64_t ts_helper; |
| 103 | 95 | ||
| @@ -109,58 +101,6 @@ typedef struct HWVoiceIn { | @@ -109,58 +101,6 @@ typedef struct HWVoiceIn { | ||
| 109 | LIST_ENTRY (HWVoiceIn) entries; | 101 | LIST_ENTRY (HWVoiceIn) entries; |
| 110 | } HWVoiceIn; | 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 | struct SWVoiceOut { | 104 | struct SWVoiceOut { |
| 165 | struct audio_pcm_info info; | 105 | struct audio_pcm_info info; |
| 166 | t_sample *conv; | 106 | t_sample *conv; |
| @@ -192,22 +132,58 @@ struct SWVoiceIn { | @@ -192,22 +132,58 @@ struct SWVoiceIn { | ||
| 192 | LIST_ENTRY (SWVoiceIn) entries; | 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 | struct audio_pcm_ops { | 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 | void (*fini_out)(HWVoiceOut *hw); | 151 | void (*fini_out)(HWVoiceOut *hw); |
| 198 | int (*run_out) (HWVoiceOut *hw); | 152 | int (*run_out) (HWVoiceOut *hw); |
| 199 | int (*write) (SWVoiceOut *sw, void *buf, int size); | 153 | int (*write) (SWVoiceOut *sw, void *buf, int size); |
| 200 | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); | 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 | void (*fini_in) (HWVoiceIn *hw); | 157 | void (*fini_in) (HWVoiceIn *hw); |
| 204 | int (*run_in) (HWVoiceIn *hw); | 158 | int (*run_in) (HWVoiceIn *hw); |
| 205 | int (*read) (SWVoiceIn *sw, void *buf, int size); | 159 | int (*read) (SWVoiceIn *sw, void *buf, int size); |
| 206 | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); | 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 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); | 187 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
| 212 | 188 | ||
| 213 | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); | 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,6 +193,9 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); | ||
| 217 | int audio_pcm_hw_get_live_out (HWVoiceOut *hw); | 193 | int audio_pcm_hw_get_live_out (HWVoiceOut *hw); |
| 218 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live); | 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 | #define VOICE_ENABLE 1 | 199 | #define VOICE_ENABLE 1 |
| 221 | #define VOICE_DISABLE 2 | 200 | #define VOICE_DISABLE 2 |
| 222 | 201 |
audio/audio_template.h
| @@ -32,6 +32,43 @@ | @@ -32,6 +32,43 @@ | ||
| 32 | #define SW glue (SWVoice, In) | 32 | #define SW glue (SWVoice, In) |
| 33 | #endif | 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 | static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw) | 72 | static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw) |
| 36 | { | 73 | { |
| 37 | glue (audio_pcm_sw_free_resources_, TYPE) (sw); | 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,89 +88,86 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw) | ||
| 51 | LIST_REMOVE (sw, entries); | 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 | if (!hw->sw_head.lh_first) { | 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 | return hw; | 114 | return hw; |
| 80 | } | 115 | } |
| 81 | } | 116 | } |
| 82 | return NULL; | 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 | return NULL; | 141 | return NULL; |
| 103 | } | 142 | } |
| 104 | 143 | ||
| 105 | static HW *glue (audio_pcm_hw_find_specific_, TYPE) ( | 144 | static HW *glue (audio_pcm_hw_find_specific_, TYPE) ( |
| 145 | + AudioState *s, | ||
| 106 | HW *hw, | 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 | return hw; | 152 | return hw; |
| 115 | } | 153 | } |
| 116 | } | 154 | } |
| 117 | return NULL; | 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 | HW *hw; | 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 | if (hw) { | 163 | if (hw) { |
| 130 | - hw->pcm_ops = audio_state.drv->pcm_ops; | 164 | + hw->pcm_ops = s->drv->pcm_ops; |
| 131 | if (!hw->pcm_ops) { | 165 | if (!hw->pcm_ops) { |
| 132 | return NULL; | 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 | return NULL; | 171 | return NULL; |
| 138 | } | 172 | } |
| 139 | else { | 173 | else { |
| @@ -144,66 +178,62 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) ( | @@ -144,66 +178,62 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) ( | ||
| 144 | return NULL; | 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 | HW *hw; | 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 | if (hw) { | 187 | if (hw) { |
| 158 | return hw; | 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 | if (hw) { | 193 | if (hw) { |
| 164 | return hw; | 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 | if (hw) { | 198 | if (hw) { |
| 169 | return hw; | 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 | static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( | 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 | SW *sw; | 211 | SW *sw; |
| 183 | HW *hw; | 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 | if (!sw) { | 223 | if (!sw) { |
| 224 | + dolog ("Could not allocate soft voice `%s' (%d bytes)\n", | ||
| 225 | + sw_name ? sw_name : "unknown", sizeof (*sw)); | ||
| 196 | goto err1; | 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 | if (!hw) { | 230 | if (!hw) { |
| 201 | goto err2; | 231 | goto err2; |
| 202 | } | 232 | } |
| 203 | 233 | ||
| 204 | glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw); | 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 | goto err3; | 237 | goto err3; |
| 208 | } | 238 | } |
| 209 | 239 | ||
| @@ -211,67 +241,86 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( | @@ -211,67 +241,86 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( | ||
| 211 | 241 | ||
| 212 | err3: | 242 | err3: |
| 213 | glue (audio_pcm_hw_del_sw_, TYPE) (sw); | 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 | err2: | 245 | err2: |
| 216 | qemu_free (sw); | 246 | qemu_free (sw); |
| 217 | err1: | 247 | err1: |
| 218 | return NULL; | 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 | if (sw) { | 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 | SW *glue (AUD_open_, TYPE) ( | 271 | SW *glue (AUD_open_, TYPE) ( |
| 272 | + QEMUSoundCard *card, | ||
| 232 | SW *sw, | 273 | SW *sw, |
| 233 | const char *name, | 274 | const char *name, |
| 234 | void *callback_opaque , | 275 | void *callback_opaque , |
| 235 | audio_callback_fn_t callback_fn, | 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 | #ifdef DAC | 281 | #ifdef DAC |
| 242 | int live = 0; | 282 | int live = 0; |
| 243 | SW *old_sw = NULL; | 283 | SW *old_sw = NULL; |
| 244 | #endif | 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 | goto fail; | 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 | goto fail; | 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 | goto fail; | 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 | return sw; | 309 | return sw; |
| 263 | } | 310 | } |
| 264 | 311 | ||
| 265 | #ifdef DAC | 312 | #ifdef DAC |
| 266 | - if (audio_state.plive && sw && (!sw->active && !sw->empty)) { | 313 | + if (conf.plive && sw && (!sw->active && !sw->empty)) { |
| 267 | live = sw->total_hw_samples_mixed; | 314 | live = sw->total_hw_samples_mixed; |
| 268 | 315 | ||
| 269 | #ifdef DEBUG_PLIVE | 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 | dolog ("Old %s freq %d, bits %d, channels %d\n", | 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 | dolog ("New %s freq %d, bits %d, channels %d\n", | 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 | nchannels); | 324 | nchannels); |
| 276 | #endif | 325 | #endif |
| 277 | 326 | ||
| @@ -283,8 +332,8 @@ SW *glue (AUD_open_, TYPE) ( | @@ -283,8 +332,8 @@ SW *glue (AUD_open_, TYPE) ( | ||
| 283 | } | 332 | } |
| 284 | #endif | 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 | sw = NULL; | 337 | sw = NULL; |
| 289 | } | 338 | } |
| 290 | 339 | ||
| @@ -292,30 +341,19 @@ SW *glue (AUD_open_, TYPE) ( | @@ -292,30 +341,19 @@ SW *glue (AUD_open_, TYPE) ( | ||
| 292 | HW *hw = sw->hw; | 341 | HW *hw = sw->hw; |
| 293 | 342 | ||
| 294 | if (!hw) { | 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 | goto fail; | 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 | goto fail; | 350 | goto fail; |
| 309 | } | 351 | } |
| 310 | } | 352 | } |
| 311 | else { | 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 | if (!sw) { | 355 | if (!sw) { |
| 318 | - dolog ("Failed to create voice %s\n", name); | 356 | + dolog ("Failed to create voice `%s'\n", name); |
| 319 | goto fail; | 357 | goto fail; |
| 320 | } | 358 | } |
| 321 | } | 359 | } |
| @@ -349,7 +387,7 @@ SW *glue (AUD_open_, TYPE) ( | @@ -349,7 +387,7 @@ SW *glue (AUD_open_, TYPE) ( | ||
| 349 | return sw; | 387 | return sw; |
| 350 | 388 | ||
| 351 | fail: | 389 | fail: |
| 352 | - glue (AUD_close_, TYPE) (sw); | 390 | + glue (AUD_close_, TYPE) (card, sw); |
| 353 | return NULL; | 391 | return NULL; |
| 354 | } | 392 | } |
| 355 | 393 | ||
| @@ -367,10 +405,7 @@ void glue (AUD_init_time_stamp_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts) | @@ -367,10 +405,7 @@ void glue (AUD_init_time_stamp_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts) | ||
| 367 | ts->old_ts = sw->hw->ts_helper; | 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 | uint64_t delta, cur_ts, old_ts; | 410 | uint64_t delta, cur_ts, old_ts; |
| 376 | 411 |
audio/coreaudio.c
| @@ -31,8 +31,6 @@ | @@ -31,8 +31,6 @@ | ||
| 31 | #define AUDIO_CAP "coreaudio" | 31 | #define AUDIO_CAP "coreaudio" |
| 32 | #include "audio_int.h" | 32 | #include "audio_int.h" |
| 33 | 33 | ||
| 34 | -#define DEVICE_BUFFER_FRAMES (512) | ||
| 35 | - | ||
| 36 | struct { | 34 | struct { |
| 37 | int buffer_frames; | 35 | int buffer_frames; |
| 38 | } conf = { | 36 | } conf = { |
| @@ -132,7 +130,7 @@ static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 ( | @@ -132,7 +130,7 @@ static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 ( | ||
| 132 | { | 130 | { |
| 133 | va_list ap; | 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 | va_start (ap, fmt); | 135 | va_start (ap, fmt); |
| 138 | AUD_vlog (AUDIO_CAP, fmt, ap); | 136 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| @@ -147,7 +145,7 @@ static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name) | @@ -147,7 +145,7 @@ static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name) | ||
| 147 | 145 | ||
| 148 | err = pthread_mutex_lock (&core->mutex); | 146 | err = pthread_mutex_lock (&core->mutex); |
| 149 | if (err) { | 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 | fn_name, strerror (err)); | 149 | fn_name, strerror (err)); |
| 152 | return -1; | 150 | return -1; |
| 153 | } | 151 | } |
| @@ -160,7 +158,7 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name) | @@ -160,7 +158,7 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name) | ||
| 160 | 158 | ||
| 161 | err = pthread_mutex_unlock (&core->mutex); | 159 | err = pthread_mutex_unlock (&core->mutex); |
| 162 | if (err) { | 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 | fn_name, strerror (err)); | 162 | fn_name, strerror (err)); |
| 165 | return -1; | 163 | return -1; |
| 166 | } | 164 | } |
| @@ -268,8 +266,7 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len) | @@ -268,8 +266,7 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len) | ||
| 268 | return audio_pcm_sw_write (sw, buf, len); | 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 | OSStatus status; | 271 | OSStatus status; |
| 275 | coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; | 272 | coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; |
| @@ -282,25 +279,22 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -282,25 +279,22 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 282 | /* create mutex */ | 279 | /* create mutex */ |
| 283 | err = pthread_mutex_init(&core->mutex, NULL); | 280 | err = pthread_mutex_init(&core->mutex, NULL); |
| 284 | if (err) { | 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 | return -1; | 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 | bits = 16; | 287 | bits = 16; |
| 291 | endianess = 1; | 288 | endianess = 1; |
| 292 | } | 289 | } |
| 293 | 290 | ||
| 294 | audio_pcm_init_info ( | 291 | audio_pcm_init_info ( |
| 295 | &hw->info, | 292 | &hw->info, |
| 296 | - freq, | ||
| 297 | - nchannels, | ||
| 298 | - fmt, | 293 | + as, |
| 299 | /* Following is irrelevant actually since we do not use | 294 | /* Following is irrelevant actually since we do not use |
| 300 | mixengs clipping routines */ | 295 | mixengs clipping routines */ |
| 301 | audio_need_to_swap_endian (endianess) | 296 | audio_need_to_swap_endian (endianess) |
| 302 | ); | 297 | ); |
| 303 | - hw->bufsize = 4 * conf.buffer_frames * nchannels * bits; | ||
| 304 | 298 | ||
| 305 | /* open default output device */ | 299 | /* open default output device */ |
| 306 | propertySize = sizeof(core->outputDeviceID); | 300 | propertySize = sizeof(core->outputDeviceID); |
| @@ -310,18 +304,18 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -310,18 +304,18 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 310 | &core->outputDeviceID); | 304 | &core->outputDeviceID); |
| 311 | if (status != kAudioHardwareNoError) { | 305 | if (status != kAudioHardwareNoError) { |
| 312 | coreaudio_logerr2 (status, typ, | 306 | coreaudio_logerr2 (status, typ, |
| 313 | - "Can not get default output Device\n"); | 307 | + "Could not get default output Device\n"); |
| 314 | return -1; | 308 | return -1; |
| 315 | } | 309 | } |
| 316 | if (core->outputDeviceID == kAudioDeviceUnknown) { | 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 | return -1; | 312 | return -1; |
| 319 | } | 313 | } |
| 320 | 314 | ||
| 321 | /* set Buffersize to conf.buffer_frames frames */ | 315 | /* set Buffersize to conf.buffer_frames frames */ |
| 322 | propertySize = sizeof(core->audioDevicePropertyBufferSize); | 316 | propertySize = sizeof(core->audioDevicePropertyBufferSize); |
| 323 | core->audioDevicePropertyBufferSize = | 317 | core->audioDevicePropertyBufferSize = |
| 324 | - conf.buffer_frames * sizeof(float) * 2; | 318 | + conf.buffer_frames * sizeof(float) << (as->nchannels == 2); |
| 325 | status = AudioDeviceSetProperty( | 319 | status = AudioDeviceSetProperty( |
| 326 | core->outputDeviceID, | 320 | core->outputDeviceID, |
| 327 | NULL, | 321 | NULL, |
| @@ -332,7 +326,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -332,7 +326,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 332 | &core->audioDevicePropertyBufferSize); | 326 | &core->audioDevicePropertyBufferSize); |
| 333 | if (status != kAudioHardwareNoError) { | 327 | if (status != kAudioHardwareNoError) { |
| 334 | coreaudio_logerr2 (status, typ, | 328 | coreaudio_logerr2 (status, typ, |
| 335 | - "Can not set device buffer size %d\n", | 329 | + "Could not set device buffer size %d\n", |
| 336 | kAudioDevicePropertyBufferSize); | 330 | kAudioDevicePropertyBufferSize); |
| 337 | return -1; | 331 | return -1; |
| 338 | } | 332 | } |
| @@ -347,9 +341,11 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -347,9 +341,11 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 347 | &propertySize, | 341 | &propertySize, |
| 348 | &core->audioDevicePropertyBufferSize); | 342 | &core->audioDevicePropertyBufferSize); |
| 349 | if (status != kAudioHardwareNoError) { | 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 | return -1; | 345 | return -1; |
| 352 | } | 346 | } |
| 347 | + hw->samples = (core->audioDevicePropertyBufferSize / sizeof (float)) | ||
| 348 | + >> (as->nchannels == 2); | ||
| 353 | 349 | ||
| 354 | /* get StreamFormat */ | 350 | /* get StreamFormat */ |
| 355 | propertySize = sizeof(core->outputStreamBasicDescription); | 351 | propertySize = sizeof(core->outputStreamBasicDescription); |
| @@ -362,13 +358,13 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -362,13 +358,13 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 362 | &core->outputStreamBasicDescription); | 358 | &core->outputStreamBasicDescription); |
| 363 | if (status != kAudioHardwareNoError) { | 359 | if (status != kAudioHardwareNoError) { |
| 364 | coreaudio_logerr2 (status, typ, | 360 | coreaudio_logerr2 (status, typ, |
| 365 | - "Can not get Device Stream properties\n"); | 361 | + "Could not get Device Stream properties\n"); |
| 366 | core->outputDeviceID = kAudioDeviceUnknown; | 362 | core->outputDeviceID = kAudioDeviceUnknown; |
| 367 | return -1; | 363 | return -1; |
| 368 | } | 364 | } |
| 369 | 365 | ||
| 370 | /* set Samplerate */ | 366 | /* set Samplerate */ |
| 371 | - core->outputStreamBasicDescription.mSampleRate = (Float64)freq; | 367 | + core->outputStreamBasicDescription.mSampleRate = (Float64)as->freq; |
| 372 | propertySize = sizeof(core->outputStreamBasicDescription); | 368 | propertySize = sizeof(core->outputStreamBasicDescription); |
| 373 | status = AudioDeviceSetProperty( | 369 | status = AudioDeviceSetProperty( |
| 374 | core->outputDeviceID, | 370 | core->outputDeviceID, |
| @@ -379,7 +375,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -379,7 +375,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 379 | propertySize, | 375 | propertySize, |
| 380 | &core->outputStreamBasicDescription); | 376 | &core->outputStreamBasicDescription); |
| 381 | if (status != kAudioHardwareNoError) { | 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 | core->outputDeviceID = kAudioDeviceUnknown; | 379 | core->outputDeviceID = kAudioDeviceUnknown; |
| 384 | return -1; | 380 | return -1; |
| 385 | } | 381 | } |
| @@ -387,7 +383,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -387,7 +383,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 387 | /* set Callback */ | 383 | /* set Callback */ |
| 388 | status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw); | 384 | status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw); |
| 389 | if (status != kAudioHardwareNoError) { | 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 | core->outputDeviceID = kAudioDeviceUnknown; | 387 | core->outputDeviceID = kAudioDeviceUnknown; |
| 392 | return -1; | 388 | return -1; |
| 393 | } | 389 | } |
| @@ -396,7 +392,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | @@ -396,7 +392,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, int freq, | ||
| 396 | if (!core->isPlaying) { | 392 | if (!core->isPlaying) { |
| 397 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); | 393 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); |
| 398 | if (status != kAudioHardwareNoError) { | 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 | AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); | 396 | AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); |
| 401 | core->outputDeviceID = kAudioDeviceUnknown; | 397 | core->outputDeviceID = kAudioDeviceUnknown; |
| 402 | return -1; | 398 | return -1; |
| @@ -417,7 +413,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) | @@ -417,7 +413,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw) | ||
| 417 | if (core->isPlaying) { | 413 | if (core->isPlaying) { |
| 418 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); | 414 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); |
| 419 | if (status != kAudioHardwareNoError) { | 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 | core->isPlaying = 0; | 418 | core->isPlaying = 0; |
| 423 | } | 419 | } |
| @@ -425,14 +421,14 @@ static void coreaudio_fini_out (HWVoiceOut *hw) | @@ -425,14 +421,14 @@ static void coreaudio_fini_out (HWVoiceOut *hw) | ||
| 425 | /* remove callback */ | 421 | /* remove callback */ |
| 426 | status = AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); | 422 | status = AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc); |
| 427 | if (status != kAudioHardwareNoError) { | 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 | core->outputDeviceID = kAudioDeviceUnknown; | 426 | core->outputDeviceID = kAudioDeviceUnknown; |
| 431 | 427 | ||
| 432 | /* destroy mutex */ | 428 | /* destroy mutex */ |
| 433 | err = pthread_mutex_destroy(&core->mutex); | 429 | err = pthread_mutex_destroy(&core->mutex); |
| 434 | if (err) { | 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,7 +443,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 447 | if (!core->isPlaying) { | 443 | if (!core->isPlaying) { |
| 448 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); | 444 | status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc); |
| 449 | if (status != kAudioHardwareNoError) { | 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 | core->isPlaying = 1; | 448 | core->isPlaying = 1; |
| 453 | } | 449 | } |
| @@ -458,7 +454,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -458,7 +454,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 458 | if (core->isPlaying) { | 454 | if (core->isPlaying) { |
| 459 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); | 455 | status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc); |
| 460 | if (status != kAudioHardwareNoError) { | 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 | core->isPlaying = 0; | 459 | core->isPlaying = 0; |
| 464 | } | 460 | } |
audio/dsound_template.h
| @@ -47,7 +47,7 @@ static int glue (dsound_unlock_, TYPE) ( | @@ -47,7 +47,7 @@ static int glue (dsound_unlock_, TYPE) ( | ||
| 47 | 47 | ||
| 48 | hr = glue (IFACE, _Unlock) (buf, p1, blen1, p2, blen2); | 48 | hr = glue (IFACE, _Unlock) (buf, p1, blen1, p2, blen2); |
| 49 | if (FAILED (hr)) { | 49 | if (FAILED (hr)) { |
| 50 | - dsound_logerr (hr, "Can not unlock " NAME "\n"); | 50 | + dsound_logerr (hr, "Could not unlock " NAME "\n"); |
| 51 | return -1; | 51 | return -1; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| @@ -93,13 +93,13 @@ static int glue (dsound_lock_, TYPE) ( | @@ -93,13 +93,13 @@ static int glue (dsound_lock_, TYPE) ( | ||
| 93 | #ifndef DSBTYPE_IN | 93 | #ifndef DSBTYPE_IN |
| 94 | if (hr == DSERR_BUFFERLOST) { | 94 | if (hr == DSERR_BUFFERLOST) { |
| 95 | if (glue (dsound_restore_, TYPE) (buf)) { | 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 | goto fail; | 97 | goto fail; |
| 98 | } | 98 | } |
| 99 | continue; | 99 | continue; |
| 100 | } | 100 | } |
| 101 | #endif | 101 | #endif |
| 102 | - dsound_logerr (hr, "Can not lock " NAME "\n"); | 102 | + dsound_logerr (hr, "Could not lock " NAME "\n"); |
| 103 | goto fail; | 103 | goto fail; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -158,38 +158,28 @@ static void dsound_fini_out (HWVoiceOut *hw) | @@ -158,38 +158,28 @@ static void dsound_fini_out (HWVoiceOut *hw) | ||
| 158 | if (ds->FIELD) { | 158 | if (ds->FIELD) { |
| 159 | hr = glue (IFACE, _Stop) (ds->FIELD); | 159 | hr = glue (IFACE, _Stop) (ds->FIELD); |
| 160 | if (FAILED (hr)) { | 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 | hr = glue (IFACE, _Release) (ds->FIELD); | 164 | hr = glue (IFACE, _Release) (ds->FIELD); |
| 165 | if (FAILED (hr)) { | 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 | ds->FIELD = NULL; | 168 | ds->FIELD = NULL; |
| 169 | } | 169 | } |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | #ifdef DSBTYPE_IN | 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 | #else | 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 | #endif | 176 | #endif |
| 187 | { | 177 | { |
| 188 | int err; | 178 | int err; |
| 189 | HRESULT hr; | 179 | HRESULT hr; |
| 190 | dsound *s = &glob_dsound; | 180 | dsound *s = &glob_dsound; |
| 191 | WAVEFORMATEX wfx; | 181 | WAVEFORMATEX wfx; |
| 192 | - struct full_fmt full_fmt; | 182 | + audsettings_t obt_as; |
| 193 | #ifdef DSBTYPE_IN | 183 | #ifdef DSBTYPE_IN |
| 194 | const char *typ = "ADC"; | 184 | const char *typ = "ADC"; |
| 195 | DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; | 185 | DSoundVoiceIn *ds = (DSoundVoiceIn *) hw; |
| @@ -202,10 +192,7 @@ static int dsound_init_out ( | @@ -202,10 +192,7 @@ static int dsound_init_out ( | ||
| 202 | DSBCAPS bc; | 192 | DSBCAPS bc; |
| 203 | #endif | 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 | if (err) { | 196 | if (err) { |
| 210 | return -1; | 197 | return -1; |
| 211 | } | 198 | } |
| @@ -233,18 +220,13 @@ static int dsound_init_out ( | @@ -233,18 +220,13 @@ static int dsound_init_out ( | ||
| 233 | #endif | 220 | #endif |
| 234 | 221 | ||
| 235 | if (FAILED (hr)) { | 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 | return -1; | 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 | if (FAILED (hr)) { | 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 | goto fail0; | 230 | goto fail0; |
| 249 | } | 231 | } |
| 250 | 232 | ||
| @@ -258,31 +240,33 @@ static int dsound_init_out ( | @@ -258,31 +240,33 @@ static int dsound_init_out ( | ||
| 258 | 240 | ||
| 259 | hr = glue (IFACE, _GetCaps) (ds->FIELD, &bc); | 241 | hr = glue (IFACE, _GetCaps) (ds->FIELD, &bc); |
| 260 | if (FAILED (hr)) { | 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 | goto fail0; | 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 | if (err) { | 248 | if (err) { |
| 267 | goto fail0; | 249 | goto fail0; |
| 268 | } | 250 | } |
| 269 | 251 | ||
| 270 | ds->first_time = 1; | 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 | #ifdef DEBUG_DSOUND | 264 | #ifdef DEBUG_DSOUND |
| 281 | dolog ("caps %ld, desc %ld\n", | 265 | dolog ("caps %ld, desc %ld\n", |
| 282 | bc.dwBufferBytes, bd.dwBufferBytes); | 266 | bc.dwBufferBytes, bd.dwBufferBytes); |
| 283 | 267 | ||
| 284 | dolog ("bufsize %d, freq %d, chan %d, fmt %d\n", | 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 | #endif | 270 | #endif |
| 287 | return 0; | 271 | return 0; |
| 288 | 272 |
audio/dsoundaudio.c
| @@ -37,12 +37,6 @@ | @@ -37,12 +37,6 @@ | ||
| 37 | 37 | ||
| 38 | /* #define DEBUG_DSOUND */ | 38 | /* #define DEBUG_DSOUND */ |
| 39 | 39 | ||
| 40 | -struct full_fmt { | ||
| 41 | - int freq; | ||
| 42 | - int nchannels; | ||
| 43 | - audfmt_e fmt; | ||
| 44 | -}; | ||
| 45 | - | ||
| 46 | static struct { | 40 | static struct { |
| 47 | int lock_retries; | 41 | int lock_retries; |
| 48 | int restore_retries; | 42 | int restore_retries; |
| @@ -50,7 +44,7 @@ static struct { | @@ -50,7 +44,7 @@ static struct { | ||
| 50 | int set_primary; | 44 | int set_primary; |
| 51 | int bufsize_in; | 45 | int bufsize_in; |
| 52 | int bufsize_out; | 46 | int bufsize_out; |
| 53 | - struct full_fmt full_fmt; | 47 | + audsettings_t settings; |
| 54 | int latency_millis; | 48 | int latency_millis; |
| 55 | } conf = { | 49 | } conf = { |
| 56 | 1, | 50 | 1, |
| @@ -71,7 +65,7 @@ typedef struct { | @@ -71,7 +65,7 @@ typedef struct { | ||
| 71 | LPDIRECTSOUND dsound; | 65 | LPDIRECTSOUND dsound; |
| 72 | LPDIRECTSOUNDCAPTURE dsound_capture; | 66 | LPDIRECTSOUNDCAPTURE dsound_capture; |
| 73 | LPDIRECTSOUNDBUFFER dsound_primary_buffer; | 67 | LPDIRECTSOUNDBUFFER dsound_primary_buffer; |
| 74 | - struct full_fmt fmt; | 68 | + audsettings_t settings; |
| 75 | } dsound; | 69 | } dsound; |
| 76 | 70 | ||
| 77 | static dsound glob_dsound; | 71 | static dsound glob_dsound; |
| @@ -259,7 +253,7 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( | @@ -259,7 +253,7 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 ( | ||
| 259 | { | 253 | { |
| 260 | va_list ap; | 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 | va_start (ap, fmt); | 257 | va_start (ap, fmt); |
| 264 | AUD_vlog (AUDIO_CAP, fmt, ap); | 258 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| 265 | va_end (ap); | 259 | va_end (ap); |
| @@ -301,7 +295,7 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) | @@ -301,7 +295,7 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) | ||
| 301 | continue; | 295 | continue; |
| 302 | 296 | ||
| 303 | default: | 297 | default: |
| 304 | - dsound_logerr (hr, "Can not restore playback buffer\n"); | 298 | + dsound_logerr (hr, "Could not restore playback buffer\n"); |
| 305 | return -1; | 299 | return -1; |
| 306 | } | 300 | } |
| 307 | } | 301 | } |
| @@ -310,19 +304,18 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) | @@ -310,19 +304,18 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb) | ||
| 310 | return -1; | 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 | memset (wfx, 0, sizeof (*wfx)); | 309 | memset (wfx, 0, sizeof (*wfx)); |
| 317 | 310 | ||
| 318 | wfx->wFormatTag = WAVE_FORMAT_PCM; | 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 | wfx->cbSize = 0; | 316 | wfx->cbSize = 0; |
| 324 | 317 | ||
| 325 | - switch (full_fmt->fmt) { | 318 | + switch (as->fmt) { |
| 326 | case AUD_FMT_S8: | 319 | case AUD_FMT_S8: |
| 327 | wfx->wBitsPerSample = 8; | 320 | wfx->wBitsPerSample = 8; |
| 328 | break; | 321 | break; |
| @@ -344,16 +337,14 @@ static int waveformat_from_full_fmt (WAVEFORMATEX *wfx, | @@ -344,16 +337,14 @@ static int waveformat_from_full_fmt (WAVEFORMATEX *wfx, | ||
| 344 | break; | 337 | break; |
| 345 | 338 | ||
| 346 | default: | 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 | return -1; | 341 | return -1; |
| 350 | } | 342 | } |
| 351 | 343 | ||
| 352 | return 0; | 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 | if (wfx->wFormatTag != WAVE_FORMAT_PCM) { | 349 | if (wfx->wFormatTag != WAVE_FORMAT_PCM) { |
| 359 | dolog ("Invalid wave format, tag is not PCM, but %d\n", | 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,15 +356,15 @@ static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, | ||
| 365 | dolog ("Invalid wave format, frequency is zero\n"); | 356 | dolog ("Invalid wave format, frequency is zero\n"); |
| 366 | return -1; | 357 | return -1; |
| 367 | } | 358 | } |
| 368 | - full_fmt->freq = wfx->nSamplesPerSec; | 359 | + as->freq = wfx->nSamplesPerSec; |
| 369 | 360 | ||
| 370 | switch (wfx->nChannels) { | 361 | switch (wfx->nChannels) { |
| 371 | case 1: | 362 | case 1: |
| 372 | - full_fmt->nchannels = 1; | 363 | + as->nchannels = 1; |
| 373 | break; | 364 | break; |
| 374 | 365 | ||
| 375 | case 2: | 366 | case 2: |
| 376 | - full_fmt->nchannels = 2; | 367 | + as->nchannels = 2; |
| 377 | break; | 368 | break; |
| 378 | 369 | ||
| 379 | default: | 370 | default: |
| @@ -386,11 +377,11 @@ static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, | @@ -386,11 +377,11 @@ static int waveformat_to_full_fmt (WAVEFORMATEX *wfx, | ||
| 386 | 377 | ||
| 387 | switch (wfx->wBitsPerSample) { | 378 | switch (wfx->wBitsPerSample) { |
| 388 | case 8: | 379 | case 8: |
| 389 | - full_fmt->fmt = AUD_FMT_U8; | 380 | + as->fmt = AUD_FMT_U8; |
| 390 | break; | 381 | break; |
| 391 | 382 | ||
| 392 | case 16: | 383 | case 16: |
| 393 | - full_fmt->fmt = AUD_FMT_S16; | 384 | + as->fmt = AUD_FMT_S16; |
| 394 | break; | 385 | break; |
| 395 | 386 | ||
| 396 | default: | 387 | default: |
| @@ -415,7 +406,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp) | @@ -415,7 +406,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp) | ||
| 415 | for (i = 0; i < conf.getstatus_retries; ++i) { | 406 | for (i = 0; i < conf.getstatus_retries; ++i) { |
| 416 | hr = IDirectSoundBuffer_GetStatus (dsb, statusp); | 407 | hr = IDirectSoundBuffer_GetStatus (dsb, statusp); |
| 417 | if (FAILED (hr)) { | 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 | return -1; | 410 | return -1; |
| 420 | } | 411 | } |
| 421 | 412 | ||
| @@ -438,7 +429,7 @@ static int dsound_get_status_in (LPDIRECTSOUNDCAPTUREBUFFER dscb, | @@ -438,7 +429,7 @@ static int dsound_get_status_in (LPDIRECTSOUNDCAPTUREBUFFER dscb, | ||
| 438 | 429 | ||
| 439 | hr = IDirectSoundCaptureBuffer_GetStatus (dscb, statusp); | 430 | hr = IDirectSoundCaptureBuffer_GetStatus (dscb, statusp); |
| 440 | if (FAILED (hr)) { | 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 | return -1; | 433 | return -1; |
| 443 | } | 434 | } |
| 444 | 435 | ||
| @@ -520,7 +511,7 @@ static void dsound_close (dsound *s) | @@ -520,7 +511,7 @@ static void dsound_close (dsound *s) | ||
| 520 | if (s->dsound_primary_buffer) { | 511 | if (s->dsound_primary_buffer) { |
| 521 | hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer); | 512 | hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer); |
| 522 | if (FAILED (hr)) { | 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 | s->dsound_primary_buffer = NULL; | 516 | s->dsound_primary_buffer = NULL; |
| 526 | } | 517 | } |
| @@ -542,7 +533,7 @@ static int dsound_open (dsound *s) | @@ -542,7 +533,7 @@ static int dsound_open (dsound *s) | ||
| 542 | ); | 533 | ); |
| 543 | 534 | ||
| 544 | if (FAILED (hr)) { | 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 | hwnd); | 537 | hwnd); |
| 547 | return -1; | 538 | return -1; |
| 548 | } | 539 | } |
| @@ -551,7 +542,7 @@ static int dsound_open (dsound *s) | @@ -551,7 +542,7 @@ static int dsound_open (dsound *s) | ||
| 551 | return 0; | 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 | if (err) { | 546 | if (err) { |
| 556 | return -1; | 547 | return -1; |
| 557 | } | 548 | } |
| @@ -569,13 +560,13 @@ static int dsound_open (dsound *s) | @@ -569,13 +560,13 @@ static int dsound_open (dsound *s) | ||
| 569 | NULL | 560 | NULL |
| 570 | ); | 561 | ); |
| 571 | if (FAILED (hr)) { | 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 | return -1; | 564 | return -1; |
| 574 | } | 565 | } |
| 575 | 566 | ||
| 576 | hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx); | 567 | hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx); |
| 577 | if (FAILED (hr)) { | 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 | hr = IDirectSoundBuffer_GetFormat ( | 572 | hr = IDirectSoundBuffer_GetFormat ( |
| @@ -585,7 +576,7 @@ static int dsound_open (dsound *s) | @@ -585,7 +576,7 @@ static int dsound_open (dsound *s) | ||
| 585 | NULL | 576 | NULL |
| 586 | ); | 577 | ); |
| 587 | if (FAILED (hr)) { | 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 | goto fail0; | 580 | goto fail0; |
| 590 | } | 581 | } |
| 591 | 582 | ||
| @@ -594,7 +585,7 @@ static int dsound_open (dsound *s) | @@ -594,7 +585,7 @@ static int dsound_open (dsound *s) | ||
| 594 | print_wave_format (&wfx); | 585 | print_wave_format (&wfx); |
| 595 | #endif | 586 | #endif |
| 596 | 587 | ||
| 597 | - err = waveformat_to_full_fmt (&wfx, &s->fmt); | 588 | + err = waveformat_to_audio_settings (&wfx, &s->settings); |
| 598 | if (err) { | 589 | if (err) { |
| 599 | goto fail0; | 590 | goto fail0; |
| 600 | } | 591 | } |
| @@ -625,7 +616,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -625,7 +616,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 625 | } | 616 | } |
| 626 | 617 | ||
| 627 | if (status & DSBSTATUS_PLAYING) { | 618 | if (status & DSBSTATUS_PLAYING) { |
| 628 | - dolog ("warning: voice is already playing\n"); | 619 | + dolog ("warning: Voice is already playing\n"); |
| 629 | return 0; | 620 | return 0; |
| 630 | } | 621 | } |
| 631 | 622 | ||
| @@ -633,7 +624,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -633,7 +624,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 633 | 624 | ||
| 634 | hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING); | 625 | hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING); |
| 635 | if (FAILED (hr)) { | 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 | return -1; | 628 | return -1; |
| 638 | } | 629 | } |
| 639 | break; | 630 | break; |
| @@ -646,12 +637,12 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -646,12 +637,12 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 646 | if (status & DSBSTATUS_PLAYING) { | 637 | if (status & DSBSTATUS_PLAYING) { |
| 647 | hr = IDirectSoundBuffer_Stop (dsb); | 638 | hr = IDirectSoundBuffer_Stop (dsb); |
| 648 | if (FAILED (hr)) { | 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 | return -1; | 641 | return -1; |
| 651 | } | 642 | } |
| 652 | } | 643 | } |
| 653 | else { | 644 | else { |
| 654 | - dolog ("warning: voice is not playing\n"); | 645 | + dolog ("warning: Voice is not playing\n"); |
| 655 | } | 646 | } |
| 656 | break; | 647 | break; |
| 657 | } | 648 | } |
| @@ -675,6 +666,7 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -675,6 +666,7 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 675 | DWORD decr; | 666 | DWORD decr; |
| 676 | DWORD wpos, ppos, old_pos; | 667 | DWORD wpos, ppos, old_pos; |
| 677 | LPVOID p1, p2; | 668 | LPVOID p1, p2; |
| 669 | + int bufsize; | ||
| 678 | 670 | ||
| 679 | if (!dsb) { | 671 | if (!dsb) { |
| 680 | dolog ("Attempt to run empty with playback buffer\n"); | 672 | dolog ("Attempt to run empty with playback buffer\n"); |
| @@ -682,6 +674,7 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -682,6 +674,7 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 682 | } | 674 | } |
| 683 | 675 | ||
| 684 | hwshift = hw->info.shift; | 676 | hwshift = hw->info.shift; |
| 677 | + bufsize = hw->samples << hwshift; | ||
| 685 | 678 | ||
| 686 | live = audio_pcm_hw_get_live_out (hw); | 679 | live = audio_pcm_hw_get_live_out (hw); |
| 687 | 680 | ||
| @@ -691,7 +684,7 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -691,7 +684,7 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 691 | ds->first_time ? &wpos : NULL | 684 | ds->first_time ? &wpos : NULL |
| 692 | ); | 685 | ); |
| 693 | if (FAILED (hr)) { | 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 | return 0; | 688 | return 0; |
| 696 | } | 689 | } |
| 697 | 690 | ||
| @@ -699,13 +692,14 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -699,13 +692,14 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 699 | 692 | ||
| 700 | if (ds->first_time) { | 693 | if (ds->first_time) { |
| 701 | if (conf.latency_millis) { | 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 | ds->first_time = 0; | 698 | ds->first_time = 0; |
| 705 | old_pos = wpos; | 699 | old_pos = wpos; |
| 706 | old_pos += | 700 | old_pos += |
| 707 | millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat; | 701 | millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat; |
| 708 | - old_pos %= hw->bufsize; | 702 | + old_pos %= bufsize; |
| 709 | old_pos &= ~hw->info.align; | 703 | old_pos &= ~hw->info.align; |
| 710 | } | 704 | } |
| 711 | else { | 705 | else { |
| @@ -734,14 +728,14 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -734,14 +728,14 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 734 | len = ppos - old_pos; | 728 | len = ppos - old_pos; |
| 735 | } | 729 | } |
| 736 | else { | 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 | return 0; | 739 | return 0; |
| 746 | } | 740 | } |
| 747 | 741 | ||
| @@ -779,7 +773,7 @@ static int dsound_run_out (HWVoiceOut *hw) | @@ -779,7 +773,7 @@ static int dsound_run_out (HWVoiceOut *hw) | ||
| 779 | } | 773 | } |
| 780 | 774 | ||
| 781 | dsound_unlock_out (dsb, p1, p2, blen1, blen2); | 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 | #ifdef DEBUG_DSOUND | 778 | #ifdef DEBUG_DSOUND |
| 785 | ds->mixed += decr << hwshift; | 779 | ds->mixed += decr << hwshift; |
| @@ -812,7 +806,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | @@ -812,7 +806,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | ||
| 812 | } | 806 | } |
| 813 | 807 | ||
| 814 | if (status & DSCBSTATUS_CAPTURING) { | 808 | if (status & DSCBSTATUS_CAPTURING) { |
| 815 | - dolog ("warning: voice is already capturing\n"); | 809 | + dolog ("warning: Voice is already capturing\n"); |
| 816 | return 0; | 810 | return 0; |
| 817 | } | 811 | } |
| 818 | 812 | ||
| @@ -820,7 +814,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | @@ -820,7 +814,7 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | ||
| 820 | 814 | ||
| 821 | hr = IDirectSoundCaptureBuffer_Start (dscb, DSCBSTART_LOOPING); | 815 | hr = IDirectSoundCaptureBuffer_Start (dscb, DSCBSTART_LOOPING); |
| 822 | if (FAILED (hr)) { | 816 | if (FAILED (hr)) { |
| 823 | - dsound_logerr (hr, "Can not start capturing\n"); | 817 | + dsound_logerr (hr, "Could not start capturing\n"); |
| 824 | return -1; | 818 | return -1; |
| 825 | } | 819 | } |
| 826 | break; | 820 | break; |
| @@ -833,12 +827,12 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | @@ -833,12 +827,12 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...) | ||
| 833 | if (status & DSCBSTATUS_CAPTURING) { | 827 | if (status & DSCBSTATUS_CAPTURING) { |
| 834 | hr = IDirectSoundCaptureBuffer_Stop (dscb); | 828 | hr = IDirectSoundCaptureBuffer_Stop (dscb); |
| 835 | if (FAILED (hr)) { | 829 | if (FAILED (hr)) { |
| 836 | - dsound_logerr (hr, "Can not stop capturing\n"); | 830 | + dsound_logerr (hr, "Could not stop capturing\n"); |
| 837 | return -1; | 831 | return -1; |
| 838 | } | 832 | } |
| 839 | } | 833 | } |
| 840 | else { | 834 | else { |
| 841 | - dolog ("warning: voice is not capturing\n"); | 835 | + dolog ("warning: Voice is not capturing\n"); |
| 842 | } | 836 | } |
| 843 | break; | 837 | break; |
| 844 | } | 838 | } |
| @@ -883,21 +877,21 @@ static int dsound_run_in (HWVoiceIn *hw) | @@ -883,21 +877,21 @@ static int dsound_run_in (HWVoiceIn *hw) | ||
| 883 | ds->first_time ? &rpos : NULL | 877 | ds->first_time ? &rpos : NULL |
| 884 | ); | 878 | ); |
| 885 | if (FAILED (hr)) { | 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 | return 0; | 881 | return 0; |
| 888 | } | 882 | } |
| 889 | 883 | ||
| 890 | if (ds->first_time) { | 884 | if (ds->first_time) { |
| 891 | ds->first_time = 0; | 885 | ds->first_time = 0; |
| 892 | if (rpos & hw->info.align) { | 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 | rpos, hw->info.align); | 888 | rpos, hw->info.align); |
| 895 | } | 889 | } |
| 896 | hw->wpos = rpos >> hwshift; | 890 | hw->wpos = rpos >> hwshift; |
| 897 | } | 891 | } |
| 898 | 892 | ||
| 899 | if (cpos & hw->info.align) { | 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 | cpos, hw->info.align); | 895 | cpos, hw->info.align); |
| 902 | } | 896 | } |
| 903 | cpos >>= hwshift; | 897 | cpos >>= hwshift; |
| @@ -951,7 +945,7 @@ static void dsound_audio_fini (void *opaque) | @@ -951,7 +945,7 @@ static void dsound_audio_fini (void *opaque) | ||
| 951 | 945 | ||
| 952 | hr = IDirectSound_Release (s->dsound); | 946 | hr = IDirectSound_Release (s->dsound); |
| 953 | if (FAILED (hr)) { | 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 | s->dsound = NULL; | 950 | s->dsound = NULL; |
| 957 | 951 | ||
| @@ -961,7 +955,7 @@ static void dsound_audio_fini (void *opaque) | @@ -961,7 +955,7 @@ static void dsound_audio_fini (void *opaque) | ||
| 961 | 955 | ||
| 962 | hr = IDirectSoundCapture_Release (s->dsound_capture); | 956 | hr = IDirectSoundCapture_Release (s->dsound_capture); |
| 963 | if (FAILED (hr)) { | 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 | s->dsound_capture = NULL; | 960 | s->dsound_capture = NULL; |
| 967 | } | 961 | } |
| @@ -974,7 +968,7 @@ static void *dsound_audio_init (void) | @@ -974,7 +968,7 @@ static void *dsound_audio_init (void) | ||
| 974 | 968 | ||
| 975 | hr = CoInitialize (NULL); | 969 | hr = CoInitialize (NULL); |
| 976 | if (FAILED (hr)) { | 970 | if (FAILED (hr)) { |
| 977 | - dsound_logerr (hr, "Can not initialize COM\n"); | 971 | + dsound_logerr (hr, "Could not initialize COM\n"); |
| 978 | return NULL; | 972 | return NULL; |
| 979 | } | 973 | } |
| 980 | 974 | ||
| @@ -986,13 +980,13 @@ static void *dsound_audio_init (void) | @@ -986,13 +980,13 @@ static void *dsound_audio_init (void) | ||
| 986 | (void **) &s->dsound | 980 | (void **) &s->dsound |
| 987 | ); | 981 | ); |
| 988 | if (FAILED (hr)) { | 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 | return NULL; | 984 | return NULL; |
| 991 | } | 985 | } |
| 992 | 986 | ||
| 993 | hr = IDirectSound_Initialize (s->dsound, NULL); | 987 | hr = IDirectSound_Initialize (s->dsound, NULL); |
| 994 | if (FAILED (hr)) { | 988 | if (FAILED (hr)) { |
| 995 | - dsound_logerr (hr, "Can not initialize DirectSound\n"); | 989 | + dsound_logerr (hr, "Could not initialize DirectSound\n"); |
| 996 | return NULL; | 990 | return NULL; |
| 997 | } | 991 | } |
| 998 | 992 | ||
| @@ -1004,16 +998,16 @@ static void *dsound_audio_init (void) | @@ -1004,16 +998,16 @@ static void *dsound_audio_init (void) | ||
| 1004 | (void **) &s->dsound_capture | 998 | (void **) &s->dsound_capture |
| 1005 | ); | 999 | ); |
| 1006 | if (FAILED (hr)) { | 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 | else { | 1003 | else { |
| 1010 | hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL); | 1004 | hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL); |
| 1011 | if (FAILED (hr)) { | 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 | hr = IDirectSoundCapture_Release (s->dsound_capture); | 1008 | hr = IDirectSoundCapture_Release (s->dsound_capture); |
| 1015 | if (FAILED (hr)) { | 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 | s->dsound_capture = NULL; | 1012 | s->dsound_capture = NULL; |
| 1019 | } | 1013 | } |
| @@ -1039,11 +1033,11 @@ static struct audio_option dsound_options[] = { | @@ -1039,11 +1033,11 @@ static struct audio_option dsound_options[] = { | ||
| 1039 | "Set the parameters of primary buffer", NULL, 0}, | 1033 | "Set the parameters of primary buffer", NULL, 0}, |
| 1040 | {"LATENCY_MILLIS", AUD_OPT_INT, &conf.latency_millis, | 1034 | {"LATENCY_MILLIS", AUD_OPT_INT, &conf.latency_millis, |
| 1041 | "(undocumented)", NULL, 0}, | 1035 | "(undocumented)", NULL, 0}, |
| 1042 | - {"PRIMARY_FREQ", AUD_OPT_INT, &conf.full_fmt.freq, | 1036 | + {"PRIMARY_FREQ", AUD_OPT_INT, &conf.settings.freq, |
| 1043 | "Primary buffer frequency", NULL, 0}, | 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 | "Primary buffer number of channels (1 - mono, 2 - stereo)", NULL, 0}, | 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 | "Primary buffer format", NULL, 0}, | 1041 | "Primary buffer format", NULL, 0}, |
| 1048 | {"BUFSIZE_OUT", AUD_OPT_INT, &conf.bufsize_out, | 1042 | {"BUFSIZE_OUT", AUD_OPT_INT, &conf.bufsize_out, |
| 1049 | "(undocumented)", NULL, 0}, | 1043 | "(undocumented)", NULL, 0}, |
audio/fmodaudio.c
| @@ -78,7 +78,7 @@ static void GCC_FMT_ATTR (2, 3) fmod_logerr2 ( | @@ -78,7 +78,7 @@ static void GCC_FMT_ATTR (2, 3) fmod_logerr2 ( | ||
| 78 | { | 78 | { |
| 79 | va_list ap; | 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 | va_start (ap, fmt); | 83 | va_start (ap, fmt); |
| 84 | AUD_vlog (AUDIO_CAP, fmt, ap); | 84 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| @@ -356,17 +356,17 @@ static void fmod_fini_out (HWVoiceOut *hw) | @@ -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 | int bits16, mode, channel; | 361 | int bits16, mode, channel; |
| 362 | FMODVoiceOut *fmd = (FMODVoiceOut *) hw; | 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 | fmd->fmod_sample = FSOUND_Sample_Alloc ( | 365 | fmd->fmod_sample = FSOUND_Sample_Alloc ( |
| 366 | FSOUND_FREE, /* index */ | 366 | FSOUND_FREE, /* index */ |
| 367 | conf.nb_samples, /* length */ | 367 | conf.nb_samples, /* length */ |
| 368 | mode, /* mode */ | 368 | mode, /* mode */ |
| 369 | - freq, /* freq */ | 369 | + as->freq, /* freq */ |
| 370 | 255, /* volume */ | 370 | 255, /* volume */ |
| 371 | 128, /* pan */ | 371 | 128, /* pan */ |
| 372 | 255 /* priority */ | 372 | 255 /* priority */ |
| @@ -386,10 +386,9 @@ static int fmod_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | @@ -386,10 +386,9 @@ static int fmod_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 386 | fmd->channel = channel; | 386 | fmd->channel = channel; |
| 387 | 387 | ||
| 388 | /* FMOD always operates on little endian frames? */ | 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 | bits16 = (mode & FSOUND_16BITS) != 0; | 390 | bits16 = (mode & FSOUND_16BITS) != 0; |
| 392 | - hw->bufsize = conf.nb_samples << (nchannels == 2) << bits16; | 391 | + hw->samples = conf.nb_samples; |
| 393 | return 0; | 392 | return 0; |
| 394 | } | 393 | } |
| 395 | 394 | ||
| @@ -417,7 +416,7 @@ static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -417,7 +416,7 @@ static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 417 | return 0; | 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 | int bits16, mode; | 421 | int bits16, mode; |
| 423 | FMODVoiceIn *fmd = (FMODVoiceIn *) hw; | 422 | FMODVoiceIn *fmd = (FMODVoiceIn *) hw; |
| @@ -426,12 +425,12 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | @@ -426,12 +425,12 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 426 | return -1; | 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 | fmd->fmod_sample = FSOUND_Sample_Alloc ( | 429 | fmd->fmod_sample = FSOUND_Sample_Alloc ( |
| 431 | FSOUND_FREE, /* index */ | 430 | FSOUND_FREE, /* index */ |
| 432 | conf.nb_samples, /* length */ | 431 | conf.nb_samples, /* length */ |
| 433 | mode, /* mode */ | 432 | mode, /* mode */ |
| 434 | - freq, /* freq */ | 433 | + as->freq, /* freq */ |
| 435 | 255, /* volume */ | 434 | 255, /* volume */ |
| 436 | 128, /* pan */ | 435 | 128, /* pan */ |
| 437 | 255 /* priority */ | 436 | 255 /* priority */ |
| @@ -443,10 +442,9 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | @@ -443,10 +442,9 @@ static int fmod_init_in (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 443 | } | 442 | } |
| 444 | 443 | ||
| 445 | /* FMOD always operates on little endian frames? */ | 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 | bits16 = (mode & FSOUND_16BITS) != 0; | 446 | bits16 = (mode & FSOUND_16BITS) != 0; |
| 449 | - hw->bufsize = conf.nb_samples << (nchannels == 2) << bits16; | 447 | + hw->samples = conf.nb_samples; |
| 450 | return 0; | 448 | return 0; |
| 451 | } | 449 | } |
| 452 | 450 | ||
| @@ -479,7 +477,7 @@ static int fmod_run_in (HWVoiceIn *hw) | @@ -479,7 +477,7 @@ static int fmod_run_in (HWVoiceIn *hw) | ||
| 479 | 477 | ||
| 480 | new_pos = FSOUND_Record_GetPosition (); | 478 | new_pos = FSOUND_Record_GetPosition (); |
| 481 | if (new_pos < 0) { | 479 | if (new_pos < 0) { |
| 482 | - fmod_logerr ("Can not get recording position\n"); | 480 | + fmod_logerr ("Could not get recording position\n"); |
| 483 | return 0; | 481 | return 0; |
| 484 | } | 482 | } |
| 485 | 483 |
audio/mixeng.c
| @@ -228,21 +228,22 @@ f_sample *mixeng_clip[2][2][2][2] = { | @@ -228,21 +228,22 @@ f_sample *mixeng_clip[2][2][2][2] = { | ||
| 228 | */ | 228 | */ |
| 229 | 229 | ||
| 230 | /* Private data */ | 230 | /* Private data */ |
| 231 | -typedef struct ratestuff { | 231 | +struct rate { |
| 232 | uint64_t opos; | 232 | uint64_t opos; |
| 233 | uint64_t opos_inc; | 233 | uint64_t opos_inc; |
| 234 | uint32_t ipos; /* position in the input stream (integer) */ | 234 | uint32_t ipos; /* position in the input stream (integer) */ |
| 235 | st_sample_t ilast; /* last sample in the input stream */ | 235 | st_sample_t ilast; /* last sample in the input stream */ |
| 236 | -} *rate_t; | 236 | +}; |
| 237 | 237 | ||
| 238 | /* | 238 | /* |
| 239 | * Prepare processing. | 239 | * Prepare processing. |
| 240 | */ | 240 | */ |
| 241 | void *st_rate_start (int inrate, int outrate) | 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 | if (!rate) { | 245 | if (!rate) { |
| 246 | + dolog ("Could not allocate resampler (%d bytes)\n", sizeof (*rate)); | ||
| 246 | return NULL; | 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,11 +67,10 @@ static int no_write (SWVoiceOut *sw, void *buf, int len) | ||
| 67 | return audio_pcm_sw_write (sw, buf, len); | 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 | return 0; | 74 | return 0; |
| 76 | } | 75 | } |
| 77 | 76 | ||
| @@ -87,11 +86,10 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -87,11 +86,10 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 87 | return 0; | 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 | return 0; | 93 | return 0; |
| 96 | } | 94 | } |
| 97 | 95 |
audio/ossaudio.c
| @@ -91,7 +91,7 @@ static void GCC_FMT_ATTR (3, 4) oss_logerr2 ( | @@ -91,7 +91,7 @@ static void GCC_FMT_ATTR (3, 4) oss_logerr2 ( | ||
| 91 | { | 91 | { |
| 92 | va_list ap; | 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 | va_start (ap, fmt); | 96 | va_start (ap, fmt); |
| 97 | AUD_vlog (AUDIO_CAP, fmt, ap); | 97 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| @@ -179,7 +179,7 @@ static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness) | @@ -179,7 +179,7 @@ static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness) | ||
| 179 | return 0; | 179 | return 0; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | -#ifdef DEBUG_MISMATCHES | 182 | +#if defined DEBUG_MISMATCHES || defined DEBUG |
| 183 | static void oss_dump_info (struct oss_params *req, struct oss_params *obt) | 183 | static void oss_dump_info (struct oss_params *req, struct oss_params *obt) |
| 184 | { | 184 | { |
| 185 | dolog ("parameter | requested value | obtained value\n"); | 185 | dolog ("parameter | requested value | obtained value\n"); |
| @@ -253,16 +253,16 @@ static int oss_open (int in, struct oss_params *req, | @@ -253,16 +253,16 @@ static int oss_open (int in, struct oss_params *req, | ||
| 253 | obt->fragsize = abinfo.fragsize; | 253 | obt->fragsize = abinfo.fragsize; |
| 254 | *pfd = fd; | 254 | *pfd = fd; |
| 255 | 255 | ||
| 256 | +#ifdef DEBUG_MISMATCHES | ||
| 256 | if ((req->fmt != obt->fmt) || | 257 | if ((req->fmt != obt->fmt) || |
| 257 | (req->nchannels != obt->nchannels) || | 258 | (req->nchannels != obt->nchannels) || |
| 258 | (req->freq != obt->freq) || | 259 | (req->freq != obt->freq) || |
| 259 | (req->fragsize != obt->fragsize) || | 260 | (req->fragsize != obt->fragsize) || |
| 260 | (req->nfrags != obt->nfrags)) { | 261 | (req->nfrags != obt->nfrags)) { |
| 261 | -#ifdef DEBUG_MISMATCHES | ||
| 262 | dolog ("Audio parameters mismatch\n"); | 262 | dolog ("Audio parameters mismatch\n"); |
| 263 | oss_dump_info (req, obt); | 263 | oss_dump_info (req, obt); |
| 264 | -#endif | ||
| 265 | } | 264 | } |
| 265 | +#endif | ||
| 266 | 266 | ||
| 267 | #ifdef DEBUG | 267 | #ifdef DEBUG |
| 268 | oss_dump_info (req, obt); | 268 | oss_dump_info (req, obt); |
| @@ -283,12 +283,15 @@ static int oss_run_out (HWVoiceOut *hw) | @@ -283,12 +283,15 @@ static int oss_run_out (HWVoiceOut *hw) | ||
| 283 | st_sample_t *src; | 283 | st_sample_t *src; |
| 284 | struct audio_buf_info abinfo; | 284 | struct audio_buf_info abinfo; |
| 285 | struct count_info cntinfo; | 285 | struct count_info cntinfo; |
| 286 | + int bufsize; | ||
| 286 | 287 | ||
| 287 | live = audio_pcm_hw_get_live_out (hw); | 288 | live = audio_pcm_hw_get_live_out (hw); |
| 288 | if (!live) { | 289 | if (!live) { |
| 289 | return 0; | 290 | return 0; |
| 290 | } | 291 | } |
| 291 | 292 | ||
| 293 | + bufsize = hw->samples << hw->info.shift; | ||
| 294 | + | ||
| 292 | if (oss->mmapped) { | 295 | if (oss->mmapped) { |
| 293 | int bytes; | 296 | int bytes; |
| 294 | 297 | ||
| @@ -300,7 +303,7 @@ static int oss_run_out (HWVoiceOut *hw) | @@ -300,7 +303,7 @@ static int oss_run_out (HWVoiceOut *hw) | ||
| 300 | 303 | ||
| 301 | if (cntinfo.ptr == oss->old_optr) { | 304 | if (cntinfo.ptr == oss->old_optr) { |
| 302 | if (abs (hw->samples - live) < 64) { | 305 | if (abs (hw->samples - live) < 64) { |
| 303 | - dolog ("warning: overrun\n"); | 306 | + dolog ("warning: Overrun\n"); |
| 304 | } | 307 | } |
| 305 | return 0; | 308 | return 0; |
| 306 | } | 309 | } |
| @@ -309,7 +312,7 @@ static int oss_run_out (HWVoiceOut *hw) | @@ -309,7 +312,7 @@ static int oss_run_out (HWVoiceOut *hw) | ||
| 309 | bytes = cntinfo.ptr - oss->old_optr; | 312 | bytes = cntinfo.ptr - oss->old_optr; |
| 310 | } | 313 | } |
| 311 | else { | 314 | else { |
| 312 | - bytes = hw->bufsize + cntinfo.ptr - oss->old_optr; | 315 | + bytes = bufsize + cntinfo.ptr - oss->old_optr; |
| 313 | } | 316 | } |
| 314 | 317 | ||
| 315 | decr = audio_MIN (bytes >> hw->info.shift, live); | 318 | decr = audio_MIN (bytes >> hw->info.shift, live); |
| @@ -321,9 +324,9 @@ static int oss_run_out (HWVoiceOut *hw) | @@ -321,9 +324,9 @@ static int oss_run_out (HWVoiceOut *hw) | ||
| 321 | return 0; | 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 | return 0; | 330 | return 0; |
| 328 | } | 331 | } |
| 329 | 332 | ||
| @@ -362,7 +365,7 @@ static int oss_run_out (HWVoiceOut *hw) | @@ -362,7 +365,7 @@ static int oss_run_out (HWVoiceOut *hw) | ||
| 362 | int wsamples = written >> hw->info.shift; | 365 | int wsamples = written >> hw->info.shift; |
| 363 | int wbytes = wsamples << hw->info.shift; | 366 | int wbytes = wsamples << hw->info.shift; |
| 364 | if (wbytes != written) { | 367 | if (wbytes != written) { |
| 365 | - dolog ("warning: misaligned write %d (requested %d), " | 368 | + dolog ("warning: Misaligned write %d (requested %d), " |
| 366 | "alignment %d\n", | 369 | "alignment %d\n", |
| 367 | wbytes, written, hw->info.align + 1); | 370 | wbytes, written, hw->info.align + 1); |
| 368 | } | 371 | } |
| @@ -396,10 +399,10 @@ static void oss_fini_out (HWVoiceOut *hw) | @@ -396,10 +399,10 @@ static void oss_fini_out (HWVoiceOut *hw) | ||
| 396 | 399 | ||
| 397 | if (oss->pcm_buf) { | 400 | if (oss->pcm_buf) { |
| 398 | if (oss->mmapped) { | 401 | if (oss->mmapped) { |
| 399 | - err = munmap (oss->pcm_buf, hw->bufsize); | 402 | + err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
| 400 | if (err) { | 403 | if (err) { |
| 401 | oss_logerr (errno, "Failed to unmap buffer %p, size %d\n", | 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 | else { | 408 | else { |
| @@ -409,7 +412,7 @@ static void oss_fini_out (HWVoiceOut *hw) | @@ -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 | OSSVoiceOut *oss = (OSSVoiceOut *) hw; | 417 | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
| 415 | struct oss_params req, obt; | 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,10 +420,11 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 417 | int err; | 420 | int err; |
| 418 | int fd; | 421 | int fd; |
| 419 | audfmt_e effective_fmt; | 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 | req.fragsize = conf.fragsize; | 428 | req.fragsize = conf.fragsize; |
| 425 | req.nfrags = conf.nfrags; | 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,24 +438,38 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 434 | return -1; | 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 | audio_pcm_init_info ( | 445 | audio_pcm_init_info ( |
| 438 | &hw->info, | 446 | &hw->info, |
| 439 | - obt.freq, | ||
| 440 | - obt.nchannels, | ||
| 441 | - effective_fmt, | 447 | + &obt_as, |
| 442 | audio_need_to_swap_endian (endianness) | 448 | audio_need_to_swap_endian (endianness) |
| 443 | ); | 449 | ); |
| 444 | oss->nfrags = obt.nfrags; | 450 | oss->nfrags = obt.nfrags; |
| 445 | oss->fragsize = obt.fragsize; | 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 | oss->mmapped = 0; | 460 | oss->mmapped = 0; |
| 449 | if (conf.try_mmap) { | 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 | if (oss->pcm_buf == MAP_FAILED) { | 470 | if (oss->pcm_buf == MAP_FAILED) { |
| 453 | oss_logerr (errno, "Failed to map %d bytes of DAC\n", | 471 | oss_logerr (errno, "Failed to map %d bytes of DAC\n", |
| 454 | - hw->bufsize); | 472 | + hw->samples << hw->info.shift); |
| 455 | } else { | 473 | } else { |
| 456 | int err; | 474 | int err; |
| 457 | int trig = 0; | 475 | int trig = 0; |
| @@ -472,18 +490,24 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | @@ -472,18 +490,24 @@ static int oss_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 472 | } | 490 | } |
| 473 | 491 | ||
| 474 | if (!oss->mmapped) { | 492 | if (!oss->mmapped) { |
| 475 | - err = munmap (oss->pcm_buf, hw->bufsize); | 493 | + err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
| 476 | if (err) { | 494 | if (err) { |
| 477 | oss_logerr (errno, "Failed to unmap buffer %p size %d\n", | 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 | if (!oss->mmapped) { | 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 | if (!oss->pcm_buf) { | 508 | if (!oss->pcm_buf) { |
| 509 | + dolog ("Could not allocate DAC buffer (%d bytes)\n", | ||
| 510 | + hw->samples << hw->info.shift); | ||
| 487 | oss_anal_close (&fd); | 511 | oss_anal_close (&fd); |
| 488 | return -1; | 512 | return -1; |
| 489 | } | 513 | } |
| @@ -528,8 +552,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) | @@ -528,8 +552,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) | ||
| 528 | return 0; | 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 | OSSVoiceIn *oss = (OSSVoiceIn *) hw; | 557 | OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
| 535 | struct oss_params req, obt; | 558 | struct oss_params req, obt; |
| @@ -537,10 +560,11 @@ static int oss_init_in (HWVoiceIn *hw, | @@ -537,10 +560,11 @@ static int oss_init_in (HWVoiceIn *hw, | ||
| 537 | int err; | 560 | int err; |
| 538 | int fd; | 561 | int fd; |
| 539 | audfmt_e effective_fmt; | 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 | req.fragsize = conf.fragsize; | 568 | req.fragsize = conf.fragsize; |
| 545 | req.nfrags = conf.nfrags; | 569 | req.nfrags = conf.nfrags; |
| 546 | if (oss_open (1, &req, &obt, &fd)) { | 570 | if (oss_open (1, &req, &obt, &fd)) { |
| @@ -553,18 +577,28 @@ static int oss_init_in (HWVoiceIn *hw, | @@ -553,18 +577,28 @@ static int oss_init_in (HWVoiceIn *hw, | ||
| 553 | return -1; | 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 | audio_pcm_init_info ( | 584 | audio_pcm_init_info ( |
| 557 | &hw->info, | 585 | &hw->info, |
| 558 | - obt.freq, | ||
| 559 | - obt.nchannels, | ||
| 560 | - effective_fmt, | 586 | + &obt_as, |
| 561 | audio_need_to_swap_endian (endianness) | 587 | audio_need_to_swap_endian (endianness) |
| 562 | ); | 588 | ); |
| 563 | oss->nfrags = obt.nfrags; | 589 | oss->nfrags = obt.nfrags; |
| 564 | oss->fragsize = obt.fragsize; | 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 | if (!oss->pcm_buf) { | 599 | if (!oss->pcm_buf) { |
| 600 | + dolog ("Could not allocate ADC buffer (%d bytes)\n", | ||
| 601 | + hw->samples << hw->info.shift); | ||
| 568 | oss_anal_close (&fd); | 602 | oss_anal_close (&fd); |
| 569 | return -1; | 603 | return -1; |
| 570 | } | 604 | } |
| @@ -623,7 +657,7 @@ static int oss_run_in (HWVoiceIn *hw) | @@ -623,7 +657,7 @@ static int oss_run_in (HWVoiceIn *hw) | ||
| 623 | 657 | ||
| 624 | if (nread > 0) { | 658 | if (nread > 0) { |
| 625 | if (nread & hw->info.align) { | 659 | if (nread & hw->info.align) { |
| 626 | - dolog ("warning: misaligned read %d (requested %d), " | 660 | + dolog ("warning: Misaligned read %d (requested %d), " |
| 627 | "alignment %d\n", nread, bufs[i].add << hwshift, | 661 | "alignment %d\n", nread, bufs[i].add << hwshift, |
| 628 | hw->info.align + 1); | 662 | hw->info.align + 1); |
| 629 | } | 663 | } |
audio/rate_template.h
| @@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
| 30 | void NAME (void *opaque, st_sample_t *ibuf, st_sample_t *obuf, | 30 | void NAME (void *opaque, st_sample_t *ibuf, st_sample_t *obuf, |
| 31 | int *isamp, int *osamp) | 31 | int *isamp, int *osamp) |
| 32 | { | 32 | { |
| 33 | - rate_t rate = (rate_t) opaque; | 33 | + struct rate *rate = opaque; |
| 34 | st_sample_t *istart, *iend; | 34 | st_sample_t *istart, *iend; |
| 35 | st_sample_t *ostart, *oend; | 35 | st_sample_t *ostart, *oend; |
| 36 | st_sample_t ilast, icur, out; | 36 | st_sample_t ilast, icur, out; |
audio/sdlaudio.c
| @@ -303,7 +303,7 @@ static void sdl_fini_out (HWVoiceOut *hw) | @@ -303,7 +303,7 @@ static void sdl_fini_out (HWVoiceOut *hw) | ||
| 303 | sdl_close (&glob_sdl); | 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 | SDLVoiceOut *sdl = (SDLVoiceOut *) hw; | 308 | SDLVoiceOut *sdl = (SDLVoiceOut *) hw; |
| 309 | SDLAudioState *s = &glob_sdl; | 309 | SDLAudioState *s = &glob_sdl; |
| @@ -312,18 +312,14 @@ static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | @@ -312,18 +312,14 @@ static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 312 | int endianess; | 312 | int endianess; |
| 313 | int err; | 313 | int err; |
| 314 | audfmt_e effective_fmt; | 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 | req.samples = conf.nb_samples; | 322 | req.samples = conf.nb_samples; |
| 325 | - shift <<= nchannels == 2; | ||
| 326 | - | ||
| 327 | req.callback = sdl_callback; | 323 | req.callback = sdl_callback; |
| 328 | req.userdata = sdl; | 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,14 +333,16 @@ static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 337 | return -1; | 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 | audio_pcm_init_info ( | 340 | audio_pcm_init_info ( |
| 341 | &hw->info, | 341 | &hw->info, |
| 342 | - obt.freq, | ||
| 343 | - obt.channels, | ||
| 344 | - effective_fmt, | 342 | + &obt_as, |
| 345 | audio_need_to_swap_endian (endianess) | 343 | audio_need_to_swap_endian (endianess) |
| 346 | ); | 344 | ); |
| 347 | - hw->bufsize = obt.samples << shift; | 345 | + hw->samples = obt.samples; |
| 348 | 346 | ||
| 349 | s->initialized = 1; | 347 | s->initialized = 1; |
| 350 | s->exit = 0; | 348 | s->exit = 0; |
audio/wavaudio.c
| @@ -35,9 +35,15 @@ typedef struct WAVVoiceOut { | @@ -35,9 +35,15 @@ typedef struct WAVVoiceOut { | ||
| 35 | } WAVVoiceOut; | 35 | } WAVVoiceOut; |
| 36 | 36 | ||
| 37 | static struct { | 37 | static struct { |
| 38 | + audsettings_t settings; | ||
| 38 | const char *wav_path; | 39 | const char *wav_path; |
| 39 | } conf = { | 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 | static int wav_run_out (HWVoiceOut *hw) | 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,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 | WAVVoiceOut *wav = (WAVVoiceOut *) hw; | 112 | WAVVoiceOut *wav = (WAVVoiceOut *) hw; |
| 107 | - int bits16; | 113 | + int bits16 = 0, stereo = 0; |
| 108 | uint8_t hdr[] = { | 114 | uint8_t hdr[] = { |
| 109 | 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, | 115 | 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, |
| 110 | 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, | 116 | 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 111 | 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, | 117 | 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, |
| 112 | 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 | 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 | case AUD_FMT_S8: | 126 | case AUD_FMT_S8: |
| 121 | case AUD_FMT_U8: | 127 | case AUD_FMT_U8: |
| 122 | bits16 = 0; | 128 | bits16 = 0; |
| @@ -126,32 +132,24 @@ static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | @@ -126,32 +132,24 @@ static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt) | ||
| 126 | case AUD_FMT_U16: | 132 | case AUD_FMT_U16: |
| 127 | bits16 = 1; | 133 | bits16 = 1; |
| 128 | break; | 134 | break; |
| 129 | - | ||
| 130 | - default: | ||
| 131 | - dolog ("Internal logic error bad format %d\n", fmt); | ||
| 132 | - return -1; | ||
| 133 | } | 135 | } |
| 134 | 136 | ||
| 135 | hdr[34] = bits16 ? 0x10 : 0x08; | 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 | if (!wav->pcm_buf) { | 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 | return -1; | 146 | return -1; |
| 149 | } | 147 | } |
| 150 | 148 | ||
| 151 | le_store (hdr + 22, hw->info.nchannels, 2); | 149 | le_store (hdr + 22, hw->info.nchannels, 2); |
| 152 | le_store (hdr + 24, hw->info.freq, 4); | 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 | wav->f = fopen (conf.wav_path, "wb"); | 154 | wav->f = fopen (conf.wav_path, "wb"); |
| 157 | if (!wav->f) { | 155 | if (!wav->f) { |
| @@ -175,7 +173,7 @@ static void wav_fini_out (HWVoiceOut *hw) | @@ -175,7 +173,7 @@ static void wav_fini_out (HWVoiceOut *hw) | ||
| 175 | uint32_t rifflen = (wav->total_samples << stereo) + 36; | 173 | uint32_t rifflen = (wav->total_samples << stereo) + 36; |
| 176 | uint32_t datalen = wav->total_samples << stereo; | 174 | uint32_t datalen = wav->total_samples << stereo; |
| 177 | 175 | ||
| 178 | - if (!wav->f || !hw->active) { | 176 | + if (!wav->f) { |
| 179 | return; | 177 | return; |
| 180 | } | 178 | } |
| 181 | 179 | ||
| @@ -214,6 +212,15 @@ static void wav_audio_fini (void *opaque) | @@ -214,6 +212,15 @@ static void wav_audio_fini (void *opaque) | ||
| 214 | } | 212 | } |
| 215 | 213 | ||
| 216 | struct audio_option wav_options[] = { | 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 | {"PATH", AUD_OPT_STR, &conf.wav_path, | 224 | {"PATH", AUD_OPT_STR, &conf.wav_path, |
| 218 | "Path to wave file", NULL, 0}, | 225 | "Path to wave file", NULL, 0}, |
| 219 | {NULL, 0, NULL, NULL, NULL, 0} | 226 | {NULL, 0, NULL, NULL, NULL, 0} |
hw/adlib.c
| @@ -53,6 +53,7 @@ static struct { | @@ -53,6 +53,7 @@ static struct { | ||
| 53 | } conf = {0x220, 44100}; | 53 | } conf = {0x220, 44100}; |
| 54 | 54 | ||
| 55 | typedef struct { | 55 | typedef struct { |
| 56 | + QEMUSoundCard card; | ||
| 56 | int ticking[2]; | 57 | int ticking[2]; |
| 57 | int enabled; | 58 | int enabled; |
| 58 | int active; | 59 | int active; |
| @@ -70,7 +71,7 @@ typedef struct { | @@ -70,7 +71,7 @@ typedef struct { | ||
| 70 | #endif | 71 | #endif |
| 71 | } AdlibState; | 72 | } AdlibState; |
| 72 | 73 | ||
| 73 | -static AdlibState adlib; | 74 | +static AdlibState glob_adlib; |
| 74 | 75 | ||
| 75 | static void adlib_stop_opl_timer (AdlibState *s, size_t n) | 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,7 +91,7 @@ static void adlib_kill_timers (AdlibState *s) | ||
| 90 | if (s->ticking[i]) { | 91 | if (s->ticking[i]) { |
| 91 | uint64_t delta; | 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 | ldebug ( | 95 | ldebug ( |
| 95 | "delta = %f dexp = %f expired => %d\n", | 96 | "delta = %f dexp = %f expired => %d\n", |
| 96 | delta / 1000000.0, | 97 | delta / 1000000.0, |
| @@ -141,10 +142,11 @@ static IO_READ_PROTO(adlib_read) | @@ -141,10 +142,11 @@ static IO_READ_PROTO(adlib_read) | ||
| 141 | 142 | ||
| 142 | static void timer_handler (int c, double interval_Sec) | 143 | static void timer_handler (int c, double interval_Sec) |
| 143 | { | 144 | { |
| 144 | - AdlibState *s = &adlib; | 145 | + AdlibState *s = &glob_adlib; |
| 145 | unsigned n = c & 1; | 146 | unsigned n = c & 1; |
| 146 | #ifdef DEBUG | 147 | #ifdef DEBUG |
| 147 | double interval; | 148 | double interval; |
| 149 | + int64_t exp; | ||
| 148 | #endif | 150 | #endif |
| 149 | 151 | ||
| 150 | if (interval_Sec == 0.0) { | 152 | if (interval_Sec == 0.0) { |
| @@ -262,16 +264,23 @@ static void Adlib_fini (AdlibState *s) | @@ -262,16 +264,23 @@ static void Adlib_fini (AdlibState *s) | ||
| 262 | 264 | ||
| 263 | s->active = 0; | 265 | s->active = 0; |
| 264 | s->enabled = 0; | 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 | #ifdef HAS_YMF262 | 280 | #ifdef HAS_YMF262 |
| 272 | if (YMF262Init (1, 14318180, conf.freq)) { | 281 | if (YMF262Init (1, 14318180, conf.freq)) { |
| 273 | dolog ("YMF262Init %d failed\n", conf.freq); | 282 | dolog ("YMF262Init %d failed\n", conf.freq); |
| 274 | - return; | 283 | + return -1; |
| 275 | } | 284 | } |
| 276 | else { | 285 | else { |
| 277 | YMF262SetTimerHandler (0, timer_handler, 0); | 286 | YMF262SetTimerHandler (0, timer_handler, 0); |
| @@ -281,7 +290,7 @@ void Adlib_init (void) | @@ -281,7 +290,7 @@ void Adlib_init (void) | ||
| 281 | s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq); | 290 | s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq); |
| 282 | if (!s->opl) { | 291 | if (!s->opl) { |
| 283 | dolog ("OPLCreate %d failed\n", conf.freq); | 292 | dolog ("OPLCreate %d failed\n", conf.freq); |
| 284 | - return; | 293 | + return -1; |
| 285 | } | 294 | } |
| 286 | else { | 295 | else { |
| 287 | OPLSetTimerHandler (s->opl, timer_handler, 0); | 296 | OPLSetTimerHandler (s->opl, timer_handler, 0); |
| @@ -289,18 +298,23 @@ void Adlib_init (void) | @@ -289,18 +298,23 @@ void Adlib_init (void) | ||
| 289 | } | 298 | } |
| 290 | #endif | 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 | s->voice = AUD_open_out ( | 307 | s->voice = AUD_open_out ( |
| 308 | + &s->card, | ||
| 293 | s->voice, | 309 | s->voice, |
| 294 | "adlib", | 310 | "adlib", |
| 295 | s, | 311 | s, |
| 296 | adlib_callback, | 312 | adlib_callback, |
| 297 | - conf.freq, | ||
| 298 | - SHIFT, | ||
| 299 | - AUD_FMT_S16 | 313 | + &as |
| 300 | ); | 314 | ); |
| 301 | if (!s->voice) { | 315 | if (!s->voice) { |
| 302 | Adlib_fini (s); | 316 | Adlib_fini (s); |
| 303 | - return; | 317 | + return -1; |
| 304 | } | 318 | } |
| 305 | 319 | ||
| 306 | s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; | 320 | s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; |
| @@ -310,7 +324,7 @@ void Adlib_init (void) | @@ -310,7 +324,7 @@ void Adlib_init (void) | ||
| 310 | dolog ("not enough memory for adlib mixing buffer (%d)\n", | 324 | dolog ("not enough memory for adlib mixing buffer (%d)\n", |
| 311 | s->samples << SHIFT); | 325 | s->samples << SHIFT); |
| 312 | Adlib_fini (s); | 326 | Adlib_fini (s); |
| 313 | - return; | 327 | + return -1; |
| 314 | } | 328 | } |
| 315 | 329 | ||
| 316 | register_ioport_read (0x388, 4, 1, adlib_read, s); | 330 | register_ioport_read (0x388, 4, 1, adlib_read, s); |
| @@ -321,4 +335,6 @@ void Adlib_init (void) | @@ -321,4 +335,6 @@ void Adlib_init (void) | ||
| 321 | 335 | ||
| 322 | register_ioport_read (conf.port + 8, 2, 1, adlib_read, s); | 336 | register_ioport_read (conf.port + 8, 2, 1, adlib_read, s); |
| 323 | register_ioport_write (conf.port + 8, 2, 1, adlib_write, s); | 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,6 +265,7 @@ struct chan { | ||
| 265 | typedef struct ES1370State { | 265 | typedef struct ES1370State { |
| 266 | PCIDevice *pci_dev; | 266 | PCIDevice *pci_dev; |
| 267 | 267 | ||
| 268 | + QEMUSoundCard card; | ||
| 268 | struct chan chan[NB_CHANNELS]; | 269 | struct chan chan[NB_CHANNELS]; |
| 269 | SWVoiceOut *dac_voice[2]; | 270 | SWVoiceOut *dac_voice[2]; |
| 270 | SWVoiceIn *adc_voice; | 271 | SWVoiceIn *adc_voice; |
| @@ -341,11 +342,11 @@ static void es1370_reset (ES1370State *s) | @@ -341,11 +342,11 @@ static void es1370_reset (ES1370State *s) | ||
| 341 | d->scount = 0; | 342 | d->scount = 0; |
| 342 | d->leftover = 0; | 343 | d->leftover = 0; |
| 343 | if (i == ADC_CHANNEL) { | 344 | if (i == ADC_CHANNEL) { |
| 344 | - AUD_close_in (s->adc_voice); | 345 | + AUD_close_in (&s->card, s->adc_voice); |
| 345 | s->adc_voice = NULL; | 346 | s->adc_voice = NULL; |
| 346 | } | 347 | } |
| 347 | else { | 348 | else { |
| 348 | - AUD_close_out (s->dac_voice[i]); | 349 | + AUD_close_out (&s->card, s->dac_voice[i]); |
| 349 | s->dac_voice[i] = NULL; | 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,28 +418,32 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl) | ||
| 417 | (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8, | 418 | (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8, |
| 418 | d->shift); | 419 | d->shift); |
| 419 | if (new_freq) { | 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 | if (i == ADC_CHANNEL) { | 427 | if (i == ADC_CHANNEL) { |
| 421 | s->adc_voice = | 428 | s->adc_voice = |
| 422 | AUD_open_in ( | 429 | AUD_open_in ( |
| 430 | + &s->card, | ||
| 423 | s->adc_voice, | 431 | s->adc_voice, |
| 424 | "es1370.adc", | 432 | "es1370.adc", |
| 425 | s, | 433 | s, |
| 426 | es1370_adc_callback, | 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 | else { | 438 | else { |
| 433 | s->dac_voice[i] = | 439 | s->dac_voice[i] = |
| 434 | AUD_open_out ( | 440 | AUD_open_out ( |
| 441 | + &s->card, | ||
| 435 | s->dac_voice[i], | 442 | s->dac_voice[i], |
| 436 | i ? "es1370.dac2" : "es1370.dac1", | 443 | i ? "es1370.dac2" : "es1370.dac1", |
| 437 | s, | 444 | s, |
| 438 | i ? es1370_dac2_callback : es1370_dac1_callback, | 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,7 +766,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, | ||
| 761 | while (temp) { | 766 | while (temp) { |
| 762 | int acquired, to_copy; | 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 | acquired = AUD_read (s->adc_voice, tmpbuf, to_copy); | 770 | acquired = AUD_read (s->adc_voice, tmpbuf, to_copy); |
| 766 | if (!acquired) | 771 | if (!acquired) |
| 767 | break; | 772 | break; |
| @@ -779,7 +784,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, | @@ -779,7 +784,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, | ||
| 779 | while (temp) { | 784 | while (temp) { |
| 780 | int copied, to_copy; | 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 | cpu_physical_memory_read (addr, tmpbuf, to_copy); | 788 | cpu_physical_memory_read (addr, tmpbuf, to_copy); |
| 784 | copied = AUD_write (voice, tmpbuf, to_copy); | 789 | copied = AUD_write (voice, tmpbuf, to_copy); |
| 785 | if (!copied) | 790 | if (!copied) |
| @@ -812,7 +817,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, | @@ -812,7 +817,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel, | ||
| 812 | else { | 817 | else { |
| 813 | d->frame_cnt = size; | 818 | d->frame_cnt = size; |
| 814 | 819 | ||
| 815 | - if (cnt <= d->frame_cnt) | 820 | + if ((uint32_t) cnt <= d->frame_cnt) |
| 816 | d->frame_cnt |= cnt << 16; | 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,6 +881,10 @@ static void es1370_map (PCIDevice *pci_dev, int region_num, | ||
| 876 | PCIES1370State *d = (PCIES1370State *) pci_dev; | 881 | PCIES1370State *d = (PCIES1370State *) pci_dev; |
| 877 | ES1370State *s = &d->es1370; | 882 | ES1370State *s = &d->es1370; |
| 878 | 883 | ||
| 884 | + (void) region_num; | ||
| 885 | + (void) size; | ||
| 886 | + (void) type; | ||
| 887 | + | ||
| 879 | register_ioport_write (addr, 0x40 * 4, 1, es1370_writeb, s); | 888 | register_ioport_write (addr, 0x40 * 4, 1, es1370_writeb, s); |
| 880 | register_ioport_write (addr, 0x40 * 2, 2, es1370_writew, s); | 889 | register_ioport_write (addr, 0x40 * 2, 2, es1370_writew, s); |
| 881 | register_ioport_write (addr, 0x40, 4, es1370_writel, s); | 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,13 +932,13 @@ static int es1370_load (QEMUFile *f, void *opaque, int version_id) | ||
| 923 | qemu_get_be32s (f, &d->frame_cnt); | 932 | qemu_get_be32s (f, &d->frame_cnt); |
| 924 | if (i == ADC_CHANNEL) { | 933 | if (i == ADC_CHANNEL) { |
| 925 | if (s->adc_voice) { | 934 | if (s->adc_voice) { |
| 926 | - AUD_close_in (s->adc_voice); | 935 | + AUD_close_in (&s->card, s->adc_voice); |
| 927 | s->adc_voice = NULL; | 936 | s->adc_voice = NULL; |
| 928 | } | 937 | } |
| 929 | } | 938 | } |
| 930 | else { | 939 | else { |
| 931 | if (s->dac_voice[i]) { | 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 | s->dac_voice[i] = NULL; | 942 | s->dac_voice[i] = NULL; |
| 934 | } | 943 | } |
| 935 | } | 944 | } |
| @@ -953,12 +962,22 @@ static void es1370_on_reset (void *opaque) | @@ -953,12 +962,22 @@ static void es1370_on_reset (void *opaque) | ||
| 953 | es1370_reset (s); | 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 | PCIES1370State *d; | 967 | PCIES1370State *d; |
| 959 | ES1370State *s; | 968 | ES1370State *s; |
| 960 | uint8_t *c; | 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 | d = (PCIES1370State *) pci_register_device (bus, "ES1370", | 981 | d = (PCIES1370State *) pci_register_device (bus, "ES1370", |
| 963 | sizeof (PCIES1370State), | 982 | sizeof (PCIES1370State), |
| 964 | -1, NULL, NULL); | 983 | -1, NULL, NULL); |
| @@ -1002,6 +1021,8 @@ int es1370_init (PCIBus *bus) | @@ -1002,6 +1021,8 @@ int es1370_init (PCIBus *bus) | ||
| 1002 | pci_register_io_region (&d->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map); | 1021 | pci_register_io_region (&d->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map); |
| 1003 | register_savevm ("es1370", 0, 1, es1370_save, es1370_load, s); | 1022 | register_savevm ("es1370", 0, 1, es1370_save, es1370_load, s); |
| 1004 | qemu_register_reset (es1370_on_reset, s); | 1023 | qemu_register_reset (es1370_on_reset, s); |
| 1024 | + | ||
| 1025 | + AUD_register_card (audio, "es1370", &s->card); | ||
| 1005 | es1370_reset (s); | 1026 | es1370_reset (s); |
| 1006 | return 0; | 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,19 +601,23 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, | ||
| 601 | DMA_init(0); | 601 | DMA_init(0); |
| 602 | 602 | ||
| 603 | if (audio_enabled) { | 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 | #ifdef CONFIG_ADLIB | 610 | #ifdef CONFIG_ADLIB |
| 608 | - if (adlib_enabled) | ||
| 609 | - Adlib_init (); | 611 | + if (adlib_enabled) |
| 612 | + Adlib_init (audio); | ||
| 610 | #endif | 613 | #endif |
| 611 | #ifdef CONFIG_GUS | 614 | #ifdef CONFIG_GUS |
| 612 | - if (gus_enabled) | ||
| 613 | - GUS_init (); | 615 | + if (gus_enabled) |
| 616 | + GUS_init (audio); | ||
| 614 | #endif | 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 | floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table); | 623 | floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table); |
hw/sb16.c
| @@ -53,6 +53,7 @@ static struct { | @@ -53,6 +53,7 @@ static struct { | ||
| 53 | } conf = {5, 4, 5, 1, 5, 0x220}; | 53 | } conf = {5, 4, 5, 1, 5, 0x220}; |
| 54 | 54 | ||
| 55 | typedef struct SB16State { | 55 | typedef struct SB16State { |
| 56 | + QEMUSoundCard card; | ||
| 56 | int irq; | 57 | int irq; |
| 57 | int dma; | 58 | int dma; |
| 58 | int hdma; | 59 | int hdma; |
| @@ -108,9 +109,6 @@ typedef struct SB16State { | @@ -108,9 +109,6 @@ typedef struct SB16State { | ||
| 108 | uint8_t mixer_regs[256]; | 109 | uint8_t mixer_regs[256]; |
| 109 | } SB16State; | 110 | } SB16State; |
| 110 | 111 | ||
| 111 | -/* XXX: suppress that and use a context */ | ||
| 112 | -static struct SB16State dsp; | ||
| 113 | - | ||
| 114 | static void SB_audio_callback (void *opaque, int free); | 112 | static void SB_audio_callback (void *opaque, int free); |
| 115 | 113 | ||
| 116 | static int magic_of_irq (int irq) | 114 | static int magic_of_irq (int irq) |
| @@ -242,15 +240,21 @@ static void dma_cmd8 (SB16State *s, int mask, int dma_len) | @@ -242,15 +240,21 @@ static void dma_cmd8 (SB16State *s, int mask, int dma_len) | ||
| 242 | s->block_size, s->dma_auto, s->fifo, s->highspeed); | 240 | s->block_size, s->dma_auto, s->fifo, s->highspeed); |
| 243 | 241 | ||
| 244 | if (s->freq) { | 242 | if (s->freq) { |
| 243 | + audsettings_t as; | ||
| 244 | + | ||
| 245 | s->audio_free = 0; | 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 | s->voice = AUD_open_out ( | 251 | s->voice = AUD_open_out ( |
| 252 | + &s->card, | ||
| 247 | s->voice, | 253 | s->voice, |
| 248 | "sb16", | 254 | "sb16", |
| 249 | s, | 255 | s, |
| 250 | SB_audio_callback, | 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,15 +334,21 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len) | ||
| 330 | } | 334 | } |
| 331 | 335 | ||
| 332 | if (s->freq) { | 336 | if (s->freq) { |
| 337 | + audsettings_t as; | ||
| 338 | + | ||
| 333 | s->audio_free = 0; | 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 | s->voice = AUD_open_out ( | 345 | s->voice = AUD_open_out ( |
| 346 | + &s->card, | ||
| 335 | s->voice, | 347 | s->voice, |
| 336 | "sb16", | 348 | "sb16", |
| 337 | s, | 349 | s, |
| 338 | SB_audio_callback, | 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,7 +359,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len) | ||
| 349 | static inline void dsp_out_data (SB16State *s, uint8_t val) | 359 | static inline void dsp_out_data (SB16State *s, uint8_t val) |
| 350 | { | 360 | { |
| 351 | ldebug ("outdata %#x\n", val); | 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 | s->out_data[s->out_data_len++] = val; | 363 | s->out_data[s->out_data_len++] = val; |
| 354 | } | 364 | } |
| 355 | } | 365 | } |
| @@ -1018,6 +1028,7 @@ static void reset_mixer (SB16State *s) | @@ -1018,6 +1028,7 @@ static void reset_mixer (SB16State *s) | ||
| 1018 | static IO_WRITE_PROTO(mixer_write_indexb) | 1028 | static IO_WRITE_PROTO(mixer_write_indexb) |
| 1019 | { | 1029 | { |
| 1020 | SB16State *s = opaque; | 1030 | SB16State *s = opaque; |
| 1031 | + (void) nport; | ||
| 1021 | s->mixer_nreg = val; | 1032 | s->mixer_nreg = val; |
| 1022 | } | 1033 | } |
| 1023 | 1034 | ||
| @@ -1025,10 +1036,8 @@ static IO_WRITE_PROTO(mixer_write_datab) | @@ -1025,10 +1036,8 @@ static IO_WRITE_PROTO(mixer_write_datab) | ||
| 1025 | { | 1036 | { |
| 1026 | SB16State *s = opaque; | 1037 | SB16State *s = opaque; |
| 1027 | 1038 | ||
| 1039 | + (void) nport; | ||
| 1028 | ldebug ("mixer_write [%#x] <- %#x\n", s->mixer_nreg, val); | 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 | switch (s->mixer_nreg) { | 1042 | switch (s->mixer_nreg) { |
| 1034 | case 0x00: | 1043 | case 0x00: |
| @@ -1088,6 +1097,8 @@ static IO_WRITE_PROTO(mixer_write_indexw) | @@ -1088,6 +1097,8 @@ static IO_WRITE_PROTO(mixer_write_indexw) | ||
| 1088 | static IO_READ_PROTO(mixer_read) | 1097 | static IO_READ_PROTO(mixer_read) |
| 1089 | { | 1098 | { |
| 1090 | SB16State *s = opaque; | 1099 | SB16State *s = opaque; |
| 1100 | + | ||
| 1101 | + (void) nport; | ||
| 1091 | #ifndef DEBUG_SB16_MOST | 1102 | #ifndef DEBUG_SB16_MOST |
| 1092 | if (s->mixer_nreg != 0x82) { | 1103 | if (s->mixer_nreg != 0x82) { |
| 1093 | ldebug ("mixer_read[%#x] -> %#x\n", | 1104 | ldebug ("mixer_read[%#x] -> %#x\n", |
| @@ -1111,11 +1122,12 @@ static int write_audio (SB16State *s, int nchan, int dma_pos, | @@ -1111,11 +1122,12 @@ static int write_audio (SB16State *s, int nchan, int dma_pos, | ||
| 1111 | 1122 | ||
| 1112 | while (temp) { | 1123 | while (temp) { |
| 1113 | int left = dma_len - dma_pos; | 1124 | int left = dma_len - dma_pos; |
| 1114 | - int to_copy, copied; | 1125 | + int copied; |
| 1126 | + size_t to_copy; | ||
| 1115 | 1127 | ||
| 1116 | to_copy = audio_MIN (temp, left); | 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 | copied = DMA_read_memory (nchan, tmpbuf, dma_pos, to_copy); | 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,21 +1320,27 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id) | ||
| 1308 | qemu_get_buffer (f, s->mixer_regs, 256); | 1320 | qemu_get_buffer (f, s->mixer_regs, 256); |
| 1309 | 1321 | ||
| 1310 | if (s->voice) { | 1322 | if (s->voice) { |
| 1311 | - AUD_close_out (s->voice); | 1323 | + AUD_close_out (&s->card, s->voice); |
| 1312 | s->voice = NULL; | 1324 | s->voice = NULL; |
| 1313 | } | 1325 | } |
| 1314 | 1326 | ||
| 1315 | if (s->dma_running) { | 1327 | if (s->dma_running) { |
| 1316 | if (s->freq) { | 1328 | if (s->freq) { |
| 1329 | + audsettings_t as; | ||
| 1330 | + | ||
| 1317 | s->audio_free = 0; | 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 | s->voice = AUD_open_out ( | 1337 | s->voice = AUD_open_out ( |
| 1338 | + &s->card, | ||
| 1319 | s->voice, | 1339 | s->voice, |
| 1320 | "sb16", | 1340 | "sb16", |
| 1321 | s, | 1341 | s, |
| 1322 | SB_audio_callback, | 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,13 +1350,25 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id) | ||
| 1332 | return 0; | 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 | int i; | 1356 | int i; |
| 1339 | static const uint8_t dsp_write_ports[] = {0x6, 0xc}; | 1357 | static const uint8_t dsp_write_ports[] = {0x6, 0xc}; |
| 1340 | static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf}; | 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 | s->cmd = -1; | 1372 | s->cmd = -1; |
| 1343 | s->irq = conf.irq; | 1373 | s->irq = conf.irq; |
| 1344 | s->dma = conf.dma; | 1374 | s->dma = conf.dma; |
| @@ -1356,7 +1386,7 @@ void SB16_init (void) | @@ -1356,7 +1386,7 @@ void SB16_init (void) | ||
| 1356 | reset_mixer (s); | 1386 | reset_mixer (s); |
| 1357 | s->aux_ts = qemu_new_timer (vm_clock, aux_timer, s); | 1387 | s->aux_ts = qemu_new_timer (vm_clock, aux_timer, s); |
| 1358 | if (!s->aux_ts) { | 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 | for (i = 0; i < LENOFA (dsp_write_ports); i++) { | 1392 | for (i = 0; i < LENOFA (dsp_write_ports); i++) { |
| @@ -1377,4 +1407,6 @@ void SB16_init (void) | @@ -1377,4 +1407,6 @@ void SB16_init (void) | ||
| 1377 | s->can_write = 1; | 1407 | s->can_write = 1; |
| 1378 | 1408 | ||
| 1379 | register_savevm ("sb16", 0, 1, SB_save, SB_load, s); | 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,12 +95,21 @@ NE2000 PCI network adapters | ||
| 95 | @item | 95 | @item |
| 96 | Serial ports | 96 | Serial ports |
| 97 | @item | 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 | @end itemize | 103 | @end itemize |
| 100 | 104 | ||
| 105 | +Note that adlib is only available when QEMU was configured with | ||
| 106 | +-enable-adlib | ||
| 107 | + | ||
| 101 | QEMU uses the PC BIOS from the Bochs project and the Plex86/Bochs LGPL | 108 | QEMU uses the PC BIOS from the Bochs project and the Plex86/Bochs LGPL |
| 102 | VGA BIOS. | 109 | VGA BIOS. |
| 103 | 110 | ||
| 111 | +QEMU uses YM3812 emulation by Tatsuyuki Satoh. | ||
| 112 | + | ||
| 104 | @c man end | 113 | @c man end |
| 105 | 114 | ||
| 106 | @section Quick Start | 115 | @section Quick Start |
vl.c
| @@ -2842,10 +2842,11 @@ void help(void) | @@ -2842,10 +2842,11 @@ void help(void) | ||
| 2842 | "-k language use keyboard layout (for example \"fr\" for French)\n" | 2842 | "-k language use keyboard layout (for example \"fr\" for French)\n" |
| 2843 | #endif | 2843 | #endif |
| 2844 | #ifdef HAS_AUDIO | 2844 | #ifdef HAS_AUDIO |
| 2845 | - "-enable-audio enable audio support\n" | 2845 | + "-enable-audio enable audio support, and all the sound cars\n" |
| 2846 | "-audio-help print list of audio drivers and their options\n" | 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 | #endif | 2850 | #endif |
| 2850 | "-localtime set the real time clock to local time [default=utc]\n" | 2851 | "-localtime set the real time clock to local time [default=utc]\n" |
| 2851 | "-full-screen start in full screen\n" | 2852 | "-full-screen start in full screen\n" |
| @@ -3145,9 +3146,9 @@ static void select_soundhw (const char *optarg) | @@ -3145,9 +3146,9 @@ static void select_soundhw (const char *optarg) | ||
| 3145 | printf ("sb16 Creative Sound Blaster 16\n"); | 3146 | printf ("sb16 Creative Sound Blaster 16\n"); |
| 3146 | #ifdef CONFIG_ADLIB | 3147 | #ifdef CONFIG_ADLIB |
| 3147 | #ifdef HAS_YMF262 | 3148 | #ifdef HAS_YMF262 |
| 3148 | - printf ("adlib Ymaha YMF262 (OPL3)\n"); | 3149 | + printf ("adlib Yamaha YMF262 (OPL3)\n"); |
| 3149 | #else | 3150 | #else |
| 3150 | - printf ("adlib Ymaha YM3812 (OPL2)\n"); | 3151 | + printf ("adlib Yamaha YM3812 (OPL2)\n"); |
| 3151 | #endif | 3152 | #endif |
| 3152 | #endif | 3153 | #endif |
| 3153 | #ifdef CONFIG_GUS | 3154 | #ifdef CONFIG_GUS |
vl.h
| @@ -631,16 +631,16 @@ int pmac_ide_init (BlockDriverState **hd_table, | @@ -631,16 +631,16 @@ int pmac_ide_init (BlockDriverState **hd_table, | ||
| 631 | SetIRQFunc *set_irq, void *irq_opaque, int irq); | 631 | SetIRQFunc *set_irq, void *irq_opaque, int irq); |
| 632 | 632 | ||
| 633 | /* es1370.c */ | 633 | /* es1370.c */ |
| 634 | -int es1370_init (PCIBus *bus); | 634 | +int es1370_init (PCIBus *bus, AudioState *s); |
| 635 | 635 | ||
| 636 | /* sb16.c */ | 636 | /* sb16.c */ |
| 637 | -void SB16_init (void); | 637 | +int SB16_init (AudioState *s); |
| 638 | 638 | ||
| 639 | /* adlib.c */ | 639 | /* adlib.c */ |
| 640 | -void Adlib_init (void); | 640 | +int Adlib_init (AudioState *s); |
| 641 | 641 | ||
| 642 | /* gus.c */ | 642 | /* gus.c */ |
| 643 | -void GUS_init (void); | 643 | +int GUS_init (AudioState *s); |
| 644 | 644 | ||
| 645 | /* dma.c */ | 645 | /* dma.c */ |
| 646 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); | 646 | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); |