mirror of
https://github.com/overte-org/overte.git
synced 2025-06-15 21:59:22 +02:00
don't replay last buffer for silent agent
This commit is contained in:
parent
47f61a2fc2
commit
cee73e4622
3 changed files with 117 additions and 123 deletions
|
@ -92,13 +92,15 @@ void *sendBuffer(void *args)
|
||||||
if (!agentBuffer->isStarted()
|
if (!agentBuffer->isStarted()
|
||||||
&& agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) {
|
&& agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) {
|
||||||
printf("Held back buffer for agent with ID %d.\n", agent->getAgentId());
|
printf("Held back buffer for agent with ID %d.\n", agent->getAgentId());
|
||||||
|
agentBuffer->setShouldBeAddedToMix(false);
|
||||||
} else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
} else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
||||||
printf("Buffer from agent with ID %d starved.\n", agent->getAgentId());
|
printf("Buffer from agent with ID %d starved.\n", agent->getAgentId());
|
||||||
agentBuffer->setStarted(false);
|
agentBuffer->setStarted(false);
|
||||||
|
agentBuffer->setShouldBeAddedToMix(false);
|
||||||
} else {
|
} else {
|
||||||
// good buffer, add this to the mix
|
// good buffer, add this to the mix
|
||||||
agentBuffer->setStarted(true);
|
agentBuffer->setStarted(true);
|
||||||
agentBuffer->setAddedToMix(true);
|
agentBuffer->setShouldBeAddedToMix(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +131,7 @@ void *sendBuffer(void *args)
|
||||||
if (otherAgent != agent || (otherAgent == agent && agentWantsLoopback)) {
|
if (otherAgent != agent || (otherAgent == agent && agentWantsLoopback)) {
|
||||||
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
|
AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData();
|
||||||
|
|
||||||
|
if (otherAgentBuffer->shouldBeAddedToMix()) {
|
||||||
float *agentPosition = agentRingBuffer->getPosition();
|
float *agentPosition = agentRingBuffer->getPosition();
|
||||||
float *otherAgentPosition = otherAgentBuffer->getPosition();
|
float *otherAgentPosition = otherAgentBuffer->getPosition();
|
||||||
|
|
||||||
|
@ -216,20 +219,21 @@ void *sendBuffer(void *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
agentList->getAgentSocket().send(agent->getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES);
|
agentList->getAgentSocket().send(agent->getPublicSocket(), clientMix, BUFFER_LENGTH_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
|
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
|
||||||
AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData();
|
AudioRingBuffer* agentBuffer = (AudioRingBuffer*) agent->getLinkedData();
|
||||||
if (agentBuffer->wasAddedToMix()) {
|
if (agentBuffer->shouldBeAddedToMix()) {
|
||||||
agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
if (agentBuffer->getNextOutput() >= agentBuffer->getBuffer() + RING_BUFFER_SAMPLES) {
|
if (agentBuffer->getNextOutput() >= agentBuffer->getBuffer() + RING_BUFFER_SAMPLES) {
|
||||||
agentBuffer->setNextOutput(agentBuffer->getBuffer());
|
agentBuffer->setNextOutput(agentBuffer->getBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
agentBuffer->setAddedToMix(false);
|
agentBuffer->setShouldBeAddedToMix(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) {
|
||||||
bufferLengthSamples = bufferSamples;
|
bufferLengthSamples = bufferSamples;
|
||||||
|
|
||||||
started = false;
|
started = false;
|
||||||
addedToMix = false;
|
_shouldBeAddedToMix = false;
|
||||||
|
|
||||||
endOfLastWrite = NULL;
|
endOfLastWrite = NULL;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ AudioRingBuffer::AudioRingBuffer(const AudioRingBuffer &otherRingBuffer) {
|
||||||
ringBufferLengthSamples = otherRingBuffer.ringBufferLengthSamples;
|
ringBufferLengthSamples = otherRingBuffer.ringBufferLengthSamples;
|
||||||
bufferLengthSamples = otherRingBuffer.bufferLengthSamples;
|
bufferLengthSamples = otherRingBuffer.bufferLengthSamples;
|
||||||
started = otherRingBuffer.started;
|
started = otherRingBuffer.started;
|
||||||
addedToMix = otherRingBuffer.addedToMix;
|
_shouldBeAddedToMix = otherRingBuffer._shouldBeAddedToMix;
|
||||||
|
|
||||||
buffer = new int16_t[ringBufferLengthSamples];
|
buffer = new int16_t[ringBufferLengthSamples];
|
||||||
memcpy(buffer, otherRingBuffer.buffer, sizeof(int16_t) * ringBufferLengthSamples);
|
memcpy(buffer, otherRingBuffer.buffer, sizeof(int16_t) * ringBufferLengthSamples);
|
||||||
|
@ -71,14 +71,6 @@ void AudioRingBuffer::setStarted(bool status) {
|
||||||
started = status;
|
started = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioRingBuffer::wasAddedToMix() {
|
|
||||||
return addedToMix;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AudioRingBuffer::setAddedToMix(bool added) {
|
|
||||||
addedToMix = added;
|
|
||||||
}
|
|
||||||
|
|
||||||
float* AudioRingBuffer::getPosition() {
|
float* AudioRingBuffer::getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
@ -136,8 +128,6 @@ int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
endOfLastWrite += bufferLengthSamples;
|
endOfLastWrite += bufferLengthSamples;
|
||||||
|
|
||||||
addedToMix = false;
|
|
||||||
|
|
||||||
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
|
if (endOfLastWrite >= buffer + ringBufferLengthSamples) {
|
||||||
endOfLastWrite = buffer;
|
endOfLastWrite = buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "AgentData.h"
|
#include "AgentData.h"
|
||||||
|
|
||||||
class AudioRingBuffer : public AgentData {
|
class AudioRingBuffer : public AgentData {
|
||||||
public:
|
public:
|
||||||
AudioRingBuffer(int ringSamples, int bufferSamples);
|
AudioRingBuffer(int ringSamples, int bufferSamples);
|
||||||
~AudioRingBuffer();
|
~AudioRingBuffer();
|
||||||
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
AudioRingBuffer(const AudioRingBuffer &otherRingBuffer);
|
||||||
|
@ -28,8 +28,8 @@ class AudioRingBuffer : public AgentData {
|
||||||
int16_t* getBuffer();
|
int16_t* getBuffer();
|
||||||
bool isStarted();
|
bool isStarted();
|
||||||
void setStarted(bool status);
|
void setStarted(bool status);
|
||||||
bool wasAddedToMix();
|
bool shouldBeAddedToMix() const { return _shouldBeAddedToMix; }
|
||||||
void setAddedToMix(bool added);
|
void setShouldBeAddedToMix(bool shouldBeAddedToMix) { _shouldBeAddedToMix = shouldBeAddedToMix; }
|
||||||
float* getPosition();
|
float* getPosition();
|
||||||
void setPosition(float newPosition[]);
|
void setPosition(float newPosition[]);
|
||||||
float getAttenuationRatio();
|
float getAttenuationRatio();
|
||||||
|
@ -38,7 +38,7 @@ class AudioRingBuffer : public AgentData {
|
||||||
void setBearing(float newBearing);
|
void setBearing(float newBearing);
|
||||||
|
|
||||||
short diffLastWriteNextOutput();
|
short diffLastWriteNextOutput();
|
||||||
private:
|
private:
|
||||||
int ringBufferLengthSamples;
|
int ringBufferLengthSamples;
|
||||||
int bufferLengthSamples;
|
int bufferLengthSamples;
|
||||||
float position[3];
|
float position[3];
|
||||||
|
@ -48,7 +48,7 @@ class AudioRingBuffer : public AgentData {
|
||||||
int16_t *endOfLastWrite;
|
int16_t *endOfLastWrite;
|
||||||
int16_t *buffer;
|
int16_t *buffer;
|
||||||
bool started;
|
bool started;
|
||||||
bool addedToMix;
|
bool _shouldBeAddedToMix;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__AudioRingBuffer__) */
|
#endif /* defined(__interface__AudioRingBuffer__) */
|
||||||
|
|
Loading…
Reference in a new issue