diff options
-rw-r--r-- | src/decode.c | 8 | ||||
-rw-r--r-- | src/outputBuffer.c | 13 | ||||
-rw-r--r-- | src/outputBuffer.h | 6 |
3 files changed, 17 insertions, 10 deletions
diff --git a/src/decode.c b/src/decode.c index 688d78322..55f272303 100644 --- a/src/decode.c +++ b/src/decode.c @@ -496,12 +496,8 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * else if (!outputBufferEmpty(cb) && cb->begin != next) { unsigned int fadePosition; if (doCrossFade == 1 && next >= 0 && - ((next > cb->begin && - (fadePosition = next - cb->begin) - <= crossFadeChunks) || - (cb->begin > next && - (fadePosition = next - cb->begin + - buffered_chunks) <= crossFadeChunks))) { + (fadePosition = outputBufferRelative(cb, next)) + <= crossFadeChunks) { /* perform cross fade */ if (nextChunk < 0) { /* beginning of the cross fade diff --git a/src/outputBuffer.c b/src/outputBuffer.c index f6fb38937..aadd5e379 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -62,12 +62,17 @@ int outputBufferEmpty(const OutputBuffer * cb) return cb->begin == cb->end; } -unsigned availableOutputBuffer(const OutputBuffer * cb) +unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i) { - if (cb->end >= cb->begin) - return cb->end - cb->begin; + if (i >= cb->begin) + return i - cb->begin; else - return cb->end + buffered_chunks - cb->begin; + return i + buffered_chunks - cb->begin; +} + +unsigned availableOutputBuffer(const OutputBuffer * cb) +{ + return outputBufferRelative(cb, cb->end); } int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative) diff --git a/src/outputBuffer.h b/src/outputBuffer.h index 252a0a905..0af264c14 100644 --- a/src/outputBuffer.h +++ b/src/outputBuffer.h @@ -58,6 +58,12 @@ void flushOutputBuffer(OutputBuffer * cb); /** is the buffer empty? */ int outputBufferEmpty(const OutputBuffer * cb); +/** + * what is the position of the specified chunk number, relative to + * the first chunk in use? + */ +unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i); + /** determine the number of decoded chunks */ unsigned availableOutputBuffer(const OutputBuffer * cb); |