src/audio/SDL_audio.c
branchgsoc2008_audio_resampling
changeset 2664 344c8da164f4
parent 2274 aedfcdeb69b6
child 2665 f39a056aec8b
equal deleted inserted replaced
2663:0caed045d01b 2664:344c8da164f4
   254     FILL_STUB(UnlockDevice);
   254     FILL_STUB(UnlockDevice);
   255     FILL_STUB(Deinitialize);
   255     FILL_STUB(Deinitialize);
   256 #undef FILL_STUB
   256 #undef FILL_STUB
   257 }
   257 }
   258 
   258 
       
   259 /* Streaming functions (for when the input and output buffer sizes are different) */
       
   260 /* Write [length] bytes from buf into the streamer */
       
   261 void SDL_StreamWrite(SDL_AudioStreamer * stream, Uint8 * buf, int length) {
       
   262 	int i;
       
   263 	
       
   264 	for(i = 0; i < length; ++i) {
       
   265 		stream->buffer[stream->write_pos] = buf[i];
       
   266 		++stream->write_pos;
       
   267 	}
       
   268 }
       
   269 
       
   270 /* Read [length] bytes out of the streamer into buf */
       
   271 void SDL_StreamRead(SDL_AudioStreamer * stream, Uint8 * buf, int length) {
       
   272 	int i;
       
   273 	
       
   274 	for(i = 0; i < length; ++i) {
       
   275 		buf[i] = stream->buffer[stream->read_pos];
       
   276 		++stream->read_pos;
       
   277 	}
       
   278 }
       
   279 
       
   280 int SDL_StreamLength(SDL_AudioStreamer * stream) {
       
   281 	return (stream->write_pos - stream->read_pos) % stream->max_len;
       
   282 }
       
   283 
       
   284 /* Initialize the stream by allocating the buffer and setting the read/write heads to the beginning */
       
   285 int SDL_StreamInit(SDL_AudioStreamer * stream, int max_len) {
       
   286 	int i;
       
   287 
       
   288 	/* First try to allocate the buffer */
       
   289 	stream->buffer = (Uint8 *)malloc(max_len);
       
   290 	if(stream->buffer == NULL) {
       
   291 		return -1;
       
   292 	}
       
   293 	
       
   294 	stream->max_len = max_len;
       
   295 	stream->read_pos = 0;
       
   296 	stream->write_pos = 0;
       
   297 	
       
   298 	/* Zero out the buffer */
       
   299 	for(i = 0; i < max_len; ++i) {
       
   300 		stream->buffer[i] = 0;
       
   301 	}
       
   302 }
       
   303 
       
   304 /* Deinitialize the stream simply by freeing the buffer */
       
   305 void SDL_StreamDeinit(SDL_AudioStreamer * stream) {
       
   306 	if(stream->buffer != NULL) {
       
   307 		free(stream->buffer);
       
   308 	}
       
   309 }
       
   310 
   259 
   311 
   260 /* The general mixing thread function */
   312 /* The general mixing thread function */
   261 int SDLCALL
   313 int SDLCALL
   262 SDL_RunAudio(void *devicep)
   314 SDL_RunAudio(void *devicep)
   263 {
   315 {