Fix bug in pcm delta compression.

error wasn't being correctly calculated for when new_sample was negative and sample was positive.
This commit is contained in:
luckytyphlosion 2021-01-05 11:34:38 -05:00
parent c506cf747f
commit fb396395e9

View File

@ -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)
{