summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorayumi <ayumi@noreply.codeberg.org>2025-04-23 23:11:45 +0200
committerayumi <ayumi@noreply.codeberg.org>2025-04-24 00:07:46 +0200
commitf656c9f5cbfa8515dab287077b10f6769c6e66bc (patch)
tree5354393a109b698c2184f312048283cb74a3f668 /src
parentfb044d5ccae7cead4c2d2fda3f729fbfc1737005 (diff)
downloadtangara-fw-f656c9f5cbfa8515dab287077b10f6769c6e66bc.tar.gz
Utilise more than one bit of the entropy returned by komihash before requesting more
Diffstat (limited to 'src')
-rw-r--r--src/codecs/sample.cpp14
1 files 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<int16_t>(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