Mercurial > hg > qm-vamp-plugins
diff plugins/BarBeatTrack.cpp @ 146:c4837ed2eeb1
Merge mepd_new_params branch
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 02 Sep 2013 09:29:34 +0100 |
parents | edad8a88a074 |
children | 88c05c0ac438 |
line wrap: on
line diff
--- a/plugins/BarBeatTrack.cpp Wed Dec 12 15:28:33 2012 +0000 +++ b/plugins/BarBeatTrack.cpp Mon Sep 02 09:29:34 2013 +0100 @@ -35,20 +35,20 @@ { public: BarBeatTrackerData(float rate, const DFConfig &config) : dfConfig(config) { - df = new DetectionFunction(config); + df = new DetectionFunction(config); // decimation factor aims at resampling to c. 3KHz; must be power of 2 int factor = MathUtilities::nextPowerOfTwo(rate / 3000); // std::cerr << "BarBeatTrackerData: factor = " << factor << std::endl; downBeat = new DownBeat(rate, factor, config.stepSize); } ~BarBeatTrackerData() { - delete df; + delete df; delete downBeat; } void reset() { - delete df; - df = new DetectionFunction(dfConfig); - dfOutput.clear(); + delete df; + df = new DetectionFunction(dfConfig); + dfOutput.clear(); downBeat->resetAudioBuffer(); origin = Vamp::RealTime::zeroTime; } @@ -59,12 +59,16 @@ vector<double> dfOutput; Vamp::RealTime origin; }; - + BarBeatTracker::BarBeatTracker(float inputSampleRate) : Vamp::Plugin(inputSampleRate), m_d(0), - m_bpb(4) + m_bpb(4), + m_alpha(0.9), // changes are as per the BeatTrack.cpp + m_tightness(4.), // changes are as per the BeatTrack.cpp + m_inputtempo(120.), // changes are as per the BeatTrack.cpp + m_constraintempo(false) // changes are as per the BeatTrack.cpp { } @@ -100,7 +104,7 @@ int BarBeatTracker::getPluginVersion() const { - return 2; + return 3; } string @@ -126,32 +130,103 @@ desc.quantizeStep = 1; list.push_back(desc); + // changes are as per the BeatTrack.cpp + //Alpha Parameter of Beat Tracker + desc.identifier = "alpha"; + desc.name = "Alpha"; + desc.description = "Inertia - Flexibility Trade Off"; + desc.minValue = 0.1; + desc.maxValue = 0.99; + desc.defaultValue = 0.90; + desc.unit = ""; + desc.isQuantized = false; + list.push_back(desc); + + + // changes are as per the BeatTrack.cpp + //Tightness Parameter of Beat Tracker + desc.identifier = "tightness"; + desc.name = "Tightness"; + desc.description = "Inertia - Flexibility Trade Off 2"; + desc.minValue = 3; + desc.maxValue = 7; + desc.defaultValue = 4; + desc.unit = ""; + desc.isQuantized = true; + list.push_back(desc); + + // changes are as per the BeatTrack.cpp + //User input tempo + desc.identifier = "inputtempo"; + desc.name = "InputTempo"; + desc.description = "User defined Tempo"; + desc.minValue = 50; + desc.maxValue = 250; + desc.defaultValue = 120; + desc.unit = "BPM"; + desc.isQuantized = true; + list.push_back(desc); + + // changes are as per the BeatTrack.cpp + desc.identifier = "constraintempo"; + desc.name = "Constrain Tempo"; + desc.description = "Constrain tempo to use Gaussian weighting"; + desc.minValue = 0; + desc.maxValue = 1; + desc.defaultValue = 0; + desc.isQuantized = true; + desc.quantizeStep = 1; + desc.unit = ""; + desc.valueNames.clear(); + list.push_back(desc); + + return list; } float BarBeatTracker::getParameter(std::string name) const { - if (name == "bpb") return m_bpb; + if (name == "bpb") { + return m_bpb; + } else if (name == "alpha") { + return m_alpha; + } else if (name == "tightness") { + return m_tightness; + } else if (name == "inputtempo") { + return m_inputtempo; + } else if (name == "constraintempo") { + return m_constraintempo ? 1.0 : 0.0; + } return 0.0; } void BarBeatTracker::setParameter(std::string name, float value) { - if (name == "bpb") m_bpb = lrintf(value); + if (name == "bpb") { + m_bpb = lrintf(value); + } else if (name == "alpha") { + m_alpha = value; + } else if (name == "tightness") { + m_tightness = value; + } else if (name == "inputtempo") { + m_inputtempo = value; + } else if (name == "constraintempo") { + m_constraintempo = (value > 0.5); + } } bool BarBeatTracker::initialise(size_t channels, size_t stepSize, size_t blockSize) { if (m_d) { - delete m_d; - m_d = 0; + delete m_d; + m_d = 0; } if (channels < getMinChannelCount() || - channels > getMaxChannelCount()) { + channels > getMaxChannelCount()) { std::cerr << "BarBeatTracker::initialise: Unsupported channel count: " << channels << std::endl; return false; @@ -177,7 +252,7 @@ dfConfig.adaptiveWhitening = false; dfConfig.whiteningRelaxCoeff = -1; dfConfig.whiteningFloor = -1; - + m_d = new BarBeatTrackerData(m_inputSampleRate, dfConfig); m_d->downBeat->setBeatsPerBar(m_bpb); return true; @@ -267,10 +342,10 @@ Vamp::RealTime timestamp) { if (!m_d) { - cerr << "ERROR: BarBeatTracker::process: " - << "BarBeatTracker has not been initialised" - << endl; - return FeatureSet(); + cerr << "ERROR: BarBeatTracker::process: " + << "BarBeatTracker has not been initialised" + << endl; + return FeatureSet(); } // We use time domain input, because DownBeat requires it -- so we @@ -311,10 +386,10 @@ BarBeatTracker::getRemainingFeatures() { if (!m_d) { - cerr << "ERROR: BarBeatTracker::getRemainingFeatures: " - << "BarBeatTracker has not been initialised" - << endl; - return FeatureSet(); + cerr << "ERROR: BarBeatTracker::getRemainingFeatures: " + << "BarBeatTracker has not been initialised" + << endl; + return FeatureSet(); } return barBeatTrack(); @@ -334,10 +409,18 @@ if (df.empty()) return FeatureSet(); TempoTrackV2 tt(m_inputSampleRate, m_d->dfConfig.stepSize); - tt.calculateBeatPeriod(df, beatPeriod, tempi); + + // changes are as per the BeatTrack.cpp - allow m_inputtempo and m_constraintempo to be set be the user + tt.calculateBeatPeriod(df, beatPeriod, tempi, m_inputtempo, m_constraintempo); vector<double> beats; - tt.calculateBeats(df, beatPeriod, beats); + // changes are as per the BeatTrack.cpp - allow m_alpha and m_tightness to be set be the user + tt.calculateBeats(df, beatPeriod, beats, m_alpha, m_tightness); + + // tt.calculateBeatPeriod(df, beatPeriod, tempi, 0., 0); // use default parameters + + // vector<double> beats; + // tt.calculateBeats(df, beatPeriod, beats, 0.9, 4.); // use default parameters until i fix this plugin too vector<int> downbeats; size_t downLength = 0; @@ -349,7 +432,7 @@ // std::cerr << "BarBeatTracker: found downbeats at: "; // for (int i = 0; i < downbeats.size(); ++i) std::cerr << downbeats[i] << " " << std::endl; - + FeatureSet returnFeatures; char label[20]; @@ -368,7 +451,7 @@ for (size_t i = 0; i < beats.size(); ++i) { - size_t frame = beats[i] * m_d->dfConfig.stepSize; + size_t frame = beats[i] * m_d->dfConfig.stepSize; if (dbi < downbeats.size() && i == downbeats[dbi]) { beat = 0; @@ -383,15 +466,15 @@ // 0 -> beats // 1 -> bars // 2 -> beat counter function - - Feature feature; - feature.hasTimestamp = true; - feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime - (frame, lrintf(m_inputSampleRate)); + + Feature feature; + feature.hasTimestamp = true; + feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime + (frame, lrintf(m_inputSampleRate)); sprintf(label, "%d", beat + 1); feature.label = label; - returnFeatures[0].push_back(feature); // labelled beats + returnFeatures[0].push_back(feature); // labelled beats feature.values.push_back(beat + 1); returnFeatures[2].push_back(feature); // beat function