Make calculateCrossFadeChunks() more generic and portable by
eliminating global variable access.
---

 src/decode.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/decode.c b/src/decode.c
index 4f12d7a..da649ec 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -64,9 +64,10 @@ static void quitDecode(void)
        wakeup_main_task();
 }
 
-static unsigned calculateCrossFadeChunks(AudioFormat * af, float totalTime)
+static unsigned calculateCrossFadeChunks(AudioFormat * af,
+                                        float totalTime, unsigned max_chunks)
 {
-       unsigned int buffered_chunks, chunks;
+       unsigned int chunks;
 
        if (pc.crossFade == 0 || pc.crossFade >= totalTime ||
            !isCurrentAudioFormat(af))
@@ -80,10 +81,8 @@ static unsigned calculateCrossFadeChunks(AudioFormat * af, 
float totalTime)
        chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
        chunks = (chunks * pc.crossFade + 0.5);
 
-       buffered_chunks = ob.size;
-       assert(buffered_chunks >= buffered_before_play);
-       if (chunks > (buffered_chunks - buffered_before_play))
-               chunks = buffered_chunks - buffered_before_play;
+       if (chunks > max_chunks)
+               chunks = max_chunks;
 
        return chunks;
 }
@@ -500,7 +499,9 @@ static void decodeParent(void)
                           for it */
                        crossFadeChunks =
                                calculateCrossFadeChunks(&(ob.audioFormat),
-                                                        dc.totalTime);
+                                                        dc.totalTime,
+                                                        ob.size -
+                                                        buffered_before_play);
                        if (crossFadeChunks > 0) {
                                do_xfade = XFADE_ENABLED;
                                nextChunk = -1;


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to