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

📄 aac_dec_stream_elements.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
//
//                  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) 2003-2007 Intel Corporation. All Rights Reserved.
//
//     Intel(R) Integrated Performance Primitives AAC Decode Sample for Windows*
//
//  By downloading and installing this sample, you hereby agree that the
//  accompanying Materials are being provided to you under the terms and
//  conditions of the End User License Agreement for the Intel(R) Integrated
//  Performance Primitives product previously accepted by you. Please refer
//  to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel(R) IPP
//  product installation for more information.
//
//  MPEG-4 and AAC are international standards promoted by ISO, IEC, ITU, ETSI
//  and other organizations. Implementations of these standards, or the standard
//  enabled platforms may require licenses from various entities, including
//  Intel Corporation.
//
*/

#include "ippdc.h"
#include "aac_dec_own.h"

Ipp32s  dec_ics_info(s_SE_Individual_channel_stream *pData,
                     sBitsreamBuffer *pBS,
                     enum AudioObjectType audioObjectType);

Ipp32s  ics_info_copy(s_SE_Individual_channel_stream *pDataSrc,
                      s_SE_Individual_channel_stream *pDataDst,
                      enum AudioObjectType audioObjectType);

Ipp32s  dec_section_data(s_SE_Individual_channel_stream *pData,
                         sBitsreamBuffer *pBS);
Ipp32s  dec_scale_factor_data(s_SE_Individual_channel_stream *pData,
                              Ipp16s scalef[8][51],
                              Ipp32s scale_factor,
                              Ipp32s noise_nrg,
                              sBitsreamBuffer *pBS);
Ipp32s  dec_spectral_data(s_SE_Individual_channel_stream *pData,
                          sBitsreamBuffer *BS);
Ipp32s  dec_pulse_data(s_SE_Individual_channel_stream *pData,
                       sBitsreamBuffer *pBS);
Ipp32s  dec_tns_data(s_SE_Individual_channel_stream *pData,
                     sBitsreamBuffer *pBS);
Ipp32s  dec_gain_control_data(s_SE_Individual_channel_stream *pData,
                              sBitsreamBuffer *pBS);
Ipp32s  dec_ltp_data(s_SE_Individual_channel_stream *pData,
                     sBitsreamBuffer *pBS,
                     enum AudioObjectType audioObjectType);

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

Ipp32s dec_cpe_channel_element(sCpe_channel_element *pElement,
                               sBitsreamBuffer *pBS,
                               enum AudioObjectType audioObjectType)
{
  Ipp32s  g;
  Ipp32s  sfb;
  Ipp32s  max_sfb;
  Ipp32s  num_window_groups;
  Ipp32u  *crc_ptr = 0, *crc_ptr1 = 0;
  Ipp32s  crc_offset = 0, crc_offset1 = 0;
  Ipp32s  decodedBits0 = 0, decodedBits1 = 0, decodedBits2 = 0;

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

  GET_BITS(pBS, pElement->element_instance_tag, 4, Ipp32s)

  GET_BITS(pBS, pElement->common_window, 1, Ipp32s)

  if (pElement->common_window) {
    if (dec_ics_info(&pElement->streams[0], pBS, audioObjectType) < 0)
      return -1;

    ics_info_copy(&pElement->streams[0], &pElement->streams[1],
                  audioObjectType);

    pElement->streams[1].ltp_data_present = 0;
    if (audioObjectType == AOT_AAC_LTP &&
        EIGHT_SHORT_SEQUENCE != pElement->streams[1].window_sequence) {
      if (pElement->streams[1].predictor_data_present) {
        GET_BITS(pBS, pElement->streams[1].ltp_data_present, 1, Ipp32s)
        if (pElement->streams[1].ltp_data_present) {
          dec_ltp_data(&pElement->streams[1], pBS, audioObjectType);
        }
      }
    }

    GET_BITS(pBS, pElement->ms_mask_present, 2, Ipp32s)
    if (pElement->ms_mask_present == 1) {
      max_sfb = pElement->streams[0].max_sfb;
      num_window_groups = pElement->streams[0].num_window_groups;
      for (g = 0; g < num_window_groups; g++) {
        for (sfb = 0; sfb < max_sfb; sfb++) {
          GET_BITS(pBS, pElement->ms_used[g][sfb], 1, Ipp32s)
        }
      }
    }
  } else {
    pElement->ms_mask_present = 0;
  }
  if (dec_individual_channel_stream
      (&pElement->streams[0], pBS, pElement->common_window, 0,
       audioObjectType) < 0)
    return -1;

  if (pElement->crc_enable) {
    crc_ptr1 = pBS->pCurrent_dword;
    crc_offset1 = pBS->nBit_offset;
    GET_BITS_COUNT(pBS, decodedBits1)
  }

