From fb396395e99fcf9058ffac27c6445a5c24597b6c Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 5 Jan 2021 11:34:38 -0500 Subject: [PATCH] Fix bug in pcm delta compression. error wasn't being correctly calculated for when new_sample was negative and sample was positive. --- tools/aif2pcm/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/aif2pcm/main.c b/tools/aif2pcm/main.c index cd5ac4a50..b9709bee8 100644 --- a/tools/aif2pcm/main.c +++ b/tools/aif2pcm/main.c @@ -426,7 +426,9 @@ int get_delta_index(uint8_t sample, uint8_t prev_sample) for (int i = 0; i < 16; i++) { uint8_t new_sample = prev_sample + gDeltaEncodingTable[i]; - int error = sample > new_sample ? sample - new_sample : new_sample - sample; + uint8_t sample_diff_1 = (sample - new_sample) & 0xff; + uint8_t sample_diff_2 = (new_sample - sample) & 0xff; + int error = sample_diff_1 < sample_diff_2 ? sample_diff_1 : sample_diff_2; if (error < best_error) {