From 21076af73907ca385e789b655fe72413f2117e0f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 Dec 2013 14:29:55 -0800 Subject: [PATCH] hook audio loudness back to QAudioInput --- interface/src/Application.cpp | 19 ++----------------- interface/src/Audio.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 02160b926e..ba2b302902 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -10,15 +10,6 @@ #include #include -#ifdef _WIN32 -#include "Syssocket.h" -#include "Systime.h" -#else -#include -#include -#include -#endif - #include #include #include @@ -2426,10 +2417,8 @@ void Application::updateAudio(float deltaTime) { PerformanceWarning warn(showWarnings, "Application::updateAudio()"); // Update audio stats for procedural sounds - #ifndef _WIN32 _audio.setLastAcceleration(_myAvatar.getThrust()); _audio.setLastVelocity(_myAvatar.getVelocity()); - #endif } void Application::updateCursor(float deltaTime) { @@ -2569,10 +2558,8 @@ void Application::updateAvatar(float deltaTime) { } // Get audio loudness data from audio input device - #ifndef _WIN32 - _myAvatar.getHead().setAudioLoudness(_audio.getLastInputLoudness()); - #endif - + _myAvatar.getHead().setAudioLoudness(_audio.getLastInputLoudness()); + NodeList* nodeList = NodeList::getInstance(); // send head/hand data to the avatar mixer and voxel server @@ -3203,14 +3190,12 @@ void Application::displayOverlay() { } } - #ifndef _WIN32 if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { _audio.render(_glWidget->width(), _glWidget->height()); if (Menu::getInstance()->isOptionChecked(MenuOption::Oscilloscope)) { _audioScope.render(45, _glWidget->height() - 200); } } - #endif //noiseTest(_glWidget->width(), _glWidget->height()); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index e4f0677787..2d7997a021 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -194,6 +194,15 @@ void Audio::handleAudioInput() { // copy samples from the inputByteArray to the stereoInputBuffer memcpy((char*) (stereoInputBuffer + bufferSizeSamples), inputByteArray.data(), inputByteArray.size()); + // Measure the loudness of the signal from the microphone and store in audio object + float loudness = 0; + for (int i = 0; i < BUFFER_LENGTH_SAMPLES_PER_CHANNEL * SAMPLE_RATE_RATIO; i += 2) { + loudness += abs(stereoInputBuffer[i]); + } + + loudness /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL * SAMPLE_RATE_RATIO; + _lastInputLoudness = loudness; + } else { // take samples we have in this callback and store them in the first half of the static buffer // to send off in the next callback