# HG changeset patch # User Chris Cannam # Date 1417700123 0 # Node ID 3f46ce2d287453e4eb878e9488f40ffe8e440f3b # Parent 6636aca831c082e99c3fc20d1a9b69f04d711e9a Start MatchPipeline diff -r 6636aca831c0 -r 3f46ce2d2874 src/MatchPipeline.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MatchPipeline.cpp Thu Dec 04 13:35:23 2014 +0000 @@ -0,0 +1,88 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ +/* + Vamp feature extraction plugin using the MATCH audio alignment + algorithm. + + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "MatchPipeline.h" + +MatchPipeline::MatchPipeline(FeatureExtractor::Parameters feParams, + FeatureConditioner::Parameters fcParams, + Matcher::Parameters matchParams) : + m_fe1(feParams), + m_fe2(feParams), + m_fc1(fcParams), + m_fc2(fcParams), + m_pm1(matchParams, 0), + m_pm2(matchParams, &m_pm1), + m_feeder(&m_pm1, &m_pm2), + m_lastFrameIn1(0), + m_lastFrameIn2(0), + m_frameNo(0) +{ + m_pm1.setOtherMatcher(&m_pm2); +} + +MatchPipeline::~MatchPipeline() +{ +} + +void +MatchPipeline::feedFrequencyDomainAudio(const float *arr1, const float *arr2) +{ + feedFeatures(m_fe1.process(arr1), m_fe2.process(arr2)); +} + +void +MatchPipeline::feedFeatures(const vector &f1, const vector &f2) +{ + feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2)); +} + +void +MatchPipeline::feedConditionedFeatures(const vector &f1, const vector &f2) +{ + m_feeder.feed(f1, f2); + + if (aboveThreshold(f1)) m_lastFrameIn1 = m_frameNo; + if (aboveThreshold(f2)) m_lastFrameIn2 = m_frameNo; + + ++m_frameNo; +} + +bool +MatchPipeline::aboveThreshold(const vector &f) +{ + double threshold = 1e-4f; + double sum = 0.f; + for (int i = 0; i < int(f.size()); ++i) { + sum += f[i] * f[i]; + } + return (sum >= threshold); +} + +void +MatchPipeline::finish() +{ + m_feeder.finish(); + getFinder()->setDurations(m_lastFrameIn1, m_lastFrameIn2); +} + +Finder * +MatchPipeline::getFinder() +{ + return m_feeder.getFinder(); +} + + + + diff -r 6636aca831c0 -r 3f46ce2d2874 src/MatchPipeline.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MatchPipeline.h Thu Dec 04 13:35:23 2014 +0000 @@ -0,0 +1,94 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ +/* + Vamp feature extraction plugin using the MATCH audio alignment + algorithm. + + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef MATCH_PIPELINE_H +#define MATCH_PIPELINE_H + +#include "Matcher.h" +#include "Finder.h" +#include "FeatureExtractor.h" +#include "FeatureConditioner.h" +#include "MatchFeatureFeeder.h" + +class MatchPipeline +{ +public: + /** + * Pipeline consisting of two Matchers, two FeatureConditioners, + * two FeatureExtractors, and a Finder. Features may be inserted + * at any point in the pipeline. + * + * The pipeline goes: + * Frequency-domain audio + * -> Features + * -> Conditioned features + * -> Matcher + */ + MatchPipeline(FeatureExtractor::Parameters feParams, + FeatureConditioner::Parameters fcParams, + Matcher::Parameters matchParams); + + ~MatchPipeline(); + + /** + * Feed in data at the first pipeline stage. The input arrays + * represent frames of audio from the two different sources. Each + * is provided as a single array of alternating real and imaginary + * components. + * + * Input arrays must have at least 2 * (feParams.fftSize/2 + 1) + * elements. The arrays will be passed to FeatureExtractor and + * then on into the rest of the pipeline. + */ + void feedFrequencyDomainAudio(const float *arr1, const float *arr2); + + /** + * Feed in data at the second pipeline stage. The vectors + * represent feature frames from two different sources. They will + * be passed in to FeatureConditioner and then on to the rest of + * the pipeline. + */ + void feedFeatures(const vector &f1, const vector &f2); + + /** + * Feed in data at the third pipeline stage. The vectors represent + * conditioned feature frames from two different sources. They + * will be passed to MatchFeatureFeeder for feeding to the two + * matchers. + */ + void feedConditionedFeatures(const vector &f1, const vector &f2); + + /** + * Indicate that both inputs have come to an end. + */ + void finish(); + + Finder *getFinder(); + +private: + FeatureExtractor m_fe1; + FeatureExtractor m_fe2; + FeatureConditioner m_fc1; + FeatureConditioner m_fc2; + Matcher m_pm1; + Matcher m_pm2; + MatchFeatureFeeder m_feeder; + int m_lastFrameIn1; + int m_lastFrameIn2; + int m_frameNo; + bool aboveThreshold(const vector &f); +}; + +#endif