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

📄 aac_dec_api_int.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 4 页
字号:
AACStatus aacidecUpdateStateMemMap(AACDec *state, Ipp32s mShift)
{
  Ipp32s  i;
  sSbrDecFilter* sbr_filter[CH_MAX];

  if (!state)
    return AAC_NULL_PTR;

  for (i = 0; i < CH_MAX; i++) {
    sbr_filter[i] = &(state->sbr_filter[i]);
  }

  for (i = 0; i < 16; i++) {
    AACDEC_UPDATE_PTR(void, state->com.huffman_tables[i], mShift)
  }
  for (i = 0; i < 10; i++) {
    AACDEC_UPDATE_PTR(IppsVLCDecodeSpec_32s, state->com.sbrHuffTables[i], mShift)
  }

  AACDEC_UPDATE_PTR(Ipp8u, state->pWorkBuffer, mShift)

  (state->com.m_sce).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]);
  (state->com.m_cpe).streams[0].p_huffman_tables = (void **)&(state->com.huffman_tables[0]);
  (state->com.m_cpe).streams[1].p_huffman_tables = (void **)&(state->com.huffman_tables[0]);
  (state->com.m_cce).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]);
  (state->com.m_lfe).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]);

  sbridecUpdateMemMap(sbr_filter, mShift);

  return AAC_OK;
}

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

#define RETURN_AAC_BAD_STREAM                                     \
{                                                                 \
  GET_BITS_COUNT(pBS, (*decodedBytes))                            \
  *decodedBytes = (*decodedBytes + 7) >> 3;                       \
  state_com->m_channel_number = state_com->m_channel_number_save; \
  state_com->m_is_chmap_valid = save_m_is_chmap_valid;            \
  state_com->m_is_pce_valid = save_m_is_pce_valid;                \
  return AAC_BAD_STREAM;                                          \
}

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

static Ipp32s aacGetChannel(Ipp32s id,
                            Ipp32s tag,
                            Ipp32s element_number,
                            sEl_map_item elmap[])
{
  Ipp32s i;
  for (i = 0; i < element_number; i++) {
    if ((elmap[i].id == id) && (elmap[i].tag == tag)) {
      return elmap[i].ch;
    }
  }
  return -1;
}

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

