From f656c9f5cbfa8515dab287077b10f6769c6e66bc Mon Sep 17 00:00:00 2001 From: ayumi Date: Wed, 23 Apr 2025 23:11:45 +0200 Subject: Utilise more than one bit of the entropy returned by komihash before requesting more --- src/codecs/sample.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/codecs/sample.cpp b/src/codecs/sample.cpp index 63d14203..faf8b0f9 100644 --- a/src/codecs/sample.cpp +++ b/src/codecs/sample.cpp @@ -13,13 +13,17 @@ namespace sample { -static uint64_t sSeed1{0}; -static uint64_t sSeed2{0}; - auto shiftWithDither(int64_t src, uint_fast8_t bits) -> Sample { // FIXME: Use a better dither. - int16_t noise = static_cast(komirand(&sSeed1, &sSeed2) & 1); - return (src >> bits) ^ noise; + static uint64_t sSeed1{0}; + static uint64_t sSeed2{0}; + static uint64_t noise; + static uint_fast8_t pos = 0; + if (pos++ % 64 == 0) + noise = komirand(&sSeed1, &sSeed2); + else + noise >>= 1; + return (src >> bits) ^ (noise & 1); } } // namespace sample -- cgit v1.2.3