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

📄 ps_dec_parser.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:

    if( 0 == env ){
      pIndxIidPrev = pState->indxIidPrev;
      pIndxIccPrev = pState->indxIccPrev;
      pIndxIpdPrev = pState->indxIpdPrev;
      pIndxOpdPrev = pState->indxOpdPrev;
    } else {
      pIndxIidPrev = pState->indxIid[env-1];
      pIndxIccPrev = pState->indxIcc[env-1];
      pIndxIpdPrev = pState->indxIpd[env-1];
      pIndxOpdPrev = pState->indxOpd[env-1];
    }

    /* first tuning */
    flag = pState->bs_enable_iid;
    dfdt = pState->bs_iid_dt[env];
    nBands = pState->nIidBands;
    offset = (pState->freq_res_iid) ? 1 : 2;
    minIndx= -nGridSteps;
    maxIndx=  nGridSteps;
    pIndxCur = pState->indxIid[env];
    pIndxPrev= pIndxIidPrev;

    for(param = 0; param < 2; param++){
      ownDeltaDecode(pIndxCur, pIndxPrev, flag, dfdt, nBands, offset, minIndx, maxIndx);

      /* second tuning */
      flag = pState->bs_enable_icc;
      dfdt = pState->bs_icc_dt[env];
      nBands = pState->nIccBands;
      offset = (pState->freq_res_icc) ? 1 : 2;
      minIndx= 0;
      maxIndx= 7;
      pIndxCur = pState->indxIcc[env];
      pIndxPrev= pIndxIccPrev;
    }

    /* third tuning */
    flag = pState->bs_enable_ipdopd;
    dfdt = pState->bs_ipd_dt[env];
    nBands = pState->nIpdOpdBands; //tabNumIpdOpdBands[ pState->freq_res_ipd ];
    offset = (pState->freq_res_ipd) ? 1 : 2;
    pIndxCur = pState->indxIpd[env];
    pIndxPrev= pIndxIpdPrev;

    for(param = 0; param < 2; param++){
      ownDeltaDecodeMod(pIndxCur, pIndxPrev, flag, dfdt, nBands, offset);
      /* fourth tuning */
      dfdt = pState->bs_opd_dt[env];
      pIndxCur = pState->indxOpd[env];
      pIndxPrev= pIndxOpdPrev;
    }
  } // end for(env = 0;

  /* [2] case nEnv == 0, we use info from prev frame */
  if( 0 == pState->nEnv ){
    /* IID */
    ownIndxUpdate(pState->indxIidPrev, pState->indxIid[0], 34, pState->bs_enable_iid);
    /* ICC */
    ownIndxUpdate(pState->indxIccPrev, pState->indxIcc[0], 34, pState->bs_enable_icc);
    /* IPD */
    ownIndxUpdate(pState->indxIpdPrev, pState->indxIpd[0], 17, pState->bs_enable_ipdopd);
    /* OPD */
    ownIndxUpdate(pState->indxOpdPrev, pState->indxOpd[0], 17, pState->bs_enable_ipdopd);

    pState->nEnv++;
  }

  /* patch */
#if 1
  if( 0 == pState->bs_frame_class ){
    pState->bufBordPos[0] = 0;
    pState->bufBordPos[ pState->nEnv ] = 32;
    for( env = 1; env < pState->nEnv; env++ ){
      pState->bufBordPos[env] = env * 32 / pState->nEnv;
    }
  }
