Mercurial > hg > silvet
changeset 302:cac0be04c43c livemode
Add output for the templates (probably temporarily)
author | Chris Cannam |
---|---|
date | Tue, 02 Dec 2014 17:13:10 +0000 |
parents | 00fab71b80ec |
children | d8468176339d |
files | src/LiveInstruments.cpp src/Silvet.cpp src/Silvet.h |
diffstat | 3 files changed, 70 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LiveInstruments.cpp Mon Dec 01 17:12:19 2014 +0000 +++ b/src/LiveInstruments.cpp Tue Dec 02 17:13:10 2014 +0000 @@ -55,8 +55,10 @@ } // re-normalise - for (int k = 0; k < (int)t.data[j].size(); ++k) { - t.data[j][k] *= 1.f / sum; + if (sum > 0.f) { + for (int k = 0; k < (int)t.data[j].size(); ++k) { + t.data[j][k] *= 1.f / sum; + } } }
--- a/src/Silvet.cpp Mon Dec 01 17:12:19 2014 +0000 +++ b/src/Silvet.cpp Tue Dec 02 17:13:10 2014 +0000 @@ -295,6 +295,35 @@ m_pitchOutputNo = list.size(); list.push_back(d); + d.identifier = "templates"; + d.name = "Templates"; + d.description = "Constant-Q spectral templates for the selected instrument pack."; + d.unit = ""; + d.hasFixedBinCount = true; + d.binCount = getPack(0).templateHeight; + d.binNames.clear(); + if (m_cq) { + char name[50]; + for (int i = 0; i < getPack(0).templateHeight; ++i) { + // We have a 600-bin (10 oct 60-bin CQ) of which the + // lowest-frequency 55 bins have been dropped, for a + // 545-bin template. The native CQ bins go high->low + // frequency though, so these are still the first 545 bins + // as reported by getBinFrequency, though in reverse order + float freq = m_cq->getBinFrequency + (getPack(0).templateHeight - i - 1); + sprintf(name, "%.1f Hz", freq); + d.binNames.push_back(name); + } + } + d.hasKnownExtents = false; + d.isQuantized = false; + d.sampleType = OutputDescriptor::FixedSampleRate; + d.sampleRate = m_colsPerSec; + d.hasDuration = false; + m_templateOutputNo = list.size(); + list.push_back(d); + return list; } @@ -467,8 +496,11 @@ Silvet::FeatureSet Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { + FeatureSet fs; + if (m_columnCount == 0) { m_startTime = timestamp; + insertTemplateFeatures(fs); } vector<float> flattened(m_blockSize); @@ -501,7 +533,7 @@ if (hadCount < resamplerLatency) { int stillToDrop = resamplerLatency - hadCount; if (stillToDrop >= int(data.size())) { - return FeatureSet(); + return fs; } else { data = vector<double>(data.begin() + stillToDrop, data.end()); } @@ -509,7 +541,7 @@ } Grid cqout = m_cq->process(data); - FeatureSet fs = transcribe(cqout); + transcribe(cqout, fs); return fs; } @@ -517,18 +549,40 @@ Silvet::getRemainingFeatures() { Grid cqout = m_cq->getRemainingOutput(); - FeatureSet fs = transcribe(cqout); + FeatureSet fs; + if (m_columnCount == 0) { + // process() was never called, but we still want these + insertTemplateFeatures(fs); + } else { + transcribe(cqout, fs); + } return fs; } -Silvet::FeatureSet -Silvet::transcribe(const Grid &cqout) +void +Silvet::insertTemplateFeatures(FeatureSet &fs) +{ + const InstrumentPack &pack = getPack(m_instrument); + for (int i = 0; i < int(pack.templates.size()) * pack.templateNoteCount; ++i) { + RealTime timestamp = RealTime::fromSeconds(double(i) / m_colsPerSec); + Feature f; + char buffer[50]; + sprintf(buffer, "Note %d", i + 1); + f.label = buffer; + f.hasTimestamp = true; + f.timestamp = timestamp; + f.values = pack.templates[i / pack.templateNoteCount] + .data[i % pack.templateNoteCount]; + fs[m_templateOutputNo].push_back(f); + } +} + +void +Silvet::transcribe(const Grid &cqout, Silvet::FeatureSet &fs) { Grid filtered = preProcess(cqout); - FeatureSet fs; - - if (filtered.empty()) return fs; + if (filtered.empty()) return; const InstrumentPack &pack(getPack(m_instrument)); @@ -634,8 +688,6 @@ fs[m_notesOutputNo].push_back(*fi); } } - - return fs; } Silvet::Grid
--- a/src/Silvet.h Mon Dec 01 17:12:19 2014 +0000 +++ b/src/Silvet.h Tue Dec 02 17:13:10 2014 +0000 @@ -121,7 +121,9 @@ float getInputGainAt(Vamp::RealTime t); - FeatureSet transcribe(const Grid &); + void insertTemplateFeatures(FeatureSet &); + + void transcribe(const Grid &, FeatureSet &); string noteName(int n, int shift, int shiftCount) const; float noteFrequency(int n, int shift, int shiftCount) const; @@ -134,6 +136,7 @@ mutable int m_notesOutputNo; mutable int m_fcqOutputNo; mutable int m_pitchOutputNo; + mutable int m_templateOutputNo; }; #endif