diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index 918264ca..903eca64 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -78,6 +78,7 @@ namespace config { constexpr int filtersPerVoice { 2 }; constexpr int eqsPerVoice { 3 }; constexpr int oscillatorsPerVoice { 9 }; + constexpr float uniformNoiseBounds { 0.25f }; constexpr float noiseVariance { 0.25f }; /** Minimum interval in frames between recomputations of coefficients of the diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index df3a46b6..4f23fd5d 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -609,8 +609,20 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept const auto rightSpan = buffer.getSpan(1); if (region->sampleId.filename() == "*noise") { - absl::c_generate(leftSpan, noiseDist); - absl::c_generate(rightSpan, noiseDist); + auto gen = [&]() { + return uniformNoiseDist(Random::randomGenerator); + }; + absl::c_generate(leftSpan, gen); + absl::c_generate(rightSpan, gen); + } else if (region->sampleId.filename() == "*gnoise") { + // You need to wrap in a lambda, otherwise generate will + // make a copy of the gaussian distribution *along with its state* + // leading to periodic behavior.... + auto gen = [&]() { + return gaussianNoiseDist(); + }; + absl::c_generate(leftSpan, gen); + absl::c_generate(rightSpan, gen); } else { const auto numFrames = buffer.getNumFrames(); diff --git a/src/sfizz/Voice.h b/src/sfizz/Voice.h index 54b03318..40accaf1 100644 --- a/src/sfizz/Voice.h +++ b/src/sfizz/Voice.h @@ -467,7 +467,8 @@ private: Voice* nextSisterVoice { this }; Voice* previousSisterVoice { this }; - fast_gaussian_generator noiseDist { 0.0f, config::noiseVariance }; + fast_real_distribution uniformNoiseDist { -config::uniformNoiseBounds, config::uniformNoiseBounds }; + fast_gaussian_generator gaussianNoiseDist { 0.0f, config::noiseVariance }; ModifierArray> modifierSmoothers; Smoother gainSmoother;