commit 6fb6d096ec5ddaa7f3645eb9d740f36a59823a05 parent c85c754b081b7707603dde3adffa588181174e7c Author: dsp56300 <dsp56300@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:13:59 +0200 fix timing Diffstat:
M | source/nord/n2x/n2xLib/n2xhardware.cpp | | | 10 | ++++++++-- |
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/source/nord/n2x/n2xLib/n2xhardware.cpp b/source/nord/n2x/n2xLib/n2xhardware.cpp @@ -199,15 +199,21 @@ namespace n2x } const auto esaiFrameIndex = m_esaiFrameIndex; + const auto esaiDelta = esaiFrameIndex - m_lastEsaiFrameIndex; const auto ucClock = m_uc.getSim().getSystemClockHz(); - const double ucCyclesPerFrame = static_cast<double>(ucClock) * m_samplerateInv; - const auto esaiDelta = esaiFrameIndex - m_lastEsaiFrameIndex; + // if the UC consumed more cycles than it was allowed to, remove them from remaining cycles + m_remainingUcCyclesD += static_cast<double>(m_remainingUcCycles); + // add cycles for the ESAI time that has passed m_remainingUcCyclesD += ucCyclesPerFrame * static_cast<double>(esaiDelta); + + // set new remaining cycle count m_remainingUcCycles = static_cast<int64_t>(m_remainingUcCyclesD); + + // and consume them m_remainingUcCyclesD -= static_cast<double>(m_remainingUcCycles); if(esaiDelta > g_syncHaltDspEsaiThreshold)