Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
3845:ee5dfa7f7993 | 3846:66fb40445587 |
---|---|
358 int | 358 int |
359 SDL_AudioInit(const char *driver_name) | 359 SDL_AudioInit(const char *driver_name) |
360 { | 360 { |
361 int i = 0; | 361 int i = 0; |
362 int initialized = 0; | 362 int initialized = 0; |
363 int tried_to_init = 0; | |
363 | 364 |
364 if (SDL_WasInit(SDL_INIT_AUDIO)) { | 365 if (SDL_WasInit(SDL_INIT_AUDIO)) { |
365 SDL_AudioQuit(); /* shutdown driver if already running. */ | 366 SDL_AudioQuit(); /* shutdown driver if already running. */ |
366 } | 367 } |
367 | 368 |
371 /* Select the proper audio driver */ | 372 /* Select the proper audio driver */ |
372 if (driver_name == NULL) { | 373 if (driver_name == NULL) { |
373 driver_name = SDL_getenv("SDL_AUDIODRIVER"); | 374 driver_name = SDL_getenv("SDL_AUDIODRIVER"); |
374 } | 375 } |
375 | 376 |
376 /* !!! FIXME: what's the point of separating available() and init()? */ | 377 for (i = 0; (!initialized) && (bootstrap[i]); ++i) { |
377 if (driver_name != NULL) { | 378 /* make sure we should even try this driver before doing so... */ |
378 for (i = 0; bootstrap[i]; ++i) { | 379 const AudioBootStrap *backend = bootstrap[i]; |
379 if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { | 380 if ( ((driver_name) && (SDL_strcasecmp(backend->name, driver_name))) || |
380 if (bootstrap[i]->available()) { | 381 ((!driver_name) && (backend->demand_only)) ) { |
381 SDL_memset(¤t_audio, 0, sizeof (current_audio)); | 382 continue; |
382 current_audio.name = bootstrap[i]->name; | 383 } |
383 current_audio.desc = bootstrap[i]->desc; | 384 |
384 initialized = bootstrap[i]->init(¤t_audio.impl); | 385 tried_to_init = 1; |
385 } | 386 SDL_memset(¤t_audio, 0, sizeof (current_audio)); |
386 break; | 387 current_audio.name = backend->name; |
388 current_audio.desc = backend->desc; | |
389 initialized = backend->init(¤t_audio.impl); | |
390 } | |
391 | |
392 if (!initialized) { | |
393 /* specific drivers will set the error message if they fail... */ | |
394 if (!tried_to_init) { | |
395 if (driver_name) { | |
396 SDL_SetError("%s not available", driver_name); | |
397 } else { | |
398 SDL_SetError("No available audio device"); | |
387 } | 399 } |
388 } | 400 } |
389 } else { | 401 |
390 for (i = 0; (!initialized) && (bootstrap[i]); ++i) { | |
391 if ((!bootstrap[i]->demand_only) && (bootstrap[i]->available())) { | |
392 SDL_memset(¤t_audio, 0, sizeof (current_audio)); | |
393 current_audio.name = bootstrap[i]->name; | |
394 current_audio.desc = bootstrap[i]->desc; | |
395 initialized = bootstrap[i]->init(¤t_audio.impl); | |
396 } | |
397 } | |
398 } | |
399 | |
400 if (!initialized) { | |
401 if (driver_name) { | |
402 SDL_SetError("%s not available", driver_name); | |
403 } else { | |
404 SDL_SetError("No available audio device"); | |
405 } | |
406 SDL_memset(¤t_audio, 0, sizeof (current_audio)); | 402 SDL_memset(¤t_audio, 0, sizeof (current_audio)); |
407 return (-1); /* No driver was available, so fail. */ | 403 return (-1); /* No driver was available, so fail. */ |
408 } | 404 } |
409 | 405 |
410 finalize_audio_entry_points(); | 406 finalize_audio_entry_points(); |