annotate align/TransformDTWAligner.h @ 780:8fa98f89eda8

Add subsequence DTW (not yet in use)
author Chris Cannam
date Wed, 01 Jul 2020 15:34:46 +0100
parents 1d6cca5a5621
children b651dc5ff555
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@767 51 Transform transform,
Chris@767 52 DTWType dtwType);
Chris@771 53
Chris@771 54 typedef std::function<double(double)> MagnitudePreprocessor;
Chris@771 55
Chris@771 56 /**
Chris@771 57 * Create a TransformDTWAligner that runs the given transform on
Chris@771 58 * both models, applies the supplied output preprocessor, and
Chris@771 59 * feeds the resulting values into a Magnitude DTW type.
Chris@771 60 */
Chris@768 61 TransformDTWAligner(Document *doc,
Chris@768 62 ModelId reference,
Chris@768 63 ModelId toAlign,
Chris@768 64 Transform transform,
Chris@771 65 MagnitudePreprocessor outputPreprocessor);
Chris@771 66
Chris@771 67 typedef std::function<RiseFallDTW::Value(double prev, double curr)>
Chris@771 68 RiseFallPreprocessor;
Chris@771 69
Chris@771 70 /**
Chris@771 71 * Create a TransformDTWAligner that runs the given transform on
Chris@771 72 * both models, applies the supplied output preprocessor, and
Chris@771 73 * feeds the resulting values into a RiseFall DTW type.
Chris@771 74 */
Chris@771 75 TransformDTWAligner(Document *doc,
Chris@771 76 ModelId reference,
Chris@771 77 ModelId toAlign,
Chris@771 78 Transform transform,
Chris@771 79 RiseFallPreprocessor outputPreprocessor);
Chris@767 80
Chris@767 81 // Destroy the aligner, cleanly cancelling any ongoing alignment
Chris@767 82 ~TransformDTWAligner();
Chris@767 83
Chris@767 84 void begin() override;
Chris@767 85
Chris@767 86 static bool isAvailable();
Chris@767 87
Chris@767 88 private slots:
Chris@767 89 void completionChanged(ModelId);
Chris@767 90
Chris@767 91 private:
Chris@767 92 bool performAlignment();
Chris@767 93 bool performAlignmentMagnitude();
Chris@767 94 bool performAlignmentRiseFall();
Chris@771 95
Chris@771 96 bool getValuesFrom(ModelId modelId,
Chris@771 97 std::vector<sv_frame_t> &frames,
Chris@771 98 std::vector<double> &values,
Chris@771 99 sv_frame_t &resolution);
Chris@771 100
Chris@771 101 Path makePath(const std::vector<size_t> &alignment,
Chris@771 102 const std::vector<sv_frame_t> &refFrames,
Chris@771 103 const std::vector<sv_frame_t> &otherFrames,
Chris@771 104 sv_samplerate_t sampleRate,
Chris@771 105 sv_frame_t resolution);
Chris@767 106
Chris@767 107 Document *m_document;
Chris@767 108 ModelId m_reference;
Chris@767 109 ModelId m_toAlign;
Chris@767 110 ModelId m_referenceOutputModel;
Chris@767 111 ModelId m_toAlignOutputModel;
Chris@767 112 ModelId m_alignmentModel;
Chris@767 113 Transform m_transform;
Chris@767 114 DTWType m_dtwType;
Chris@767 115 bool m_incomplete;
Chris@771 116 MagnitudePreprocessor m_magnitudePreprocessor;
Chris@771 117 RiseFallPreprocessor m_riseFallPreprocessor;
Chris@771 118
Chris@771 119 static QMutex m_dtwMutex;
Chris@767 120 };
Chris@767 121
Chris@767 122 #endif