diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 6a4d8db0b9..50d2002399 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -464,14 +464,11 @@ std::chrono::microseconds AudioMixer::timeFrame(p_high_resolution_clock::time_po // compute how long the last frame took auto duration = std::chrono::duration_cast(now - timestamp); - // sleep until the next frame should start - if (nextTimestamp > now) { - auto timeToSleep = std::chrono::duration_cast(nextTimestamp - now); - std::this_thread::sleep_for(timeToSleep); - } - // set the new frame timestamp - timestamp = p_high_resolution_clock::now(); + timestamp = std::max(now, nextTimestamp); + + // sleep until the next frame should start + std::this_thread::sleep_until(timestamp); return duration; }