  if (dec_individual_channel_stream
      (&pElement->streams[1], pBS, pElement->common_window, 0,
       audioObjectType) < 0)
    return -1;

  if (pElement->crc_enable) {
    Ipp32s len;
    Ipp32u crc = (Ipp32u)pElement->crc;

    GET_BITS_COUNT(pBS, decodedBits2)

    len = decodedBits2 - decodedBits0;
    if (len > 192) len = 192;
    bs_CRC_update(crc_ptr, crc_offset, len, &crc);

    if (len < 192)
      bs_CRC_update_zero(192 - len, &crc);

    len = decodedBits2 - decodedBits1;
    if (len > 128) len = 128;
    bs_CRC_update(crc_ptr1, crc_offset1, len, &crc);

    if (len < 128)
      bs_CRC_update_zero(128 - len, &crc);

    pElement->crc = (Ipp32s)crc;
  }

  return 0;
}

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

Ipp32s dec_sce_channel_element(sSce_channel_element *pElement,
                               sBitsreamBuffer *pBS,
                               enum AudioObjectType audioObjectType)
{
  Ipp32u  *crc_ptr = 0;
  Ipp32s  crc_offset = 0;
  Ipp32s  decodedBits0 = 0, decodedBits2 = 0;

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

  GET_BITS(pBS, pElement->element_instance_tag, 4, Ipp32s)

  if (dec_individual_channel_stream
      (&pElement->stream, pBS, 0, 0, audioObjectType) < 0)
    return -1;

  if (pElement->crc_enable) {
    Ipp32s len;
    Ipp32u crc = (Ipp32u)pElement->crc;

    GET_BITS_COUNT(pBS, decodedBits2)

    len = decodedBits2 - decodedBits0;
    if (len > 192) len = 192;
    bs_CRC_update(crc_ptr, crc_offset, len, &crc);

    if (len < 192)
      bs_CRC_update_zero(192 - len, &crc);

    pElement->crc = (Ipp32s)crc;
  }

  return 0;
}

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

Ipp32s dec_lfe_channel_element(sLfe_channel_element *pElement,
                               sBitsreamBuffer *pBS,
                               enum AudioObjectType audioObjectType)
{
  Ipp32u  *crc_ptr = 0;
  Ipp32s  crc_offset = 0;
  Ipp32s  decodedBits0 = 0, decodedBits2 = 0;

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

  GET_BITS(pBS, pElement->element_instance_tag, 4, Ipp32s)

  if (dec_individual_channel_stream
      (&pElement->stream, pBS, 0, 0, audioObjectType) < 0)
    return -1;

  if (pElement->crc_enable) {
    Ipp32s len;
    Ipp32u crc = (Ipp32u)pElement->crc;

    GET_BITS_COUNT(pBS, decodedBits2)

      len = decodedBits2 - decodedBits0;
    if (len > 192) len = 192;
    bs_CRC_update(crc_ptr, crc_offset, len, &crc);

    if (len < 192)
      bs_CRC_update_zero(192 - len, &crc);

    pElement->crc = (Ipp32s)crc;
  }

  return 0;
}

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

Ipp32s dec_individual_channel_stream(s_SE_Individual_channel_stream *pData,
                                     sBitsreamBuffer *pBS,
                                     Ipp32s common_window,
                                     Ipp32s scal_flag,
                                     enum AudioObjectType audioObjectType)
{
  GET_BITS(pBS, pData->global_gain, 8, Ipp32s)

  if (!common_window && !scal_flag) {
    if (dec_ics_info(pData, pBS, audioObjectType) < 0)
      return -1;
  }

  if (dec_section_data(pData, pBS) < 0)
    return -1;

  dec_scale_factor_data(pData, pData->sf, pData->global_gain,
                        pData->global_gain - 90, pBS);

  if (!scal_flag) {

    GET_BITS(pBS, pData->pulse_data_present, 1, Ipp32s)
    if (pData->pulse_data_present) {
      if (dec_pulse_data(pData, pBS) < 0)
        return -1;
    }

    GET_BITS(pBS, pData->tns_data_present, 1, Ipp32s)
    if (pData->tns_data_present) {
      dec_tns_data(pData, pBS);
    }
    GET_BITS(pBS, pData->gain_control_data_present, 1, Ipp32s)
    if (pData->gain_control_data_present) {
      if (AOT_AAC_SSR == audioObjectType) {
        dec_gain_control_data(pData, pBS);
      } else {
        return -1;
      }
    }
  }

  dec_spectral_data(pData, pBS);

  return 0;
}

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

