don't replay last buffer for silent agent

This commit is contained in:
Stephen Birarda 2013-05-01 10:57:59 -07:00
parent 47f61a2fc2
commit cee73e4622
3 changed files with 117 additions and 123 deletions

View file

@ -92,13 +92,15 @@ void *sendBuffer(void *args)
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());
agentBuffer->setShouldBeAddedToMix(false);
} else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
printf("Buffer from agent with ID %d starved.\n", agent->getAgentId());
agentBuffer->setStarted(false);
agentBuffer->setShouldBeAddedToMix(false);
} else {
// good buffer, add this to the mix
agentBuffer->setStarted(true);
agentBuffer->setAddedToMix(true);
agentBuffer->setShouldBeAddedToMix(true);
}
}
}
@ -129,6 +131,7 @@ void *sendBuffer(void *args)
if (otherAgent != agent || (otherAgent == agent && agentWantsLoopback)) {
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
if (otherAgentBuffer->shouldBeAddedToMix()) {
float *agentPosition = agentRingBuffer->getPosition();
float *otherAgentPosition = otherAgentBuffer->getPosition();
@ -216,20 +219,21 @@ void *sendBuffer(void *args)
}
}
}
}
agentList->getAgentSocket().send(agent->getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES);
}
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData();
if (agentBuffer->wasAddedToMix()) {
if (agentBuffer->shouldBeAddedToMix()) {
agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
if (agentBuffer->getNextOutput() >= agentBuffer->getBuffer() + RING_BUFFER_SAMPLES) {
agentBuffer->setNextOutput(agentBuffer->getBuffer());
}
agentBuffer->setAddedToMix(false);
agentBuffer->setShouldBeAddedToMix(false);
}
}

View file

@ -14,7 +14,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) {
bufferLengthSamples = bufferSamples;
started = false;
addedToMix = false;
_shouldBeAddedToMix = false;
endOfLastWrite = NULL;
@ -26,7 +26,7 @@ AudioRingBuffer::AudioRingBuffer(const AudioRingBuffer &otherRingBuffer) {
ringBufferLengthSamples = otherRingBuffer.ringBufferLengthSamples;
bufferLengthSamples = otherRingBuffer.bufferLengthSamples;
started = otherRingBuffer.started;
addedToMix = otherRingBuffer.addedToMix;
_shouldBeAddedToMix = otherRingBuffer._shouldBeAddedToMix;
buffer = new int16_t[ringBufferLengthSamples];
memcpy(buffer, otherRingBuffer.buffer, sizeof(int16_t) * ringBufferLengthSamples);
@ -71,14 +71,6 @@ void AudioRingBuffer::setStarted(bool status) {
started = status;
}
bool AudioRingBuffer::wasAddedToMix() {
return addedToMix;
}
void AudioRingBuffer::setAddedToMix(bool added) {
addedToMix = added;
}
float* AudioRingBuffer::getPosition() {
return position;
}
@ -136,8 +128,6 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
endOfLastWrite += bufferLengthSamples;
addedToMix = false;
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
endOfLastWrite = buffer;
}

View file

@ -13,7 +13,7 @@
#include "AgentData.h"
class AudioRingBuffer : public AgentData {
public:
public:
AudioRingBuffer(int ringSamples, int bufferSamples);
~AudioRingBuffer();
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
@ -28,8 +28,8 @@ class AudioRingBuffer : public AgentData {
int16_t* getBuffer();
bool isStarted();
void setStarted(bool status);
bool wasAddedToMix();
void setAddedToMix(bool added);
bool shouldBeAddedToMix() const { return _shouldBeAddedToMix; }
void setShouldBeAddedToMix(bool shouldBeAddedToMix) { _shouldBeAddedToMix = shouldBeAddedToMix; }
float* getPosition();
void setPosition(float newPosition[]);
float getAttenuationRatio();
@ -38,7 +38,7 @@ class AudioRingBuffer : public AgentData {
void setBearing(float newBearing);
short diffLastWriteNextOutput();
private:
private:
int ringBufferLengthSamples;
int bufferLengthSamples;
float position[3];
@ -48,7 +48,7 @@ class AudioRingBuffer : public AgentData {
int16_t *endOfLastWrite;
int16_t *buffer;
bool started;
bool addedToMix;
bool _shouldBeAddedToMix;
};
#endif /* defined(__interface__AudioRingBuffer__) */