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