13#include "MockedPrefs.h"
18#include <catch2/catch.hpp>
20using namespace std::literals::string_literals;
21using namespace std::literals::chrono_literals;
25 MockedPrefs mockedPrefs;
29 std::pair<std::string, std::optional<std::chrono::seconds>>;
30 const auto [filenameStem, upTo] = GENERATE(
31 TestParameter {
"AudacitySpectral", std::nullopt },
32 TestParameter {
"FifeAndDrumsStereo", 3s });
33 const auto inputPath = std::string(CMAKE_SOURCE_DIR) +
"/tests/samples/" +
34 filenameStem +
".wav";
36 std::optional<std::string> outputDir;
40 std::vector<std::vector<float>> input;
42 REQUIRE(WavFileIO::Read(inputPath, input, info, upTo));
43 for (
const auto pitchRatio : std::vector<std::pair<int, int>> {
50 static_cast<double>(pitchRatio.first) / pitchRatio.second;
51 for (
const auto timeRatio : std::vector<std::pair<int, int>> {
58 static_cast<double>(timeRatio.first) / timeRatio.second;
59 const auto numOutputFrames =
60 static_cast<size_t>(info.numFrames * tr);
67 info.sampleRate, info.numChannels, src, std::move(
params));
68 constexpr size_t blockSize = 1234u;
70 while (offset < numOutputFrames)
72 std::vector<float*> offsetBuffers(info.numChannels);
73 for (
auto i = 0u; i < info.numChannels; ++i)
75 const auto numToRead =
76 std::min(numOutputFrames - offset, blockSize);
77 sut.
GetSamples(offsetBuffers.data(), numToRead);
83 const auto filename = filenameStem +
"_t"s +
84 std::to_string(timeRatio.first) +
"-" +
85 std::to_string(timeRatio.second) +
"_p" +
86 std::to_string(pitchRatio.first) +
"-" +
87 std::to_string(pitchRatio.second) +
".wav";
88 const auto outputPath = *outputDir +
"/" + filename;
89 REQUIRE(WavFileIO::Write(
96 SECTION(
"Not specifying time or pitch or ratio yields bit-exact results")
102 const auto inputPath =
103 std::string(CMAKE_SOURCE_DIR) +
"/tests/samples/AudacitySpectral.wav";
104 std::vector<std::vector<float>> input;
106 REQUIRE(WavFileIO::Read(inputPath, input, info));
111 info.sampleRate, info.numChannels, src, std::move(
params));
116 REQUIRE(outputEqualsInput);
119 SECTION(
"Extreme stretch ratios")
121 constexpr auto originalDuration = 60.;
122 constexpr auto targetDuration = 1. / 44100;
123 constexpr auto superSmallRatio = targetDuration / originalDuration;
124 constexpr auto requestedNumSamples =
127 constexpr auto numChannels = 1;
131 params.timeRatio = superSmallRatio;
135 requestedNumSamples);
EffectDistortionSettings params
for(int ii=0, nn=names.size();ii< nn;++ii)
TEST_CASE("StaffPadTimeAndPitch")
void GetSamples(float *const *, size_t) override
std::vector< float * > channelPointers
std::vector< std::vector< float > > channelVectors
float *const * Get() const