diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index cda13a7e..6e27153b 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -227,6 +227,7 @@ absl::optional sfz::FilePool::getFileInformation(const Fil if (!fileId.isReverse()) { if (instrumentInfo.loop_count > 0) { + returnedValue.hasLoop = true; returnedValue.loopBegin = instrumentInfo.loops[0].start; returnedValue.loopEnd = min(returnedValue.end, instrumentInfo.loops[0].end - 1); } diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index cbec5f8f..9d099550 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -52,6 +52,7 @@ struct FileInformation { uint32_t end { Default::sampleEndRange.getEnd() }; uint32_t loopBegin { Default::loopRange.getStart() }; uint32_t loopEnd { Default::loopRange.getEnd() }; + bool hasLoop { false }; double sampleRate { config::defaultSampleRate }; int numChannels { 0 }; }; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 9f095c4c..40dd331b 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -482,7 +482,7 @@ void sfz::Synth::finalizeSfzLoad() region->sampleEnd = std::min(region->sampleEnd, fileInformation->end); - if (fileInformation->loopBegin != Default::loopRange.getStart() && fileInformation->loopEnd != Default::loopRange.getEnd()) { + if (fileInformation->hasLoop) { if (region->loopRange.getStart() == Default::loopRange.getStart()) region->loopRange.setStart(fileInformation->loopBegin); diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 98b16dce..f92f496c 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -564,6 +564,17 @@ TEST_CASE("[Files] Looped regions taken from files and possibly overriden") REQUIRE(synth.getRegionView(2)->loopRange == Range { 4, 124 }); } +TEST_CASE("[Files] Looped regions can start at 0") +{ + Synth synth; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/loop_can_start_at_0.sfz", R"( + sample=wavetable_with_loop_at_endings.wav + )"); + REQUIRE( synth.getNumRegions() == 1 ); + REQUIRE( synth.getRegionView(0)->loopMode == SfzLoopMode::loop_continuous ); + REQUIRE( synth.getRegionView(0)->loopRange == Range { 0, synth.getRegionView(0)->sampleEnd } ); +} + TEST_CASE("[Files] Case sentitiveness") { const fs::path sfzFilePath = fs::current_path() / "tests/TestFiles/case_insensitive.sfz"; diff --git a/tests/TestFiles/wavetable_with_loop_at_endings.wav b/tests/TestFiles/wavetable_with_loop_at_endings.wav new file mode 100644 index 00000000..b6aafda4 Binary files /dev/null and b/tests/TestFiles/wavetable_with_loop_at_endings.wav differ