From 0d285cf494285c6fa44f9404ad981f9a9c8a2403 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 1 Dec 2019 21:40:27 +0100 Subject: [PATCH] Add flags to the command line client for oversampling and preloading --- clients/jack_client.cpp | 22 +++++++++++++++++++++- src/sfizz/FilePool.cpp | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clients/jack_client.cpp b/clients/jack_client.cpp index f2e8c11b..1092a487 100644 --- a/clients/jack_client.cpp +++ b/clients/jack_client.cpp @@ -23,6 +23,7 @@ #include "sfizz.hpp" #include +#include #include #include #include @@ -156,17 +157,36 @@ static void done(int sig [[maybe_unused]]) // exit(0); } +ABSL_FLAG(std::string, oversampling, "1x", "Internal oversampling factor (value values are 1x, 2x, 4x, 8x)"); +ABSL_FLAG(uint32_t, preload_size, 8192, "Preloaded value"); + int main(int argc, char** argv) { // std::ios::sync_with_stdio(false); auto arguments = absl::ParseCommandLine(argc, argv); auto filesToParse = absl::MakeConstSpan(arguments).subspan(1); + const std::string oversampling = absl::GetFlag(FLAGS_oversampling); + const uint32_t preload_size = absl::GetFlag(FLAGS_preload_size); + + std::cout << "Flags" << '\n'; + std::cout << "- Oversampling: " << oversampling << '\n'; + std::cout << "- Preloaded Size: " << preload_size << '\n'; + const auto factor = [&]() { + if (oversampling == "x1") return sfz::Oversampling::x1; + if (oversampling == "x2") return sfz::Oversampling::x2; + if (oversampling == "x4") return sfz::Oversampling::x4; + if (oversampling == "x8") return sfz::Oversampling::x8; + return sfz::Oversampling::x1; + }(); + std::cout << "Positional arguments:"; for (auto& file : filesToParse) std::cout << " " << file << ','; std::cout << '\n'; sfz::Synth synth; + synth.setOversamplingFactor(factor); + synth.setPreloadSize(preload_size); synth.loadSfzFile(filesToParse[0]); std::cout << "==========" << '\n'; std::cout << "Total:" << '\n'; @@ -260,4 +280,4 @@ int main(int argc, char** argv) std::cout << "Closing..." << '\n'; jack_client_close(client); return 0; -} \ No newline at end of file +} diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index 46d11841..44bb446f 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -141,10 +141,10 @@ bool sfz::FilePool::preloadFile(const std::string& filename, uint32_t maxOffset) if (preloadedFiles.contains(filename)) { if (framesToLoad > preloadedFiles[filename].preloadedData->getNumFrames()) { - preloadedFiles[filename].preloadedData = readFromFile(sndFile, framesToLoad); + preloadedFiles[filename].preloadedData = readFromFile(sndFile, framesToLoad, oversamplingFactor); } } else { - preloadedFiles.insert_or_assign(filename, { readFromFile(sndFile, framesToLoad), static_cast(sndFile.samplerate()) * static_cast(oversamplingFactor) }); + preloadedFiles.insert_or_assign(filename, { readFromFile(sndFile, framesToLoad, oversamplingFactor), static_cast(sndFile.samplerate() * oversamplingFactor) }); } return true;