117{
118 const auto filenameStem = "FifeAndDrumsStereo"s;
119 const auto inputPath =
120 std::string(CMAKE_SOURCE_DIR) + "/tests/samples/" + filenameStem + ".wav";
121
122 std::optional<std::string> outputDir;
123
124
125 const auto backwards = GENERATE(false, true);
126
127 SECTION("with one clip")
128 {
129 const auto ratio = GENERATE(0.75, 1.5);
130 std::vector<std::vector<float>> input;
131 AudioFileInfo info;
132 REQUIRE(WavFileIO::Read(inputPath, input, info, 7s));
133 const auto clip =
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);
138 const auto sut =
140 const size_t numOutputSamples = clip->stretchRatio * input[0].size() + .5;
142 sut->GetFloats(
143 container.channelPointers.data(), backwards ? numOutputSamples : 0,
144 numOutputSamples, backwards);
145 if (outputDir)
146 {
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(
152 outputPath, container.channelVectors, info.sampleRate));
153 }
154 }
155
156 SECTION("with several clips")
157 {
158 std::vector<std::vector<float>> input;
159 AudioFileInfo info;
160 REQUIRE(WavFileIO::Read(inputPath, input, info, 7s));
161 const auto clip1 =
162 std::make_shared<FloatVectorClip>(info.sampleRate, input);
163 const auto clip2 =
164 std::make_shared<FloatVectorClip>(info.sampleRate, input);
165 clip1->stretchRatio = 0.75;
166 clip2->stretchRatio = 1.5;
167
168
169 clip1->playStartTime = 1.;
170 clip2->playStartTime = clip1->GetPlayEndTime() + 2.;
171 const auto totalDuration = clip2->GetPlayEndTime();
172
173 const auto mockSequence =
174 std::make_shared<MockPlayableSequence>(info.sampleRate, 2u);
177 const size_t numOutputSamples =
178 totalDuration * info.sampleRate
179 + .5;
181 const auto start = backwards ? numOutputSamples : 0u;
182 sut->GetFloats(
183 container.channelPointers.data(), start, numOutputSamples, backwards);
184 if (outputDir)
185 {
186 const auto filename = "manyClips_"s + filenameStem +
187 (backwards ? "_bwd" : "_fwd") + ".wav";
188 const auto outputPath = *outputDir + "/" + filename;
189 REQUIRE(WavFileIO::Write(
190 outputPath, container.channelVectors, info.sampleRate));
191 }
192 }
193}