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

📄 decg722.c

📁 C__ code For Audio Coding
💻 C
📖 第 1 页 / 共 3 页
字号:
//  Purpose:   Recove stdDeviations and absRegPowerIndices from code bits
*F*/
void RecoveStdDeviations(SBitObj* pBitObj, Ipp16s *pStdDeviations,
         Ipp16s *pRegPowerIndices, Ipp16s *pScale) {
   Ipp16s regNum, i;
   Ipp16s index;
   Ipp16s diffIndex[REG_NUM];
   Ipp16s maxIndex;
   Ipp16s temp;

   index = GetNextBits(pBitObj, 5);
   diffIndex[0] = index - ESF_ADJUSTMENT_TO_RMS_INDEX;
   for (regNum=1; regNum<REG_NUM; regNum++) {
      index = 0;
      do {
         index = cnstDiffRegionPowerDecTree_G722[regNum][index][GetNextBits(pBitObj, 1)];
      } while (index > 0);
      diffIndex[regNum] = -index;
   }
   /* Reconstruct absRegPowerIndices[] from diffIndex[]. */
   pRegPowerIndices[0] = diffIndex[0];
   for (regNum=1; regNum<REG_NUM; regNum++)
      pRegPowerIndices[regNum] =
         pRegPowerIndices[regNum-1] + diffIndex[regNum] + DRP_DIFF_MIN;
   /* Reconstruct stdDeviations[] from absRegPowerIndices[]. */
   temp = 0;
   maxIndex = 0;
   for (regNum=0; regNum<REG_NUM; regNum++) {
      i = pRegPowerIndices[regNum] + REG_POW_TABLE_NUM_NEGATIVES;
      if (i > maxIndex)
         maxIndex = i;
      temp += cnstStdDeviation_G722[i];
   }
   i = 9;
   while ((i >= 0) && ((temp >= 8) || (maxIndex > 28))) {
      i--;
      temp>>=1;
      maxIndex -= 2;
   }
   *pScale = i;
   temp = (Ipp16s )(REG_POW_TABLE_NUM_NEGATIVES + 2 * i);
   for (regNum=0; regNum<REG_NUM; regNum++) {
      i = pRegPowerIndices[regNum] + temp;
      pStdDeviations[regNum] = cnstStdDeviation_G722[i];
   }
}

/*F*
//  Name:      ArrangePowerCategories
//  Purpose:   Arrange the power categories based on the categorization control
*F*/
void ArrangePowerCategories(Ipp16s ctgCtrl, Ipp16s* pPowerCtgs, Ipp16s* pCtgBalances){
   Ipp16s regNum, i=0;

   while (ctgCtrl > 0) {
      regNum = pCtgBalances[i++];
      pPowerCtgs[regNum]++;
      ctgCtrl--;
   }
}

/*F*
//  Name:      DecodeBitsToMlt
//  Purpose:   decode the quantized bits into mlt coefs
*F*/
void DecodeBitsToMlt(SBitObj* pBitObj, Ipp16s* pRandVec,
         Ipp16s* pStdDeviations, Ipp16s* pPowerCtgs, Ipp16s* pMlt) {
   Ipp16s stdDeviation;
   Ipp16s *pCurMlt;
   Ipp16s mltValue;
   Ipp16s noifillpos;
   Ipp16s noifillneg;
   Ipp16s regNum, ctgNum, j, n;
   Ipp16s k[MAX_VECTOR_DIMENSION];
   Ipp16s vecDim, nVecs;
   Ipp16s index;
   Ipp16s signsIndex=0;
   Ipp16s bit=0;
   Ipp16s nSignBits;
   Ipp16s outFlag;
   Ipp16s *pDecoderTable;
   Ipp16s randWord;

   outFlag = 0;
   for (regNum=0; regNum<REG_NUM; regNum++) {
      ctgNum = pPowerCtgs[regNum];
      pCurMlt = &pMlt[regNum*REG_SIZE];
      stdDeviation = pStdDeviations[regNum];
      if (ctgNum < 7) {
         pDecoderTable = (Ipp16s *) cnstDecoderTreeTable_G722[ctgNum];
         vecDim = cnstVectorDimentions_G722[ctgNum];
         nVecs = cnstNumberOfVectors_G722[ctgNum];
         for (n=0; n<nVecs; n++) {
            index = 0;
            do {
               if (pBitObj->curBitsNumber <= 0) {
                  outFlag = 1;
                  break;
               }
                index = (Ipp16s)*(pDecoderTable + 2 * index + GetNextBits(pBitObj, 1));
            } while (index > 0);
            if (outFlag != 0)
               break;
            index = -index;
            /* get the number of sign bits */
            nSignBits = ExpandIndexToVector(index, k, ctgNum);
            if (pBitObj->curBitsNumber >= nSignBits) {
               if (nSignBits != 0) {
                  signsIndex = GetNextBits(pBitObj, nSignBits);
                  bit = 1 << (nSignBits-1);
               }
                for (j=0; j<vecDim; j++) {
                  mltValue = (stdDeviation * cnstMLTQuantCentroid_G722[ctgNum][k[j]]) >> 12;
                  if (mltValue != 0) {
                     if ((signsIndex & bit) == 0)
                        mltValue = -mltValue;
                     bit >>= 1;
                  }
                  *pCurMlt++ = mltValue;
               }
            } else {
               outFlag = 1;
               break;
            }
         }

         if (outFlag != 0) {
            /* noise fill */
            for (j=regNum+1; j<REG_NUM; j++)
               pPowerCtgs[j] = 7;
            ctgNum = 7;
            pCurMlt = &pMlt[regNum*REG_SIZE];
         }
      }
      if ((ctgNum == 5) || (ctgNum == 6)){
         pCurMlt = &pMlt[regNum*REG_SIZE];
         noifillpos = (stdDeviation * cnstNoiseFactors_G722[ctgNum - 5])>>15;
         noifillneg = -noifillpos;
         randWord = GetRand(pRandVec);
         for (j=0; j<10; j++) {
            if (*pCurMlt == 0) {
               if ((randWord & 1) == 0)
                  *pCurMlt = noifillneg;
               else
                  *pCurMlt = noifillpos;
               randWord >>= 1;
            }
            pCurMlt++;
         }
         randWord = GetRand(pRandVec);
         for (j=0; j<10; j++) {
            if (*pCurMlt == 0) {
               if ((randWord & 1) == 0)
                  *pCurMlt = noifillneg;
               else
                  *pCurMlt = noifillpos;
               randWord  >>= 1;
            }
            pCurMlt++;
         }
      } else if (ctgNum == 7) {
         index = ctgNum - 5;
         noifillpos = (stdDeviation * cnstNoiseFactors_G722[index])>>15;
         noifillneg = -noifillpos;
         randWord = GetRand(pRandVec);
         for (j=0; j<10; j++) {
            if ((randWord & 1) == 0)
               *pCurMlt++  = noifillneg;
            else
               *pCurMlt++  = noifillpos;
            randWord >>= 1;
         }
         randWord = GetRand(pRandVec);
         for (j=0; j<10; j++) {
            if ((randWord & 1) == 0)
               *pCurMlt++ = noifillneg;
            else
               *pCurMlt++ = noifillpos;
            randWord >>= 1;
         }
      }
   }
   if (outFlag)
      pBitObj->curBitsNumber--;
}

