diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:16:37 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:16:37 +0000 |
commit | e566c4c64cbfae1141bb8619c6f4029fedc68ad6 (patch) | |
tree | ea4f39952f58a60219c2068618134d003fd9feda /src/decode.c | |
parent | f275a1a1abf353873ce85c5c66b2be7c51d317a5 (diff) |
decode: fix unsigned comparision and add some paranoid assertions
git-svn-id: https://svn.musicpd.org/mpd/trunk@7301 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/decode.c')
-rw-r--r-- | src/decode.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/decode.c b/src/decode.c index 7d292726d..0c4503872 100644 --- a/src/decode.c +++ b/src/decode.c @@ -79,24 +79,25 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc) static unsigned calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af, float totalTime) { - long chunks; + unsigned chunks; - if (pc->crossFade <= 0 || pc->crossFade >= totalTime || + if (pc->crossFade == 0 || pc->crossFade >= totalTime || !isCurrentAudioFormat(af)) return 0; + assert(pc->crossFade > 0); + assert(af->bits > 0); + assert(af->channels > 0); + assert(af->sampleRate > 0); + chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE); chunks = (chunks * pc->crossFade + 0.5); assert(buffered_chunks >= buffered_before_play); - if (chunks > (buffered_chunks - buffered_before_play)) { + if (chunks > (buffered_chunks - buffered_before_play)) chunks = buffered_chunks - buffered_before_play; - } - - if (chunks < 0) - chunks = 0; - return (unsigned)chunks; + return chunks; } static int waitOnDecode(PlayerControl * pc, DecoderControl * dc, |