diff 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
line wrap: on
line diff
--- a/src/audio/SDL_audio.c	Wed Dec 31 08:05:21 2008 +0000
+++ b/src/audio/SDL_audio.c	Thu Jan 01 07:54:58 2009 +0000
@@ -589,6 +589,8 @@
     int i = 0;
     int initialized = 0;
     int tried_to_init = 0;
+    int rc = 0;
+    int best_choice = -1;
 
     if (SDL_WasInit(SDL_INIT_AUDIO)) {
         SDL_AudioQuit();        /* shutdown driver if already running. */
@@ -614,7 +616,25 @@
         SDL_memset(&current_audio, 0, sizeof(current_audio));
         current_audio.name = backend->name;
         current_audio.desc = backend->desc;
-        initialized = backend->init(&current_audio.impl);
+        rc = backend->init(&current_audio.impl);
+        if (rc == 2) {  /* init'd, and devices available. Take it! */
+            initialized = 1;
+            best_choice = i;
+        } else if (rc == 1) { /* init'd, but can't see any devices. */
+            current_audio.impl.Deinitialize();
+            if (best_choice == -1) {
+                best_choice = i;
+            }
+        }
+    }
+
+    /* No definite choice. Pick one that works but can't promise a device. */
+    if ((!initialized) && (best_choice != -1)) {
+        const AudioBootStrap *backend = bootstrap[best_choice];
+        SDL_memset(&current_audio, 0, sizeof(current_audio));
+        current_audio.name = backend->name;
+        current_audio.desc = backend->desc;
+        initialized = (backend->init(&current_audio.impl) > 0);
     }
 
     if (!initialized) {