Chris@26: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@26: Chris@26: /* Chris@26: Vamp feature extraction plugin using the MATCH audio alignment Chris@26: algorithm. Chris@26: Chris@26: Centre for Digital Music, Queen Mary, University of London. Chris@26: This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. Chris@26: Chris@26: This program is free software; you can redistribute it and/or Chris@26: modify it under the terms of the GNU General Public License as Chris@26: published by the Free Software Foundation; either version 2 of the Chris@26: License, or (at your option) any later version. See the file Chris@26: COPYING included with this distribution for more information. Chris@26: */ Chris@26: Chris@26: #ifndef DISTANCE_METRIC_H Chris@26: #define DISTANCE_METRIC_H Chris@26: Chris@26: #include Chris@26: Chris@26: class DistanceMetric Chris@26: { Chris@26: public: Chris@26: enum DistanceNormalisation { Chris@26: Chris@26: /** Do not normalise distance metrics */ Chris@26: NoDistanceNormalisation, Chris@26: Chris@26: /** Normalise distance metric for pairs of frames by the sum Chris@26: * of the two frames. */ Chris@26: NormaliseDistanceToSum, Chris@26: Chris@26: /** Normalise distance metric for pairs of frames by the log Chris@26: * of the sum of the frames. */ Chris@26: NormaliseDistanceToLogSum, Chris@26: }; Chris@26: Chris@143: struct Parameters { Chris@143: Chris@143: Parameters() : Chris@144: norm(NormaliseDistanceToLogSum) Chris@143: {} Chris@143: Chris@143: /** Normalisation for distance metrics. */ Chris@143: DistanceNormalisation norm; Chris@143: }; Chris@143: Chris@143: DistanceMetric(Parameters params); Chris@26: Chris@26: /** Calculates the Manhattan distance between two vectors, with an Chris@26: * optional normalisation by the combined values in the Chris@26: * vectors. Since the vectors contain energy, this could be Chris@26: * considered as a squared Euclidean distance metric. Note that Chris@26: * normalisation assumes the values are all non-negative. Chris@26: * Chris@26: * @param f1 one of the vectors involved in the distance calculation Chris@26: * @param f2 one of the vectors involved in the distance calculation Chris@26: * @return the distance Chris@26: */ Chris@26: double calcDistance(const std::vector &f1, Chris@26: const std::vector &f2); Chris@26: Chris@26: private: Chris@143: Parameters m_params; Chris@26: }; Chris@26: Chris@26: #endif