Mercurial > hg > svcore
changeset 1092:70f18770b72d simple-fft-model
Normalization function
author | Chris Cannam |
---|---|
date | Fri, 12 Jun 2015 18:20:09 +0100 |
parents | bdebff3265ae |
children | 44b079427b36 |
files | data/model/FFTModel.cpp data/model/FFTModel.h |
diffstat | 2 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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