1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************
Audacity: A Digital Audio Editor
StretchingSequenceIntegrationTest.cpp
Matthieu Hodgkinson
**********************************************************************/
#include "AudioContainerHelper.h"
#include "MockPlayableSequence.h"
#include "MockSampleBlockFactory.h"
#include "SampleFormat.h"
#include "StretchingSequence.h"
#include "TestWaveClipMaker.h"
#include "TestWaveTrackMaker.h"
#include <catch2/catch.hpp>
namespace
{
constexpr auto sampleRate = 3;
constexpr auto iChannel = 0u;
const auto sampleBlockFactory = std::make_shared<MockSampleBlockFactory>();
TestWaveClipMaker clipMaker { sampleRate, sampleBlockFactory };
TestWaveTrackMaker trackMaker { sampleRate, sampleBlockFactory };
} // namespace
TEST_CASE("StretchingSequence integration tests")
{
const auto numChannels =
GENERATE(1 /*, 2*/); // When wide WaveTrack is implemented this test
// should also run in stereo.
const auto mockSequence =
std::make_shared<MockPlayableSequence>(sampleRate, numChannels);
SECTION(
"StretchingSequence and WaveTrack have identical outputs when clips aren't stretched.")
{
constexpr auto totalLength =
sampleRate * 4; // 1s no clip, 1s minusClip, 1s no clip, 1s plusClip
const auto minusClip = clipMaker.ClipFilledWith(
-.5f, sampleRate, numChannels,
[](auto& clip) { clip.SetPlayStartTime(1.0); });
const auto plusClip = clipMaker.ClipFilledWith(
+.5f, sampleRate, numChannels,
[](auto& clip) { clip.SetPlayStartTime(3.0); });
const auto sut = StretchingSequence::Create(
*mockSequence, ClipConstHolders { minusClip, plusClip });
const auto track = trackMaker.Track({ minusClip, plusClip });
constexpr auto backwards = false;
AudioContainer sutOutput(totalLength, numChannels);
REQUIRE(sut->DoGet(
iChannel, numChannels,
AudioContainerHelper::GetData<char>(sutOutput).data(), floatSample, 0u,
totalLength, backwards));
AudioContainer waveTrackOutput(totalLength, numChannels);
REQUIRE(track->DoGet(
iChannel, numChannels,
AudioContainerHelper::GetData<char>(waveTrackOutput).data(),
floatSample, 0u, totalLength, backwards));
const auto outputsAreIdentical =
sutOutput.channelVectors == waveTrackOutput.channelVectors;
REQUIRE(outputsAreIdentical);
}
}
|