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

📄 ps_dec_parser.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2007 Intel Corporation. All Rights Reserved.
//
*/

#include <math.h>
#include <stdio.h>
#include "ippac.h"
/* parametric stereo */
#include "ps_dec_struct.h"
#include "sbr_huff_tabs.h"
#include "ps_dec_parser.h"
/* debug */
#include "vm_debug.h"

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

#define OWN_MIN_MAX(indx, minIndx, maxIndx) IPP_MIN( IPP_MAX(indx, minIndx), maxIndx)

#define MOD_IDX (8)

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

void ps_header_fill_default( sPSDecComState* pPSItem )
{
  pPSItem->bs_enable_iid = 0;
  pPSItem->bs_iid_mode   = 0;
  pPSItem->bs_enable_icc = 0;
  pPSItem->bs_icc_mode   = 0;
  pPSItem->bs_enable_ext = 0;
  pPSItem->bs_enable_ipdopd = 0;

  pPSItem->flag_HAconfig     = CONFIG_HA_BAND1020;
  pPSItem->flag_HAconfigPrev = pPSItem->flag_HAconfig;


  return;
}

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

#define EXIT_ERR_PS_PARSER             \
{                                      \
     ps_header_fill_default( pPSDec ); \
     return PS_ERR_PARSER;             \
}

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

static Ipp16s ps_huff_dec(void *t_huff, sBitsreamBuffer * pBS)
{
  Ipp16s index = 0;
  Ipp8u  *pSrc;
  Ipp32s bitoffset;

  pSrc = (Ipp8u *)pBS->pCurrent_dword + ((32 - pBS->nBit_offset) >> 3);
  bitoffset = (32 - pBS->nBit_offset) & 0x7;

  ippsVLCDecodeOne_1u16s(&pSrc, &bitoffset, &index,
    (IppsVLCDecodeSpec_32s *) t_huff);

  pBS->pCurrent_dword = (Ipp32u *)(pSrc - ((Ipp32s)(pSrc) & 3));
  pBS->dword = BSWAP(pBS->pCurrent_dword[0]);
  pBS->nBit_offset =
    32 - ((pSrc - (Ipp8u *)pBS->pCurrent_dword) << 3) - bitoffset;

  return index;
}

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

static
Ipp32s ps_extension_parser(sBitsreamBuffer* pBS,
                           sPSDecComState*  pPSDec,
                           Ipp32s ps_ext_id,
                           Ipp32s num_bits_left)
{
  Ipp32s tabNumIpdOpdBands[] = { 5, 11, 17,  5, 11, 17 };
  void*  pHuffTab = NULL;

  Ipp32s cnt = 0, bytes = 0, empty_bits = 0, env = 0;
  Ipp32s b = 0, nIpdOpdBands = 0;
  Ipp32s reserved_ps = 0, indx = 0;

  switch( ps_ext_id ){
    case PS_EXTENSION_VER0:

      GET_BITS(pBS, pPSDec->bs_enable_ipdopd, 1, Ipp32s);

      if( pPSDec->bs_enable_ipdopd ){

        nIpdOpdBands = tabNumIpdOpdBands[pPSDec->bs_iid_mode];

        for( env = 0; env < pPSDec->nEnv; env++){

          GET_BITS(pBS, pPSDec->bs_ipd_dt[env], 1, Ipp32s);
          // ipd_data
          indx     = ( pPSDec->bs_ipd_dt[env] ) ? 7 : 6;
          pHuffTab = pPSDec->psHuffTables[ indx ];

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

          GET_BITS(pBS, pPSDec->bs_opd_dt[env], 1, Ipp32s);
          // opd_data
          indx = ( pPSDec->bs_opd_dt[env] ) ? 9 : 8;
          pHuffTab = pPSDec->psHuffTables[ indx ];

          for (b = 0; b < nIpdOpdBands; b++) {
            pPSDec->indxOpd[env][b] = ps_huff_dec(pHuffTab, pBS);
          }
        }// for (env = 0; env ...
      }// if( pPSDec->bs_enable_ipdopd )

      GET_BITS(pBS, reserved_ps, 1, Ipp32s);

      break;

    default: // version of PS extension > V0. doesn't support
      cnt = num_bits_left >> 3; /* bits2bytes */
      for (bytes=0; bytes<cnt; bytes++){
        GET_BITS(pBS, empty_bits, 8, Ipp32s);
      }
      break;
  }

  pPSDec->nIpdOpdBands = nIpdOpdBands;

  return PS_NO_ERR;
}

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

