Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
hit_life.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace pulp::signal::drum {
6
33
35 std::uint32_t seed = 0;
36 bool reseed_excitation = true;
37 bool reset_dsp_state = true;
38};
39
41class HitLife {
42public:
45
47 if (mode_ == mode) return;
48 mode_ = mode;
49 hit_index_ = 0;
50 }
51 HitLifeMode mode() const { return mode_; }
52
53 void reset() { hit_index_ = 0; }
54
55 HitLifeDecision trigger(std::uint32_t base_seed) {
56 switch (mode_) {
58 return {base_seed, true, true};
60 return {advance_seed(base_seed), true, true};
62 return {base_seed, false, false};
64 return {base_seed, true, false};
66 return {advance_seed(base_seed), true, false};
67 }
68 return {base_seed, true, true};
69 }
70
71private:
72 // Knuth's multiplicative constant. The hit index is what advances, so the
73 // sequence is reproducible from the base seed rather than being drawn from
74 // any ambient state.
75 std::uint32_t advance_seed(std::uint32_t base_seed) {
76 ++hit_index_;
77 return base_seed + static_cast<std::uint32_t>(hit_index_ * 2654435761u);
78 }
79
81 std::uint32_t hit_index_ = 0;
82};
83
84} // namespace pulp::signal::drum
HitLifeMode mode() const
Definition hit_life.hpp:51
HitLife(HitLifeMode mode=HitLifeMode::fixed_seed)
Definition hit_life.hpp:43
HitLifeDecision trigger(std::uint32_t base_seed)
Definition hit_life.hpp:55
void set_mode(HitLifeMode mode)
Definition hit_life.hpp:46
void reset()
Definition hit_life.hpp:53
Definition clap.hpp:13
HitLifeMode
Selects the intentional source of variation between otherwise identical hits.
Definition hit_life.hpp:26
@ advancing_seed
Definition hit_life.hpp:28
@ advancing_seed_preserved_body
Definition hit_life.hpp:31
@ fixed_seed_preserved_body
Definition hit_life.hpp:30
@ preserved_state
Definition hit_life.hpp:29
@ fixed_seed
Definition hit_life.hpp:27
Definition hit_life.hpp:34
bool reseed_excitation
Definition hit_life.hpp:36
std::uint32_t seed
Definition hit_life.hpp:35
bool reset_dsp_state
Definition hit_life.hpp:37