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

📄 dtx.c

📁 GSM中半速率语音编解码源码
💻 C
📖 第 1 页 / 共 3 页
字号:
 *     ppL_CorrHistory[OVERHANG][NP+1] - - history of the OVERHANG
 *     frames worth of pL_UnqntzdCorr[].
 *
 *   RETURN VALUE:
 *
 *     none
 *
 *************************************************************************/

void   updateCNHist(Longword L_UnqntzdR0,
                           Longword *pL_UnqntzdCorr,
                           Longword pL_R0History[],
                           Longword ppL_CorrHistory[OVERHANG][NP + 1])
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/

  int    i;


/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  /* update */
  pL_R0History[siUpdPointer] = L_UnqntzdR0;

  for (i = 0; i < NP + 1; i++)
    ppL_CorrHistory[siUpdPointer][i] = pL_UnqntzdCorr[i];

  siUpdPointer = (siUpdPointer + 1) % OVERHANG;
}


/*************************************************************************
 *
 *   FUNCTION NAME: avgGsHistQntz
 *
 *   PURPOSE:
 *
 *     Average gs history, where history is of length OVERHANG-1
 *     frames.  The last frame's (i.e. this frame) gs values are not
 *     available since quantization would have occured only after the
 *     VAD decision is made.
 *
 *   INPUTS:
 *
 *     pL_GsHistory[(OVERHANG-1)*N_SUB] - the GS of the past
 *     OVERHANG-1 frames. The GS values are stored shifted down by 2
 *     shifts to avoid overflow (the largest GS is greater than 2.0).
 *
 *
 *   OUTPUTS:
 *
 *     *pL_GsAvgd - the average of pL_GsHistory[], also shifted down
 *     by two shifts.
 *
 *   RETURN VALUE:
 *
 *     none.
 *
 *
 *************************************************************************/

void   avgGsHistQntz(Longword pL_GsHistory[], Longword *pL_GsAvgd)
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/

  int    i;
  Longword L_avg;

/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  L_avg = L_shift_r(pL_GsHistory[0], -(OH_SHIFT + 2));

  for (i = 1; i < N_SUB * (OVERHANG - 1); i++)
    L_avg = L_add(L_shift_r(pL_GsHistory[i], -(OH_SHIFT + 2)), L_avg);

  /* avg number x/32 not x/28 */

  *pL_GsAvgd = L_add(L_avg, L_mpy_ls(L_avg, 0x1249));   /* L_avg *= 32/28 */

}


/*************************************************************************
 *
 *   FUNCTION NAME: gsQuant
 *
 *   PURPOSE:
 *
 *     Quantize a value of gs in any of the voicing modes.  Input GS
 *     is a 32 bit number.  The GSP0 index is returned.
 *
 *   INPUTS:
 *
 *     L_GsIn - 32 bit GS value,  shifted down by 2 shifts.
 *
 *     swVoicingMode - voicing level
 *
 *     ppLr_gsTable[4][32] - Rom GS Table. (global), all GS values
 *     have been shifted down by 2 from their true value.
 *
 *   OUTPUTS:
 *
 *     none
 *
 *   RETURN VALUE:
 *
 *
 *     GSP0 Index closest to the input value of GS.
 *
 *
 *************************************************************************/

Shortword gsQuant(Longword L_GsIn, Shortword swVoicingMode)
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/

  Shortword swGsIndex,
         swBestGs;
  Longword L_diff,
         L_min = LW_MAX;


/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  for (swGsIndex = 0; swGsIndex < 32; swGsIndex++)
  {
    L_diff = L_abs(L_sub(L_GsIn, ppLr_gsTable[swVoicingMode][swGsIndex]));

    if (L_sub(L_diff, L_min) < 0)
    {
      /* new minimum */
      /* ----------- */

      swBestGs = swGsIndex;
      L_min = L_diff;

    }
  }

  return (swBestGs);

}