static Ipp32s ownInterpolation(Ipp32s* pSrcDst, Ipp32s len)
{
  Ipp32s i = 0;

  len <<= 1;
  for (i = len-1; i > 0; i--) {
    pSrcDst[i] = pSrcDst[i >> 1];
  }

  return 0;//OK
}

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

static Ipp32s
ownDeltaDecode(  Ipp32s *pIndxCur,
                 Ipp32s *pIndxPrev,

                 Ipp32s flag,
                 Ipp32s dtdf,
                 Ipp32s nBands,

                 Ipp32s offset,
                 Ipp32s minIndx,
                 Ipp32s maxIndx)
{
  Ipp32s band = 0, startBand = 0;
  Ipp32s* pIndx1 = NULL;

  /* [1] passive delta decode */
  if( !flag ){
    ippsZero_32s(pIndxCur, nBands*offset);
    return 0;//OK
  }

  /* [2] active delta decode */
  /* tuning */
  pIndx1    = (dtdf) ? pIndxPrev : pIndxCur;
  startBand = (dtdf) ? 0 : 1;

  for (band = startBand; band < nBands; band++) {
    pIndxCur[band] += pIndx1[ dtdf ? band*offset : band-1];
  }

  /* patch */
  for(band = 0; band < nBands; band++){
    pIndxCur[band] = OWN_MIN_MAX(pIndxCur[band],minIndx,maxIndx);
  }

  /* [4] interpolation */
  if (2 == offset) {
    ownInterpolation(pIndxCur, nBands);
  }

  return 0;//OK
}

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

static Ipp32s
ownDeltaDecodeMod(Ipp32s *pIndxCur,
                  Ipp32s *pIndxPrev,
                  Ipp32s flag,
                  Ipp32s dtdf,

                  Ipp32s nBands,
                  Ipp32s offset)
{
  Ipp32s band = 0, startBand = 0;
  Ipp32s* pIndx1 = NULL;

  /* passive delta decode mod */
  if( !flag ){
    ippsZero_32s(pIndxCur, nBands * offset);
    return 0;
  }

  /* tuning */
  pIndx1      = (dtdf) ? pIndxPrev : pIndxCur;
  startBand   = (dtdf) ? 0 : 1;
  pIndxCur[0] = (dtdf) ? pIndxCur[0] : pIndxCur[0] % MOD_IDX;

  /* decode */
  for( band = startBand; band < nBands; band++ ){
     pIndxCur[band] += pIndx1[ dtdf ? band*offset : band-1];
     pIndxCur[band] %= MOD_IDX;
  }

  /* [4] interpolation */
  if (2 == offset) {
    ownInterpolation(pIndxCur, nBands);
  }

  return 0;//OK
}

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

