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

📄 aac_filterbank_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 <stdlib.h>
#include <math.h>
#include "aac_filterbank_fp.h"
#include "aac_wnd_tables_fp.h"

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

AACStatus InitFilterbank(sFilterbank* pBlock,
                         Ipp8u* mem,
                         Ipp32s mode,
                         enum AudioObjectType audioObjectType,
                         Ipp32s *sizeAll)
{
  Ipp32s i;
  Ipp32s j;
  Ipp32s sizeInit = 0;
  Ipp32s sizeWork = 0;
  Ipp32s sizeSpecInvLong = 0;
  Ipp32s sizeSpecInvShort = 0;
  Ipp32s sizeSpecFwdLong = 0;
  Ipp32s sizeSpecFwdShort = 0;
  Ipp32s sizeInitTmp = 0;
  Ipp32s sizeWorkTmp = 0;
  Ipp32s len_long = N_LONG;
  Ipp32s len_short = N_SHORT;
  Ipp32f *KBD_win_long = KBD_long;
  Ipp32f *KBD_win_short = KBD_short;
  Ipp8u  *ptrInvShort, *ptrFwdLong, *ptrFwdShort, *ptrWork, *ptrInit;

  if (pBlock) {
    if (AOT_AAC_SSR == audioObjectType) {
      len_long = N_LONG/4;
      len_short = N_SHORT/4;
      KBD_win_long = KBD_long_ssr;
      KBD_win_short = KBD_short_ssr;
    }

    ippsZero_8u((Ipp8u*)pBlock, sizeof(sFilterbank));
  }

  if (mode & FB_DECODER) {
    if (ippsMDCTInvGetSize_32f(len_long, &sizeSpecInvLong,
      &sizeInitTmp, &sizeWorkTmp) != ippStsOk) {
      return AAC_ALLOC;
    }

    if (sizeInit < sizeInitTmp) sizeInit = sizeInitTmp;
    if (sizeWork < sizeWorkTmp) sizeWork = sizeWorkTmp;

    if (ippsMDCTInvGetSize_32f(len_short, &sizeSpecInvShort,
        &sizeInitTmp, &sizeWorkTmp) != ippStsOk) {
        return AAC_ALLOC;
    }

    if (sizeInit < sizeInitTmp) sizeInit = sizeInitTmp;
    if (sizeWork < sizeWorkTmp) sizeWork = sizeWorkTmp;
  }

  if (mode & FB_ENCODER) {
    if (ippsMDCTFwdGetSize_32f(len_long, &sizeSpecFwdLong,
      &sizeInitTmp, &sizeWorkTmp) != ippStsOk) {
      return AAC_ALLOC;
    }

    if (sizeInit < sizeInitTmp) sizeInit = sizeInitTmp;
    if (sizeWork < sizeWorkTmp) sizeWork = sizeWorkTmp;

    if (ippsMDCTFwdGetSize_32f(len_short, &sizeSpecFwdShort,
        &sizeInitTmp, &sizeWorkTmp) != ippStsOk) {
      return AAC_ALLOC;
    }

    if (sizeInit < sizeInitTmp) sizeInit = sizeInitTmp;
    if (sizeWork < sizeWorkTmp) sizeWork = sizeWorkTmp;
  }

  *sizeAll = sizeSpecInvLong + sizeSpecInvShort + sizeSpecFwdLong +
             sizeSpecFwdShort + sizeWork + sizeInit;

  *sizeAll = 0;

  if (pBlock) {
#if 0
    ptrInvShort = mem + sizeSpecInvLong;
    ptrFwdLong = ptrInvShort + sizeSpecInvShort;
    ptrFwdShort = ptrFwdLong + sizeSpecFwdLong;
    ptrWork = ptrFwdShort + sizeSpecFwdShort;
    ptrInit = ptrWork + sizeWork;

    if (mode & FB_DECODER) {
      if (ippsMDCTInvInit_32f(&pBlock->p_mdct_inv_long, len_long,
        mem, ptrInit) != ippStsOk)
        return AAC_ALLOC;

      if (ippsMDCTInvInit_32f(&pBlock->p_mdct_inv_short, len_short,
        ptrInvShort, ptrInit) != ippStsOk)
        return AAC_ALLOC;
    }

    if (mode & FB_ENCODER) {
      if (ippsMDCTFwdInit_32f(&pBlock->p_mdct_fwd_long, len_long,
        ptrFwdLong, ptrInit) != ippStsOk)
        return AAC_ALLOC;

      if (ippsMDCTFwdInit_32f(&pBlock->p_mdct_fwd_short, len_short,
        ptrFwdShort, ptrInit) != ippStsOk)
        return AAC_ALLOC;
    }
#else
    ptrWork = ippsMalloc_8u(sizeWork);

    if (mode & FB_DECODER) {
      if (ippsMDCTInvInitAlloc_32f(&pBlock->p_mdct_inv_long, len_long) != ippStsOk)
        return AAC_ALLOC;

      if (ippsMDCTInvInitAlloc_32f(&pBlock->p_mdct_inv_short, len_short) != ippStsOk)
        return AAC_ALLOC;
    }

    if (mode & FB_ENCODER) {
      if (ippsMDCTFwdInitAlloc_32f(&pBlock->p_mdct_fwd_long, len_long) != ippStsOk)
        return AAC_ALLOC;

      if (ippsMDCTFwdInitAlloc_32f(&pBlock->p_mdct_fwd_short, len_short) != ippStsOk)
        return AAC_ALLOC;
    }

#endif


    pBlock->p_buffer_inv = ptrWork;
    pBlock->p_buffer_fwd = ptrWork;

    for (i = 0; i < len_short; i++) {
      pBlock->sin_short_wnd_table[i] =
        (Ipp32f)sin(PI/(2.0f * len_short/2) * (i + 0.5));
    }

    for (i = 0; i < len_long; i++) {
      pBlock->sin_long_wnd_table[i] =
        (Ipp32f)sin(PI/(2.0f * len_long/2) * (i + 0.5));
    }

    for (i = 0, j = (len_short)-1; i < len_short /2; i++, j--) {
      pBlock->KBD_short_wnd_table[j] =
        pBlock->KBD_short_wnd_table[i] = KBD_win_short[i];
    }

    for (i = 0, j = (len_long)-1; i < len_long/2; i++, j--) {
      pBlock->KBD_long_wnd_table[j] =
        pBlock->KBD_long_wnd_table[i] = KBD_win_long[i];
    }
  }

  return AAC_OK;
}

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

