don't set _lastInputLoudness if input is muted

This commit is contained in:
Stephen Birarda 2013-12-06 13:26:40 -08:00
parent 098010e099
commit bcdc066a98

View file

@ -185,16 +185,7 @@ void Audio::handleAudioInput() {
if (_isBufferSendCallback) { if (_isBufferSendCallback) {
// copy samples from the inputByteArray to the stereoInputBuffer // copy samples from the inputByteArray to the stereoInputBuffer
memcpy((char*) (stereoInputBuffer + bufferSizeSamples), inputByteArray.data(), inputByteArray.size()); 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 { } else {
// this is the first half of a full buffer of data // this is the first half of a full buffer of data
@ -264,6 +255,8 @@ void Audio::handleAudioInput() {
currentPacketPtr += sizeof(headOrientation); currentPacketPtr += sizeof(headOrientation);
if (!_muted) { if (!_muted) {
float loudness = 0;
// we aren't muted, average each set of four samples together to set up the mono input buffers // we aren't muted, average each set of four samples together to set up the mono input buffers
for (int i = 2; i < BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2 * SAMPLE_RATE_RATIO; i += 4) { for (int i = 2; i < BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2 * SAMPLE_RATE_RATIO; i += 4) {
@ -275,9 +268,16 @@ void Audio::handleAudioInput() {
+ (stereoInputBuffer[i + 2] / 4); + (stereoInputBuffer[i + 2] / 4);
} }
loudness += abs(averagedSample);
// add the averaged sample to our array of audio samples // add the averaged sample to our array of audio samples
monoAudioSamples[(i - 2) / 4] += averagedSample; monoAudioSamples[(i - 2) / 4] += averagedSample;
} }
loudness /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
_lastInputLoudness = loudness;
} else {
_lastInputLoudness = 0;
} }
nodeList->getNodeSocket().writeDatagram(monoAudioDataPacket, BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes, nodeList->getNodeSocket().writeDatagram(monoAudioDataPacket, BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes,