📄 sbr_enc_sin_estimation_fp.c
字号:
state.bufGuideDiff[i+1] = 0;
for(est = start; est < stop; est++){
bufDetection[est][i+1] = 0;
}
} else {
state.bufGuideDetect[i] = 0;
state.bufGuideOrig[i] = 0;
state.bufGuideDiff[i] = 0;
for(est = start; est < stop; est++){
bufDetection[est][i] = 0;
}
}
}
}
return 0;//OK
}
/**************************************************************************/
static Ipp32s
sbrencTotalDetectionSinEst(Ipp32f bufT[][64],
Ipp32f bufDiff[][64],
Ipp32s nBand,
Ipp32s* pFreqTab,
Ipp32f bufSfmOrig[][64],
Ipp32f bufSfmSBR[][64],
Ipp32s bufDetection[][64],
Ipp32s* prev_bs_add_harmonic,
sSBRGuideData* pGuideState,
Ipp32s noEstPerFrame,
Ipp32s totNoEst,
Ipp32s newDetectionAllowed,
Ipp32s* bs_add_harmonic)
{
Ipp32s est = 0;
Ipp32s start = (newDetectionAllowed) ? noEstPerFrame : 0;
Ipp32s band;
ippsZero_32s(bs_add_harmonic, nBand);
/* ******************************
* up-date buffers
* ****************************** */
if(newDetectionAllowed){
ippsCopy_32f(pGuideState[0].bufGuideDiff, pGuideState[noEstPerFrame].bufGuideDiff, nBand);
ippsCopy_32f(pGuideState[0].bufGuideOrig, pGuideState[noEstPerFrame].bufGuideOrig, nBand);
ippsZero_32s(pGuideState[noEstPerFrame-1].bufGuideDetect, nBand);
}
for(est = start; est < totNoEst; est++){
if(est > 0){
ippsCopy_32s(bufDetection[est-1], pGuideState[est].bufGuideDetect, nBand);
}
ippsZero_32s(bufDetection[est], nBand);
band = (est < totNoEst-1) ? est+1 : est;
ippsZero_32f(pGuideState[band].bufGuideDiff, nBand);
ippsZero_32f(pGuideState[band].bufGuideOrig, nBand);
ippsZero_32s(pGuideState[band].bufGuideDetect, nBand);
/* ******************************
* main detection algorithm
* ****************************** */
sbrencDetectionSinEst(bufT[est],
bufDiff[est],
bufDetection[est],
pFreqTab,
nBand,
bufSfmOrig[est],
bufSfmSBR[est],
pGuideState[est],
pGuideState[band]);
}
/* *******************************************
* additional step: because there is transient
* ******************************************* */
if(newDetectionAllowed){
sbrencTransientCorrection(bufT,
bufDetection,
pFreqTab,
nBand,
pGuideState[noEstPerFrame],
start,
totNoEst);
}
/* *****************************************************
* finally decision: merged
* ***************************************************** */
for(band = 0; band< nBand; band++){
for(est = start; est < totNoEst; est++){
bs_add_harmonic[band] = bs_add_harmonic[band] || bufDetection[est][band];
}
}
/* *****************************************************
* detections that were not present before are removed
* ***************************************************** */
if(!newDetectionAllowed){
for(band=0; band < nBand; band++){
if(bs_add_harmonic[band] - prev_bs_add_harmonic[band] > 0) {
bs_add_harmonic[band] = 0;
}
}
}
return 0;//OK
}
/**************************************************************************/
static Ipp32s
sbrencCalcCompensation(Ipp32f bufT[][64],
Ipp32f bufDiff[][64],
Ipp32s* pFreqTab,
Ipp32s nBand,
Ipp32s* bs_add_harmonic,
Ipp32s* bufComp,
Ipp32s totNoEst)
{
Ipp32f maxVal;
Ipp32f curThres;
Ipp32s band, j, i, iStart, iEnd;
Ipp32s maxPosF,maxPosT;
Ipp32s compValue;
ippsZero_32s(bufComp, nBand);
for(band=0 ; band < nBand; band++){
if(0 == bs_add_harmonic[band]) continue;
/* miss sine has been detected */
iStart = pFreqTab[band];
iEnd = pFreqTab[band+1];
maxPosF = 0;
maxPosT = 0;
maxVal = 0;
for(j=0;j<totNoEst;j++){
for(i=iStart; i<iEnd; i++){
if(bufT[j][i] > maxVal) {
maxVal = bufT[j][i];
maxPosF = i;
maxPosT = j;
}
}
}
if(maxPosF == iStart && band){
compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band - 1]+EPS)) + 0.5f);
compValue = IPP_MIN( compValue, MAX_COMP );
if(!bs_add_harmonic[band-1]) {
if(bufT[maxPosT][maxPosF -1] > TONALITY_QUOTA*bufT[maxPosT][maxPosF]){
bufComp[band-1] = -1*compValue;
}
}
}
/* STEP2 [+1] */
if(maxPosF == iEnd-1 && band+1 < nBand){
compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band + 1]+EPS)) + 0.5f);
compValue = IPP_MIN( compValue, MAX_COMP );
if(!bs_add_harmonic[band+1]) {
if(bufT[maxPosT][maxPosF+1] > TONALITY_QUOTA*bufT[maxPosT][maxPosF]){
bufComp[band+1] = compValue;
}
}
}
/* intermediate band: (0, nBand) */
if(band && band < nBand - 1){
/* [-1] */
compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band -1]+EPS)) + 0.5f);
compValue = IPP_MIN( compValue, MAX_COMP );
curThres = bufDiff[maxPosT][band]*bufDiff[maxPosT][band-1];
curThres *= DIFF_QUOTA;
if(1.0f > curThres){
bufComp[band-1] = -1*compValue;
}
/* [+1] */
compValue = (Ipp32s) (fabs(ILOG2*log(bufDiff[maxPosT][band + 1]+EPS)) + 0.5f);
compValue = IPP_MIN( compValue, MAX_COMP );
curThres = bufDiff[maxPosT][band]*bufDiff[maxPosT][band+1];
curThres *= DIFF_QUOTA;
if(1.0f > curThres ){
bufComp[band+1] = compValue;
}
}
}
return 0; //OK
}
/**************************************************************************/
static Ipp32s
sbrencCompensationCorrect(Ipp32s* bufComp, Ipp32s* bufCompPrev, Ipp32s nBand)
{
Ipp32s band;
for(band = 0; band < nBand; band++){
if( (0 == bufCompPrev[band]) && (0 != bufComp[band]) ) {
bufComp[band] = 0;
}
}
return 0;//OK
}
/**************************************************************************/
static Ipp32s
sbrencIsHarmonicAddition(Ipp32s* bs_add_harmonic, Ipp32s nBand)
{
Ipp32s i;
for(i = 0; i < nBand; i++){
if (bs_add_harmonic[i]){
return bs_add_harmonic[i];
}
}
return 0;
}
/**************************************************************************/
Ipp32s sbrencSinEstimation(sSBREnc_SCE_State* pState, sSBRFeqTabsState* pFreqTabsState)
{
//sSBRFeqTabsState* pFreqTabsState = (pState->sbrFreqTabsState);
sSBRSinEst* pSinEst = &( pState->sbrSinEst );
Ipp32s* bufComp = pSinEst->bufCompensation;
Ipp32s* bufCompPrev = pSinEst->bufCompensationPrev;
Ipp32s* harmonicFlag = &(pState->sbrEDState.bs_add_harmonic_flag);
Ipp32s* prevTranFrame = &(pState->sbrTransientState.prevTranFrame);
Ipp32s* prevTranPos = &(pState->sbrTransientState.prevTranPos);
Ipp32s* prevTranFlag = &(pState->sbrTransientState.prevTranFlag);
Ipp32s nBand = pFreqTabsState->nHiBand;
Ipp32s tranFlag = pState->sbrTransientState.tranFlag;
Ipp32s tranPos = pState->sbrTransientState.tranPos;
Ipp32s tranPosOffset = 4;
Ipp32s isDetectNewTone = 0;
Ipp32s band;
Ipp32s criterion1, criterion2, criterion3;
/*
sbrencCalcInDataSinEst( pState->bufT,
pSinEst->bufDiff,
pSinEst->bufSfmOrig,
pSinEst->bufSfmSBR,
pState->tabPatchMap,
pState->fHiBandTab,
pState->nHiBand );
*/
isDetectNewTone = sbrencIsDetectNewToneAllow(&(pState->sbrFIState),
prevTranFrame,
prevTranPos,
prevTranFlag,
tranPosOffset,
tranFlag,
tranPos);
/* AYA log */
#ifdef SBR_NEED_LOG
fprintf(logFile, "\isDetection\nprevTranFlag = %i, prevTranFrame = %i, prevTranPos = %i\n",
*prevTranFlag, *prevTranFrame, *prevTranPos);
fprintf(logFile, "newDetection = %i\n", isDetectNewTone);
#endif
sbrencCalcInDataSinEst(pState->bufT,
pSinEst->bufDiff,
pSinEst->bufSfmOrig,
pSinEst->bufSfmSBR,
pState->tabPatchMap,
pFreqTabsState->fHiBandTab,
nBand);
sbrencTotalDetectionSinEst(pState->bufT,
pSinEst->bufDiff,
nBand,
pFreqTabsState->fHiBandTab,
pSinEst->bufSfmOrig,
pSinEst->bufSfmSBR,
pSinEst->bufDetection,
pSinEst->guideScfb,
pSinEst->sbrGuideState,
2, //Ipp32s noEstPerFrame,
4, //Ipp32s totNoEst,
isDetectNewTone,
pState->sbrEDState.bs_add_harmonic);
/* AYA log */
#ifdef SBR_NEED_LOG
{
Ipp32s i;
fprintf(logFile, "\naddHarmonic\n");
for(i=0; i<pFreqTabsState->nHiBand; i++){
fprintf(logFile, "%i\n", pState->sbrEDState.bs_add_harmonic[i]);
}
}
#endif
sbrencCalcCompensation(pState->bufT,
pSinEst->bufDiff,
pFreqTabsState->fHiBandTab,
nBand,
pState->sbrEDState.bs_add_harmonic,
bufComp,
4);
/* patch */
if( !isDetectNewTone ){
sbrencCompensationCorrect(bufComp, bufCompPrev, nBand);
}
*harmonicFlag = sbrencIsHarmonicAddition( pState->sbrEDState.bs_add_harmonic, nBand );
/* buffer up-date */
ippsCopy_32s(bufComp, bufCompPrev, nBand);
ippsCopy_32s(pState->sbrEDState.bs_add_harmonic, pSinEst->guideScfb, nBand);
ippsCopy_32s(pState->sbrEDState.bs_add_harmonic, pSinEst->sbrGuideState[0].bufGuideDetect, nBand);
ippsCopy_32f(pSinEst->sbrGuideState[2].bufGuideDiff, pSinEst->sbrGuideState[0].bufGuideDiff, nBand);
ippsCopy_32f(pSinEst->sbrGuideState[2].bufGuideOrig, pSinEst->sbrGuideState[0].bufGuideOrig, nBand);
for(band = 0; band < nBand; band++){
criterion1 = (Ipp32s)pSinEst->sbrGuideState[0].bufGuideDiff[band];
criterion2 = (Ipp32s)pSinEst->sbrGuideState[0].bufGuideOrig[band];
criterion3 = (Ipp32s)pState->sbrEDState.bs_add_harmonic[band];
if((criterion1 || criterion2) && !criterion3){
pSinEst->sbrGuideState[0].bufGuideDiff[band] = 0;
pSinEst->sbrGuideState[0].bufGuideOrig[band] = 0;
}
}
/* AYA log */
#ifdef SBR_NEED_LOG
{
Ipp32s i;
fprintf(logFile, "\nCompensation\n");
for(i=0; i<nBand; i++){
fprintf(logFile, "%i\n", pSinEst->bufCompensation[i]);
}
}
#endif
return 0; //OK
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -