comparison 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
comparison
equal deleted inserted replaced
149:1df5c106504e 150:033afe96afbc
76 { 76 {
77 for (i = rc; *i != NULL; i++) 77 for (i = rc; *i != NULL; i++)
78 { 78 {
79 printf(" * %s\n", (*i)->description); 79 printf(" * %s\n", (*i)->description);
80 for (ext = (*i)->extensions; *ext != NULL; ext++) 80 for (ext = (*i)->extensions; *ext != NULL; ext++)
81 printf(" Extension \"%s\"\n", *ext); 81 printf(" File extension \"%s\"\n", *ext);
82 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url); 82 printf(" Written by %s.\n %s\n\n", (*i)->author, (*i)->url);
83 } /* for */ 83 } /* for */
84 } /* else */ 84 } /* else */
85 85
86 printf("\n"); 86 printf("\n");
118 static Uint32 decoded_bytes = 0; 118 static Uint32 decoded_bytes = 0;
119 119
120 static void audio_callback(void *userdata, Uint8 *stream, int len) 120 static void audio_callback(void *userdata, Uint8 *stream, int len)
121 { 121 {
122 Sound_Sample *sample = (Sound_Sample *) userdata; 122 Sound_Sample *sample = (Sound_Sample *) userdata;
123 int bw = 0; /* bytes written to stream*/ 123 int bw = 0; /* bytes written to stream this time through the callback */
124 int cpysize;
125 124
126 while (bw < len) 125 while (bw < len)
127 { 126 {
128 if (!decoded_bytes) 127 int cpysize; /* bytes to copy on this iteration of the loop. */
128
129 if (!decoded_bytes) /* need more data decoded from sample? */
129 { 130 {
130 if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF)) 131 if (sample->flags & (SOUND_SAMPLEFLAG_ERROR|SOUND_SAMPLEFLAG_EOF))
131 { 132 {
133 /* ...but there isn't any more data to decode! */
132 memset(stream + bw, '\0', len - bw); 134 memset(stream + bw, '\0', len - bw);
133 done_flag = 1; 135 done_flag = 1;
134 return; 136 return;
135 } /* if */ 137 } /* if */
136 138
144 146
145 if (cpysize > 0) 147 if (cpysize > 0)
146 { 148 {
147 memcpy(stream + bw, decoded_ptr, cpysize); 149 memcpy(stream + bw, decoded_ptr, cpysize);
148 bw += cpysize; 150 bw += cpysize;
149 decoded_ptr += bw; 151 decoded_ptr += cpysize;
150 decoded_bytes -= bw; 152 decoded_bytes -= cpysize;
151 } /* if */ 153 } /* if */
152 } /* while */ 154 } /* while */
153 } /* audio_callback */ 155 } /* audio_callback */
154 156
155 157