diff options
author | luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> | 2021-01-05 11:34:38 -0500 |
---|---|---|
committer | luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> | 2021-01-05 11:34:38 -0500 |
commit | fb396395e99fcf9058ffac27c6445a5c24597b6c (patch) | |
tree | 59ca9c6e46cc7ca07021ee103e625435ecaca943 | |
parent | c506cf747fa2e0a0eaff428cfd28ada7ffa58b67 (diff) |
Fix bug in pcm delta compression.
error wasn't being correctly calculated for when new_sample was negative and sample was positive.
-rw-r--r-- | tools/aif2pcm/main.c | 4 |
1 files changed, 3 insertions, 1 deletions
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) { |