From b223fb5e4f167e258256741d1efbe80237af90ad Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 28 Mar 2020 20:11:09 +0100 Subject: [PATCH] Add a helper to get the normalized phase --- src/sfizz/Region.cpp | 13 +++++++++++++ src/sfizz/Region.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 4f05f314..d21b3cc2 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -917,6 +917,19 @@ float sfz::Region::getBaseGain() noexcept return normalizePercents(amplitude); } +float sfz::Region::getPhase() noexcept +{ + float phase; + if (oscillatorPhase >= 0) { + phase = oscillatorPhase * (1.0f / 360.0f); + phase -= static_cast(phase); + } else { + std::uniform_real_distribution phaseDist { 0.0001f, 0.9999f }; + phase = phaseDist(Random::randomGenerator); + } + return phase; +} + uint32_t sfz::Region::getOffset(Oversampling factor) noexcept { return (offset + offsetDistribution(Random::randomGenerator)) * static_cast(factor); diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index ebacc207..b3966a47 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -167,6 +167,12 @@ struct Region { * @return float */ float getBaseGain() noexcept; + /** + * @brief Get the base gain of the region. + * + * @return float + */ + float getPhase() noexcept; /** * @brief Computes the gain value related to the velocity of the note *