7 constexpr uint32_t max_bits = 24;
9 [[nodiscard]]
double top(uint32_t bits)
noexcept
11 return static_cast<double>((uint32_t { 1 } << std::clamp(bits, uint32_t { 1 }, max_bits)) - 1U);
18 const double clamped = std::clamp(
value, -1.0, 1.0);
19 return static_cast<uint32_t
>(std::lrint((clamped + 1.0) * 0.5 * top(bits)));
22double from_word(uint32_t word, uint32_t bits)
noexcept
24 const double highest = top(bits);
25 const auto masked =
static_cast<double>(word &
static_cast<uint32_t
>(highest));
26 return masked / highest * 2.0 - 1.0;
Samples read as fixed width binary words.
double from_word(uint32_t word, uint32_t bits) noexcept
The value of an offset binary word; bits above the width are ignored.
uint32_t to_word(double value, uint32_t bits) noexcept
The offset binary word of a value, clamped to [-1, 1].