Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

sdl: fix two bugs in ROCKBOXAUD_PlayAudio()

First was an off-by-one bug in the loop over buffers. The condition was
`i < this->hidden->n_buffers', but should have been <=, not <. This wasn't
a critical issue, because the last iteration would check the currently
playing buffer - an unlikely situation.

The second logic bug would make the code always think it had found an empty
buffer, even when it had not, since `idx' was being unconditionally set
every loop, rendering it unusable for a sentinel value. Fix that.

Change-Id: I137330965d699acf827e59b6aa5c5f9ddf2ca617

authored by

Franklin Wei and committed by
Solomon Peachy
4554b908 e232f692

+21 -17
+21 -17
apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c
··· 132 132 } 133 133 134 134 /* when this is called, SDL wants us to play the samples in mixbuf */ 135 - static void ROCKBOXAUD_PlayAudio(_THIS) 135 + static void 136 + ROCKBOXAUD_PlayAudio(_THIS) 136 137 { 137 138 /* There are two cases in which we should be called: 138 139 * - There is an empty buffer (marked with status = 0) 139 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 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 148 /* Empty or stale. */ 149 149 if(this->hidden->status[idx] == 0 || 150 - this->hidden->status[idx] == 2) 151 - break; 152 - } 153 - if(idx < 0) 154 - return; 150 + this->hidden->status[idx] == 2) { 155 151 156 - /* probably premature optimization here */ 157 - char *dst = (char*)this->hidden->rb_buf[idx], *src = this->hidden->mixbuf; 158 - int size = this->hidden->mixlen / 2; 159 - memcpy(dst, src, size); 152 + LOGF("found empty buffer: %d (status: %d)", idx, this->hidden->status[idx]); 160 153 161 - this->hidden->status[idx] = 1; 162 - rb->yield(); 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); 158 + 159 + this->hidden->status[idx] = 1; 160 + rb->yield(); 161 + 162 + memcpy(dst + size, src + size, this->spec.size - size); 163 + 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]); 163 165 164 - memcpy(dst + size, src + size, this->hidden->mixlen - size); 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 169 173 static SDL_AudioDevice *ROCKBOXAUD_CreateDevice(int devindex)