#endif

  /* [5] - borders. class FIX or VAR */
  if( pState->bs_frame_class ){

    /* dublicating */
    if( pState->bufBordPos[pState->nEnv] < 32 ){
      /* IID */
      ippsCopy_32s(pState->indxIid[pState->nEnv - 1], pState->indxIid[pState->nEnv], 34);
      /* ICC */
      ippsCopy_32s(pState->indxIcc[pState->nEnv - 1], pState->indxIcc[pState->nEnv], 34);
      /* IPD */
      ippsCopy_32s(pState->indxIpd[pState->nEnv - 1], pState->indxIpd[pState->nEnv], 17);
      /* OPD */
      ippsCopy_32s(pState->indxOpd[pState->nEnv - 1], pState->indxOpd[pState->nEnv], 17);

      /* update */
      pState->nEnv++;
      pState->bufBordPos[pState->nEnv] = 32;
    }

    /* patch, from ref code */
    for( env = 1; env < pState->nEnv; env++ ){
      Ipp32s thres = 0;

      thres = 32 - ( pState->nEnv - env );
      if( pState->bufBordPos[env] > thres ){
        pState->bufBordPos[env] = thres;
      } else {
        thres = pState->bufBordPos[env - 1] + 1;
        if( pState->bufBordPos[env] < thres ){
          pState->bufBordPos[env] = thres;
        }
      }// if()
    }
  }// if( class )

  /* [6] preprocessing mapping */
  for( env = 0; env < pState->nEnv; env++ ){
    /* IID */
    ippsCopy_32s(pState->indxIid[env], pState->indxIidMapped[env], 34);
    /* ICC */
    ippsCopy_32s(pState->indxIcc[env], pState->indxIccMapped[env], 34);
    /* IPD */
    ippsCopy_32s(pState->indxIpd[env], pState->indxIpdMapped[env], 17);
    /* OPD */
    ippsCopy_32s(pState->indxOpd[env], pState->indxOpdMapped[env], 17);
  }

  /* [7] */
  if ( PS_ENABLE_BL == pState->modePS ){
    for( env = 0; env < pState->nEnv; env++ ){
      if( 2 == pState->freq_res_iid ){
        map34To20Idx( pState->indxIidMapped[env], 34 );
      }
      if( 2 == pState->freq_res_icc ){
        map34To20Idx( pState->indxIccMapped[env], 34 );
      }
      /* IPD - DISABLE */
      ippsZero_32s(pState->indxIpdMapped[env], 17);
      /* OPD - DISABLE */
      ippsZero_32s(pState->indxOpdMapped[env], 17);
    }
  } else if ( CONFIG_HA_BAND34 == pState->flag_HAconfig ){
    for( env = 0; env < pState->nEnv; env++ ){
      if( 2 > pState->freq_res_iid ){
        map20To34Idx( pState->indxIidMapped[env], 34 );
      }
      if( 2 > pState->freq_res_icc ){
        map20To34Idx( pState->indxIccMapped[env], 34 );
      }
      if( 2 > pState->freq_res_ipd ){
        map20To34Idx(pState->indxIpdMapped[env], 17);
        map20To34Idx(pState->indxOpdMapped[env], 17);
      }
    }
  }//f ( PS_ENABLE_BL == pState->modePS ){

  /* [8] active update of previous data */
  /* IID */
  ippsCopy_32s(pState->indxIid[pState->nEnv - 1], pState->indxIidPrev, 34);
  /* ICC */
  ippsCopy_32s(pState->indxIcc[pState->nEnv - 1], pState->indxIccPrev, 34);
  /* IPD */
  ippsCopy_32s(pState->indxIpd[pState->nEnv - 1], pState->indxIpdPrev, 17);
  /* OPD */
  ippsCopy_32s(pState->indxOpd[pState->nEnv - 1], pState->indxOpdPrev, 17);


  return 0;//OK
}

/* ************************************************************************** */

