Added test for standard deviation calcs at startup.

This commit is contained in:
Philip Rosedale 2013-02-04 13:38:54 -08:00
parent 3d1e249db7
commit 765cded31a
3 changed files with 39 additions and 8 deletions

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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