From bbc188db8d03e30cd29b67b5fc0257efe9ae67b5 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 11 Aug 2019 05:37:53 +0100 Subject: [PATCH] AudioMidiSyncHelper: Fix run cycles with many events --- distrho/DistrhoPluginUtils.hpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/distrho/DistrhoPluginUtils.hpp b/distrho/DistrhoPluginUtils.hpp index f4c153ae..7c343033 100644 --- a/distrho/DistrhoPluginUtils.hpp +++ b/distrho/DistrhoPluginUtils.hpp @@ -92,9 +92,11 @@ public: // render audio until first midi event, if needed if (const uint32_t firstEventFrame = midiEvents[0].frame) { - frames = midiEvents[0].frame; - remainingFrames -= frames; - totalFramesUsed += frames; + DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame < remainingFrames, + firstEventFrame, remainingFrames, false); + frames = firstEventFrame; + remainingFrames -= firstEventFrame; + totalFramesUsed += firstEventFrame; return true; } } @@ -120,7 +122,8 @@ public: midiEvents += midiEventCount; const uint32_t firstEventFrame = midiEvents[0].frame; - DISTRHO_SAFE_ASSERT_RETURN((firstEventFrame - frames) < remainingFrames, false); + DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame >= totalFramesUsed, + firstEventFrame, totalFramesUsed, false); midiEventCount = 1; while (midiEventCount < remainingMidiEventCount) @@ -131,16 +134,7 @@ public: break; } - if (totalFramesUsed != 0) - { - for (uint32_t i=0; i < midiEventCount; ++i) - { - DISTRHO_SAFE_ASSERT_UINT2_BREAK(midiEvents[i].frame - totalFramesUsed == 0, - midiEvents[i].frame, totalFramesUsed); - } - } - - frames = remainingFrames - firstEventFrame; + frames = firstEventFrame - totalFramesUsed; remainingFrames -= frames; remainingMidiEventCount -= midiEventCount; totalFramesUsed += frames;