From ad95190e157691300bf58c3bd5776a3d2a4a4ab4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 10:52:20 -0700 Subject: [PATCH 1/7] add debugging for current mixer crash --- audio-mixer/src/main.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index e4a4f83b07..b6e3ab2d7a 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -225,15 +225,15 @@ int main(int argc, const char* argv[]) { } int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f - ? clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL - : clientSamples; + ? clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL + : clientSamples; int16_t* delayedChannel = bearingRelativeAngleToSource > 0.0f - ? clientSamples - : clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; + ? clientSamples + : clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; int16_t* delaySamplePointer = otherAgentBuffer->getNextOutput() == otherAgentBuffer->getBuffer() - ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay - : otherAgentBuffer->getNextOutput() - numSamplesDelay; + ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay + : otherAgentBuffer->getNextOutput() - numSamplesDelay; for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { @@ -247,6 +247,9 @@ int main(int argc, const char* argv[]) { plateauAdditionOfSamples(goodChannel[s], currentSample); if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { + printf("Attemping to grab a sample at %d\n", s + numSamplesDelay); + printf("The sample here is %d\n", delayedChannel[s + numSamplesDelay]); + plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], currentSample * weakChannelAmplitudeRatio); } From 2a1357e8e11f84a5fe55cf99c30da3a6504f0276 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:00:51 -0700 Subject: [PATCH 2/7] more debugging to track down a mixer crash --- audio-mixer/src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index b6e3ab2d7a..3a7aa7eb63 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -214,12 +214,13 @@ int main(int argc, const char* argv[]) { (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] - * otherAgentBuffer->getAttenuationRatio() - * offAxisCoefficient; + * otherAgentBuffer->getAttenuationRatio() + * offAxisCoefficient; bearingRelativeAngleToSource *= (M_PI / 180); float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); + printf("BRA: %f, SR: %f\n", bearingRelativeAngleToSource, sinRatio); numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); } From 78df9fb2edb43e95baf4f5af5ffb972f79e65c66 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:04:46 -0700 Subject: [PATCH 3/7] last pieces of debugging for mixer crash --- libraries/audio/src/AudioRingBuffer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index 299ffcc2cb..a9a514ebcb 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -36,6 +36,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { unsigned char* dataBuffer = sourceBuffer + 1; + printf("The number of bytes received is %d\n", numBytes); + if (sourceBuffer[0] == PACKET_HEADER_INJECT_AUDIO || sourceBuffer[0] == PACKET_HEADER_MICROPHONE_AUDIO) { // if this came from an injector or interface client @@ -56,6 +58,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&_bearing, dataBuffer, sizeof(float)); dataBuffer += sizeof(_bearing); + printf("This agent's bearing is %f\n", _bearing); + if (_bearing > 180 || _bearing < -180) { // we were passed an invalid bearing because this agent wants loopback (pressed the H key) _shouldLoopbackForAgent = true; From f45062a097a39f84a32dd3d599e63bb9a91c1b16 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:14:50 -0700 Subject: [PATCH 4/7] don't use audio when the bearing sent by the agent is garbage --- libraries/audio/src/AudioRingBuffer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index a9a514ebcb..7cc45ff39f 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -36,8 +36,6 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { unsigned char* dataBuffer = sourceBuffer + 1; - printf("The number of bytes received is %d\n", numBytes); - if (sourceBuffer[0] == PACKET_HEADER_INJECT_AUDIO || sourceBuffer[0] == PACKET_HEADER_MICROPHONE_AUDIO) { // if this came from an injector or interface client @@ -58,19 +56,22 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { memcpy(&_bearing, dataBuffer, sizeof(float)); dataBuffer += sizeof(_bearing); - printf("This agent's bearing is %f\n", _bearing); - - if (_bearing > 180 || _bearing < -180) { + // if this agent sent us a NaN bearing then don't consider this good audio and bail + if (_bearing != _bearing) { + _endOfLastWrite = _nextOutput = _buffer; + _started = false; + return 0; + } else if (_bearing > 180 || _bearing < -180) { // we were passed an invalid bearing because this agent wants loopback (pressed the H key) _shouldLoopbackForAgent = true; // correct the bearing _bearing = _bearing > 0 - ? _bearing - AGENT_LOOPBACK_MODIFIER - : _bearing + AGENT_LOOPBACK_MODIFIER; + ? _bearing - AGENT_LOOPBACK_MODIFIER + : _bearing + AGENT_LOOPBACK_MODIFIER; } else { _shouldLoopbackForAgent = false; - } + } } // make sure we have enough bytes left for this to be the right amount of audio From 1fb61faded185318e761e49e72e12f6265e26e3b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:22:25 -0700 Subject: [PATCH 5/7] fix the isnan check for agent bearing --- libraries/audio/src/AudioRingBuffer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index 7cc45ff39f..f397c3210b 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -7,6 +7,7 @@ // #include +#include #include "PacketHeaders.h" @@ -57,7 +58,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { dataBuffer += sizeof(_bearing); // if this agent sent us a NaN bearing then don't consider this good audio and bail - if (_bearing != _bearing) { + if (std::isnan(_bearing)) { + printf("Got a nan bearing for this agent\n"); _endOfLastWrite = _nextOutput = _buffer; _started = false; return 0; From 56e0e3882d51cf34672eedd080ad85b84ced36d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:29:38 -0700 Subject: [PATCH 6/7] kill agents who send NaN bearings --- audio-mixer/src/main.cpp | 6 +++++- libraries/audio/src/AudioRingBuffer.cpp | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 3a7aa7eb63..0b4d21ab6e 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -220,7 +220,6 @@ int main(int argc, const char* argv[]) { bearingRelativeAngleToSource *= (M_PI / 180); float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); - printf("BRA: %f, SR: %f\n", bearingRelativeAngleToSource, sinRatio); numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); } @@ -291,6 +290,11 @@ int main(int argc, const char* argv[]) { } agentList->updateAgentWithData(agentAddress, packetData, receivedBytes); + + if (std::isnan(((AudioRingBuffer *)avatarAgent->getLinkedData())->getBearing())) { + // kill off this agent - temporary solution to mixer crash on mac sleep + avatarAgent->setAlive(false); + } } else if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) { Agent* matchingInjector = NULL; diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index f397c3210b..006dd825bf 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -59,7 +59,6 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { // if this agent sent us a NaN bearing then don't consider this good audio and bail if (std::isnan(_bearing)) { - printf("Got a nan bearing for this agent\n"); _endOfLastWrite = _nextOutput = _buffer; _started = false; return 0; @@ -69,8 +68,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { // correct the bearing _bearing = _bearing > 0 - ? _bearing - AGENT_LOOPBACK_MODIFIER - : _bearing + AGENT_LOOPBACK_MODIFIER; + ? _bearing - AGENT_LOOPBACK_MODIFIER + : _bearing + AGENT_LOOPBACK_MODIFIER; } else { _shouldLoopbackForAgent = false; } From 76f7752f2f38db4f816b586149feb8c4f0bff53c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 May 2013 11:31:46 -0700 Subject: [PATCH 7/7] remove debugging used to track down mixer crash --- audio-mixer/src/main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 0b4d21ab6e..9204e39b8e 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -246,10 +246,7 @@ int main(int argc, const char* argv[]) { int16_t currentSample = (otherAgentBuffer->getNextOutput()[s] * attenuationCoefficient); plateauAdditionOfSamples(goodChannel[s], currentSample); - if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { - printf("Attemping to grab a sample at %d\n", s + numSamplesDelay); - printf("The sample here is %d\n", delayedChannel[s + numSamplesDelay]); - + if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], currentSample * weakChannelAmplitudeRatio); }