/*F*
//  Name:      ExpandIndexToVector
//  Purpose:   Computes a vector of sign bits with the length of the category vector
//             Returns the number of sign bits in the vector
*F*/
Ipp16s ExpandIndexToVector(Ipp16s index, Ipp16s* pVector, Ipp16s ctgNumber){
   Ipp16s i, q, p;
   Ipp16s maxBin, maxBinInv;
   Ipp16s nSignBits = 0;

   maxBin = cnstMaxBin_G722[ctgNumber] + 1;
   maxBinInv = cnstMaxBinInverse_G722[ctgNumber];
   p = index;
   for (i=cnstVectorDimentions_G722[ctgNumber] - 1; i>=0; i--){
      q = (p * maxBinInv)>>15;
      pVector[i] = p - q * maxBin;
      p = q;
      if (pVector[i] != 0)
         nSignBits++;
   }
   return nSignBits;
}

/*F*
//  Name:      TestFrame
//  Purpose:   Tests frame for error conditions and sets the errFlag accordingly
*F*/
void TestFrame(SBitObj* pBitObj, Ipp16s errFlag,
                         Ipp16s ctgCtrl, Ipp16s *pRegPowerIndices){
   Ipp16s i;

   if (pBitObj->curBitsNumber > 0){
      for (i=0; i<pBitObj->curBitsNumber; i++){
         GetNextBit(pBitObj);
         if (pBitObj->nextBit == 0)
            errFlag = 1;
      }
   } else {
      if ((ctgCtrl < CAT_CONTROL_NUM-1) &&
         (pBitObj->curBitsNumber < 0))
         errFlag |= 2;
   }
   /* checks stdDeviations  */

   for (i=0; i<REG_NUM; i++){
      if ((pRegPowerIndices[i] > 31 - ESF_ADJUSTMENT_TO_RMS_INDEX) ||
         (pRegPowerIndices[i] < -8 - ESF_ADJUSTMENT_TO_RMS_INDEX))
         errFlag |= 4; /* error flag  */
   }
}

/*F*
//  Name:      ProcessErrors
//  Purpose:   For error in current frame repeat the previous mlt.
//             Otherwise, set the mlt coefficients to 0.
*F*/
void ProcessErrors(Ipp16s* pErrFlag, Ipp16s* pMlt, Ipp16s* pOldMlt,
                    Ipp16s* pScale, Ipp16s* pOldScale){
   if (*pErrFlag != 0) {
      ippsCopy_16s(pOldMlt, pMlt, NUMBER_OF_VALID_COEFS);
      ippsZero_16s(pOldMlt, NUMBER_OF_VALID_COEFS);
      *pScale = *pOldScale;
      *pOldScale = 0;
   } else {
      ippsCopy_16s(pMlt, pOldMlt, NUMBER_OF_VALID_COEFS);
      *pOldScale = *pScale;
   }
   ippsZero_16s(&pMlt[NUMBER_OF_VALID_COEFS], DCT_LENGTH-NUMBER_OF_VALID_COEFS);
}

⌨️ 快捷键说明

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