MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Word.cpp
Go to the documentation of this file.
1#include "Word.hpp"
2
4
5namespace {
6
7 constexpr uint32_t max_bits = 24;
8
9 [[nodiscard]] double top(uint32_t bits) noexcept
10 {
11 return static_cast<double>((uint32_t { 1 } << std::clamp(bits, uint32_t { 1 }, max_bits)) - 1U);
12 }
13
14}
15
16uint32_t to_word(double value, uint32_t bits) noexcept
17{
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)));
20}
21
22double from_word(uint32_t word, uint32_t bits) noexcept
23{
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;
27}
28
29} // namespace MayaFlux::Kinesis::Discrete
glm::vec3 value
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.
Definition Word.cpp:22
uint32_t to_word(double value, uint32_t bits) noexcept
The offset binary word of a value, clamped to [-1, 1].
Definition Word.cpp:16