Mercurial > hg > tipic
changeset 25:2c913b88b808
Fix folding
author | Chris Cannam |
---|---|
date | Tue, 29 Sep 2015 16:51:49 +0100 |
parents | 353e88e4ebea |
children | 3d1c5cabadcc |
files | src/CRP.cpp src/CRP.h src/Normalise.h src/OctaveFold.h test/examples/README.txt |
diffstat | 5 files changed, 24 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/CRP.cpp Tue Sep 29 16:36:23 2015 +0100 +++ b/src/CRP.cpp Tue Sep 29 16:51:49 2015 +0100 @@ -24,9 +24,14 @@ if (in.empty()) { return in; } + + // The chroma processing chain requires a 120-bin pitch filterbank + // output, even though ours only actually contains 88 bins. + + int size = 120; + if (!m_dctReduce) { - m_size = in[0].size(); - m_dctReduce = new DCTReduce(m_size, m_params.coefficientsToDrop); + m_dctReduce = new DCTReduce(size, m_params.coefficientsToDrop); } RealBlock out; @@ -37,10 +42,14 @@ col = LogCompress::process(col, m_params.logFactor, m_params.logAddTerm); } + RealColumn resized(20, 0.0); + resized.insert(resized.end(), col.begin(), col.end()); + resized.resize(size); + out.push_back(Normalise::normalise (OctaveFold::process - (m_dctReduce->process(col)), - m_params.normP)); + (m_dctReduce->process(resized)), + m_params.normP, m_params.normThresh)); } return out;
--- a/src/CRP.h Tue Sep 29 16:36:23 2015 +0100 +++ b/src/CRP.h Tue Sep 29 16:51:49 2015 +0100 @@ -18,23 +18,24 @@ double logFactor; double logAddTerm; int normP; + double normThresh; Parameters() : - coefficientsToDrop(54), + coefficientsToDrop(55), applyLogCompression(true), logFactor(1000.0), logAddTerm(1.0), - normP(2) + normP(2), + normThresh(1e-6) { } }; - CRP(Parameters params) : m_params(params), m_size(0), m_dctReduce(0) { } + CRP(Parameters params) : m_params(params), m_dctReduce(0) { } ~CRP(); RealBlock process(const RealBlock &in); private: Parameters m_params; - int m_size; DCTReduce *m_dctReduce; };
--- a/src/Normalise.h Tue Sep 29 16:36:23 2015 +0100 +++ b/src/Normalise.h Tue Sep 29 16:51:49 2015 +0100 @@ -9,10 +9,10 @@ { public: static double norm(std::vector<double> v, - int p = 2); // L^p norm + int p); // L^p norm static std::vector<double> normalise(std::vector<double> v, - int p = 2, + int p, double threshold = 1e-6); };
--- a/src/OctaveFold.h Tue Sep 29 16:36:23 2015 +0100 +++ b/src/OctaveFold.h Tue Sep 29 16:51:49 2015 +0100 @@ -8,17 +8,10 @@ class OctaveFold { public: - /** - * Take an 88-bin pitch feature and sum it into a 12-bin - * octave. Each bin gets summed into chroma bin corresponding to - * its MIDI pitch modulo 12. The first 20 MIDI pitches are - * missing, so bin number n (for n from 0 to 87) is for MIDI pitch - * 21+n. - */ static std::vector<double> process(std::vector<double> in) { std::vector<double> out(12, 0.0); for (int i = 0; i < int(in.size()); ++i) { - out[(21+i) % 12] += in[i]; + out[(i+1) % 12] += in[i]; } return std::move(out); }
--- a/test/examples/README.txt Tue Sep 29 16:36:23 2015 +0100 +++ b/test/examples/README.txt Tue Sep 29 16:51:49 2015 +0100 @@ -39,5 +39,7 @@ The proposition that these are intended to help test is: If Tipic produces the pitch features found in ylsf-30sec-tipic-pitch.csv, and if we assume the MATLAB implementations are correct, then Tipic should -also produce chroma features matching those in these files. +also produce chroma features matching those in these files. (Up to +rounding error based on the limited precision with which the original +pitch values were written out to CSV.)