comparison src/audio/arts/SDL_artsaudio.c @ 2121:85ed90a755fa

Reworked r3067:3068 from branches/SDL-1.2: arts unavailable hardware bug fix.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 14 Jun 2007 14:22:54 +0000
parents 866052b01ee5
children e1a70460c354
comparison
equal deleted inserted replaced
2120:2c835d58faad 2121:85ed90a755fa
55 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s, 55 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
56 arts_parameter_t param); 56 arts_parameter_t param);
57 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer, 57 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
58 int count); 58 int count);
59 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s); 59 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
60 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s); 60 static int (*SDL_NAME(arts_suspended))(void);
61 static const char *(*SDL_NAME(arts_error_text)) (int errorcode); 61 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
62 62
63 #define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } 63 #define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
64 static struct 64 static struct
65 { 65 {
70 SDL_ARTS_SYM(arts_free), 70 SDL_ARTS_SYM(arts_free),
71 SDL_ARTS_SYM(arts_play_stream), 71 SDL_ARTS_SYM(arts_play_stream),
72 SDL_ARTS_SYM(arts_stream_set), 72 SDL_ARTS_SYM(arts_stream_set),
73 SDL_ARTS_SYM(arts_stream_get), 73 SDL_ARTS_SYM(arts_stream_get),
74 SDL_ARTS_SYM(arts_write), 74 SDL_ARTS_SYM(arts_write),
75 SDL_ARTS_SYM(arts_close_stream), SDL_ARTS_SYM(arts_error_text),}; 75 SDL_ARTS_SYM(arts_close_stream),
76 SDL_ARTS_SYM(arts_suspended),
77 SDL_ARTS_SYM(arts_error_text),
78 };
76 #undef SDL_ARTS_SYM 79 #undef SDL_ARTS_SYM
77 80
78 static void 81 static void
79 UnloadARTSLibrary() 82 UnloadARTSLibrary()
80 { 83 {
257 ARTS_CloseDevice(this); 260 ARTS_CloseDevice(this);
258 SDL_SetError("Unable to initialize ARTS: %s", 261 SDL_SetError("Unable to initialize ARTS: %s",
259 SDL_NAME(arts_error_text) (rc)); 262 SDL_NAME(arts_error_text) (rc));
260 return 0; 263 return 0;
261 } 264 }
265
266 if ( ! SDL_NAME(arts_suspended)() ) {
267 ARTS_CloseDevice(this);
268 SDL_SetError("ARTS can not open audio device");
269 return 0;
270 }
271
262 this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq, 272 this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
263 bits, 273 bits,
264 this->spec.channels, 274 this->spec.channels,
265 "SDL"); 275 "SDL");
276
277 /* Play nothing so we have at least one write (server bug workaround). */
278 SDL_NAME(arts_write) (this->hidden->stream, "", 0);
266 279
267 /* Calculate the final parameters for this audio specification */ 280 /* Calculate the final parameters for this audio specification */
268 SDL_CalculateAudioSpec(&this->spec); 281 SDL_CalculateAudioSpec(&this->spec);
269 282
270 /* Determine the power of two of the fragment size */ 283 /* Determine the power of two of the fragment size */
324 SDL_SetError("ARTS: arts_init failed (no audio server?)"); 337 SDL_SetError("ARTS: arts_init failed (no audio server?)");
325 return 0; 338 return 0;
326 } 339 }
327 340
328 /* Play a stream so aRts doesn't crash */ 341 /* Play a stream so aRts doesn't crash */
329 arts_stream_t stream; 342 if ( SDL_NAME(arts_suspended)() ) {
330 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL"); 343 arts_stream_t stream;
331 SDL_NAME(arts_write) (stream, "", 0); 344 stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
332 SDL_NAME(arts_close_stream) (stream); 345 SDL_NAME(arts_write) (stream, "", 0);
346 SDL_NAME(arts_close_stream) (stream);
347 }
348
333 SDL_NAME(arts_free) (); 349 SDL_NAME(arts_free) ();
334 } 350 }
335 351
336 /* Set the function pointers */ 352 /* Set the function pointers */
337 impl->OpenDevice = ARTS_OpenDevice; 353 impl->OpenDevice = ARTS_OpenDevice;