/*************************************************************************
 *
 *   FUNCTION NAME: avgCNHist
 *
 *   PURPOSE:
 *
 *     Average the unquantized R0 and LPC data stored at the encoder
 *     to arrive at an average R0 and LPC frame for use in a SID
 *     frame.
 *
 *   INPUTS:
 *
 *   pL_R0History[OVERHANG] - contains unquantized R(0) data from the
 *   most recent OVERHANG frame (including this one).
 *
 *   ppL_CorrHistory[OVERHANG][NP+1] - Unquantized correlation
 *   coefficients from the most recent OVERHANG frame (including this
 *   one).  The data stored here is an output of FLAT.
 *
 *   OUTPUTS:
 *
 *   *pL_AvgdR0 - the average of pL_R0History[]
 *
 *   pL_AvgdCorrSeq[NP+1] - the average of ppL_CorrHistory[][].
 *
 *
 *   RETURN VALUE:
 *
 *     none
 *
 *************************************************************************/

void   avgCNHist(Longword pL_R0History[],
                        Longword ppL_CorrHistory[OVERHANG][NP + 1],
                        Longword *pL_AvgdR0,
                        Longword pL_AvgdCorrSeq[])
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/

  int    i,
         j;
  Longword L_avg;

/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  /* R0 Averaging */
  /* ------------ */

  for (L_avg = 0, i = 0; i < OVERHANG; i++)
    L_avg = L_add(L_shr(pL_R0History[i], OH_SHIFT), L_avg);

  *pL_AvgdR0 = L_avg;


  /* LPC: average the last OVERHANG frames */
  /* ------------------------------------- */

  for (j = 0; j < NP + 1; j++)
  {
    for (L_avg = 0, i = 0; i < OVERHANG; i++)
    {
      L_avg = L_add(L_shift_r(ppL_CorrHistory[i][j], -OH_SHIFT), L_avg);
    }

    pL_AvgdCorrSeq[j] = L_avg;
  }

}


/***************************************************************************
 *
 *    FUNCTION NAME: lpcCorrQntz
 *
 *    PURPOSE:  Quantize a correlation sequence
 *
 *
 *    INPUT:
 *
 *         pL_CorrelSeq[NP+1]
 *                     Correlation sequence to quantize.
 *
 *    OUTPUTS:
 *
 *        pswFinalRc[0:NP-1]
 *                     A quantized set of NP reflection coefficients.
 *
 *        piVQCodewds[0:2]
 *                     An array containing the indices of the 3 reflection
 *                     coefficient vectors selected from the three segment
 *                     Rc-VQ.
 *
 *    RETURN:
 *        None.
 *
 *    KEYWORDS: AFLAT,aflat,flat,vectorquantization, reflectioncoefficients
 *
 *************************************************************************/

void   lpcCorrQntz(Longword pL_CorrelSeq[],
                          Shortword pswFinalRc[],
                          int piVQCodewds[])
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/

  Shortword pswPOldSpace[NP_AFLAT],
         pswPNewSpace[NP_AFLAT],
         pswVOldSpace[2 * NP_AFLAT - 1],
         pswVNewSpace[2 * NP_AFLAT - 1],
        *ppswPAddrs[2],
        *ppswVAddrs[2],
        *pswVBar,
         pswPBar[NP_AFLAT],
         pswVBarSpace[2 * NP_AFLAT - 1],
         pswFlatsRc[NP],               /* Unquantized Rc's computed by FLAT */
         pswRc[NP + 1];                /* Temp list for the converted RC's */
  Longword *pL_VBarFull,
         pL_PBarFull[NP],
         pL_VBarFullSpace[2 * NP - 1];

  int    i,
         iVec,
         iSeg,
         iCnt;                         /* Loop counter */
  struct QuantList quantList,          /* A list of vectors */
         bestPql[4];                   /* The four best vectors from
                                        * the PreQ */
  struct QuantList bestQl[LPC_VQ_SEG + 1];      /* Best vectors for each of
                                                 * the three segments */

