Added streamer code. I haven't yet incorporated it into SDL_RunAudio() though.
1.1 --- a/src/audio/SDL_audio.c Tue Aug 12 00:24:42 2008 +0000
1.2 +++ b/src/audio/SDL_audio.c Tue Aug 12 00:50:58 2008 +0000
1.3 @@ -256,6 +256,58 @@
1.4 #undef FILL_STUB
1.5 }
1.6
1.7 +/* Streaming functions (for when the input and output buffer sizes are different) */
1.8 +/* Write [length] bytes from buf into the streamer */
1.9 +void SDL_StreamWrite(SDL_AudioStreamer * stream, Uint8 * buf, int length) {
1.10 + int i;
1.11 +
1.12 + for(i = 0; i < length; ++i) {
1.13 + stream->buffer[stream->write_pos] = buf[i];
1.14 + ++stream->write_pos;
1.15 + }
1.16 +}
1.17 +
1.18 +/* Read [length] bytes out of the streamer into buf */
1.19 +void SDL_StreamRead(SDL_AudioStreamer * stream, Uint8 * buf, int length) {
1.20 + int i;
1.21 +
1.22 + for(i = 0; i < length; ++i) {
1.23 + buf[i] = stream->buffer[stream->read_pos];
1.24 + ++stream->read_pos;
1.25 + }
1.26 +}
1.27 +
1.28 +int SDL_StreamLength(SDL_AudioStreamer * stream) {
1.29 + return (stream->write_pos - stream->read_pos) % stream->max_len;
1.30 +}
1.31 +
1.32 +/* Initialize the stream by allocating the buffer and setting the read/write heads to the beginning */
1.33 +int SDL_StreamInit(SDL_AudioStreamer * stream, int max_len) {
1.34 + int i;
1.35 +
1.36 + /* First try to allocate the buffer */
1.37 + stream->buffer = (Uint8 *)malloc(max_len);
1.38 + if(stream->buffer == NULL) {
1.39 + return -1;
1.40 + }
1.41 +
1.42 + stream->max_len = max_len;
1.43 + stream->read_pos = 0;
1.44 + stream->write_pos = 0;
1.45 +
1.46 + /* Zero out the buffer */
1.47 + for(i = 0; i < max_len; ++i) {
1.48 + stream->buffer[i] = 0;
1.49 + }
1.50 +}
1.51 +
1.52 +/* Deinitialize the stream simply by freeing the buffer */
1.53 +void SDL_StreamDeinit(SDL_AudioStreamer * stream) {
1.54 + if(stream->buffer != NULL) {
1.55 + free(stream->buffer);
1.56 + }
1.57 +}
1.58 +
1.59
1.60 /* The general mixing thread function */
1.61 int SDLCALL
2.1 --- a/src/audio/SDL_audio_c.h Tue Aug 12 00:24:42 2008 +0000
2.2 +++ b/src/audio/SDL_audio_c.h Tue Aug 12 00:50:58 2008 +0000
2.3 @@ -42,4 +42,12 @@
2.4 } SDL_AudioTypeFilters;
2.5 extern const SDL_AudioTypeFilters sdl_audio_type_filters[];
2.6
2.7 +/* Streamer */
2.8 +typedef struct
2.9 +{
2.10 + Uint8 *buffer;
2.11 + int max_len; // the maximum length in bytes
2.12 + int read_pos, write_pos; // the position of the write and read heads in bytes
2.13 +} SDL_AudioStreamer;
2.14 +
2.15 /* vi: set ts=4 sw=4 expandtab: */