Add a helper to get the normalized phase

This commit is contained in:
Paul Ferrand 2020-03-28 20:11:09 +01:00
parent bad1120296
commit b223fb5e4f
2 changed files with 19 additions and 0 deletions

View file

@ -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<int>(phase);
} else {
std::uniform_real_distribution<float> 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<uint32_t>(factor);

View file

@ -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
*