From 9e08925d7e5f2f7c58df1f222ba5a7c30bc17544 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 3 Apr 2017 11:34:29 -0700 Subject: [PATCH] involve clock time in _mouthTime calculation --- interface/src/avatar/Head.cpp | 16 +++++++++++++--- interface/src/avatar/Head.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index f4fb844d9b..1e075fa0c8 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -235,6 +235,7 @@ void Head::calculateMouthShapes() { const float JAW_OPEN_RATE = 0.9f; const float JAW_CLOSE_RATE = 0.90f; const float TIMESTEP_CONSTANT = 0.0032f; + const float USECS_IN_SIXTIETH_SEC = (1.0f / 60.0f) * USECS_PER_SECOND; const float MMMM_POWER = 0.10f; const float SMILE_POWER = 0.10f; const float FUNNEL_POWER = 0.35f; @@ -251,11 +252,20 @@ void Head::calculateMouthShapes() { _audioJawOpen *= JAW_CLOSE_RATE; } _audioJawOpen = glm::clamp(_audioJawOpen, 0.0f, 1.0f); - _trailingAudioJawOpen = glm::mix(_trailingAudioJawOpen, _audioJawOpen, 0.99f); + _trailingAudioJawOpen = glm::mix(_trailingAudioJawOpen, _audioJawOpen, 0.99f); - // Advance time at a rate proportional to loudness, and move the mouth shapes through + // Advance time at a rate proportional to loudness, and move the mouth shapes through // a cycle at differing speeds to create a continuous random blend of shapes. - _mouthTime += sqrtf(_averageLoudness) * TIMESTEP_CONSTANT; + + quint64 now = usecTimestampNow(); + float timeRatio = 1.0f; + if (_calculateMouthShapesTime > 0) { + quint64 timeDelta = now - _calculateMouthShapesTime; + timeRatio = (float)timeDelta / USECS_IN_SIXTIETH_SEC; + } + _calculateMouthShapesTime = now; + + _mouthTime += sqrtf(_averageLoudness) * TIMESTEP_CONSTANT * timeRatio; _mouth2 = (sinf(_mouthTime * MMMM_SPEED) + 1.0f) * MMMM_POWER * glm::min(1.0f, _trailingAudioJawOpen * STOP_GAIN); _mouth3 = (sinf(_mouthTime * FUNNEL_SPEED) + 1.0f) * FUNNEL_POWER * glm::min(1.0f, _trailingAudioJawOpen * STOP_GAIN); _mouth4 = (sinf(_mouthTime * SMILE_SPEED) + 1.0f) * SMILE_POWER * glm::min(1.0f, _trailingAudioJawOpen * STOP_GAIN); diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index aa801e5eb5..609a1a039d 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -114,6 +114,8 @@ private: float _mouth2; float _mouth3; float _mouth4; + + quint64 _calculateMouthShapesTime { 0 }; float _mouthTime; glm::vec3 _saccade;