21#include <catch2/catch.hpp>
23using namespace std::literals::string_literals;
24using namespace std::literals::chrono_literals;
35 constexpr auto backwards =
true;
36 constexpr auto numChannels = 1u;
38 SECTION(
"Samples can be queried backwards")
43 const auto clip1 = std::make_shared<FloatVectorClip>(
44 sampleRate, std::vector<float> { 1.f, 2.f, 3.f }, numChannels);
45 const auto clip3 = std::make_shared<FloatVectorClip>(
46 sampleRate, std::vector<float> { 4.f, 5.f, 6.f }, numChannels);
47 clip1->playStartTime = 1.0;
48 clip3->playStartTime = 3.0;
49 const auto mockSequence =
50 std::make_shared<MockPlayableSequence>(
sampleRate, numChannels);
54 constexpr auto len = 2;
55 const std::array<std::vector<float>, 6> expected { { { 6.f, 5.f },
62 for (
const auto& expected : expected)
65 constexpr auto backwards =
true;
74 SECTION(
"reconstructs segment sequence when expected")
77 const auto mockSequence =
78 std::make_shared<MockPlayableSequence>(
sampleRate, numChannels);
81 std::unique_ptr<AudioSegmentFactoryInterface> {
factory });
82 constexpr auto numSamples = 3;
83 constexpr auto numChannels = 1;
84 constexpr auto start = 10;
86 REQUIRE(sut.GetFloats(
90 const auto refCount =
factory->callCount;
92 REQUIRE(sut.GetFloats(
94 numSamples, !backwards));
95 REQUIRE(
factory->callCount == refCount);
97 REQUIRE(sut.GetFloats(
99 numSamples, !backwards));
100 REQUIRE(
factory->callCount == refCount + 1);
102 REQUIRE(sut.GetFloats(
104 start + numSamples * 2, numSamples, backwards));
105 REQUIRE(
factory->callCount == refCount + 2);
108 REQUIRE(sut.GetFloats(
110 numSamples, backwards));
111 REQUIRE(
factory->callCount == refCount + 2);
118 const auto filenameStem =
"FifeAndDrumsStereo"s;
119 const auto inputPath =
120 std::string(CMAKE_SOURCE_DIR) +
"/tests/samples/" + filenameStem +
".wav";
122 std::optional<std::string> outputDir;
125 const auto backwards = GENERATE(
false,
true);
127 SECTION(
"with one clip")
129 const auto ratio = GENERATE(0.75, 1.5);
130 std::vector<std::vector<float>> input;
132 REQUIRE(WavFileIO::Read(inputPath, input, info, 7s));
134 std::make_shared<FloatVectorClip>(info.sampleRate, input);
135 clip->stretchRatio = ratio;
136 const auto mockSequence = std::make_shared<MockPlayableSequence>(
137 info.sampleRate, info.numChannels);
140 const size_t numOutputSamples = clip->stretchRatio * input[0].size() + .5;
144 numOutputSamples, backwards);
147 const auto filename =
"oneclip_"s + filenameStem +
148 (backwards ?
"_bwd" :
"_fwd") +
149 (ratio < 1. ?
"_fast" :
"_slow") +
".wav";
150 const auto outputPath = *outputDir +
"/" + filename;
151 REQUIRE(WavFileIO::Write(
156 SECTION(
"with several clips")
158 std::vector<std::vector<float>> input;
160 REQUIRE(WavFileIO::Read(inputPath, input, info, 7s));
162 std::make_shared<FloatVectorClip>(info.sampleRate, input);
164 std::make_shared<FloatVectorClip>(info.sampleRate, input);
165 clip1->stretchRatio = 0.75;
166 clip2->stretchRatio = 1.5;
169 clip1->playStartTime = 1.;
170 clip2->playStartTime = clip1->GetPlayEndTime() + 2.;
171 const auto totalDuration = clip2->GetPlayEndTime();
173 const auto mockSequence =
174 std::make_shared<MockPlayableSequence>(info.sampleRate, 2u);
177 const size_t numOutputSamples =
178 totalDuration * info.sampleRate
181 const auto start = backwards ? numOutputSamples : 0u;
186 const auto filename =
"manyClips_"s + filenameStem +
187 (backwards ?
"_bwd" :
"_fwd") +
".wav";
188 const auto outputPath = *outputDir +
"/" + filename;
189 REQUIRE(WavFileIO::Write(
std::vector< std::shared_ptr< const ClipInterface > > ClipConstHolders
TEST_CASE("StretchingSequence unit tests")
static std::vector< T * > GetData(const AudioContainer &container, size_t offset=0u)
static std::shared_ptr< StretchingSequence > Create(const PlayableSequence &, const ClipConstHolders &clips)
constexpr auto sampleRate
std::vector< float * > channelPointers
std::vector< std::vector< float > > channelVectors