mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:27:48 +02:00
Merge pull request #14984 from kencooke/master
Case 21384: Avatar mouth blendshapes are not working correctly (master)
This commit is contained in:
commit
1213084fc6
3 changed files with 21 additions and 10 deletions
|
@ -27,8 +27,9 @@ QString Audio::HMD { "VR" };
|
||||||
Setting::Handle<bool> enableNoiseReductionSetting { QStringList { Audio::AUDIO, "NoiseReduction" }, true };
|
Setting::Handle<bool> enableNoiseReductionSetting { QStringList { Audio::AUDIO, "NoiseReduction" }, true };
|
||||||
|
|
||||||
float Audio::loudnessToLevel(float loudness) {
|
float Audio::loudnessToLevel(float loudness) {
|
||||||
float level = 6.02059991f * fastLog2f(loudness); // level in dBFS
|
float level = loudness * (1/32768.0f); // level in [0, 1]
|
||||||
level = (level + 48.0f) * (1/39.0f); // map [-48, -9] dBFS to [0, 1]
|
level = 6.02059991f * fastLog2f(level); // convert to dBFS
|
||||||
|
level = (level + 48.0f) * (1/42.0f); // map [-48, -6] dBFS to [0, 1]
|
||||||
return glm::clamp(level, 0.0f, 1.0f);
|
return glm::clamp(level, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ static float computeLoudness(int16_t* samples, int numSamples, int numChannels,
|
||||||
const int32_t CLIPPING_THRESHOLD = 32392; // -0.1 dBFS
|
const int32_t CLIPPING_THRESHOLD = 32392; // -0.1 dBFS
|
||||||
const int32_t CLIPPING_DETECTION = 3; // consecutive samples over threshold
|
const int32_t CLIPPING_DETECTION = 3; // consecutive samples over threshold
|
||||||
|
|
||||||
float scale = numSamples ? 1.0f / (numSamples * 32768.0f) : 0.0f;
|
float scale = numSamples ? 1.0f / numSamples : 0.0f;
|
||||||
|
|
||||||
int32_t loudness = 0;
|
int32_t loudness = 0;
|
||||||
isClipping = false;
|
isClipping = false;
|
||||||
|
@ -249,6 +249,8 @@ AudioClient::AudioClient() :
|
||||||
_outputBufferSizeFrames("audioOutputBufferFrames", DEFAULT_BUFFER_FRAMES),
|
_outputBufferSizeFrames("audioOutputBufferFrames", DEFAULT_BUFFER_FRAMES),
|
||||||
_sessionOutputBufferSizeFrames(_outputBufferSizeFrames.get()),
|
_sessionOutputBufferSizeFrames(_outputBufferSizeFrames.get()),
|
||||||
_outputStarveDetectionEnabled("audioOutputStarveDetectionEnabled", DEFAULT_STARVE_DETECTION_ENABLED),
|
_outputStarveDetectionEnabled("audioOutputStarveDetectionEnabled", DEFAULT_STARVE_DETECTION_ENABLED),
|
||||||
|
_lastRawInputLoudness(0.0f),
|
||||||
|
_lastSmoothedRawInputLoudness(0.0f),
|
||||||
_lastInputLoudness(0.0f),
|
_lastInputLoudness(0.0f),
|
||||||
_timeSinceLastClip(-1.0f),
|
_timeSinceLastClip(-1.0f),
|
||||||
_muted(false),
|
_muted(false),
|
||||||
|
@ -1144,6 +1146,9 @@ void AudioClient::handleAudioInput(QByteArray& audioBuffer) {
|
||||||
emit inputReceived(audioBuffer);
|
emit inputReceived(audioBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loudness after mute/gate
|
||||||
|
_lastInputLoudness = (_muted || !audioGateOpen) ? 0.0f : _lastRawInputLoudness;
|
||||||
|
|
||||||
// detect gate opening and closing
|
// detect gate opening and closing
|
||||||
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
|
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
|
||||||
bool closedInLastBlock = _audioGateOpen && !audioGateOpen; // the gate just closed
|
bool closedInLastBlock = _audioGateOpen && !audioGateOpen; // the gate just closed
|
||||||
|
@ -1222,12 +1227,15 @@ void AudioClient::handleMicAudioInput() {
|
||||||
|
|
||||||
// detect loudness and clipping on the raw input
|
// detect loudness and clipping on the raw input
|
||||||
bool isClipping = false;
|
bool isClipping = false;
|
||||||
float inputLoudness = computeLoudness(inputAudioSamples.get(), inputSamplesRequired, _inputFormat.channelCount(), isClipping);
|
float loudness = computeLoudness(inputAudioSamples.get(), inputSamplesRequired, _inputFormat.channelCount(), isClipping);
|
||||||
|
_lastRawInputLoudness = loudness;
|
||||||
|
|
||||||
float tc = (inputLoudness > _lastInputLoudness) ? 0.378f : 0.967f; // 10ms attack, 300ms release @ 100Hz
|
// envelope detection
|
||||||
inputLoudness += tc * (_lastInputLoudness - inputLoudness);
|
float tc = (loudness > _lastSmoothedRawInputLoudness) ? 0.378f : 0.967f; // 10ms attack, 300ms release @ 100Hz
|
||||||
_lastInputLoudness = inputLoudness;
|
loudness += tc * (_lastSmoothedRawInputLoudness - loudness);
|
||||||
|
_lastSmoothedRawInputLoudness = loudness;
|
||||||
|
|
||||||
|
// clipping indicator
|
||||||
if (isClipping) {
|
if (isClipping) {
|
||||||
_timeSinceLastClip = 0.0f;
|
_timeSinceLastClip = 0.0f;
|
||||||
} else if (_timeSinceLastClip >= 0.0f) {
|
} else if (_timeSinceLastClip >= 0.0f) {
|
||||||
|
@ -1235,7 +1243,7 @@ void AudioClient::handleMicAudioInput() {
|
||||||
}
|
}
|
||||||
isClipping = (_timeSinceLastClip >= 0.0f) && (_timeSinceLastClip < 2.0f); // 2 second hold time
|
isClipping = (_timeSinceLastClip >= 0.0f) && (_timeSinceLastClip < 2.0f); // 2 second hold time
|
||||||
|
|
||||||
emit inputLoudnessChanged(_lastInputLoudness, isClipping);
|
emit inputLoudnessChanged(_lastSmoothedRawInputLoudness, isClipping);
|
||||||
|
|
||||||
if (!_muted) {
|
if (!_muted) {
|
||||||
possibleResampling(_inputToNetworkResampler,
|
possibleResampling(_inputToNetworkResampler,
|
||||||
|
|
|
@ -127,7 +127,7 @@ public:
|
||||||
|
|
||||||
const QAudioFormat& getOutputFormat() const { return _outputFormat; }
|
const QAudioFormat& getOutputFormat() const { return _outputFormat; }
|
||||||
|
|
||||||
float getLastInputLoudness() const { return _lastInputLoudness; } // TODO: relative to noise floor?
|
float getLastInputLoudness() const { return _lastInputLoudness; }
|
||||||
|
|
||||||
float getTimeSinceLastClip() const { return _timeSinceLastClip; }
|
float getTimeSinceLastClip() const { return _timeSinceLastClip; }
|
||||||
float getAudioAverageInputLoudness() const { return _lastInputLoudness; }
|
float getAudioAverageInputLoudness() const { return _lastInputLoudness; }
|
||||||
|
@ -355,7 +355,9 @@ private:
|
||||||
|
|
||||||
StDev _stdev;
|
StDev _stdev;
|
||||||
QElapsedTimer _timeSinceLastReceived;
|
QElapsedTimer _timeSinceLastReceived;
|
||||||
float _lastInputLoudness;
|
float _lastRawInputLoudness; // before mute/gate
|
||||||
|
float _lastSmoothedRawInputLoudness;
|
||||||
|
float _lastInputLoudness; // after mute/gate
|
||||||
float _timeSinceLastClip;
|
float _timeSinceLastClip;
|
||||||
int _totalInputAudioSamples;
|
int _totalInputAudioSamples;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue