7#include "xorshift128p.hpp"
8#include "../required.hpp"
37 tt_axiom(num_bits > 0);
38 auto maximum_value =
static_cast<float>((1_uz << num_bits) - 1);
41 maximum_value *= 127.0f;
44 maximum_value *= 2.0f;
46 _multiplier = f32x4::broadcast(1.0f / maximum_value);
54 if (
static_cast<bool>(++_counter & 1)) {
55 auto rand = _state.next<
u64x2>();
56 auto spdf1 =
i16x8{bit_cast<i8x16>(rand)};
58 auto spdf2 =
i16x8{bit_cast<i8x16>(rand)};
60 _tpdf = spdf1 + spdf2;
63 auto second_tpdf = bit_cast<i16x8>(bit_cast<u64x2>(_tpdf).yx());
64 return f32x4{
i32x4{second_tpdf}} * _multiplier;
75 return samples +
next();
83 [[nodiscard]]
float next(
float sample)
noexcept
85 return get<0>(f32x4::broadcast(sample) +
next());
89 f32x4 _multiplier = {};
91 xorshift128p _state = {};
92 unsigned char _counter = 0;
An object that create dither values to add to samples before rounding.
Definition dither.hpp:23
f32x4 next(f32x4 samples) noexcept
Add dither to the given samples.
Definition dither.hpp:73
float next(float sample) noexcept
Add dither to the given samples.
Definition dither.hpp:83
f32x4 next() noexcept
Get 8 floating point number to add to a samples.
Definition dither.hpp:52
dither(int num_bits) noexcept
Create a dither object.
Definition dither.hpp:35