FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
noise::MultirateGenerator Class Referencefinal

Generates multirate noise using a hierarchical tree structure. More...

#include "noise_generators.h"

+ Inheritance diagram for noise::MultirateGenerator:
+ Collaboration diagram for noise::MultirateGenerator:

Public Member Functions

 MultirateGenerator (std::mt19937 &rngEngine, RealType alpha, unsigned branches)
 Constructor to initialize the multirate generator.
 
RealType getSample () override
 Generates a multirate noise sample.
 
void skipSamples (std::size_t samples) noexcept
 Skips a number of samples in the noise sequence.
 
void reset () noexcept
 Resets the noise generator state.
 

Detailed Description

Generates multirate noise using a hierarchical tree structure.

Definition at line 118 of file noise_generators.h.

Constructor & Destructor Documentation

◆ MultirateGenerator()

noise::MultirateGenerator::MultirateGenerator ( std::mt19937 &  rngEngine,
RealType  alpha,
unsigned  branches 
)

Constructor to initialize the multirate generator.

Parameters
rngEngineThe random number engine to use for generation.
alphaThe scaling parameter that controls the noise properties.
branchesThe number of branches in the tree structure.

Definition at line 24 of file noise_generators.cpp.

24 :
25 _scale(1.0 / std::pow(10.0, (-alpha + 2.0) * 2.0)), _rng_engine(rngEngine)
26 {
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);
30
31 createTree(ffrac, fint, branches);
32 // TODO: verify scale factor calculation (* 2.0 appears to be a bug)
33 }
double RealType
Type for real numbers.
Definition config.h:27
math::Vec3 max

References max.

Member Function Documentation

◆ getSample()

RealType noise::MultirateGenerator::getSample ( )
overridevirtual

Generates a multirate noise sample.

Returns
A noise sample of type RealType.

Implements noise::NoiseGenerator.

Definition at line 135 of file noise_generators.h.

135{ return _topbranch->getSample() * _scale; }

◆ reset()

void noise::MultirateGenerator::reset ( )
noexcept

Resets the noise generator state.

Definition at line 90 of file noise_generators.cpp.

91 {
92 std::vector<FAlphaBranch*> branches;
93 // NOLINTNEXTLINE(misc-const-correctness): Collected branches are flushed through mutable aliases below.
94 FAlphaBranch* branch = _topbranch.get();
95
96 while (branch != nullptr)
97 {
98 branches.push_back(branch);
99 branch = branch->getPre();
100 }
101
102 for (const auto& b : std::ranges::reverse_view(branches))
103 {
104 b->flush(1.0);
105 }
106 }
RealType b

References b, and max.

◆ skipSamples()

void noise::MultirateGenerator::skipSamples ( std::size_t  samples)
noexcept

Skips a number of samples in the noise sequence.

Parameters
samplesThe number of samples to skip.

Definition at line 36 of file noise_generators.cpp.

37 {
38 if (samples == 0)
39 {
40 return;
41 }
42
43 if (const int skip_branches = static_cast<int>(std::log10(static_cast<double>(samples))) - 1; skip_branches > 0)
44 {
45 std::vector<FAlphaBranch*> flushbranches;
46 FAlphaBranch* branch = _topbranch.get();
47
48 for (int i = 0; i < skip_branches && (branch != nullptr); ++i)
49 {
50 flushbranches.push_back(branch);
51 branch = branch->getPre();
52 }
53
54 if (branch != nullptr)
55 {
56 const auto reduced_samples =
57 samples / static_cast<std::size_t>(std::pow(10.0, static_cast<double>(skip_branches)));
58 for (std::size_t i = 0; i < reduced_samples; ++i)
59 {
60 branch->getSample();
61 }
62 }
63
64 for (const auto& fb : std::ranges::reverse_view(flushbranches))
65 {
66 fb->flush(1.0);
67 }
68 }
69 else
70 {
71 for (std::size_t i = 0; i < samples; ++i)
72 {
73 _topbranch->getSample();
74 }
75 }
76 }

References max.


The documentation for this class was generated from the following files: