1
0
Fork 0
forked from len0rd/rockbox

Add comments, and prevent a nearly impossible wrapping bug. There's always enough space for the next whole audio chunk now, so it's faster too

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8678 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Brandon Low 2006-02-13 17:08:53 +00:00
parent 3a37faee57
commit 3bbd93b260

View file

@ -717,7 +717,8 @@ static bool prepare_insert(size_t length)
return false; return false;
} }
if (audiobuffer_free < length && !crossfade_active) /* Need to save PCMBUF_MIN_CHUNK to prevent wrapping overwriting */
if (audiobuffer_free < length + PCMBUF_MIN_CHUNK && !crossfade_active)
{ {
pcmbuf_boost(false); pcmbuf_boost(false);
return false; return false;
@ -750,16 +751,18 @@ void* pcmbuf_request_buffer(size_t length, size_t *realsize)
if(prepare_insert(length)) if(prepare_insert(length))
{ {
size_t audiobuffer_index = audiobuffer_pos + audiobuffer_fillpos; size_t audiobuffer_index = audiobuffer_pos + audiobuffer_fillpos;
if (pcmbuf_size - audiobuffer_index < PCMBUF_MIN_CHUNK) { *realsize = length;
pcmbuf_flush_fillpos(); if (pcmbuf_size - audiobuffer_index >= PCMBUF_MIN_CHUNK)
audiobuffer_pos = 0; {
*realsize = MIN(length, pcmbuf_size); /* Usual case, there's space here */
return &audiobuffer[0]; return &audiobuffer[audiobuffer_index];
} }
else else
{ {
*realsize = MIN(length, pcmbuf_size - audiobuffer_index); /* Flush and wrap the buffer */
return &audiobuffer[audiobuffer_index]; pcmbuf_flush_fillpos();
audiobuffer_pos = 0;
return &audiobuffer[0];
} }
} }
else else