diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 6a9581498674393c2a698b645299d354c29f2a9c..bf832b6406227404a4b3ef4da5e6595bea4ae48e 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -60,6 +60,19 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); static void cldfb_init_proto_and_twiddles_enc_fx( HANDLE_CLDFB_FILTER_BANK hs ); +static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ); /*-------------------------------------------------------------------* * cplxMult() @@ -1552,6 +1565,168 @@ void resampleCldfb_ivas_fx( return; } +static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) +{ + Word16 j; + Word16 k; + Word16 s; + Word16 sm; + Word32 nrg; + Word16 numberColsL; + Word16 numberBandsM; + Word16 numberBandsM20; + Word32 energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 energyValuesSumE[CLDFB_NO_CHANNELS_MAX]; + // Word16 freqTable[2] = {20, 40}; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + + FOR( k = 0; k < numberCols; k++ ) + { + FOR( j = 0; j < numberBands; j++ ) + { + nrg = L_mult0( realValues[k][j], realValues[k][j] ); // Q(2*sf_Values) + nrg = L_mac0( nrg, imagValues[k][j], imagValues[k][j] ); // Q(2*sf_Values) + + energyValues[k][j] = nrg; + move32(); + } + } + + IF( GE_16( numberBands, freqTable[1] ) && hTecEnc != NULL ) + { + Word32 *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; + Word16 ScaleX2; + assert( numberCols == CLDFB_NO_COL_MAX ); + FOR( j = 0; j < numberCols; j++ ) + { + tempEnergyValuesArry[j] = &energyValues[j][0]; + } + + ScaleX2 = shl( sf_Values, 1 ); + calcHiEnvLoBuff_Fix( + numberCols, + freqTable, + 1, + tempEnergyValuesArry, + hTecEnc->loBuffer, + hTecEnc->hiTempEnv, + ScaleX2 ); + } + + FOR( j = 0; j < numberBands; j++ ) + { + energyValuesSum[j] = 0; + move32(); + energyValuesSumE[j] = 31; + move16(); + FOR( k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); // Q(2*sf_Values - (energyValuesSumE[j]-31)) + IF( LT_32( L_sub( maxWord32, nrg ), energyValuesSum[j] ) ) + { + energyValuesSumE[j] = add( energyValuesSumE[j], 1 ); + move16(); + energyValuesSum[j] = L_shr_r( energyValuesSum[j], 1 ); + move32(); + nrg = L_shr_r( nrg, 1 ); + } + energyValuesSum[j] = L_add( energyValuesSum[j], nrg ); + move32(); + } + test(); + if ( j == 0 || GT_16( energyValuesSumE[j], *energyValuesSum_Exp ) ) + { + *energyValuesSum_Exp = energyValuesSumE[j]; + move16(); + } + } + FOR( j = 0; j < numberBands; j++ ) + { + energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); // Q(energyValuesSum_Exp - (2*sf_Values)) + move32(); + } + *energyValuesSum_Exp = sub( *energyValuesSum_Exp, shl( sf_Values, 1 ) ); + move16(); + + IF( GT_16( numberBands, 20 ) ) + { + numberBandsM = s_min( numberBands, 40 ); + numberBandsM20 = sub( numberBandsM, 20 ); + + numberColsL = sub( numberCols, numLookahead ); + + /* sum up CLDFB energy above 8 kHz */ + s = BASOP_util_norm_s_bands2shift( i_mult( numberColsL, numberBandsM20 ) ); + s = sub( s, 4 ); + nrg = 0; + move32(); + FOR( k = 0; k < numberColsL; k++ ) + { + FOR( j = 20; j < numberBandsM; j++ ) + { + nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); + } + } + + s = sub( sub( shl( sf_Values, 1 ), 1 ), s ); + sm = sub( s_min( s, *sf_energyLookahead ), 1 ); + + *energyHF = L_add( L_shr( nrg, limitScale32( sub( s, sm ) ) ), + L_shr( *energyLookahead, sub( *sf_energyLookahead, sm ) ) ); // Q(31-(-nm)) + move32(); + + *energyHF_Exp = negate( sm ); + move16(); + + /* process look-ahead region */ + s = BASOP_util_norm_s_bands2shift( i_mult( numLookahead, numberBandsM20 ) ); + s = sub( s, 2 ); + nrg = 0; + move32(); + FOR( k = numberColsL; k < numberCols; k++ ) + { + FOR( j = 20; j < numberBandsM; j++ ) + { + nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); + } + } + + s = sub( shl( sf_Values, 1 ), s ); + sm = sub( s_min( s, 44 ), 1 ); + BASOP_SATURATE_WARNING_OFF_EVS + /* nrg + 6.1e-5f => value 0x40000000, scale 44 */ + *energyLookahead = L_add_sat( L_shr_sat( nrg, sub( s, sm ) ), + L_shr_sat( 0x40000000, s_max( -31, s_min( 31, sub( 44, sm ) ) ) ) ); + move32(); + BASOP_SATURATE_WARNING_ON_EVS + *sf_energyLookahead = sm; + move16(); + + return; + } + + + *energyHF = 0x40000000; + move32(); + *energyHF_Exp = 17; + move16(); +} + void analysisCldfbEncoder_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ @@ -1613,7 +1788,7 @@ void analysisCldfbEncoder_ivas_fx( AnalysisPostSpectrumScaling_Fx( st->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, ppBuf_Real16, ppBuf_Imag16, &enerScale.lb_scale16 ); - GetEnergyCldfb( &st->energyCoreLookahead_Fx, &st->sf_energyCoreLookahead_Fx, 1, ppBuf_Real16, ppBuf_Imag16, enerScale.lb_scale16, st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, &st->currEnergyHF_fx, &st->currEnergyHF_e_fx, ppBuf_Ener, enerBuffSum_exp, st->hTECEnc ); + GetEnergyCldfb_ivas_fx( &st->energyCoreLookahead_Fx, &st->sf_energyCoreLookahead_Fx, 1, ppBuf_Real16, ppBuf_Imag16, enerScale.lb_scale16, st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, &st->currEnergyHF_fx, &st->currEnergyHF_e_fx, ppBuf_Ener, enerBuffSum_exp, st->hTECEnc ); return; } diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index 8d3efb834861291c952a374edd1a1e3c9c7a065a..989f309d2f2a5ee0305103ec476bc9ca9416ba80 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -219,13 +219,13 @@ void find_targets_ivas_fx( /* first half: xn[] --> cn[] */ temp[0] = 0; move16(); - preemph_copy_fx( xn, cn, tilt_fac, L_SUBFR / 2, temp ); - syn_filt_s_lc_fx( 1, Ap, cn, temp, L_SUBFR / 2 ); /* Q-1 -> Q-2 */ - Residu3_lc_fx( p_Aq, M, temp, cn, L_SUBFR / 2, 1 ); /* Q-2 -> Q-1 */ - Scale_sig( cn, L_SUBFR / 2, 1 ); + preemph_copy_fx( xn, cn, tilt_fac, L_subfr / 2, temp ); + syn_filt_s_lc_fx( 1, Ap, cn, temp, L_subfr / 2 ); /* Q-1 -> Q-2 */ + Residu3_lc_fx( p_Aq, M, temp, cn, L_subfr / 2, 1 ); /* Q-2 -> Q-1 */ + Scale_sig( cn, L_subfr / 2, 1 ); /* second half: res[] --> cn[] (approximated and faster) */ - Copy( &res[i_subfr + ( L_SUBFR / 2 )], cn + ( L_SUBFR / 2 ), L_SUBFR / 2 ); + Copy( &res[i_subfr + ( L_subfr / 2 )], cn + ( L_subfr / 2 ), L_subfr / 2 ); } /*---------------------------------------------------------------*