comparison playsound/playsound.c @ 144:195c96fa355a

Fix for properly streaming from the overflow buffer.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 17 Oct 2001 06:51:29 +0000
parents e3f4767d6037
children 023c3e7f028b
comparison
equal deleted inserted replaced
143:3e60862fbd76 144:195c96fa355a
88 static volatile int done_flag = 0; 88 static volatile int done_flag = 0;
89 89
90 static void audio_callback(void *userdata, Uint8 *stream, int len) 90 static void audio_callback(void *userdata, Uint8 *stream, int len)
91 { 91 {
92 static Uint8 overflow[16384]; /* this is a hack. */ 92 static Uint8 overflow[16384]; /* this is a hack. */
93 static Uint8 *overflow_ptr;
93 static int overflowBytes = 0; 94 static int overflowBytes = 0;
94 Sound_Sample *sample = (Sound_Sample *) userdata; 95 Sound_Sample *sample = (Sound_Sample *) userdata;
95 int bw = 0; /* bytes written to stream*/ 96 int bw = 0; /* bytes written to stream*/
96 Uint32 rc; /* return code */ 97 Uint32 rc; /* return code */
97 98
98 if (overflowBytes > 0) 99 if (overflowBytes > 0)
99 { 100 {
100 bw = (overflowBytes < len) ? overflowBytes : len; 101 bw = (overflowBytes < len) ? overflowBytes : len;
101 memcpy(stream, overflow, bw); 102 memcpy(stream, overflow_ptr, bw);
103 overflow_ptr += bw;
102 overflowBytes -= bw; 104 overflowBytes -= bw;
103 } /* if */ 105 } /* if */
104 106
105 while ((bw < len) && (!done_flag)) 107 while ((bw < len) && (!done_flag))
106 { 108 {
111 { 113 {
112 overflowBytes = (bw + rc) - len; 114 overflowBytes = (bw + rc) - len;
113 memcpy(overflow, 115 memcpy(overflow,
114 ((Uint8 *) sample->buffer) + (rc - overflowBytes), 116 ((Uint8 *) sample->buffer) + (rc - overflowBytes),
115 overflowBytes); 117 overflowBytes);
118 overflow_ptr = overflow;
116 rc -= overflowBytes; 119 rc -= overflowBytes;
117 } /* if */ 120 } /* if */
118 121
119 memcpy(stream + bw, sample->buffer, rc); 122 memcpy(stream + bw, sample->buffer, rc);
120 bw += rc; 123 bw += rc;