Mercurial > hg > pyin
changeset 39:39499ccf7656 tony
Return candidates as a stack of values per frame
author | Chris Cannam |
---|---|
date | Tue, 28 Jan 2014 11:51:47 +0000 |
parents | 4fb53b23d611 |
children | c1781761aa23 |
files | LocalCandidatePYIN.cpp |
diffstat | 1 files changed, 39 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/LocalCandidatePYIN.cpp Mon Jan 27 15:26:32 2014 +0000 +++ b/LocalCandidatePYIN.cpp Tue Jan 28 11:51:47 2014 +0000 @@ -25,9 +25,11 @@ // #include <iostream> #include <cmath> #include <complex> +#include <map> using std::string; using std::vector; +using std::map; using Vamp::RealTime; @@ -222,16 +224,14 @@ d.description = "Multiple candidate pitch tracks."; d.unit = "Hz"; d.hasFixedBinCount = false; - // d.binCount = 1; d.hasKnownExtents = true; d.minValue = m_fmin; - d.maxValue = 500; + d.maxValue = 500; //!!!??? d.isQuantized = false; d.sampleType = OutputDescriptor::FixedSampleRate; d.sampleRate = (m_inputSampleRate / m_stepSize); d.hasDuration = false; outputs.push_back(d); - // m_oPitchTrackCandidates = outputNumber++; return outputs; } @@ -279,7 +279,6 @@ LocalCandidatePYIN::process(const float *const *inputBuffers, RealTime timestamp) { timestamp = timestamp + Vamp::RealTime::frame2RealTime(m_blockSize/4, lrintf(m_inputSampleRate)); - FeatureSet fs; double *dInputBuffers = new double[m_blockSize]; for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i]; @@ -318,22 +317,19 @@ } m_timestamp.push_back(timestamp); - return fs; + return FeatureSet(); } LocalCandidatePYIN::FeatureSet LocalCandidatePYIN::getRemainingFeatures() { - FeatureSet fs; - Feature f; - f.hasTimestamp = true; - f.hasDuration = false; - f.values.push_back(0); + // timestamp -> candidate number -> value + map<RealTime, map<int, float> > featureValues; std::cerr << "in remaining features" << std::endl; if (m_pitchProb.empty()) { - return fs; + return FeatureSet(); } // MONO-PITCH STUFF @@ -378,6 +374,9 @@ } } + map<int, int> candidateActuals; + map<int, std::string> candidateLabels; + int actualCandidateNumber = 0; for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate) { bool isDuplicate = false; @@ -392,15 +391,15 @@ { std::ostringstream convert; convert << actualCandidateNumber++; - f.label = convert.str(); + candidateLabels[iCandidate] = convert.str(); + candidateActuals[iCandidate] = actualCandidateNumber; std::cerr << freqNumber[iCandidate] << " " << freqMean[iCandidate] << std::endl; for (size_t iFrame = 0; iFrame < nFrame; ++iFrame) { if (pitchTracks[iCandidate][iFrame] > 0) { - f.values[0] = pitchTracks[iCandidate][iFrame]; - f.timestamp = m_timestamp[iFrame]; - fs[m_oPitchTrackCandidates].push_back(f); + featureValues[m_timestamp[iFrame]][iCandidate] = + pitchTracks[iCandidate][iFrame]; } } } @@ -408,6 +407,31 @@ } // only retain those that are close to their means + //!!!??? what does the above mean? + + // adapt our features so as to return a stack of candidate values + // per frame + + FeatureSet fs; + + for (map<RealTime, map<int, float> >::const_iterator i = + featureValues.begin(); i != featureValues.end(); ++i) { + Feature f; + f.hasTimestamp = true; + f.timestamp = i->first; + int nextCandidate = candidateActuals.begin()->second; + for (map<int, float>::const_iterator j = + i->second.begin(); j != i->second.end(); ++j) { + while (candidateActuals[j->first] > nextCandidate) { + f.values.push_back(0); + ++nextCandidate; + } + f.values.push_back(j->second); + nextCandidate = j->first + 1; + } + //!!! can't use labels? + fs[0].push_back(f); + } return fs; }