Wayverb
maximum_length_sequence.h
1 #pragma once
2 
3 #include <functional>
4 
5 namespace wayverb {
6 namespace core {
7 
8 using mls_callback = std::function<void(bool value, size_t step)>;
9 
10 namespace {
11 constexpr uint32_t masks[] = {
12  0x000000U, 0x000000U, 0x000002U, 0x000006U, 0x00000CU,
13  0x000014U, 0x000030U, 0x000060U, 0x0000E1U, 0x000100U,
14  0x000240U, 0x000500U, 0x000E08U, 0x001C80U, 0x003802U,
15  0x006000U, 0x00D008U, 0x012000U, 0x020400U, 0x072000U,
16  0x090000U, 0x500000U, 0xC00000U, 0x420000U, 0xE10000U};
17 } // namespace
18 
19 template <typename Word>
20 void generate_maximum_length_sequence(Word order,
21  const mls_callback& callback) {
22  const auto signal_length = (Word{1} << order) - 1;
23  const auto mask = masks[order];
24  for (Word i{0ul}, reg{1}; i != signal_length; ++i) {
25  callback(reg & 1, i);
26  reg = (reg >> 1) ^ Word { (0 - (reg & 1)) & mask };
27  }
28 }
29 
30 } // namespace core
31 } // namespace wayverb
Definition: traits.cpp:2
Definition: capsule_base.h:9