📄 sbr_dec_hf_adjust_fp.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-2007 Intel Corporation. All Rights Reserved.
//
*/
#include<math.h>
#include <stdio.h>
#include "ipps.h"
#include "ippsr.h"
#include "sbr_settings.h"
#include "sbr_dec_struct.h"
#include "sbr_dec_tabs_fp.h"
#include "aac_dec_sbr_fp.h"
/********************************************************************/
static const Ipp32s POW_MINUS_UNIT[] =
{ 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1,
1, -1, 1, -1, 1, -1, 1, -1, 1, -1
};
/********************************************************************/
static const Ipp32f EPS0 = 1e-12f;
/********************************************************************/
static const Ipp32s SIN_FI_RE[4] = { 1, 0, -1, 0 };
/********************************************************************/
static const Ipp32s SIN_FI_IM[4] = { 0, 1, 0, -1 };
/********************************************************************/
static const Ipp32f TABLE_LIMIT_GAIN[4] = { 0.70795f, 1.f, 1.41254f, 1e10f };
/********************************************************************/
static const Ipp32f hSmoothFilter[] = { 0.03183050093751f,
0.11516383427084f,
0.21816949906249f,
0.30150283239582f,
0.33333333333333f
};
/********************************************************************/
static void sbrAliasReduction(Ipp32f *degPatched, Ipp32f *bufECurr,
Ipp32f *bufG, Ipp32s *s_mapped, Ipp32s kx,
Ipp32s M)
{
Ipp32f denum, energ_total, new_gain, energ_total_new, alpha;
Ipp32s grouping, i, n_group, k, m, i_start, i_end;
Ipp32s f_group[64];
/* -------------------------------- calculation gain groups ---------------------------- */
i = 0;
grouping = 0;
for (k = kx; k < kx + M - 1; k++) {
if (degPatched[k + 1] && s_mapped[k - kx] == 0) {
if (grouping == 0) {
f_group[i] = k;
grouping = 1;
i++;
}
} else {
if (grouping == 1) {
if (s_mapped[k - kx] == 0)
f_group[i] = k + 1;
else
f_group[i] = k;
grouping = 0;
i++;
}
}
}
if (grouping == 1) {
f_group[i] = M + kx;
i++;
}
n_group = i >> 1;
/* -------------------------------- aliasing reduction ---------------------------- */
for (k = 0; k < n_group; k++) {
i_start = f_group[2 * k] - kx;
i_end = f_group[2 * k + 1] - kx;
denum = EPS0;
energ_total = 0.0f;
for (i = i_start; i < i_end; i++) {
energ_total += bufG[i] * bufG[i] * bufECurr[i];
denum += bufECurr[i];
}
new_gain = energ_total / (denum);
energ_total_new = EPS0;
for (m = i_start + kx; m < i_end + kx; m++) {
if (m < M + kx - 1) {
alpha = IPP_MAX(degPatched[m], degPatched[m + 1]);
} else {
alpha = degPatched[m];
}
bufG[m - kx] =
alpha * new_gain + (1.0f - alpha) * bufG[m - kx] * bufG[m - kx];
}
for (i = i_start; i < i_end; i++)
energ_total_new += bufG[i] * bufECurr[i];
energ_total_new = energ_total / energ_total_new;
for (i = i_start; i < i_end; i++) {
bufG[i] = (Ipp32f)(sqrt(energ_total_new * bufG[i]));
}
}
return;
}
/********************************************************************/
static Ipp32s sbrUpdate_lA(Ipp32s bs_pointer, Ipp32s bs_frame_class, Ipp32s L_E)
{
Ipp32s table_lA[3][3] = {
{-1, -1, -1}, {-1, -1, -1}, {-1, -1, -1}
};
Ipp32s indx1, indx2;
Ipp32s lA;
table_lA[1][1] = table_lA[2][1] = L_E + 1 - bs_pointer;
table_lA[2][2] = bs_pointer - 1;
if ((bs_pointer > 1) || (bs_pointer < 0))
indx1 = 2;
else
indx1 = bs_pointer;
if (bs_frame_class == VARVAR)
indx2 = 1;
else
indx2 = bs_frame_class;
lA = table_lA[indx1][indx2];
return lA;
}
/********************************************************************/
static Ipp32s sbrSinAdd_LP_32f(Ipp32f **YRe, Ipp32s indxSine, Ipp32s i, Ipp32s tE0,
Ipp32s m, Ipp32s kx, Ipp32f *bufSM, Ipp32s M, Ipp32s *numSin)
{
Ipp32s fIndexSineMinus1 = 0;
Ipp32s fIndexSinePlus1 = 0;
Ipp32s num_sinusoids = *numSin;
Ipp32f ksi_middle = 0.f;
fIndexSineMinus1 = (indxSine + (i - 1) - RATE * tE0) & 3;
fIndexSinePlus1 = (indxSine + (i + 1) - RATE * tE0) & 3;
if (m == 0) {
YRe[i][m + kx - 1] =
-0.00815f * POW_MINUS_UNIT[kx -
1] * bufSM[0] * SIN_FI_RE[fIndexSinePlus1];
if (m < M - 1) {
YRe[i][m + kx] +=
-0.00815f * POW_MINUS_UNIT[kx] * bufSM[1] * SIN_FI_RE[fIndexSinePlus1];
}
} else if ((0 < m) && (m < M - 1) && (num_sinusoids < 16)) {
ksi_middle =
(bufSM[m - 1] * SIN_FI_RE[fIndexSineMinus1] +
bufSM[m + 1] * SIN_FI_RE[fIndexSinePlus1]);
ksi_middle *= -0.00815f * POW_MINUS_UNIT[m + kx];
YRe[i][m + kx] += ksi_middle;
} else if ((m == M - 1) && (num_sinusoids < 16)) {
if (m > 0) {
YRe[i][m + kx] +=
-0.00815f * POW_MINUS_UNIT[m + kx] * bufSM[m -
1] *
SIN_FI_RE[fIndexSineMinus1];
}
if (M + kx < 64) {
YRe[i][m + kx + 1] =
-0.00815f * POW_MINUS_UNIT[m + kx +
1] * bufSM[m] * SIN_FI_RE[fIndexSineMinus1];
}
}
if (bufSM[m])
num_sinusoids++;
*numSin = num_sinusoids;
return 0; // OK
}
/********************************************************************/
void sbrAdjustmentHF(Ipp32f **YBuf,
Ipp32f *bufEnvOrig, Ipp32f *bufNoiseOrig,
Ipp32f BufGain[][MAX_NUM_ENV_VAL],
Ipp32f BufNoise[][MAX_NUM_ENV_VAL],
sSBRDecComState * comState, Ipp32f *degPatched,
Ipp8u *WorkBuffer, Ipp32s reset, Ipp32s ch,
Ipp32s decode_mode)
{
/*
* VALUES
*/
Ipp32s k, m, n, pos, kl, kh, l, p, i, j, delta_step, delta;
Ipp32f energ, sumEOrig, sumECurr, g_max_temp, gainMax, denum, boost_gain,
gainFilt, noiseFilt;
Ipp32s iStart, iEnd;
Ipp32s nResolution;
Ipp32f mulQ = 0.0f;
Ipp32f mulQQ = 0.0f;
Ipp32f *bufSM;
Ipp32f *bufQM;
Ipp32f *bufECurr;
Ipp32f *bufEOrig;
Ipp32f *bufG;
Ipp32f bufQMapped[64];
Ipp32f sumEWoInterpol = 0.0f;
Ipp32f LimiterGains = TABLE_LIMIT_GAIN[comState->sbrHeader.bs_limiter_gains];
Ipp32s interpolation = comState->sbrHeader.bs_interpol_freq;
Ipp32s fIndexNoise = 0;
Ipp32s fIndexSine = 0;
Ipp32s num_sinusoids = 0;
Ipp32s s_mapped[64];
Ipp32s hSmoothLen = (comState->sbrHeader.bs_smoothing_mode == 0) ? 4 : 0;
Ipp32s hSmoothLenConst = hSmoothLen;
Ipp32s kx = comState->kx;
Ipp32s M = comState->M;
Ipp32s nEnv = comState->sbrFIState[ch].nEnv;
Ipp32s nNoiseEnv = comState->sbrFreqTabsState.nNoiseBand;// N_Q;
Ipp32s lA = 0;
Ipp32s offset_32f = 64 * sizeof(Ipp32f);
Ipp32s *sineIndxMap;
Ipp32s *sineIndxMapPrev;
Ipp32s *pFreqTbl;
Ipp32s *F[2];
Ipp32s resolution[2];
//Ipp32f **YRe = YBufRe + SBR_TIME_HFADJ;
//Ipp32f **YIm = YBufIm + SBR_TIME_HFADJ;
Ipp32fc** pYcmp = (Ipp32fc**)YBuf + SBR_TIME_HFADJ;
Ipp32f** pYre = YBuf + SBR_TIME_HFADJ;
sSBRFeqTabsState* pFTState = &( comState->sbrFreqTabsState );
sSBRFrameInfoState* pFIState = &( comState->sbrFIState[ch] );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -