Files
oak-editor/app/widget/timelinewidget/timelinewidgetwaveformsync.h
T
Mike-Solar caafac4203 sync: masked waveform correlation, stretch sync, manual start time
- Waveform sync no longer treats uncached waveform regions as silence:
  the envelope extraction now reports a per-window validity mask and the
  correlation skips invalid windows on either side, improving accuracy
  for partially cached clips
- Add stretch/speed sync: AudioWaveformSync::EstimateStretchAndOffset
  searches a playback-rate range plus offset, and a new timeline
  context action 'Synchronize by Waveform (Adjust Speed)' applies the
  estimated rate as a clip speed change (with undo) when plain offset
  alignment is inconclusive
- Footage properties dialog gains a Source Start Time field so the
  value used by source-time sync can be viewed and edited manually
  instead of relying solely on auto-detected metadata; applied via an
  undo command, with Footage::ClearSourceStartTime() for removal
- Regression tests for masked correlation, stretch estimation, the
  envelope validity mask, and source-start-time set/clear
2026-07-16 23:09:12 +08:00

89 lines
2.7 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef TIMELINEWIDGETWAVEFORMSYNC_H
#define TIMELINEWIDGETWAVEFORMSYNC_H
#include <QVector>
#include "node/block/block.h"
#include "olive/core/util/rational.h"
#include "olive/core/util/timerange.h"
namespace olive
{
class AudioWaveformCache;
class ClipBlock;
/**
* @brief Data required to synchronize a clip using its cached audio waveform.
*/
struct WaveformSyncClip {
ClipBlock *clip = nullptr;
const AudioWaveformCache *waveform = nullptr;
TimeRange media_range;
int sample_rate = 0;
};
/**
* @brief Helpers used by TimelineWidget for waveform-based clip synchronization.
*
* Kept in a separate unit so they can be exercised directly by unit tests.
*/
namespace TimelineWaveformSync
{
/**
* @brief Fill @p out with waveform-sync metadata for @p block if it is usable.
*
* A clip is considered usable as long as at least a portion of its media range
* has been validated in the waveform cache. Previously the whole range had to
* be validated, which made the context-menu action unavailable for long clips.
*/
bool GetWaveformSyncClip(Block *block, WaveformSyncClip *out);
/**
* @brief Return all selected blocks that can be synchronized by waveform.
*/
QVector<WaveformSyncClip>
GetSelectedWaveformSyncClips(const QVector<Block *> &blocks);
/**
* @brief Extract a peak envelope from the validated regions of a waveform cache.
*
* Windows that have not been cached yet are filled with zero so that every
* envelope stays aligned to the same absolute timeline; when @p valid_mask is
* provided it receives one flag per window marking whether the window was
* actually cached, allowing the correlation to skip uncached regions instead
* of treating them as silence.
*/
QVector<double> ExtractWaveformCacheEnvelope(const WaveformSyncClip &clip,
int sample_rate,
size_t window_samples,
QVector<bool> *valid_mask = nullptr);
} // namespace TimelineWaveformSync
} // namespace olive
#endif // TIMELINEWIDGETWAVEFORMSYNC_H