10 #ifndef _MpDspUtils_h_ 11 #define _MpDspUtils_h_ 14 #define MP_FIXED_POINT 18 #define MP_DSP_INLINE_VECTOR_FUNCTIONS 20 #ifdef MP_DSP_INLINE_VECTOR_FUNCTIONS // [ 21 # define MP_DSP_VECTOR_API inline 22 #else // MP_DSP_INLINE_VECTOR_FUNCTIONS ][ 23 # define MP_DSP_VECTOR_API 24 #endif // MP_DSP_INLINE_VECTOR_FUNCTIONS ] 28 #include <os/OsStatus.h> 29 #include <os/OsIntTypes.h> 30 #ifdef MP_FIXED_POINT // [ 32 #endif // MP_FIXED_POINT ] 35 #define MPF_SIGN_BIT16 (1<<15) 36 #define MPF_SIGN_BIT32 (1<<31) 39 #ifdef MP_FIXED_POINT // [ 40 # define MPF_FLOAT(num, intLength, fracLength) (floor((num)*(float)(1<<(fracLength)))) 41 #else // MP_FIXED_POINT ][ 42 # define MPF_FLOAT(num, intLength, fracLength) (num) 43 #endif // MP_FIXED_POINT ] 45 #define MPF_STEP(intLength, fracLength) MPF_FLOAT(1.0/(1<<(fracLength)), (intLength), (fracLength)) 46 #define MPF_MAX(intLength, fracLength) MPF_FLOAT((1<<(intLength))-1.0/(1<<(fracLength)), (intLength), (fracLength)) 55 #define MPF_SATURATE(val, maxval) ((val)>=(maxval) ? (maxval) : (val)<-(maxval) ? -(maxval) : (val)) 60 #define MPF_SATURATE16(val) MPF_SATURATE(val, INT16_MAX) 65 #define MPF_SATURATE32(val) MPF_SATURATE(val, INT32_MAX) 71 #define MPF_EXTRACRT16(val) ((int16_t)(val)) 131 int16_t
add(int16_t a, int16_t b);
135 void add_I(int16_t &a, int16_t b);
139 int32_t
add(int32_t a, int32_t b);
143 void add_I(int32_t &a, int32_t b);
147 void addMul_I(int32_t &a, int16_t b, int16_t c);
149 #ifndef MP_FIXED_POINT // [ 153 float maximum(
float a,
float b);
157 float add(
float a,
float b);
161 void add_I(
float &a,
float b);
165 void addMul_I(
float &a,
float b,
float c);
167 #endif // !MP_FIXED_POINT ] 171 int16_t
abs(int16_t a);
181 int16_t
minimum(int16_t a, int16_t b);
185 int16_t
maximum(int16_t a, int16_t b);
189 int32_t
abs(int32_t a);
199 int32_t
minimum(int32_t a, int32_t b);
203 int32_t
maximum(int32_t a, int32_t b);
207 uint32_t
sqrt(uint32_t val);
242 void shl16_I(int32_t &a,
unsigned scale);
248 int32_t
shl16(int32_t a,
unsigned scale);
254 void shl32_I(int32_t &a,
unsigned scale);
260 int32_t
shl32(int32_t a,
unsigned scale);
271 #ifdef MP_FIXED_POINT // [ 275 OsStatus
add_I(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength);
279 OsStatus
add_IGain(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor);
283 OsStatus
add_IAtt(
const int16_t *pSrc1, int32_t *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor);
287 OsStatus
add(
const int32_t *pSrc1,
const int32_t *pSrc2, int32_t *pDst,
int dataLength);
294 OsStatus
addMul_I(
const int16_t *pSrc1, int16_t val, int32_t *pSrc2Dst,
int dataLength);
299 OsStatus
addMulLinear_I(
const int16_t *pSrc1, int16_t valStart, int16_t valEnd,
300 int32_t *pSrc2Dst,
int dataLength);
310 OsStatus
mul(
const int16_t *pSrc,
const int16_t val, int32_t *pDst,
int dataLength);
317 OsStatus
mul_I(int16_t *pSrcDst,
const int16_t val,
int dataLength);
325 OsStatus
mulLinear(
const int16_t *pSrc, int16_t valStart, int16_t valEnd,
326 int32_t *pDst,
int dataLength);
334 #else // MP_FIXED_POINT ][ 338 OsStatus
add_I(
const int16_t *pSrc1,
float *pSrc2Dst,
int dataLength);
342 OsStatus
add_IGain(
const int16_t *pSrc1,
float *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor)
344 return add_I(pSrc1, pSrc2Dst, dataLength);
349 OsStatus
add_IAtt(
const int16_t *pSrc1,
float *pSrc2Dst,
int dataLength,
unsigned src1ScaleFactor)
351 return add_I(pSrc1, pSrc2Dst, dataLength);
356 OsStatus
add(
const float *pSrc1,
const float *pSrc2,
float *pDst,
int dataLength);
363 OsStatus
addMul_I(
const int16_t *pSrc1,
float val,
float *pSrc2Dst,
int dataLength);
368 OsStatus
addMulLinear_I(
const int16_t *pSrc1,
float valStart,
float valEnd,
369 float *pSrc2Dst,
int dataLength);
376 OsStatus
mul(
const int16_t *pSrc,
const float val,
float *pDst,
int dataLength);
384 OsStatus
mulLinear(
const int16_t *pSrc,
float valStart,
float valEnd,
385 float *pDst,
int dataLength);
393 #endif // MP_FIXED_POINT ] 397 int maxAbs(
const int16_t *pSrc,
int dataLength);
404 int16_t
maximum(
const int16_t *pSrc,
int dataLength);
408 int32_t
maximum(
const int32_t *pSrc,
int dataLength);
412 int16_t
minimum(
const int16_t *pSrc,
int dataLength);
416 int32_t
minimum(
const int32_t *pSrc,
int dataLength);
428 #ifdef MP_FIXED_POINT // [ 432 OsStatus
convert(
const int32_t *pSrc, int16_t *pDst,
int dataLength);
436 OsStatus
convert_Gain(
const int32_t *pSrc, int16_t *pDst,
int dataLength,
unsigned srcScaleFactor);
440 OsStatus
convert_Att(
const int32_t *pSrc, int16_t *pDst,
int dataLength,
unsigned srcScaleFactor);
444 OsStatus
convert(
const int16_t *pSrc, int32_t *pDst,
int dataLength);
451 OsStatus
convert_Gain(
const int16_t *pSrc, int32_t *pDst,
int dataLength,
unsigned srcScaleFactor);
458 OsStatus
convert_Att(
const int16_t *pSrc, int32_t *pDst,
int dataLength,
unsigned srcScaleFactor);
463 #else // MP_FIXED_POINT ][ 467 OsStatus
convert(
const float *pSrc, int16_t *pDst,
int dataLength);
471 OsStatus
convert_Gain(
const float *pSrc, int16_t *pDst,
int dataLength,
unsigned srcScaleFactor)
473 return convert(pSrc, pDst, dataLength);
478 OsStatus
convert_Att(
const float *pSrc, int16_t *pDst,
int dataLength,
unsigned srcScaleFactor)
480 return convert(pSrc, pDst, dataLength);
485 OsStatus
convert(
const int16_t *pSrc,
float *pDst,
int dataLength)
490 const int16_t* srcIntPtr = pSrc;
491 float* dstFloatPtr = pDst;
492 for(
int dataIndex = 0; dataIndex < dataLength; dataIndex++)
494 *dstFloatPtr = float(*srcIntPtr);
503 OsStatus
convert_Gain(
const int16_t *pSrc,
float *pDst,
int dataLength,
unsigned srcScaleFactor)
505 return convert(pSrc, pDst, dataLength);
510 OsStatus
convert_Att(
const int16_t *pSrc,
float *pDst,
int dataLength,
unsigned srcScaleFactor)
512 return convert(pSrc, pDst, dataLength);
515 #endif // MP_FIXED_POINT ] 530 #endif // _MpDspUtils_h_ static void shl16_I(int32_t &a, unsigned scale)
Definition: MpDspUtilsShift.h:25
static uint32_t sqrt(uint32_t val)
Integer square root.
Definition: MpDspUtilsIntSqrt.h:33
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 convert_Gain(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
Gain vector of 32-bit integers and convert them to 16-bit integers.
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.
#define MP_DSP_VECTOR_API
Definition: MpDspUtils.h:21
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 MP_DSP_VECTOR_API OsStatus convert(const int32_t *pSrc, int16_t *pDst, int dataLength)
Convert vector of 32-bit integers to 16-bit integers.
static int compareSerials(uint32_t val1, uint32_t val2)
Is val1 bigger, equal or lesser then val2.
Definition: MpDspUtilsSerials.h:35
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 int32_t shl16(int32_t a, unsigned scale)
Definition: MpDspUtilsShift.h:30
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 int16_t abs(int16_t a)
Perform absolute value calculation with saturation.
Definition: MpDspUtilsSum.h:97
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
Class for generic DSP functions.
Definition: MpDspUtils.h:120
static void shl32_I(int32_t &a, unsigned scale)
Definition: MpDspUtilsShift.h:38
static int16_t add(int16_t a, int16_t b)
Return (a+b) saturated (16-bit).
Definition: MpDspUtilsSum.h:22
static int32_t shl32(int32_t a, unsigned scale)
Definition: MpDspUtilsShift.h:43
static MP_DSP_VECTOR_API OsStatus convert_Att(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
Attenuate vector of 32-bit integers and convert them to 16-bit integers.
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