Add a more correct absolute difference function to dsp-util.

Differences between signed samples cover the entire unsigned 32-bit
range. "abs" will think any difference exceeding INT32_MAX is negative
which is not corrent. Test which argument is greater and subtract the
lesser from it, outputting unsigned difference.

Change-Id: I73a8e5e418d49ff73d1a7c98eeb4731946dcfe84
This commit is contained in:
Michael Sevakis 2012-04-26 15:21:43 -04:00
parent 2866063c3c
commit e5c3327cef
2 changed files with 13 additions and 7 deletions

View file

@ -29,6 +29,7 @@
#include "system.h"
#include "tdspeed.h"
#include "settings.h"
#include "dsp-util.h"
#define assert(cond)
@ -308,8 +309,7 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2],
for (int j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2)
{
int32_t diff = *curr - *prev;
delta += abs(diff);
delta += ad_s32(*curr, *prev);
if (delta >= min_delta)
goto skip;
@ -322,8 +322,7 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2],
for (int j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2)
{
int32_t diff = *curr - *prev;
delta += abs(diff);
delta += ad_s32(*curr, *prev);
if (delta >= min_delta)
goto skip;