⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owng723.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 5 页
字号:
    11628,   8568,   6188,   4368,   3003,  2002,   1287,    792,    462,    252,
      126,     56,     21,      6,      1,     0,      0,      0,      0,      0,
    23751,  20475,  17550,  14950,  12650, 10626,   8855,   7315,   5985,   4845,
     3876,   3060,   2380,   1820,   1365,  1001,    715,    495,    330,    210,
      126,     70,     35,     15,      5,     1,      0,      0,      0,      0,
     3654,   3276,   2925,   2600,   2300,  2024,   1771,   1540,   1330,   1140,
      969,    816,    680,    560,    455,   364,    286,    220,    165,    120,
       84,     56,     35,     20,     10,     4,      1,      0,      0,      0,
      406,    378,    351,    325,    300,   276,    253,    231,    210,    190,
      171,    153,    136,    120,    105,    91,     78,     66,     55,     45,
       36,     28,     21,     15,     10,     6,      3,      1,      0,      0,
       29,     28,     27,     26,     25,    24,     23,     22,     21,     20,
       19,     18,     17,     16,     15,    14,     13,     12,     11,     10,
        9,      8,      7,      6,      5,     4,      3,      2,      1,      0,
        1,      1,      1,      1,      1,     1,      1,      1,      1,      1,
        1,      1,      1,      1,      1,     1,      1,      1,      1,      1,
        1,      1,      1,      1,      1,     1,      1,      1,      1,      1
};

static __ALIGN32 CONST int MaxPosition[4] = {593775, 142506, 593775, 142506};

static __ALIGN32 CONST short PitchContrb[2*170] = {
    60,      0,     0,  2489,     60,     0,      0,  5217,      1,  6171,      0,   3953,     0,  10364,     1,  9357,     -1,   8843,     1,  9396,
     0,   5794,    -1, 10816,      2, 11606,     -2, 12072,      0,  8616,      1,  12170,     0,  14440,     0,  7787,     -1,  13721,     0, 18205,
     0,  14471,     0, 15807,      1, 15275,      0, 13480,     -1, 18375,     -1,      0,     1,  11194,    -1, 13010,      1,  18836,    -2, 20354,
     1,  16233,    -1,     0,     60,     0,      0, 12130,      0, 13385,      1,  17834,     1,  20875,     0, 21996,      1,      0,     1, 18277,
    -1,  21321,     1, 13738,     -1, 19094,     -1, 20387,     -1,     0,      0,  21008,    60,      0,    -2, 22807,      0,  15900,     1,     0,
     0,  17989,    -1, 22259,      1, 24395,      1, 23138,      0, 23948,      1,  22997,     2,  22604,    -1, 25942,      0,  26246,     1, 25321,
     0,  26423,     0, 24061,      0, 27247,     60,     0,     -1, 25572,      1,  23918,     1,  25930,     2, 26408,     -1,  19049,     1, 27357,
    -1,  24538,    60,     0,     -1, 25093,      0, 28549,      1,     0,      0,  22793,    -1,  25659,     0, 29377,      0,  30276,     0, 26198,
     1,  22521,    -1, 28919,      0, 27384,      1, 30162,     -1,     0,      0,  24237,    -1,  30062,     0, 21763,      1,  30917,    60,     0,
     0,  31284,     0, 29433,      1, 26821,      1, 28655,      0, 31327,      2,  30799,     1,  31389,     0, 32322,      1,  31760,    -2, 31830,
     0,  26936,    -1, 31180,      1, 30875,      0, 27873,     -1, 30429,      1,  31050,     0,      0,     0, 31912,      1,  31611,     0, 31565,
     0,  25557,     0, 31357,     60,     0,      1, 29536,      1, 28985,     -1,  26984,    -1,  31587,     2, 30836,     -2,  31133,     0, 30243,
    -1,  30742,    -1, 32090,     60,     0,      2, 30902,     60,     0,      0,  30027,     0,  29042,    60,     0,      0,  31756,     0, 24553,
     0,  25636,    -2, 30501,     60,     0,     -1, 29617,      0, 30649,     60,      0,     0,  29274,     2, 30415,      0,  27480,     0, 31213,
    -1,  28147,     0, 30600,      1, 31652,      2, 29068,     60,     0,      1,  28571,     1,  28730,     1, 31422,      0,  28257,     0, 24797,
    60,      0,     0,     0,     60,     0,      0, 22105,      0, 27852,     60,      0,    60,      0,    -1, 24214,      0,  24642,     0, 23305,
    60,      0,    60,     0,      1, 22883,      0, 21601,     60,     0,      2,  25650,    60,      0,    -2, 31253,     -2,  25144,     0, 17998
};

static __ALIGN32 CONST short NPulse[4] =
{6,5,
 6,5};

void FixedCodebookVector_G723_16s( int lDecPos, int lAmplitude, int mamp, int lGrid,
       int lGain, int lNSbfr, G723_Rate currRate, Ipp16s *pDst, int *pLag, Ipp16s *pGain )

{
   int   i, j, lTmp, lOffset, lPos;
   short sCdbkGain, sCdbkSign, sCdbkShift, sCdbkPos;

   ippsZero_16s(pDst,G723_SBFR_LEN);

   switch(currRate)  {
      case G723_Rate63: {
         if ( lDecPos < MaxPosition[lNSbfr] ){
            /* Decode the amplitudes and positions */

            j = N_PULSES - NPulse[lNSbfr] ;
            lTmp = lDecPos ;
            for ( i = 0 ; i < G723_SBFR_LEN/GRIDSIZE ; i ++ )  {
               lTmp -= CombTbl[j*COMBTBL_LINE_LEN + i];
               if ( lTmp < 0 ) {
                  lTmp += CombTbl[(j++)*COMBTBL_LINE_LEN+i];
                  if ( (lAmplitude & (1 << (N_PULSES-j) )) !=  0 )
                     pDst[lGrid + GRIDSIZE*i] = GainDBLvls[mamp] ;
                  else
                     pDst[lGrid + GRIDSIZE*i] = -GainDBLvls[mamp] ;

                  if ( j == N_PULSES ) break ;
               }
            }
         }
         break;
      }

      case G723_Rate53: {
         sCdbkGain = -GainDBLvls[mamp];
         sCdbkShift = lGrid;
         sCdbkSign = lAmplitude<<1;
         sCdbkPos = (short) lDecPos;

         for(lOffset=0; lOffset<8; lOffset+=2) {
            lPos = (sCdbkPos & 0x7) ;
            lPos = (lPos<<3) + sCdbkShift + lOffset;
            if (lPos < G723_SBFR_LEN)
               pDst[lPos] = sCdbkGain * ((sCdbkSign & 2 ) - 1);
            sCdbkPos >>= 3;
            sCdbkSign >>= 1;
         }

         *pLag = PitchContrb[lGain<<1];
         *pGain = PitchContrb[(lGain<<1) + 1];
         break;
      }
   }
}

void ResidualInterpolation_G723_16s_I
        (Ipp16s *pSrcDst, Ipp16s *pDst,  int lag, Ipp16s gain, Ipp16s *pSeed)
{
   int   i;
   if ( lag ) {/* Voiced case*/
      for ( i = 0 ; i < lag ; i ++ ){ /* attenuation  */
         pSrcDst[G723_MAX_PITCH+i-lag] = (pSrcDst[G723_MAX_PITCH+i-lag] * 0x6000)>>15;
      }
      ippsCopy_16s(&pSrcDst[G723_MAX_PITCH-lag],&pSrcDst[G723_MAX_PITCH],G723_FRM_LEN);
      ippsCopy_16s(&pSrcDst[G723_MAX_PITCH],pDst,G723_FRM_LEN);
   } else {/* Unvoiced case*/
      for ( i = 0 ; i < G723_FRM_LEN ; i ++ )
         pDst[i] = (gain * Rand2_16s(pSeed))>>15;
      /* reset memory */
      ippsZero_16s(pSrcDst,G723_FRM_LEN+G723_MAX_PITCH);
   }
   return;
}