void FreeFilterbank(sFilterbank* pBlock)
{
  if (pBlock->p_mdct_inv_long) {
    ippsMDCTInvFree_32f(pBlock->p_mdct_inv_long);
    pBlock->p_mdct_inv_long = NULL;
  }
  if (pBlock->p_mdct_inv_short) {
    ippsMDCTInvFree_32f(pBlock->p_mdct_inv_short);
    pBlock->p_mdct_inv_short = NULL;
  }

  if (pBlock->p_mdct_fwd_long) {
    ippsMDCTFwdFree_32f(pBlock->p_mdct_fwd_long);
    pBlock->p_mdct_fwd_long = NULL;
  }

  if (pBlock->p_mdct_fwd_short) {
    ippsMDCTFwdFree_32f(pBlock->p_mdct_fwd_short);
    pBlock->p_mdct_fwd_short = NULL;
  }

  if (pBlock->p_buffer_inv) {
    ippsFree(pBlock->p_buffer_inv);
    pBlock->p_buffer_inv = NULL;
    pBlock->p_buffer_fwd = NULL;
  }
}

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

void FilterbankDec(sFilterbank* p_data,
                   Ipp32f* p_in_spectrum,
                   Ipp32f* p_in_prev_samples,
                   Ipp32s  window_sequence,
                   Ipp32s  window_shape,
                   Ipp32s  prev_window_shape,
                   Ipp32f* p_out_samples_1st_part,
                   Ipp32f* p_out_samples_2nd_part)
{
  Ipp32f samples[N_LONG];
  Ipp32f* p_samples;
  Ipp32f* p_spectrum;
  Ipp32f *window_table_long, *prev_window_table_long;
  Ipp32f *window_table_short, *prev_window_table_short;
  Ipp32f mdct_out_short[N_SHORT];
  Ipp32s j;

  if (0 == window_shape) {
    window_table_long  = p_data->sin_long_wnd_table;
    window_table_short = p_data->sin_short_wnd_table;
  } else {
    window_table_long  = p_data->KBD_long_wnd_table;
    window_table_short = p_data->KBD_short_wnd_table;
  }

  if (0 == prev_window_shape) {
    prev_window_table_long  = p_data->sin_long_wnd_table;
    prev_window_table_short = p_data->sin_short_wnd_table;
  } else {
    prev_window_table_long  = p_data->KBD_long_wnd_table;
    prev_window_table_short = p_data->KBD_short_wnd_table;
  }

  switch(window_sequence)
  {
  case ONLY_LONG_SEQUENCE:
    ippsMDCTInv_32f(p_in_spectrum, samples, p_data->p_mdct_inv_long,
                    p_data->p_buffer_inv);

    ippsMul_32f(prev_window_table_long, samples,
                p_out_samples_1st_part, N_LONG/2);

    ippsAdd_32f_I(p_in_prev_samples,p_out_samples_1st_part,N_LONG/2);

    ippsMul_32f(&window_table_long[N_LONG/2], &samples[N_LONG/2],
                p_out_samples_2nd_part, N_LONG/2);
    break;
  case LONG_START_SEQUENCE:
    ippsMDCTInv_32f(p_in_spectrum, samples, p_data->p_mdct_inv_long,
                    p_data->p_buffer_inv);

    ippsMul_32f(prev_window_table_long, samples,
                p_out_samples_1st_part, N_LONG/2);

    ippsAdd_32f_I(p_in_prev_samples, p_out_samples_1st_part, N_LONG/2);

    ippsCopy_32f(&samples[N_LONG / 2], p_out_samples_2nd_part,
                ((3*N_LONG-N_SHORT)/4-N_LONG/2));

    ippsMul_32f(&window_table_short[N_SHORT / 2],
                &samples[(3*N_LONG-N_SHORT)/4],
                &p_out_samples_2nd_part[((3*N_LONG-N_SHORT)/4-N_LONG/2)],
                N_SHORT/2);

    ippsZero_32f(&p_out_samples_2nd_part[(3*N_LONG+N_SHORT)/4-N_LONG/2],
                  N_LONG-(3*N_LONG+N_SHORT)/4);

⌨️ 快捷键说明

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