Mercurial > sdl-ios-xcode
diff src/audio/arts/SDL_artsaudio.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 | 9d070c1a45fa |
children |
line wrap: on
line diff
--- a/src/audio/arts/SDL_artsaudio.c Tue Oct 17 08:04:51 2006 +0000 +++ b/src/audio/arts/SDL_artsaudio.c Tue Oct 17 09:09:21 2006 +0000 @@ -126,32 +126,6 @@ #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */ -/* Audio driver bootstrap functions */ - -static int -ARTS_Available(void) -{ - int available = 0; - - if (LoadARTSLibrary() == 0) { - if (SDL_NAME(arts_init) () == 0) { -#define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */ -#ifdef ARTS_CRASH_HACK - arts_stream_t stream; - stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL"); - SDL_NAME(arts_write) (stream, "", 0); - SDL_NAME(arts_close_stream) (stream); -#endif - available = 1; - SDL_NAME(arts_free) (); - } - UnloadARTSLibrary(); - } - - return available; -} - - /* This function waits until it is possible to write a full sound buffer */ static void ARTS_WaitDevice(_THIS) @@ -232,7 +206,6 @@ SDL_free(this->hidden); this->hidden = NULL; } - UnloadARTSLibrary(); } @@ -252,12 +225,6 @@ } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); - if (LoadARTSLibrary() < 0) { - ARTS_CloseDevice(this); - SDL_SetError("ARTS: failed to load library: %s", SDL_GetError()); - return 0; - } - /* Try for a closest match on audio format */ for (test_format = SDL_FirstAudioFormat(this->spec.format); !format && test_format;) { @@ -341,9 +308,33 @@ } +static void +ARTS_Deinitialize(void) +{ + UnloadARTSLibrary(); +} + + static int ARTS_Init(SDL_AudioDriverImpl *impl) { + if (LoadARTSLibrary() < 0) { + return 0; + } else { + if (SDL_NAME(arts_init) () != 0) { + UnloadARTSLibrary(); + SDL_SetError("ARTS: arts_init failed (no audio server?)"); + return 0; + } + + /* Play a stream so aRts doesn't crash */ + arts_stream_t stream; + stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL"); + SDL_NAME(arts_write) (stream, "", 0); + SDL_NAME(arts_close_stream) (stream); + SDL_NAME(arts_free) (); + } + /* Set the function pointers */ impl->OpenDevice = ARTS_OpenDevice; impl->PlayDevice = ARTS_PlayDevice; @@ -351,6 +342,7 @@ impl->GetDeviceBuf = ARTS_GetDeviceBuf; impl->CloseDevice = ARTS_CloseDevice; impl->WaitDone = ARTS_WaitDone; + impl->Deinitialize = ARTS_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; return 1; @@ -358,8 +350,7 @@ AudioBootStrap ARTS_bootstrap = { - ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", - ARTS_Available, ARTS_Init, 0 + ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", ARTS_Init, 0 }; /* vi: set ts=4 sw=4 expandtab: */