From 23f861f5e2e27937aa131e5e646e9bca8302d24b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 9 May 2013 13:30:11 -0700 Subject: [PATCH] fixes per code review comments --- audio-mixer/src/main.cpp | 20 ++++++++++---------- libraries/shared/src/AudioRingBuffer.cpp | 8 ++++---- libraries/shared/src/AudioRingBuffer.h | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 88cb867df4..52889cee8e 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -72,7 +72,7 @@ void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { } void attachNewBufferToAgent(Agent *newAgent) { - if (newAgent->getLinkedData() == NULL) { + if (!newAgent->getLinkedData()) { newAgent->setLinkedData(new AudioRingBuffer(RING_BUFFER_SAMPLES, BUFFER_LENGTH_SAMPLES_PER_CHANNEL)); } } @@ -89,9 +89,9 @@ int main(int argc, const char* argv[]) { agentList->startSilentAgentRemovalThread(); agentList->startDomainServerCheckInThread(); - unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE]; + unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE]; - sockaddr *agentAddress = new sockaddr; + sockaddr* agentAddress = new sockaddr; // make sure our agent socket is non-blocking agentList->getAgentSocket().setBlocking(false); @@ -106,7 +106,7 @@ int main(int argc, const char* argv[]) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData(); - if (agentBuffer->getEndOfLastWrite() != NULL) { + if (agentBuffer->getEndOfLastWrite()) { if (!agentBuffer->isStarted() && agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) { printf("Held back buffer for agent with ID %d.\n", agent->getAgentId()); @@ -217,15 +217,15 @@ int main(int argc, const char* argv[]) { } int16_t* goodChannel = bearingRelativeAngleToSource > 0.0f - ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL - : clientMix; + ? clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL + : clientMix; int16_t* delayedChannel = bearingRelativeAngleToSource > 0.0f - ? clientMix - : clientMix + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; + ? clientMix + : clientMix + 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++) { diff --git a/libraries/shared/src/AudioRingBuffer.cpp b/libraries/shared/src/AudioRingBuffer.cpp index fb8ecdac86..b49b65945c 100644 --- a/libraries/shared/src/AudioRingBuffer.cpp +++ b/libraries/shared/src/AudioRingBuffer.cpp @@ -50,8 +50,8 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { unsigned char *dataPtr = sourceBuffer + 1; - memcpy(&_position, dataPtr, sizeof(_position.x) * 3); - dataPtr += (sizeof(_position.x) * 3); + memcpy(&_position, dataPtr, sizeof(_position)); + dataPtr += (sizeof(_position)); unsigned int attenuationByte = *(dataPtr++); _attenuationRatio = attenuationByte / 255.0f; @@ -74,7 +74,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer = dataPtr; } - if (_endOfLastWrite == NULL) { + if (!_endOfLastWrite) { _endOfLastWrite = _buffer; } else if (diffLastWriteNextOutput() > _ringBufferLengthSamples - _bufferLengthSamples) { _endOfLastWrite = _buffer; @@ -94,7 +94,7 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { } short AudioRingBuffer::diffLastWriteNextOutput() { - if (_endOfLastWrite == NULL) { + if (!_endOfLastWrite) { return 0; } else { short sampleDifference = _endOfLastWrite - _nextOutput; diff --git a/libraries/shared/src/AudioRingBuffer.h b/libraries/shared/src/AudioRingBuffer.h index 0e0e1ca8bc..fb739629c9 100644 --- a/libraries/shared/src/AudioRingBuffer.h +++ b/libraries/shared/src/AudioRingBuffer.h @@ -28,10 +28,10 @@ public: AudioRingBuffer* clone() const; int16_t* getNextOutput() const { return _nextOutput; } - void setNextOutput(int16_t *nextOutput) { _nextOutput = nextOutput; } + void setNextOutput(int16_t* nextOutput) { _nextOutput = nextOutput; } int16_t* getEndOfLastWrite() const { return _endOfLastWrite; } - void setEndOfLastWrite(int16_t *endOfLastWrite) { _endOfLastWrite = endOfLastWrite; } + void setEndOfLastWrite(int16_t* endOfLastWrite) { _endOfLastWrite = endOfLastWrite; } int16_t* getBuffer() const { return _buffer; }