summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-01-19 08:47:37 +1100
committerjacqueline <me@jacqueline.id.au>2024-01-19 08:47:37 +1100
commit1525afe8aaadfaa877f8987f0ea224263a612b5e (patch)
tree8307e691c6ddf2da81764868b3c68e7f086e1487
parentd1ae1a4230b413b6a92179936d431c83247c5fd2 (diff)
downloadtangara-fw-1525afe8aaadfaa877f8987f0ea224263a612b5e.tar.gz
fix issue with unclipped dither
-rw-r--r--src/codecs/sample.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/codecs/sample.cpp b/src/codecs/sample.cpp
index c99710f1..63d14203 100644
--- a/src/codecs/sample.cpp
+++ b/src/codecs/sample.cpp
@@ -17,12 +17,9 @@ static uint64_t sSeed1{0};
static uint64_t sSeed2{0};
auto shiftWithDither(int64_t src, uint_fast8_t bits) -> Sample {
- // Generate `bits` random bits
- uint64_t mask = 0xFFFFFFFF;
- mask >>= 32 - bits;
- int64_t noise = static_cast<int32_t>(komirand(&sSeed1, &sSeed2) & mask);
- // Apply to the sample, then shift to 16 bit.
- return (src + noise) >> bits;
+ // FIXME: Use a better dither.
+ int16_t noise = static_cast<int16_t>(komirand(&sSeed1, &sSeed2) & 1);
+ return (src >> bits) ^ noise;
}
} // namespace sample