# HG changeset patch # User Chris Cannam # Date 1396634747 -3600 # Node ID 5164bccf3064368b972cfe87340b00fccc1da375 # Parent 947996aac974729f383878025a84af5638ef7be8 Return pitch activation matrix diff -r 947996aac974 -r 5164bccf3064 src/EM.cpp --- a/src/EM.cpp Fri Apr 04 18:18:18 2014 +0100 +++ b/src/EM.cpp Fri Apr 04 19:05:47 2014 +0100 @@ -152,9 +152,10 @@ newSources[i][n] = epsilon; if (inRange(i, n)) { float *w = silvet_templates[i].data[n]; + double pitch = m_pitches[n]; + double source = m_sources[i][n]; for (int j = 0; j < m_bins; ++j) { - newSources[i][n] += - w[j] * m_q[j] * m_pitches[n] * m_sources[i][n]; + newSources[i][n] += w[j] * m_q[j] * pitch * source; } } } diff -r 947996aac974 -r 5164bccf3064 src/EM.h --- a/src/EM.h Fri Apr 04 18:18:18 2014 +0100 +++ b/src/EM.h Fri Apr 04 19:05:47 2014 +0100 @@ -27,6 +27,16 @@ void iterate(std::vector column); void report(); + const std::vector &getEstimate() const { + return m_estimate; + } + const std::vector &getPitchDistribution() const { + return m_pitches; + } + const std::vector > &getSources() const { + return m_sources; + } + private: typedef std::vector V; typedef std::vector > Grid; diff -r 947996aac974 -r 5164bccf3064 src/Silvet.cpp --- a/src/Silvet.cpp Fri Apr 04 18:18:18 2014 +0100 +++ b/src/Silvet.cpp Fri Apr 04 19:05:47 2014 +0100 @@ -32,6 +32,7 @@ static int processingSampleRate = 44100; static int processingBPO = 60; static int processingHeight = 545; +static int processingNotes = 88; Silvet::Silvet(float inputSampleRate) : Plugin(inputSampleRate), @@ -203,9 +204,44 @@ m_cqOutputNo = list.size(); list.push_back(d); + d.identifier = "pitchdistribution"; + d.name = "Pitch distribution"; + d.description = "The estimated pitch contribution matrix"; + d.unit = ""; + d.hasFixedBinCount = true; + d.binCount = processingNotes; + d.binNames.clear(); + for (int i = 0; i < processingNotes; ++i) { + d.binNames.push_back(noteName(i)); + } + d.hasKnownExtents = false; + d.isQuantized = false; + d.sampleType = OutputDescriptor::FixedSampleRate; + d.sampleRate = 25; + d.hasDuration = false; + m_pitchOutputNo = list.size(); + list.push_back(d); + return list; } +std::string +Silvet::noteName(int i) const +{ + static const char *names[] = { + "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" + }; + + const char *n = names[i % 12]; + + int oct = (i + 9) / 12; + + char buf[20]; + sprintf(buf, "%s%d", n, oct); + + return buf; +} + bool Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) { @@ -310,6 +346,13 @@ em.iterate(filtered[i]); } + vector pitches = em.getPitchDistribution(); + Feature f; + for (int j = 0; j < (int)pitches.size(); ++j) { + f.values.push_back(float(pitches[i])); + } + fs[m_pitchOutputNo].push_back(f); + //!!! now do something with the results from em! em.report(); } diff -r 947996aac974 -r 5164bccf3064 src/Silvet.h --- a/src/Silvet.h Fri Apr 04 18:18:18 2014 +0100 +++ b/src/Silvet.h Fri Apr 04 19:05:47 2014 +0100 @@ -77,12 +77,15 @@ Grid preProcess(const Grid &); FeatureSet transcribe(const Grid &); + std::string noteName(int n) const; + int m_blockSize; int m_columnCount; int m_reducedColumnCount; mutable int m_notesOutputNo; mutable int m_cqOutputNo; + mutable int m_pitchOutputNo; }; #endif