forked from len0rd/rockbox
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:
parent
2866063c3c
commit
e5c3327cef
2 changed files with 13 additions and 7 deletions
|
@ -18,8 +18,8 @@
|
|||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef DSP_HELPER_H
|
||||
#define DSP_HELPER_H
|
||||
#ifndef DSP_UTIL_H
|
||||
#define DSP_UTIL_H
|
||||
|
||||
/** Clip sample to signed 16 bit range **/
|
||||
|
||||
|
@ -48,4 +48,11 @@ static FORCE_INLINE int32_t clip_sample_16(int32_t sample)
|
|||
|
||||
#undef CLIP_SAMPLE_16_DEFINED
|
||||
|
||||
#endif /* DSP_HELPER_H */
|
||||
/* Absolute difference of signed 32-bit numbers which must be dealt with
|
||||
* in the unsigned 32-bit range */
|
||||
static FORCE_INLINE uint32_t ad_s32(int32_t a, int32_t b)
|
||||
{
|
||||
return (a >= b) ? (a - b) : (b - a);
|
||||
}
|
||||
|
||||
#endif /* DSP_UTIL_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue