Mercurial > hg > svapp
comparison align/TransformDTWAligner.h @ 771:1d6cca5a5621 pitch-align
Allow use of proper sparse models (i.e. retaining event time info) in alignment; use this to switch to note alignment, which is what we have most recently been doing in the external program. Not currently producing correct results, though
author | Chris Cannam |
---|---|
date | Fri, 29 May 2020 17:39:02 +0100 |
parents | 1b1960009be6 |
children | b651dc5ff555 |
comparison
equal
deleted
inserted
replaced
770:486add472c3f | 771:1d6cca5a5621 |
---|---|
14 | 14 |
15 #ifndef SV_TRANSFORM_DTW_ALIGNER_H | 15 #ifndef SV_TRANSFORM_DTW_ALIGNER_H |
16 #define SV_TRANSFORM_DTW_ALIGNER_H | 16 #define SV_TRANSFORM_DTW_ALIGNER_H |
17 | 17 |
18 #include "Aligner.h" | 18 #include "Aligner.h" |
19 #include "DTW.h" | |
19 | 20 |
20 #include "transform/Transform.h" | 21 #include "transform/Transform.h" |
22 #include "svcore/data/model/Path.h" | |
21 | 23 |
22 #include <functional> | 24 #include <functional> |
25 | |
26 #include <QMutex> | |
23 | 27 |
24 class AlignmentModel; | 28 class AlignmentModel; |
25 class Document; | 29 class Document; |
26 | 30 |
27 class TransformDTWAligner : public Aligner | 31 class TransformDTWAligner : public Aligner |
31 public: | 35 public: |
32 enum DTWType { | 36 enum DTWType { |
33 Magnitude, | 37 Magnitude, |
34 RiseFall | 38 RiseFall |
35 }; | 39 }; |
36 | 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 */ | |
37 TransformDTWAligner(Document *doc, | 48 TransformDTWAligner(Document *doc, |
38 ModelId reference, | 49 ModelId reference, |
39 ModelId toAlign, | 50 ModelId toAlign, |
40 Transform transform, | 51 Transform transform, |
41 DTWType dtwType); | 52 DTWType dtwType); |
42 | 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 */ | |
43 TransformDTWAligner(Document *doc, | 61 TransformDTWAligner(Document *doc, |
44 ModelId reference, | 62 ModelId reference, |
45 ModelId toAlign, | 63 ModelId toAlign, |
46 Transform transform, | 64 Transform transform, |
47 DTWType dtwType, | 65 MagnitudePreprocessor outputPreprocessor); |
48 std::function<double(double)> 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); | |
49 | 80 |
50 // Destroy the aligner, cleanly cancelling any ongoing alignment | 81 // Destroy the aligner, cleanly cancelling any ongoing alignment |
51 ~TransformDTWAligner(); | 82 ~TransformDTWAligner(); |
52 | 83 |
53 void begin() override; | 84 void begin() override; |
59 | 90 |
60 private: | 91 private: |
61 bool performAlignment(); | 92 bool performAlignment(); |
62 bool performAlignmentMagnitude(); | 93 bool performAlignmentMagnitude(); |
63 bool performAlignmentRiseFall(); | 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); | |
64 | 106 |
65 Document *m_document; | 107 Document *m_document; |
66 ModelId m_reference; | 108 ModelId m_reference; |
67 ModelId m_toAlign; | 109 ModelId m_toAlign; |
68 ModelId m_referenceOutputModel; | 110 ModelId m_referenceOutputModel; |
69 ModelId m_toAlignOutputModel; | 111 ModelId m_toAlignOutputModel; |
70 ModelId m_alignmentModel; | 112 ModelId m_alignmentModel; |
71 Transform m_transform; | 113 Transform m_transform; |
72 DTWType m_dtwType; | 114 DTWType m_dtwType; |
73 bool m_incomplete; | 115 bool m_incomplete; |
74 std::function<double(double)> m_outputPreprocessor; | 116 MagnitudePreprocessor m_magnitudePreprocessor; |
117 RiseFallPreprocessor m_riseFallPreprocessor; | |
118 | |
119 static QMutex m_dtwMutex; | |
75 }; | 120 }; |
76 | 121 |
77 #endif | 122 #endif |