summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c b/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c
index cb72687d48..ac268b4a19 100644
--- a/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c
+++ b/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c
@@ -132,38 +132,42 @@ static void ROCKBOXAUD_WaitAudio(_THIS)
132} 132}
133 133
134/* when this is called, SDL wants us to play the samples in mixbuf */ 134/* when this is called, SDL wants us to play the samples in mixbuf */
135static void ROCKBOXAUD_PlayAudio(_THIS) 135static void
136ROCKBOXAUD_PlayAudio(_THIS)
136{ 137{
137 /* There are two cases in which we should be called: 138 /* There are two cases in which we should be called:
138 * - There is an empty buffer (marked with status = 0) 139 * - There is an empty buffer (marked with status = 0)
139 * - There are more than two buffers marked as playing, meaning at least one is stale. 140 * - There are more than two buffers marked as playing, meaning at least one is stale.
140 */ 141 */
141 int idx = -1;
142 142
143 /* Find the next empty or stale buffer and fill. */ 143 /* Find the next empty or stale buffer and fill. */
144 for(int i = 1; i < this->hidden->n_buffers; ++i) 144 for(int i = 1; i <= this->hidden->n_buffers; ++i)
145 { 145 {
146 idx = (this->hidden->current_playing + i) % this->hidden->n_buffers; 146 int idx = (this->hidden->current_playing + i) % this->hidden->n_buffers;
147 147
148 /* Empty or stale. */ 148 /* Empty or stale. */
149 if(this->hidden->status[idx] == 0 || 149 if(this->hidden->status[idx] == 0 ||
150 this->hidden->status[idx] == 2) 150 this->hidden->status[idx] == 2) {
151 break; 151
152 } 152 LOGF("found empty buffer: %d (status: %d)", idx, this->hidden->status[idx]);
153 if(idx < 0) 153
154 return; 154 /* probably premature optimization here */
155 char *dst = (char*)this->hidden->rb_buf[idx], *src = this->hidden->mixbuf;
156 int size = this->spec.size / 2;
157 memcpy(dst, src, size);
155 158
156 /* probably premature optimization here */ 159 this->hidden->status[idx] = 1;
157 char *dst = (char*)this->hidden->rb_buf[idx], *src = this->hidden->mixbuf; 160 rb->yield();
158 int size = this->hidden->mixlen / 2;
159 memcpy(dst, src, size);
160 161
161 this->hidden->status[idx] = 1; 162 memcpy(dst + size, src + size, this->spec.size - size);
162 rb->yield();
163 163
164 memcpy(dst + size, src + size, this->hidden->mixlen - size); 164 LOGF("filled buffer %d (status %d %d %d %d)", idx, this->hidden->status[0], this->hidden->status[1], this->hidden->status[2], this->hidden->status[3]);
165
166 return;
167 }
168 }
165 169
166 //LOGF("filled buffer %d (status %d %d %d)", idx, this->hidden->status[0], this->hidden->status[1], this->hidden->status[2]); 170 LOGF("WARNING: PlayDevice could not find buffer to fill; DROPPING SAMPLES!");
167} 171}
168 172
169static SDL_AudioDevice *ROCKBOXAUD_CreateDevice(int devindex) 173static SDL_AudioDevice *ROCKBOXAUD_CreateDevice(int devindex)