annotate align/TransformDTWAligner.h @ 781:b651dc5ff555

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