static Ipp32s map34To20Idx (Ipp32s *pIndx, Ipp32s nBands)
{
  pIndx[0]  = (2*pIndx[0]+pIndx[1])/3;
  pIndx[1]  = (pIndx[1]+2*pIndx[2])/3;
  pIndx[2]  = (2*pIndx[3]+pIndx[4])/3;
  pIndx[3]  = (pIndx[4]+2*pIndx[5])/3;
  pIndx[4]  = (pIndx[6]+pIndx[7]) >> 1;
  pIndx[5]  = (pIndx[8]+pIndx[9]) >> 1;
  pIndx[6]  = pIndx[10];
  pIndx[7]  = pIndx[11];
  pIndx[8]  = (pIndx[12]+pIndx[13]) >> 1;
  pIndx[9]  = (pIndx[14]+pIndx[15]) >> 1;
  pIndx[10] = pIndx[16];

  if( 17 == nBands ) return 0;//OK

  pIndx[11] = pIndx[17];
  pIndx[12] = pIndx[18];
  pIndx[13] = pIndx[19];
  pIndx[14] = (pIndx[20]+pIndx[21])>>1;
  pIndx[15] = (pIndx[22]+pIndx[23])>>1;
  pIndx[16] = (pIndx[24]+pIndx[25])>>1;
  pIndx[17] = (pIndx[26]+pIndx[27])>>1;
  pIndx[18] = (pIndx[28]+pIndx[29]+pIndx[30]+pIndx[31])>>2;
  pIndx[19] = (pIndx[32]+pIndx[33])>>1;


  return 0;//OK
}

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

static Ipp32s map20To34Idx (Ipp32s *pIndx, Ipp32s nBands)
{
  int bufT[34];

  bufT[0] = pIndx[0];
  bufT[1] = (pIndx[0] + pIndx[1]) >> 1;
  bufT[2] = pIndx[1];
  bufT[3] = pIndx[2];
  bufT[4] = (pIndx[2] + pIndx[3]) >> 1;
  bufT[5] = pIndx[3];
  bufT[6] = pIndx[4];
  bufT[7] = pIndx[4];
  bufT[8] = pIndx[5];
  bufT[9] = pIndx[5];
  bufT[10] = pIndx[6];
  bufT[11] = pIndx[7];
  bufT[12] = pIndx[8];
  bufT[13] = pIndx[8];
  bufT[14] = pIndx[9];
  bufT[15] = pIndx[9];
  bufT[16] = pIndx[10];

  if( 17 == nBands ) return 0;//OK

  bufT[17] = pIndx[11];
  bufT[18] = pIndx[12];
  bufT[19] = pIndx[13];
  bufT[20] = pIndx[14];
  bufT[21] = pIndx[14];
  bufT[22] = pIndx[15];
  bufT[23] = pIndx[15];
  bufT[24] = pIndx[16];
  bufT[25] = pIndx[16];
  bufT[26] = pIndx[17];
  bufT[27] = pIndx[17];
  bufT[28] = pIndx[18];
  bufT[29] = pIndx[18];
  bufT[30] = pIndx[18];
  bufT[31] = pIndx[18];
  bufT[32] = pIndx[19];
  bufT[33] = pIndx[19];

  ippsCopy_32s(bufT, pIndx, nBands);

  return 0;//OK
}

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

static Ipp32s ownIndxUpdate(Ipp32s* pSrc, Ipp32s* pDst, Ipp32s len, Ipp32s flag)
{

  if( flag ){
    ippsCopy_32s(pSrc, pDst, len);
  } else {
    ippsZero_32s(pDst, len);
  }

  return 0;//OK
}

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

static Ipp32s ps_delta_decode_phase_params( sPSDecComState* pState )
{
  Ipp32s env;
  Ipp32s nGridSteps = pState->iid_quant ? 15 : 7;

  /* [1] delta decoding */
  for( env = 0; env < pState->nEnv; env++ ){
    Ipp32s *pIndxIidPrev = NULL;
    Ipp32s *pIndxIccPrev = NULL;
    Ipp32s *pIndxIpdPrev = NULL;
    Ipp32s *pIndxOpdPrev = NULL;
    Ipp32s* pIndxCur     = NULL;
    Ipp32s* pIndxPrev    = NULL;
    Ipp32s param, flag, dfdt, nBands, offset, minIndx, maxIndx;

⌨️ 快捷键说明

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