pre-enumerate all sources to push buffers when there is only one source

This commit is contained in:
Stephen Birarda 2013-06-05 12:31:13 -07:00
parent d64b46a6b2
commit 16d1f8da5a
3 changed files with 19 additions and 11 deletions

View file

@ -15,7 +15,7 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() :
_position(0.0f, 0.0f, 0.0f), _position(0.0f, 0.0f, 0.0f),
_orientation(0.0f, 0.0f, 0.0f, 0.0f), _orientation(0.0f, 0.0f, 0.0f, 0.0f),
_shouldLoopbackForAgent(false), _shouldLoopbackForAgent(false),
_wasAddedToMix(false) _willBeAddedToMix(false)
{ {
} }

View file

@ -22,8 +22,8 @@ public:
bool shouldBeAddedToMix(int numJitterBufferSamples); bool shouldBeAddedToMix(int numJitterBufferSamples);
bool wasAddedToMix() const { return _wasAddedToMix; } bool willBeAddedToMix() const { return _willBeAddedToMix; }
void setWasAddedToMix(bool wasAddedToMix) { _wasAddedToMix = wasAddedToMix; } void setWillBeAddedToMix(bool willBeAddedToMix) { _willBeAddedToMix = willBeAddedToMix; }
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }
const glm::quat& getOrientation() const { return _orientation; } const glm::quat& getOrientation() const { return _orientation; }
@ -38,7 +38,7 @@ protected:
glm::vec3 _position; glm::vec3 _position;
glm::quat _orientation; glm::quat _orientation;
bool _shouldLoopbackForAgent; bool _shouldLoopbackForAgent;
bool _wasAddedToMix; bool _willBeAddedToMix;
}; };
#endif /* defined(__hifi__PositionalAudioRingBuffer__) */ #endif /* defined(__hifi__PositionalAudioRingBuffer__) */

View file

@ -111,7 +111,17 @@ int main(int argc, const char* argv[]) {
gettimeofday(&startTime, NULL); gettimeofday(&startTime, NULL);
while (true) { while (true) {
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
PositionalAudioRingBuffer* positionalRingBuffer = (PositionalAudioRingBuffer*) agent->getLinkedData();
if (positionalRingBuffer && positionalRingBuffer->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) {
// this is a ring buffer that is ready to go
// set its flag so we know to push its buffer when all is said and done
positionalRingBuffer->setWillBeAddedToMix(true);
}
}
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getType() == AGENT_TYPE_AVATAR) { if (agent->getType() == AGENT_TYPE_AVATAR) {
AvatarAudioRingBuffer* agentRingBuffer = (AvatarAudioRingBuffer*) agent->getLinkedData(); AvatarAudioRingBuffer* agentRingBuffer = (AvatarAudioRingBuffer*) agent->getLinkedData();
@ -120,12 +130,10 @@ int main(int argc, const char* argv[]) {
memset(clientSamples, 0, sizeof(clientSamples)); memset(clientSamples, 0, sizeof(clientSamples));
for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) { for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) {
if ((otherAgent != agent if (((PositionalAudioRingBuffer*) otherAgent->getLinkedData())->willBeAddedToMix()
&& ((PositionalAudioRingBuffer*)otherAgent->getLinkedData())->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) && (otherAgent != agent || (otherAgent == agent && agentRingBuffer->shouldLoopbackForAgent()))) {
|| (otherAgent == agent && agentRingBuffer->shouldLoopbackForAgent())) {
PositionalAudioRingBuffer* otherAgentBuffer = (PositionalAudioRingBuffer*) otherAgent->getLinkedData(); PositionalAudioRingBuffer* otherAgentBuffer = (PositionalAudioRingBuffer*) otherAgent->getLinkedData();
otherAgentBuffer->setWasAddedToMix(true);
float bearingRelativeAngleToSource = 0.0f; float bearingRelativeAngleToSource = 0.0f;
float attenuationCoefficient = 1.0f; float attenuationCoefficient = 1.0f;
@ -294,14 +302,14 @@ int main(int argc, const char* argv[]) {
// push forward the next output pointers for any audio buffers we used // push forward the next output pointers for any audio buffers we used
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
PositionalAudioRingBuffer* agentBuffer = (PositionalAudioRingBuffer*) agent->getLinkedData(); PositionalAudioRingBuffer* agentBuffer = (PositionalAudioRingBuffer*) agent->getLinkedData();
if (agentBuffer && agentBuffer->wasAddedToMix()) { if (agentBuffer && agentBuffer->willBeAddedToMix()) {
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_LENGTH_SAMPLES) { if (agentBuffer->getNextOutput() >= agentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
agentBuffer->setNextOutput(agentBuffer->getBuffer()); agentBuffer->setNextOutput(agentBuffer->getBuffer());
} }
agentBuffer->setWasAddedToMix(false); agentBuffer->setWillBeAddedToMix(false);
} }
} }