Ipp32s dec_ics_info(s_SE_Individual_channel_stream *pData,
                    sBitsreamBuffer *pBS,
                    enum AudioObjectType audioObjectType)
{
  Ipp32s  i;
  Ipp32s  pred_min_sfb;

  GET_BITS(pBS, pData->ics_reserved_bit, 1, Ipp32s)
  GET_BITS(pBS, pData->window_sequence, 2, Ipp32s)
  GET_BITS(pBS, pData->window_shape, 1, Ipp32s)

  pData->num_window_groups = 1;
  pData->len_window_group[0] = 1;
  pData->predictor_reset = 0;
  pData->ltp_data_present = 0;

  if (pData->window_sequence == EIGHT_SHORT_SEQUENCE) {
    pData->num_windows = 8;
    GET_BITS(pBS, pData->max_sfb, 4, Ipp32s)
    if (pData->num_swb_short < pData->max_sfb)
      return -1;
    for (i = 0; i < 7; i++) {
      GET_BITS(pBS, pData->scale_factor_grouping[i], 1, Ipp32s)

      if (pData->scale_factor_grouping[i] == 0) {
        pData->len_window_group[pData->num_window_groups] = 1;
        pData->num_window_groups++;
      } else {
        pData->len_window_group[pData->num_window_groups - 1]++;

      }
    }
  } else {
    pData->num_windows = 1;
    GET_BITS(pBS, pData->max_sfb, 6, Ipp32s)
    if (pData->num_swb_long < pData->max_sfb)
      return -1;
    GET_BITS(pBS, pData->predictor_data_present, 1, Ipp32s)
    if (pData->predictor_data_present) {
      if (audioObjectType == AOT_AAC_MAIN) {
        GET_BITS(pBS, pData->predictor_reset, 1, Ipp32s)
        if (pData->predictor_reset) {
          GET_BITS(pBS, pData->predictor_reset_group_number, 5, Ipp32s)
        }
        pred_min_sfb =
          pData->max_sfb <
          pData->pred_max_sfb ? pData->max_sfb : pData->pred_max_sfb;
        for (i = 0; i < pred_min_sfb; i++) {
          GET_BITS(pBS, pData->prediction_used[i], 1, Ipp8u)
        }
        for (i = pred_min_sfb; i < pData->pred_max_sfb; i++) {
          pData->prediction_used[i] = 0;
        }
      } else if (audioObjectType == AOT_AAC_LTP) {
        GET_BITS(pBS, pData->ltp_data_present, 1, Ipp32s)
        if (pData->ltp_data_present) {
//                    dbg_trace("ltp_data_present\n");
          dec_ltp_data(pData, pBS, audioObjectType);
        }
      } else {
        return -1;
      }
    } else {
      if (audioObjectType == AOT_AAC_MAIN) {
        for (i = 0; i < pData->pred_max_sfb; i++) {
          pData->prediction_used[i] = 0;
        }
      }
    }
  }

  return 0;
}

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

Ipp32s ics_info_copy(s_SE_Individual_channel_stream *pDataSrc,
                     s_SE_Individual_channel_stream *pDataDst,
                     enum AudioObjectType audioObjectType)
{
  Ipp32s  i;

  pDataDst->ics_reserved_bit = pDataSrc->ics_reserved_bit;
  pDataDst->window_sequence = pDataSrc->window_sequence;
  pDataDst->window_shape = pDataSrc->window_shape;

  pDataDst->num_window_groups = 1;
  pDataDst->len_window_group[0] = 1;

  if (pDataSrc->window_sequence == EIGHT_SHORT_SEQUENCE) {
    pDataDst->num_windows = 8;
    pDataDst->max_sfb = pDataSrc->max_sfb;

    for (i = 0; i < 7; i++) {
      pDataDst->scale_factor_grouping[i] = pDataSrc->scale_factor_grouping[i];

      if (pDataDst->scale_factor_grouping[i] == 0) {
        pDataDst->len_window_group[pDataDst->num_window_groups] = 1;
        pDataDst->num_window_groups++;
      } else {
        pDataDst->len_window_group[pDataDst->num_window_groups - 1]++;
      }
    }

  } else {
    pDataDst->num_windows = 1;
    pDataDst->max_sfb = pDataSrc->max_sfb;
    pDataDst->predictor_data_present = pDataSrc->predictor_data_present;

    if (audioObjectType == AOT_AAC_MAIN) {
      pDataDst->predictor_reset = pDataSrc->predictor_reset;
      pDataDst->predictor_reset_group_number =
        pDataSrc->predictor_reset_group_number;
      for (i = 0; i < pDataDst->pred_max_sfb; i++) {
        pDataDst->prediction_used[i] = pDataSrc->prediction_used[i];
      }
    }
  }

  return 0;
}

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

⌨️ 快捷键说明

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