From 96205ac2080f1ef71e4e06215b83bc001dbccc7f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 4 Feb 2013 13:38:54 -0800 Subject: [PATCH] Added test for standard deviation calcs at startup. --- Source/Audio.cpp | 6 +++--- Source/Util.cpp | 10 +++++++--- Source/main.cpp | 31 +++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Source/Audio.cpp b/Source/Audio.cpp index 37c2e9b69a..29b05dda40 100644 --- a/Source/Audio.cpp +++ b/Source/Audio.cpp @@ -84,7 +84,7 @@ int audioCallback (const void *inputBuffer, // int16_t *inputRight = ((int16_t **) inputBuffer)[1]; if (inputLeft != NULL) { - data->audioSocket->send((char *) EC2_WEST_AUDIO_SERVER, 55443, (void *)inputLeft, BUFFER_LENGTH_BYTES); + data->audioSocket->send((char *) WORKCLUB_AUDIO_SERVER, 55443, (void *)inputLeft, BUFFER_LENGTH_BYTES); } int16_t *outputLeft = ((int16_t **) outputBuffer)[0]; @@ -236,12 +236,12 @@ void *receiveAudioViaUDP(void *args) { } } - // Compute standard deviation for jitter + // Compute and report standard deviation for jitter calculation if (firstSample) { stdev.reset(); } else { stdev.addValue(diffclock(previousReceiveTime, currentReceiveTime)); - if (stdev.getSamples() > 300) { + if (stdev.getSamples() > 500) { printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); stdev.reset(); } diff --git a/Source/Util.cpp b/Source/Util.cpp index 6eedd863b8..2fb5ad14eb 100644 --- a/Source/Util.cpp +++ b/Source/Util.cpp @@ -17,7 +17,11 @@ #include "util.h" -const int MAX_STDEV_SAMPLES = 1000; +// +// Standard Deviation Object +// + +const int MAX_STDEV_SAMPLES = 1000; // Don't add more than this number of samples. StDev::StDev() { data = new float[MAX_STDEV_SAMPLES]; @@ -49,8 +53,8 @@ float StDev::getStDev() { for (int i = 0; i < sampleCount; i++) { stdev += powf(data[i] - average, 2); } - if (sampleCount > 0) - return sqrt(stdev/(float)sampleCount); + if (sampleCount > 1) + return sqrt(stdev/(float)(sampleCount - 1.0)); else return 0; } diff --git a/Source/main.cpp b/Source/main.cpp index 49e9bc6829..1dc89ffeee 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -903,8 +903,35 @@ int main(int argc, char** argv) int test_recv = network_receive(UDP_socket, &from_addr, incoming_packet, delay); printf("Received %i bytes\n", test_recv); - // Load textures - //Img.Load("/Users/philip/Downloads/galaxy1.tga"); + // + printf("Testing math... standard deviation.\n"); + StDev stdevtest; + stdevtest.reset(); + stdevtest.addValue(1345); + stdevtest.addValue(1301); + stdevtest.addValue(1368); + stdevtest.addValue(1322); + stdevtest.addValue(1310); + stdevtest.addValue(1370); + stdevtest.addValue(1318); + stdevtest.addValue(1350); + stdevtest.addValue(1303); + stdevtest.addValue(1299); + + if (stdevtest.getSamples() == 10) + printf("Samples=PASS "); + else + printf("Samples=FAIL "); + + if (floor(stdevtest.getAverage()*100.0) == 132859.0) + printf("Average=PASS "); + else + printf("Average=FAIL, avg reported = %5.3f ", floor(stdevtest.getAverage()*100.0)); + + if (floor(stdevtest.getStDev()*100.0) == 2746.0) + printf("Stdev=PASS \n"); + else + printf("Stdev=FAIL \n"); // // Try to connect the serial port I/O