src/audio/arts/SDL_artsaudio.c
branchSDL-1.2
changeset 6151 331f27f01cdb
parent 6137 4720145f848b
equal deleted inserted replaced
6150:5f0b3693ab60 6151:331f27f01cdb
    63 static arts_stream_t (*SDL_NAME(arts_play_stream))(int rate, int bits, int channels, const char *name);
    63 static arts_stream_t (*SDL_NAME(arts_play_stream))(int rate, int bits, int channels, const char *name);
    64 static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param, int value);
    64 static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param, int value);
    65 static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param);
    65 static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param);
    66 static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count);
    66 static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count);
    67 static void (*SDL_NAME(arts_close_stream))(arts_stream_t s);
    67 static void (*SDL_NAME(arts_close_stream))(arts_stream_t s);
       
    68 static int (*SDL_NAME(arts_suspend))(void);
    68 static int (*SDL_NAME(arts_suspended))(void);
    69 static int (*SDL_NAME(arts_suspended))(void);
    69 static const char *(*SDL_NAME(arts_error_text))(int errorcode);
    70 static const char *(*SDL_NAME(arts_error_text))(int errorcode);
    70 
    71 
    71 static struct {
    72 static struct {
    72 	const char *name;
    73 	const char *name;
    77 	{ "arts_play_stream",	(void **)&SDL_NAME(arts_play_stream)	},
    78 	{ "arts_play_stream",	(void **)&SDL_NAME(arts_play_stream)	},
    78 	{ "arts_stream_set",	(void **)&SDL_NAME(arts_stream_set)	},
    79 	{ "arts_stream_set",	(void **)&SDL_NAME(arts_stream_set)	},
    79 	{ "arts_stream_get",	(void **)&SDL_NAME(arts_stream_get)	},
    80 	{ "arts_stream_get",	(void **)&SDL_NAME(arts_stream_get)	},
    80 	{ "arts_write",		(void **)&SDL_NAME(arts_write)		},
    81 	{ "arts_write",		(void **)&SDL_NAME(arts_write)		},
    81 	{ "arts_close_stream",	(void **)&SDL_NAME(arts_close_stream)	},
    82 	{ "arts_close_stream",	(void **)&SDL_NAME(arts_close_stream)	},
       
    83 	{ "arts_suspend",	(void **)&SDL_NAME(arts_suspend)	},
    82 	{ "arts_suspended",	(void **)&SDL_NAME(arts_suspended)	},
    84 	{ "arts_suspended",	(void **)&SDL_NAME(arts_suspended)	},
    83 	{ "arts_error_text",	(void **)&SDL_NAME(arts_error_text)	},
    85 	{ "arts_error_text",	(void **)&SDL_NAME(arts_error_text)	},
    84 };
    86 };
    85 
    87 
    86 static void UnloadARTSLibrary()
    88 static void UnloadARTSLibrary()
   126 
   128 
   127 #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
   129 #endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
   128 
   130 
   129 /* Audio driver bootstrap functions */
   131 /* Audio driver bootstrap functions */
   130 
   132 
       
   133 static int ARTS_Suspend(void)
       
   134 {
       
   135 	const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
       
   136 	while ( (!SDL_NAME(arts_suspended)()) && (SDL_GetTicks() < abortms) ) {
       
   137 		if ( SDL_NAME(arts_suspend)() ) {
       
   138 			break;
       
   139 		}
       
   140 	}
       
   141 
       
   142 	return SDL_NAME(arts_suspended)();
       
   143 }
       
   144 
   131 static int Audio_Available(void)
   145 static int Audio_Available(void)
   132 {
   146 {
   133 	int available = 0;
   147 	int available = 0;
   134 
   148 
   135 	if ( LoadARTSLibrary() < 0 ) {
   149 	if ( LoadARTSLibrary() < 0 ) {
   136 		return available;
   150 		return available;
   137 	}
   151 	}
   138 	if ( SDL_NAME(arts_init)() == 0 ) {
   152 	if ( SDL_NAME(arts_init)() == 0 ) {
   139 		if ( SDL_NAME(arts_suspended)() ) {
   153 		if ( ARTS_Suspend() ) {
   140 			/* Play a stream so aRts doesn't crash */
   154 			/* Play a stream so aRts doesn't crash */
   141 			arts_stream_t stream2;
   155 			arts_stream_t stream2;
   142 			stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
   156 			stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
   143 			SDL_NAME(arts_write)(stream2, "", 0);
   157 			SDL_NAME(arts_write)(stream2, "", 0);
   144 			SDL_NAME(arts_close_stream)(stream2);
   158 			SDL_NAME(arts_close_stream)(stream2);
   305 	error_code = SDL_NAME(arts_init)();
   319 	error_code = SDL_NAME(arts_init)();
   306 	if ( error_code != 0 ) {
   320 	if ( error_code != 0 ) {
   307 		SDL_SetError("Unable to initialize ARTS: %s", SDL_NAME(arts_error_text)(error_code));
   321 		SDL_SetError("Unable to initialize ARTS: %s", SDL_NAME(arts_error_text)(error_code));
   308 		return(-1);
   322 		return(-1);
   309 	}
   323 	}
   310 	if ( ! SDL_NAME(arts_suspended)() ) {
   324 	if ( ! ARTS_Suspend() ) {
   311 		SDL_SetError("ARTS can not open audio device");
   325 		SDL_SetError("ARTS can not open audio device");
   312 		return(-1);
   326 		return(-1);
   313 	}
   327 	}
   314 	stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL");
   328 	stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL");
   315 
   329