comparison src/audio/SDL_audio.c @ 2938:2929ed239d2a

Adjusted default choice of audio driver. If a driver can definitely see available devices, it is chosen. Otherwise, we'll take the first driver that initializes but saw no devices...this might be because it can't enumerate them, or there really aren't any available. This prevents the dsp driver from hogging control when there are no /dev/dsp* nodes (for example, on a Linux box with ALSA and no OSS emulation).
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 01 Jan 2009 07:54:58 +0000
parents e532417a6977
children 084e5b4fc5be
comparison
equal deleted inserted replaced
2937:017d4334accf 2938:2929ed239d2a
587 SDL_AudioInit(const char *driver_name) 587 SDL_AudioInit(const char *driver_name)
588 { 588 {
589 int i = 0; 589 int i = 0;
590 int initialized = 0; 590 int initialized = 0;
591 int tried_to_init = 0; 591 int tried_to_init = 0;
592 int rc = 0;
593 int best_choice = -1;
592 594
593 if (SDL_WasInit(SDL_INIT_AUDIO)) { 595 if (SDL_WasInit(SDL_INIT_AUDIO)) {
594 SDL_AudioQuit(); /* shutdown driver if already running. */ 596 SDL_AudioQuit(); /* shutdown driver if already running. */
595 } 597 }
596 598
612 614
613 tried_to_init = 1; 615 tried_to_init = 1;
614 SDL_memset(&current_audio, 0, sizeof(current_audio)); 616 SDL_memset(&current_audio, 0, sizeof(current_audio));
615 current_audio.name = backend->name; 617 current_audio.name = backend->name;
616 current_audio.desc = backend->desc; 618 current_audio.desc = backend->desc;
617 initialized = backend->init(&current_audio.impl); 619 rc = backend->init(&current_audio.impl);
620 if (rc == 2) { /* init'd, and devices available. Take it! */
621 initialized = 1;
622 best_choice = i;
623 } else if (rc == 1) { /* init'd, but can't see any devices. */
624 current_audio.impl.Deinitialize();
625 if (best_choice == -1) {
626 best_choice = i;
627 }
628 }
629 }
630
631 /* No definite choice. Pick one that works but can't promise a device. */
632 if ((!initialized) && (best_choice != -1)) {
633 const AudioBootStrap *backend = bootstrap[best_choice];
634 SDL_memset(&current_audio, 0, sizeof(current_audio));
635 current_audio.name = backend->name;
636 current_audio.desc = backend->desc;
637 initialized = (backend->init(&current_audio.impl) > 0);
618 } 638 }
619 639
620 if (!initialized) { 640 if (!initialized) {
621 /* specific drivers will set the error message if they fail... */ 641 /* specific drivers will set the error message if they fail... */
622 if (!tried_to_init) { 642 if (!tried_to_init) {