/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  /* Setup pointers temporary space */
  /*--------------------------------*/

  pswVBar = pswVBarSpace + NP_AFLAT - 1;
  pL_VBarFull = pL_VBarFullSpace + NP - 1;
  ppswPAddrs[0] = pswPOldSpace;
  ppswPAddrs[1] = pswPNewSpace;
  ppswVAddrs[0] = pswVOldSpace + NP_AFLAT - 1;
  ppswVAddrs[1] = pswVNewSpace + NP_AFLAT - 1;


  /* Set up pL_PBarFull and pL_VBarFull initial conditions, using the   */
  /* autocorrelation sequence derived from the optimal reflection       */
  /* coefficients computed by FLAT. The initial conditions are shifted  */
  /* right by RSHIFT bits. These initial conditions, stored as          */
  /* Longwords, are used to initialize PBar and VBar arrays for the     */
  /* next VQ segment.                                                   */
  /*--------------------------------------------------------------------*/

  initPBarFullVBarFullL(pL_CorrelSeq, pL_PBarFull, pL_VBarFull);

  /* Set up initial PBar and VBar initial conditions, using pL_PBarFull */
  /* and pL_VBarFull arrays initialized above. These are the initial    */
  /* PBar and VBar conditions to be used by the AFLAT recursion at the  */
  /* 1-st Rc-VQ segment.                                                */
  /*--------------------------------------------------------------------*/

  initPBarVBarL(pL_PBarFull, pswPBar, pswVBar);

  for (iSeg = 1; iSeg <= LPC_VQ_SEG; iSeg++)
  {
    /* initialize candidate list */
    /*---------------------------*/

    quantList.iNum = psrPreQSz[iSeg - 1];
    quantList.iRCIndex = 0;

    /* do aflat for all vectors in the list */
    /*--------------------------------------*/

    setupPreQ(iSeg, quantList.iRCIndex);        /* set up vector ptrs */

    for (iCnt = 0; iCnt < quantList.iNum; iCnt++)
    {
      /* get a vector */
      /*--------------*/

      getNextVec(pswRc);

      /* clear the limiter flag */
      /*------------------------*/

      iLimit = 0;

      /* find the error values for each vector */
      /*---------------------------------------*/

      quantList.pswPredErr[iCnt] =
              aflatRecursion(&pswRc[psvqIndex[iSeg - 1].l],
                             pswPBar, pswVBar,
                             ppswPAddrs, ppswVAddrs,
                             psvqIndex[iSeg - 1].len);

      /* check the limiter flag */
      /*------------------------*/

      if (iLimit)
        quantList.pswPredErr[iCnt] = 0x7fff;    /* set error to bad value */

    }                                  /* done list loop */

    /* find 4 best prequantizer levels */
    /*---------------------------------*/

    findBestInQuantList(quantList, 4, bestPql);

    for (iVec = 0; iVec < 4; iVec++)
    {

      /* initialize quantizer list */
      /*---------------------------*/

      quantList.iNum = psrQuantSz[iSeg - 1];
      quantList.iRCIndex = bestPql[iVec].iRCIndex * psrQuantSz[iSeg - 1];

      setupQuant(iSeg, quantList.iRCIndex);     /* set up vector ptrs */

      /* do aflat recursion on each element of list */
      /*--------------------------------------------*/

      for (iCnt = 0; iCnt < quantList.iNum; iCnt++)
      {
        /* get a vector */
        /*--------------*/

        getNextVec(pswRc);

        /* clear the limiter flag */
        /*------------------------*/

        iLimit = 0;

        /* find the error values for each vector */
        /*---------------------------------------*/

        quantList.pswPredErr[iCnt] =
                aflatRecursion(&pswRc[psvqIndex[iSeg - 1].l],
                               pswPBar, pswVBar,
                               ppswPAddrs, ppswVAddrs,
                               psvqIndex[iSeg - 1].len);

        /* check the limiter flag */
        /*------------------------*/

        if (iLimit)
          quantList.pswPredErr[iCnt] = 0x7fff;  /* set error to the worst
                                                 * value */

      }                                /* done list loop */

      /* find best quantizer vector for this segment, and save it */
      /*----------------------------------------------------------*/

      findBestInQuantList(quantList, 1, bestQl);
      if (iVec == 0)
        bestQl[iSeg] = bestQl[0];
      else if (sub(bestQl[iSeg].pswPredErr[0], bestQl[0].pswPredErr[0]) > 0)

⌨️ 快捷键说明

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