25 _rng_engine(rngEngine)
27 const RealType beta = -(alpha - 2) / 2.0;
28 const int fint =
static_cast<int>(std::floor(beta));
29 const RealType ffrac = std::fmod(beta, 1.0);
31 createTree(ffrac, fint, branches);
33 _scale = 1.0 / std::pow(10.0, (-alpha + 2.0) * 2.0);
39 if (
const int skip_branches =
static_cast<int>(std::log10(samples)) - 1; skip_branches > 0)
41 std::vector<FAlphaBranch*> flushbranches;
44 for (
int i = 0; i < skip_branches && branch; ++i)
46 flushbranches.push_back(branch);
52 const auto reduced_samples = samples /
static_cast<long long>(std::pow(10.0, skip_branches));
53 for (
long long i = 0; i < reduced_samples; ++i)
59 for (
const auto& fb : std::ranges::reverse_view(flushbranches))
66 for (
long long i = 0; i < samples; ++i)
68 _topbranch->getSample();
73 void MultirateGenerator::createTree(
const RealType fAlpha,
const int fInt,
const unsigned branches)
75 std::unique_ptr<FAlphaBranch> previous_branch =
nullptr;
76 for (
unsigned i = 0; i < branches; ++i)
78 previous_branch = std::make_unique<FAlphaBranch>(_rng_engine.get(), fAlpha, fInt,
79 std::move(previous_branch), i == branches - 1);
81 _topbranch = std::move(previous_branch);
87 std::vector<FAlphaBranch*> branches;
92 branches.push_back(branch);
96 for (
const auto& b : std::ranges::reverse_view(branches))
103 const std::vector<RealType>& inWeights,
const RealType frequency,
105 int branches) noexcept :
106 _rng_engine(rngEngine), _weights(inWeights), _phase_offset(phaseOffset), _freq_offset(freqOffset),
107 _frequency(frequency)
109 for (
size_t i = 0; i < alpha.size(); ++i)
111 auto mgen = std::make_unique<MultirateGenerator>(_rng_engine.get(), alpha[i], branches);
112 _generators.push_back(std::move(mgen));
114 switch (
static_cast<int>(alpha[i]))
117 _weights[i] *= std::pow(10.0, 1.225);
120 _weights[i] *= std::pow(10.0, 0.25);
123 _weights[i] *= std::pow(10.0, -0.25);
126 _weights[i] *= std::pow(10.0, -0.5);
129 _weights[i] *= std::pow(10.0, -1.0);
140 for (
size_t i = 0; i < _generators.size(); ++i)
142 sample += _generators[i]->getSample() * _weights[i];
145 sample += _phase_offset;
146 sample += 2 *
PI * _freq_offset *
static_cast<double>(_count) /
params::rate();
154 for (
const auto& generator : _generators)
156 generator->skipSamples(samples);
165 for (
const auto& generator : _generators)
174 return !_generators.empty() || _freq_offset != 0 || _phase_offset != 0;
void skipSamples(long long samples)
Skips a number of samples in the noise sequence.
void reset()
Resets the noise generator state.
bool enabled() const
Checks if the noise generator is enabled.
ClockModelGenerator(std::mt19937 &rngEngine, const std::vector< RealType > &alpha, const std::vector< RealType > &inWeights, RealType frequency, RealType phaseOffset, RealType freqOffset, int branches) noexcept
Constructor to initialize the clock model generator.
RealType getSample() override
Generates a clock model noise sample.
Class responsible for generating fractional and integer noise components.
FAlphaBranch * getPre() const noexcept
Retrieves the previous branch in the chain.
void flush(RealType scale)
Flushes the branch with a new scaling factor.
RealType getSample() noexcept
Retrieves the current noise sample.
MultirateGenerator(std::mt19937 &rngEngine, RealType alpha, unsigned branches)
Constructor to initialize the multirate generator.
void reset() noexcept
Resets the noise generator state.
void skipSamples(long long samples) noexcept
Skips a number of samples in the noise sequence.
double RealType
Type for real numbers.
constexpr RealType PI
Mathematical constant π (pi).
Implementation of the FAlphaBranch class for noise generation.
RealType rate() noexcept
Get the rendering sample rate.
Header file for noise generator classes.
Defines the Parameters struct and provides methods for managing simulation parameters.