Chris@26
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@26
|
2
|
Chris@26
|
3 /*
|
Chris@26
|
4 Vamp feature extraction plugin using the MATCH audio alignment
|
Chris@26
|
5 algorithm.
|
Chris@26
|
6
|
Chris@26
|
7 Centre for Digital Music, Queen Mary, University of London.
|
Chris@26
|
8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
|
Chris@26
|
9
|
Chris@26
|
10 This program is free software; you can redistribute it and/or
|
Chris@26
|
11 modify it under the terms of the GNU General Public License as
|
Chris@26
|
12 published by the Free Software Foundation; either version 2 of the
|
Chris@26
|
13 License, or (at your option) any later version. See the file
|
Chris@26
|
14 COPYING included with this distribution for more information.
|
Chris@26
|
15 */
|
Chris@26
|
16
|
Chris@26
|
17 #ifndef DISTANCE_METRIC_H
|
Chris@26
|
18 #define DISTANCE_METRIC_H
|
Chris@26
|
19
|
Chris@26
|
20 #include <vector>
|
Chris@26
|
21
|
Chris@26
|
22 class DistanceMetric
|
Chris@26
|
23 {
|
Chris@26
|
24 public:
|
Chris@26
|
25 enum DistanceNormalisation {
|
Chris@26
|
26
|
Chris@26
|
27 /** Do not normalise distance metrics */
|
Chris@26
|
28 NoDistanceNormalisation,
|
Chris@26
|
29
|
Chris@26
|
30 /** Normalise distance metric for pairs of frames by the sum
|
Chris@26
|
31 * of the two frames. */
|
Chris@26
|
32 NormaliseDistanceToSum,
|
Chris@26
|
33
|
Chris@26
|
34 /** Normalise distance metric for pairs of frames by the log
|
Chris@26
|
35 * of the sum of the frames. */
|
Chris@26
|
36 NormaliseDistanceToLogSum,
|
Chris@26
|
37 };
|
Chris@26
|
38
|
Chris@26
|
39 DistanceMetric(DistanceNormalisation norm) : m_norm(norm) { }
|
Chris@26
|
40
|
Chris@26
|
41 /** Calculates the Manhattan distance between two vectors, with an
|
Chris@26
|
42 * optional normalisation by the combined values in the
|
Chris@26
|
43 * vectors. Since the vectors contain energy, this could be
|
Chris@26
|
44 * considered as a squared Euclidean distance metric. Note that
|
Chris@26
|
45 * normalisation assumes the values are all non-negative.
|
Chris@26
|
46 *
|
Chris@26
|
47 * @param f1 one of the vectors involved in the distance calculation
|
Chris@26
|
48 * @param f2 one of the vectors involved in the distance calculation
|
Chris@26
|
49 * @return the distance
|
Chris@26
|
50 */
|
Chris@26
|
51 double calcDistance(const std::vector<double> &f1,
|
Chris@26
|
52 const std::vector<double> &f2);
|
Chris@26
|
53
|
Chris@26
|
54 private:
|
Chris@26
|
55 DistanceNormalisation m_norm;
|
Chris@26
|
56 };
|
Chris@26
|
57
|
Chris@26
|
58 #endif
|