27 while (n > 1) { n >>= 1; ++r; }
38template<u
int16_t Size>
41 static_assert(bits >= 1 && bits <= 16,
"Size must be power of 2 in [2, 65536]");
43 uint32_t idx = phase >> (32 - bits);
44 uint32_t a = table[idx];
45 uint32_t b = table[idx + 1];
46 uint16_t frac = (phase >> (16 - bits)) &
FRAC16_MASK;
47 return static_cast<uint16_t
>(a + (((b - a) * frac) >> 16));
52inline uint16_t
mix(uint16_t a, uint16_t b, uint16_t balance) {
53 return static_cast<uint16_t
>(
54 (
static_cast<uint32_t
>(a) * (
U16_MAX - balance) +
55 static_cast<uint32_t
>(b) * balance) >> 16);
70template<u
int16_t Size>
73 static_assert(bits >= 1 && bits <= 16,
"Size must be power of 2 in [2, 65536]");
75 uint32_t idx = phase >> (32 - bits);
76 float frac =
static_cast<float>(phase & ((1u << (32 - bits)) - 1))
77 * (1.0f /
static_cast<float>(1u << (32 - bits)));
78 return table[idx] + (table[idx + 1] - table[idx]) * frac;
83template<u
int16_t Size>
86 static_assert(bits >= 2 && bits <= 16,
"Size must be power of 2 in [4, 65536]");
88 uint32_t idx = phase >> (32 - bits);
89 float f =
static_cast<float>(phase & ((1u << (32 - bits)) - 1))
90 * (1.0f /
static_cast<float>(1u << (32 - bits)));
92 float xm1 = table[idx > 0 ? idx - 1 : Size - 1];
93 float x0 = table[idx];
94 float x1 = table[idx + 1];
95 float x2 = table[idx + 2];
98 float c = (x1 - xm1) * 0.5f;
101 float a = w + v + (x2 - x0) * 0.5f;
105 return ((a * f - b_neg) * f + c) * f + x0;
112template<u
int16_t Size>
113inline float crossfade(
const float* table_a,
const float* table_b,
114 uint32_t phase,
float balance) {
constexpr uint8_t log2_of(uint16_t n)
uint16_t lookup_linear(const uint16_t *table, uint32_t phase)
float lookup_cubic(const float *table, uint32_t phase)
uint16_t mix(uint16_t a, uint16_t b, uint16_t balance)
float crossfade(const float *table_a, const float *table_b, uint32_t phase, float balance)
constexpr uint16_t FRAC16_MASK
constexpr uint16_t U16_MAX