sipxmedialib  Version 3.3
MpDspUtilsConvertVect.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2007 SIPez LLC.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>
12 
13 #ifndef _MpDspUtilsConvertVect_h_
14 #define _MpDspUtilsConvertVect_h_
15 
23 /* ============================ INLINE METHODS ============================ */
24 
25 #ifdef MP_FIXED_POINT // [
26 
27 OsStatus MpDspUtils::convert(const int32_t *pSrc, int16_t *pDst, int dataLength)
28 {
29  for (int i=0; i<dataLength; i++)
30  {
31  pDst[i] = MPF_EXTRACRT16(MPF_SATURATE16(pSrc[i]));
32  }
33  return OS_SUCCESS;
34 }
35 
36 OsStatus MpDspUtils::convert_Gain(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
37 {
38  for (int i=0; i<dataLength; i++)
39  {
40  pDst[i] = MPF_EXTRACRT16(shl16(pSrc[i], srcScaleFactor));
41  }
42  return OS_SUCCESS;
43 }
44 
45 OsStatus MpDspUtils::convert_Att(const int32_t *pSrc, int16_t *pDst, int dataLength, unsigned srcScaleFactor)
46 {
47  for (int i=0; i<dataLength; i++)
48  {
49  pDst[i] = MPF_EXTRACRT16(MPF_SATURATE16(pSrc[i]>>srcScaleFactor));
50  }
51  return OS_SUCCESS;
52 }
53 
54 OsStatus MpDspUtils::convert(const int16_t *pSrc, int32_t *pDst, int dataLength)
55 {
56  for (int i=0; i<dataLength; i++)
57  {
58  pDst[i] = pSrc[i];
59  }
60  return OS_SUCCESS;
61 }
62 
63 OsStatus MpDspUtils::convert_Gain(const int16_t *pSrc, int32_t *pDst, int dataLength, unsigned srcScaleFactor)
64 {
65  for (int i=0; i<dataLength; i++)
66  {
67  pDst[i] = shl32((int32_t)pSrc[i], srcScaleFactor);
68  }
69  return OS_SUCCESS;
70 }
71 
72 OsStatus MpDspUtils::convert_Att(const int16_t *pSrc, int32_t *pDst, int dataLength, unsigned srcScaleFactor)
73 {
74  for (int i=0; i<dataLength; i++)
75  {
76  pDst[i] = pSrc[i]>>srcScaleFactor;
77  }
78  return OS_SUCCESS;
79 }
80 
81 #else // MP_FIXED_POINT ][
82 
83 OsStatus MpDspUtils::convert(const float *pSrc, int16_t *pDst, int dataLength)
84 {
85  for (int i=0; i<dataLength; i++)
86  {
87  pDst[i] = MPF_EXTRACRT16(MPF_SATURATE16(pSrc[i]));
88  }
89 
90  return OS_SUCCESS;
91 }
92 
93 #endif // MP_FIXED_POINT ]
94 
95 #endif // _MpDspUtilsConvertVect_h_
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 convert(const int32_t *pSrc, int16_t *pDst, int dataLength)
Convert vector of 32-bit integers to 16-bit integers.
static int32_t shl16(int32_t a, unsigned scale)
Definition: MpDspUtilsShift.h:30
#define MPF_SATURATE16(val)
Saturate val to fit 16-bit signed integer.
Definition: MpDspUtils.h:60
#define MPF_EXTRACRT16(val)
Return 16 bit integer.
Definition: MpDspUtils.h:71
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.