diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-02-13 17:08:53 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-02-13 17:08:53 +0000 |
commit | 3bbd93b26019e638739641b70557d17eebfac08a (patch) | |
tree | 1787a202d5e96c77f8e724402bf6813648d7ebfb /apps/pcmbuf.c | |
parent | 3a37faee5719d14218cd003a43b70c177810c838 (diff) |
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
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r-- | apps/pcmbuf.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index a5b5fd0c4b..c79b0d5fd9 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -717,7 +717,8 @@ static bool prepare_insert(size_t length) 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); return false; @@ -750,16 +751,18 @@ void* pcmbuf_request_buffer(size_t length, size_t *realsize) if(prepare_insert(length)) { size_t audiobuffer_index = audiobuffer_pos + audiobuffer_fillpos; - if (pcmbuf_size - audiobuffer_index < PCMBUF_MIN_CHUNK) { - pcmbuf_flush_fillpos(); - audiobuffer_pos = 0; - *realsize = MIN(length, pcmbuf_size); - return &audiobuffer[0]; + *realsize = length; + if (pcmbuf_size - audiobuffer_index >= PCMBUF_MIN_CHUNK) + { + /* Usual case, there's space here */ + return &audiobuffer[audiobuffer_index]; } else { - *realsize = MIN(length, pcmbuf_size - audiobuffer_index); - return &audiobuffer[audiobuffer_index]; + /* Flush and wrap the buffer */ + pcmbuf_flush_fillpos(); + audiobuffer_pos = 0; + return &audiobuffer[0]; } } else |