diff playsound/playsound.c @ 150:033afe96afbc

Commenting and fixes for the audio callback.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 09 Nov 2001 08:06:28 +0000
parents d51546293fd1
children 87b00f023710
line wrap: on
line diff
--- 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 */