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
This commit is contained in:
Max Kellermann 2008-04-12 04:14:01 +00:00 committed by Eric Wong
parent b009b2a437
commit dc55e13ca1

View File

@ -76,11 +76,13 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc)
wakeup_main_task();
}
static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af)
static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af,
float totalTime)
{
long chunks;
if (pc->crossFade <= 0)
if (pc->crossFade <= 0 || pc->crossFade >= totalTime ||
!isCurrentAudioFormat(af))
return 0;
chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
@ -499,21 +501,17 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
/* enable cross fading in this song? if yes,
calculate how many chunks will be required
for it */
if (isCurrentAudioFormat(&(cb->audioFormat))) {
crossFadeChunks =
calculateCrossFadeChunks(pc,
&(cb->
audioFormat),
dc->totalTime);
if (crossFadeChunks > 0) {
doCrossFade = 1;
nextChunk = -1;
crossFadeChunks =
calculateCrossFadeChunks(pc,
&(cb->
audioFormat));
if (!crossFadeChunks
|| pc->crossFade >= dc->totalTime) {
/* cross fading is disabled or
the next song is too
short */
doCrossFade = -1;
}
} else
/* cross fading is disabled or the
next song is too short */
doCrossFade = -1;
}