static __ALIGN32 CONST short BetaTbl[2*170] = {
  1024,  1024,   1308,  1591,   1906, 1678,   2291, 1891,   2511,  2120,
  2736,  2399,   3298,  2966,   3489, 3049,   3531, 3185,   3844,  3317,
  4360,  3433,   4541,  3523,   4684, 3729,   4813, 3779,   5069,  3789,
  5528,  4262,   5577,  4450,   5713, 4469,   5923, 4713,   5958,  4944,
  5958,  4950,   6064,  4980,   6132, 5010,   6331, 5032,   6370,  5299,
  6527,  5389,   6533,  5389,   6575, 5389,   6633, 5646,   6671,  5701,
  6832,  5733,   6832,  5765,   6972, 5997,   6996, 5997,   7199,  6150,
  7205,  6211,   7414,  6336,   7529, 6360,   7543, 6415,   7543,  6415,
  7692,  6430,   7758,  6440,   7839, 6461,   7839, 6461,   7869,  6512,
  7992,  6601,   8000,  6787,   8016, 6872,   8055, 6931,   8079,  6972,
  8119,  6984,   8208,  7056,   8250, 7056,   8266, 7105,   8291,  7117,
  8300,  7123,   8325,  7136,   8402, 7161,   8445, 7167,   8605,  7180,
  8623,  7180,   8687,  7262,   8752, 7308,   8837, 7334,   8847,  7334,
  8973,  7387,   9002,  7407,   9012, 7434,   9184, 7441,   9593,  7441,
  9672,  7481,   9752,  7536,   9846, 7564,   9978, 7592,  10139,  7685,
 10202,  7714,  10317,  7758,  10476, 7772,  10598, 7794,  10598,  7802,
 10695,  7817,  11425,  7839,  11670, 7869,  14629, 7885,  15255,  7907,
     0,  7946,      0,  7992,      0, 8039,      0, 8063,      0,  8087,
     0,  8087,      0,  8167,      0, 8184,      0, 8200,      0,  8200,
     0,  8241,      0,  8266,      0, 8283,      0, 8308,      0,  8308,
     0,  8334,      0,  8376,      0, 8402,      0, 8463,      0,  8516,
     0,  8524,      0,  8533,      0, 8641,      0, 8669,      0,  8696,
     0,  8752,      0,  8761,      0, 8799,      0, 8828,      0,  8943,
     0,  9112,      0,  9122,      0, 9133,      0, 9153,      0,  9288,
     0,  9299,      0,  9373,      0, 9384,      0, 9384,      0,  9405,
     0,  9416,      0,  9471,      0, 9503,      0, 9559,      0,  9581,
     0,  9660,      0,  9660,      0, 9718,      0, 9799,      0,  9823,
     0,  9846,      0,  9846,      0, 9930,      0,10039,      0, 10164,
     0, 10227,      0, 10291,      0,10436,      0,10503,      0, 10516,
     0, 10530,      0, 10598,      0,10611,      0,10625,      0, 11040,
     0, 11070,      0, 11100,      0,11115,      0,11315,      0, 11331,
     0, 11804,      0, 12100,      0,12263,      0,12263,      0, 12300,
     0, 12337,      0, 12431,      0,12800,      0,12962,      0, 13065,
     0, 13496,      0, 13815,      0,14100,      0,14198,      0, 18409
};

void ErrorUpdate_G723(int *pError, short openLoopLag, short AdCbbkLag, short AdCbbkGain, G723_Rate currRate)
{
    int ilag, lag, e0, e1, li0=0,li1=0;
    short sBeta;

    lag = openLoopLag - 1 + AdCbbkLag;

    AdCbbkGain<<=1;
    if ( currRate == G723_Rate63) {
        if ( openLoopLag >= (G723_SBFR_LEN-2) ) AdCbbkGain++;
    } else {
        AdCbbkGain++;
    }
    sBeta = BetaTbl[AdCbbkGain];

    if(lag > 30) {
        ilag = (lag * 273)>>13;   /*  x 1/30 */
        if(30*(ilag+1) != lag) {
            if(ilag == 1) {
               if(pError[0] <= pError[1]){
                  li0 = 1;
                  li1 = 1;
               }
            }else {
               li0 = ilag-2;
               li1 = ilag-1;
               if(pError[li1] > pError[li0]){
                  li0 = li1;
               }
               if(pError[li1] <= pError[ilag]){
                  li1 = ilag;
               }
            }
        }
        else {  /* lag = 60, 90, 120 */
           li0 = ilag-1;
           li1 = ilag;
        }
    }
    e0 = Add_32s(ShiftL_32s(MulC_32s(sBeta,pError[li0]),2),4);
    e1 = Add_32s(ShiftL_32s(MulC_32s(sBeta,pError[li1]),2),4);
    pError[4] = pError[2];
    pError[3] = pError[1];
    pError[2] = pError[0];
    pError[1] = e1;
    pError[0] = e0;
    return;
}

