📄 aac_filterbank_int.c
字号:
/*//// 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-2005 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 ipplic.htm 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_int.h"#include "aac_wnd_tables_int.h"/********************************************************************/#undef IS_POWER_2#undef GOTO_RET#undef RESERVE_SIZE#undef MDCT_BUFSIZE_COUNT/*******************************************************************/#define IS_POWER_2(len) (((len-1)&len)==0)#define GOTO_RET(stat) { res = stat; goto RET; }/*******************************************************************/#define MALLOC_ALIGNED_BYTES 32#define ALIGNED_PTR(ptr, bytes) \ (ptr + ((bytes - ((Ipp32s)ptr & (bytes-1))) & (bytes-1)))#define RESERVE_SIZE MALLOC_ALIGNED_BYTES#define RETURN_ALIGNED_MEM(ptr) ALIGNED_PTR(ptr, MALLOC_ALIGNED_BYTES)/*******************************************************************/#define MDCT_BUFSIZE_COUNT(FFTBufSize, MDCTBufSize) \ MDCTBufSize = FFTBufSize; \ if (MDCTBufSize < ((len)*(int)sizeof(Ipp32sc))) \ MDCTBufSize = ((len)*(int)sizeof(Ipp32sc)); \ \ MDCTBufSize += ((len/4)*sizeof(Ipp32sc) + MALLOC_ALIGNED_BYTES);/*******************************************************************/typedef struct { int len; int bufSize; int order; int alloc; Ipp32s *sincos; IppsFFTSpec_C_32sc *ctxFFT;} IppMDCTContext_32s;/*******************************************************************/static void deleteMdctCtx(IppMDCTContext_32s * pCtxMDCT){ if (pCtxMDCT != NULL) {// pCtxMDCT->idCtx = idCtxUnknown; if (pCtxMDCT->alloc != 0) { if (pCtxMDCT->ctxFFT != NULL) { ippsFFTFree_C_32sc(pCtxMDCT->ctxFFT); } ippsFree(pCtxMDCT); } }}/*******************************************************************/static void ownMDCTFwdPreProc_32s(Ipp32s *pSrc, Ipp32sc *y, int n, int scalef, Ipp32s *pSinCos){ int n4 = n / 4; Ipp64s round = 0; int i; Ipp64s re, im; if (scalef < 32) { round = ((Ipp64s)1) << (31 - scalef); } for (i = 0; i < (n4+1)/2; i++) { re = (Ipp64s)(-pSrc[n-n4+2*i]) - pSrc[n-n4-1-2*i]; im = (Ipp64s)(pSrc[n4-1-2*i]) - pSrc[n4+2*i]; y[i].re = (Ipp32s)((re * pSinCos[2*i+1] + im * pSinCos[2*i] + round) >> (32 - scalef)); y[i].im = (Ipp32s)((im * pSinCos[2*i+1] - re * pSinCos[2*i] + round) >> (32 - scalef)); } for (i = (n4+1)/2; i < n4; i++) { re = (Ipp64s)(pSrc[2*i-n4] ) - pSrc[n-n4-1-2*i]; im = (Ipp64s)(-pSrc[n-1+n4-2*i]) - pSrc[n4+2*i]; y[i].re = (Ipp32s)((re * pSinCos[2*i+1] + im * pSinCos[2*i] + round) >> (32 - scalef)); y[i].im = (Ipp32s)((im * pSinCos[2*i+1] - re * pSinCos[2*i] + round) >> (32 - scalef)); }}/*******************************************************************/static void ownMDCTInvPreProc_32s(Ipp32s *pSrc, Ipp32sc *y, int n, int scalef, Ipp32s *pSinCos){ int n2 = n / 2; int n4 = n / 4; Ipp64s round = 0; int i; Ipp64s re, im; if (scalef < 32) { round = ((Ipp64s)1) << (31 - scalef); } for (i = 0; i < n4; i++) { re = (Ipp64s)pSrc[2 * i]; im = (Ipp64s)pSrc[n2 - 1 - 2 * i]; y[i].re = (Ipp32s)((re * pSinCos[2 * i + 1] + im * pSinCos[2 * i] + round) >> (32 - scalef)); y[i].im = (Ipp32s)((im * pSinCos[2 * i + 1] - re * pSinCos[2 * i] + round) >> (32 - scalef)); }}/*******************************************************************/static void ownMDCTFwdPostProc_32s(Ipp32sc *y, Ipp64s *pDst, int n, Ipp32s *pSinCos){ int n2 = n / 2; int n4 = n / 4; int i; Ipp64s re, im; for (i = 0; i < n4; i++) { re = (Ipp64s)y[i].re; im = (Ipp64s)y[i].im; pDst[2*i] = re * pSinCos[2 * i + 1] + im * pSinCos[2 * i ]; pDst[n2-1-2*i] = re * pSinCos[2 * i ] - im * pSinCos[2 * i + 1]; }}/*******************************************************************/static void ownMDCTInvPostProc_32s(Ipp32sc *y, Ipp64s *pDst, int n, Ipp32s *pSinCos){ int n4 = n / 4; int i; Ipp64s re, im; for (i = 0; i < (n4 + 1) / 2; i++) { re = (Ipp64s)y[i].re * pSinCos[2 * i + 1] + (Ipp64s)y[i].im * pSinCos[2 * i]; im = (Ipp64s)y[i].im * pSinCos[2 * i + 1] - (Ipp64s)y[i].re * pSinCos[2 * i]; pDst[n - n4 + 2 * i] = -re; pDst[n - n4 - 1 - 2 * i] = -re; pDst[n4 + 2 * i] = im; pDst[n4 - 1 - 2 * i] = -im; } for (i = (n4 + 1) / 2; i < n4; i++) { re = (Ipp64s)y[i].re * pSinCos[2 * i + 1] + (Ipp64s)y[i].im * pSinCos[2 * i]; im = (Ipp64s)y[i].im * pSinCos[2 * i + 1] - (Ipp64s)y[i].re * pSinCos[2 * i]; pDst[2 * i - n4] = re; pDst[n - n4 - 1 - 2 * i] = -re; pDst[n4 + 2 * i] = im; pDst[n - 1 + n4 - 2 * i] = im; }}/*******************************************************************/static void ownFwdFillSinCosBuf_32s(Ipp32s *sincos, Ipp32s len){ double ang; int i; ang = IPP_2PI/len; for (i = 0; i < len/4; i++) { sincos[2*i ] = (Ipp32s)(sin(ang * (i+0.125)) * 1073741824 + 0.5); /* 1073741824 = 2^30 */ sincos[2*i+1] = (Ipp32s)(cos(ang * (i+0.125)) * 1073741824 + 0.5); }}/*******************************************************************/static IppStatus ownMDCTinitAlloc(IppMDCTContext_32s **ppCtxMDCT, int len){ IppMDCTContext_32s *pCtxMDCT = NULL; IppStatus res; Ipp32s *sincos; int i, order = 0; int stateSize, bufSize = 0, FFTBufSize = 0; stateSize = sizeof(IppMDCTContext_32s) + (len/2) * sizeof(Ipp32s) + MALLOC_ALIGNED_BYTES; pCtxMDCT = (IppMDCTContext_32s*)ippsMalloc_8u(stateSize); if (pCtxMDCT == NULL) { return ippStsMemAllocErr; } ippsZero_8u((Ipp8u*)pCtxMDCT, sizeof(IppMDCTContext_32s)); pCtxMDCT->alloc = 1; sincos = (Ipp32s*)((Ipp8u*)pCtxMDCT + sizeof(IppMDCTContext_32s)); sincos = (Ipp32s*)ALIGNED_PTR(sincos, MALLOC_ALIGNED_BYTES); pCtxMDCT->sincos = sincos; pCtxMDCT->len = len; if (IS_POWER_2(len)) { for (i = 1; i < len/4; i *= 2) { order++; } res = ippsFFTInitAlloc_C_32sc(&pCtxMDCT->ctxFFT, order, IPP_FFT_NODIV_BY_ANY, ippAlgHintNone); if (res != ippStsNoErr) { GOTO_RET(res); } res = ippsFFTGetBufSize_C_32sc(pCtxMDCT->ctxFFT, &FFTBufSize); if (res != ippStsNoErr) { GOTO_RET(res); } } MDCT_BUFSIZE_COUNT(FFTBufSize, bufSize) pCtxMDCT->bufSize = bufSize; pCtxMDCT->order = order; *ppCtxMDCT = pCtxMDCT; return (ippStsNoErr);RET: deleteMdctCtx(pCtxMDCT); return (res);}/*******************************************************************/static IppStatus ownMDCTinit(IppMDCTContext_32s **ppCtxMDCT, int len, Ipp8u *pMemSpec, Ipp8u *pMemInit){ IppMDCTContext_32s *pCtxMDCT = NULL; IppStatus res; Ipp32s *sincos; int i, order = 0; int bufSize, FFTBufSize = 0; pCtxMDCT = (IppMDCTContext_32s*)RETURN_ALIGNED_MEM(pMemSpec); ippsZero_8u((Ipp8u*)pCtxMDCT, sizeof(IppMDCTContext_32s)); pCtxMDCT->alloc = 0; sincos = (Ipp32s*)((Ipp8u*)pCtxMDCT + sizeof(IppMDCTContext_32s)); sincos = (Ipp32s*)ALIGNED_PTR(sincos, MALLOC_ALIGNED_BYTES); pCtxMDCT->sincos = sincos; pCtxMDCT->len = len; pCtxMDCT->ctxFFT = NULL; if (IS_POWER_2(len)) { for (i = 1; i < len/4; i *= 2) { order++; } res = ippsFFTInit_C_32sc(&pCtxMDCT->ctxFFT, order, IPP_FFT_NODIV_BY_ANY, ippAlgHintNone, (Ipp8u*)(sincos + (len/2)), pMemInit); if (res != ippStsNoErr) { GOTO_RET(res); } res = ippsFFTGetBufSize_C_32sc(pCtxMDCT->ctxFFT, &FFTBufSize); if (res != ippStsNoErr) { GOTO_RET(res); } } MDCT_BUFSIZE_COUNT(FFTBufSize, bufSize) pCtxMDCT->bufSize = bufSize; pCtxMDCT->order = order; *ppCtxMDCT = pCtxMDCT; return (ippStsNoErr);RET: deleteMdctCtx(pCtxMDCT); return (res);}/*******************************************************************/static IppStatus ippsMDCTFwdInitAlloc_32s(IppsMDCTFwdSpec_32s **ppMDCTSpec, int len){ IppStatus res; IppMDCTContext_32s *pCtxMDCT; res = ownMDCTinitAlloc(&pCtxMDCT, len); ownFwdFillSinCosBuf_32s(pCtxMDCT->sincos, len); if (res == ippStsNoErr) { *ppMDCTSpec = (IppsMDCTFwdSpec_32s*)pCtxMDCT; } return (res);}/*******************************************************************/static IppStatus ippsMDCTInvInitAlloc_32s(IppsMDCTInvSpec_32s **ppMDCTSpec, int len){ IppStatus res; IppMDCTContext_32s *pCtxMDCT; res = ownMDCTinitAlloc(&pCtxMDCT, len); ownFwdFillSinCosBuf_32s(pCtxMDCT->sincos, len); if (res == ippStsNoErr) { *ppMDCTSpec = (IppsMDCTInvSpec_32s*)pCtxMDCT; } return (res);}/*******************************************************************/static IppStatus ippsMDCTFwdInit_32s(IppsMDCTFwdSpec_32s **ppMDCTSpec, int len, Ipp8u *pMemSpec, Ipp8u *pMemInit){ IppStatus res; IppMDCTContext_32s *pCtxMDCT; res = ownMDCTinit(&pCtxMDCT, len, pMemSpec, pMemInit); ownFwdFillSinCosBuf_32s(pCtxMDCT->sincos, len); if (res == ippStsNoErr) { *ppMDCTSpec = (IppsMDCTFwdSpec_32s*)pCtxMDCT; } return (res);}/*******************************************************************/static IppStatus ippsMDCTInvInit_32s (IppsMDCTInvSpec_32s **ppMDCTSpec, int len, Ipp8u *pMemSpec, Ipp8u *pMemInit){ IppStatus res; IppMDCTContext_32s *pCtxMDCT; res = ownMDCTinit(&pCtxMDCT, len, pMemSpec, pMemInit); ownFwdFillSinCosBuf_32s(pCtxMDCT->sincos, len); if (res == ippStsNoErr) { *ppMDCTSpec = (IppsMDCTInvSpec_32s*)pCtxMDCT; } return (res);}/*******************************************************************/static IppStatus ippsMDCTFwdFree_32s (IppsMDCTFwdSpec_32s *pMDCTSpec){ IppMDCTContext_32s *pCtxMDCT; pCtxMDCT = (IppMDCTContext_32s*)pMDCTSpec; deleteMdctCtx(pCtxMDCT); return (ippStsNoErr);}/*******************************************************************/static IppStatus ippsMDCTInvFree_32s (IppsMDCTInvSpec_32s *pMDCTSpec){ IppMDCTContext_32s *pCtxMDCT; pCtxMDCT = (IppMDCTContext_32s*)pMDCTSpec; deleteMdctCtx(pCtxMDCT); return (ippStsNoErr);}/*******************************************************************/static IppStatus ippsMDCTFwdGetSize_32s (int len, int *pSizeSpec, int *pSizeInit, int *pSizeBuf){ IppStatus res; int i; int order = 0; int FFTSpecSize = 0, bufSize = 0, MDCTSpecSize; *pSizeInit = 0; if (IS_POWER_2(len)) { for (i = 1; i < len/4; i *= 2) { order++; } res = ippsFFTGetSize_C_32sc(order, IPP_FFT_NODIV_BY_ANY, ippAlgHintNone, &FFTSpecSize, pSizeInit, &bufSize); if (res != ippStsNoErr) { return (res); } } MDCT_BUFSIZE_COUNT(bufSize, bufSize) *pSizeBuf = bufSize; MDCTSpecSize = sizeof(IppMDCTContext_32s) + (len/2) * sizeof(Ipp32s) + 2 * MALLOC_ALIGNED_BYTES; *pSizeSpec = FFTSpecSize + MALLOC_ALIGNED_BYTES + MDCTSpecSize; return (ippStsNoErr);}/*******************************************************************/static IppStatus ippsMDCTInvGetSize_32s (int len, int *pSizeSpec, int *pSizeInit, int *pSizeBuf){ IppStatus res; int i; int order = 0; int FFTSpecSize = 0, bufSize = 0, MDCTSpecSize; *pSizeInit = 0; if (IS_POWER_2(len)) { for (i = 1; i < len/4; i *= 2) { order++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -