comparison 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
comparison
equal deleted inserted replaced
3845:ee5dfa7f7993 3846:66fb40445587
124 return 0; 124 return 0;
125 } 125 }
126 126
127 #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */ 127 #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
128 128
129 /* Audio driver bootstrap functions */
130
131 static int
132 ARTS_Available(void)
133 {
134 int available = 0;
135
136 if (LoadARTSLibrary() == 0) {
137 if (SDL_NAME(arts_init) () == 0) {
138 #define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */
139 #ifdef ARTS_CRASH_HACK
140 arts_stream_t stream;
141 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
142 SDL_NAME(arts_write) (stream, "", 0);
143 SDL_NAME(arts_close_stream) (stream);
144 #endif
145 available = 1;
146 SDL_NAME(arts_free) ();
147 }
148 UnloadARTSLibrary();
149 }
150
151 return available;
152 }
153
154
155 /* This function waits until it is possible to write a full sound buffer */ 129 /* This function waits until it is possible to write a full sound buffer */
156 static void 130 static void
157 ARTS_WaitDevice(_THIS) 131 ARTS_WaitDevice(_THIS)
158 { 132 {
159 Sint32 ticks; 133 Sint32 ticks;
230 } 204 }
231 SDL_NAME(arts_free) (); 205 SDL_NAME(arts_free) ();
232 SDL_free(this->hidden); 206 SDL_free(this->hidden);
233 this->hidden = NULL; 207 this->hidden = NULL;
234 } 208 }
235 UnloadARTSLibrary();
236 } 209 }
237 210
238 211
239 static int 212 static int
240 ARTS_OpenDevice(_THIS, const char *devname, int iscapture) 213 ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
249 if (this->hidden == NULL) { 222 if (this->hidden == NULL) {
250 SDL_OutOfMemory(); 223 SDL_OutOfMemory();
251 return 0; 224 return 0;
252 } 225 }
253 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 226 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
254
255 if (LoadARTSLibrary() < 0) {
256 ARTS_CloseDevice(this);
257 SDL_SetError("ARTS: failed to load library: %s", SDL_GetError());
258 return 0;
259 }
260 227
261 /* Try for a closest match on audio format */ 228 /* Try for a closest match on audio format */
262 for (test_format = SDL_FirstAudioFormat(this->spec.format); 229 for (test_format = SDL_FirstAudioFormat(this->spec.format);
263 !format && test_format;) { 230 !format && test_format;) {
264 #ifdef DEBUG_AUDIO 231 #ifdef DEBUG_AUDIO
339 /* We're ready to rock and roll. :-) */ 306 /* We're ready to rock and roll. :-) */
340 return 1; 307 return 1;
341 } 308 }
342 309
343 310
311 static void
312 ARTS_Deinitialize(void)
313 {
314 UnloadARTSLibrary();
315 }
316
317
344 static int 318 static int
345 ARTS_Init(SDL_AudioDriverImpl *impl) 319 ARTS_Init(SDL_AudioDriverImpl *impl)
346 { 320 {
321 if (LoadARTSLibrary() < 0) {
322 return 0;
323 } else {
324 if (SDL_NAME(arts_init) () != 0) {
325 UnloadARTSLibrary();
326 SDL_SetError("ARTS: arts_init failed (no audio server?)");
327 return 0;
328 }
329
330 /* Play a stream so aRts doesn't crash */
331 arts_stream_t stream;
332 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
333 SDL_NAME(arts_write) (stream, "", 0);
334 SDL_NAME(arts_close_stream) (stream);
335 SDL_NAME(arts_free) ();
336 }
337
347 /* Set the function pointers */ 338 /* Set the function pointers */
348 impl->OpenDevice = ARTS_OpenDevice; 339 impl->OpenDevice = ARTS_OpenDevice;
349 impl->PlayDevice = ARTS_PlayDevice; 340 impl->PlayDevice = ARTS_PlayDevice;
350 impl->WaitDevice = ARTS_WaitDevice; 341 impl->WaitDevice = ARTS_WaitDevice;
351 impl->GetDeviceBuf = ARTS_GetDeviceBuf; 342 impl->GetDeviceBuf = ARTS_GetDeviceBuf;
352 impl->CloseDevice = ARTS_CloseDevice; 343 impl->CloseDevice = ARTS_CloseDevice;
353 impl->WaitDone = ARTS_WaitDone; 344 impl->WaitDone = ARTS_WaitDone;
345 impl->Deinitialize = ARTS_Deinitialize;
354 impl->OnlyHasDefaultOutputDevice = 1; 346 impl->OnlyHasDefaultOutputDevice = 1;
355 347
356 return 1; 348 return 1;
357 } 349 }
358 350
359 351
360 AudioBootStrap ARTS_bootstrap = { 352 AudioBootStrap ARTS_bootstrap = {
361 ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", 353 ARTS_DRIVER_NAME, "Analog RealTime Synthesizer", ARTS_Init, 0
362 ARTS_Available, ARTS_Init, 0
363 }; 354 };
364 355
365 /* vi: set ts=4 sw=4 expandtab: */ 356 /* vi: set ts=4 sw=4 expandtab: */