static void CodewordImpConv_G723(short *pSrc, short *pDst, short *pSrcSign, short *pPos, short* pDstSign, int* ComposedIdx)
{
   int i;
   short sImpPos0, sImpPos1, sImpPos2, sImpPos3;
   short sImpSign0, sImpSign1, sImpSign2, sImpSign3;

   sImpPos0 = pPos[0];
   sImpPos1 = pPos[1];
   sImpPos2 = pPos[2];
   sImpPos3 = pPos[3];

   sImpSign0 = pSrcSign[0];
   sImpSign1 = pSrcSign[1];
   sImpSign2 = pSrcSign[2];
   sImpSign3 = pSrcSign[3];

   /* find codebook index;  17-bit address */

   *pDstSign = 0;
   if(sImpSign0 > 0) *pDstSign=1;
   if(sImpSign1 > 0) *pDstSign += 2;
   if(sImpSign2 > 0) *pDstSign += 4;
   if(sImpSign3 > 0) *pDstSign += 8;

   i = sImpPos0 >> 3;
   i += sImpPos1 & 0xfff8;
   i += (sImpPos2 & 0xfff8) << 3;
   i += (sImpPos3 & 0xfff8) << 6;

   *ComposedIdx = i;

   /* Compute the filtered codeword */

   ippsZero_16s(pDst,G723_SBFR_LEN);

   if (sImpPos0>sImpPos1) {i=sImpPos0; sImpPos0=sImpPos1; sImpPos1=i; i=sImpSign0; sImpSign0=sImpSign1; sImpSign1=i;}
   if (sImpPos2>sImpPos3) {i=sImpPos2; sImpPos2=sImpPos3; sImpPos3=i; i=sImpSign2; sImpSign2=sImpSign3; sImpSign3=i;}
   if (sImpPos0>sImpPos2) {i=sImpPos0; sImpPos0=sImpPos2; sImpPos2=i; i=sImpSign0; sImpSign0=sImpSign2; sImpSign2=i;}
   if (sImpPos1>sImpPos3) {i=sImpPos1; sImpPos1=sImpPos3; sImpPos3=i; i=sImpSign1; sImpSign1=sImpSign3; sImpSign3=i;}
   if (sImpPos1>sImpPos2) {i=sImpPos1; sImpPos1=sImpPos2; sImpPos2=i; i=sImpSign1; sImpSign1=sImpSign2; sImpSign2=i;}

   for (i=0; i<sImpPos0; i++)
      pDst[i]=0;
   for (; i<sImpPos1; i++)
      pDst[i]=sImpSign0*pSrc[i-sImpPos0];
   for (; i<sImpPos2; i++)
      pDst[i]=sImpSign0*pSrc[i-sImpPos0]+sImpSign1*pSrc[i-sImpPos1];
   for (; i<sImpPos3; i++)
      pDst[i]=sImpSign0*pSrc[i-sImpPos0]+sImpSign1*pSrc[i-sImpPos1]+sImpSign2*pSrc[i-sImpPos2];
   for (; i<G723_SBFR_LEN; i++)
      pDst[i]=sImpSign0*pSrc[i-sImpPos0]+sImpSign1*pSrc[i-sImpPos1]+sImpSign2*pSrc[i-sImpPos2]+sImpSign3*pSrc[i-sImpPos3];

   return;
}

