From 367a553f1e9883d7e51e39e6b71a95cf75cc0202 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 12 Mar 2013 10:15:37 -0700 Subject: [PATCH] compute standard deviation for one client receive times --- mixer/src/main.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 566b48dfed..f6f89765cc 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -12,9 +12,10 @@ #include #include #include -#include "AudioRingBuffer.h" #include #include +#include +#include "AudioRingBuffer.h" const unsigned short MIXER_LISTEN_PORT = 55443; @@ -46,6 +47,7 @@ char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup const int DOMAINSERVER_PORT = 40102; AgentList agentList(MIXER_LISTEN_PORT); +StDev stdev; void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { long sumSample = sampleToAdd + mixSample; @@ -60,7 +62,7 @@ void *sendBuffer(void *args) { int sentBytes; int nextFrame = 0; - timeval startTime, lastSend; + timeval startTime; gettimeofday(&startTime, NULL); @@ -305,12 +307,27 @@ int main(int argc, const char * argv[]) sockaddr *agentAddress = new sockaddr; timeval lastReceive; gettimeofday(&lastReceive, NULL); + + bool firstSample = true; while (true) { if(agentList.getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if (packetData[0] == 'I') { + + // Compute and report standard deviation for jitter calculation + if (firstSample) { + stdev.reset(); + firstSample = false; + } else { + double tDiff = (usecTimestampNow() - usecTimestamp(&lastReceive)) / 1000; + stdev.addValue(tDiff); + + if (stdev.getSamples() > 500) { + printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); + stdev.reset(); + } + } - printf("Last receive was %f ms ago\n", (usecTimestampNow() - usecTimestamp(&lastReceive)) / 1000); gettimeofday(&lastReceive, NULL); // add or update the existing interface agent