# HG changeset patch # User Chris Cannam # Date 1434129609 -3600 # Node ID 70f18770b72d86d036dc22033c6934322d0028d8 # Parent bdebff3265ae4ede7cad64b512d6fa43be12ea27 Normalization function diff -r bdebff3265ae -r 70f18770b72d data/model/FFTModel.cpp --- a/data/model/FFTModel.cpp Fri Jun 12 18:08:57 2015 +0100 +++ b/data/model/FFTModel.cpp Fri Jun 12 18:20:09 2015 +0100 @@ -109,9 +109,11 @@ FFTModel::getMaximumMagnitudeAt(int x) const { Column col(getColumn(x)); - auto itr = max_element(col.begin(), col.end()); - if (itr == col.end()) return 0.f; - else return *itr; + float max = 0.f; + for (int i = 0; i < col.size(); ++i) { + if (col[i] > max) max = col[i]; + } + return max; } float @@ -150,8 +152,18 @@ bool FFTModel::getNormalizedMagnitudesAt(int x, float *values, int minbin, int count) const { - //!!! WRONG - return getMagnitudesAt(x, values, minbin, count); + if (!getMagnitudesAt(x, values, minbin, count)) return false; + if (count == 0) count = getHeight(); + float max = 0.f; + for (int i = 0; i < count; ++i) { + if (values[i] > max) max = values[i]; + } + if (max > 0.f) { + for (int i = 0; i < count; ++i) { + values[i] /= max; + } + } + return true; } bool diff -r bdebff3265ae -r 70f18770b72d data/model/FFTModel.h --- a/data/model/FFTModel.h Fri Jun 12 18:08:57 2015 +0100 +++ b/data/model/FFTModel.h Fri Jun 12 18:20:09 2015 +0100 @@ -37,6 +37,9 @@ { Q_OBJECT + //!!! threading requirements? + //!!! doubles? since we're not caching much + public: /** * Construct an FFT model derived from the given