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

📄 aac_dec_decoding_fp.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) 2003-2006 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 "aac_dec_fp.h"
#include "aac_dec_own.h"
#include "aac_dec_own_fp.h"
#include <math.h>

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

static Ipp32s is_intensity(s_SE_Individual_channel_stream *pData,
                           Ipp32s group,
                           Ipp32s sfb);

static Ipp32s is_noise(s_SE_Individual_channel_stream *pData,
                       Ipp32s group,
                       Ipp32s sfb);

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

Ipp32s ics_apply_scale_factors(s_SE_Individual_channel_stream *pData,
                               Ipp32f *p_spectrum)
{
  Ipp32s  g;
  Ipp32s  w_num;
  Ipp32f  real_sf[60];

  if (pData->window_sequence != EIGHT_SHORT_SEQUENCE) {
    if (pData->sfb_offset_long_window[pData->max_sfb] > 0) {
      ippsPow43_16s32f(pData->spectrum_data, p_spectrum,
        pData->sfb_offset_long_window[pData->max_sfb]);

      ippsCalcSF_16s32f(pData->sf[0], SF_OFFSET, real_sf, pData->max_sfb);
      ippsScale_32f_I(p_spectrum, real_sf, pData->sfb_offset_long_window,
                      pData->max_sfb);
    }

    ippsZero_32f(p_spectrum + pData->sfb_offset_long_window[pData->max_sfb],
                 1024 - pData->sfb_offset_long_window[pData->max_sfb]);

  } else {
    Ipp32s sfb_offset_buf[20], i;

    if (pData->sfb_offset_long_window[pData->max_sfb] > 0) {

      ippsPow43_16s32f(pData->spectrum_data, p_spectrum,
        pData->sfb_offset_short_window[pData->max_sfb] * 8);

      for (g = 0; g < pData->num_window_groups; g++) {
        w_num = pData->len_window_group[g];

        for (i = 0; i <= pData->max_sfb; i++) {
          sfb_offset_buf[i] = pData->sfb_offset_short_window[i] * w_num;
        }

        ippsCalcSF_16s32f(pData->sf[g], SF_OFFSET, real_sf, pData->max_sfb);
        ippsScale_32f_I(p_spectrum, real_sf, sfb_offset_buf, pData->max_sfb);

        p_spectrum +=
          w_num * pData->sfb_offset_short_window[pData->max_sfb];
      }
    }
  }

  return 0;
}

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

Ipp32s cpe_apply_ms(sCpe_channel_element *pElement,
                    Ipp32f *l_spec,
                    Ipp32f *r_spec)
{
  Ipp32s i, g, sfb;
  Ipp32f tmp;
  Ipp32s *sfb_offset;
  Ipp32s num_window_groups = pElement->streams[0].num_window_groups;
  Ipp32s max_sfb = pElement->streams[0].max_sfb;
  s_SE_Individual_channel_stream *p_ics_right;

  p_ics_right = &pElement->streams[1];

  sfb_offset =
    pElement->streams[0].window_sequence == EIGHT_SHORT_SEQUENCE ?
    pElement->streams[0].sfb_offset_short_window :
    pElement->streams[0].sfb_offset_long_window;

  if (pElement->ms_mask_present >= 1) {
    for (g = 0; g < num_window_groups; g++) {
      Ipp32s len_window_group = pElement->streams[0].len_window_group[g];
      for (sfb = 0; sfb < max_sfb; sfb++) {
        if ((pElement->ms_used[g][sfb] || pElement->ms_mask_present == 2) &&
            !is_intensity(p_ics_right, g, sfb) &&
            !is_noise(p_ics_right, g, sfb)) {
          for (i = sfb_offset[sfb] * len_window_group;
               i < sfb_offset[sfb + 1]  * len_window_group; i++) {
            tmp = l_spec[i] - r_spec[i];
            l_spec[i] = l_spec[i] + r_spec[i];
            r_spec[i] = tmp;
          }
        }
      }
      l_spec += sfb_offset[max_sfb] * len_window_group;
      r_spec += sfb_offset[max_sfb] * len_window_group;
    }
  }
  return 0;
}

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

static Ipp32s invert_intensity(sCpe_channel_element *pElement,
                               Ipp32s group,
                               Ipp32s sfb)
{
  if (pElement->ms_mask_present == 1)
    return (1 - 2 * pElement->ms_used[group][sfb]);
  return 1;
}

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

