diff --git a/libraries/shared/src/StdDev.cpp b/libraries/shared/src/StdDev.cpp index c5d78345e4..387b67cf4f 100644 --- a/libraries/shared/src/StdDev.cpp +++ b/libraries/shared/src/StdDev.cpp @@ -13,50 +13,40 @@ #include #include "StdDev.h" -const int MAX_STDEV_SAMPLES = 1000; +const int NUM_SAMPLES = 1000; StDev::StDev() { - data = new float[MAX_STDEV_SAMPLES]; - sampleCount = 0; + _data = new float[NUM_SAMPLES]; + _sampleCount = 0; } void StDev::reset() { - sampleCount = 0; + _sampleCount = 0; } void StDev::addValue(float v) { - data[sampleCount++] = v; - if (sampleCount == MAX_STDEV_SAMPLES) sampleCount = 0; + _data[_sampleCount++] = v; + if (_sampleCount == NUM_SAMPLES) _sampleCount = 0; } float StDev::getAverage() const { float average = 0; - for (int i = 0; i < sampleCount; i++) { - average += data[i]; + for (int i = 0; i < _sampleCount; i++) { + average += _data[i]; } - if (sampleCount > 0) - return average/(float)sampleCount; + if (_sampleCount > 0) + return average / (float)_sampleCount; else return 0; } -/* -float StDev::getMax() { - float average = -FLT_MAX; - for (int i = 0; i < sampleCount; i++) { - average += data[i]; - } - if (sampleCount > 0) - return average/(float)sampleCount; - else return 0; -}*/ float StDev::getStDev() const { float average = getAverage(); float stdev = 0; - for (int i = 0; i < sampleCount; i++) { - stdev += powf(data[i] - average, 2); + for (int i = 0; i < _sampleCount; i++) { + stdev += powf(_data[i] - average, 2); } - if (sampleCount > 1) - return sqrt(stdev/(float)(sampleCount - 1.0)); + if (_sampleCount > 1) + return sqrt(stdev / (float)(_sampleCount - 1.0f)); else return 0; } diff --git a/libraries/shared/src/StdDev.h b/libraries/shared/src/StdDev.h index a05cc32992..40148007a9 100644 --- a/libraries/shared/src/StdDev.h +++ b/libraries/shared/src/StdDev.h @@ -13,16 +13,16 @@ #define hifi_StdDev_h class StDev { - public: - StDev(); - void reset(); - void addValue(float v); - float getAverage() const; - float getStDev() const; - int getSamples() const { return sampleCount; } - private: - float * data; - int sampleCount; +public: + StDev(); + void reset(); + void addValue(float v); + float getAverage() const; + float getStDev() const; + int getSamples() const { return _sampleCount; } +private: + float* _data; + int _sampleCount; }; #endif // hifi_StdDev_h