comparison src/audio/SDL_audio.c @ 2665:f39a056aec8b gsoc2008_audio_resampling

More streamer work.
author Aaron Wishnick <schnarf@gmail.com>
date Tue, 12 Aug 2008 01:03:05 +0000
parents 344c8da164f4
children e12ccc6c9576
comparison
equal deleted inserted replaced
2664:344c8da164f4 2665:f39a056aec8b
280 int SDL_StreamLength(SDL_AudioStreamer * stream) { 280 int SDL_StreamLength(SDL_AudioStreamer * stream) {
281 return (stream->write_pos - stream->read_pos) % stream->max_len; 281 return (stream->write_pos - stream->read_pos) % stream->max_len;
282 } 282 }
283 283
284 /* Initialize the stream by allocating the buffer and setting the read/write heads to the beginning */ 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) { 285 int SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence) {
286 int i; 286 int i;
287 287
288 /* First try to allocate the buffer */ 288 /* First try to allocate the buffer */
289 stream->buffer = (Uint8 *)malloc(max_len); 289 stream->buffer = (Uint8 *)malloc(max_len);
290 if(stream->buffer == NULL) { 290 if(stream->buffer == NULL) {
295 stream->read_pos = 0; 295 stream->read_pos = 0;
296 stream->write_pos = 0; 296 stream->write_pos = 0;
297 297
298 /* Zero out the buffer */ 298 /* Zero out the buffer */
299 for(i = 0; i < max_len; ++i) { 299 for(i = 0; i < max_len; ++i) {
300 stream->buffer[i] = 0; 300 stream->buffer[i] = silence;
301 } 301 }
302 } 302 }
303 303
304 /* Deinitialize the stream simply by freeing the buffer */ 304 /* Deinitialize the stream simply by freeing the buffer */
305 void SDL_StreamDeinit(SDL_AudioStreamer * stream) { 305 void SDL_StreamDeinit(SDL_AudioStreamer * stream) {
337 stream_len = device->convert.len; 337 stream_len = device->convert.len;
338 } else { 338 } else {
339 silence = device->spec.silence; 339 silence = device->spec.silence;
340 stream_len = device->spec.size; 340 stream_len = device->spec.size;
341 } 341 }
342
343 /* Determine if the streamer is necessary here */
342 344
343 /* Loop, filling the audio buffers */ 345 /* Loop, filling the audio buffers */
344 while (device->enabled) { 346 while (device->enabled) {
345 347
346 /* Fill the current buffer with sound */ 348 /* Fill the current buffer with sound */