split sleep timing from check time timing

This commit is contained in:
Stephen Birarda 2018-09-05 16:29:11 -07:00
parent 996e033dee
commit 925c39cbd3
2 changed files with 12 additions and 5 deletions

View file

@ -283,6 +283,7 @@ void AudioMixer::sendStatsPacket() {
}; };
addTiming(_ticTiming, "tic"); addTiming(_ticTiming, "tic");
addTiming(_checkTimeTiming, "check_time");
addTiming(_sleepTiming, "sleep"); addTiming(_sleepTiming, "sleep");
addTiming(_frameTiming, "frame"); addTiming(_frameTiming, "frame");
addTiming(_packetsTiming, "packets"); addTiming(_packetsTiming, "packets");
@ -391,7 +392,7 @@ void AudioMixer::start() {
auto ticTimer = _ticTiming.timer(); auto ticTimer = _ticTiming.timer();
{ {
auto timer = _sleepTiming.timer(); auto timer = _checkTimeTiming.timer();
auto frameDuration = timeFrame(frameTimestamp); auto frameDuration = timeFrame(frameTimestamp);
throttle(frameDuration, frame); throttle(frameDuration, frame);
} }
@ -459,10 +460,14 @@ chrono::microseconds AudioMixer::timeFrame(p_high_resolution_clock::time_point&
// set the new frame timestamp // set the new frame timestamp
timestamp = max(now, nextTimestamp); timestamp = max(now, nextTimestamp);
{
auto timer = _sleepTiming.timer();
// sleep until the next frame should start // sleep until the next frame should start
// WIN32 sleep_until is broken until VS2015 Update 2 // WIN32 sleep_until is broken until VS2015 Update 2
// instead, max (above) guarantees that timestamp >= now, so we can sleep_for // instead, max (above) guarantees that timestamp >= now, so we can sleep_for
this_thread::sleep_for(timestamp - now); this_thread::sleep_for(timestamp - now);
}
return duration; return duration;
} }

View file

@ -125,7 +125,9 @@ private:
uint64_t _history[TIMER_TRAILING_SECONDS] {}; uint64_t _history[TIMER_TRAILING_SECONDS] {};
int _index { 0 }; int _index { 0 };
}; };
Timer _ticTiming; Timer _ticTiming;
Timer _checkTimeTiming;
Timer _sleepTiming; Timer _sleepTiming;
Timer _frameTiming; Timer _frameTiming;
Timer _prepareTiming; Timer _prepareTiming;