Ipp32s ps_dec_parser( sBitsreamBuffer * pBS, sPSDecComState* pPSDec)
{
  /* tables */
  Ipp32s tabNumEnv[2][4] = { { 0, 1, 2, 4 }, { 1, 2, 3, 4 } };
  Ipp32s tabNumIidBands[]= { 10, 20, 34, 10, 20, 34 };
  Ipp32s tabNumIccBands[]= { 10, 20, 34, 10, 20, 34, 0, 0}; // 2 last elements - reserved

  Ipp32s nIidBands = 0, nIccBands = 0;

  Ipp32s nEnv = 0, env = 0, b = 0;
  Ipp32s iid_quant  = 0;// default

  Ipp32s cnt = 0, esc_cnt = 0;
  Ipp32s num_bits_left = 0;
  Ipp32s ps_ext_id  = 0;
  Ipp32s empty_bits = 0;
  Ipp32s decodeBitsStart = 0, decodeBitsStop = 0, error = 0;

  void*   pHuffTab = NULL;
  Ipp32s  indx = 0;

  /* header */
  GET_BITS(pBS, pPSDec->bs_enable_ps_header, 1, Ipp32s);
  if( pPSDec->bs_enable_ps_header ){

    GET_BITS(pBS, pPSDec->bs_enable_iid, 1, Ipp32s);
    if(pPSDec->bs_enable_iid){
      GET_BITS(pBS, pPSDec->bs_iid_mode, 3, Ipp32s);
    }
    /* protection: iid_mode = [0, 5] */
    if( pPSDec->bs_iid_mode < 0 || pPSDec->bs_iid_mode > 5 ){
      EXIT_ERR_PS_PARSER( pPSDec );
    }

    GET_BITS(pBS, pPSDec->bs_enable_icc, 1, Ipp32s);
    if( pPSDec->bs_enable_icc ){
      GET_BITS(pBS, pPSDec->bs_icc_mode, 3, Ipp32s);
    }
    /* protection: icc_mode = [0, 5] */
    if( pPSDec->bs_icc_mode < 0 || pPSDec->bs_icc_mode > 5 ){
      EXIT_ERR_PS_PARSER( pPSDec );
    }

    GET_BITS(pBS, pPSDec->bs_enable_ext, 1, Ipp32s);
  }

  /* frame info */
  GET_BITS(pBS, pPSDec->bs_frame_class, 1, Ipp32s);
  GET_BITS(pBS, pPSDec->bs_num_env_idx, 2, Ipp32s);

  nEnv = tabNumEnv[pPSDec->bs_frame_class][pPSDec->bs_num_env_idx];
  pPSDec->nEnv = nEnv;

  if( pPSDec->bs_frame_class ){
    pPSDec->bufBordPos[0] = 0;
    for(env = 0; env < nEnv; env++){
      GET_BITS(pBS, pPSDec->bufBordPos[env + 1], 5, Ipp32s);
      pPSDec->bufBordPos[env + 1] += 1;
    }
  } else {
    for(env = 0; env < nEnv; env++){
      pPSDec->bufBordPos[ nEnv ] = 32 / nEnv * env;
    }
  }
  pPSDec->bufBordPos[ nEnv ] = 32;

  /* correct selection of quant */
  iid_quant    = (pPSDec->bs_iid_mode < 3) ? 0 : 1;
  nIidBands    = tabNumIidBands[pPSDec->bs_iid_mode];
  nIccBands    = tabNumIccBands[pPSDec->bs_icc_mode];

  /* patch, tuning freq_resolution */
  if (pPSDec->bs_iid_mode > 2){
    pPSDec->freq_res_iid = pPSDec->bs_iid_mode - 3;
  }else{
    pPSDec->freq_res_iid = pPSDec->bs_iid_mode;
  }

  /* the same result */
  pPSDec->freq_res_ipd =  pPSDec->freq_res_iid;

  if (pPSDec->bs_icc_mode > 2){
    pPSDec->freq_res_icc = pPSDec->bs_icc_mode-3;
    pPSDec->mix_strategy = PS_MIX_RB; //Rb
  }else{
    pPSDec->freq_res_icc = pPSDec->bs_icc_mode;
    pPSDec->mix_strategy = PS_MIX_RA; //Ra
  }

  /* select correct HA config (not clear from ISO spec) */
  // flag of HA has been changed if IID or ICC has been sent
  if( pPSDec->bs_enable_iid || pPSDec->bs_enable_icc ){
    pPSDec->flag_HAconfig  = (pPSDec->bs_enable_iid && (34 == nIidBands));
    pPSDec->flag_HAconfig |= (pPSDec->bs_enable_icc && (34 == nIccBands));
    pPSDec->flag_HAconfig  = (pPSDec->flag_HAconfig) ? CONFIG_HA_BAND34 : CONFIG_HA_BAND1020;
  }

  /* IID_DATA */
  if( pPSDec->bs_enable_iid ){
    for( env = 0; env < nEnv; env++ ){
      GET_BITS(pBS, pPSDec->bs_iid_dt[env], 1, Ipp32s);

      indx = ( pPSDec->bs_iid_dt[env] ) ? 1 : 0;
      indx = ( iid_quant ) ? indx : indx + 2;
      pHuffTab = pPSDec->psHuffTables[indx];

      for (b = 0; b < nIidBands; b++){
        pPSDec->indxIid[env][b] = ps_huff_dec(pHuffTab, pBS);
      }
    }
  }

  /* ICC_DATA */
  if( pPSDec->bs_enable_icc ){
    for( env = 0; env < nEnv; env++ ){
      GET_BITS(pBS, pPSDec->bs_icc_dt[env], 1, Ipp32s);

      indx = ( pPSDec->bs_icc_dt[env] ) ? 5 : 4;
      pHuffTab = pPSDec->psHuffTables[indx];

      for( b = 0; b < nIccBands; b++){
        pPSDec->indxIcc[env][b] = ps_huff_dec(pHuffTab, pBS);
      }
    }
  }

  /* extension */
  if(pPSDec->bs_enable_ext){
    GET_BITS(pBS, cnt, 4, Ipp32s); // ps_extension_size
    if( 15 == cnt ){
      GET_BITS(pBS, esc_cnt, 8, Ipp32s);
      cnt += esc_cnt;
    }

    num_bits_left = 8*cnt;
    while ( num_bits_left > 7 ) {
      GET_BITS(pBS, ps_ext_id, 2, Ipp32s);
      num_bits_left -= 2;

      GET_BITS_COUNT(pBS, decodeBitsStart);
      error = ps_extension_parser(pBS, pPSDec, ps_ext_id, num_bits_left);

      if( error ) return PS_ERR_PARSER;

      GET_BITS_COUNT(pBS, decodeBitsStop);

      num_bits_left -= (decodeBitsStop - decodeBitsStart);
    }

    // fill elements
    if( num_bits_left < 0 ) return PS_ERR_PARSER;

    /* read fill bits for byte alignment */
    GET_BITS(pBS, empty_bits, num_bits_left, Ipp32s);
  }

  /* save params */
  pPSDec->iid_quant = iid_quant;
  pPSDec->nIidBands = nIidBands;
  pPSDec->nIccBands = nIccBands;

  /* delta decode of phase params */
  ps_delta_decode_phase_params( pPSDec );

  /* tuning mode of PSDec */
  if( PS_ENABLE_BL == pPSDec->modePS ){
    pPSDec->mix_strategy  = PS_MIX_RA;// Ra
    pPSDec->flag_HAconfig = CONFIG_HA_BAND1020;
  } //else if UNRESTRICTED

  return 0;
}

/* EOF */

⌨️ 快捷键说明

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