# HG changeset patch # User Chris Cannam # Date 1396700335 -3600 # Node ID 303c06efa8d2d5c7168c406c79fe576b487bb932 # Parent 2b254fc68e81d991e37779e50c01ab194d1a084d Return a sketch of notes from pitch activation matrix diff -r 2b254fc68e81 -r 303c06efa8d2 src/Silvet.cpp --- a/src/Silvet.cpp Sat Apr 05 08:41:55 2014 +0100 +++ b/src/Silvet.cpp Sat Apr 05 13:18:55 2014 +0100 @@ -28,6 +28,7 @@ using std::vector; using std::cerr; using std::endl; +using Vamp::RealTime; static int processingSampleRate = 44100; static int processingBPO = 60; @@ -168,10 +169,10 @@ d.identifier = "transcription"; d.name = "Transcription"; d.description = ""; //!!! - d.unit = "Hz"; + d.unit = "MIDI Pitch"; d.hasFixedBinCount = true; d.binCount = 2; - d.binNames.push_back("Frequency"); + d.binNames.push_back("Note"); d.binNames.push_back("Velocity"); d.hasKnownExtents = false; d.isQuantized = false; @@ -289,13 +290,21 @@ } m_columnCount = 0; m_reducedColumnCount = 0; + m_transcribedColumnCount = 0; + m_startTime = RealTime::zeroTime; } Silvet::FeatureSet Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { + if (m_columnCount == 0) { + m_startTime = timestamp; + } + vector data; - for (int i = 0; i < m_blockSize; ++i) data.push_back(inputBuffers[0][i]); + for (int i = 0; i < m_blockSize; ++i) { + data.push_back(inputBuffers[0][i]); + } if (m_resampler) { data = m_resampler->process(data.data(), data.size()); @@ -331,8 +340,16 @@ int iterations = 12; + // we have 25 columns per second + double columnDuration = 1.0 / 25.0; + for (int i = 0; i < width; ++i) { + RealTime t = m_startTime + + RealTime::fromSeconds(m_transcribedColumnCount * columnDuration); + + ++m_transcribedColumnCount; + double sum = 0.0; for (int j = 0; j < processingHeight; ++j) { sum += filtered[i][j]; @@ -349,10 +366,27 @@ vector pitches = em.getPitchDistribution(); Feature f; for (int j = 0; j < (int)pitches.size(); ++j) { - f.values.push_back(float(pitches[j])); + f.values.push_back(float(pitches[j] * sum)); } fs[m_pitchOutputNo].push_back(f); + //!!! fake notes + for (int j = 0; j < (int)pitches.size(); ++j) { + if (pitches[j] * sum > 5) { + cerr << "pitch " << j << " level: " << pitches[j] * sum << endl; + Feature nf; + nf.hasTimestamp = true; + nf.timestamp = t; + nf.hasDuration = true; + nf.duration = RealTime::fromSeconds(columnDuration); + nf.values.push_back(j + 21); + float velocity = pitches[j] * sum * 2; + if (velocity > 127.f) velocity = 127.f; + nf.values.push_back(velocity); + fs[m_notesOutputNo].push_back(nf); + } + } + //!!! now do something with the results from em! em.report(); } diff -r 2b254fc68e81 -r 303c06efa8d2 src/Silvet.h --- a/src/Silvet.h Sat Apr 05 08:41:55 2014 +0100 +++ b/src/Silvet.h Sat Apr 05 13:18:55 2014 +0100 @@ -82,6 +82,8 @@ int m_blockSize; int m_columnCount; int m_reducedColumnCount; + int m_transcribedColumnCount; + Vamp::RealTime m_startTime; mutable int m_notesOutputNo; mutable int m_cqOutputNo;