From 3bbd93b26019e638739641b70557d17eebfac08a Mon Sep 17 00:00:00 2001 From: Brandon Low Date: Mon, 13 Feb 2006 17:08:53 +0000 Subject: 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 --- apps/pcmbuf.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'apps/pcmbuf.c') 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 -- cgit v1.2.3