File indexing completed on 2024-04-28 04:51:59
0001 /* 0002 SPDX-FileCopyrightText: 2012 Simon Andreas Eugster <simon.eu@gmail.com> 0003 This file is part of kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include "audioCorrelationInfo.h" 0011 #include "audioEnvelope.h" 0012 #include "definitions.h" 0013 #include <QList> 0014 0015 /** 0016 This class does the correlation between two tracks 0017 in order to synchronize (align) them. 0018 0019 It uses one main track (used in the initializer); further tracks will be 0020 aligned relative to this main track. 0021 */ 0022 class AudioCorrelation : public QObject 0023 { 0024 Q_OBJECT 0025 public: 0026 /** 0027 @param mainTrackEnvelope Envelope of the reference track. Its 0028 actual computation will be started in 0029 this constructor 0030 (i.e. mainTrackEnvelope->StartComputeEnvelope() 0031 will be called). The computation of the 0032 envelop must not be started when passed 0033 to this constructor 0034 (i.e. mainTrackEnvelope->HasComputationStarted() 0035 must return false). 0036 */ 0037 explicit AudioCorrelation(std::unique_ptr<AudioEnvelope> mainTrackEnvelope); 0038 ~AudioCorrelation() override; 0039 0040 /** 0041 Adds a child envelope that will be aligned to the reference 0042 envelope. This function returns immediately, the alignment 0043 computation is done asynchronously. When done, the signal 0044 gotAudioAlignData will be emitted. Similarly to the main 0045 envelope, the computation of the envelope must not be started 0046 when it is passed to this object. 0047 0048 This object will take ownership of the passed envelope. 0049 */ 0050 void addChild(AudioEnvelope *envelope); 0051 0052 const AudioCorrelationInfo *info(int childIndex) const; 0053 int getShift(int childIndex) const; 0054 0055 /** 0056 Correlates the two vectors envMain and envSub. 0057 \c correlation must be a pre-allocated vector of size sizeMain+sizeSub+1. 0058 */ 0059 static void correlate(const qint64 *envMain, size_t sizeMain, const qint64 *envSub, size_t sizeSub, qint64 *correlation, qint64 *out_max = nullptr); 0060 0061 private: 0062 std::unique_ptr<AudioEnvelope> m_mainTrackEnvelope; 0063 0064 QList<AudioEnvelope *> m_children; 0065 QList<AudioCorrelationInfo *> m_correlations; 0066 0067 private Q_SLOTS: 0068 /** 0069 This is invoked when the child envelope is computed. This 0070 triggers the actual computations of the cross-correlation for 0071 aligning the envelope to the reference envelope. 0072 0073 Takes ownership of @p envelope. 0074 */ 0075 void slotProcessChild(AudioEnvelope *envelope); 0076 void slotAnnounceEnvelope(); 0077 0078 Q_SIGNALS: 0079 void gotAudioAlignData(int, int); 0080 void displayMessage(const QString &, MessageType, int); 0081 };