# HG changeset patch # User Ryan C. Gordon # Date 1005293188 0 # Node ID 033afe96afbcf2d7f1dafb0bdfa95017c84b9d4e # Parent 1df5c106504ee7c994a765ada01f0fa18cc92a19 Commenting and fixes for the audio callback. diff -r 1df5c106504e -r 033afe96afbc playsound/playsound.c --- a/playsound/playsound.c Thu Nov 01 19:13:17 2001 +0000 +++ b/playsound/playsound.c Fri Nov 09 08:06:28 2001 +0000 @@ -78,7 +78,7 @@ { printf(" * %s\n", (*i)->description); for (ext = (*i)->extensions; *ext != NULL; ext++) - printf(" Extension \"%s\"\n", *ext); + printf(" File extension \"%s\"\n", *ext); printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url); } /* for */ } /* else */ @@ -120,15 +120,17 @@ static void audio_callback(void *userdata, Uint8 *stream, int len) { Sound_Sample *sample = (Sound_Sample *) userdata; - int bw = 0; /* bytes written to stream*/ - int cpysize; + int bw = 0; /* bytes written to stream this time through the callback */ while (bw < len) { - if (!decoded_bytes) + int cpysize; /* bytes to copy on this iteration of the loop. */ + + if (!decoded_bytes) /* need more data decoded from sample? */ { if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF)) { + /* ...but there isn't any more data to decode! */ memset(stream + bw, '\0', len - bw); done_flag = 1; return; @@ -146,8 +148,8 @@ { memcpy(stream + bw, decoded_ptr, cpysize); bw += cpysize; - decoded_ptr += bw; - decoded_bytes -= bw; + decoded_ptr += cpysize; + decoded_bytes -= cpysize; } /* if */ } /* while */ } /* audio_callback */