Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
chaos.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include <algorithm>
16#include <cmath>
17#include <cstdint>
18
19namespace pulp::signal {
20
32template <typename SampleType = float>
34public:
35 static constexpr double kMinR = 3.5;
36 static constexpr double kMaxR = 4.0;
37
39 static constexpr double kEpsilon = 1.0e-6;
40
41 void set_r(double r) { r_ = std::clamp(r, kMinR, kMaxR); }
42 double r() const { return r_; }
43
47 void seed(double x0) {
48 seed_ = std::clamp(x0, kEpsilon, 1.0 - kEpsilon);
49 x_ = seed_;
50 }
51
52 void reset() { x_ = seed_; }
53
55 SampleType next() {
56 x_ = std::clamp(r_ * x_ * (1.0 - x_), kEpsilon, 1.0 - kEpsilon);
57 return static_cast<SampleType>(x_);
58 }
59
61 SampleType next_bipolar() { return static_cast<SampleType>(2.0) * next() - static_cast<SampleType>(1); }
62
63 SampleType current() const { return static_cast<SampleType>(x_); }
64
65private:
66 double r_ = 3.9;
67 double x_ = 0.5;
68 double seed_ = 0.5;
69};
70
73
74} // namespace pulp::signal
Logistic map: x <- r * x * (1 - x) (May, "Simple mathematical models withvery complicated dynamics",...
Definition chaos.hpp:33
void reset()
Definition chaos.hpp:52
static constexpr double kMinR
Definition chaos.hpp:35
SampleType next()
Advance and return the state in [0, 1].
Definition chaos.hpp:55
double r() const
Definition chaos.hpp:42
static constexpr double kEpsilon
Definition chaos.hpp:39
SampleType next_bipolar()
Advance and return the state mapped to [-1, 1].
Definition chaos.hpp:61
SampleType current() const
Definition chaos.hpp:63
static constexpr double kMaxR
Definition chaos.hpp:36
void seed(double x0)
Initial condition, in (0, 1).
Definition chaos.hpp:47
void set_r(double r)
Definition chaos.hpp:41
Definition additive_bank.hpp:218
LogisticMapT< double > LogisticMap64
Definition chaos.hpp:72
LogisticMapT< float > LogisticMap
Definition chaos.hpp:71