From dbcb778ea9d84d242640ab09a4ae0a79f8c04c77 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 18 Sep 2014 08:33:41 -0700 Subject: [PATCH] Drive mouth with loudness relative to long term average --- examples/headMove.js | 2 +- interface/src/avatar/Head.cpp | 22 ++++++++++++++++------ interface/src/avatar/Head.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/headMove.js b/examples/headMove.js index 0a7686c569..f8a1895a08 100644 --- a/examples/headMove.js +++ b/examples/headMove.js @@ -79,7 +79,7 @@ function moveWithHead(deltaTime) { if (Math.abs(headDelta.z) > HEAD_MOVE_DEAD_ZONE) { if (Math.abs(Vec3.dot(velocity, forward)) < maxVelocity) { thrust = Vec3.sum(thrust, Vec3.multiply(forward, -headDelta.z * HEAD_THRUST_FWD_SCALE * deltaTime)); - } + } } if (Math.abs(headDelta.x) > HEAD_STRAFE_DEAD_ZONE) { if (Math.abs(Vec3.dot(velocity, right)) < maxVelocity) { diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index b226b8ed31..d1fcc0f33f 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -32,6 +32,7 @@ Head::Head(Avatar* owningAvatar) : _eyePosition(0.0f, 0.0f, 0.0f), _scale(1.0f), _lastLoudness(0.0f), + _longTermAverageLoudness(-1.0f), _audioAttack(0.0f), _angularVelocity(0,0,0), _renderLookatVectors(false), @@ -62,7 +63,7 @@ void Head::reset() { } void Head::simulate(float deltaTime, bool isMine, bool billboard) { - // Update audio trailing average for rendering facial animations + if (isMine) { MyAvatar* myAvatar = static_cast(_owningAvatar); @@ -78,6 +79,18 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { } } } + // Update audio trailing average for rendering facial animations + const float AUDIO_AVERAGING_SECS = 0.05f; + const float AUDIO_LONG_TERM_AVERAGING_SECS = 30.f; + _averageLoudness = glm::mix(_averageLoudness, _audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f)); + + if (_longTermAverageLoudness == -1.0) { + _longTermAverageLoudness = _averageLoudness; + } else { + _longTermAverageLoudness = glm::mix(_longTermAverageLoudness, _averageLoudness, glm::min(deltaTime / AUDIO_LONG_TERM_AVERAGING_SECS, 1.0f)); + } + float deltaLoudness = glm::max(0.0f, _averageLoudness - _longTermAverageLoudness); + qDebug() << "deltaLoudness: " << deltaLoudness; if (!(_isFaceshiftConnected || billboard)) { // Update eye saccades @@ -92,9 +105,6 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { _saccadeTarget = SACCADE_MAGNITUDE * randVector(); } _saccade += (_saccadeTarget - _saccade) * 0.50f; - - const float AUDIO_AVERAGING_SECS = 0.05f; - _averageLoudness = glm::mix(_averageLoudness, _audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f)); // Detect transition from talking to not; force blink after that and a delay bool forceBlink = false; @@ -108,8 +118,8 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) { } // Update audio attack data for facial animation (eyebrows and mouth) - _audioAttack = 0.9f * _audioAttack + 0.1f * fabs(_audioLoudness - _lastLoudness); - _lastLoudness = _audioLoudness; + _audioAttack = 0.9f * _audioAttack + 0.1f * fabs((_audioLoudness - _longTermAverageLoudness) - _lastLoudness); + _lastLoudness = (_audioLoudness - _longTermAverageLoudness); const float BROW_LIFT_THRESHOLD = 100.0f; if (_audioAttack > BROW_LIFT_THRESHOLD) { diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 1cdfdaf5a3..e99a7f5c7b 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -121,6 +121,7 @@ private: float _scale; float _lastLoudness; + float _longTermAverageLoudness; float _audioAttack; glm::vec3 _angularVelocity; bool _renderLookatVectors;