Mercurial > hg > svapp
comparison align/TransformDTWAligner.h @ 778:83a7b10b7415
Merge from branch pitch-align
author | Chris Cannam |
---|---|
date | Fri, 26 Jun 2020 13:48:52 +0100 |
parents | 1d6cca5a5621 |
children | b651dc5ff555 |
comparison
equal
deleted
inserted
replaced
774:7bded7599874 | 778:83a7b10b7415 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef SV_TRANSFORM_DTW_ALIGNER_H | |
16 #define SV_TRANSFORM_DTW_ALIGNER_H | |
17 | |
18 #include "Aligner.h" | |
19 #include "DTW.h" | |
20 | |
21 #include "transform/Transform.h" | |
22 #include "svcore/data/model/Path.h" | |
23 | |
24 #include <functional> | |
25 | |
26 #include <QMutex> | |
27 | |
28 class AlignmentModel; | |
29 class Document; | |
30 | |
31 class TransformDTWAligner : public Aligner | |
32 { | |
33 Q_OBJECT | |
34 | |
35 public: | |
36 enum DTWType { | |
37 Magnitude, | |
38 RiseFall | |
39 }; | |
40 | |
41 /** | |
42 * Create a TransformDTWAligner that runs the given transform on | |
43 * both models and feeds the resulting values into the given DTW | |
44 * type. If DTWType is Magnitude, the transform output values are | |
45 * used unmodified; if RiseFall, the deltas between consecutive | |
46 * values are used. | |
47 */ | |
48 TransformDTWAligner(Document *doc, | |
49 ModelId reference, | |
50 ModelId toAlign, | |
51 Transform transform, | |
52 DTWType dtwType); | |
53 | |
54 typedef std::function<double(double)> MagnitudePreprocessor; | |
55 | |
56 /** | |
57 * Create a TransformDTWAligner that runs the given transform on | |
58 * both models, applies the supplied output preprocessor, and | |
59 * feeds the resulting values into a Magnitude DTW type. | |
60 */ | |
61 TransformDTWAligner(Document *doc, | |
62 ModelId reference, | |
63 ModelId toAlign, | |
64 Transform transform, | |
65 MagnitudePreprocessor outputPreprocessor); | |
66 | |
67 typedef std::function<RiseFallDTW::Value(double prev, double curr)> | |
68 RiseFallPreprocessor; | |
69 | |
70 /** | |
71 * Create a TransformDTWAligner that runs the given transform on | |
72 * both models, applies the supplied output preprocessor, and | |
73 * feeds the resulting values into a RiseFall DTW type. | |
74 */ | |
75 TransformDTWAligner(Document *doc, | |
76 ModelId reference, | |
77 ModelId toAlign, | |
78 Transform transform, | |
79 RiseFallPreprocessor outputPreprocessor); | |
80 | |
81 // Destroy the aligner, cleanly cancelling any ongoing alignment | |
82 ~TransformDTWAligner(); | |
83 | |
84 void begin() override; | |
85 | |
86 static bool isAvailable(); | |
87 | |
88 private slots: | |
89 void completionChanged(ModelId); | |
90 | |
91 private: | |
92 bool performAlignment(); | |
93 bool performAlignmentMagnitude(); | |
94 bool performAlignmentRiseFall(); | |
95 | |
96 bool getValuesFrom(ModelId modelId, | |
97 std::vector<sv_frame_t> &frames, | |
98 std::vector<double> &values, | |
99 sv_frame_t &resolution); | |
100 | |
101 Path makePath(const std::vector<size_t> &alignment, | |
102 const std::vector<sv_frame_t> &refFrames, | |
103 const std::vector<sv_frame_t> &otherFrames, | |
104 sv_samplerate_t sampleRate, | |
105 sv_frame_t resolution); | |
106 | |
107 Document *m_document; | |
108 ModelId m_reference; | |
109 ModelId m_toAlign; | |
110 ModelId m_referenceOutputModel; | |
111 ModelId m_toAlignOutputModel; | |
112 ModelId m_alignmentModel; | |
113 Transform m_transform; | |
114 DTWType m_dtwType; | |
115 bool m_incomplete; | |
116 MagnitudePreprocessor m_magnitudePreprocessor; | |
117 RiseFallPreprocessor m_riseFallPreprocessor; | |
118 | |
119 static QMutex m_dtwMutex; | |
120 }; | |
121 | |
122 #endif |