📄 sbrdec_decoder_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) 2005 Intel Corporation. All Rights Reserved.//*//********************************************************************/#include<ipps.h>#include<ippac.h>#include<math.h>#include"sbrdec_api_int.h"#include"sbrdec_element.h"#include"sbrdec_tables_int.h"#include"sbrdec_own_int.h"/********************************************************************/#ifndef ID_SCE#define ID_SCE 0x0#endif#ifndef ID_CPE#define ID_CPE 0x1#endif#ifndef UMC_MAX#define UMC_MAX(a,b) (((a) > (b)) ? (a) : (b))#endif#ifndef UMC_MIN#define UMC_MIN(a,b) (((a) < (b)) ? (a) : (b))#endif/********************************************************************/static Ipp32s sbrPassiveUpsampling(Ipp32s** XBufRe, Ipp32s** XBufIm, Ipp32s** iZBufRe, Ipp32s** iZBufIm, Ipp32s mode);/********************************************************************/static Ipp32s sbrActiveUpsampling(Ipp32s** XBufRe, Ipp32s** XBufIm, Ipp32s** iYBufRe, Ipp32s** iYBufIm, Ipp32s transitionBand, Ipp32s kx_prev, Ipp32s kx, Ipp32s M, Ipp32s M_prev, Ipp32s** iZBufRe, Ipp32s** iZBufIm, Ipp32s mode);/********************************************************************//* Set HF subbands to zero */int sbrCleanHFBand(int** pYBufRe, int** pYBufIm, int startBand, int stopBand);/********************************************************************/int sbrUpDateLowBand(int** pXBufRe, int** pXBufIm );/********************************************************************/static int sbrUpdateAmpRes( int bs_frame_class, int L_E, int bs_amp_res){ if ((bs_frame_class == FIXFIX) && (L_E == 1)) bs_amp_res = 0; return bs_amp_res;}/********************************************************************/Ipp32s sbrdecReset( sSbrBlock* pSbr ){ IppStatus status; sbrdecResetCommon( &(pSbr->sbr_com) ); // FIXED-POINT status = ippsZero_32s(pSbr->sbr_WS.iBufGain[0][0], 2*MAX_NUM_ENV*MAX_NUM_ENV_VAL); status = ippsZero_32s(pSbr->sbr_WS.iBufNoise[0][0], 2*MAX_NUM_ENV*MAX_NUM_ENV_VAL); status = ippsZero_32s(pSbr->sbr_WS.bwArray[0], 2*MAX_NUM_NOISE_VAL); return 0;//OK}/********************************************************************/sSbrBlock *sbrInitDecoder( void ){ Ipp32s ch, j; sSbrBlock *pSbr = 0; const Ipp32s Size32 = (32) * (NUM_TIME_SLOTS * RATE + SBR_TIME_HFGEN); const Ipp32s Size64 = (64) * (NUM_TIME_SLOTS * RATE + SBR_TIME_HFGEN); IppStatus status = ippStsNoErr; pSbr = (sSbrBlock *) ippsMalloc_8u(sizeof(sSbrBlock)); if ( pSbr == 0 ) return 0;/* -------------------------------- set memory for matrix ------------------------------------ */ for (ch = 0; ch < 2; ch++) { pSbr->sbr_WS.iXBufRe[ch][0] = ippsMalloc_32s((Size32 + 2 * Size64) * 2); ippsZero_32s(pSbr->sbr_WS.iXBufRe[ch][0], (Size32 + 2 * Size64) * 2); /* process need because mixing memory will be done */ pSbr->sbr_WS._dcMemoryMatrix[ch] = 0; pSbr->sbr_WS._dcMemoryMatrix[ch] = pSbr->sbr_WS.iXBufRe[ch][0]; for (j = 0; j < (NUM_TIME_SLOTS * RATE + SBR_TIME_HFGEN); j++) { pSbr->sbr_WS.iXBufRe[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + j * (32); pSbr->sbr_WS.iXBufIm[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + (Size32 + 2 * Size64) + j * (32); pSbr->sbr_WS.iZBufRe[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + (Size32 + 0 * Size64) + j * (64); pSbr->sbr_WS.iZBufIm[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + (Size32 + 2 * Size64) + (Size32 + 0 * Size64) + j * (64); pSbr->sbr_WS.iYBufRe[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + (Size32 + 1 * Size64) + j * (64); pSbr->sbr_WS.iYBufIm[ch][j] = pSbr->sbr_WS.iXBufRe[ch][0] + (Size32 + 2 * Size64) + (Size32 + 1 * Size64) + j * (64); } }/* -------------------------------- set default values ------------------------------------ */ /* FIXED-POINT BLOCK */ sbrdecReset( pSbr ); // only once time pSbr->sbr_com.sbrHeaderFlagPresent = 0;/* -------------------------------- malloc memory for general work buffer ---------------------------- */ if (status == ippStsNoErr) return pSbr; // OK else return 0;}/********************************************************************/Ipp32s sbrFreeDecoder(sSbrBlock * pSbr){ Ipp32s ch; if( pSbr == 0 ) return 0; for (ch = 0; ch < 2; ch++) { if( pSbr->sbr_WS._dcMemoryMatrix[ch] ) ippsFree( (Ipp32s*)(pSbr->sbr_WS._dcMemoryMatrix[ch]) ); } ippsFree(pSbr); return 0; // OK}/********************************************************************/Ipp32s sbrGetFrame(Ipp32s *pSrc, Ipp32s *pDst, sSbrBlock * pSbr, sSbrDecFilter* sbr_filter, int ch, int decode_mode, int dwnsmpl_mode, Ipp8u* pWorkBuffer, int* scaleFactor ){ sSbrDecCommon* com = &(pSbr->sbr_com); sSbrDecWorkSpace* ws = &(pSbr->sbr_WS); int l; int transitionBand = pSbr->sbr_com.transitionBand[ch]; /* patch */ Ipp32s* tmpMatrixBuffRe[1]; Ipp32s* tmpMatrixBuffIm[1]; int bs_amp_res; int my_ch;/* -------------------------------- Analysis ---------------------------- */ /********************************************************************* * NOTE: * (1) matrix idea is better than 1D * but if you can use this function for non-matrix, * you must use such consrtuctions * (2) you can use non-standard function of window and get better * result (speech codec or other area) *********************************************************************/ for(l=0; l<NUM_TIME_SLOTS * RATE; l++) { tmpMatrixBuffRe[0] = ws->iXBufRe[ch][l+SBR_TIME_HFGEN]; tmpMatrixBuffIm[0] = ws->iXBufIm[ch][l+SBR_TIME_HFGEN]; ippsAnalysisFilter_SBR_RToC_32s_D2L_Sfs(pSrc + l*32, tmpMatrixBuffRe, tmpMatrixBuffIm, SBR_TABLE_QMF_WINDOW_320_INT_Q30, 1, com->kx, sbr_filter->pFFTSpecQMFA, ws->AnalysisBufDelay[ch], pWorkBuffer, *scaleFactor); }/* -------------------------------- <SBR process> ---------------------------- */ if ((com->sbrHeaderFlagPresent != 0) && (com->sbrFlagError == 0) && ((com->id_aac == ID_SCE) || (com->id_aac == ID_CPE))) { /* skip couple channel for ch == R == 1 */ if ( !ch || !com->bs_coupling ) { bs_amp_res = sbrUpdateAmpRes( com->bs_frame_class[ch], com->L_E[ch], com->bs_amp_res); sbrDequantization( com, ws, ws->vScaleFactorsEOrig[ch], ch, bs_amp_res ); } /* Set HF subbands to zero */ { int startBand = RATE * com->tE[ch][0]; int stopBand = RATE * com->tE[ch][ com->L_E[ch] ]; sbrCleanHFBand(ws->iYBufRe[ch], ws->iYBufIm[ch], startBand, stopBand); } sbrGenerationHF(ws->iXBufRe[ch], ws->iXBufIm[ch], ws->iYBufRe[ch],ws->iYBufIm[ch], &(pSbr->sbr_com), ws->bwArray[ch], 0, ch, decode_mode, (Ipp32s*)pWorkBuffer ); if (com->bs_coupling) my_ch = 0; else my_ch = ch; sbrAdjustmentHF(//ws->YBufRe[ch], ws->YBufIm[ch], ws->iYBufRe[ch], ws->iYBufIm[ch], ws->vEOrig[ch], ws->vNoiseOrig[ch], ws->vScaleFactorsEOrig[my_ch], ws->iBufGain[ch], ws->iBufNoise[ch], &(pSbr->sbr_com), 0, pWorkBuffer, com->Reset, ch, decode_mode ); sbrActiveUpsampling( // in data ws->iXBufRe[ch], ws->iXBufIm[ch], ws->iYBufRe[ch], ws->iYBufIm[ch], transitionBand, com->kx_prev, com->kx, com->M, com->M_prev, // out data ws->iZBufRe[ch], ws->iZBufIm[ch], decode_mode);// store ch independ com->transitionBand[ch] = RATE * com->tE[ch][com->L_E[ch]] - NUM_TIME_SLOTS * RATE; } else { sbrPassiveUpsampling(ws->iXBufRe[ch], ws->iXBufIm[ch], ws->iZBufRe[ch], ws->iZBufIm[ch], decode_mode); } /********************************************************************************* * see comment in sbrPassiveUpsampling OR sbrActiveUpsampling functions *********************************************************************************/ ippsSynthesisFilter_SBR_CToR_32s_D2L(ws->iZBufRe[ch], ws->iZBufIm[ch], pDst, SBR_TABLE_QMF_WINDOW_640_INT_Q31, NUM_TIME_SLOTS * RATE, sbr_filter->pFFTSpecQMFS, ws->SynthesisBufDelay[ch], scaleFactor, // !!! pWorkBuffer); sbrUpDateLowBand(ws->iXBufRe[ch], ws->iXBufIm[ch] );/* ---------------------------- <store ch depend> ---------------------------- */ if ((com->id_aac == ID_SCE) || ((com->id_aac == ID_CPE) && (ch == 1))) { com->kx_prev = com->kx; com->M_prev = com->M; com->Reset = 0; } return 0; // OK}/********************************************************************/Ipp32s sbrPassiveUpsampling(Ipp32s** iXBufRe, Ipp32s** iXBufIm, Ipp32s** iZBufRe, Ipp32s** iZBufIm, Ipp32s mode){ Ipp32s l; /******************************************************************** * NOTE: code may be optimized (memory), if synthesis implement here ********************************************************************/ for (l = 0; l < NUM_TIME_SLOTS * RATE; l++) { ippsCopy_32s(iXBufRe[l + SBR_TIME_HFADJ], iZBufRe[l], NUM_TIME_SLOTS * RATE); ippsZero_32s(&(iZBufRe[l][32]), NUM_TIME_SLOTS * RATE); ippsCopy_32s(iXBufIm[l + SBR_TIME_HFADJ], iZBufIm[l], NUM_TIME_SLOTS * RATE); ippsZero_32s(&(iZBufIm[l][32]), NUM_TIME_SLOTS * RATE); } return 0; // OK}/********************************************************************/Ipp32s sbrActiveUpsampling( Ipp32s** iXBufRe, Ipp32s** iXBufIm, Ipp32s** iYBufRe, Ipp32s** iYBufIm, Ipp32s transitionBand, Ipp32s kx_prev, Ipp32s kx, Ipp32s M, Ipp32s M_prev, Ipp32s** iZBufRe, Ipp32s** iZBufIm, Ipp32s mode){ Ipp32s k, l; Ipp32s xoverBand, xoverM; /******************************************************************** * NOTE: code may be optimized (memory), if synthesis implement here ********************************************************************/ for (l = 0; l < 32; l++) { if (l < transitionBand) { xoverBand = kx_prev; xoverM = M_prev; } else { xoverBand = kx; xoverM = M; } for (k = 0; k < xoverBand; k++) { iZBufRe[l][k] = iXBufRe[SBR_TIME_HFADJ + l][k]; iZBufIm[l][k] = iXBufIm[SBR_TIME_HFADJ + l][k]; }/* if (mode == HEAAC_LP_MODE) { ZBufRe[l][xoverBand - 1] += YBufRe[SBR_TIME_HFADJ + l][xoverBand - 1]; }*/ for (k = xoverBand; k < 64; k++) { iZBufRe[l][k] = iYBufRe[SBR_TIME_HFADJ + l][k]; iZBufIm[l][k] = iYBufIm[SBR_TIME_HFADJ + l][k]; } }/* ----------------------- <Update High Band Data>------------------------- */ for (l = 0; l < SBR_TIME_HFGEN; l++) { int* pBufTmp = 0; // Re part pBufTmp = iYBufRe[l]; iYBufRe[l] = iYBufRe[l + 32]; iYBufRe[l + 32] = pBufTmp; // Im part pBufTmp = iYBufIm[l]; iYBufIm[l] = iYBufIm[l + 32]; iYBufIm[l + 32] = pBufTmp; //ippsCopy_32s(iYBufRe[NUM_TIME_SLOTS * RATE + l], iYBufRe[0 + l], 64); //ippsCopy_32s(iYBufIm[NUM_TIME_SLOTS * RATE + l], iYBufIm[0 + l], 64); } return 0; // OK}/********************************************************************//* Set HF subbands to zero */int sbrCleanHFBand(int** pYBufRe, int** pYBufIm, int startBand, int stopBand){ int i; for (i = startBand; i < stopBand; i++) { ippsZero_32s(pYBufRe[i + SBR_TIME_HFADJ], 64); ippsZero_32s(pYBufIm[i + SBR_TIME_HFADJ], 64); } return 0; //OK}/********************************************************************/int sbrUpDateLowBand(int** pXBufRe, int** pXBufIm ){ int l; int* pBufTmp; for (l = 0; l < SBR_TIME_HFGEN; l++) { // Re part pBufTmp = pXBufRe[l]; pXBufRe[l] = pXBufRe[NUM_TIME_SLOTS * RATE + l]; pXBufRe[NUM_TIME_SLOTS * RATE + l] = pBufTmp; // Im part pBufTmp = pXBufIm[l]; pXBufIm[l] = pXBufIm[NUM_TIME_SLOTS * RATE + l]; pXBufIm[NUM_TIME_SLOTS * RATE + l] = pBufTmp; //ippsCopy_32s(pXBufRe[NUM_TIME_SLOTS * RATE + l], pXBufRe[0 + l], NUM_TIME_SLOTS * RATE); //ippsCopy_32s(pXBufIm[NUM_TIME_SLOTS * RATE + l], pXBufIm[0 + l], NUM_TIME_SLOTS * RATE); } return 0;}/********************************************************************//* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -