player/CrossFade: move code to CanCrossFade()

This commit is contained in:
Max Kellermann
2021-12-03 23:43:13 +01:00
parent b78c64376f
commit 2cafbb2aba
3 changed files with 42 additions and 23 deletions
+11 -6
View File
@@ -804,24 +804,29 @@ Player::CheckCrossFade() noexcept
can decide */
return;
if (!pc.cross_fade.CanCrossFade(pc.total_time, dc.total_time,
dc.out_audio_format,
play_audio_format)) {
/* cross fading is disabled or the next song is too
short */
xfade_state = CrossFadeState::DISABLED;
return;
}
/* enable cross fading in this song? if yes, calculate how
many chunks will be required for it */
cross_fade_chunks =
pc.cross_fade.Calculate(pc.total_time,
dc.total_time,
dc.replay_gain_db,
pc.cross_fade.Calculate(dc.replay_gain_db,
dc.replay_gain_prev_db,
dc.GetMixRampStart(),
dc.GetMixRampPreviousEnd(),
dc.out_audio_format,
play_audio_format,
buffer.GetSize() -
buffer_before_play);
if (cross_fade_chunks > 0)
xfade_state = CrossFadeState::ENABLED;
else
/* cross fading is disabled or the
next song is too short */
// TODO: eliminate this "else" branch
xfade_state = CrossFadeState::DISABLED;
}