Chris@105: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@105: /* Chris@105: Vamp feature extraction plugin using the MATCH audio alignment Chris@105: algorithm. Chris@105: Chris@105: Centre for Digital Music, Queen Mary, University of London. Chris@236: Copyright (c) 2007-2020 Simon Dixon, Chris Cannam, and Queen Mary Chris@230: University of London, Copyright (c) 2014-2015 Tido GmbH. Chris@105: Chris@105: This program is free software; you can redistribute it and/or Chris@105: modify it under the terms of the GNU General Public License as Chris@105: published by the Free Software Foundation; either version 2 of the Chris@105: License, or (at your option) any later version. See the file Chris@105: COPYING included with this distribution for more information. Chris@105: */ Chris@105: Chris@105: #ifndef MATCH_PIPELINE_H Chris@105: #define MATCH_PIPELINE_H Chris@105: Chris@105: #include "Matcher.h" Chris@105: #include "Finder.h" Chris@105: #include "FeatureExtractor.h" Chris@105: #include "FeatureConditioner.h" Chris@105: #include "MatchFeatureFeeder.h" Chris@105: Chris@105: class MatchPipeline Chris@105: { Chris@105: public: Chris@105: /** Chris@105: * Pipeline consisting of two Matchers, two FeatureConditioners, Chris@105: * two FeatureExtractors, and a Finder. Features may be inserted Chris@105: * at any point in the pipeline. Chris@105: * Chris@105: * The pipeline goes: Chris@105: * Frequency-domain audio Chris@105: * -> Features Chris@105: * -> Conditioned features Chris@105: * -> Matcher Chris@160: * Chris@160: * Only one set of FeatureExtractor::Parameters is provided; this Chris@160: * contains a single reference frequency, but it's possible the Chris@160: * two input streams may have different tuning frequencies. A Chris@160: * separate frequency for the second input can be provided here as Chris@160: * an optional parameter if needed. Chris@105: */ Chris@105: MatchPipeline(FeatureExtractor::Parameters feParams, Chris@105: FeatureConditioner::Parameters fcParams, Chris@143: DistanceMetric::Parameters dParams, Chris@160: Matcher::Parameters matchParams, Chris@160: double secondReferenceFrequency = 0.0); Chris@105: Chris@105: ~MatchPipeline(); Chris@105: Chris@105: /** Chris@105: * Feed in data at the first pipeline stage. The input arrays Chris@105: * represent frames of audio from the two different sources. Each Chris@105: * is provided as a single array of alternating real and imaginary Chris@105: * components. Chris@105: * Chris@105: * Input arrays must have at least 2 * (feParams.fftSize/2 + 1) Chris@105: * elements. The arrays will be passed to FeatureExtractor and Chris@105: * then on into the rest of the pipeline. Chris@105: */ Chris@105: void feedFrequencyDomainAudio(const float *arr1, const float *arr2); Chris@105: Chris@105: /** Chris@105: * Feed in data at the second pipeline stage. The vectors Chris@105: * represent feature frames from two different sources. They will Chris@105: * be passed in to FeatureConditioner and then on to the rest of Chris@105: * the pipeline. Chris@105: */ Chris@183: void feedFeatures(const feature_t &f1, const feature_t &f2); Chris@106: Chris@105: /** Chris@105: * Feed in data at the third pipeline stage. The vectors represent Chris@105: * conditioned feature frames from two different sources. They Chris@105: * will be passed to MatchFeatureFeeder for feeding to the two Chris@105: * matchers. Chris@105: */ Chris@183: void feedConditionedFeatures(const feature_t &f1, const feature_t &f2); Chris@105: Chris@105: /** Chris@106: * If a frame was just fed in at the first or second pipeline Chris@106: * stage, it can be retrieved from the second stage here. That is, Chris@106: * if you provided frequency-domain audio, extractFeatures will Chris@106: * give you back the FeatureExtractor's features. Chris@106: */ Chris@183: void extractFeatures(feature_t &f1, feature_t &f2); Chris@106: Chris@106: /** Chris@106: * Retrieve the conditioned features from the third pipeline stage. Chris@106: */ Chris@183: void extractConditionedFeatures(feature_t &f1, feature_t &f2); Chris@106: Chris@106: /** Chris@105: * Indicate that both inputs have come to an end. Chris@105: */ Chris@105: void finish(); Chris@105: Chris@155: /** Chris@155: * Retrieve the final path. Only valid once all the features have Chris@155: * been supplied and finish() has been called. Chris@155: * Chris@155: * See Finder::retrievePath for more details. Chris@155: */ Chris@155: int retrievePath(bool smooth, std::vector &pathx, std::vector &pathy); Chris@155: Chris@155: /** Chris@155: * Retrieve the forward path resulting from the online search. Chris@155: * Chris@155: * See MatchFeatureFeeder::retrieveForwardPath for more details. Chris@155: */ Chris@155: void retrieveForwardPath(std::vector &pathx, std::vector &pathy); Chris@173: Chris@173: /** Chris@173: * Get the path cost for the overall path to the end of both Chris@173: * sources. Chris@173: * Chris@173: * See Finder::getOverallCost for more details. Chris@173: */ Chris@173: double getOverallCost(); Chris@173: Chris@237: /** Chris@237: * Return true if the feature's level is above a low threshold, Chris@237: * intended to determine when either of the input streams has Chris@237: * ended (the last frame for a stream is considered to be the last Chris@237: * one that was above the threshold). This is different from the Chris@237: * silence threshold in FeatureConditioner. Chris@237: * Chris@237: * Users of this class do not normally need to call this function Chris@237: * explicitly: it's used internally when processing the Chris@237: * streams. It is exposed here in case other code wants to perform Chris@237: * a similar test in a consistent way. Chris@237: */ Chris@237: static bool isAboveEndingThreshold(const feature_t &f); Chris@237: Chris@105: private: Chris@105: FeatureExtractor m_fe1; Chris@105: FeatureExtractor m_fe2; Chris@105: FeatureConditioner m_fc1; Chris@105: FeatureConditioner m_fc2; Chris@105: Matcher m_pm1; Chris@105: Matcher m_pm2; Chris@105: MatchFeatureFeeder m_feeder; Chris@105: int m_lastFrameIn1; Chris@105: int m_lastFrameIn2; Chris@105: int m_frameNo; Chris@183: feature_t m_f1; Chris@183: feature_t m_f2; Chris@183: feature_t m_c1; Chris@183: feature_t m_c2; Chris@183: bool aboveThreshold(const feature_t &f); Chris@166: FeatureExtractor::Parameters paramsWithFreq(FeatureExtractor::Parameters, Chris@166: double); Chris@105: }; Chris@105: Chris@105: #endif