void  FixedCodebookSearch_G723_16s(G723Encoder_Obj *encoderObj, ParamStream_G723 *Params, short *pSrcDst, short *ImpResp, short sNSbfr)
{
    short sPitchPeriod, sGain;

    switch(Params->currRate)  {

    case G723_Rate63:
       {
          ippsMPMLQFixedCodebookSearch_G723(Params->PitchLag[sNSbfr>>1], ImpResp, pSrcDst, pSrcDst,
             &Params->sGrid[sNSbfr], &Params->sTrainDirac[sNSbfr], &Params->sAmpIndex[sNSbfr], &Params->sAmplitude[sNSbfr], &Params->sPosition[sNSbfr], sNSbfr);
          break;
        }

    case G723_Rate53:
       {
          short sCurrGrid, sSign, sGainCoeff;
          int lCdbkIdx, lGainIdx;

          LOCAL_ALIGN_ARRAY(16, short, pTargetImpRespCorr, G723_SBFR_LEN+4, encoderObj) ;
          LOCAL_ALIGN_ARRAY(16, short, pFixedVector,       G723_SBFR_LEN+4, encoderObj) ;
          LOCAL_ALIGN_ARRAY(16, short, pFltFixedVector,    G723_SBFR_LEN+4, encoderObj) ;
          LOCAL_ALIGN_ARRAY(16, int,   pToeplizMatrix,     G723_TOEPLIZ_MATRIX_SIZE, encoderObj) ;
          LOCAL_ALIGN_ARRAY(16, short, pAlignBuff,         G723_SBFR_LEN, encoderObj) ;
          LOCAL_ARRAY(short, pDstFixedSign,    4, encoderObj) ;
          LOCAL_ARRAY(short, pDstFixedPosition,4, encoderObj) ;

          sPitchPeriod = Params->PitchLag[sNSbfr>>1]-1+Params->AdCdbkLag[sNSbfr] + PitchContrb[Params->AdCdbkGain[sNSbfr]<<1];
          sGain = PitchContrb[(Params->AdCdbkGain[sNSbfr]<<1)+1];

          /* Find correlations of h[] needed for the codebook search. */
          ippsRShiftC_16s_I(1,ImpResp,G723_SBFR_LEN); /* Q13 -->  Q12*/
          if (sPitchPeriod < G723_SBFR_LEN-2) {
              ippsHarmonicFilter_16s_I(sGain,sPitchPeriod,&ImpResp[sPitchPeriod],G723_SBFR_LEN-sPitchPeriod);
          }
          /* Compute correlation of target vector with impulse response. */

          ippsCrossCorr_NormM_16s(ImpResp, pSrcDst, G723_SBFR_LEN, pTargetImpRespCorr);
          /* Compute the covariance matrix of the impulse response. */
          ippsToeplizMatrix_G723_16s32s(ImpResp, pToeplizMatrix);

          /* Find innovative codebook (filtered codeword) */
          ippsACELPFixedCodebookSearch_G723_32s16s(pTargetImpRespCorr, pToeplizMatrix, pDstFixedSign, pDstFixedPosition, &sCurrGrid, pFixedVector, &encoderObj->sSearchTime);

          CodewordImpConv_G723(ImpResp, pFltFixedVector, pDstFixedSign, pDstFixedPosition, &sSign, &lCdbkIdx);
          /* Compute innovation vector gain */
          FixedCodebookGain_G723_16s(pSrcDst,pFltFixedVector,&sGainCoeff,&lGainIdx,pAlignBuff);

          ippsMulC_16s_Sfs(pFixedVector,sGainCoeff,pSrcDst,G723_SBFR_LEN,0);
          if(sPitchPeriod < G723_SBFR_LEN-2)
              ippsHarmonicFilter_16s_I(sGain,sPitchPeriod,&pSrcDst[sPitchPeriod],G723_SBFR_LEN-sPitchPeriod);

          Params->sTrainDirac[sNSbfr] = 0;
          Params->sAmpIndex[sNSbfr] = lGainIdx;
          Params->sGrid[sNSbfr] = sCurrGrid;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -