From 64a591fb7a4ff9f12c322cf724c4c48b7c9c10d5 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 7 Apr 2020 17:38:31 +0200 Subject: [PATCH 1/5] Parse offset_cc --- src/sfizz/Defaults.h | 1 + src/sfizz/Region.cpp | 6 ++++++ src/sfizz/Region.h | 1 + tests/RegionT.cpp | 13 +++++++++++++ 4 files changed, 21 insertions(+) diff --git a/src/sfizz/Defaults.h b/src/sfizz/Defaults.h index 8506d90f..34a43ba5 100644 --- a/src/sfizz/Defaults.h +++ b/src/sfizz/Defaults.h @@ -49,6 +49,7 @@ namespace Default constexpr uint32_t offset { 0 }; constexpr uint32_t offsetRandom { 0 }; constexpr Range offsetRange { 0, std::numeric_limits::max() }; + constexpr Range offsetCCRange = offsetRange; constexpr Range sampleEndRange { 0, std::numeric_limits::max() }; constexpr Range sampleCountRange { 0, std::numeric_limits::max() }; constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop }; diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 3411e915..a8ffa43f 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -59,6 +59,12 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) case hash("offset_random"): setValueFromOpcode(opcode, offsetRandom, Default::offsetRange); break; + case hash("offset_cc&"): + if (opcode.parameters.back() > config::numCCs) + return false; + if (auto value = readOpcode(opcode.value, Default::offsetCCRange)) + offsetCC[opcode.parameters.back()] = *value; + break; case hash("end"): setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange); break; diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index fa952675..6e93b96f 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -232,6 +232,7 @@ struct Region { float delayRandom { Default::delayRandom }; // delay_random uint32_t offset { Default::offset }; // offset uint32_t offsetRandom { Default::offsetRandom }; // offset_random + CCMap offsetCC { Default::offset }; uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end absl::optional sampleCount {}; // count absl::optional loopMode {}; // loopmode diff --git a/tests/RegionT.cpp b/tests/RegionT.cpp index f982c424..c90ebc78 100644 --- a/tests/RegionT.cpp +++ b/tests/RegionT.cpp @@ -53,6 +53,19 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "offset", "-1" }); REQUIRE(region.offset == 0); } + SECTION("offset_cc") + { + REQUIRE(region.offsetCC.empty()); + region.parseOpcode({ "offset_cc1", "1" }); + REQUIRE(region.offsetCC.contains(1)); + REQUIRE(region.offsetCC[1] == 1); + region.parseOpcode({ "offset_cc2", "15420" }); + REQUIRE(region.offsetCC.contains(2)); + REQUIRE(region.offsetCC[2] == 15420); + region.parseOpcode({ "offset_cc2", "-1" }); + REQUIRE(region.offsetCC[2] == 0); + } + SECTION("offset_random") { From 02ad421fa3208e795a11f83c940114f569a520a0 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 7 Apr 2020 17:38:38 +0200 Subject: [PATCH 2/5] Adapt preload size --- src/sfizz/Synth.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index fd12b218..46c0109d 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -374,7 +374,16 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) region->hasStereoSample = true; // TODO: adjust with LFO targets - const auto maxOffset = region->offset + region->offsetRandom; + const auto maxOffset = [region]() { + uint64_t sumOffsetCC = region->offset + region->offsetRandom; + for (const auto& offsets: region->offsetCC) + sumOffsetCC += offsets.value; + if (static_cast(Default::offsetCCRange.getEnd()) < sumOffsetCC) + return Default::offsetCCRange.getEnd(); + + return static_cast(sumOffsetCC); + }(); + if (!resources.filePool.preloadFile(region->sample, maxOffset)) removeCurrentRegion(); } From 7a59b35b803d1973ca587f8d65229356bcd0cd60 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 7 Apr 2020 17:55:22 +0200 Subject: [PATCH 3/5] Used clamp int64 and get the modified offsets in getOffset() --- src/sfizz/Defaults.h | 8 ++++---- src/sfizz/Region.cpp | 9 ++++++--- src/sfizz/Region.h | 8 ++++---- src/sfizz/Synth.cpp | 5 +---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/sfizz/Defaults.h b/src/sfizz/Defaults.h index 34a43ba5..4fe7e973 100644 --- a/src/sfizz/Defaults.h +++ b/src/sfizz/Defaults.h @@ -46,10 +46,10 @@ namespace Default constexpr float delay { 0.0 }; constexpr float delayRandom { 0.0 }; constexpr Range delayRange { 0.0, 100.0 }; - constexpr uint32_t offset { 0 }; - constexpr uint32_t offsetRandom { 0 }; - constexpr Range offsetRange { 0, std::numeric_limits::max() }; - constexpr Range offsetCCRange = offsetRange; + constexpr int64_t offset { 0 }; + constexpr int64_t offsetRandom { 0 }; + constexpr Range offsetRange { 0, std::numeric_limits::max() }; + constexpr Range offsetCCRange = offsetRange; constexpr Range sampleEndRange { 0, std::numeric_limits::max() }; constexpr Range sampleCountRange { 0, std::numeric_limits::max() }; constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop }; diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index a8ffa43f..8fbed19c 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1140,10 +1140,13 @@ float sfz::Region::getPhase() const noexcept return phase; } -uint32_t sfz::Region::getOffset(Oversampling factor) const noexcept +uint64_t sfz::Region::getOffset(Oversampling factor) const noexcept { - std::uniform_int_distribution offsetDistribution { 0, offsetRandom }; - return (offset + offsetDistribution(Random::randomGenerator)) * static_cast(factor); + std::uniform_int_distribution offsetDistribution { 0, offsetRandom }; + uint64_t finalOffset = offset + offsetDistribution(Random::randomGenerator); + for (const auto& mod: offsetCC) + finalOffset += static_cast(mod.value * midiState.getCCValue(mod.cc)); + return Default::offsetCCRange.clamp(offset + offsetDistribution(Random::randomGenerator)) * static_cast(factor); } float sfz::Region::getDelay() const noexcept diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 6e93b96f..9540b1cc 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -189,7 +189,7 @@ struct Region { * * @return uint32_t */ - uint32_t getOffset(Oversampling factor = Oversampling::x1) const noexcept; + uint64_t getOffset(Oversampling factor = Oversampling::x1) const noexcept; /** * @brief Get the region delay in seconds * @@ -230,9 +230,9 @@ struct Region { std::string sample {}; // Sample float delay { Default::delay }; // delay float delayRandom { Default::delayRandom }; // delay_random - uint32_t offset { Default::offset }; // offset - uint32_t offsetRandom { Default::offsetRandom }; // offset_random - CCMap offsetCC { Default::offset }; + int64_t offset { Default::offset }; // offset + int64_t offsetRandom { Default::offsetRandom }; // offset_random + CCMap offsetCC { Default::offset }; uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end absl::optional sampleCount {}; // count absl::optional loopMode {}; // loopmode diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 46c0109d..0913f9a6 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -378,10 +378,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) uint64_t sumOffsetCC = region->offset + region->offsetRandom; for (const auto& offsets: region->offsetCC) sumOffsetCC += offsets.value; - if (static_cast(Default::offsetCCRange.getEnd()) < sumOffsetCC) - return Default::offsetCCRange.getEnd(); - - return static_cast(sumOffsetCC); + return Default::offsetCCRange.clamp(sumOffsetCC); }(); if (!resources.filePool.preloadFile(region->sample, maxOffset)) From 0ceb58e6ae6fbb1f90dafbc8729a7aa841044392 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 7 Apr 2020 18:26:04 +0200 Subject: [PATCH 4/5] Rebase on the new modifiers --- src/sfizz/Region.cpp | 2 +- src/sfizz/Synth.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 8fbed19c..501550da 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1145,7 +1145,7 @@ uint64_t sfz::Region::getOffset(Oversampling factor) const noexcept std::uniform_int_distribution offsetDistribution { 0, offsetRandom }; uint64_t finalOffset = offset + offsetDistribution(Random::randomGenerator); for (const auto& mod: offsetCC) - finalOffset += static_cast(mod.value * midiState.getCCValue(mod.cc)); + finalOffset += static_cast(mod.data * midiState.getCCValue(mod.cc)); return Default::offsetCCRange.clamp(offset + offsetDistribution(Random::randomGenerator)) * static_cast(factor); } diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 0913f9a6..d52aa86c 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -377,7 +377,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) const auto maxOffset = [region]() { uint64_t sumOffsetCC = region->offset + region->offsetRandom; for (const auto& offsets: region->offsetCC) - sumOffsetCC += offsets.value; + sumOffsetCC += offsets.data; return Default::offsetCCRange.clamp(sumOffsetCC); }(); From ad16540778bafb1a2efe24e0111d138f78dcc5ec Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 15 Apr 2020 18:41:06 +0200 Subject: [PATCH 5/5] Remove an excess space character [ci skip] --- src/sfizz/Defaults.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/Defaults.h b/src/sfizz/Defaults.h index 4fe7e973..2b12a504 100644 --- a/src/sfizz/Defaults.h +++ b/src/sfizz/Defaults.h @@ -49,7 +49,7 @@ namespace Default constexpr int64_t offset { 0 }; constexpr int64_t offsetRandom { 0 }; constexpr Range offsetRange { 0, std::numeric_limits::max() }; - constexpr Range offsetCCRange = offsetRange; + constexpr Range offsetCCRange = offsetRange; constexpr Range sampleEndRange { 0, std::numeric_limits::max() }; constexpr Range sampleCountRange { 0, std::numeric_limits::max() }; constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };