12 #ifndef _MpDspUtilsSumVect_h_ 13 #define _MpDspUtilsSumVect_h_ 24 #ifdef MP_FIXED_POINT // [ 26 OsStatus
MpDspUtils::add_I(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength)
28 for (
int i=0; i<dataLength; i++)
30 add_I(pSrc2Dst[i], (int32_t)pSrc1[i]);
35 OsStatus
MpDspUtils::add_IGain(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor)
37 for (
int i=0; i<dataLength; i++)
39 add_I(pSrc2Dst[i], ((int32_t)pSrc1[i])<<src1ScaleFactor);
45 OsStatus
MpDspUtils::add_IAtt(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor)
47 for (
int i=0; i<dataLength; i++)
49 add_I(pSrc2Dst[i], (int32_t)pSrc1[i]>>src1ScaleFactor);
55 OsStatus
MpDspUtils::add(
const int32_t *pSrc1,
const int32_t *pSrc2, int32_t *pDst,
int dataLength)
57 for (
int i=0; i<dataLength; i++)
59 pDst[i] =
add(pSrc1[i], pSrc2[i]);
64 OsStatus
MpDspUtils::addMul_I(
const int16_t *pSrc1, int16_t val, int32_t *pSrc2Dst,
int dataLength)
66 for (
int i=0; i<dataLength; i++)
68 addMul_I(pSrc2Dst[i], pSrc1[i], val);
75 int32_t *pSrc2Dst,
int dataLength)
82 int16_t step = (valEnd - valStart) / dataLength;
83 int16_t val = valStart;
85 for (
int i=0; i<dataLength; i++, val += step)
87 addMul_I(pSrc2Dst[i], pSrc1[i], val);
92 OsStatus
MpDspUtils::mul(
const int16_t *pSrc,
const int16_t val, int32_t *pDst,
int dataLength)
94 for (
int i=0; i<dataLength; i++)
96 pDst[i] = pSrc[i]*val;
104 const int16_t thresold = INT16_MAX/val;
105 for (
int i=0; i<dataLength; i++)
107 if (pSrcDst[i] > thresold)
109 pSrcDst[i] = INT16_MAX;
111 else if (pSrcDst[i] < -thresold)
113 pSrcDst[i] = -INT16_MAX;
125 int32_t *pDst,
int dataLength)
132 int16_t step = (valEnd - valStart) / dataLength;
133 int16_t val = valStart;
135 for (
int i=0; i<dataLength; i++, val += step)
137 pDst[i] = pSrc[i] * val;
142 #else // MP_FIXED_POINT ][ 144 OsStatus
MpDspUtils::add_I(
const int16_t *pSrc1,
float *pSrc2Dst,
int dataLength)
146 for (
int i=0; i<dataLength; i++)
148 add_I(pSrc2Dst[i], pSrc1[i]);
154 OsStatus
MpDspUtils::add(
const float *pSrc1,
const float *pSrc2,
float *pDst,
int dataLength)
156 for (
int i=0; i<dataLength; i++)
158 pDst[i] =
add(pSrc1[i], pSrc2[i]);
166 for (
int i=0; i<dataLength; i++)
168 add_I(pSrc2Dst[i], pSrc1[i]*val);
175 float *pSrc2Dst,
int dataLength)
177 float step = (valEnd - valStart) / dataLength;
178 float val = valStart;
180 for (
int i=0; i<dataLength; i++, val += step)
182 addMul_I(pSrc2Dst[i], pSrc1[i], val);
187 OsStatus
MpDspUtils::mul(
const int16_t *pSrc,
const float val,
float *pDst,
int dataLength)
189 for (
int i=0; i<dataLength; i++)
191 pDst[i] = pSrc[i]*val;
198 float *pDst,
int dataLength)
205 float step = (valEnd - valStart) / dataLength;
206 float val = valStart;
208 for (
int i=0; i<dataLength; i++, val += step)
210 pDst[i] = pSrc[i] * val;
215 #endif // MP_FIXED_POINT ] 219 int16_t startValue = pSrc[0];
221 startValue = -startValue;
223 for (
int i = 1; i < dataLength; i++)
225 startValue =
maximum(startValue,
226 (int16_t)( (pSrc[i] > 0) ? pSrc[i] : -(pSrc[i]) ));
233 int16_t val = pSrc[0];
234 for (
int i = 0; i < dataLength; i++)
243 int32_t val = pSrc[0];
244 for (
int i = 0; i < dataLength; i++)
253 int16_t val = pSrc[0];
254 for (int16_t i = 0; i < dataLength; i++)
263 int32_t val = pSrc[0];
264 for (int32_t i = 0; i < dataLength; i++)
273 int32_t clippedCount = 0;
274 for (int32_t i = 0; i < dataLength; i++)
276 if(pSrc[i] >= INT16_MAX || pSrc[i] <= -INT16_MAX)
282 return(clippedCount);
285 #endif // _MpDspUtilsSumVect_h_ static int maxAbs(const int16_t *pSrc, int dataLength)
Calculate absolute maximum value of array.
Definition: MpDspUtilsSumVect.h:217
static MP_DSP_VECTOR_API OsStatus mul_I(int16_t *pSrcDst, const int16_t val, int dataLength)
Multiply vector by constant with saturation.
static MP_DSP_VECTOR_API OsStatus add_IAtt(const int16_t *pSrc1, int32_t *pSrc2Dst, int dataLength, unsigned src1ScaleFactor)
Attenuate source vector by 2^src1ScaleFactor factor and add it to accumulator.
static int32_t countClippedValues(const int16_t *pSrc, int dataLength)
Find the number of values in vector that are at maximum or minimum 16 bit value.
Definition: MpDspUtilsSumVect.h:271
static void addMul_I(int32_t &a, int16_t b, int16_t c)
Perform (a+=b*c) saturated (32-bit accumulator, 16-bit operands).
Definition: MpDspUtilsSum.h:32
static void add_I(int16_t &a, int16_t b)
Perform (a+=b) saturated (16-bit).
Definition: MpDspUtilsSum.h:27
static int16_t minimum(int16_t a, int16_t b)
Perform minimum value calculation.
Definition: MpDspUtilsSum.h:103
static MP_DSP_VECTOR_API OsStatus addMulLinear_I(const int16_t *pSrc1, int16_t valStart, int16_t valEnd, int32_t *pSrc2Dst, int dataLength)
Multiply source vector by values linearly changing from valStart to valEnd and add it to accumulator ...
Definition: MpDspUtilsSumVect.h:174
static int16_t maximum(int16_t a, int16_t b)
Perform maximum value calculation.
Definition: MpDspUtilsSum.h:108
static MP_DSP_VECTOR_API OsStatus mulLinear(const int16_t *pSrc, int16_t valStart, int16_t valEnd, int32_t *pDst, int dataLength)
Multiply source vector by values linearly changing from valStart to valEnd and add it to accumulator ...
Definition: MpDspUtilsSumVect.h:197
static int16_t add(int16_t a, int16_t b)
Return (a+b) saturated (16-bit).
Definition: MpDspUtilsSum.h:22
static MP_DSP_VECTOR_API OsStatus add_IGain(const int16_t *pSrc1, int32_t *pSrc2Dst, int dataLength, unsigned src1ScaleFactor)
Gain source vector by 2^src1ScaleFactor factor and add it to accumulator.
static MP_DSP_VECTOR_API OsStatus mul(const int16_t *pSrc, const int16_t val, int32_t *pDst, int dataLength)
Multiply vector by constant.
Definition: MpDspUtilsSumVect.h:187