From b071d6ecf67afd8353430f1df51844d54510b5cd Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Mon, 24 Oct 2022 16:01:22 -0400 Subject: [PATCH] Avoid creation of legacy-invalid frame positions. --- src/audio/frame.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/audio/frame.h b/src/audio/frame.h index 1e37faeb652..29495ea7c7d 100644 --- a/src/audio/frame.h +++ b/src/audio/frame.h @@ -44,7 +44,15 @@ class FramePos final { /// values), use `FramePos::toEngineSamplePosMaybeInvalid` instead. double toEngineSamplePos() const { DEBUG_ASSERT(isValid()); - return value() * mixxx::kEngineChannelCount; + double engineSamplePos = value() * mixxx::kEngineChannelCount; + // In the rare but possible instance that the position is valid but + // the engine sample position is exactly -1.0, we nudge the position + // because otherwise fromEngineSamplePosMaybeInvalid() will think + // the position is invalid. + if (engineSamplePos == kLegacyInvalidEnginePosition) { + return kLegacyInvalidEnginePosition - .0001; + } + return engineSamplePos; } /// Return a `FramePos` from a given engine sample position. Sample