From 84de88841be5ca0846eed380b11ad7cf8587754a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 22 Sep 2018 19:06:53 +0200 Subject: player/CrossFade: use AudioFormat::SizeToTime() instead of GetTimeToSize() --- src/player/CrossFade.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/player') diff --git a/src/player/CrossFade.cxx b/src/player/CrossFade.cxx index b7c5787c4..aafd137e7 100644 --- a/src/player/CrossFade.cxx +++ b/src/player/CrossFade.cxx @@ -97,7 +97,6 @@ CrossFadeSettings::Calculate(SignedSongTime total_time, unsigned max_chunks) const noexcept { unsigned int chunks = 0; - float chunks_f; if (total_time.IsNegative() || duration <= FloatDuration::zero() || @@ -109,11 +108,12 @@ CrossFadeSettings::Calculate(SignedSongTime total_time, assert(duration > FloatDuration::zero()); assert(af.IsValid()); - chunks_f = (float)af.GetTimeToSize() / (float)sizeof(MusicChunk::data); + const auto chunk_duration = + af.SizeToTime(sizeof(MusicChunk::data)); if (mixramp_delay <= FloatDuration::zero() || !mixramp_start || !mixramp_prev_end) { - chunks = std::lround(chunks_f * duration.count()); + chunks = std::lround(duration / chunk_duration); } else { /* Calculate mixramp overlap. */ const auto mixramp_overlap_current = @@ -128,7 +128,8 @@ CrossFadeSettings::Calculate(SignedSongTime total_time, if (mixramp_overlap_current >= FloatDuration::zero() && mixramp_overlap_prev >= FloatDuration::zero() && mixramp_delay <= mixramp_overlap) { - chunks = (chunks_f * (mixramp_overlap - mixramp_delay).count()); + chunks = lround((mixramp_overlap - mixramp_delay) + / chunk_duration); FormatDebug(cross_fade_domain, "will overlap %d chunks, %fs", chunks, (mixramp_overlap - mixramp_delay).count()); -- cgit v1.2.3