2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This header file includes the inline functions in
|
|
|
|
|
// the fix point signal processing library.
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_SPL_SPL_INL_H_
|
|
|
|
|
#define WEBRTC_SPL_SPL_INL_H_
|
|
|
|
|
|
2012-08-28 04:09:50 +00:00
|
|
|
#ifdef WEBRTC_ARCH_ARM_V7
|
2013-05-27 09:49:58 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
|
|
|
|
|
2013-09-18 17:40:46 +00:00
|
|
|
#if defined(MIPS32_LE)
|
|
|
|
|
#include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !defined(MIPS_DSP_R1_LE)
|
2013-04-09 16:40:28 +00:00
|
|
|
static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
|
|
|
|
|
int16_t out16 = (int16_t) value32;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-26 16:35:25 +00:00
|
|
|
if (value32 > 32767)
|
|
|
|
|
out16 = 32767;
|
|
|
|
|
else if (value32 < -32768)
|
|
|
|
|
out16 = -32768;
|
|
|
|
|
|
|
|
|
|
return out16;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-05-23 04:07:00 -07:00
|
|
|
static __inline int32_t WebRtcSpl_AddSatW32(int32_t a, int32_t b) {
|
|
|
|
|
// Do the addition in unsigned numbers, since signed overflow is undefined
|
|
|
|
|
// behavior.
|
|
|
|
|
const int32_t sum = (int32_t)((uint32_t)a + (uint32_t)b);
|
|
|
|
|
|
|
|
|
|
// a + b can't overflow if a and b have different signs. If they have the
|
|
|
|
|
// same sign, a + b also has the same sign iff it didn't overflow.
|
|
|
|
|
if ((a < 0) == (b < 0) && (a < 0) != (sum < 0)) {
|
|
|
|
|
// The direction of the overflow is obvious from the sign of a + b.
|
|
|
|
|
return sum < 0 ? INT32_MAX : INT32_MIN;
|
2014-08-26 09:36:25 +00:00
|
|
|
}
|
2016-05-23 04:07:00 -07:00
|
|
|
return sum;
|
2014-08-26 09:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 04:07:00 -07:00
|
|
|
static __inline int32_t WebRtcSpl_SubSatW32(int32_t a, int32_t b) {
|
|
|
|
|
// Do the subtraction in unsigned numbers, since signed overflow is undefined
|
|
|
|
|
// behavior.
|
|
|
|
|
const int32_t diff = (int32_t)((uint32_t)a - (uint32_t)b);
|
2014-08-26 09:36:25 +00:00
|
|
|
|
2016-05-23 04:07:00 -07:00
|
|
|
// a - b can't overflow if a and b have the same sign. If they have different
|
|
|
|
|
// signs, a - b has the same sign as a iff it didn't overflow.
|
|
|
|
|
if ((a < 0) != (b < 0) && (a < 0) != (diff < 0)) {
|
|
|
|
|
// The direction of the overflow is obvious from the sign of a - b.
|
|
|
|
|
return diff < 0 ? INT32_MAX : INT32_MIN;
|
2014-08-26 09:36:25 +00:00
|
|
|
}
|
2016-05-23 04:07:00 -07:00
|
|
|
return diff;
|
2014-08-26 09:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 16:40:28 +00:00
|
|
|
static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
|
|
|
|
|
return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 16:40:28 +00:00
|
|
|
static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
|
|
|
|
|
return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-09-18 17:40:46 +00:00
|
|
|
#endif // #if !defined(MIPS_DSP_R1_LE)
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-18 17:40:46 +00:00
|
|
|
#if !defined(MIPS32_LE)
|
2013-04-09 16:40:28 +00:00
|
|
|
static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
|
2014-09-04 13:21:44 +00:00
|
|
|
int16_t bits;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
if (0xFFFF0000 & n) {
|
|
|
|
|
bits = 16;
|
|
|
|
|
} else {
|
|
|
|
|
bits = 0;
|
|
|
|
|
}
|
|
|
|
|
if (0x0000FF00 & (n >> bits)) bits += 8;
|
|
|
|
|
if (0x000000F0 & (n >> bits)) bits += 4;
|
|
|
|
|
if (0x0000000C & (n >> bits)) bits += 2;
|
|
|
|
|
if (0x00000002 & (n >> bits)) bits += 1;
|
|
|
|
|
if (0x00000001 & (n >> bits)) bits += 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
return bits;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 13:21:44 +00:00
|
|
|
static __inline int16_t WebRtcSpl_NormW32(int32_t a) {
|
|
|
|
|
int16_t zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-10-30 01:19:42 +00:00
|
|
|
if (a == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (a < 0) {
|
|
|
|
|
a = ~a;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
if (!(0xFFFF8000 & a)) {
|
|
|
|
|
zeros = 16;
|
|
|
|
|
} else {
|
|
|
|
|
zeros = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!(0xFF800000 & (a << zeros))) zeros += 8;
|
|
|
|
|
if (!(0xF8000000 & (a << zeros))) zeros += 4;
|
|
|
|
|
if (!(0xE0000000 & (a << zeros))) zeros += 2;
|
|
|
|
|
if (!(0xC0000000 & (a << zeros))) zeros += 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
return zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 13:21:44 +00:00
|
|
|
static __inline int16_t WebRtcSpl_NormU32(uint32_t a) {
|
|
|
|
|
int16_t zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
if (a == 0) return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
if (!(0xFFFF0000 & a)) {
|
|
|
|
|
zeros = 16;
|
|
|
|
|
} else {
|
|
|
|
|
zeros = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!(0xFF000000 & (a << zeros))) zeros += 8;
|
|
|
|
|
if (!(0xF0000000 & (a << zeros))) zeros += 4;
|
|
|
|
|
if (!(0xC0000000 & (a << zeros))) zeros += 2;
|
|
|
|
|
if (!(0x80000000 & (a << zeros))) zeros += 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
return zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 13:21:44 +00:00
|
|
|
static __inline int16_t WebRtcSpl_NormW16(int16_t a) {
|
|
|
|
|
int16_t zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-10-30 01:19:42 +00:00
|
|
|
if (a == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (a < 0) {
|
|
|
|
|
a = ~a;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
if (!(0xFF80 & a)) {
|
|
|
|
|
zeros = 8;
|
|
|
|
|
} else {
|
|
|
|
|
zeros = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!(0xF800 & (a << zeros))) zeros += 4;
|
|
|
|
|
if (!(0xE000 & (a << zeros))) zeros += 2;
|
|
|
|
|
if (!(0xC000 & (a << zeros))) zeros += 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-09-09 16:23:50 +00:00
|
|
|
return zeros;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 16:40:28 +00:00
|
|
|
static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
|
2011-10-05 16:44:11 +00:00
|
|
|
return (a * b + c);
|
|
|
|
|
}
|
2013-09-18 17:40:46 +00:00
|
|
|
#endif // #if !defined(MIPS32_LE)
|
2011-10-05 16:44:11 +00:00
|
|
|
|
2012-08-28 04:09:50 +00:00
|
|
|
#endif // WEBRTC_ARCH_ARM_V7
|
2011-09-09 16:23:50 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_SPL_SPL_INL_H_
|