From 89beff42532a19fa0d011c173cde13615766afe5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 16 Dec 2013 15:41:58 -0800 Subject: [PATCH] fix the scope and last input loudness --- interface/src/Audio.cpp | 13 ++++++++----- interface/src/Oscilloscope.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index c1794fc4dd..c17f5ff1dd 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -353,15 +353,18 @@ void Audio::handleAudioInput() { memcpy(currentPacketPtr, &headOrientation, sizeof(headOrientation)); currentPacketPtr += sizeof(headOrientation); + float loudness = 0; + if (!_muted) { - float loudness = 0; - // loudness /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL; - _lastInputLoudness = loudness; + for (int i = 0; i < NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; i++) { + loudness += fabsf(_monoAudioSamples[i]); + } - } else { - _lastInputLoudness = 0; + loudness /= NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; } + _lastInputLoudness = loudness; + nodeList->getNodeSocket().writeDatagram(monoAudioDataPacket, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes, audioMixer->getActiveSocket()->getAddress(), diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index ff8da61130..5b3cfb9f09 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -77,7 +77,7 @@ void Oscilloscope::addSamples(const QByteArray& audioByteArray, bool isStereo, b int numSamplesPerChannel = audioByteArray.size() / (sizeof(int16_t) * (isStereo ? 2 : 1)); int16_t* samples = (int16_t*) audioByteArray.data(); - for (int channel = 0; channel < (isStereo ? 1 : 2); channel++) { + for (int channel = 0; channel < (isStereo ? 2 : 1); channel++) { // add samples for each of the channels // determine start/end offset of this channel's region