From b028d84aab49c2f407383c7e3820de45c47c8db4 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 24 Jan 2017 18:20:17 +0000 Subject: [PATCH] fix audio-mixer sleep --- assignment-client/src/audio/AudioMixer.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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; }