diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2aa3311b8a8719f465fc9101cdf700dfb6e10ab1..7358bd3b5e10963266e35d3a3f5bafeb333bf191 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10830,8 +10830,8 @@ void ProcessStereoIGF_fx( Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 frameno, /* i : flag indicating index of current subfr. */ const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate /* i : element bitrate */ -); + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on ); /*igf_enc.c*/ void IGFEncApplyStereo_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ @@ -10844,8 +10844,8 @@ void IGFEncApplyStereo_fx( Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 frameno, /* i : flag indicating index of current subfr. */ const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate /* i : element bitrate */ -); + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on ); void IGFSaveSpectrumForITF_ivas_fx( IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 2e76bd1fd11462223a94df4fde6e943c26ab3df2..aeca8dff14131d58c6155fd7045c276a833a4110 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -3753,7 +3753,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( IF( LT_32( bitrate, ACELP_24k40 ) ) #endif { - syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); /* i: exc16kWhtnd in Q_bwe_exc */ /* o: excSHB in Q_bwe_exc */ } diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index cfef5801892d6cf3df8b5af6f3fcab0a0de94cbb..c15c6866657d1b7c26783976a8d66dc552edce4c 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -703,7 +703,7 @@ static void IGF_CalculateEnvelope_ivas_fx( BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb], negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &diffSFM ); test(); - IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, tmp_tb_e ) ) ) /* check whether target SFB is more tonal than source SFB */ + IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, hPrivateData->sfb_tb_e[sfb] ) ) ) /* check whether target SFB is more tonal than source SFB */ { Word16 currDampingFactor, dampingFactor; Word16 slope, threshold; @@ -2668,7 +2668,7 @@ void IGFEncApplyMono_ivas_fx( move16(); } } - IGF_ErodeSpectrum( &highPassEner_exp, st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx ); + IGF_ErodeSpectrum_ivas_fx( &highPassEner_exp, st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx, 0 ); } @@ -2689,8 +2689,8 @@ void IGFEncApplyStereo_fx( Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 frameno, /* i : flag indicating index of current subfr. */ const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate /* i : element bitrate */ -) + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on ) { Word16 highPassEner_exp; Word32 *pPowerSpectrumParameter_fx[NB_DIV]; /* If it is NULL it informs a function that specific handling is needed */ @@ -2766,7 +2766,7 @@ void IGFEncApplyStereo_fx( IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], &exp_pPowerSpectrum[0], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); - IGF_ErodeSpectrum( &highPassEner_exp, hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx ); + IGF_ErodeSpectrum_ivas_fx( &highPassEner_exp, hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], sts[ch]->hTcxEnc->spectrum_e[frameno], igfGridIdx, mct_on ); } return; } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index e7337cd0978a4d435c9ec16b1fd8f2078c19f046..9e38d4d6cdefa19275cfebb90d2fd1825e568676 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -516,6 +516,199 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou } } +void IGF_ErodeSpectrum_ivas_fx( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum Qx*/ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ + const Word16 mct_on ) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 i; + Word16 igfBgn; + Word16 igfEnd; + Word32 highPassEner; /* Q31 */ + Word32 lastLine; + Word32 nextLine; + Word32 L_c; + Word32 highPassEner_Ovfl; + Word16 s; + Word16 tmploop; + Word16 *swb_offset; + Word16 sfb; + Word16 startSfb; + Word16 stopSfb; + Word16 line; + Word16 flag; + Word16 *igfScaleF; + Word16 tmp; + Word32 L_tmp; + +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + Flag Carry = 0; + move32(); + move32(); +#endif + + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + igfBgn = hGrid->startLine; + move16(); + igfEnd = hGrid->stopLine; + move16(); + swb_offset = hGrid->swb_offset; + move16(); + startSfb = hGrid->startSfb; + move16(); + stopSfb = hGrid->stopSfb; + move16(); + igfScaleF = hPrivateData->igfScfQuantized; + move16(); + *highPassEner_exp = 0; + move16(); + highPassEner = 0; + move32(); + + IF( NULL == pPowerSpectrum ) + { + FOR( i = igfBgn; i < hGrid->infoGranuleLen; i++ ) + { + pSpectrum[i] = 0; + move32(); + } + return; + } + + IF( igfBgn > 0 ) + { + L_c = 0; + move32(); + FOR( i = 0; i < igfBgn; i++ ) + { + Carry = 0; + highPassEner = L_add_co( highPassEner, Mpy_32_16_1( pPowerSpectrum[i], shl( i, 4 ) /*Q4*/ ) /*Q20, pPowerSpectrum_exp*/, &Carry, &Overflow ); + Overflow = 0; + L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); + } + + highPassEner = norm_llQ31( L_c, highPassEner, highPassEner_exp ); /*Q20, highPassEner_exp*/ + *highPassEner_exp = add( *highPassEner_exp, pPowerSpectrum_exp ); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600 ) || + EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200 ) || + EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) || + EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_16400_CPE ) ) + { + igfBgn = shl( igfBgn, 0 ); + } + ELSE IF( mct_on && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) ) ) + { + igfBgn = imult1616( igfBgn, 45 /*0.7.Q6*/ ); + igfBgn = shr( igfBgn, 7 ); + } + ELSE + { + igfBgn = shl( igfBgn, 1 ); + } + highPassEner = L_deposit_l( BASOP_Util_Divide3216_Scale( highPassEner /*Q20, highPassEner_exp*/, igfBgn /*Q0*/, &s ) ); /*Q15, highPassEner_exp+11-16+s*/ + *highPassEner_exp = add( add( *highPassEner_exp, s ), 12 - 16 + ( 31 - 15 ) ); /*Q15->Q31,highPassEner_exp*/ + lastLine = pSpectrum[i - 1]; + move32(); + nextLine = 0; + move32(); + + /* May overflow - just for threshold comparison */ + /* negate because the negated may be 1 larger in abs, */ + /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger */ + highPassEner_Ovfl = L_shl_o( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ), &Overflow ); + L_tmp = L_add_o( pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow ); + + if ( L_tmp >= 0 ) + { + nextLine = pSpectrum[i]; + move32(); + } + tmploop = sub( igfEnd, 1 ); + FOR( /*i*/; i < tmploop; i++ ) + { + /* May overflow - just for threshold comparison */ + BASOP_SATURATE_WARNING_OFF_EVS + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); + BASOP_SATURATE_WARNING_ON_EVS; + + IF( L_tmp < 0 ) + { + lastLine = pSpectrum[i]; + move32(); + pSpectrum[i] = nextLine; + move32(); + nextLine = 0; + move32(); + } + ELSE + { + pSpectrum[i - 1] = lastLine; + move32(); + lastLine = pSpectrum[i]; + move32(); + nextLine = pSpectrum[i + 1]; + move32(); + } + } + + /* May overflow - just for threshold comparison */ + BASOP_SATURATE_WARNING_OFF_EVS + L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); + BASOP_SATURATE_WARNING_ON_EVS + if ( L_tmp < 0 ) + { + pSpectrum[i] = 0; + move32(); + } + } + + /* delete spectrum above igfEnd: */ + FOR( i = igfEnd; i < hGrid->infoGranuleLen; i++ ) + { + pSpectrum[i] = 0; + pPowerSpectrum[i] = 0; + move32(); + move32(); + } + + FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) + { + flag = 0; + move16(); + FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ ) + { + if ( pSpectrum[line] != 0 ) + { + flag = 1; + move16(); + } + } + tmp = igfScaleF[sfb]; + move16(); + IF( flag ) + { + tmp = sub( igfScaleF[sfb], 1 ); + } + if ( igfScaleF[sfb] ) + { + igfScaleF[sfb] = tmp; + move16(); + } + } +} + /**********************************************************************/ /* crest factor calculation **************************************************************************/ diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index 7729bbff5b2d88eb5517f4f3a1dc2bbc21ea4c3c..18218aa257144fde5068e0a7799cf17a9672b152 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -1088,7 +1088,7 @@ void mctStereoIGF_enc_fx( ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, q_origSpec, q_origSpec, - p_powerSpec_fx, p_powerSpecMsInv_fx, p_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate ); + p_powerSpec_fx, p_powerSpecMsInv_fx, p_inv_spectrum_fx, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); } ELSE { diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 354871a3eacab1cc60d28b3c12f95810dbec9b67..ffc671d4126704f6d9128b99a18e21b723b79856 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -653,7 +653,7 @@ void stereo_mdct_core_enc_fx( move16(); ProcessStereoIGF_fx( hStereoMdct, sts, ms_mask, orig_spectrum_fx, sub( Q31, p_orig_spectrum_e[0] ), sub( Q31, p_orig_spectrum_e[1] ), - p_powerSpec_fx, powerSpecMsInv_fx, inv_spectrum_fx, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate ); + p_powerSpec_fx, powerSpecMsInv_fx, inv_spectrum_fx, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 ); } ELSE { @@ -672,9 +672,10 @@ void stereo_mdct_core_enc_fx( { q_spectrum = s_min( q_spectrum, sub( Q31, st->hIGFEnc->spec_be_igf_e ) ); } + q_spectrum = sub( Q31, st->hTcxEnc->spectrum_e[n] ); - Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ + Scale_sig32( orig_spectrum_fx[ch][n], st->hIGFEnc->infoStopLine, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); } @@ -712,9 +713,10 @@ void stereo_mdct_core_enc_fx( { q_spectrum = s_min( q_spectrum, sub( Q31, st->hIGFEnc->spec_be_igf_e ) ); } + q_spectrum = sub( Q31, st->hTcxEnc->spectrum_e[n] ); - Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ + Scale_sig32( orig_spectrum_fx[ch][n], st->hIGFEnc->infoStopLine, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 8c034e73c9d3bee791207c3807046612dbe9540a..f993c8e28b9fe8adf62dd5d298e811440cb09734 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -557,8 +557,8 @@ void stereo_tcx_core_enc( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); - s = sub( getScaleFactor16( st->synth, st->L_frame ), 2 ); - s = s_min( s, getScaleFactor16( st->hLPDmem->syn, M ) ); + s = sub( norm_arr( st->synth, st->L_frame ), 2 ); + s = s_min( s, norm_arr( st->hLPDmem->syn, M ) ); IF( st->tcxonly == 0 ) { s = s_min( s, norm_s( st->wspeech_enc[st->L_frame - 1] ) ); @@ -579,7 +579,7 @@ void stereo_tcx_core_enc( coder_tcx_post_ivas_fx( st, st->hLPDmem, st->hTcxCfg, st->synth, A_q_fx, Aw_fx, st->wspeech_enc, Q_new ); /* Upscaling old_exc buffer */ - s = getScaleFactor16( st->hLPDmem->old_exc, L_EXC_MEM ) - 1; + s = norm_arr( st->hLPDmem->old_exc, L_EXC_MEM ) - 1; Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, s ); IF( st->hTdCngEnc != NULL ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index a4beb2f4c06e636a9135c90b7a6c612ad876e037..c80b502c46946fd6a77dd830e8c07a41d81d4f34 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3033,6 +3033,15 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< out: | Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ); + +void IGF_ErodeSpectrum_ivas_fx( Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ + const Word16 mct_on ); + void IGFEncApplyMono_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ Encoder_State *st, /**< in: | Encoder state */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 6f75c37873c3654ab4540b0c0308020d5c945d32..bafd932a3088f30bb93d3b9eaa081a4c58589816 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -3947,8 +3947,8 @@ void ProcessStereoIGF_fx( Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i : inverse spectrum */ const Word16 frameno, /* i : flag indicating index of current subfr. */ const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ - const Word32 element_brate /* i : element bitrate */ -) + const Word32 element_brate, /* i : element bitrate */ + const Word16 mct_on ) { Word16 ch, igfGridIdx, isIndepFlag, bsBits, pBsStart, curr_order; Word16 predictionGain; @@ -3988,7 +3988,7 @@ void ProcessStereoIGF_fx( IGFSaveSpectrumForITF_ivas_fx( hIGFEnc[1], igfGridIdx, pITFMDCTSpectrum_fx[1][frameno], sub( Q31, q_pITFMDCTSpectrum_2 ) ); - IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, inv_spectrum_fx, frameno, sp_aud_decision0, element_brate ); + IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, inv_spectrum_fx, frameno, sp_aud_decision0, element_brate, mct_on ); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) {