From 16d1f8da5aff85253da11a46a69e5b17743d3915 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 5 Jun 2013 12:31:13 -0700 Subject: [PATCH] pre-enumerate all sources to push buffers when there is only one source --- audio-mixer/src/PositionalAudioRingBuffer.cpp | 2 +- audio-mixer/src/PositionalAudioRingBuffer.h | 6 ++--- audio-mixer/src/main.cpp | 22 +++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/audio-mixer/src/PositionalAudioRingBuffer.cpp b/audio-mixer/src/PositionalAudioRingBuffer.cpp index 5cd856d8c1..e555b7e3d5 100644 --- a/audio-mixer/src/PositionalAudioRingBuffer.cpp +++ b/audio-mixer/src/PositionalAudioRingBuffer.cpp @@ -15,7 +15,7 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() : _position(0.0f, 0.0f, 0.0f), _orientation(0.0f, 0.0f, 0.0f, 0.0f), _shouldLoopbackForAgent(false), - _wasAddedToMix(false) + _willBeAddedToMix(false) { } diff --git a/audio-mixer/src/PositionalAudioRingBuffer.h b/audio-mixer/src/PositionalAudioRingBuffer.h index 567c6cbf78..d1752fa0bf 100644 --- a/audio-mixer/src/PositionalAudioRingBuffer.h +++ b/audio-mixer/src/PositionalAudioRingBuffer.h @@ -22,8 +22,8 @@ public: bool shouldBeAddedToMix(int numJitterBufferSamples); - bool wasAddedToMix() const { return _wasAddedToMix; } - void setWasAddedToMix(bool wasAddedToMix) { _wasAddedToMix = wasAddedToMix; } + bool willBeAddedToMix() const { return _willBeAddedToMix; } + void setWillBeAddedToMix(bool willBeAddedToMix) { _willBeAddedToMix = willBeAddedToMix; } const glm::vec3& getPosition() const { return _position; } const glm::quat& getOrientation() const { return _orientation; } @@ -38,7 +38,7 @@ protected: glm::vec3 _position; glm::quat _orientation; bool _shouldLoopbackForAgent; - bool _wasAddedToMix; + bool _willBeAddedToMix; }; #endif /* defined(__hifi__PositionalAudioRingBuffer__) */ diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index f50507a45f..6582fa57bf 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -111,7 +111,17 @@ int main(int argc, const char* argv[]) { 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++) { if (agent->getType() == AGENT_TYPE_AVATAR) { AvatarAudioRingBuffer* agentRingBuffer = (AvatarAudioRingBuffer*) agent->getLinkedData(); @@ -120,12 +130,10 @@ int main(int argc, const char* argv[]) { memset(clientSamples, 0, sizeof(clientSamples)); for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) { - if ((otherAgent != agent - && ((PositionalAudioRingBuffer*)otherAgent->getLinkedData())->shouldBeAddedToMix(JITTER_BUFFER_SAMPLES)) - || (otherAgent == agent && agentRingBuffer->shouldLoopbackForAgent())) { + if (((PositionalAudioRingBuffer*) otherAgent->getLinkedData())->willBeAddedToMix() + && (otherAgent != agent || (otherAgent == agent && agentRingBuffer->shouldLoopbackForAgent()))) { PositionalAudioRingBuffer* otherAgentBuffer = (PositionalAudioRingBuffer*) otherAgent->getLinkedData(); - otherAgentBuffer->setWasAddedToMix(true); float bearingRelativeAngleToSource = 0.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 for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { PositionalAudioRingBuffer* agentBuffer = (PositionalAudioRingBuffer*) agent->getLinkedData(); - if (agentBuffer && agentBuffer->wasAddedToMix()) { + if (agentBuffer && agentBuffer->willBeAddedToMix()) { agentBuffer->setNextOutput(agentBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL); if (agentBuffer->getNextOutput() >= agentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) { agentBuffer->setNextOutput(agentBuffer->getBuffer()); } - agentBuffer->setWasAddedToMix(false); + agentBuffer->setWillBeAddedToMix(false); } }