Commit dc55e13c authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

let calculateCrossFadeChunks() decide

Moved the decision whether to cross-fade the current song to calculateCrossFadeChunks(). This simplifies the function decoderParent() and eliminates one layer of indentation. git-svn-id: https://svn.musicpd.org/mpd/trunk@7276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent b009b2a4
...@@ -76,11 +76,13 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc) ...@@ -76,11 +76,13 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc)
wakeup_main_task(); wakeup_main_task();
} }
static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af,
float totalTime)
{ {
long chunks; long chunks;
if (pc->crossFade <= 0) if (pc->crossFade <= 0 || pc->crossFade >= totalTime ||
!isCurrentAudioFormat(af))
return 0; return 0;
chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE); chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
...@@ -499,21 +501,17 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * ...@@ -499,21 +501,17 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
/* enable cross fading in this song? if yes, /* enable cross fading in this song? if yes,
calculate how many chunks will be required calculate how many chunks will be required
for it */ for it */
if (isCurrentAudioFormat(&(cb->audioFormat))) {
doCrossFade = 1;
nextChunk = -1;
crossFadeChunks = crossFadeChunks =
calculateCrossFadeChunks(pc, calculateCrossFadeChunks(pc,
&(cb-> &(cb->
audioFormat)); audioFormat),
if (!crossFadeChunks dc->totalTime);
|| pc->crossFade >= dc->totalTime) { if (crossFadeChunks > 0) {
/* cross fading is disabled or doCrossFade = 1;
the next song is too nextChunk = -1;
short */
doCrossFade = -1;
}
} else } else
/* cross fading is disabled or the
next song is too short */
doCrossFade = -1; doCrossFade = -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment