diff src/audio/SDL_audio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents ce229f6b5ce0
children
line wrap: on
line diff
--- a/src/audio/SDL_audio.c	Tue Oct 17 08:04:51 2006 +0000
+++ b/src/audio/SDL_audio.c	Tue Oct 17 09:09:21 2006 +0000
@@ -360,6 +360,7 @@
 {
     int i = 0;
     int initialized = 0;
+    int tried_to_init = 0;
 
     if (SDL_WasInit(SDL_INIT_AUDIO)) {
         SDL_AudioQuit();  /* shutdown driver if already running. */
@@ -373,36 +374,31 @@
         driver_name = SDL_getenv("SDL_AUDIODRIVER");
     }
 
-    /* !!! FIXME: what's the point of separating available() and init()? */
-    if (driver_name != NULL) {
-        for (i = 0; bootstrap[i]; ++i) {
-            if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
-                if (bootstrap[i]->available()) {
-                    SDL_memset(&current_audio, 0, sizeof (current_audio));
-                    current_audio.name = bootstrap[i]->name;
-                    current_audio.desc = bootstrap[i]->desc;
-                    initialized = bootstrap[i]->init(&current_audio.impl);
-                }
-                break;
-            }
+    for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
+        /* make sure we should even try this driver before doing so... */
+        const AudioBootStrap *backend = bootstrap[i];
+        if ( ((driver_name) && (SDL_strcasecmp(backend->name, driver_name))) ||
+             ((!driver_name) && (backend->demand_only)) ) {
+            continue;
         }
-    } else {
-        for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
-            if ((!bootstrap[i]->demand_only) && (bootstrap[i]->available())) {
-                SDL_memset(&current_audio, 0, sizeof (current_audio));
-                current_audio.name = bootstrap[i]->name;
-                current_audio.desc = bootstrap[i]->desc;
-                initialized = bootstrap[i]->init(&current_audio.impl);
-            }
-        }
+
+        tried_to_init = 1;
+        SDL_memset(&current_audio, 0, sizeof (current_audio));
+        current_audio.name = backend->name;
+        current_audio.desc = backend->desc;
+        initialized = backend->init(&current_audio.impl);
     }
 
     if (!initialized) {
-        if (driver_name) {
-            SDL_SetError("%s not available", driver_name);
-        } else {
-            SDL_SetError("No available audio device");
+        /* specific drivers will set the error message if they fail... */
+        if (!tried_to_init) {
+            if (driver_name) {
+                SDL_SetError("%s not available", driver_name);
+            } else {
+                SDL_SetError("No available audio device");
+            }
         }
+
         SDL_memset(&current_audio, 0, sizeof (current_audio));
         return (-1);  /* No driver was available, so fail. */
     }