From 593730682dad4d09ecf43cca2fe0b64c245b9a68 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 14 Jun 2013 12:04:25 -0600 Subject: [PATCH 1/6] add timing for TwoPole calls --- audio-mixer/src/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 362be4506e..09d74e6ccf 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -116,6 +116,8 @@ int main(int argc, const char* argv[]) { float sumFrameTimePercentages = 0.0f; int numStatCollections = 0; + timeval twoPoleStart, twoPoleEnd; + // if we'll be sending stats, call the Logstash::socket() method to make it load the logstash IP outside the loop if (Logstash::shouldSendStats()) { Logstash::socket(); @@ -257,6 +259,8 @@ int main(int argc, const char* argv[]) { numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); + gettimeofday(&twoPoleStart, NULL); + // grab the TwoPole object for this source, add it if it doesn't exist TwoPoleAgentMap& agentTwoPoles = agentRingBuffer->getTwoPoles(); TwoPoleAgentMap::iterator twoPoleIterator = agentTwoPoles.find(otherAgent->getAgentID()); @@ -276,6 +280,10 @@ int main(int argc, const char* argv[]) { TWO_POLE_MAX_FILTER_STRENGTH * fabsf(bearingRelativeAngleToSource) / 180.0f, true); + + gettimeofday(&twoPoleEnd, NULL); + + printf("TPP: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); } } @@ -302,7 +310,14 @@ int main(int argc, const char* argv[]) { } if (otherAgentTwoPole) { + + gettimeofday(&twoPoleStart, NULL); + otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); + + gettimeofday(&twoPoleEnd, NULL); + + printf("TPC: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); } int16_t currentSample = otherAgentBuffer->getNextOutput()[s] * attenuationCoefficient; From 892167510a007147e8a05eab98ce60f2d1fd6d4b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 14 Jun 2013 12:15:12 -0600 Subject: [PATCH 2/6] time TwoPole call for 256 samples --- audio-mixer/src/main.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 09d74e6ccf..39ae1b8637 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -259,8 +259,6 @@ int main(int argc, const char* argv[]) { numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio; weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio); - gettimeofday(&twoPoleStart, NULL); - // grab the TwoPole object for this source, add it if it doesn't exist TwoPoleAgentMap& agentTwoPoles = agentRingBuffer->getTwoPoles(); TwoPoleAgentMap::iterator twoPoleIterator = agentTwoPoles.find(otherAgent->getAgentID()); @@ -280,10 +278,6 @@ int main(int argc, const char* argv[]) { TWO_POLE_MAX_FILTER_STRENGTH * fabsf(bearingRelativeAngleToSource) / 180.0f, true); - - gettimeofday(&twoPoleEnd, NULL); - - printf("TPP: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); } } @@ -298,6 +292,17 @@ int main(int argc, const char* argv[]) { ? otherAgentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay : otherAgentBuffer->getNextOutput() - numSamplesDelay; + gettimeofday(&twoPoleStart, NULL); + + for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { + if (otherAgentTwoPole) { + otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); + } + } + + gettimeofday(&twoPoleEnd, NULL); + + printf("TPC: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { if (s < numSamplesDelay) { @@ -309,16 +314,9 @@ int main(int argc, const char* argv[]) { plateauAdditionOfSamples(delayedChannel[s], earlierSample); } - if (otherAgentTwoPole) { - - gettimeofday(&twoPoleStart, NULL); - - otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); - - gettimeofday(&twoPoleEnd, NULL); - - printf("TPC: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); - } +// if (otherAgentTwoPole) { +// otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); +// } int16_t currentSample = otherAgentBuffer->getNextOutput()[s] * attenuationCoefficient; From edc13776926204732fde0c34e85dd80601c8ddd3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Jun 2013 09:19:35 -0700 Subject: [PATCH 3/6] perform the two-pole effect across 256 samples, not one per call --- audio-mixer/src/main.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 39ae1b8637..e74191ea60 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -116,6 +116,8 @@ int main(int argc, const char* argv[]) { float sumFrameTimePercentages = 0.0f; int numStatCollections = 0; + stk::StkFrames stkFrameBuffer(BUFFER_LENGTH_SAMPLES_PER_CHANNEL, 1); + timeval twoPoleStart, twoPoleEnd; // if we'll be sending stats, call the Logstash::socket() method to make it load the logstash IP outside the loop @@ -163,6 +165,9 @@ int main(int argc, const char* argv[]) { } for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { + + const int PHASE_DELAY_AT_90 = 20; + if (agent->getType() == AGENT_TYPE_AVATAR) { AvatarAudioRingBuffer* agentRingBuffer = (AvatarAudioRingBuffer*) agent->getLinkedData(); @@ -250,7 +255,6 @@ int main(int argc, const char* argv[]) { glm::normalize(rotatedSourcePosition), glm::vec3(0.0f, 1.0f, 0.0f)); - const int PHASE_DELAY_AT_90 = 20; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; // figure out the number of samples of delay and the ratio of the amplitude @@ -281,6 +285,8 @@ int main(int argc, const char* argv[]) { } } + int16_t* sourceBuffer = otherAgentBuffer->getNextOutput(); + int16_t* goodChannel = (bearingRelativeAngleToSource > 0.0f) ? clientSamples : clientSamples + BUFFER_LENGTH_SAMPLES_PER_CHANNEL; @@ -292,33 +298,25 @@ int main(int argc, const char* argv[]) { ? otherAgentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay : otherAgentBuffer->getNextOutput() - numSamplesDelay; - gettimeofday(&twoPoleStart, NULL); - for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { - if (otherAgentTwoPole) { - otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); - } + // load up the stkFrameBuffer with this source's samples + stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s]; } - gettimeofday(&twoPoleEnd, NULL); - - printf("TPC: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); + // perform the TwoPole effect on the stkFrameBuffer + if (otherAgentTwoPole) { + otherAgentTwoPole->tick(stkFrameBuffer); + } for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { if (s < numSamplesDelay) { // pull the earlier sample for the delayed channel - int earlierSample = delaySamplePointer[s] - * attenuationCoefficient - * weakChannelAmplitudeRatio; + int earlierSample = delaySamplePointer[s] * attenuationCoefficient * weakChannelAmplitudeRatio; plateauAdditionOfSamples(delayedChannel[s], earlierSample); } -// if (otherAgentTwoPole) { -// otherAgentBuffer->getNextOutput()[s] = otherAgentTwoPole->tick(otherAgentBuffer->getNextOutput()[s]); -// } - - int16_t currentSample = otherAgentBuffer->getNextOutput()[s] * attenuationCoefficient; + int16_t currentSample = stkFrameBuffer[s] * attenuationCoefficient; plateauAdditionOfSamples(goodChannel[s], currentSample); @@ -326,6 +324,12 @@ int main(int argc, const char* argv[]) { plateauAdditionOfSamples(delayedChannel[s + numSamplesDelay], currentSample * weakChannelAmplitudeRatio); } + + if (s >= BUFFER_LENGTH_SAMPLES_PER_CHANNEL - PHASE_DELAY_AT_90) { + // this could be a delayed sample on the next pass + // so store the affected back in the ARB + otherAgentBuffer->getNextOutput()[s] = (int16_t) stkFrameBuffer[s]; + } } } } From 5acb0bd1a300faabec6a54d6ffe1872573465a7e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Jun 2013 09:22:43 -0700 Subject: [PATCH 4/6] add timing for two pole effect --- audio-mixer/src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index e74191ea60..b1494d3c61 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -298,6 +298,8 @@ int main(int argc, const char* argv[]) { ? otherAgentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay : otherAgentBuffer->getNextOutput() - numSamplesDelay; + gettimeofday(&twoPoleStart, NULL); + for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { // load up the stkFrameBuffer with this source's samples stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s]; @@ -308,6 +310,10 @@ int main(int argc, const char* argv[]) { otherAgentTwoPole->tick(stkFrameBuffer); } + gettimeofday(&twoPoleEnd, NULL); + + printf("Time taken for TP: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); + for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { if (s < numSamplesDelay) { // pull the earlier sample for the delayed channel From 8cef77bbda2c86dc18ea9be7b917331c2de5d053 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Jun 2013 09:53:30 -0700 Subject: [PATCH 5/6] remove the timing for twopole testing --- audio-mixer/src/main.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index b1494d3c61..e74191ea60 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -298,8 +298,6 @@ int main(int argc, const char* argv[]) { ? otherAgentBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay : otherAgentBuffer->getNextOutput() - numSamplesDelay; - gettimeofday(&twoPoleStart, NULL); - for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { // load up the stkFrameBuffer with this source's samples stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s]; @@ -310,10 +308,6 @@ int main(int argc, const char* argv[]) { otherAgentTwoPole->tick(stkFrameBuffer); } - gettimeofday(&twoPoleEnd, NULL); - - printf("Time taken for TP: %lld\n", usecTimestamp(&twoPoleEnd) - usecTimestamp(&twoPoleStart)); - for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { if (s < numSamplesDelay) { // pull the earlier sample for the delayed channel From 2ba7fe0031d52ff544af93562fda948c9874beb2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Jun 2013 09:55:04 -0700 Subject: [PATCH 6/6] remove the unused timevals --- audio-mixer/src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index e74191ea60..6606e97c9c 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -118,8 +118,6 @@ int main(int argc, const char* argv[]) { stk::StkFrames stkFrameBuffer(BUFFER_LENGTH_SAMPLES_PER_CHANNEL, 1); - timeval twoPoleStart, twoPoleEnd; - // if we'll be sending stats, call the Logstash::socket() method to make it load the logstash IP outside the loop if (Logstash::shouldSendStats()) { Logstash::socket();