AACStatus aacidecGetFrame(Ipp8u  *inPointer,
                          Ipp32s *decodedBytes,
                          Ipp16s *outPointer,
                          Ipp32s outBufferSize,
                          AACDec *state)
{
  sData_stream_element m_data;
  sDynamic_range_info m_drc_info;
  sEl_map_item m_elmap[EL_TAG_MAX];

  sBitsreamBuffer BS;
  sBitsreamBuffer *pBS = &BS;
  AACDec_com      *state_com;

  Ipp32s  el_num;
  Ipp32s  ch_num;
  Ipp32s  order_counter = 0;
  Ipp32s  cur_frame_el_num = 0;
  Ipp32s  save_m_is_chmap_valid;
  Ipp32s  save_m_is_pce_valid;

  Ipp32s  id;
  Ipp32s  tag = 0;
  Ipp32s  ch = 0;
  Ipp32s  ncch = 0;
  Ipp32s  tag_counter[4][EL_TAG_MAX];

/* HE-AAC param */
  Ipp32s  cnt_fill_sbr_element = 0;
  Ipp32s  cnt_idaac_sbr_element = 0;
  Ipp32s  sbrFlagPresentLFE = 0;
  Ipp32s  NumRealCh = 0;
  Ipp32s  ch_counter;
  Ipp32s  scaleFactorCoreAAC;
  Ipp32s  scaleFactorAAC;
  Ipp32s  errSBRParser = 0;

  s_tns_data tns_data0;
  Ipp32s  i, j, m_channel_number;

  if (!inPointer || !outPointer)
    return AAC_NULL_PTR;

  for (i = 0; i < 4; i++) {
    for (j = 0; j < EL_TAG_MAX; j++) {
      tag_counter[i][j] = 0;
    }
  }

  state_com = &(state->com);
  el_num = state_com->m_element_number;
  ch_num = state_com->m_channel_number_all;

  save_m_is_chmap_valid = state_com->m_is_chmap_valid;
  save_m_is_pce_valid = state_com->m_is_pce_valid;

  /* state_com->decodedBytes != 0 means that this frame   */
  /* has been decoded already but output buffer was small */
  if (state_com->decodedBytes == 0) {

    GET_INIT_BITSTREAM(pBS, inPointer)

    // init
    state->com.m_up_sample  = 1;

    GET_BITS(pBS, id, 3, Ipp32s)
    while (id != ID_END) {
      if (CH_MAX - 1 < NumRealCh)
        RETURN_AAC_BAD_STREAM;
      switch (id) {
      case ID_SCE:
        /* may be there is HE-AAC element */
      state->sbrBlock[cnt_idaac_sbr_element++].comState.id_aac = ID_SCE;
        NumRealCh++;

        /* Parsing bitstream */
        (state_com->m_sce).crc = state_com->crc;
        (state_com->m_sce).crc_enable = state_com->crc_enable;
        if (dec_sce_channel_element(&(state_com->m_sce), pBS, state_com->m_audio_object_type) < 0)
          RETURN_AAC_BAD_STREAM;
        state_com->crc = (state_com->m_sce).crc;
        tag = (state_com->m_sce).element_instance_tag;
        /* several equal tags are supported */
        tag_counter[0][tag] += 1;
        tag += ((tag_counter[0][tag] - 1) * EL_TAG_MAX);
        break;
      case ID_CPE:
        /* may be there is HE-AAC element */
      state->sbrBlock[cnt_idaac_sbr_element++].comState.id_aac = ID_CPE;
        NumRealCh += 2;

        /* Parsing bitstream */
        (state_com->m_cpe).crc = state_com->crc;
        (state_com->m_cpe).crc_enable = state_com->crc_enable;
        if (dec_cpe_channel_element(&(state_com->m_cpe), pBS, state_com->m_audio_object_type) < 0)
          RETURN_AAC_BAD_STREAM;
        state_com->crc = (state_com->m_cpe).crc;
        tag = (state_com->m_cpe).element_instance_tag;
        /* several equal tags are supported */
        tag_counter[1][tag] += 1;
        tag += ((tag_counter[1][tag] - 1) * EL_TAG_MAX);
        break;
      case ID_CCE:
        if (COUPL_CH_MAX - 1 < ncch)
          RETURN_AAC_BAD_STREAM;

        (state_com->m_cce).crc = state_com->crc;
        (state_com->m_cce).crc_enable = state_com->crc_enable;
        if (dec_coupling_channel_element(&(state_com->m_cce), &(state_com->m_cdata[ncch]),
              pBS, state_com->m_audio_object_type) < 0)
          RETURN_AAC_BAD_STREAM;
        state_com->crc = (state_com->m_cce).crc;
        tag = (state_com->m_cce).element_instance_tag;
        /* several equal tags are supported */
        tag_counter[2][tag] += 1;
        tag += ((tag_counter[2][tag] - 1) * EL_TAG_MAX);
        break;
      case ID_LFE:
        /* may be there is HE-AAC element */
        if (CH_MAX - 1 < cnt_idaac_sbr_element)
          RETURN_AAC_BAD_STREAM;

      state->sbrBlock[cnt_idaac_sbr_element++].comState.id_aac = ID_LFE;

        if (cnt_fill_sbr_element > 0) {
          sbrFlagPresentLFE++;

          if ( CH_MAX - 1 < cnt_fill_sbr_element )
            RETURN_AAC_BAD_STREAM;

          cnt_fill_sbr_element++;
        }

        /* Parsing bitstream */
        (state_com->m_lfe).crc = state_com->crc;
        (state_com->m_lfe).crc_enable = state_com->crc_enable;
        if (dec_lfe_channel_element(&(state_com->m_lfe), pBS, state_com->m_audio_object_type) < 0)
          RETURN_AAC_BAD_STREAM;
        state_com->crc = (state_com->m_lfe).crc;
        tag = (state_com->m_lfe).element_instance_tag;
        /* several equal tags are supported */
        tag_counter[3][tag] += 1;
        tag += ((tag_counter[3][tag] - 1) * EL_TAG_MAX);
        NumRealCh++;
        break;
      case ID_DSE:
        dec_data_stream_element(&m_data, pBS);
        break;
      case ID_PCE:
        {
          Ipp32u  *crc_ptr = 0;
          Ipp32s  crc_offset = 0;
          Ipp32s  decodedBits0 = 0;
          Ipp32s  decodedBits2 = 0;

          if (state_com->crc_enable) {
            crc_ptr = pBS->pCurrent_dword;
            crc_offset = pBS->nBit_offset;
            GET_BITS_COUNT(pBS, decodedBits0)
          }

          dec_program_config_element(&(state_com->m_pce), pBS);

          if (state_com->crc_enable) {
            Ipp32u crc = (Ipp32u)state_com->crc;
            GET_BITS_COUNT(pBS, decodedBits2)
              bs_CRC_update(crc_ptr, crc_offset, decodedBits2 - decodedBits0, &crc);
            state_com->crc = (Ipp32s)crc;
          }
          state_com->m_is_chmap_valid = 0;
          state_com->m_is_pce_valid = 1;
        }
        break;
      case ID_FIL:
/*
* NOTES:
* (1)SBR FILL ELEMENT there is for SCE & CPE modes only.
* (2)If AOT AAC is MAIN, LC or LTP
* then
*   <SCE> <FIL <EXT_SBR_DATA(SCE)>> // center
*   <CPE> <FIL <EXT_SBR_DATA(CPE)>> // front L/R
*   <CPE> <FIL <EXT_SBR_DATA(CPE)>> // back L/R
*   <LFE> // sub
*   <END> // (end of raw data block)
*
* (3)If AOT AAC is ER LC or ER LTP
* then
*   <SCE> <CPE> <CPE> <LFE> <EXT <SBR(SCE)> <SBR(CPE)> <SBR(CPE)>>
*
* (4) may be more then one FILL ELEMENT, for ex:
*  <SCE> <FILL.. <CPE> <FILL.. <CPE> <FILL..><FILL..> <LFE><FILL..><FILL..><FILL..>
*/
        if ( CH_MAX - 1 < cnt_fill_sbr_element )
          RETURN_AAC_BAD_STREAM;

      state->sbrBlock[cnt_fill_sbr_element].comState.sbr_freq_sample =
          state_com->m_sampling_frequency * 2;

        if (state->com.m_sampling_frequency_index >= 3)
        state->sbrBlock[cnt_fill_sbr_element].comState.sbr_freq_indx =
            state->com.m_sampling_frequency_index - 3;

      /* AYA: move to parser */
      //state->sbrBlock[cnt_fill_sbr_element]->comState.sbrFlagError = 0;

      errSBRParser = dec_fill_element(&(state->sbrBlock[cnt_fill_sbr_element].comState),
                                       &cnt_fill_sbr_element, &m_drc_info, pBS, SBR_ENABLE);

        /* patch while fixed point sbr isn't implemented
        {
        sSBRDecComState SbrBlock;
        dec_fill_element(&SbrBlock, &cnt_fill_sbr_element, &m_drc_info, pBS);
        }
        */

        /*************************************************************
        * if there is problem with HE-AAC parser then QUIT
        *************************************************************/
        if ( errSBRParser )
          RETURN_AAC_BAD_STREAM

        break;
      }

      if ((ID_DSE > id) && (ID_CCE != id)) {
        ch = aacGetChannel(id, tag, el_num, state_com->m_elmap);

        m_elmap[cur_frame_el_num].id = (Ipp16s)id;
        m_elmap[cur_frame_el_num].tag = (Ipp16s)tag;
        m_elmap[cur_frame_el_num].ch = (Ipp16s)ch;

        if (ch < 0) {
          if (el_num >= CH_MAX)
            RETURN_AAC_BAD_STREAM
          state_com->m_elmap[el_num].id = (Ipp16s)id;
          state_com->m_elmap[el_num].tag = (Ipp16s)tag;
          state_com->m_elmap[el_num].ch = (Ipp16s)ch_num;
          ch = ch_num;
          el_num++;
          ch_num++;
          if (ID_CPE == id) ch_num++;
        }

        m_elmap[cur_frame_el_num].id = (Ipp16s)id;
        m_elmap[cur_frame_el_num].tag = (Ipp16s)tag;
        m_elmap[cur_frame_el_num].ch = (Ipp16s)ch;

        cur_frame_el_num++;

        state_com->m_order[order_counter] = ch;
        order_counter++;

        if (ch >= CH_MAX)
          RETURN_AAC_BAD_STREAM

        if (ID_CPE == id) {
          state_com->m_order[order_counter] = ch+1;
          order_counter++;
          if (ch+1 >= CH_MAX)
            RETURN_AAC_BAD_STREAM
        }
      }

      switch (id) {
      case ID_SCE:

        state_com->m_curr_win_shape[ch] = (state_com->m_sce).stream.window_shape;
        state_com->m_curr_win_sequence[ch] = (state_com->m_sce).stream.window_sequence;

        if (0 != (state_com->m_sce).stream.pulse_data_present) {
          ics_apply_pulse_I(&(state_com->m_sce).stream);
        }

        aacidec_ics_apply_scale_factors(&(state_com->m_sce).stream, state->m_spectrum_data[ch]);

        aacidec_apply_pns(&(state_com->m_sce).stream, NULL, state->m_spectrum_data[ch], NULL, 1,
                  0, NULL, &(state_com->noiseState));

        aacidec_deinterlieve(&(state_com->m_sce).stream, state->m_spectrum_data[ch]);
        aacidec_ics_calc_tns_data(&(state_com->m_sce).stream, &(state->tns_data[ch]));

        if (AOT_AAC_LTP == state_com->m_audio_object_type) {
          state->m_ltp.p_samples_1st_part = state->m_ltp_buf[ch][state_com->m_index_1st];
          state->m_ltp.p_samples_2nd_part = state->m_ltp_buf[ch][state_com->m_index_2nd];
          state->m_ltp.p_samples_3rd_part = state->m_ltp_buf[ch][state_com->m_index_3rd];
          state->m_ltp.prev_windows_shape = state_com->m_prev_win_shape[ch];

          state->m_ltp.p_tns_data = &(state->tns_data[ch]);

          aacidec_ics_apply_ltp_I(&(state->m_ltp), &(state_com->m_sce).stream, state->m_spectrum_data[ch]);
        }

⌨️ 快捷键说明

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