From 4939ee7fb09f8eeee77d410953e00e96e6d263f9 Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 14 Oct 2026 19:19:50 +0200 Subject: [PATCH] Account for transposer prefill in source coordinates --- lib/soundtouch-master/source/SoundTouch/RateTransposer.h | 3 ++- tools/chatgui/tests/test_soundtouch_clock.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/soundtouch-master/source/SoundTouch/RateTransposer.h b/lib/soundtouch-master/source/SoundTouch/RateTransposer.h index 28311ba4..48244c80 100644 --- a/lib/soundtouch-master/source/SoundTouch/RateTransposer.h +++ b/lib/soundtouch-master/source/SoundTouch/RateTransposer.h @@ -136,7 +136,8 @@ public: AAFilter *getAAFilter(); /// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable - int unitySourceOffset() const { return bUseAAFilter ? -1 : pTransposer->unitySourceOffset(); } + // clear() добавляет getLatency() нулей: они компенсируют смещение интерполятора. + int unitySourceOffset() const { return bUseAAFilter ? -1 : pTransposer->unitySourceOffset() - getLatency(); } void enableAAFilter(bool newMode); diff --git a/tools/chatgui/tests/test_soundtouch_clock.cpp b/tools/chatgui/tests/test_soundtouch_clock.cpp index 9b024627..e73db40a 100644 --- a/tools/chatgui/tests/test_soundtouch_clock.cpp +++ b/tools/chatgui/tests/test_soundtouch_clock.cpp @@ -74,6 +74,11 @@ static void check_exact(unsigned channels, unsigned block) { expected = expected * (1.0f - weight) + source[(s.input1 + i) * channels + ch] * weight; } float actual = output[(s.output + i) * channels + ch]; + if (std::abs(actual - expected) >= 0.000002f) + DEBUG_ERROR(DEBUG_CATEGORY_CALL, "source mismatch channels=%u block=%u kind=%d out=%llu input0=%llu input1=%llu" + " count=%u i=%u channel=%u actual=%.9g expected=%.9g", channels, block, (int)s.kind, + (unsigned long long)s.output, (unsigned long long)s.input0, (unsigned long long)s.input1, + s.count, i, ch, actual, expected); CHECK(std::abs(actual - expected) < 0.000002f); if (s.kind == soundtouch::SourceKind::Copy) CHECK(actual == expected); } @@ -84,7 +89,7 @@ static void check_exact(unsigned channels, unsigned block) { tracked.clear(); plain.clear(); CHECK(trace.resets == 2 && trace.spans.empty()); tracked.putSamples(source.data(), 4000); plain.putSamples(source.data(), 4000); - CHECK(!trace.spans.empty() && trace.spans.front().output == 0 && trace.spans.front().input0 == 1); + CHECK(!trace.spans.empty() && trace.spans.front().output == 0 && trace.spans.front().input0 == 0); CHECK(!tracked.setSourceCallback(source_event, &trace) && trace.reason == soundtouch::SourceError::LateAttach); trace.invalid = 0; tracked.setRate(1.01);