Ipp32s cpe_apply_intensity(sCpe_channel_element *pElement,
                           Ipp32f *l_spec,
                           Ipp32f *r_spec)
{
  Ipp32s i, g, sfb;
  Ipp32f scale;
  Ipp32s *sfb_offset;
  Ipp32s num_window_groups;
  Ipp32s max_sfb;
  s_SE_Individual_channel_stream *p_ics_right;

  p_ics_right = &pElement->streams[1];

  sfb_offset =
    pElement->streams[0].window_sequence == EIGHT_SHORT_SEQUENCE ?
    pElement->streams[0].sfb_offset_short_window :
    pElement->streams[0].sfb_offset_long_window;

  num_window_groups = p_ics_right->num_window_groups;
  max_sfb = p_ics_right->max_sfb;

  for (g = 0; g < num_window_groups; g++) {
    Ipp32s len_window_group = p_ics_right->len_window_group[g];
    for (sfb = 0; sfb < max_sfb; sfb++) {
        if (is_intensity(p_ics_right, g, sfb)) {
          scale =
            is_intensity(p_ics_right, g, sfb) * invert_intensity(pElement, g,
                                                                 sfb) *
            (Ipp32f)pow(0.5, (0.25 * p_ics_right->sf[g][sfb]));

          for (i = sfb_offset[sfb] * len_window_group;
             i < sfb_offset[sfb + 1]  * len_window_group; i++) {
          r_spec[i] = l_spec[i] * scale;
        }
      }
    }
    l_spec += sfb_offset[max_sfb] * len_window_group;
    r_spec += sfb_offset[max_sfb] * len_window_group;
  }

  return 0;
}

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

Ipp32s is_intensity(s_SE_Individual_channel_stream *pData,
                    Ipp32s group,
                    Ipp32s sfb)
{
  switch (pData->sfb_cb[group][sfb]) {
  case INTENSITY_HCB:
    return 1;
  case INTENSITY_HCB2:
    return -1;
  default:
    return 0;
  }
}

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

Ipp32s is_noise(s_SE_Individual_channel_stream *pData,
                Ipp32s group,
                Ipp32s sfb)
{
  if (pData->sfb_cb[group][sfb] == NOISE_HCB)
    return 1;
  return 0;
}

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

static Ipp32f noise_generator(Ipp32f *dst,
                              Ipp32s len,
                              Ipp32s *noiseState)
{
  Ipp32f norm;
  Ipp32s seed, i;

  norm = 0;
  seed = *noiseState;
  for (i = 0; i < len; i++) {
    seed = (1664525L * seed) + 1013904223L;
    dst[i] = (Ipp32f)seed;
    norm += dst[i] * dst[i];
  }
  *noiseState = seed;

  norm = (Ipp32f)(1 / sqrt(norm));
  return(norm);
}

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

Ipp32s apply_pns(s_SE_Individual_channel_stream *pDataL,
                 s_SE_Individual_channel_stream *pDataR,
                 Ipp32f *p_spectrumL,
                 Ipp32f *p_spectrumR,
                 Ipp32s numCh,
                 Ipp32s ms_mask_present,
                 Ipp32s ms_used[8][49],
                 Ipp32s *noiseState)
{
  Ipp32s  i, g, sfb, ich;
  Ipp32f  norm;
  Ipp32s  *sfb_offset;
  Ipp32s  num_window_groups, max_sfb;
  s_SE_Individual_channel_stream *pData = pDataL;
  Ipp32f  *p_spectrum = p_spectrumL;
  Ipp32f  *p_spectrum_l = p_spectrumL;

  for (ich = 0; ich < numCh; ich++) {
    sfb_offset = pData->window_sequence == EIGHT_SHORT_SEQUENCE ?
      pData->sfb_offset_short_window : pData->sfb_offset_long_window;

    num_window_groups = pData->num_window_groups;
    max_sfb = pData->max_sfb;

    for (g = 0; g < num_window_groups; g++) {
      Ipp32s len_window_group = pData->len_window_group[g];
      for (sfb = 0; sfb < max_sfb; sfb++) {
        if (pData->sfb_cb[g][sfb] == NOISE_HCB) {
          Ipp32s tmp = 0;
          if ((ich == 1) && (ms_mask_present >= 1)) {
            if ((ms_used[g][sfb] != 0) || (ms_mask_present == 2)) {
              tmp = 1;
            }
          }

          if (tmp) {
            norm = (Ipp32f)pow(2.0, 0.25 * (pData->sf[g][sfb] - pDataL->sf[g][sfb]));

            for (i = sfb_offset[sfb] * len_window_group;
                  i < sfb_offset[sfb + 1]  * len_window_group; i++) {
              p_spectrum[i] = norm * p_spectrum_l[i];
            }
          } else {
            norm = noise_generator(p_spectrum + sfb_offset[sfb] * len_window_group,
                                   (sfb_offset[sfb + 1] - sfb_offset[sfb]) * len_window_group,
                                   noiseState);

            norm *= (Ipp32f)pow(2.0, 0.25 * (pData->sf[g][sfb]));

⌨️ 快捷键说明

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