diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7a7126490db82d87e25a8f2c7f077977b198387f..c89b5a6040475d0bfc6b7fb32739c5c2e364412f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1652,9 +1652,9 @@ void InternalTCXDecoder( void stereo_mdct_core_enc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples */ - Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ + Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples Q0*/ + Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP Qx*/ + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe Q6*/ ); void initMdctStereoEncData( @@ -1931,12 +1931,12 @@ void splitAvailableBits( int16_t *bits_ch1 /* o : bits for channel 1 */ ); -int16_t write_stereo_to_bitstream +Word16 write_stereo_to_bitstream_fx ( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ - int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); diff --git a/lib_com/options.h b/lib_com/options.h index b1141a2d1c9c847045445efe9cb0e1c4681cae19..a6da9ca3a65a71cda2ad93653cad2ff3545f9190 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -104,7 +104,6 @@ #define FIX_1127_IMPROVE_SBA_MLD /* Ittiam: Avoid saturation for DiRAC reference power */ #define FIX_1100_REMOVE_LPC_RESCALING /* VA: Remove the rescaling of LPC coefficient to Q12 as residu and syn-filt are already taking care of it*/ #define FIX_1133_IMPROVE_MC_MLD /* Ittiam: Correcting wrong updation of exponents in ivas_mc_paramupmix_param_est_enc_fx() */ - #define FIX_ISSUE_1122 /* Ittiam: Fix issue 1122: corrected incorrect scaling of a buffer leading to incorrect metadata bits */ #define FIX_1132_STACK_CORRUPTION /* Stack corruption issue due of extending index access*/ #endif diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 7a08226e6965f430712dffa0b718d7476eb1cd77..e3b554fcb4ee702814d03c814d7b7531f98cdd0e 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3799,7 +3799,7 @@ void QuantizeTCXSpectrum_fx( } /* Quantize original spectrum */ - sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); + sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly ); @@ -3887,7 +3887,7 @@ void QuantizeTCXSpectrum_fx( } ELSE { - sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); + sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); } /* Quantize spectrum */ tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly ); diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index db8ca015496e2fac9d6fba4059527925140ac78e..27203fedef2dafdf9921f0006aafd84d4786299f 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -496,13 +496,13 @@ void ivas_mct_core_enc_fx( FOR( i = 1; i < L_subframeTCX - 1; i++ ) { - mdst_fx = L_sub( L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i - 1], 1 ) ); /* An MDST estimate */ + mdst_fx = L_sub( L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i - 1], 1 ) ); /* An MDST estimate, Q = q_spec - 1 */ - W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ) ); + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ) ); // Q = 2 * (q_spec - 1) + 1 tmp_s = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp ); - tmp_q_powSpec[add( i, imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + powerSpec_fx[ch][i + ( n * L_subframeTCX )] = W_extract_h( W_tmp ); + tmp_q_powSpec[i + ( n * L_subframeTCX )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 33 ); // Q = 2 * (q_spec - 1) + 1 + tmp_s - 32 move32(); move16(); } diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index db6d8916cef61c38c87ca125eb505a6af97d9d55..30c45b5ef3245af9f21b09b8f1759e737031b295 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -959,7 +959,7 @@ void write_mct_bitstream_fx( p_st[1] = sts[hBlock->ch2]; /*then business as usual for each block pair */ - write_stereo_to_bitstream( hMCT->hBlockData[pair]->hStereoMdct, p_st, hBlock->mask, 1, hBstr ); + write_stereo_to_bitstream_fx( hMCT->hBlockData[pair]->hStereoMdct, p_st, hBlock->mask, 1, hBstr ); } hMCT->nBitsMCT = sub( hBstr->nb_bits_tot, nbits_start ); diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 28218d70d4752d444463a6a490574e85054484ba..6f080d8a81d3ac3c6500ed79b0e9ffa37f544a60 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6542,7 +6542,6 @@ void ivas_omasa_encode_masa_to_total_fx( Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; Word32 dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; Word32 dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - Word16 dct_data_e = 0, dct_data_tmp_e, q_dct_data_e; Word16 bits_pos, nb_bits; Word16 n_streams, len_stream, tmp_e; Word32 L_tmp; @@ -6558,7 +6557,7 @@ void ivas_omasa_encode_masa_to_total_fx( { FOR( j = 0; j < nblocks; j++ ) { - data[k] = masa_to_total_energy_ratio[j][i]; + data[k] = L_shr( masa_to_total_energy_ratio[j][i], Q5 ); move32(); k = add( k, 1 ); } @@ -6571,42 +6570,42 @@ void ivas_omasa_encode_masa_to_total_fx( SWITCH( len_stream ) { case 4: - matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, data, 1 /* Q30*/, 1, nblocks, 1, dct_data, &dct_data_e ); + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 0, data, 1, nblocks, 1, dct_data ); n_streams = 1; len_stream = 4; move16(); BREAK; case 5: - matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + matrix_product_q30_fx( dct5_fx, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); n_streams = 1; len_stream = nbands; move16(); move16(); BREAK; case 8: - matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + matrix_product_q30_fx( dct8_fx, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); n_streams = 1; len_stream = nbands; move16(); BREAK; case 12: - matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + matrix_product_q30_fx( dct12_fx, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); n_streams = 1; len_stream = nbands; move16(); move16(); BREAK; case 20: - matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); - matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + matrix_product_fx( dct5_fx, nbands, nbands, 0, data, nblocks, nbands, 1, dct_data_tmp ); + matrix_product_q30_fx( dct_data_tmp, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 1, dct_data ); n_streams = 1; len_stream = imult1616( nbands, nblocks ); move16(); move16(); BREAK; case 32: - matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); - matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + matrix_product_fx( dct8_fx, nbands, nbands, 0, data, nblocks, nbands, 1, dct_data_tmp ); + matrix_product_q30_fx( dct_data_tmp, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 1, dct_data ); n_streams = nblocks; len_stream = nbands; move16(); @@ -6622,7 +6621,7 @@ void ivas_omasa_encode_masa_to_total_fx( j = imult1616( k, len_stream ); /* quantize with fixed common step */ L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j], step, &tmp_e ); - tmp_e = add( tmp_e, dct_data_e ); + tmp_e = add( tmp_e, Q1 ); q_idx[j] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) /* Q16 */ ); // Q0 move16(); @@ -6645,7 +6644,7 @@ void ivas_omasa_encode_masa_to_total_fx( FOR( i = 1; i < len_stream; i++ ) { L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j + i], step, &tmp_e ); - tmp_e = add( tmp_e, dct_data_e ); + tmp_e = add( tmp_e, Q1 ); q_idx[j + i] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) ); move16(); q_dct_data[j + i] = Mpy_32_16_1( step, shl( q_idx[j + i], 9 ) /* Q9 */ ); // Q25 @@ -6689,50 +6688,38 @@ void ivas_omasa_encode_masa_to_total_fx( } } - q_dct_data_e = 6; // Q25 - move16(); /* inverse DCT2 transform */ SWITCH( len_stream ) { case 4: - matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, q_dct_data, q_dct_data_e, nblocks, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data, nblocks, 1, 0, dct_data_tmp ); Copy32( dct_data_tmp, q_dct_data, nblocks ); - q_dct_data_e = dct_data_tmp_e; - move16(); BREAK; case 5: - matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); Copy32( dct_data_tmp, q_dct_data, nbands ); - q_dct_data_e = dct_data_tmp_e; - move16(); BREAK; case 8: - matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); Copy32( dct_data_tmp, q_dct_data, nbands ); - q_dct_data_e = dct_data_tmp_e; - move16(); BREAK; case 12: - matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); Copy32( dct_data_tmp, q_dct_data, nbands ); - q_dct_data_e = dct_data_tmp_e; - move16(); BREAK; case 20: - matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); - matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); /* reuse of variable*/ + matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product_q30_fx( dct_data_tmp, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data ); /* reuse of variable*/ BREAK; case 32: - matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); - matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); + matrix_product_fx( dct8_fx, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product_q30_fx( dct_data_tmp, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data ); BREAK; default: printf( "Incorrect number of coefficients for OMASA.\n" ); BREAK; } - scale_sig32( q_dct_data, MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS, sub( Q30, sub( 31, q_dct_data_e ) ) ); // Scaling to Q30 - k = 0; move16(); FOR( i = 0; i < nblocks; i++ ) diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index dbf4e1f7cfe5cb2b388a9e22e8133c46a40e9c3a..3cdf88902dab6b866b623ff6012926b12c89b365 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -52,14 +52,14 @@ static void unclr_calc_corr_features_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier handle */ STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: ICA Stereo Encoder handle */ - Word32 buf1[], /* i : left channel */ - Word32 buf2[], /* i : right channel */ + Word32 buf1[], /* i : left channel q_com*/ + Word32 buf2[], /* i : right channel q_com*/ Word16 q_com, - const Word16 length, /* i : length of input signal buffers */ - Word32 corrEst[], /* i : buffer containing inter-channel correlation values */ + const Word16 length, /* i : length of input signal buffers Q0*/ + Word32 corrEst[], /* i : buffer containing inter-channel correlation values Q31-corrEst_exp*/ Word16 corrEst_exp, - const int16_t lagSearchRange[], /* i : minimum and maximum lags for corrEst[] */ - Word32 *corrEst_ncorr, /* o : norm. x-correlation btw. current and previous correlation buffers */ + const Word16 lagSearchRange[], /* i : minimum and maximum lags for corrEst[] Q0*/ + Word32 *corrEst_ncorr, /* o : norm. x-correlation btw. current and previous correlation buffers Q31-corrEst_ncorr_exp*/ Word16 *corrEst_ncorr_exp ); @@ -82,11 +82,11 @@ static void unclr_calc_corr_features_fx( * ---------------------------------------------------------------*/ static void tcaTargetCh_LA_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, - Word32 *ptrChanL, - Word32 *ptrChanR, + Word32 *ptrChanL, /* q_com */ + Word32 *ptrChanR, /* q_com */ Word16 *q_com, - const Word16 currentNCShift, - const Word16 input_frame ) + const Word16 currentNCShift, /* Q0 */ + const Word16 input_frame /* Q0 */ ) { Word16 i, j; Word16 tempS, temp, sine_inp; @@ -121,44 +121,46 @@ static void tcaTargetCh_LA_fx( move32(); tempF2_exp = 0; move16(); - FOR( i = 0; i < sub( input_frame, currentNCShift ); i++ ) + FOR( i = 0; i < ( input_frame - currentNCShift ); i++ ) { - tempF1 = BASOP_Util_Add_Mant32Exp( tempF1, tempF1_exp, L_abs( ref[i] ), ref_exp, &tempF1_exp ); - tempF2 = BASOP_Util_Add_Mant32Exp( tempF2, tempF2_exp, L_abs( target[i + currentNCShift] ), target_exp, &tempF2_exp ); + tempF1 = BASOP_Util_Add_Mant32Exp( tempF1, tempF1_exp, L_abs( ref[i] ), ref_exp, &tempF1_exp ); /* Q31-tempF1_exp */ + tempF2 = BASOP_Util_Add_Mant32Exp( tempF2, tempF2_exp, L_abs( target[i + currentNCShift] ), target_exp, &tempF2_exp ); /* Q31-tempF2_exp */ } IF( tempF1 == 0 ) { - gAdj = ONE_IN_Q31; + gAdj = ONE_IN_Q31; /* Q31 */ move32(); gAdj_exp = 0; move16(); } ELSE { - Word32 deno = BASOP_Util_Add_Mant32Exp( tempF1, tempF1_exp, -21475 /*0.00001f in Q31*/, 0, &temp ); + Word32 deno = BASOP_Util_Add_Mant32Exp( tempF1, tempF1_exp, -21475 /*0.00001f in Q31*/, 0, &temp ); /* Q31-temp */ Word16 deno_exp; IF( deno > 0 ) { deno = tempF1; + move32(); deno_exp = tempF1_exp; + move16(); } ELSE { deno = 21475; + move32(); deno_exp = 0; + move16(); } - move32(); - move32(); - gAdj = BASOP_Util_Divide3232_Scale_cadence( tempF2, deno, &gAdj_exp ); + gAdj = BASOP_Util_Divide3232_Scale_cadence( tempF2, deno, &gAdj_exp ); /* Q31-gAdj_exp */ gAdj_exp = add( gAdj_exp, sub( tempF2_exp, deno_exp ) ); } FOR( i = 0; i < tempS; i++ ) { - sine_inp = BASOP_Util_Divide1616_Scale( add( shl( i, 10 ), 512 ), shl( tempS, 1 ), &temp ); - sine_inp = shl_sat( sine_inp, add( temp, -10 ) ); - win[i] = getSineWord16R2( shr( sine_inp, 1 ) ); + sine_inp = BASOP_Util_Divide1616_Scale( add( shl( i, 10 ), 512 /* 0.5 Q10 */ ), shl( tempS, 1 ), &temp ); /* Q15-(temp+(15-10)) */ + sine_inp = shl_sat( sine_inp, add( temp, -10 ) ); /*Q0*/ + win[i] = getSineWord16R2( shr( sine_inp, 1 ) ); /*Q15*/ move16(); } @@ -167,9 +169,9 @@ static void tcaTargetCh_LA_fx( Word16 exp_com = target_exp_temp[0]; move16(); - FOR( i = sub( input_frame, add( currentNCShift, tempS ) ); i < sub( input_frame, currentNCShift ); ( i++, j++ ) ) + FOR( i = ( input_frame - ( currentNCShift + tempS ) ); i < ( input_frame - currentNCShift ); ( i++, j++ ) ) { - target[i + currentNCShift] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( Mpy_32_16_1( gAdj, win[j] ), ref[i] ), add( ref_exp, gAdj_exp ), Mpy_32_16_1( target[i + currentNCShift], sub( MAX_16, win[j] ) ), target_exp, &temp ); + target[i + currentNCShift] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( Mpy_32_16_1( gAdj, win[j] ), ref[i] ), add( ref_exp, gAdj_exp ), Mpy_32_16_1( target[i + currentNCShift], sub( MAX_16, win[j] ) ), target_exp, &temp ); /* Q31-temp */ move32(); target_exp_temp[i + currentNCShift] = temp; move16(); @@ -178,7 +180,7 @@ static void tcaTargetCh_LA_fx( FOR( ; i < input_frame; i++ ) { - target[i + currentNCShift] = Mpy_32_32( gAdj, ref[i] ); + target[i + currentNCShift] = Mpy_32_32( gAdj, ref[i] ); /* Q31-target_exp_temp */ move32(); target_exp_temp[i + currentNCShift] = add( gAdj_exp, ref_exp ); move16(); @@ -187,9 +189,9 @@ static void tcaTargetCh_LA_fx( FOR( i = 0; i < input_frame; i++ ) { - target[i] = L_shl( target[i], sub( target_exp_temp[i], exp_com ) ); + target[i] = L_shl( target[i], sub( target_exp_temp[i], exp_com ) ); /* Q31-exp_com */ move32(); - ref[i] = L_shl( ref[i], sub( ref_exp, exp_com ) ); + ref[i] = L_shl( ref[i], sub( ref_exp, exp_com ) ); /* Q31-exp_com */ move32(); } *q_com = sub( 31, exp_com ); @@ -206,8 +208,8 @@ static void tcaTargetCh_LA_fx( void spectral_balancer_fx16( Word16 *signal, /* i/o : signal Qx */ Word16 *mem, /* i/o : mem Qx */ - const Word16 lg, /* i : input signal length */ - const Word16 coeff_set /* i : coefficient set */ + const Word16 lg, /* i : input signal length Q0*/ + const Word16 coeff_set /* i : coefficient set Q0*/ ) { Word16 i; @@ -268,26 +270,26 @@ void spectral_balancer_fx16( FOR( i = 0; i < lg; i++ ) { - x2 = x1; + x2 = x1; /*Qx*/ move16(); - x1 = x0; + x1 = x0; /*Qx*/ move16(); - x0 = signal[i]; + x0 = signal[i]; /*Qx*/ move16(); // y0 = (y1 * a1) + (y2 * a2) + (x0 * b0) + (x1 * b1) + (x2 * b2); y0 = extract_l( W_extract_l( W_shr( W_mac_32_16( W_mac_32_16( W_mac_32_16( W_mac_32_16( W_mult_32_16( a1, y1 ), a2, y2 ), b0, x0 ), b1, x1 ), b2, x2 ), 30 ) ) ); // Qx - signal[i] = y0; + signal[i] = y0; /*Qx*/ move16(); - y2 = y1; + y2 = y1; /*Qx*/ move16(); - y1 = y0; + y1 = y0; /*Qx*/ move16(); } - mem[0] = y1; - mem[1] = y2; - mem[2] = x0; - mem[3] = x1; + mem[0] = y1; /*Qx*/ + mem[1] = y2; /*Qx*/ + mem[2] = x0; /*Qx*/ + mem[3] = x1; /*Qx*/ move16(); move16(); move16(); @@ -299,18 +301,18 @@ void spectral_balancer_fx16( void spectral_balancer_fx( Word32 *signal, /* i/o : signal Qx */ Word32 *mem, /* i/o : mem Qx */ - const Word16 lg, /* i : input signal length */ - const Word16 coeff_set /* i : coefficient set */ + const Word16 lg, /* i : input signal length Q0*/ + const Word16 coeff_set /* i : coefficient set Q0*/ ) { Word16 i; Word32 x0, x1, x2, y0, y1, y2; Word32 a1, a2, b0, b1, b2; - y1 = mem[0]; - y2 = mem[1]; - x0 = mem[2]; - x1 = mem[3]; + y1 = mem[0]; /*Qx*/ + y2 = mem[1]; /*Qx*/ + x0 = mem[2]; /*Qx*/ + x1 = mem[3]; /*Qx*/ move32(); move32(); move32(); @@ -351,28 +353,28 @@ void spectral_balancer_fx( FOR( i = 0; i < lg; i++ ) { - x2 = x1; + x2 = x1; /*Qx*/ move16(); - x1 = x0; + x1 = x0; /*Qx*/ move16(); - x0 = signal[i]; + x0 = signal[i]; /*Qx*/ move16(); y0 = W_extract_l( W_shr( W_mac_32_32( W_mac_32_32( W_mac_32_32( W_mac_32_32( W_mult_32_32( a1, y1 ), a2, y2 ), b0, x0 ), b1, x1 ), b2, x2 ), 30 ) ); // Qx - signal[i] = y0; + signal[i] = y0; /*Qx*/ move16(); - y2 = y1; + y2 = y1; /*Qx*/ move16(); - y1 = y0; + y1 = y0; /*Qx*/ move16(); } - mem[0] = y1; + mem[0] = y1; /*Qx*/ move32(); - mem[1] = y2; + mem[1] = y2; /*Qx*/ move32(); - mem[2] = x0; + mem[2] = x0; /*Qx*/ move32(); - mem[3] = x1; + mem[3] = x1; /*Qx*/ move32(); return; @@ -384,14 +386,14 @@ void spectral_balancer_fx( * * De-emphasize and resample the L and R channels. * ---------------------------------------------------------------*/ -static void deEmphResample( +static void deEmphResample_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo TCA encoder handle */ const Word32 *tempChan1_fx, /* i : Stereo data Qx*/ const Word32 *tempChan2_fx, /* i : Stereo data Qx*/ - Word32 *chan1_fx, // Qx - Word32 *chan2_fx, // Qx - const Word16 input_frame, - const Word16 dsFactor ) + Word32 *chan1_fx, /*Qx*/ + Word32 *chan2_fx, /*Qx*/ + const Word16 input_frame, /*Q0*/ + const Word16 dsFactor /*Q0*/ ) { Word32 buf1_fx[L_FRAME48k], buf2_fx[L_FRAME48k]; Word32 tempBuf1_fx[2 * L_FRAME_DS], tempBuf2_fx[2 * L_FRAME_DS]; @@ -399,23 +401,23 @@ static void deEmphResample( Word16 dsFac1, dsFac2; /* Estimate first and second stage downsample factors */ - dsFac1 = shr( dsFactor, 1 ); - dsFac2 = idiv1616( dsFactor, dsFac1 ); + dsFac1 = shr( dsFactor, 1 ); /*Qx*/ + dsFac2 = idiv1616( dsFactor, dsFac1 ); /*Qx*/ /* convert stereo data to two distinct channels, e.g., L, R */ - Copy32( tempChan1_fx, buf1_fx, input_frame ); - Copy32( tempChan2_fx, buf2_fx, input_frame ); + Copy32( tempChan1_fx, buf1_fx, input_frame ); /*Qx*/ + Copy32( tempChan2_fx, buf2_fx, input_frame ); /*Qx*/ /* De-emphasis, 1/(1-mu z^-1), and resample, stage 1 */ deemph_fx_32( 0, buf1_fx, PREEMPH_FAC_16k, input_frame, &hStereoTCA->memdecim_fx[0] ); deemph_fx_32( 0, buf2_fx, PREEMPH_FAC_16k, input_frame, &hStereoTCA->memdecim_fx[1] ); - FOR( i = 0; i < idiv1616( input_frame, dsFac1 ); i++ ) + FOR( i = 0; i < ( input_frame / dsFac1 ); i++ ) { - tempBuf1_fx[i] = buf1_fx[i * dsFac1]; + tempBuf1_fx[i] = buf1_fx[i * dsFac1]; /*Qx*/ move32(); - tempBuf2_fx[i] = buf2_fx[i * dsFac1]; + tempBuf2_fx[i] = buf2_fx[i * dsFac1]; /*Qx*/ move32(); } @@ -423,11 +425,11 @@ static void deEmphResample( deemph_fx_32( 0, tempBuf1_fx, PREEMPH_FAC_16k, idiv1616( input_frame, dsFac1 ), &hStereoTCA->memdecim_fx[2] ); deemph_fx_32( 0, tempBuf2_fx, PREEMPH_FAC_16k, idiv1616( input_frame, dsFac1 ), &hStereoTCA->memdecim_fx[3] ); - FOR( i = 0; i < idiv1616( input_frame, dsFactor ); i++ ) + FOR( i = 0; i < ( input_frame / dsFactor ); i++ ) { - chan1_fx[i] = tempBuf1_fx[i * dsFac2]; + chan1_fx[i] = tempBuf1_fx[i * dsFac2]; /*Qx*/ move32(); - chan2_fx[i] = tempBuf2_fx[i * dsFac2]; + chan2_fx[i] = tempBuf2_fx[i * dsFac2]; /*Qx*/ move32(); } @@ -444,13 +446,13 @@ static void deEmphResample( * ---------------------------------------------------------------*/ static void utilCrossCorr_mod_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: ICA Stereo Encoder handle */ - Word32 *buf1, - Word32 *buf2, + Word32 *buf1, /*q_com*/ + Word32 *buf2, /*q_com*/ const Word16 q_com, - Word32 *corrEst, /* o : correlation estimate */ - Word16 *corrEst_Exp, /* o : correlation estimate */ - const Word16 *lagSearchRange, - const Word16 len ) + Word32 *corrEst, /* o : correlation estimate Q31-corrEst_Exp*/ + Word16 *corrEst_Exp, /* o : correlation estimate Q31-corrEst_Exp*/ + const Word16 *lagSearchRange, /*Q0*/ + const Word16 len /*Q0*/ ) { Word32 C, E1, E2, C_C_mem; Word16 i, j, E1_exp, E2_exp, Inv_Tot_E_exp, k, C_exp, exp, gb; @@ -463,33 +465,33 @@ static void utilCrossCorr_mod_fx( gb = 0; move16(); - if ( LT_16( L_norm_arr( buf1, len ), 2 ) ) + IF( LT_16( L_norm_arr( buf1, len ), 2 ) ) { gb = 2; move16(); } - E1 = sum2_32_exp_fx( buf1, len, &E1_exp, gb ); + E1 = sum2_32_exp_fx( buf1, len, &E1_exp, gb ); /* Q31-E1_exp */ gb = 0; move16(); - if ( LT_16( L_norm_arr( buf2, len ), 2 ) ) + IF( LT_16( L_norm_arr( buf2, len ), 2 ) ) { gb = 2; move16(); } - E2 = sum2_32_exp_fx( buf2, len, &E2_exp, gb ); + E2 = sum2_32_exp_fx( buf2, len, &E2_exp, gb ); /* Q31-E2_exp */ - Word32 E1_mul = BASOP_Util_Add_Mant32Exp( E1, E1_exp, hStereoTCA->E1_mem_fx, hStereoTCA->E1_mem_exp, &E1_exp ); - Word32 E2_mul = BASOP_Util_Add_Mant32Exp( E2, E2_exp, hStereoTCA->E2_mem_fx, hStereoTCA->E2_mem_exp, &E2_exp ); + Word32 E1_mul = BASOP_Util_Add_Mant32Exp( E1, E1_exp, hStereoTCA->E1_mem_fx, hStereoTCA->E1_mem_exp, &E1_exp ); /* Q31-E1_exp */ + Word32 E2_mul = BASOP_Util_Add_Mant32Exp( E2, E2_exp, hStereoTCA->E2_mem_fx, hStereoTCA->E2_mem_exp, &E2_exp ); /* Q31-E2_exp */ Word32 sqr_inp = Mpy_32_32( E1_mul, E2_mul ); Word16 sq_exp = add( E1_exp, E2_exp ); IF( sqr_inp ) { - sqr_inp = Sqrt32( sqr_inp, &sq_exp ); - sqr_inp = Mpy_32_32( sqr_inp, 1342177280 /* 320 in Q22*/ ); + sqr_inp = Sqrt32( sqr_inp, &sq_exp ); /* Q31-sq_exp */ + sqr_inp = Mpy_32_32( sqr_inp, 1342177280 /* 320 in Q22*/ ); /* Q31-sq_exp+22-31 */ sq_exp = add( sq_exp, 9 ); - Inv_Tot_E = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, sqr_inp, &Inv_Tot_E_exp ); + Inv_Tot_E = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, sqr_inp, &Inv_Tot_E_exp ); /* Q15-Inv_Tot_E_exp */ Inv_Tot_E_exp = add( Inv_Tot_E_exp, sub( 0, sq_exp ) ); } ELSE @@ -500,9 +502,9 @@ static void utilCrossCorr_mod_fx( move16(); } - hStereoTCA->E1_mem_fx = E1; + hStereoTCA->E1_mem_fx = E1; /* Q31-E1_exp */ move32(); - hStereoTCA->E2_mem_fx = E2; + hStereoTCA->E2_mem_fx = E2; /* Q31-E2_exp */ move32(); hStereoTCA->E1_mem_exp = E1_exp; move16(); @@ -511,21 +513,20 @@ static void utilCrossCorr_mod_fx( *corrEst_Exp = corrEst_exp[0]; move16(); - /* FOR BASOP causing error/warning */ - for ( i = lagSearchRange[0], j = 0; i <= 0; i++, j++ ) + FOR( ( i = lagSearchRange[0], j = 0 ); i <= 0; ( i++, j++ ) ) { L64_sum = 1; move64(); FOR( k = 0; k < len; k++ ) { - L64_sum = W_mac_32_32( L64_sum, buf1[k], buf2[k + i] ); + L64_sum = W_mac_32_32( L64_sum, buf1[k], buf2[k + i] ); /* 2*q_com+1 */ } k = W_norm( L64_sum ); - L64_sum = W_shl( L64_sum, k ); - C = W_extract_h( L64_sum ); // ener_side_q + L64_sum = W_shl( L64_sum, k ); /* 2*q_com+1+k */ + C = W_extract_h( L64_sum ); // ener_side_q C_exp = sub( 31, sub( add( add( shl( q_com, 1 ), 1 ), k ), 32 ) ); - C_C_mem = BASOP_Util_Add_Mant32Exp( C, C_exp, hStereoTCA->C_mem_fx[j], hStereoTCA->C_mem_exp[j], &exp ); - corrEst[j] = Mpy_32_16_1( C_C_mem, Inv_Tot_E ); + C_C_mem = BASOP_Util_Add_Mant32Exp( C, C_exp, hStereoTCA->C_mem_fx[j], hStereoTCA->C_mem_exp[j], &exp ); /* Q31-exp */ + corrEst[j] = Mpy_32_16_1( C_C_mem, Inv_Tot_E ); /* Q31-corrEst_exp */ move32(); corrEst_exp[j] = add( Inv_Tot_E_exp, exp ); move16(); @@ -537,21 +538,20 @@ static void utilCrossCorr_mod_fx( move16(); } - /* FOR BASOP causing error/warning */ - for ( ; i <= lagSearchRange[1]; i++, j++ ) + FOR( ; i <= lagSearchRange[1]; ( i++, j++ ) ) { L64_sum = 1; move64(); FOR( k = 0; k < len; k++ ) { - L64_sum = W_mac_32_32( L64_sum, buf1[k - i], buf2[k] ); + L64_sum = W_mac_32_32( L64_sum, buf1[k - i], buf2[k] ); /* 2*q_com+1 */ } k = W_norm( L64_sum ); - L64_sum = W_shl( L64_sum, k ); - C = W_extract_h( L64_sum ); // ener_side_q + L64_sum = W_shl( L64_sum, k ); /* 2*q_com+1+k */ + C = W_extract_h( L64_sum ); // ener_side_q C_exp = sub( 31, sub( add( add( shl( q_com, 1 ), 1 ), k ), 32 ) ); - C_C_mem = BASOP_Util_Add_Mant32Exp( C, C_exp, hStereoTCA->C_mem_fx[j], hStereoTCA->C_mem_exp[j], &exp ); - corrEst[j] = Mpy_32_16_1( C_C_mem, Inv_Tot_E ); + C_C_mem = BASOP_Util_Add_Mant32Exp( C, C_exp, hStereoTCA->C_mem_fx[j], hStereoTCA->C_mem_exp[j], &exp ); /* Q31-exp */ + corrEst[j] = Mpy_32_16_1( C_C_mem, Inv_Tot_E ); /* Q31-corrEst_exp */ move32(); corrEst_exp[j] = add( Inv_Tot_E_exp, exp ); move16(); @@ -567,7 +567,7 @@ static void utilCrossCorr_mod_fx( FOR( i = 0; i < ( 2 * L_NCSHIFT_DS + 1 ); i++ ) { - corrEst[i] = L_shl( corrEst[i], sub( corrEst_exp[i], *corrEst_Exp ) ); + corrEst[i] = L_shl( corrEst[i], sub( corrEst_exp[i], *corrEst_Exp ) ); /* Q31-corrEst_Exp */ move32(); } @@ -584,12 +584,12 @@ static void utilCrossCorr_fx( Word16 buf1_q, const Word32 *buf2, // buf2_q Word16 buf2_q, - const Word32 *win, - Word32 *corrEst, /* o : correlation estimate corrEst_e */ + const Word32 *win, /*Qx*/ + Word32 *corrEst, /* o : correlation estimate corrEst_e */ Word16 *corrEst_e, - const Word16 *lagSearchRange, - const Word16 len, - const Word16 winSymmFlag ) + const Word16 *lagSearchRange, /*Q0*/ + const Word16 len, /*Q0*/ + const Word16 winSymmFlag /*Q0*/ ) { Word32 tempBuf1[L_FRAME48k]; Word32 tempBuf2[L_FRAME48k]; @@ -619,17 +619,17 @@ static void utilCrossCorr_fx( FOR( i = shr( len, 1 ); i < len; i++ ) { - tempBuf1[i] = Mpy_32_32( win[len - 1 - i], buf1[i] ); + tempBuf1[i] = Mpy_32_32( win[len - 1 - i], buf1[i] ); /* Qx+buf1_q-31 */ move32(); - tempBuf2[i] = Mpy_32_32( win[len - 1 - i], buf2[i] ); + tempBuf2[i] = Mpy_32_32( win[len - 1 - i], buf2[i] ); /* Qx+buf2_q-31 */ move32(); } } } ELSE { - Copy32( buf1, tempBuf1, len ); - Copy32( buf2, tempBuf2, len ); + Copy32( buf1, tempBuf1, len ); /* buf1_q */ + Copy32( buf2, tempBuf2, len ); /* buf2_q */ } Word16 temp1_e = sub( Q31, buf1_q ); @@ -653,20 +653,20 @@ static void utilCrossCorr_fx( assert( lagSearchRange[0] <= lagSearchRange[1] ); /* first part of noncausal corr est. */ - for ( i = lagSearchRange[0], j = 0; i <= s_min( 0, lagSearchRange[1] ); ( i++, j++ ) ) + FOR( ( i = lagSearchRange[0], j = 0 ); i <= s_min( 0, lagSearchRange[1] ); ( i++, j++ ) ) { L64_sum = 0; move64(); - FOR( k = 0; k < add( len, i ); k++ ) + FOR( k = 0; k < ( len + i ); k++ ) { - L64_sum = W_mac_32_32( L64_sum, buf1[k - i], buf2[k] ); + L64_sum = W_mac_32_32( L64_sum, buf1[k - i], buf2[k] ); /* buf1_q+buf2_q+1 */ } k = W_norm( L64_sum ); - L64_sum = W_shl( L64_sum, k ); - temp = W_extract_h( L64_sum ); + L64_sum = W_shl( L64_sum, k ); /* buf1_q+buf2_q+1+k */ + temp = W_extract_h( L64_sum ); /* buf1_q+buf2_q+1+k-32 */ res_e = sub( 31, sub( add( add( add( buf1_q, buf2_q ), 1 ), k ), 32 ) ); - corrEst[j] = L_deposit_h( BASOP_Util_Divide3216_Scale( temp, ( len + i ), &tmp_e ) ); + corrEst[j] = L_deposit_h( BASOP_Util_Divide3216_Scale( temp, ( len + i ), &tmp_e ) ); /* Q31-max_e */ move32(); corrEstTemp_e[j] = add( tmp_e, sub( res_e, 15 ) ); move16(); @@ -674,20 +674,20 @@ static void utilCrossCorr_fx( } /* second part of noncausal corr est. */ - for ( ; i <= lagSearchRange[1]; ( i++, j++ ) ) + FOR( ; i <= lagSearchRange[1]; ( i++, j++ ) ) { L64_sum = 1; move64(); FOR( k = 0; k < sub( len, i ); k++ ) { - L64_sum = W_mac_32_32( L64_sum, buf1[k], buf2[k + i] ); + L64_sum = W_mac_32_32( L64_sum, buf1[k], buf2[k + i] ); /* buf1_q+buf2_q+1 */ } k = W_norm( L64_sum ); - L64_sum = W_shl( L64_sum, k ); - temp = W_extract_h( L64_sum ); + L64_sum = W_shl( L64_sum, k ); /* buf1_q+buf2_q+1+k */ + temp = W_extract_h( L64_sum ); /* buf1_q+buf2_q+1+k-32 */ res_e = sub( 31, sub( add( add( add( buf1_q, buf2_q ), 1 ), k ), 32 ) ); - corrEst[j] = L_deposit_h( BASOP_Util_Divide3216_Scale( temp, ( len - i ), &tmp_e ) ); + corrEst[j] = L_deposit_h( BASOP_Util_Divide3216_Scale( temp, ( len - i ), &tmp_e ) ); /* Q31-max_e */ move32(); corrEstTemp_e[j] = add( tmp_e, sub( res_e, 15 ) ); move16(); @@ -698,7 +698,7 @@ static void utilCrossCorr_fx( FOR( i = 0; i < j; i++ ) { - corrEst[i] = L_shr( corrEst[i], sub( max_e, corrEstTemp_e[i] ) ); + corrEst[i] = L_shr( corrEst[i], sub( max_e, corrEstTemp_e[i] ) ); /* Q31-corrEstTemp_e */ move32(); } @@ -716,22 +716,23 @@ static void utilCrossCorr_fx( * Non-causal shift estimation to encode future samples. * ---------------------------------------------------------------*/ -static Word16 TRUNC_FX( Word32 inp, Word16 exp ) +static Word16 TRUNC_FX( Word32 inp /*Q31-exp*/, Word16 exp ) { Word16 ouptut; Word32 temp; - temp = L_shr( inp, sub( 31, exp ) ); + temp = L_shr( inp, sub( 31, exp ) ); /*Q0*/ test(); IF( GT_32( temp, 32767 ) || LT_32( temp, -32768 ) ) { + test(); IF( temp < 0 ) { - ouptut = -32768; + ouptut = -32768; /*Q0*/ } ELSE { - ouptut = 32767; + ouptut = 32767; /*Q0*/ } move16(); } @@ -739,31 +740,31 @@ static Word16 TRUNC_FX( Word32 inp, Word16 exp ) { IF( NE_32( temp, L_shl_sat( 1, sub( 31, exp ) ) ) ) { - Word32 temp1 = L_add_sat( inp, L_shl_sat( 1, sub( 31, add( exp, 1 ) ) ) ); - ouptut = (Word16) L_shr( temp1, sub( 31, exp ) ); + Word32 temp1 = L_add_sat( inp, L_shl_sat( 1, sub( 31, add( exp, 1 ) ) ) ); /* Q31-exp */ + ouptut = extract_l( L_shr( temp1, sub( 31, exp ) ) ); /*Q0*/ IF( temp < 0 ) { - ouptut = add( ouptut, 1 ); + ouptut = add( ouptut, 1 ); /*Q0*/ } } ELSE { - ouptut = (Word16) temp; + ouptut = extract_l( temp ); /*Q0*/ move16(); } } - return ouptut; + return ouptut; /*Q0*/ } static void corrStatsEst_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo TCA Encoder handle */ Word32 *buf1_fx, /* i : channel 1 q_com*/ Word32 *buf2_fx, /* i : channel 2 q_com*/ Word16 q_com, - const Word16 bufLenDS, /* i : buffer length */ - const Word16 dsFactor, /* i : buffer length */ - const Word16 vad_flag1, /* i : VAD flag channel 1 */ - const Word16 vad_flag2, /* i : VAD flag channel 2 */ + const Word16 bufLenDS, /* i : buffer length Q0*/ + const Word16 dsFactor, /* i : buffer length Q0*/ + const Word16 vad_flag1, /* i : VAD flag channel 1 Q0*/ + const Word16 vad_flag2, /* i : VAD flag channel 2 Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier handle */ ) { @@ -831,46 +832,46 @@ static void corrStatsEst_fx( /* back up the corrEst */ FOR( i = 0; i < 2; i++ ) { - Copy32( hStereoTCA->corrEstPrev_fx[i + 1], hStereoTCA->corrEstPrev_fx[i], tempLen ); + Copy32( hStereoTCA->corrEstPrev_fx[i + 1], hStereoTCA->corrEstPrev_fx[i], tempLen ); /* Q31-hStereoTCA->corrEstPrev_exp */ } temp = getScaleFactor32( corrEst_fx, 2 * L_NCSHIFT_DS + 1 ); - scale_sig32( corrEst_fx, 2 * L_NCSHIFT_DS + 1, temp ); + scale_sig32( corrEst_fx, 2 * L_NCSHIFT_DS + 1, temp ); /* Q31-corrEst_exp */ corrEst_exp = sub( corrEst_exp, temp ); IF( GT_16( corrEst_exp, hStereoTCA->corrEstPrev_exp ) ) { - scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); - scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); - Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); + scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); /* Q31-hStereoTCA->corrEstPrev_exp */ + scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); /* Q31-hStereoTCA->corrEstPrev_exp */ + Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); /* Q31-corrEst_exp */ hStereoTCA->corrEstPrev_exp = corrEst_exp; move16(); } ELSE { - Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); - scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, sub( corrEst_exp, hStereoTCA->corrEstPrev_exp ) ); + Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); /* Q31-corrEst_exp */ + scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, sub( corrEst_exp, hStereoTCA->corrEstPrev_exp ) ); /* Q31-corrEst_exp */ } - scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, -1 ); - scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, -1 ); - scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, -1 ); + scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ + scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ + scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ hStereoTCA->corrEstPrev_exp = add( hStereoTCA->corrEstPrev_exp, 1 ); move16(); Word32 buf1_fx_temp[L_FRAME_DS]; Word32 buf2_fx_temp[L_FRAME_DS]; - Copy32( buf1_fx, buf1_fx_temp, L_FRAME_DS ); - Copy32( buf2_fx, buf2_fx_temp, L_FRAME_DS ); + Copy32( buf1_fx, buf1_fx_temp, L_FRAME_DS ); /* q_com */ + Copy32( buf2_fx, buf2_fx_temp, L_FRAME_DS ); /* q_com */ - scale_sig32( buf1_fx_temp, L_FRAME_DS, -4 ); - scale_sig32( buf2_fx_temp, L_FRAME_DS, -4 ); + scale_sig32( buf1_fx_temp, L_FRAME_DS, -4 ); /* q_com-4 */ + scale_sig32( buf2_fx_temp, L_FRAME_DS, -4 ); /* q_com-4 */ temp_A_fx = L_add( sumAbs_fx( buf1_fx_temp, L_FRAME_DS - L_XCORRMEM_DS ), sumAbs_fx( buf2_fx_temp, L_FRAME_DS - L_XCORRMEM_DS ) ); temp_B_fx = L_add( sumAbs_fx( buf1_fx_temp + ( L_FRAME_DS - L_XCORRMEM_DS ), L_XCORRMEM_DS ), sumAbs_fx( buf2_fx_temp + ( L_FRAME_DS - L_XCORRMEM_DS ), L_XCORRMEM_DS ) ); - tempF_fx = BASOP_Util_Add_Mant32Exp( L_add( temp_A_fx, temp_B_fx ), sub( 31, sub( q_com, 4 ) ), hStereoTCA->mem_tempF_fx, hStereoTCA->mem_tempF_exp, &temp ); + tempF_fx = BASOP_Util_Add_Mant32Exp( L_add( temp_A_fx, temp_B_fx ), sub( 31, sub( q_com, 4 ) ), hStereoTCA->mem_tempF_fx, hStereoTCA->mem_tempF_exp, &temp ); /* Q31-tempF_exp */ Word16 tempF_exp = temp; - hStereoTCA->mem_tempF_fx = temp_B_fx; + hStereoTCA->mem_tempF_fx = temp_B_fx; /* Q31-hStereoTCA->mem_tempF_exp */ move32(); hStereoTCA->mem_tempF_exp = sub( 31, sub( q_com, 4 ) ); move16(); @@ -894,18 +895,18 @@ static void corrStatsEst_fx( move32(); /* long term corr Stats estimation */ - v_multc_fixed_16( hStereoTCA->corrEstLT_fx, alpha_fx, hStereoTCA->corrEstLT_fx, 2 * L_NCSHIFT_DS + 1 ); - v_multc_fixed_16( corrEst_fx, sub( MAX_16, alpha_fx ), corrEst_fx, 2 * L_NCSHIFT_DS + 1 ); + v_multc_fixed_16( hStereoTCA->corrEstLT_fx, alpha_fx, hStereoTCA->corrEstLT_fx, 2 * L_NCSHIFT_DS + 1 ); /* Q31-hStereoTCA->corrEstLT_exp */ + v_multc_fixed_16( corrEst_fx, sub( MAX_16, alpha_fx ), corrEst_fx, 2 * L_NCSHIFT_DS + 1 ); /* Q31-corrEst_exp */ v_add_fixed_me( hStereoTCA->corrEstLT_fx, hStereoTCA->corrEstLT_exp, corrEst_fx, corrEst_exp, hStereoTCA->corrEstLT_fx, &hStereoTCA->corrEstLT_exp, 2 * L_NCSHIFT_DS + 1, 0 ); - hStereoTCA->ica_envVarLT_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->ica_envVarLT_fx, SMOOTH_ENV_FACTOR_FX_Q15 ), hStereoTCA->ica_envVarLT_exp, Mpy_32_16_1( tempF_fx, ONE_IN_Q15 - SMOOTH_ENV_FACTOR_FX_Q15 ), tempF_exp, &hStereoTCA->ica_envVarLT_exp ); // SMOOTH_ENV_FACTOR_FX_Q15 + hStereoTCA->ica_envVarLT_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->ica_envVarLT_fx, SMOOTH_ENV_FACTOR_FX_Q15 ), hStereoTCA->ica_envVarLT_exp, Mpy_32_16_1( tempF_fx, ONE_IN_Q15 - SMOOTH_ENV_FACTOR_FX_Q15 ), tempF_exp, &hStereoTCA->ica_envVarLT_exp ); // SMOOTH_ENV_FACTOR_FX_Q15 (Q31-hStereoTCA->ica_envVarLT_exp) move32(); - Copy32( hStereoTCA->corrEstLT_fx, corrEst_fx, 2 * L_NCSHIFT_DS + 1 ); + Copy32( hStereoTCA->corrEstLT_fx, corrEst_fx, 2 * L_NCSHIFT_DS + 1 ); /* Q31-hStereoTCA->corrEstLT_exp */ corrEst_exp = hStereoTCA->corrEstLT_exp; move16(); - Y_hat_fx = hStereoTCA->delay_0_mem_fx[0]; + Y_hat_fx = hStereoTCA->delay_0_mem_fx[0]; /* Q31-hStereoTCA->delay_0_mem_exp */ move32(); Y_hat_exp = hStereoTCA->delay_0_mem_exp; move16(); @@ -913,35 +914,35 @@ static void corrStatsEst_fx( /* Note: keep X_hat and X_SQR_hat calculations inside the loop to allow future tuning of MAX_DELAYREGLEN */ FOR( i = 1; i < MAX_DELAYREGLEN; i++ ) { - X_hat_fx = BASOP_Util_Add_Mant32Exp( X_hat_fx, X_hat_exp, L_shl( i, 27 ), 4, &X_hat_exp ); - Y_hat_fx = BASOP_Util_Add_Mant32Exp( Y_hat_fx, Y_hat_exp, hStereoTCA->delay_0_mem_fx[i], hStereoTCA->delay_0_mem_exp, &Y_hat_exp ); - XY_hat_fx = BASOP_Util_Add_Mant32Exp( XY_hat_fx, XY_hat_exp, Mpy_32_32( hStereoTCA->delay_0_mem_fx[i], L_shl( i, 27 ) ), add( 4, hStereoTCA->delay_0_mem_exp ), &XY_hat_exp ); - X_SQR_hat_fx = BASOP_Util_Add_Mant32Exp( X_SQR_hat_fx, X_SQR_hat_exp, Mpy_32_32( L_shl( i, 27 ), L_shl( i, 27 ) ), 8, &X_SQR_hat_exp ); + X_hat_fx = BASOP_Util_Add_Mant32Exp( X_hat_fx, X_hat_exp, L_shl( i, 27 ), 4, &X_hat_exp ); /* Q31-X_hat_exp */ + Y_hat_fx = BASOP_Util_Add_Mant32Exp( Y_hat_fx, Y_hat_exp, hStereoTCA->delay_0_mem_fx[i], hStereoTCA->delay_0_mem_exp, &Y_hat_exp ); /* Q31-Y_hat_exp */ + XY_hat_fx = BASOP_Util_Add_Mant32Exp( XY_hat_fx, XY_hat_exp, Mpy_32_32( hStereoTCA->delay_0_mem_fx[i], L_shl( i, 27 ) ), add( 4, hStereoTCA->delay_0_mem_exp ), &XY_hat_exp ); /* Q31-XY_hat_exp */ + X_SQR_hat_fx = BASOP_Util_Add_Mant32Exp( X_SQR_hat_fx, X_SQR_hat_exp, Mpy_32_32( L_shl( i, 27 ), L_shl( i, 27 ) ), 8, &X_SQR_hat_exp ); /* Q31-X_SQR_hat_exp */ } - X_hat_fx = Mpy_32_16_1( X_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); - Y_hat_fx = Mpy_32_16_1( Y_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); - XY_hat_fx = Mpy_32_16_1( XY_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); - X_SQR_hat_fx = Mpy_32_16_1( X_SQR_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); + X_hat_fx = Mpy_32_16_1( X_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); /* Q31-X_hat_exp */ + Y_hat_fx = Mpy_32_16_1( Y_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); /* Q31-Y_hat_exp */ + XY_hat_fx = Mpy_32_16_1( XY_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); /* Q31-XY_hat_exp */ + X_SQR_hat_fx = Mpy_32_16_1( X_SQR_hat_fx, INV_MAX_DELAYREGLEN_FX_Q15 ); /* Q31-X_SQR_hat_exp */ beta_reg_fx = 0; move32(); beta_reg_exp = 0; move16(); - tempF_fx = BASOP_Util_Add_Mant32Exp( X_SQR_hat_fx, X_SQR_hat_exp, L_negate( Mpy_32_32( X_hat_fx, X_hat_fx ) ), shl( X_hat_exp, 1 ), &tempF_exp ); + tempF_fx = BASOP_Util_Add_Mant32Exp( X_SQR_hat_fx, X_SQR_hat_exp, L_negate( Mpy_32_32( X_hat_fx, X_hat_fx ) ), shl( X_hat_exp, 1 ), &tempF_exp ); /* Q31-tempF_exp */ IF( tempF_fx != 0 ) { - temp32 = BASOP_Util_Add_Mant32Exp( XY_hat_fx, XY_hat_exp, L_negate( Mpy_32_32( X_hat_fx, Y_hat_fx ) ), add( X_hat_exp, Y_hat_exp ), &exp ); - beta_reg_fx = BASOP_Util_Divide3232_Scale_cadence( temp32, tempF_fx, &beta_reg_exp ); + temp32 = BASOP_Util_Add_Mant32Exp( XY_hat_fx, XY_hat_exp, L_negate( Mpy_32_32( X_hat_fx, Y_hat_fx ) ), add( X_hat_exp, Y_hat_exp ), &exp ); /* Q31-exp */ + beta_reg_fx = BASOP_Util_Divide3232_Scale_cadence( temp32, tempF_fx, &beta_reg_exp ); /* Q31-beta_reg_exp */ if ( beta_reg_fx ) { beta_reg_exp = add( beta_reg_exp, sub( exp, tempF_exp ) ); } } - alpha_reg_fx = BASOP_Util_Add_Mant32Exp( Y_hat_fx, Y_hat_exp, L_negate( Mpy_32_32( X_hat_fx, beta_reg_fx ) ), add( X_hat_exp, beta_reg_exp ), &alpha_reg_exp ); - reg_prv_corr_fx = BASOP_Util_Add_Mant32Exp( alpha_reg_fx, alpha_reg_exp, Mpy_32_32( beta_reg_fx, L_shl( MAX_DELAYREGLEN, 27 ) ), add( 4, beta_reg_exp ), ®_prv_corr_exp ); + alpha_reg_fx = BASOP_Util_Add_Mant32Exp( Y_hat_fx, Y_hat_exp, L_negate( Mpy_32_32( X_hat_fx, beta_reg_fx ) ), add( X_hat_exp, beta_reg_exp ), &alpha_reg_exp ); /* Q31-alpha_reg_exp */ + reg_prv_corr_fx = BASOP_Util_Add_Mant32Exp( alpha_reg_fx, alpha_reg_exp, Mpy_32_32( beta_reg_fx, L_shl( MAX_DELAYREGLEN, 27 ) ), add( 4, beta_reg_exp ), ®_prv_corr_exp ); /* Q31-reg_prv_corr_exp */ IF( LE_16( TRUNC_FX( reg_prv_corr_fx, reg_prv_corr_exp ), -L_NCSHIFT_DS ) ) { @@ -959,21 +960,21 @@ static void corrStatsEst_fx( move16(); } - bias_par_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->smooth_dist_reg_prv_corr_fx, A_BIAS_FX_Q15 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, L_shl( B_BIAS_FX_Q15, Q16 ), 0, &bias_par_exp ); + bias_par_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->smooth_dist_reg_prv_corr_fx, A_BIAS_FX_Q15 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, L_shl( B_BIAS_FX_Q15, Q16 ), 0, &bias_par_exp ); /* Q31-bias_par_exp */ - Word32 XH_BIAS_tmp = L_shl( XH_BIAS_FX_Q15, Q16 ); - Word32 XL_BIAS_tmp = L_shl( XL_BIAS_FX_Q15, Q16 ); + Word32 XH_BIAS_tmp = L_shl( XH_BIAS_FX_Q15, Q16 ); /* Q31 */ + Word32 XL_BIAS_tmp = L_shl( XL_BIAS_FX_Q15, Q16 ); /* Q31 */ IF( bias_par_exp < 0 ) { - bias_par_fx = L_shl( bias_par_fx, bias_par_exp ); + bias_par_fx = L_shl( bias_par_fx, bias_par_exp ); /* Q31 */ bias_par_exp = 0; move16(); } ELSE { - XH_BIAS_tmp = L_shr( XH_BIAS_tmp, bias_par_exp ); - XL_BIAS_tmp = L_shr( XL_BIAS_tmp, bias_par_exp ); + XH_BIAS_tmp = L_shr( XH_BIAS_tmp, bias_par_exp ); /* Q31-bias_par_exp */ + XL_BIAS_tmp = L_shr( XL_BIAS_tmp, bias_par_exp ); /* Q31-bias_par_exp */ } bias_par_fx = L_min( bias_par_fx, XH_BIAS_tmp ); @@ -982,13 +983,13 @@ static void corrStatsEst_fx( bias_par_exp = 0; move16(); - width_par_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hStereoTCA->smooth_dist_reg_prv_corr_fx, A_WIDTH_FX_Q31 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, B_WIDTH_FX_Q31, 0, &width_par_exp ); - Word32 XH_WIDTH_tmp = L_shl( XH_WIDTH_FX_Q15, Q16 ); - Word32 XL_WIDTH_tmp = L_shl( XL_WIDTH_FX_Q15, Q16 ); + width_par_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hStereoTCA->smooth_dist_reg_prv_corr_fx, A_WIDTH_FX_Q31 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, B_WIDTH_FX_Q31, 0, &width_par_exp ); /* Q31-width_par_exp */ + Word32 XH_WIDTH_tmp = L_shl( XH_WIDTH_FX_Q15, Q16 ); /* Q31 */ + Word32 XL_WIDTH_tmp = L_shl( XL_WIDTH_FX_Q15, Q16 ); /* Q31 */ IF( width_par_exp < 0 ) { - width_par_fx = L_shl( width_par_fx, width_par_exp ); + width_par_fx = L_shl( width_par_fx, width_par_exp ); /* Q31 */ width_par_exp = 0; move16(); } @@ -1003,39 +1004,39 @@ static void corrStatsEst_fx( width_par_exp = 0; move16(); - win_width = (Word16) L_shr( Mpy_32_32( width_par_fx, 1350565888 /* ( 4L_NCSHIFT_DS + 1 ) in Q23 */ ), sub( 31, add( width_par_exp, 8 ) ) ); + win_width = (Word16) L_shr( Mpy_32_32( width_par_fx, 1350565888 /* ( 4L_NCSHIFT_DS + 1 ) in Q23 */ ), sub( 31, add( width_par_exp, 8 ) ) ); /* Q23-(31-(width_par_exp-8)) */ win_bias_fx = round_fx( bias_par_fx ); // Q15 k1_fx = add( MAX_16 >> 1, shr( win_bias_fx, 1 ) ); // Q15 k2_fx = sub( MAX_16 >> 1, shr( win_bias_fx, 1 ) ); // Q15 - FOR( i = 0; i < sub( 2 * L_NCSHIFT_DS, shl( win_width, 1 ) ); i++ ) + FOR( i = 0; i < ( 2 * L_NCSHIFT_DS - ( win_width * 2 ) ); i++ ) { loc_weight_win_fx[i] = win_bias_fx; // Q15 move16(); } - FOR( i = sub( 2 * L_NCSHIFT_DS, shl( win_width, 1 ) ); i <= add( 2 * L_NCSHIFT_DS, shl( win_width, 1 ) ); i++ ) + FOR( i = ( 2 * L_NCSHIFT_DS - ( win_width * 2 ) ); i <= ( 2 * L_NCSHIFT_DS + ( win_width * 2 ) ); i++ ) { - Word16 cos_inp = BASOP_Util_Divide1616_Scale( sub( i, 2 * L_NCSHIFT_DS ), shl( win_width, 1 ), &exp ); + Word16 cos_inp = BASOP_Util_Divide1616_Scale( sub( i, 2 * L_NCSHIFT_DS ), shl( win_width, 1 ), &exp ); /* Q15-exp */ cos_inp = shr_sat( cos_inp, sub( 0, exp ) ); - cos_inp = getCosWord16R2( shr( cos_inp, 1 ) ); - loc_weight_win_fx[i] = add( k1_fx, mult( k2_fx, cos_inp ) ); + cos_inp = getCosWord16R2( shr( cos_inp, 1 ) ); // Q15 + loc_weight_win_fx[i] = add( k1_fx, mult( k2_fx, cos_inp ) ); // Q15 move16(); } - FOR( i = add( 2 * L_NCSHIFT_DS, shl( win_width, 1 ) ); i < ( 4 * L_NCSHIFT_DS + 1 ); i++ ) + FOR( i = ( 2 * L_NCSHIFT_DS + ( win_width * 2 ) ); i < ( 4 * L_NCSHIFT_DS + 1 ); i++ ) { loc_weight_win_fx[i] = win_bias_fx; // Q15 move16(); } - Word16 x = TRUNC_FX( reg_prv_corr_fx, reg_prv_corr_exp ); + Word16 x = TRUNC_FX( reg_prv_corr_fx, reg_prv_corr_exp ); /* Q0 */ move16(); - for ( i = 0, j = sub( L_NCSHIFT_DS, x ); i < 2 * L_NCSHIFT_DS + 1; i++, j++ ) + for ( i = 0, j = ( L_NCSHIFT_DS - x ); i < 2 * L_NCSHIFT_DS + 1; i++, j++ ) { - corrEst_fx[i] = Mpy_32_16_1( corrEst_fx[i], loc_weight_win_fx[j] ); + corrEst_fx[i] = Mpy_32_16_1( corrEst_fx[i], loc_weight_win_fx[j] ); /* Q31-corrEst_exp */ move32(); } test(); @@ -1043,15 +1044,15 @@ static void corrStatsEst_fx( IF( LT_32( hStereoTCA->prevTargetGain_fx, 429496730 /*0.8f in Q29*/ ) && vad_flag1 ) { /* ch 2 is prev reference channel */ - v_multc_fixed( corrEst_fx, 644245095 /*1.2f in Q29*/, corrEst_fx, L_NCSHIFT_DS + 1 ); - v_multc_fixed( corrEst_fx + L_NCSHIFT_DS + 1, 447213470 /* 0.833 in Q29*/, corrEst_fx + L_NCSHIFT_DS + 1, L_NCSHIFT_DS ); + v_multc_fixed( corrEst_fx, 644245095 /*1.2f in Q29*/, corrEst_fx, L_NCSHIFT_DS + 1 ); /* Q31-corrEst_exp */ + v_multc_fixed( corrEst_fx + L_NCSHIFT_DS + 1, 447213470 /* 0.833 in Q29*/, corrEst_fx + L_NCSHIFT_DS + 1, L_NCSHIFT_DS ); /* Q31-corrEst_exp */ corrEst_exp = add( corrEst_exp, 2 ); } ELSE IF( GT_32( hStereoTCA->prevTargetGain_fx, 644245094 /*1.2f in Q29*/ ) && vad_flag1 ) { /* ch 1 is prev reference channel */ - v_multc_fixed( corrEst_fx, 447213470 /* 0.833 f in Q29*/, corrEst_fx, L_NCSHIFT_DS ); - v_multc_fixed( corrEst_fx + L_NCSHIFT_DS, 644245095 /*1.2f in Q29*/, corrEst_fx + L_NCSHIFT_DS, L_NCSHIFT_DS + 1 ); + v_multc_fixed( corrEst_fx, 447213470 /* 0.833 f in Q29*/, corrEst_fx, L_NCSHIFT_DS ); /* Q31-corrEst_exp */ + v_multc_fixed( corrEst_fx + L_NCSHIFT_DS, 644245095 /*1.2f in Q29*/, corrEst_fx + L_NCSHIFT_DS, L_NCSHIFT_DS + 1 ); /* Q31-corrEst_exp */ corrEst_exp = add( corrEst_exp, 2 ); } test(); @@ -1061,9 +1062,9 @@ static void corrStatsEst_fx( j = s_min( 2 * L_NCSHIFT_DS, add( hStereoTCA->prevCorrLagStats[0], 1 + L_NCSHIFT_DS ) ); k = add( sub( j, i ), 1 ); - v_multc_fixed( corrEst_fx, ONE_IN_Q29 /*1.0f in Q29*/, corrEst_fx, i ); // to allign in same exp - v_multc_fixed( corrEst_fx + i, 644245095 /*1.2f in Q29*/, corrEst_fx + i, k ); - v_multc_fixed( corrEst_fx + i + k, ONE_IN_Q29 /*1.0f in Q29*/, corrEst_fx + i + k, sub( 2 * L_NCSHIFT_DS + 1, i + k ) ); // to allign in same exp + v_multc_fixed( corrEst_fx, ONE_IN_Q29 /*1.0f in Q29*/, corrEst_fx, i ); // to allign in same exp (Q31-corrEst_exp) + v_multc_fixed( corrEst_fx + i, 644245095 /*1.2f in Q29*/, corrEst_fx + i, k ); /* Q31-corrEst_exp */ + v_multc_fixed( corrEst_fx + i + k, ONE_IN_Q29 /*1.0f in Q29*/, corrEst_fx + i + k, sub( 2 * L_NCSHIFT_DS + 1, i + k ) ); // to allign in same exp (Q31-corrEst_exp) corrEst_exp = add( corrEst_exp, 2 ); } @@ -1075,34 +1076,34 @@ static void corrStatsEst_fx( corrLagStats[0] = add( corrLagStats[0], lagSearchRange[0] ); move16(); - stmp = i_mult( corrLagStats[0], dsFactor ); - hStereoClassif->unclr_fv_fx[E_corrLagStats0] = L_shl( stmp, Q15 ); + stmp = i_mult( corrLagStats[0], dsFactor ); /* Q0 */ + hStereoClassif->unclr_fv_fx[E_corrLagStats0] = L_shl( stmp, Q15 ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_corrLagStats0] = L_shl( stmp, Q15 ); + hStereoClassif->xtalk_fv_fx[E_corrLagStats0] = L_shl( stmp, Q15 ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_ica_corr_value0] = L_shl( tempF_fx, sub( tempF_exp, Q16 ) ); + hStereoClassif->xtalk_fv_fx[E_ica_corr_value0] = L_shl( tempF_fx, sub( tempF_exp, Q16 ) ); /* Q15 */ move32(); test(); - if ( vad_flag1 == 0 && GT_16( alpha_fx, 22938 /* 0.7f in Q15 */ ) ) + IF( vad_flag1 == 0 && GT_16( alpha_fx, 22938 /* 0.7f in Q15 */ ) ) { corrLagStats[0] = 0; move16(); } - dist_reg_prv_corr_fx = L_abs( BASOP_Util_Add_Mant32Exp( reg_prv_corr_fx, reg_prv_corr_exp, -corrLagStats[0], Q31, &dist_reg_prv_corr_exp ) ); + dist_reg_prv_corr_fx = L_abs( BASOP_Util_Add_Mant32Exp( reg_prv_corr_fx, reg_prv_corr_exp, -corrLagStats[0], Q31, &dist_reg_prv_corr_exp ) ); /* Q31-dist_reg_prv_corr_exp */ test(); IF( EQ_16( vad_flag1, 1 ) && EQ_16( vad_flag2, 1 ) ) { - hStereoTCA->smooth_dist_reg_prv_corr_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->smooth_dist_reg_prv_corr_fx, SMOOTH_DIST_FACTOR_FX_Q15 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, Mpy_32_16_1( dist_reg_prv_corr_fx, MAX_16 - SMOOTH_DIST_FACTOR_FX_Q15 ), dist_reg_prv_corr_exp, &hStereoTCA->smooth_dist_reg_prv_corr_exp ); + hStereoTCA->smooth_dist_reg_prv_corr_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( hStereoTCA->smooth_dist_reg_prv_corr_fx, SMOOTH_DIST_FACTOR_FX_Q15 ), hStereoTCA->smooth_dist_reg_prv_corr_exp, Mpy_32_16_1( dist_reg_prv_corr_fx, MAX_16 - SMOOTH_DIST_FACTOR_FX_Q15 ), dist_reg_prv_corr_exp, &hStereoTCA->smooth_dist_reg_prv_corr_exp ); /* Q31-hStereoTCA->smooth_dist_reg_prv_corr_exp */ move32(); - Copy32( &( hStereoTCA->delay_0_mem_fx[1] ), &( hStereoTCA->delay_0_mem_fx[0] ), MAX_DELAYREGLEN - 1 ); + Copy32( &( hStereoTCA->delay_0_mem_fx[1] ), &( hStereoTCA->delay_0_mem_fx[0] ), MAX_DELAYREGLEN - 1 ); /* Q31-hStereoTCA->delay_0_mem_exp */ - hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], 429496730 /* 0.2 in Q31*/ ), hStereoTCA->delay_0_mem_exp, L_mult0( 26214 /* 0.8 in Q15*/, corrLagStats[0] ), Q16, &temp ); + hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], 429496730 /* 0.2 in Q31*/ ), hStereoTCA->delay_0_mem_exp, L_mult0( 26214 /* 0.8 in Q15*/, corrLagStats[0] ), Q16, &temp ); /* Q31-temp */ move32(); - Word32 inpp = L_abs( BASOP_Util_Add_Mant32Exp( reg_prv_corr_fx, reg_prv_corr_exp, -hStereoTCA->delay_0_mem_fx[0], hStereoTCA->delay_0_mem_exp, &exp ) ); - inpp = L_shr( inpp, sub( Q31, exp ) ); + Word32 inpp = L_abs( BASOP_Util_Add_Mant32Exp( reg_prv_corr_fx, reg_prv_corr_exp, -hStereoTCA->delay_0_mem_fx[0], hStereoTCA->delay_0_mem_exp, &exp ) ); /* Q31-exp */ + inpp = L_shr( inpp, sub( Q31, exp ) ); /* Q0 */ IF( GT_32( inpp, 25 ) ) { set32_fx( &( hStereoTCA->delay_0_mem_fx[0] ), hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], MAX_DELAYREGLEN - 1 ); @@ -1113,13 +1114,13 @@ static void corrStatsEst_fx( { IF( GT_16( temp, hStereoTCA->delay_0_mem_exp ) ) { - scale_sig32( hStereoTCA->delay_0_mem_fx, MAX_DELAYREGLEN - 1, sub( hStereoTCA->delay_0_mem_exp, temp ) ); + scale_sig32( hStereoTCA->delay_0_mem_fx, MAX_DELAYREGLEN - 1, sub( hStereoTCA->delay_0_mem_exp, temp ) ); /* Q31-hStereoTCA->delay_0_mem_exp */ hStereoTCA->delay_0_mem_exp = temp; move16(); } ELSE { - hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1] = L_shl( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], sub( temp, hStereoTCA->delay_0_mem_exp ) ); + hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1] = L_shl( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], sub( temp, hStereoTCA->delay_0_mem_exp ) ); /* Q31-temp */ move32(); } } @@ -1134,7 +1135,7 @@ static void corrStatsEst_fx( test(); IF( vad_flag1 == 0 || vad_flag2 == 0 ) { - corrLagStats[0] = TRUNC_FX( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], hStereoTCA->delay_0_mem_exp ); + corrLagStats[0] = TRUNC_FX( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], hStereoTCA->delay_0_mem_exp ); /* Q0 */ move32(); } @@ -1155,7 +1156,7 @@ static void corrStatsEst_fx( winInterp_fx = ica_sincInterp6_fx + SINC_ORDER1; } - corrLagStats[1] = i_mult( corrLagStats[0], dsFactor ); + corrLagStats[1] = i_mult( corrLagStats[0], dsFactor ); /* Q0 */ move16(); interpMin = s_max( -sub( dsFactor, 1 ), -add( corrLagStats[1], i_mult( L_NCSHIFT_DS, dsFactor ) ) ); interpMax = s_min( sub( dsFactor, 1 ), sub( i_mult( L_NCSHIFT_DS, dsFactor ), corrLagStats[1] ) ); @@ -1165,29 +1166,29 @@ static void corrStatsEst_fx( { rInterp_fx[k] = 0; move32(); - FOR( j = -idiv1616( SINC_ORDER1, dsFactor ); j <= idiv1616( SINC_ORDER1, dsFactor ); j++ ) + FOR( j = -( SINC_ORDER1 / dsFactor ); j <= ( SINC_ORDER1 / dsFactor ); j++ ) { - m = i_mult( j, dsFactor ); + m = i_mult( j, dsFactor ); /* Q0 */ test(); IF( GE_16( sub( m, i ), -SINC_ORDER1 ) && LE_16( sub( m, i ), SINC_ORDER1 ) ) { IF( GT_16( j, sub( lagSearchRange[1], corrLagStats[0] ) ) ) { - rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[lagSearchRange[1] - corrLagStats[0]], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); + rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[lagSearchRange[1] - corrLagStats[0]], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); /* Q31-temp */ move32(); rInterp_exp[k] = temp; move16(); } ELSE IF( LT_16( j, sub( lagSearchRange[0], corrLagStats[0] ) ) ) { - rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[lagSearchRange[0] - corrLagStats[0]], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); + rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[lagSearchRange[0] - corrLagStats[0]], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); /* Q31-temp */ move32(); rInterp_exp[k] = temp; move16(); } ELSE { - rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[j], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); + rInterp_fx[k] = BASOP_Util_Add_Mant32Exp( rInterp_fx[k], rInterp_exp[k], Mpy_32_32( tempRK_fx[j], winInterp_fx[m - i] ), hStereoTCA->corrEstLT_exp, &temp ); /* Q31-temp */ move32(); rInterp_exp[k] = temp; move16(); @@ -1204,15 +1205,15 @@ static void corrStatsEst_fx( FOR( i = 0; i < MAX_INTERPOLATE; i++ ) { - rInterp_fx[i] = L_shl( rInterp_fx[i], sub( rInterp_exp[i], temp ) ); + rInterp_fx[i] = L_shl( rInterp_fx[i], sub( rInterp_exp[i], temp ) ); /* Q31-rInterp_exp[i] */ move32(); } - corrLagStats[1] = add( corrLagStats[1], add( maximum_32_fx( rInterp_fx, interpLen, &tempF_fx ), interpMin ) ); + corrLagStats[1] = add( corrLagStats[1], add( maximum_32_fx( rInterp_fx, interpLen, &tempF_fx ), interpMin ) ); /* Q0 */ move16(); /* save corr lag stats for the current frame */ - Copy( corrLagStats, hStereoTCA->corrLagStats, 3 ); + Copy( corrLagStats, hStereoTCA->corrLagStats, 3 ); /* Q0 */ return; } @@ -1225,14 +1226,14 @@ static void corrStatsEst_fx( static void estDownmixGain_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo TCA Encoder handle */ - const Word32 *chan1, /* i : reference signal Qx */ - const Word32 *chan2, /* i/o: target signal to be scaled Qx */ - const Word16 q_chan, /* i : Q of the channel signal */ - const Word16 ncShift, /* i : shift */ - const Word16 length, /* i : input frame length */ - const Word16 element_mode, /* i : element mode */ + const Word32 *chan1, /* i : reference signal q_chan */ + const Word32 *chan2, /* i/o: target signal to be scaled q_chan */ + const Word16 q_chan, /* i : Q of the channel signal Q0*/ + const Word16 ncShift, /* i : shift Q0*/ + const Word16 length, /* i : input frame length Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier handle */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag Q0*/ ) { Word16 i, i1, i2; @@ -1251,12 +1252,12 @@ static void estDownmixGain_fx( { i1 = 0; move16(); - i2 = ncShift; + i2 = ncShift; /* Q0 */ move16(); } ELSE { - i1 = ncShift; + i1 = ncShift; /* Q0 */ move16(); i2 = 0; move16(); @@ -1269,11 +1270,11 @@ static void estDownmixGain_fx( move32(); FOR( i = 0; i < length; i++ ) { - tempN = L_add( tempN, L_abs( chan1[i1 + i] ) ); - tempD = L_add( tempD, L_abs( chan2[i2 + i] ) ); + tempN = L_add( tempN, L_abs( chan1[i1 + i] ) ); /* q_chan */ + tempD = L_add( tempD, L_abs( chan2[i2 + i] ) ); /* q_chan */ } - alpha = hStereoTCA->corrStatsSmoothFac_fx; + alpha = hStereoTCA->corrStatsSmoothFac_fx; /* Q15 */ move16(); IF( tempD == 0 ) { @@ -1283,7 +1284,7 @@ static void estDownmixGain_fx( } ELSE { - currentGain = BASOP_Util_Divide3232_Scale( tempN, tempD, &exp ); + currentGain = BASOP_Util_Divide3232_Scale( tempN, tempD, &exp ); /* Q31-exp */ currentGain_e = exp; move16(); if ( currentGain == 0 ) @@ -1306,7 +1307,7 @@ static void estDownmixGain_fx( currentGain_log10 = BASOP_Util_Log10( L_deposit_h( currentGain ), currentGain_e ); // Output in Q25 // multiplication result will be Q25 should be fit to Q15 hence right shift by 10. // Q25 - Q10 = Q15 - currentGain = extract_l( L_shr( Madd_32_16( Mpy_32_16_1( prevTargetGain_log10, alpha ), currentGain_log10, sub( MAX_16, alpha ) ), Q10 ) ); + currentGain = extract_l( L_shr( Madd_32_16( Mpy_32_16_1( prevTargetGain_log10, alpha ), currentGain_log10, sub( MAX_16, alpha ) ), Q10 ) ); /* Q15 */ currentGain_e = 0; move16(); @@ -1318,8 +1319,8 @@ static void estDownmixGain_fx( // tempD = powf( 10, currentGain ); // 10 ^ currentGain = 2 ^ (3.32192809488 * currentGain) // 3.32192809488 in Q13 27213 - tempD = BASOP_util_Pow2( L_mult( currentGain, 27213 ), add( currentGain_e, Q2 ), &exp ); - unclr_instTargetGain = L_deposit_h( BASOP_Util_Divide3232_Scale( tempN, L_add( tempD, EPSILON_FX ), &exp_div ) ); + tempD = BASOP_util_Pow2( L_mult( currentGain, 27213 ), add( currentGain_e, Q2 ), &exp ); /* Q31-exp */ + unclr_instTargetGain = L_deposit_h( BASOP_Util_Divide3232_Scale( tempN, L_add( tempD, EPSILON_FX ), &exp_div ) ); /* Q31-exp */ exp = add( sub( exp_chan, exp ), exp_div ); if ( unclr_instTargetGain == 0 ) { @@ -1328,7 +1329,7 @@ static void estDownmixGain_fx( } unclr_instTargetGain = BASOP_Util_Log10( L_add( unclr_instTargetGain, L_shr( MAX_32, sub( Q31, exp ) ) ), exp ); // unclr_fv_fx is expected in Q15 - log result will be in Q25 - hence rightshift by 10. - hStereoClassif->unclr_fv_fx[E_ica_instTargetGain] = L_shr( unclr_instTargetGain, Q10 ); + hStereoClassif->unclr_fv_fx[E_ica_instTargetGain] = L_shr( unclr_instTargetGain, Q10 ); /* Q15 */ move32(); } @@ -1344,7 +1345,7 @@ static void estDownmixGain_fx( /* Division result Q has to be got back to the Q of initial currentGain hence the shift operation below */ IF( currentGain_e != 0 ) { - currentGain = shr( currentGain, sub( Q15, currentGain_e ) ); + currentGain = shr( currentGain, sub( Q15, currentGain_e ) ); /* Q15 */ currentGain_e = 0; move16(); } @@ -1354,7 +1355,7 @@ static void estDownmixGain_fx( IF( GE_16( norm_s( currentGain ), sub( currentGain_e, 1 ) ) ) { /* convert currentGain into Q14 */ - currentGain = shl( currentGain, sub( currentGain_e, 1 ) ); + currentGain = shl( currentGain, sub( currentGain_e, 1 ) ); /* Q14 */ currentGain_e = 1; move16(); } @@ -1365,7 +1366,7 @@ static void estDownmixGain_fx( } /* quantize the target gain */ - hStereoTCA->indx_ica_gD = usquant_fx( currentGain, &temp, shr( STEREO_TCA_GDMIN_FX_Q14, shift ), shr( STEREO_TCA_GDSTEP_FX_Q13, shift ), 1 << STEREO_BITS_TCA_GD ); + hStereoTCA->indx_ica_gD = usquant_fx( currentGain, &temp, shr( STEREO_TCA_GDMIN_FX_Q14, shift ), shr( STEREO_TCA_GDSTEP_FX_Q13, shift ), ( 1 << STEREO_BITS_TCA_GD ) ); /* Q13 */ move16(); // hStereoTCA->targetGain_fx = powf( 10, temp ); // 10 ^ temp = 2 ^ (3.32192809488 * temp) @@ -1373,7 +1374,7 @@ static void estDownmixGain_fx( // exponent of power function input will be 2 more since constant is in Q13 exp = 2; move16(); - hStereoTCA->targetGain_fx = BASOP_util_Pow2( L_mult( temp, 27213 ), add( currentGain_e, 2 ), &exp ); + hStereoTCA->targetGain_fx = BASOP_util_Pow2( L_mult( temp, 27213 ), add( currentGain_e, 2 ), &exp ); /* Q31-exp */ move32(); hStereoTCA->targetGain_fx = L_shl( hStereoTCA->targetGain_fx, sub( exp, 2 ) ); // Q29 move32(); @@ -1391,9 +1392,9 @@ static void icaMemUpdate_fx( Word32 *bufChanL, /* i/o: L signal correction from previous frame q_com*/ Word32 *bufChanR, /* i/o: R signal correction from previous frame q_com*/ Word16 q_com, - const Word16 lMemRecalc, /* i : memory length at input Sampling Rate */ - const Word16 lMemRecalc_SCh, /* i : SCh memory length at input Sampling Rate*/ - const Word16 input_frame /* i : frame length */ + const Word16 lMemRecalc, /* i : memory length at input Sampling Rate Q0*/ + const Word16 lMemRecalc_SCh, /* i : SCh memory length at input Sampling Rate Q0*/ + const Word16 input_frame /* i : frame length Q0*/ ) { Word32 *ptr1, *ptr2; @@ -1409,29 +1410,29 @@ static void icaMemUpdate_fx( IF( hCPE->hStereoTD->tdm_last_SM_flag ) { - ratio_L = hCPE->hStereoTD->tdm_last_ratio_SM_fx; + ratio_L = hCPE->hStereoTD->tdm_last_ratio_SM_fx; /* Q31 */ move32(); One_m_Ratio = L_sub( ratio_L, MAX_32 ); } ELSE { - ratio_L = hCPE->hStereoTD->tdm_last_ratio_fx; + ratio_L = hCPE->hStereoTD->tdm_last_ratio_fx; /* Q31 */ move32(); One_m_Ratio = L_sub( MAX_32, ratio_L ); } - ptr1 = sts[0]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ); - ptr2 = sts[1]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ); + ptr1 = sts[0]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ); /* Q31-sts[0]->q_inp32 */ + ptr2 = sts[1]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ); /* Q31-sts[1]->q_inp32 */ IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { IF( hCPE->hStereoTD->flag_skip_DMX ) { - FOR( i = lMemRecalc_SCh; i < add( lMemRecalc, lMemRecalc_SCh ); i++ ) + FOR( i = lMemRecalc_SCh; i < ( lMemRecalc + lMemRecalc_SCh ); i++ ) { - ptr1[i] = bufChanL[i]; + ptr1[i] = bufChanL[i]; /* q_com */ move32(); - ptr2[i] = bufChanR[i]; + ptr2[i] = bufChanR[i]; /* q_com */ move32(); } } @@ -1439,9 +1440,9 @@ static void icaMemUpdate_fx( { FOR( i = lMemRecalc_SCh; i < lMemRecalc + lMemRecalc_SCh; i++ ) { - ptr1[i] = L_add( Mpy_32_32( bufChanR[i], One_m_Ratio ), Mpy_32_32( bufChanL[i], ratio_L ) ); + ptr1[i] = L_add( Mpy_32_32( bufChanR[i], One_m_Ratio ), Mpy_32_32( bufChanL[i], ratio_L ) ); /* q_com */ move32(); - ptr2[i] = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); + ptr2[i] = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); /* q_com */ move32(); } } @@ -1459,7 +1460,7 @@ static void icaMemUpdate_fx( /* reconstruction of the Secondary channel past segment */ FOR( i = 0; i < lMemRecalc_SCh; i++ ) { - ptr2[i] = L_add( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); + ptr2[i] = L_add( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); /* q_com */ move32(); } @@ -1468,18 +1469,18 @@ static void icaMemUpdate_fx( incr = fac; // Q15 move16(); - FOR( i = lMemRecalc_SCh; i < add( lMemRecalc, lMemRecalc_SCh ); i++ ) + FOR( i = lMemRecalc_SCh; i < ( lMemRecalc + lMemRecalc_SCh ); i++ ) { - tmp1 = bufChanL[i]; + tmp1 = bufChanL[i]; /* q_com */ move32(); - tmp2 = bufChanR[i]; + tmp2 = bufChanR[i]; /* q_com */ move32(); - ptr1[i] = L_add( Mpy_32_16_1( ptr1[i], sub( MAX_16, fac ) ), Mpy_32_16_1( tmp1, fac ) ); + ptr1[i] = L_add( Mpy_32_16_1( ptr1[i], sub( MAX_16, fac ) ), Mpy_32_16_1( tmp1, fac ) ); /* q_com */ move32(); /*ptr2[i] = (1.0f - fac) * ptr2[i] + fac * tmp2;*/ /* the secondary channel (downmixed) buffer of DFT stereo is empty ! */ - ptr2[i] = tmp2; + ptr2[i] = tmp2; /* q_com */ move32(); fac = add_sat( fac, incr ); @@ -1490,7 +1491,7 @@ static void icaMemUpdate_fx( /* reconstruction of the Secondary channel past segment */ FOR( i = 0; i < lMemRecalc_SCh; i++ ) { - ptr2[i] = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); + ptr2[i] = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); /* q_com */ move32(); } @@ -1498,15 +1499,15 @@ static void icaMemUpdate_fx( fac = div_s( 1, lMemRecalc ); // Q15 incr = fac; // Q15 move16(); - FOR( i = lMemRecalc_SCh; i < add( lMemRecalc, lMemRecalc_SCh ); i++ ) + FOR( i = lMemRecalc_SCh; i < ( lMemRecalc + lMemRecalc_SCh ); i++ ) { - tmp1 = L_add( Mpy_32_32( bufChanR[i], One_m_Ratio ), Mpy_32_32( bufChanL[i], ratio_L ) ); - tmp2 = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); + tmp1 = L_add( Mpy_32_32( bufChanR[i], One_m_Ratio ), Mpy_32_32( bufChanL[i], ratio_L ) ); /* q_com */ + tmp2 = L_sub( Mpy_32_32( bufChanL[i], One_m_Ratio ), Mpy_32_32( bufChanR[i], ratio_L ) ); /* q_com */ - ptr1[i] = L_add( Mpy_32_16_1( ptr1[i], sub( MAX_16, fac ) ), Mpy_32_16_1( tmp1, fac ) ); + ptr1[i] = L_add( Mpy_32_16_1( ptr1[i], sub( MAX_16, fac ) ), Mpy_32_16_1( tmp1, fac ) ); /* q_com */ move32(); /*ptr2[i] = (1.0f - fac) * ptr2[i] + fac * tmp2;*/ /* the secondary channel (downmixed) buffer of DFT stereo is empty ! */ - ptr2[i] = tmp2; + ptr2[i] = tmp2; /* q_com */ move32(); fac = add_sat( fac, incr ); @@ -1519,8 +1520,8 @@ static void icaMemUpdate_fx( { assert( L_MEM_RECALC_TBE_NS <= L_MEM_RECALC_NS ); i = NS2SA( sts[0]->input_Fs, L_MEM_RECALC_TBE_NS ); - Copy_Scale_sig_32_16( bufChanL + sub( add( lMemRecalc, lMemRecalc_SCh ), i ), hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], i, -Q16 ); - Copy_Scale_sig_32_16( bufChanR + sub( add( lMemRecalc, lMemRecalc_SCh ), i ), hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], i, -Q16 ); + Copy_Scale_sig_32_16( bufChanL + sub( add( lMemRecalc, lMemRecalc_SCh ), i ), hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], i, -Q16 ); /* q_com-16 */ + Copy_Scale_sig_32_16( bufChanR + sub( add( lMemRecalc, lMemRecalc_SCh ), i ), hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], i, -Q16 ); /* q_com-16 */ hCPE->hStereoICBWE->q_dataChan_fx = sub( q_com, Q16 ); move16(); } @@ -1535,7 +1536,7 @@ static void icaMemUpdate_fx( * ---------------------------------------------------------------*/ void stereo_tca_enc_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word16 input_frame /* i : length of a frame per channel */ + const Word16 input_frame /* i : length of a frame per channel Q0*/ ) { /* temp variables */ @@ -1599,12 +1600,12 @@ void stereo_tca_enc_fx( /* populate L/R memories into current buffers */ Word16 tempp_scale = L_norm_arr( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); tempp_scale = s_min( tempp_scale, L_norm_arr( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); - scale_sig32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); - scale_sig32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); + scale_sig32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); /* hStereoTCA->memChan_q + tempp_scale */ + scale_sig32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); /* hStereoTCA->memChan_q + tempp_scale */ hStereoTCA->memChan_q = add( hStereoTCA->memChan_q, tempp_scale ); move16(); - Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); - Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* hStereoTCA->memChan_q */ + Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* hStereoTCA->memChan_q */ bufChan_q = hStereoTCA->memChan_q; move16(); /* pointers to the current frame */ @@ -1612,14 +1613,14 @@ void stereo_tca_enc_fx( ptrChanR_fx = bufChanR_fx + add( lMemRecalc, lMemRecalc_SCh ); // Q:bufChan_q /* copy interleaved stereo data to two channels, e.g., L, R */ - Copy32( sts[0]->input32_fx, ptrChanL_fx, input_frame ); - Copy32( sts[1]->input32_fx, ptrChanR_fx, input_frame ); + Copy32( sts[0]->input32_fx, ptrChanL_fx, input_frame ); /* sts[0]->q_inp32 */ + Copy32( sts[1]->input32_fx, ptrChanR_fx, input_frame ); /* sts[1]->q_inp32 */ /* Scaling buffers to common Q*/ - scale_sig32( ptrChanL_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); - scale_sig32( ptrChanR_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); - scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); - scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); + scale_sig32( ptrChanL_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); /* s_min( q_com, bufChan_q ) */ + scale_sig32( ptrChanR_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); /* s_min( q_com, bufChan_q ) */ + scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); /* s_min( q_com, bufChan_q ) */ + scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); /* s_min( q_com, bufChan_q ) */ bufChan_q = s_min( q_com, bufChan_q ); q_com = bufChan_q; move16(); @@ -1673,7 +1674,7 @@ void stereo_tca_enc_fx( tempS = hStereoTCA->prevRefChanIndx; move16(); - Copy( hStereoTCA->prevCorrLagStats, tempS_buff, 3 ); + Copy( hStereoTCA->prevCorrLagStats, tempS_buff, 3 ); /* Q0 */ stereo_tca_init_enc_fx( hStereoTCA, input_Fs ); @@ -1695,13 +1696,13 @@ void stereo_tca_enc_fx( hStereoTCA->prevRefChanIndx = tempS; move16(); - Copy( tempS_buff, hStereoTCA->prevCorrLagStats, 3 ); + Copy( tempS_buff, hStereoTCA->prevCorrLagStats, 3 ); /* Q0 */ /* populate memory */ IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { - Copy32( sts[0]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); - Copy32( sts[1]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( sts[0]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* sts[0]->q_inp32 */ + Copy32( sts[1]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* sts[1]->q_inp32 */ } } @@ -1723,14 +1724,14 @@ void stereo_tca_enc_fx( /* pointers to the current frame of DS */ - ptrChanL_DS_fx = bufChanL_DS_fx + ADDED_MEM_DS; - ptrChanR_DS_fx = bufChanR_DS_fx + ADDED_MEM_DS; + ptrChanL_DS_fx = bufChanL_DS_fx + ADDED_MEM_DS; /* hStereoTCA->memChan_DS_q */ + ptrChanR_DS_fx = bufChanR_DS_fx + ADDED_MEM_DS; /* hStereoTCA->memChan_DS_q */ /* resample factor */ - dsFactor = (Word16) Mpy_32_32( input_Fs, 268436 /* 1/CORR_INTER_FS in Q31*/ ); // Q0 + dsFactor = extract_l( Mpy_32_32( input_Fs, 268436 /* 1/CORR_INTER_FS in Q31*/ ) ); // Q0 /* resample the stereo channels */ - deEmphResample( hStereoTCA, ptrChanL_fx, ptrChanR_fx, ptrChanL_DS_fx, ptrChanR_DS_fx, input_frame, dsFactor ); + deEmphResample_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, ptrChanL_DS_fx, ptrChanR_DS_fx, input_frame, dsFactor ); /**********************NEED to Allign first 40 index in each channel ************************************/ /* inter-channel corrStats estimation */ @@ -1757,7 +1758,7 @@ void stereo_tca_enc_fx( move16(); maxCorrStatsDev = N_MAX_SHIFT_CHANGE; move16(); - if ( LE_16( hStereoTCA->corrStatsSmoothFac_fx, 22938 /*0.7f*/ ) ) + IF( LE_16( hStereoTCA->corrStatsSmoothFac_fx, 22938 /*0.7f*/ ) ) { maxCorrStatsDev = 160; /* L_NCSHIFT_MAX @ 32kHz */ move16(); @@ -1765,7 +1766,7 @@ void stereo_tca_enc_fx( IF( LT_32( input_Fs, 32000 ) ) { - maxCorrStatsDev = (Word16) Mpy_32_32( imult3216( input_Fs, maxCorrStatsDev ), 67109 /* 1/32000.0f in Q31*/ ); // Q0 + maxCorrStatsDev = extract_l( Mpy_32_32( imult3216( input_Fs, maxCorrStatsDev ), 67109 /* 1/32000.0f in Q31*/ ) ); // Q0 } musicMode = ( hCPE->hCoreCoder[0]->sp_aud_decision0 == 1 || sts[0]->last_core > ACELP_CORE ); @@ -1778,17 +1779,17 @@ void stereo_tca_enc_fx( set16_fx( hStereoTCA->corrLagStats + 1, 0, 2 ); } - tempS = sub( hStereoTCA->corrLagStats[1], hStereoTCA->prevCorrLagStats[2] ); + tempS = sub( hStereoTCA->corrLagStats[1], hStereoTCA->prevCorrLagStats[2] ); /* Q0 */ IF( GT_16( abs_s( tempS ), maxCorrStatsDev ) ) { IF( tempS > 0 ) { - hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], maxCorrStatsDev ); + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], maxCorrStatsDev ); /* Q0 */ } ELSE { - hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], -maxCorrStatsDev ); + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], -maxCorrStatsDev ); /* Q0 */ } move16(); } @@ -1804,20 +1805,20 @@ void stereo_tca_enc_fx( move32(); IF( !musicMode ) { - tempLag[0] = s_min( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); + tempLag[0] = s_min( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); /* Q0 */ move16(); - tempLag[1] = s_max( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); + tempLag[1] = s_max( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); /* Q0 */ move16(); neighborLimit = s_min( 3, maxCorrStatsDev ); IF( LT_16( hStereoTCA->prevCorrLagStats[2], hStereoTCA->corrLagStats[2] ) ) { - tempLag[1] = s_min( tempLag[1], add( tempLag[0], neighborLimit ) ); + tempLag[1] = s_min( tempLag[1], add( tempLag[0], neighborLimit ) ); /* Q0 */ } ELSE { - tempLag[0] = s_max( tempLag[0], sub( tempLag[1], neighborLimit ) ); + tempLag[0] = s_max( tempLag[0], sub( tempLag[1], neighborLimit ) ); /* Q0 */ } move16(); utilCrossCorr_fx( ptrChanL_fx, q_com, ptrChanR_fx, q_com, NULL, corrEstStage2_fx, &corrEstStage2_exp, tempLag, input_frame, 0 ); @@ -1830,9 +1831,9 @@ void stereo_tca_enc_fx( IF( GT_16( abs_s( tempS ), neighborLimit ) ) { - tempLag[0] = hStereoTCA->corrLagStats[1]; + tempLag[0] = hStereoTCA->corrLagStats[1]; /* Q0 */ move16(); - tempLag[1] = hStereoTCA->corrLagStats[1]; + tempLag[1] = hStereoTCA->corrLagStats[1]; /* Q0 */ move16(); utilCrossCorr_fx( ptrChanL_fx, q_com, ptrChanR_fx, q_com, NULL, &tempF1_fx, &tempF1_exp, tempLag, input_frame, 0 ); @@ -1841,11 +1842,11 @@ void stereo_tca_enc_fx( { IF( tempS > 0 ) { - hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_min( abs_s( tempS ), maxCorrStatsDev ) ); + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_min( abs_s( tempS ), maxCorrStatsDev ) ); /* Q0 */ } ELSE { - hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_max( -abs_s( tempS ), -maxCorrStatsDev ) ); + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_max( -abs_s( tempS ), -maxCorrStatsDev ) ); /* Q0 */ } move16(); } @@ -1879,37 +1880,37 @@ void stereo_tca_enc_fx( 1. adjust samples, 2. interp shift variation, 3. gain estimation */ - prevNCShift = abs_s( hStereoTCA->prevCorrLagStats[2] ); - currentNCShift = abs_s( hStereoTCA->corrLagStats[2] ); + prevNCShift = abs_s( hStereoTCA->prevCorrLagStats[2] ); /* Q0 */ + currentNCShift = abs_s( hStereoTCA->corrLagStats[2] ); /* Q0 */ IF( EQ_16( hStereoTCA->prevRefChanIndx, L_CH_INDX ) ) { - v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ + v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q - 2*/ Copy32( ptrChanL_fx - add( lMemRecalc, lMemRecalc_SCh ), input_mem_loc_fx[0], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q - 2 v_multc_fixed( ptrChanR_fx + sub( prevNCShift, add( lMemRecalc, lMemRecalc_SCh ) ), hStereoTCA->prevTargetGain_fx, input_mem_loc_fx[1], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q-2 - v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2 */ + v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2*/ } ELSE { - v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ + v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2*/ Copy32( ptrChanL_fx + add( prevNCShift, sub( lMemRecalc, lMemRecalc_SCh ) ), input_mem_loc_fx[0], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 v_multc_fixed( ptrChanR_fx - add( lMemRecalc, lMemRecalc_SCh ), hStereoTCA->prevTargetGain_fx, input_mem_loc_fx[1], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 - v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ + v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2*/ } bufChan_q = sub( bufChan_q, 2 ); q_com = bufChan_q; move16(); input_mem_loc_q = bufChan_q; move16(); - target_fx = ptrChanR_fx; - target_idx = R_CH_INDX; + target_fx = ptrChanR_fx; /* bufChan_q -2 */ + target_idx = R_CH_INDX; /* Q0 */ move16(); /* identify target signal to correct for shift variations */ test(); test(); IF( ( prevNCShift == 0 && hStereoTCA->corrLagStats[2] < 0 ) || EQ_16( hStereoTCA->prevRefChanIndx, R_CH_INDX ) ) { - target_fx = ptrChanL_fx; + target_fx = ptrChanL_fx; /* bufChan_q - 2 */ target_idx = L_CH_INDX; move16(); } @@ -1926,7 +1927,7 @@ void stereo_tca_enc_fx( } /* Note!! : Always keep the assert (prevNCShift>>1) below according to the equation used here to get tempS */ - tempS = shr( currentNCShift, 1 ); + tempS = shr( currentNCShift, 1 ); /* Q0 */ IF( LE_32( abs( sub( currentNCShift, prevNCShift ) ), L_min( N_MAX_SHIFT_CHANGE, Mpy_32_32( imult3216( input_Fs, N_MAX_SHIFT_CHANGE ), 67109 /* 1/32000.0f in Q31*/ ) ) ) ) { @@ -1934,18 +1935,18 @@ void stereo_tca_enc_fx( } ELSE { - tempS = s_min( s_max( tempS, add( sub( prevNCShift, currentNCShift ), sub( L_shift_adapt, input_frame ) ) ), add( sub( prevNCShift, currentNCShift ), lMemRecalc ) ); + tempS = s_min( s_max( tempS, add( sub( prevNCShift, currentNCShift ), sub( L_shift_adapt, input_frame ) ) ), add( sub( prevNCShift, currentNCShift ), lMemRecalc ) ); /* Q0 */ adjustTargetSignal_fx( ( target_fx - tempS ), prevNCShift, currentNCShift, L_shift_adapt, 1 ); } IF( target_idx == L_CH_INDX ) { - Copy32( target_fx - tempS, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); + Copy32( target_fx - tempS, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); /* bufChan_q - 2 */ } ELSE { - v_multc_fixed( target_fx - tempS, hStereoTCA->prevTargetGain_fx, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); + v_multc_fixed( target_fx - tempS, hStereoTCA->prevTargetGain_fx, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); /* bufChan_q - 2 */ } } @@ -1967,16 +1968,16 @@ void stereo_tca_enc_fx( /* quantize the corrStats */ Word16 temp_exp, tempF_16fx; - Word16 scalar_value = BASOP_Util_Divide1616_Scale( currentNCShift, dsFactor, &temp_exp ); + Word16 scalar_value = BASOP_Util_Divide1616_Scale( currentNCShift, dsFactor, &temp_exp ); /* Q15-temp_exp */ IF( temp_exp < 0 ) { - scalar_value = shl( scalar_value, sub( temp_exp, Q3 ) ); // Q12 - hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, ONE_IN_Q11, 1 << STEREO_BITS_TCA_CORRSTATS ); + scalar_value = shl( scalar_value, sub( temp_exp, Q3 ) ); // Q12 + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, ONE_IN_Q11, ( 1 << STEREO_BITS_TCA_CORRSTATS ) ); /* Q0 */ move16(); } ELSE { - hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), ( 1 << STEREO_BITS_TCA_CORRSTATS ) ); /* Q0 */ move16(); } tempF_fx = tempF_16fx; @@ -1995,7 +1996,7 @@ void stereo_tca_enc_fx( currentNCShift = 0; /* only to avoid compilation warning */ move16(); - target_fx = ptrChanL_fx; /* only to avoid compilation warning */ + target_fx = ptrChanL_fx; /* only to avoid compilation warning bufChan_q*/ move16(); target_idx = L_CH_INDX; /* only to avoid compilation warning */ move16(); @@ -2021,8 +2022,8 @@ void stereo_tca_enc_fx( *-----------------------------------------------------------------*/ /* back up the L/R missing target */ - Copy32( bufChanL_fx + input_frame, hStereoTCA->memChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); - Copy32( bufChanR_fx + input_frame, hStereoTCA->memChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( bufChanL_fx + input_frame, hStereoTCA->memChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* bufChan_q */ + Copy32( bufChanR_fx + input_frame, hStereoTCA->memChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); /* bufChan_q */ hStereoTCA->memChan_q = bufChan_q; IF( currentNCShift != 0 ) @@ -2051,7 +2052,7 @@ void stereo_tca_enc_fx( scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( s_min( input_mem_loc_q, sts[0]->q_inp32 ), sts[0]->q_inp32 ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( s_min( input_mem_loc_q, sts[1]->q_inp32 ), sts[1]->q_inp32 ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) - input_mem_loc_q = s_min( input_mem_loc_q, sts[0]->q_inp32 ); + input_mem_loc_q = s_min( input_mem_loc_q, sts[0]->q_inp32 ); /* sts[0]->q_inp32 */ sts[0]->q_inp32 = input_mem_loc_q; move16(); sts[1]->q_inp32 = input_mem_loc_q; @@ -2063,7 +2064,7 @@ void stereo_tca_enc_fx( test(); IF( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || EQ_16( prev_ICA_flag, 1 ) ) { - Copy32( target_fx + currentNCShift, sts[target_idx]->input32_fx, input_frame ); + Copy32( target_fx + currentNCShift, sts[target_idx]->input32_fx, input_frame ); /* bufChan_q */ } IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) ) @@ -2100,14 +2101,14 @@ void stereo_tca_enc_fx( } /* update L/R DS memories */ - Copy32( bufChanL_DS_fx + L_FRAME_DS, hStereoTCA->memChanL_DS_fx, ADDED_MEM_DS ); - Copy32( bufChanR_DS_fx + L_FRAME_DS, hStereoTCA->memChanR_DS_fx, ADDED_MEM_DS ); + Copy32( bufChanL_DS_fx + L_FRAME_DS, hStereoTCA->memChanL_DS_fx, ADDED_MEM_DS ); /* hStereoTCA->memChan_DS_q */ + Copy32( bufChanR_DS_fx + L_FRAME_DS, hStereoTCA->memChanR_DS_fx, ADDED_MEM_DS ); /* hStereoTCA->memChan_DS_q */ /* save the reference channel index for next frame */ - hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; + hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; /* Q0 */ move16(); /* save the corr lag stats for next frame */ - Copy( hStereoTCA->corrLagStats, hStereoTCA->prevCorrLagStats, 3 ); + Copy( hStereoTCA->corrLagStats, hStereoTCA->prevCorrLagStats, 3 ); /* Q0 */ /* save the target gain for next frame */ hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; // Q29 @@ -2121,18 +2122,18 @@ void stereo_tca_enc_fx( *-------------------------------------------------------------------*/ void stereo_tca_init_enc_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ - const Word32 input_Fs /* i : input sampling frequency */ + const Word32 input_Fs /* i : input sampling frequency Q0*/ ) { Word16 div1; Word16 div_e; hStereoTCA->lMemRecalc = NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ); move16(); - div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_12k8 ), input_Fs, &div_e ); + div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_12k8 ), input_Fs, &div_e ); /* Q15-div_e */ hStereoTCA->lMemRecalc_12k8 = shr( div1, 1 + sub( 15, div_e ) ); move16(); - div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_16k ), input_Fs, &div_e ); + div1 = BASOP_Util_Divide3232_Scale( L_mult( hStereoTCA->lMemRecalc, INT_FS_16k ), input_Fs, &div_e ); /* Q15-div_e */ hStereoTCA->lMemRecalc_16k = shr( div1, 1 + sub( 15, div_e ) ); move16(); @@ -2210,10 +2211,10 @@ static void unclr_calc_corr_features_fx( Word32 buf1[], /* i : left channel q_com*/ Word32 buf2[], /* i : right channel q_com*/ Word16 q_com, - const Word16 length, /* i : length of input signal buffers */ + const Word16 length, /* i : length of input signal buffers Q0*/ Word32 corrEst[], /* i : buffer containing inter-channel correlation values corrEst_exp*/ Word16 corrEst_exp, - const Word16 lagSearchRange[], /* i : minimum and maximum lags for corrEst[] */ + const Word16 lagSearchRange[], /* i : minimum and maximum lags for corrEst[] Q0*/ Word32 *corrEst_ncorr, /* o : norm. x-correlation btw. current and previous correlation buffers corrEst_ncorr_exp*/ Word16 *corrEst_ncorr_exp ) { @@ -2246,22 +2247,22 @@ static void unclr_calc_corr_features_fx( FOR( i = 0; i < length; i++ ) { - mono_i = BASOP_Util_Add_Mant32Exp( L_shr( buf1[i], 1 ), sub( 31, q_com ), L_shr( buf2[i], 1 ), sub( 31, q_com ), &exp ); - corrL = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, Mpy_32_32( buf1[i], mono_i ), add( sub( 31, q_com ), exp ), &corrL_exp ); - corrR = BASOP_Util_Add_Mant32Exp( corrR, corrR_exp, Mpy_32_32( buf2[i], mono_i ), add( sub( 31, q_com ), exp ), &corrR_exp ); + mono_i = BASOP_Util_Add_Mant32Exp( L_shr( buf1[i], 1 ), sub( 31, q_com ), L_shr( buf2[i], 1 ), sub( 31, q_com ), &exp ); /* Q31-exp */ + corrL = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, Mpy_32_32( buf1[i], mono_i ), add( sub( 31, q_com ), exp ), &corrL_exp ); /* Q31-corrL_exp */ + corrR = BASOP_Util_Add_Mant32Exp( corrR, corrR_exp, Mpy_32_32( buf2[i], mono_i ), add( sub( 31, q_com ), exp ), &corrR_exp ); /* Q31-corrR_exp */ ener = BASOP_Util_Add_Mant32Exp( ener, ener_exp, Mpy_32_32( mono_i, mono_i ), shl( exp, 1 ), &ener_exp ); - side_i = BASOP_Util_Add_Mant32Exp( L_shr( buf1[i], 1 ), sub( 31, q_com ), L_negate( L_shr( buf2[i], 1 ) ), sub( 31, q_com ), &exp ); - ener_side = BASOP_Util_Add_Mant32Exp( ener_side, ener_side_exp, Mpy_32_32( side_i, side_i ), shl( exp, 1 ), &ener_side_exp ); - sum_prod = BASOP_Util_Add_Mant32Exp( sum_prod, sum_prod_exp, Mpy_32_32( buf1[i], buf2[i] ), sub( 62, shl( q_com, 1 ) ), &sum_prod_exp ); + side_i = BASOP_Util_Add_Mant32Exp( L_shr( buf1[i], 1 ), sub( 31, q_com ), L_negate( L_shr( buf2[i], 1 ) ), sub( 31, q_com ), &exp ); /* Q31-exp */ + ener_side = BASOP_Util_Add_Mant32Exp( ener_side, ener_side_exp, Mpy_32_32( side_i, side_i ), shl( exp, 1 ), &ener_side_exp ); /* Q31-ener_side_exp */ + sum_prod = BASOP_Util_Add_Mant32Exp( sum_prod, sum_prod_exp, Mpy_32_32( buf1[i], buf2[i] ), sub( 62, shl( q_com, 1 ) ), &sum_prod_exp ); /* Q31-sum_prod_exp */ } /* average energy of L and R channels */ - hStereoClassif->ave_ener_L_fx = Mpy_32_32( hStereoTCA->E1_mem_fx, 13421772 /* 1/length in Q31*/ ); + hStereoClassif->ave_ener_L_fx = Mpy_32_32( hStereoTCA->E1_mem_fx, 13421772 /* 1/length in Q31*/ ); /* Q31-hStereoClassif->ave_ener_L_fx_e */ move32(); hStereoClassif->ave_ener_L_fx_e = hStereoTCA->E1_mem_exp; move16(); - hStereoClassif->ave_ener_R_fx = Mpy_32_32( hStereoTCA->E2_mem_fx, 13421772 /* 1/length in Q31*/ ); + hStereoClassif->ave_ener_R_fx = Mpy_32_32( hStereoTCA->E2_mem_fx, 13421772 /* 1/length in Q31*/ ); /* Q31-hStereoClassif->ave_ener_R_fx_e */ move32(); hStereoClassif->ave_ener_R_fx_e = hStereoTCA->E2_mem_exp; move16(); @@ -2269,7 +2270,7 @@ static void unclr_calc_corr_features_fx( /* unnormalized L/R correlation */ IF( sum_prod ) { - sum_prod = BASOP_Util_Log10( L_abs( sum_prod ), sum_prod_exp ); + sum_prod = BASOP_Util_Log10( L_abs( sum_prod ), sum_prod_exp ); /* Q31-sum_prod_exp */ sum_prod_exp = 6; move16(); } @@ -2286,12 +2287,12 @@ static void unclr_calc_corr_features_fx( hStereoClassif->xtalk_fv_fx[E_sum_prod] = L_shr( sum_prod, 10 ); // Q15 move32(); /* S/M energy ratio */ - Word32 inp1 = Sqrt32( Mpy_32_32( ener_side, 13421773 /* 1/L_FRAME_DS in Q31*/ ), &ener_side_exp ); - inp1 = BASOP_Util_Log10( inp1, ener_side_exp ); + Word32 inp1 = Sqrt32( Mpy_32_32( ener_side, 13421773 /* 1/L_FRAME_DS in Q31*/ ), &ener_side_exp ); /* Q31-ener_side_exp */ + inp1 = BASOP_Util_Log10( inp1, ener_side_exp ); /* Q31-ener_side_exp */ Word16 temp = ener_exp; move16(); - Word32 inp2 = Sqrt32( Mpy_32_32( ener, 13421773 /* 1/L_FRAME_DS in Q31*/ ), &ener_exp ); - inp2 = BASOP_Util_Log10( inp2, ener_exp ); + Word32 inp2 = Sqrt32( Mpy_32_32( ener, 13421773 /* 1/L_FRAME_DS in Q31*/ ), &ener_exp ); /* Q31-ener_exp */ + inp2 = BASOP_Util_Log10( inp2, ener_exp ); /* Q31-ener_exp */ ener_exp = temp; move16(); @@ -2319,17 +2320,17 @@ static void unclr_calc_corr_features_fx( move32(); } - hStereoClassif->unclr_fv_fx[E_corrEst0] = L_shl( corrEst[abs_s( lagSearchRange[0] )], sub( corrEst_exp, 16 ) ); + hStereoClassif->unclr_fv_fx[E_corrEst0] = L_shl( corrEst[abs_s( lagSearchRange[0] )], sub( corrEst_exp, 16 ) ); /* Q15 */ move32(); - hStereoClassif->unclr_fv_fx[E_corrEstMax] = L_shl( corrEstMax, sub( corrEst_exp, 16 ) ); + hStereoClassif->unclr_fv_fx[E_corrEstMax] = L_shl( corrEstMax, sub( corrEst_exp, 16 ) ); /* Q15 */ move32(); - hStereoClassif->unclr_fv_fx[E_corrLagMax] = L_shl( corrLagMax, 15 ); + hStereoClassif->unclr_fv_fx[E_corrLagMax] = L_shl( corrLagMax, 15 ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_corrEst0] = L_shl( corrEst[abs_s( lagSearchRange[0] )], sub( corrEst_exp, 16 ) ); + hStereoClassif->xtalk_fv_fx[E_corrEst0] = L_shl( corrEst[abs_s( lagSearchRange[0] )], sub( corrEst_exp, 16 ) ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_corrEstMax] = L_shl( corrEstMax, sub( corrEst_exp, 16 ) ); + hStereoClassif->xtalk_fv_fx[E_corrEstMax] = L_shl( corrEstMax, sub( corrEst_exp, 16 ) ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_corrLagMax] = L_shl( corrLagMax, 15 ); + hStereoClassif->xtalk_fv_fx[E_corrLagMax] = L_shl( corrLagMax, 15 ); /* Q15 */ move32(); /* L/M and R/M correlation */ @@ -2345,14 +2346,14 @@ static void unclr_calc_corr_features_fx( move32(); } - ic_Lm = BASOP_Util_Divide3232_Scale_cadence( corrL, ener, &exp1 ); + ic_Lm = BASOP_Util_Divide3232_Scale_cadence( corrL, ener, &exp1 ); /* Q31-exp1 */ exp1 = add( exp1, sub( corrL_exp, ener_exp ) ); - ic_Rm = BASOP_Util_Divide3232_Scale_cadence( corrR, ener, &exp2 ); + ic_Rm = BASOP_Util_Divide3232_Scale_cadence( corrR, ener, &exp2 ); /* Q31-exp2 */ exp2 = add( exp2, sub( corrR_exp, ener_exp ) ); m_corrL_corrR = L_sub( L_max( L_abs( L_shl( ic_Lm, sub( exp1, s_max( exp1, exp2 ) ) ) ), L_abs( L_shl( ic_Rm, sub( exp2, s_max( exp1, exp2 ) ) ) ) ), L_min( L_abs( L_shl( ic_Lm, sub( exp1, s_max( exp1, exp2 ) ) ) ), L_abs( L_shl( ic_Rm, sub( exp2, s_max( exp1, exp2 ) ) ) ) ) ); // s_max(exp1, exp2) - inp1 = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, corrR, corrR_exp, &exp ); + inp1 = BASOP_Util_Add_Mant32Exp( corrL, corrL_exp, corrR, corrR_exp, &exp ); /* Q31-exp */ IF( inp1 ) { d_corrL_corrR = BASOP_Util_Log10( L_abs( inp1 ), exp ); // Q25 @@ -2372,16 +2373,17 @@ static void unclr_calc_corr_features_fx( /* norm. x-correlation btw. current and previous correlation buffers */ tempLen = ( 2 * L_NCSHIFT_DS + 1 ); + move16(); Word64 L64_sum = 0; move64(); FOR( k = 0; k < tempLen; k++ ) { - L64_sum = W_mac_32_32( L64_sum, corrEst[k], hStereoTCA->corrEstPrev_fx[2][k] ); + L64_sum = W_mac_32_32( L64_sum, corrEst[k], hStereoTCA->corrEstPrev_fx[2][k] ); /* 2*(Q31-corrEst_exp)+1 */ } k = W_norm( L64_sum ); - L64_sum = W_shl( L64_sum, k ); - num = W_extract_h( L64_sum ); // ener_side_q + L64_sum = W_shl( L64_sum, k ); /* 2*(Q31-corrEst_exp)+1+k */ + num = W_extract_h( L64_sum ); // ener_side_q num_exp = sub( 31, sub( add( add( add( sub( 31, corrEst_exp ), sub( 31, hStereoTCA->corrEstPrev_exp ) ), 1 ), k ), 32 ) ); exp1 = corrEst_exp; @@ -2393,24 +2395,26 @@ static void unclr_calc_corr_features_fx( inp2 = sum2_32_exp_fx( hStereoTCA->corrEstPrev_fx[2], tempLen, &exp2, 3 ); den_exp = add( exp1, exp2 ); - den = Sqrt32( Mpy_32_32( inp1, inp2 ), &den_exp ); + den = Sqrt32( Mpy_32_32( inp1, inp2 ), &den_exp ); /* Q31-den_exp */ IF( den == 0 ) { *corrEst_ncorr = 0; - move16(); - *corrEst_ncorr_exp = 0; move32(); + *corrEst_ncorr_exp = 0; + move16(); } ELSE { - *corrEst_ncorr = BASOP_Util_Divide3232_Scale_cadence( num, den, &exp ); + *corrEst_ncorr = BASOP_Util_Divide3232_Scale_cadence( num, den, &exp ); /* Q31-corrEst_ncorr_exp */ *corrEst_ncorr_exp = add( exp, sub( num_exp, den_exp ) ); + move32(); + move16(); } - hStereoClassif->unclr_fv_fx[E_corrEst_ncorr] = L_shl( *corrEst_ncorr, sub( *corrEst_ncorr_exp, 16 ) ); + hStereoClassif->unclr_fv_fx[E_corrEst_ncorr] = L_shl( *corrEst_ncorr, sub( *corrEst_ncorr_exp, 16 ) ); /* Q15 */ move32(); - hStereoClassif->xtalk_fv_fx[E_corrEst_ncorr] = L_shl( *corrEst_ncorr, sub( *corrEst_ncorr_exp, 16 ) ); + hStereoClassif->xtalk_fv_fx[E_corrEst_ncorr] = L_shl( *corrEst_ncorr, sub( *corrEst_ncorr_exp, 16 ) ); /* Q15 */ move32(); return; diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 7ed9d71d179ec00e7e98b21412195130e0481684..30df4e0bc125069dadccfc09b6b9d87a9b188422 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -61,7 +61,7 @@ static void ic_bwe_enc_reset_fx( /* inter-channel BWE spectral shape adj. */ hStereoICBWE->prevSpecMapping_fx = 0; move32(); - hStereoICBWE->prevgsMapping_fx = ONE_IN_Q31; + hStereoICBWE->prevgsMapping_fx = ONE_IN_Q31; /* Q31 */ move32(); hStereoICBWE->prevgsMapping_e = 0; move16(); @@ -71,7 +71,7 @@ static void ic_bwe_enc_reset_fx( set32_fx( hStereoICBWE->memShbSpecXcorr_fx, 0, 6 ); hStereoICBWE->memShbSpecXcorr_e = 0; move16(); - set32_fx( hStereoICBWE->memGsEnerMap_fx, ONE_IN_Q31, 2 ); + set32_fx( hStereoICBWE->memGsEnerMap_fx, ONE_IN_Q31, 2 ); /* Q31 */ hStereoICBWE->memGsEnerMap_e = 0; move16(); set32_fx( hStereoICBWE->mem_nrg_L_fx, 0, 2 ); @@ -83,7 +83,7 @@ static void ic_bwe_enc_reset_fx( set32_fx( hStereoICBWE->mem_nrg_DMX_fx, 0, 2 ); hStereoICBWE->mem_nrg_DMX_fx_e = 0; move16(); - hStereoICBWE->gDes_pastFrame_fx = ONE_IN_Q31; + hStereoICBWE->gDes_pastFrame_fx = ONE_IN_Q31; /* Q31 */ move32(); hStereoICBWE->gDes_pastFrame_e = 0; move16(); @@ -101,13 +101,13 @@ static void ic_bwe_enc_reset_fx( * Encode and apply the spectral shape mapping of ref to the non-ref channel *---------------------------------------------------------------------------*/ static Word16 ic_bwe_enc_specMapping_ivas_fx( - const Word32 *shb_frame_target_fx, /* i : target shb */ + const Word32 *shb_frame_target_fx, /* i : target shb Q31-shb_frame_target_e*/ Word16 shb_frame_target_e, - Word32 *shb_synth_nonref_fx, /* o : non-ref shb synth */ + Word32 *shb_synth_nonref_fx, /* o : non-ref shb synth Q31-shb_synth_nonref_e*/ Word16 shb_synth_nonref_e, - Word32 *specMapping_fx, /* i/o: current frame's mapping */ - Word32 *memShbSpecMapping_fx, /* i/o: current frame's mapping */ - Word32 *memShbSpecXcorr_fx, /* i/o: ic bwe spec mapping scorr memory */ + Word32 *specMapping_fx, /* i/o: current frame's mapping Qx*/ + Word32 *memShbSpecMapping_fx, /* i/o: current frame's mapping Qx*/ + Word32 *memShbSpecXcorr_fx, /* i/o: ic bwe spec mapping scorr memory Q31-memShbSpecXcorr_e*/ Word16 *memShbSpecXcorr_e ) { Word16 idx; @@ -133,8 +133,8 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( /* Calculate rxx(1)/rxx(0) of the non ref target */ - temp0_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx, shb_frame_target_e, L_FRAME16k - 1, &temp0_exp ); - temp1_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx + 1, shb_frame_target_e, L_FRAME16k - 1, &temp1_exp ); + temp0_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx, shb_frame_target_e, L_FRAME16k - 1, &temp0_exp ); /* Q31-temp0_exp */ + temp1_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx + 1, shb_frame_target_e, L_FRAME16k - 1, &temp1_exp ); /* Q31-temp1_exp */ /* Smoothing */ temp0_fx = L_shr( temp0_fx, 1 ); @@ -164,10 +164,10 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( } /* Calculate rxx(1)/rxx(0) of the non ref synth */ - temp0_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, L_FRAME16k - 3, &temp0_exp ); - temp1_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 1, shb_synth_nonref_e, L_FRAME16k - 3, &temp1_exp ); - temp2_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 2, shb_synth_nonref_e, L_FRAME16k - 3, &temp2_exp ); - temp3_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 3, shb_synth_nonref_e, L_FRAME16k - 3, &temp3_exp ); + temp0_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, L_FRAME16k - 3, &temp0_exp ); /* Q31-temp0_exp */ + temp1_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 1, shb_synth_nonref_e, L_FRAME16k - 3, &temp1_exp ); /* Q31-temp1_exp */ + temp2_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 2, shb_synth_nonref_e, L_FRAME16k - 3, &temp2_exp ); /* Q31-temp2_exp */ + temp3_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 3, shb_synth_nonref_e, L_FRAME16k - 3, &temp3_exp ); /* Q31-temp3_exp */ /* Smoothing */ temp0_fx = L_shr( temp0_fx, 1 ); @@ -193,10 +193,10 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( move16(); } } - memShbSpecXcorr_fx[2] = L_shr( temp0_fx, sub( exp, temp0_exp ) ); - memShbSpecXcorr_fx[3] = L_shr( temp1_fx, sub( exp, temp1_exp ) ); - memShbSpecXcorr_fx[4] = L_shr( temp2_fx, sub( exp, temp2_exp ) ); - memShbSpecXcorr_fx[5] = L_shr( temp3_fx, sub( exp, temp3_exp ) ); + memShbSpecXcorr_fx[2] = L_shr( temp0_fx, sub( exp, temp0_exp ) ); /* Q31-exp */ + memShbSpecXcorr_fx[3] = L_shr( temp1_fx, sub( exp, temp1_exp ) ); /* Q31-exp */ + memShbSpecXcorr_fx[4] = L_shr( temp2_fx, sub( exp, temp2_exp ) ); /* Q31-exp */ + memShbSpecXcorr_fx[5] = L_shr( temp3_fx, sub( exp, temp3_exp ) ); /* Q31-exp */ *memShbSpecXcorr_e = exp; move32(); @@ -208,9 +208,9 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( IF( temp0_fx != 0 ) { - Txx1_fx = BASOP_Util_Divide3232_Scale( temp1_fx, temp0_fx, &Txx1_e ); - Txx2_fx = BASOP_Util_Divide3232_Scale( temp2_fx, temp0_fx, &Txx2_e ); - Txx3_fx = BASOP_Util_Divide3232_Scale( temp3_fx, temp0_fx, &Txx3_e ); + Txx1_fx = BASOP_Util_Divide3232_Scale( temp1_fx, temp0_fx, &Txx1_e ); /* Q31-Txx1_e */ + Txx2_fx = BASOP_Util_Divide3232_Scale( temp2_fx, temp0_fx, &Txx2_e ); /* Q31-Txx1_e */ + Txx3_fx = BASOP_Util_Divide3232_Scale( temp3_fx, temp0_fx, &Txx3_e ); /* Q31-Txx1_e */ } T_desired_fx = T_nonref_target_fx; @@ -219,32 +219,32 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( move16(); Word16 tmp, tmp1; - exp = BASOP_Util_Add_MantExp( Txx3_fx, Txx3_e, Txx1_fx, Txx1_e, &tmp ); - tmp1 = mult( Txx2_fx, T_desired_fx ); // Txx2_e + T_desired_e - a_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx2_e, T_desired_e ), 1 ), negate( tmp ), exp, &a_fx ); + exp = BASOP_Util_Add_MantExp( Txx3_fx, Txx3_e, Txx1_fx, Txx1_e, &tmp ); /* Q15-exp */ + tmp1 = mult( Txx2_fx, T_desired_fx ); // Txx2_e + T_desired_e + a_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx2_e, T_desired_e ), 1 ), negate( tmp ), exp, &a_fx ); /* Q15-a_e */ - exp = BASOP_Util_Add_MantExp( Txx2_fx, Txx2_e, 32767, 1, &tmp ); - tmp1 = mult( Txx1_fx, T_desired_fx ); // Txx1_e + T_desired_e - b_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx1_e, T_desired_e ), 1 ), negate( tmp ), exp, &b_fx ); + exp = BASOP_Util_Add_MantExp( Txx2_fx, Txx2_e, 32767, 1, &tmp ); /* Q15-exp */ + tmp1 = mult( Txx1_fx, T_desired_fx ); // Txx1_e + T_desired_e + b_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx1_e, T_desired_e ), 1 ), negate( tmp ), exp, &b_fx ); /* Q15-b_fx */ - c_e = BASOP_Util_Add_MantExp( T_desired_fx, T_desired_e, negate( Txx1_fx ), Txx1_e, &c_fx ); + c_e = BASOP_Util_Add_MantExp( T_desired_fx, T_desired_e, negate( Txx1_fx ), Txx1_e, &c_fx ); /* Q15-c_fx */ u_fx = extract_l( *specMapping_fx ); tmp = mult( b_fx, b_fx ); // b_e + b_e; tmp1 = mult( a_fx, c_fx ); // a_e + c_e + 2 - exp = BASOP_Util_Add_MantExp( tmp, add( b_e, b_e ), tmp1, add( a_e, add( c_e, 2 ) ), &temp_fx ); + exp = BASOP_Util_Add_MantExp( tmp, add( b_e, b_e ), tmp1, add( a_e, add( c_e, 2 ) ), &temp_fx ); /* Q15-exp */ test(); IF( temp_fx >= 0 && a_fx != 0 ) { - temp_fx = Sqrt16( temp_fx, &exp ); - exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, temp_fx, exp, &tmp ); - u1_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u1_fx ); + temp_fx = Sqrt16( temp_fx, &exp ); /* Q15-exp */ + exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, temp_fx, exp, &tmp ); /* Q15-exp */ + u1_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u1_fx ); /* Q15-u1_e */ u1_e = add( u1_e, sub( exp, add( a_e, 1 ) ) ); - exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, negate( temp_fx ), exp, &tmp ); - u2_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u2_fx ); + exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, negate( temp_fx ), exp, &tmp ); /* Q15-exp */ + u2_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u2_fx ); /* Q15-u2_e */ u2_e = add( u2_e, sub( exp, add( a_e, 1 ) ) ); test(); @@ -298,7 +298,7 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( /* Quantize spec. mapping **/ Word16 specMapping16; - idx = usquant_fx( shr( u_fx, sub( 0, u_e ) ), &specMapping16, -19660, 6553, 1 << STEREO_ICBWE_SPBITS ); // -0.6 in in Q15 -> -19660, 0.2 in Q15 -> 6553 + idx = usquant_fx( shr( u_fx, sub( 0, u_e ) ), &specMapping16, -19660, 6553, ( 1 << STEREO_ICBWE_SPBITS ) ); // -0.6 in in Q15 -> -19660, 0.2 in Q15 -> 6553 *specMapping_fx = L_deposit_h( specMapping16 ); move32(); @@ -324,17 +324,17 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( /*! r: return quant. index value */ static Word16 ic_bwe_enc_gsMapping_ivas_fx( - const Word32 relG_targ_fx, /* i : gDes, rel gain target */ + const Word32 relG_targ_fx, /* i : gDes, rel gain target Q31-relG_targ_e*/ Word16 relG_targ_e, - const Word16 *shbSynth_fx, /* i : ref synth signal */ + const Word16 *shbSynth_fx, /* i : ref synth signal Q15-shbSynth_e*/ Word16 shbSynth_e, /* i : ref synth signal */ - Word32 *synthSHB_nonref_fx, /* i : nonref synth signal */ + Word32 *synthSHB_nonref_fx, /* i : nonref synth signal Q31-synthSHB_nonref_e*/ Word16 *synthSHB_nonref_e, /* i : nonref synth signal */ - Word32 *gsMapping_fx, /* i/o: gs mapping */ + Word32 *gsMapping_fx, /* i/o: gs mapping Q31-gsMapping_e*/ Word16 *gsMapping_e, /* i/o: gs mapping */ - Word32 *memEner_fx, /* */ + Word32 *memEner_fx, /* Q31-memEner_e*/ Word16 *memEner_e, - const Word16 element_mode /* i : element mode */ + const Word16 element_mode /* i : element mode Q0*/ ) { Word16 i; @@ -355,13 +355,13 @@ static Word16 ic_bwe_enc_gsMapping_ivas_fx( move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { - temp1_fx32 = BASOP_Util_Add_Mant32Exp( temp1_fx32, temp1_exp, L_abs( L_deposit_h( shbSynth_fx[i] ) ), exp1, &temp1_exp ); - temp2_fx32 = BASOP_Util_Add_Mant32Exp( temp2_fx32, temp2_exp, L_abs( synthSHB_nonref_fx[i] ), exp2, &temp2_exp ); + temp1_fx32 = BASOP_Util_Add_Mant32Exp( temp1_fx32, temp1_exp, L_abs( L_deposit_h( shbSynth_fx[i] ) ), exp1, &temp1_exp ); /* Q31-temp1_exp */ + temp2_fx32 = BASOP_Util_Add_Mant32Exp( temp2_fx32, temp2_exp, L_abs( synthSHB_nonref_fx[i] ), exp2, &temp2_exp ); /* Q31-temp2_exp */ } - memEner_fx[0] = temp1_fx32; - memEner_fx[1] = L_shr( temp2_fx32, abs_s( sub( temp1_exp, temp2_exp ) ) ); + memEner_fx[0] = temp1_fx32; /* Q31-temp1_exp */ + memEner_fx[1] = L_shr( temp2_fx32, abs_s( sub( temp1_exp, temp2_exp ) ) ); /* Q31-temp1_exp */ move32(); move32(); *memEner_e = s_max( temp1_exp, temp2_exp ); @@ -389,7 +389,7 @@ static Word16 ic_bwe_enc_gsMapping_ivas_fx( temp2_fx = extract_l( L_shr( temp2_fx32, Q10 ) ); // Q15 gsMapping_fx16 = 0; move16(); - idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMapping_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); // Q12 + idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMapping_tbl_fx, ( 1 << STEREO_ICBWE_GSBITS ) ); // Q12 // idx = squant_fx( temp2, gsMapping, icbwe_gsMapping_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); } ELSE @@ -397,13 +397,13 @@ static Word16 ic_bwe_enc_gsMapping_ivas_fx( temp2_fx = extract_l( L_shr( temp2_fx32, Q10 ) ); // Q15 gsMapping_fx16 = 0; move16(); - idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMappingDFT_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); // Q12 + idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMappingDFT_tbl_fx, ( 1 << STEREO_ICBWE_GSBITS ) ); // Q12 } *gsMapping_fx = L_deposit_h( gsMapping_fx16 ); // Q28 move32(); Word16 e; L_mult = Mult_32_16( *gsMapping_fx, 27213 /*=log2(10)*2^13*/ ); // Q27 + Q13 - Q15 -> Q26 - *gsMapping_fx = BASOP_util_Pow2( L_mult, 5, &e ); + *gsMapping_fx = BASOP_util_Pow2( L_mult, 5, &e ); /* Q31-e */ move32(); *gsMapping_e = e; // Q31 @@ -420,7 +420,7 @@ static void icbwe_dft_stereo_param_ivas_fx( STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: */ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i : */ Encoder_State *st, /* i/o: */ - Word32 *shb_synth_nonref_fx, /* i/o: */ + Word32 *shb_synth_nonref_fx, /* i/o: Q31-shb_synth_nonref_e*/ Word16 shb_synth_nonref_e /* i/o: */ ) { @@ -465,6 +465,9 @@ static void icbwe_dft_stereo_param_ivas_fx( sum_nrg_L_fx = sum_32_fx( hStereoICBWE->mem_nrg_L_fx, 2, &sum_nrg_L_e ); // hStereoICBWE->mem_nrg_L_fx_e sum_nrg_R_fx = sum_32_fx( hStereoICBWE->mem_nrg_R_fx, 2, &sum_nrg_R_e ); // hStereoICBWE->mem_nrg_R_fx_e sum_nrg_DMX_fx = sum_32_fx( hStereoICBWE->mem_nrg_DMX_fx, 2, &sum_nrg_DMX_e ); // hStereoICBWE->mem_nrg_DMX_fx_e + move16(); + move16(); + move16(); /* refChanIndex_bwe refinement */ @@ -487,7 +490,7 @@ static void icbwe_dft_stereo_param_ivas_fx( slopeILD_fx = 0; move32(); - spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); /* Q0 */ test(); test(); @@ -499,26 +502,26 @@ static void icbwe_dft_stereo_param_ivas_fx( Word32 L_tmp, L_tmp1; L_tmp = Mpy_32_32( hStereoICBWE->mem_nrg_L_fx[1], hStereoICBWE->mem_nrg_R_fx[0] ); // hStereoICBWE->mem_nrg_L_fx_e[1] + hStereoICBWE->mem_nrg_R_fx_e[1] L_tmp1 = Mpy_32_32( hStereoICBWE->mem_nrg_R_fx[1], hStereoICBWE->mem_nrg_L_fx[0] ); // hStereoICBWE->mem_nrg_L_fx_e[1] + hStereoICBWE->mem_nrg_R_fx_e[1] - tmp1 = BASOP_Util_Divide3232_Scale( L_tmp, L_tmp1, &exp1 ); + tmp1 = BASOP_Util_Divide3232_Scale( L_tmp, L_tmp1, &exp1 ); /* Q15-exp1 */ exp1 = add( exp1, sub( add( hStereoICBWE->mem_nrg_L_fx_e, hStereoICBWE->mem_nrg_R_fx_e ), add( hStereoICBWE->mem_nrg_L_fx_e, hStereoICBWE->mem_nrg_R_fx_e ) ) ); L_tmp = BASOP_Util_Log10( L_deposit_h( tmp1 ), exp1 ); L_tmp = Mpy_32_32( normFac_fx, L_tmp ); // // Q25 + Q29 - Q31 -> Q23 slopeILD_fx = extract_l( L_shr( L_tmp, 16 ) ); // Q23 - Q16 -> Q7 IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - slopeILD_fx = negate( slopeILD_fx ); + slopeILD_fx = negate( slopeILD_fx ); /* Q7 */ } ELSE { - slopeILD_fx = slopeILD_fx; + slopeILD_fx = slopeILD_fx; /* Q7 */ move16(); } - spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); /* Q0 */ IF( Mpy_32_32( spec_table_fx[spIndx], hStereoICBWE->prevSpecMapping_fx ) < 0 ) { slopeILD_fx = 0; move32(); - spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); /* Q0 */ } hStereoICBWE->prevSpecMapping_fx = spec_table_fx[spIndx]; // q31 @@ -538,16 +541,16 @@ static void icbwe_dft_stereo_param_ivas_fx( Word16 exp; IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_R_fx, sum_nrg_DMX_fx, &exp ); + gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_R_fx, sum_nrg_DMX_fx, &exp ); /* Q15-exp */ exp = add( exp, sub( sum_nrg_R_e, sum_nrg_DMX_e ) ); } ELSE { - gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_L_fx, sum_nrg_DMX_fx, &exp ); + gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_L_fx, sum_nrg_DMX_fx, &exp ); /* Q15-exp */ exp = add( exp, sub( sum_nrg_L_e, sum_nrg_DMX_e ) ); } - gDes_fx = Sqrt16( gDes_fx, &exp ); + gDes_fx = Sqrt16( gDes_fx, &exp ); /* Q15-exp */ Word16 exp1 = hStereoICBWE->gDes_pastFrame_e, exp2, tmp; Word32 tmp321 = 0, tmp322 = 0; move32(); @@ -556,16 +559,16 @@ static void icbwe_dft_stereo_param_ivas_fx( tmp321 = Sqrt32( hStereoICBWE->gDes_pastFrame_fx, &exp1 ); // exp1 exp2 = exp; move16(); - tmp = Sqrt16( gDes_fx, &exp2 ); + tmp = Sqrt16( gDes_fx, &exp2 ); /* Q15-exp2 */ tmp322 = Mpy_32_32( tmp321, L_deposit_h( tmp ) ); // exp1 + exp2 hStereoICBWE->gDes_pastFrame_fx = tmp322; hStereoICBWE->gDes_pastFrame_e = add( exp1, exp2 ); move32(); move16(); - gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); + gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ - hStereoICBWE->gDes_pastFrame_fx = L_deposit_h( gDes_fx ); + hStereoICBWE->gDes_pastFrame_fx = L_deposit_h( gDes_fx ); /* Q31-exp */ hStereoICBWE->gDes_pastFrame_e = exp; move32(); move16(); @@ -584,9 +587,9 @@ static void icbwe_dft_stereo_param_ivas_fx( void stereo_icBWE_enc_ivas_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel */ + const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel Q31-shb_speech_ref_e*/ const Word16 shb_speech_ref_e, /* i : SHB speech ref channel */ - Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel */ + Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel Q31-shb_speech_nonref_e*/ Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ const Word32 *voice_factors_fx /* i : voicing factors Q31 */ ) @@ -689,7 +692,7 @@ void stereo_icBWE_enc_ivas_fx( shb_synth_nonref_e = max_e; move16(); - Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); + Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); /* shb_speech_ref_e */ Copy_Scale_sig_32_16( shb_frame_ref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) - Q16 ); // mem_shb_speech_ref_e test(); @@ -724,7 +727,7 @@ void stereo_icBWE_enc_ivas_fx( { temp1_fx = 0; temp1_e = 0; - temp2_fx = ONE_IN_Q31; + temp2_fx = ONE_IN_Q31; /* Q31 */ temp2_e = 0; move16(); move32(); @@ -735,16 +738,16 @@ void stereo_icBWE_enc_ivas_fx( { temp1_e = 0, temp2_e = 0; move16(); - move32(); + move16(); temp1_fx = Sqrt32( nlMixFac_fx[i], &temp1_e ); - temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); + temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); /* Q31-temp2_e */ } - tmp = BASOP_Util_Divide1616_Scale( L_FRAME16k, nbSubFr, &exp ); - tmp = shr( tmp, sub( Q15, exp ) ); + tmp = BASOP_Util_Divide1616_Scale( L_FRAME16k, nbSubFr, &exp ); /* Q15-exp */ + tmp = shr( tmp, sub( Q15, exp ) ); /* Q0 */ FOR( j = 0; j < tmp; ( j++, k++ ) ) { - excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), add( temp1_e, hStereoICBWE->nlExc16k_e ), Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), add( temp2_e, hStereoICBWE->mixExc16k_e ), &exp_buf[k] ) ); + excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), add( temp1_e, hStereoICBWE->nlExc16k_e ), Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), add( temp2_e, hStereoICBWE->mixExc16k_e ), &exp_buf[k] ) ); /* Q31-exp_buf */ move32(); } } @@ -762,7 +765,7 @@ void stereo_icBWE_enc_ivas_fx( FOR( j = 0; j < L_FRAME16k; j++ ) { - excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); + excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); /* Q31-max_e */ move32(); } /* LP synthesis */ @@ -770,8 +773,8 @@ void stereo_icBWE_enc_ivas_fx( Word32 lpSHBRef_fx32[LPC_SHB_ORDER + 1]; - Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); - Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); + Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); /* Q31-tmp_e */ + Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); /* Q31-tmp_e */ // set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); E_UTIL_synthesis_fx( 0, lpSHBRef_fx32, excSHB_nonref_fx, shb_synth_nonref_fx, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); @@ -782,10 +785,10 @@ void stereo_icBWE_enc_ivas_fx( } ELSE { - Copy_Scale_sig_32_16( shb_frame_ref_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k, -16 ); // max_e + Copy_Scale_sig_32_16( shb_frame_ref_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k, -16 ); /* Q15-shb_frame_ref_e */ hStereoICBWE->shbSynthRef_e = shb_frame_ref_e; move16(); - Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); // max_e + Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); /* Q31-shb_frame_ref_e */ shb_synth_nonref_e = shb_frame_ref_e; move16(); set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, 10 ); @@ -810,7 +813,7 @@ void stereo_icBWE_enc_ivas_fx( move16(); /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ - Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); + Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); /* Q31-max_e */ Copy_Scale_sig_32_16( shb_frame_ref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e set32_fx( shb_frame_nonref_fx, 0, L_LOOK_16k + L_FRAME16k ); @@ -826,7 +829,7 @@ void stereo_icBWE_enc_ivas_fx( move16(); /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ - Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); + Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); /* Q31-max_e */ Copy_Scale_sig_32_16( shb_frame_nonref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e @@ -871,14 +874,14 @@ void stereo_icBWE_enc_ivas_fx( move32(); move32(); L_tmp = sum2_32_fx( shb_frame_nonref_fx + sub( L_LOOK_16k, refMemLen ), L_FRAME16k, &temp1_e ); - temp1_fx = Sqrt32( L_tmp, &temp1_e ); + temp1_fx = Sqrt32( L_tmp, &temp1_e ); /* Q31-temp1_e */ /*temp1 = 0.8f*hStereoICBWE->prevNonRefEner + 0.2f*temp1;*/ /*temp2 = 0.8f*hStereoICBWE->prevRefEner + 0.2f*temp2;*/ IF( temp2_fx == 0 ) { - gDes_fx = 1073741824; + gDes_fx = 1073741824; /* 1.0 in Q30 */ gDes_e = 1; move16(); move32(); @@ -894,8 +897,8 @@ void stereo_icBWE_enc_ivas_fx( exp = hStereoICBWE->gDes_pastFrame_e; move16(); move16(); - L_tmp = Sqrt32( gDes_fx, &tmp ); - L_tmp1 = Sqrt32( hStereoICBWE->gDes_pastFrame_fx, &exp ); + L_tmp = Sqrt32( gDes_fx, &tmp ); /* Q31-tmp */ + L_tmp1 = Sqrt32( hStereoICBWE->gDes_pastFrame_fx, &exp ); /* Q31-exp */ hStereoICBWE->gDes_pastFrame_fx = Mpy_32_32( L_tmp, L_tmp1 ); // tmp + exp hStereoICBWE->gDes_pastFrame_e = add( tmp, exp ); @@ -918,9 +921,9 @@ void stereo_icBWE_enc_ivas_fx( Copy32( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); // Q31 test(); - IF( LT_32( gTarget_fx, 268435456 ) || GT_32( gTarget_fx, 1073741824 ) ) // + IF( LT_32( gTarget_fx, 268435456 ) || GT_32( gTarget_fx, 1073741824 ) ) // 0.5 in Q29 & 2.0 in Q29 { - v_multc_fixed( voice_factors_fx, 1073741824, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed( voice_factors_fx, 1073741824 /*0.5 in Q31*/, nlMixFac_fx, NB_SUBFR16k ); /* Q31 */ } IF( st->flag_ACELP16k == 0 ) @@ -944,7 +947,7 @@ void stereo_icBWE_enc_ivas_fx( temp1_fx = 0; temp1_e = 0; - temp2_fx = ONE_IN_Q31; + temp2_fx = ONE_IN_Q31; /* Q31 */ temp2_e = 0; move32(); move32(); @@ -954,15 +957,15 @@ void stereo_icBWE_enc_ivas_fx( ELSE { temp1_e = 0, temp2_e = 0; - temp1_fx = Sqrt32( nlMixFac_fx[i], &temp1_e ); - temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); + temp1_fx = Sqrt32( nlMixFac_fx[i], &temp1_e ); /* Q31-temp1_e */ + temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); /* Q31 */ move32(); move16(); } FOR( j = 0; j < ( L_FRAME16k / nbSubFr ); ( j++, k++ ) ) { - excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), temp1_e + hStereoICBWE->nlExc16k_e, Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), temp2_e + hStereoICBWE->mixExc16k_e, &exp_buf[k] ) ); + excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), temp1_e + hStereoICBWE->nlExc16k_e, Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), temp2_e + hStereoICBWE->mixExc16k_e, &exp_buf[k] ) ); /* Q31-exp_buf */ move32(); } } @@ -980,7 +983,7 @@ void stereo_icBWE_enc_ivas_fx( FOR( j = 0; j < L_FRAME16k; j++ ) { - excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); + excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); /* Q31-max_e */ move32(); } /* LP synthesis */ @@ -989,8 +992,8 @@ void stereo_icBWE_enc_ivas_fx( Word32 lpSHBRef_fx32[LPC_SHB_ORDER + 1]; - Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); - Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); + Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); /* Q31-tmp_e */ + Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); /* Q31-tmp_e */ E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); shb_synth_nonref_e = sub( 31, tmp_e ); @@ -1002,7 +1005,7 @@ void stereo_icBWE_enc_ivas_fx( Copy_Scale_sig_32_16( shb_frame_ref_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k, -16 ); // max_e hStereoICBWE->shbSynthRef_e = shb_frame_ref_e; move16(); - Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); + Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); /* Q31-shb_synth_nonref_e */ shb_synth_nonref_e = shb_frame_ref_e; move16(); set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, 10 ); @@ -1014,7 +1017,7 @@ void stereo_icBWE_enc_ivas_fx( IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { /* IC BWE spectral mapping */ - spIndx = ic_bwe_enc_specMapping_ivas_fx( shb_frame_nonref_fx, shb_frame_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, &( hStereoICBWE->prevSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_fx ), hStereoICBWE->memShbSpecXcorr_fx, &( hStereoICBWE->memShbSpecXcorr_e ) ); + spIndx = ic_bwe_enc_specMapping_ivas_fx( shb_frame_nonref_fx, shb_frame_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, &( hStereoICBWE->prevSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_fx ), hStereoICBWE->memShbSpecXcorr_fx, &( hStereoICBWE->memShbSpecXcorr_e ) ); /* Q0 */ } ELSE { @@ -1038,9 +1041,9 @@ void stereo_icBWE_enc_ivas_fx( /* IC BWE GS mapping */ - gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); + gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ - hStereoICBWE->gDes_pastFrame_fx = gDes_fx; + hStereoICBWE->gDes_pastFrame_fx = gDes_fx; /* Q31-hStereoICBWE->gDes_pastFrame_e */ hStereoICBWE->gDes_pastFrame_e = gDes_e; move32(); move16(); @@ -1048,7 +1051,7 @@ void stereo_icBWE_enc_ivas_fx( } /* IC-BWE updates */ - hStereoICBWE->prev_refChanIndx_bwe = hStereoICBWE->refChanIndx_bwe; + hStereoICBWE->prev_refChanIndx_bwe = hStereoICBWE->refChanIndx_bwe; /* Q0 */ move16(); return; @@ -1152,19 +1155,19 @@ void stereo_icBWE_init_enc_fx( * Inter-channel BWE pre-proc of the non-ref channel *-------------------------------------------------------------------*/ static void findRefChanBWE_fx( - const Word16 *input0_fx, /* i/o : input 0 Qx */ - const Word16 *input1_fx, /* i/o : input 1 Qx */ - Word16 *refChanIndx_bwe, /* o : Ref Channel Index bwe */ - const Word16 input_frame, /* i : input 0 & 1 frame length */ - Word16 *mem0_fx, /* i/o : mem 0 for input 0 Qx */ - Word16 *mem1_fx /* i/o : mem 1 for input 1 Qx */ + const Word16 *input0_fx, /* i/o : input 0 Qx q_dataChan_fx*/ + const Word16 *input1_fx, /* i/o : input 1 Qx q_dataChan_fx*/ + Word16 *refChanIndx_bwe, /* o : Ref Channel Index bwe Q0*/ + const Word16 input_frame, /* i : input 0 & 1 frame length Q0*/ + Word16 *mem0_fx, /* i/o : mem 0 for input 0 Qx q_dataChan_fx*/ + Word16 *mem1_fx /* i/o : mem 1 for input 1 Qx q_dataChan_fx*/ ) { Word16 inp0_fx[L_FRAME48k], inp1_fx[L_FRAME48k]; Word32 tempF_fx, tempF1_fx; - Copy( input0_fx, inp0_fx, input_frame ); - Copy( input1_fx, inp1_fx, input_frame ); + Copy( input0_fx, inp0_fx, input_frame ); /* q_dataChan_fx */ + Copy( input1_fx, inp1_fx, input_frame ); /* q_dataChan_fx */ spectral_balancer_fx16( inp0_fx, mem0_fx, input_frame, 1 ); spectral_balancer_fx16( inp1_fx, mem1_fx, input_frame, 1 ); @@ -1174,12 +1177,12 @@ static void findRefChanBWE_fx( IF( LT_32( tempF1_fx, Mpy_32_32( 1374389535 /* 0.64f Q31 */, tempF_fx ) ) ) { - *refChanIndx_bwe = L_CH_INDX; + *refChanIndx_bwe = L_CH_INDX; /* Q0 */ move16(); } ELSE IF( LT_32( tempF_fx, Mpy_32_32( 1374389535 /* 0.64f Q31 */, tempF1_fx ) ) ) { - *refChanIndx_bwe = R_CH_INDX; + *refChanIndx_bwe = R_CH_INDX; /* Q0 */ move16(); } @@ -1194,8 +1197,8 @@ static void findRefChanBWE_fx( *-------------------------------------------------------------------*/ void stereo_icBWE_preproc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word16 input_frame, /* i : input frame length */ - Word16 shb_speech_nonref_fx[], /* o : SHB speech non-ref channel */ + const Word16 input_frame, /* i : input frame length Q0*/ + Word16 shb_speech_nonref_fx[], /* o : SHB speech non-ref channel q_shb_speech_nonref_fx*/ Word16 q_shb_speech_nonref_fx /* i : Q SHB speech non-ref channel */ ) { @@ -1238,11 +1241,11 @@ void stereo_icBWE_preproc_fx( IF( GE_16( hCPE->element_mode, IVAS_CPE_DFT ) && GE_32( input_Fs, 32000 ) ) { set16_fx( temp_inp_fx, 0, L_FRAME48k ); - Copy( hStereoICBWE->dataChan_fx[0], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); + Copy( hStereoICBWE->dataChan_fx[0], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); /* q_dataChan_fx */ IF( EQ_32( input_Fs, 48000 ) ) { - Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); + Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); /* q_dataChan_fx */ set16_fx( temp_inp_fx, 0, L_FRAME48k ); i = 2 * L_FILT48k + L_FILT_2OVER3; move16(); @@ -1252,17 +1255,17 @@ void stereo_icBWE_preproc_fx( /* flip the spectrum */ FOR( i = 0; i < L_FRAME32k; i += 2 ) { - temp_inp_fx[i] = negate( temp_inp_fx[i] ); + temp_inp_fx[i] = negate( temp_inp_fx[i] ); /* q_dataChan_fx */ move16(); } - Copy( temp_inp_fx + L_FRAME32k - 2 * L_FILT32k, hStereoICBWE->memModifyFs_icbwe_fx[0], 2 * L_FILT32k ); + Copy( temp_inp_fx + L_FRAME32k - 2 * L_FILT32k, hStereoICBWE->memModifyFs_icbwe_fx[0], 2 * L_FILT32k ); /* q_dataChan_fx */ set16_fx( temp_inp_fx, 0, L_FRAME48k ); - Copy( hStereoICBWE->dataChan_fx[1], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); + Copy( hStereoICBWE->dataChan_fx[1], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); /* q_dataChan_fx */ IF( EQ_32( input_Fs, 48000 ) ) { - Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); + Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); /* q_dataChan_fx */ set16_fx( temp_inp_fx, 0, L_FRAME48k ); i = 2 * L_FILT48k + L_FILT_2OVER3; move16(); @@ -1273,10 +1276,10 @@ void stereo_icBWE_preproc_fx( /* flip the spectrum */ FOR( i = 0; i < input_frame; i += 2 ) { - temp_inp_fx[i] = negate( temp_inp_fx[i] ); + temp_inp_fx[i] = negate( temp_inp_fx[i] ); /* q_dataChan_fx */ move16(); } - Copy( temp_inp_fx + L_FRAME32k - 2 * L_FILT32k, hStereoICBWE->memModifyFs_icbwe_fx[1], 2 * L_FILT32k ); + Copy( temp_inp_fx + L_FRAME32k - 2 * L_FILT32k, hStereoICBWE->memModifyFs_icbwe_fx[1], 2 * L_FILT32k ); /* q_dataChan_fx */ } return; @@ -1285,10 +1288,10 @@ void stereo_icBWE_preproc_fx( IF( NE_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* initial estimate of refChanIndx_bwe */ - gD_fx = hStereoTCA->targetGain_fx; + gD_fx = hStereoTCA->targetGain_fx; /* Q29 */ move32(); - refChanIndx_bwe = hStereoTCA->refChanIndx; + refChanIndx_bwe = hStereoTCA->refChanIndx; /* Q0 */ move16(); test(); test(); @@ -1298,7 +1301,7 @@ void stereo_icBWE_preproc_fx( refChanIndx_bwe = !( hStereoTCA->refChanIndx ); move16(); } - hStereoICBWE->refChanIndx_bwe = refChanIndx_bwe; + hStereoICBWE->refChanIndx_bwe = refChanIndx_bwe; /* Q0 */ move16(); set16_fx( hStereoICBWE->dec_2over3_mem_fx, 0, L_FILT_2OVER3 ); @@ -1310,10 +1313,10 @@ void stereo_icBWE_preproc_fx( return; } - gD_fx = hStereoTCA->targetGain_fx; + gD_fx = hStereoTCA->targetGain_fx; /* Q29 */ move32(); - refChanIndx_bwe = hStereoTCA->refChanIndx; + refChanIndx_bwe = hStereoTCA->refChanIndx; /* Q0 */ move16(); test(); test(); @@ -1331,19 +1334,19 @@ void stereo_icBWE_preproc_fx( IF( EQ_16( refChanIndx_bwe, R_CH_INDX ) ) { - Copy( hStereoICBWE->icbwe_inp_mem_fx[0], temp_inp_fx, nonRefMemLen ); - Copy( hStereoICBWE->dataChan_fx[0], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); + Copy( hStereoICBWE->icbwe_inp_mem_fx[0], temp_inp_fx, nonRefMemLen ); /* q_dataChan_fx */ + Copy( hStereoICBWE->dataChan_fx[0], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); /* q_dataChan_fx */ } ELSE { - Copy( hStereoICBWE->icbwe_inp_mem_fx[1], temp_inp_fx, nonRefMemLen ); - Copy( hStereoICBWE->dataChan_fx[1], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); + Copy( hStereoICBWE->icbwe_inp_mem_fx[1], temp_inp_fx, nonRefMemLen ); /* q_dataChan_fx */ + Copy( hStereoICBWE->dataChan_fx[1], temp_inp_fx + nonRefMemLen, sub( input_frame, nonRefMemLen ) ); /* q_dataChan_fx */ } IF( EQ_32( input_Fs, 48000 ) ) { /*printf("\n Non-ref target HB generation for 48 kHz sample rate needs alignment verification \n");*/ - Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); + Copy( temp_inp_fx, temp_in_fx, L_FRAME48k ); /* q_dataChan_fx */ set16_fx( temp_inp_fx, 0, L_FRAME48k ); decimate_2_over_3_allpass_fx( temp_in_fx, L_FRAME48k, temp_inp_fx, hStereoICBWE->dec_2over3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hStereoICBWE->dec_2over3_mem_lp_fx ); @@ -1352,25 +1355,25 @@ void stereo_icBWE_preproc_fx( /* flip the spectrum */ FOR( i = 0; i < input_frame; i += 2 ) { - temp_inp_fx[i] = negate( temp_inp_fx[i] ); + temp_inp_fx[i] = negate( temp_inp_fx[i] ); /* q_dataChan_fx */ move16(); } test(); test(); test(); - IF( GE_16( hCPE->element_mode, IVAS_CPE_DFT ) && GE_32( input_Fs, 32000 ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_extl, -1 ) ) ) + IF( GE_16( hCPE->element_mode, IVAS_CPE_DFT ) && GE_32( input_Fs, 32000 ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_extl, -1 ) ) ) { - Copy_Scale_sig( hStereoICBWE->memModifyFs_icbwe_fx[!refChanIndx_bwe], hStereoICBWE->mem_decim_shb_ch0_fx, 2 * L_FILT32k, sub( 0, hStereoICBWE->q_dataChan_fx ) ); + Copy_Scale_sig( hStereoICBWE->memModifyFs_icbwe_fx[!refChanIndx_bwe], hStereoICBWE->mem_decim_shb_ch0_fx, 2 * L_FILT32k, sub( 0, hStereoICBWE->q_dataChan_fx ) ); /* Q0 */ } Word16 Q_new_inp, mem_decim_size; - Scale_sig( temp_inp_fx, L_FRAME48k, sub( 0, hStereoICBWE->q_dataChan_fx ) ); + Scale_sig( temp_inp_fx, L_FRAME48k, sub( 0, hStereoICBWE->q_dataChan_fx ) ); /* q_dataChan_fx */ /* IVAS-219: Re-wire the shb nonref estimation through a lite CLDFB */ modify_Fs_fx( temp_inp_fx, L_FRAME32k, 32000, tempSHB_fx, 16000, hStereoICBWE->mem_decim_shb_ch0_fx, 0, &Q_new_inp, &mem_decim_size ); - Copy_Scale_sig( tempSHB_fx, shb_speech_nonref_fx, L_FRAME16k, sub( q_shb_speech_nonref_fx, Q_new_inp ) ); + Copy_Scale_sig( tempSHB_fx, shb_speech_nonref_fx, L_FRAME16k, sub( q_shb_speech_nonref_fx, Q_new_inp ) ); /* q_shb_speech_nonref_fx */ return; } diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 123b2615905547e3fb23f1144414bc3145d03e35..bf549609691c58aad9cecdd70589c7863bf23bae 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -49,17 +49,17 @@ * Synchronize under certain conditions the tcx modes and set overlap * windows accordingly *-------------------------------------------------------------------*/ -static void sync_tcx_mode( +static void sync_tcx_mode_fx( Encoder_State **st /* i/o: Encoder state */ ) { - const Word32 prevAccNrg0 = st[0]->hTranDet->subblockEnergies.accSubblockNrg[st[0]->hTranDet->subblockEnergies.nDelay]; + const Word32 prevAccNrg0 = st[0]->hTranDet->subblockEnergies.accSubblockNrg[st[0]->hTranDet->subblockEnergies.nDelay]; /* Q0 */ move32(); - const Word32 prevAccNrg1 = st[1]->hTranDet->subblockEnergies.accSubblockNrg[st[1]->hTranDet->subblockEnergies.nDelay]; + const Word32 prevAccNrg1 = st[1]->hTranDet->subblockEnergies.accSubblockNrg[st[1]->hTranDet->subblockEnergies.nDelay]; /* Q0 */ move32(); - const Word32 lastAccNrg0 = st[0]->hTranDet->subblockEnergies.accSubblockNrg[add( st[0]->hTranDet->subblockEnergies.nDelay, st[0]->hTranDet->transientDetector.nSubblocksToCheck )]; + const Word32 lastAccNrg0 = st[0]->hTranDet->subblockEnergies.accSubblockNrg[( st[0]->hTranDet->subblockEnergies.nDelay + st[0]->hTranDet->transientDetector.nSubblocksToCheck )]; /* Q0 */ move32(); - const Word32 lastAccNrg1 = st[1]->hTranDet->subblockEnergies.accSubblockNrg[add( st[1]->hTranDet->subblockEnergies.nDelay, st[1]->hTranDet->transientDetector.nSubblocksToCheck )]; + const Word32 lastAccNrg1 = st[1]->hTranDet->subblockEnergies.accSubblockNrg[( st[1]->hTranDet->subblockEnergies.nDelay + st[1]->hTranDet->transientDetector.nSubblocksToCheck )]; /* Q0 */ move32(); test(); @@ -84,8 +84,8 @@ static void sync_tcx_mode( test(); test(); test(); - IF( GT_32( prevAccNrg0, Mpy_32_16_1( prevAccNrg1, 1311 ) ) && GT_32( prevAccNrg1, Mpy_32_16_1( prevAccNrg0, 1311 ) ) /* 14 dB */ - && GT_32( lastAccNrg0, Mpy_32_16_1( lastAccNrg1, 2048 ) ) && GT_32( lastAccNrg1, Mpy_32_16_1( lastAccNrg0, 2048 ) ) ) /* 12 dB */ + IF( GT_32( prevAccNrg0, Mpy_32_16_1( prevAccNrg1, 1311 /*1/25 in Q15*/ ) ) && GT_32( prevAccNrg1, Mpy_32_16_1( prevAccNrg0, 1311 /*1/25 in Q15*/ ) ) /* 14 dB */ + && GT_32( lastAccNrg0, Mpy_32_16_1( lastAccNrg1, 2048 /*1/12 in Q15*/ ) ) && GT_32( lastAccNrg1, Mpy_32_16_1( lastAccNrg0, 2048 /*1/12 in Q15*/ ) ) ) /* 12 dB */ { st[0]->hTcxEnc->tcxMode = st[1]->hTcxEnc->tcxMode = s_max( st[0]->hTcxEnc->tcxMode, st[1]->hTcxEnc->tcxMode ); /* synchronize TCX mode of both channels */ move16(); @@ -130,9 +130,9 @@ static void sync_tcx_mode( *-------------------------------------------------------------------*/ void stereo_mdct_core_enc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples */ - Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP */ - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe */ + Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples Q0*/ + Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP Qx*/ + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe Q6*/ ) { Word32 orig_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* MDCT output (L/R). */ @@ -209,11 +209,11 @@ void stereo_mdct_core_enc_fx( Word16 tmp_e = 0; move16(); Word32 L_tmp; - L_tmp = Sqrt32( L_add( L_shr( Mpy_32_32( sts[0]->hTcxEnc->tfm_mem_fx, sts[0]->hTcxEnc->tfm_mem_fx ), 1 ), L_shr( Mpy_32_32( sts[1]->hTcxEnc->tfm_mem_fx, sts[1]->hTcxEnc->tfm_mem_fx ), 1 ) ), &tmp_e ); /* RMS */ + L_tmp = Sqrt32( L_add( L_shr( Mpy_32_32( sts[0]->hTcxEnc->tfm_mem_fx, sts[0]->hTcxEnc->tfm_mem_fx ), 1 ), L_shr( Mpy_32_32( sts[1]->hTcxEnc->tfm_mem_fx, sts[1]->hTcxEnc->tfm_mem_fx ), 1 ) ), &tmp_e ); /* RMS Q31-tmp_e*/ sts[0]->hTcxEnc->tfm_mem_fx = sts[1]->hTcxEnc->tfm_mem_fx = L_shl( L_tmp, tmp_e ); /* Q31 */ move32(); move32(); - sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = extract_l( L_shr( L_add( sts[0]->hTcxEnc->tcxltp_norm_corr_past, sts[1]->hTcxEnc->tcxltp_norm_corr_past ), 1 ) ); + sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = extract_l( L_shr( L_add( sts[0]->hTcxEnc->tcxltp_norm_corr_past, sts[1]->hTcxEnc->tcxltp_norm_corr_past ), 1 ) ); /* Q15 */ move16(); move16(); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -229,7 +229,7 @@ void stereo_mdct_core_enc_fx( EQ_16( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ) || EQ_16( add( sts[0]->hTcxCfg->tcx_last_overlap_mode, sts[1]->hTcxCfg->tcx_last_overlap_mode ), extract_l( 5 ) ) ) ) /* disable syncing for stereo switching or large diff in last frame overlap */ { - sync_tcx_mode( sts ); + sync_tcx_mode_fx( sts ); } IF( hCPE->hCoreCoder[0]->igf ) { @@ -270,8 +270,8 @@ void stereo_mdct_core_enc_fx( sts[ch]->hTcxEnc->tns_ms_flag[1] = 0; move16(); - Scale_sig( sts[ch]->input_fx, (Word16) ( sts[ch]->input_Fs / 50 ) + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), negate( sts[ch]->q_inp ) ); - Scale_sig( sts[ch]->old_input_signal_fx, (Word16) ( sts[ch]->input_Fs / 50 ), negate( sts[ch]->q_old_inp ) ); + Scale_sig( sts[ch]->input_fx, add( extract_l( Mpy_32_32( sts[ch]->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( sts[ch]->q_inp ) ); /* Q0 */ + Scale_sig( sts[ch]->old_input_signal_fx, extract_l( Mpy_32_32( sts[ch]->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), negate( sts[ch]->q_old_inp ) ); /* Q0 */ sts[ch]->q_old_inp = 0; move16(); sts[ch]->q_inp = 0; @@ -303,8 +303,8 @@ void stereo_mdct_core_enc_fx( IF( EQ_16( nSubframes, NB_DIV ) ) { Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] ); - Scale_sig32( orig_spectrum_fx[i][0], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); - Scale_sig32( orig_spectrum_fx[i][1], N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); + Scale_sig32( orig_spectrum_fx[i][0], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); /* Q31-max_e */ + Scale_sig32( orig_spectrum_fx[i][1], N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); /* Q31-max_e */ p_orig_spectrum_e[i] = max_e; move16(); } @@ -328,19 +328,19 @@ void stereo_mdct_core_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { - st->side_bits_frame_channel = add( st->side_bits_frame_channel, NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + st->side_bits_frame_channel = add( st->side_bits_frame_channel, NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); /* Q0 */ move16(); } } - sts[0]->side_bits_frame_channel = add( sts[0]->side_bits_frame_channel, SMDCT_NBBITS_SPLIT_RATIO ); + sts[0]->side_bits_frame_channel = add( sts[0]->side_bits_frame_channel, SMDCT_NBBITS_SPLIT_RATIO ); /* Q0 */ move16(); /*--------------------------------------------------------------* * Stereo Processing *---------------------------------------------------------------*/ - - if ( !hStereoMdct->isSBAStereoMode ) + test(); + IF( !hStereoMdct->isSBAStereoMode ) { /* Common q for mdst_spectrum and spectrum */ Word16 k; @@ -365,13 +365,13 @@ void stereo_mdct_core_enc_fx( n_sb = 1; move16(); } - length = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); + length = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); /* Q0 */ FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) { - Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[k], length, sub( q_spec, sub( Q31, sts[ch]->hTcxEnc->spectrum_e[k] ) ) ); + Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[k], length, sub( q_spec, sub( Q31, sts[ch]->hTcxEnc->spectrum_e[k] ) ) ); /* q_spec */ sts[ch]->hTcxEnc->spectrum_e[k] = sub( Q31, q_spec ); - Scale_sig32( mdst_spectrum_fx[ch][k], length, sub( q_spec, sub( Q31, mdst_spectrum_e[ch][k] ) ) ); + Scale_sig32( mdst_spectrum_fx[ch][k], length, sub( q_spec, sub( Q31, mdst_spectrum_e[ch][k] ) ) ); /* q_spec */ mdst_spectrum_e[ch][k] = sub( Q31, q_spec ); } } @@ -388,7 +388,7 @@ void stereo_mdct_core_enc_fx( IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { nSubframes = 1; - L_subframeTCX = sts[ch]->hTcxEnc->L_frameTCX; + L_subframeTCX = sts[ch]->hTcxEnc->L_frameTCX; /* Q0 */ move16(); move16(); } @@ -396,13 +396,13 @@ void stereo_mdct_core_enc_fx( { nSubframes = NB_DIV; move16(); - L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); + L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); /* Q0 */ } /* in MCT only relevant for bitrate switching from non-MCT bitrates */ IF( EQ_16( sts[ch]->last_core, ACELP_CORE ) ) { - L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); /* Q0 */ } FOR( n = 0; n < nSubframes; n++ ) @@ -414,18 +414,18 @@ void stereo_mdct_core_enc_fx( /* power spectrum: MDCT^2 + MDST^2 */ FOR( i = 0; i < L_subframeTCX; i++ ) { - W_tmp = W_mac_32_32( W_mult_32_32( mdst_spectrum_fx[ch][n][i], mdst_spectrum_fx[ch][n][i] ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); + W_tmp = W_mac_32_32( W_mult_32_32( mdst_spectrum_fx[ch][n][i], mdst_spectrum_fx[ch][n][i] ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_powSpec[( i + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); - W_tmp = W_mac_32_32( W_mult_32_32( inv_mdst_spectrum_fx[ch][n][i], inv_mdst_spectrum_fx[ch][n][i] ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); + W_tmp = W_mac_32_32( W_mult_32_32( inv_mdst_spectrum_fx[ch][n][i], inv_mdst_spectrum_fx[ch][n][i] ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); @@ -436,62 +436,62 @@ void stereo_mdct_core_enc_fx( IF( NE_16( hStereoMdct->mdct_stereo_mode[n], SMDCT_DUAL_MONO ) ) { /* power spectrum: MDCT^2 + MDST^2 */ - W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] ); + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_psi[n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); FOR( i = 1; i < L_subframeTCX - 1; i++ ) { - Word32 mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); /* An MDST estimate */ + Word32 mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); /* An MDST estimate q_spec*/ - W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } - W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] ); + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_psi[n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } /* power spectrum: MDCT^2 + MDST^2 */ - W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][0], sts[ch]->hTcxEnc->spectrum_fx[n][0] ); + W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][0], sts[ch]->hTcxEnc->spectrum_fx[n][0] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][n * L_subframeTCX] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpec_fx[ch][n * L_subframeTCX] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_powSpec[n * L_subframeTCX] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); FOR( i = 1; i < L_subframeTCX - 1; i++ ) { - Word32 mdst_fx = L_sub( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], sts[ch]->hTcxEnc->spectrum_fx[n][i - 1] ); /* An MDST estimate */ + Word32 mdst_fx = L_sub( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], sts[ch]->hTcxEnc->spectrum_fx[n][i - 1] ); /* An MDST estimate q_spec*/ - W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), sts[ch]->hTcxEnc->spectrum_fx[n][i], sts[ch]->hTcxEnc->spectrum_fx[n][i] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_powSpec[( i + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); } - W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1], sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1] ); + W_tmp = W_mult_32_32( sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1], sts[ch]->hTcxEnc->spectrum_fx[n][L_subframeTCX - 1] ); /* 2*q_spec+1 */ tmp_s = sub( W_norm( W_tmp ), 1 ); - W_tmp = W_shl( W_tmp, tmp_s ); - powerSpec_fx[ch][( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); + W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ + powerSpec_fx[ch][( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ tmp_q_powSpec[( ( L_subframeTCX - 1 ) + ( n * L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 move32(); move16(); @@ -522,8 +522,8 @@ void stereo_mdct_core_enc_fx( { FOR( i = 0; i < L_subframeTCX; i++ ) { - powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powSpec[ch] ) ); - powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) ); + powerSpecMsInv_fx[ch][n][i] = L_shr( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_powSpec[ch] ) ); /* q_powSpec */ + powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )] = L_shr( powerSpec_fx[ch][( i + ( n * L_subframeTCX ) )], sub( tmp_q_powSpec[i], q_powSpec[ch] ) ); /* q_powSpec */ move32(); move32(); } @@ -545,11 +545,11 @@ void stereo_mdct_core_enc_fx( nSubframes = NB_DIV; move16(); } - L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); + L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); /* Q0 */ IF( st->last_core == ACELP_CORE ) { - L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); /* Q0 */ } test(); test(); @@ -564,7 +564,7 @@ void stereo_mdct_core_enc_fx( NE_32( imult3216( st->last_sr_core, st->L_frame ), imult3216( st->sr_core, st->L_frame_past ) ) || NE_16( st->last_core, TCX_20_CORE ), st->hTcxEnc->memQuantZeros, L_subframeTCX ); } - st->hTcxEnc->measuredBwRatio = ONE_IN_Q14; /* No bandwidth limit for the noise filling */ + st->hTcxEnc->measuredBwRatio = ONE_IN_Q14; /* No bandwidth limit for the noise filling Q14*/ move16(); } @@ -586,7 +586,7 @@ void stereo_mdct_core_enc_fx( nSubframes = 1; move16(); } - L_subframeTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); + L_subframeTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); /* Q0 */ FOR( n = 0; n < nSubframes; n++ ) { test(); @@ -609,18 +609,18 @@ void stereo_mdct_core_enc_fx( n_sb = 1; move16(); } - length = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); + length = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); /* Q0 */ IF( GT_16( q_spec, q_powSpec[ch] ) ) { - Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[n], length, sub( q_powSpec[ch], q_spec ) ); - Scale_sig32( inv_spectrum_fx[ch][n], length, sub( q_powSpec[ch], q_spec ) ); + Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[n], length, sub( q_powSpec[ch], q_spec ) ); /* q_powSpec */ + Scale_sig32( inv_spectrum_fx[ch][n], length, sub( q_powSpec[ch], q_spec ) ); /* q_powSpec */ sts[ch]->hTcxEnc->spectrum_e[n] = sub( Q31, q_powSpec[ch] ); move16(); } ELSE { - Scale_sig32( &p_powerSpec_fx[ch][0], L_subframeTCX, sub( q_spec, q_powSpec[ch] ) ); - Scale_sig32( powerSpecMsInv_fx[ch][0], L_subframeTCX, sub( q_spec, q_powSpec[ch] ) ); + Scale_sig32( &p_powerSpec_fx[ch][0], L_subframeTCX, sub( q_spec, q_powSpec[ch] ) ); /* q_spec */ + Scale_sig32( powerSpecMsInv_fx[ch][0], L_subframeTCX, sub( q_spec, q_powSpec[ch] ) ); /* q_spec */ } } hIGFEnc[0]->spec_be_igf_e = p_orig_spectrum_e[0]; @@ -641,14 +641,14 @@ void stereo_mdct_core_enc_fx( { st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } - L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); + L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); /* Q0 */ Word16 q_spectrum; q_spectrum = sub( Q31, p_orig_spectrum_e[ch] ); IF( st->hIGFEnc ) { q_spectrum = s_min( q_spectrum, sub( Q31, st->hIGFEnc->spec_be_igf_e ) ); } - Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); + Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ q_spectrum = sub( Q31, st->hTcxEnc->spectrum_e[n] ); ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powSpec[ch], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); @@ -681,13 +681,13 @@ void stereo_mdct_core_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { Word16 q_spectrum; - L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); + L_subframeTCX = idiv1616( st->hTcxEnc->L_frameTCX, nSubframes ); /* Q0 */ q_spectrum = sub( Q31, p_orig_spectrum_e[ch] ); IF( st->hIGFEnc ) { q_spectrum = s_min( q_spectrum, sub( Q31, st->hIGFEnc->spec_be_igf_e ) ); } - Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); + Scale_sig32( orig_spectrum_fx[ch][n], N_TCX10_MAX, sub( q_spectrum, sub( Q31, p_orig_spectrum_e[ch] ) ) ); /* q_spectrum */ q_spectrum = sub( Q31, st->hTcxEnc->spectrum_e[n] ); ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powSpec[ch], st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); @@ -709,7 +709,7 @@ void stereo_mdct_core_enc_fx( move16(); IF( !hStereoMdct->isSBAStereoMode ) { - stereo_bits = write_stereo_to_bitstream( hStereoMdct, sts, ms_mask, 0, hBstr ); + stereo_bits = write_stereo_to_bitstream_fx( hStereoMdct, sts, ms_mask, 0, hBstr ); /* Q0 */ } ELSE { @@ -731,11 +731,11 @@ void stereo_mdct_core_enc_fx( n_sb = 1; move16(); } - L_subframeTCX = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); + L_subframeTCX = idiv1616( sts[ch]->hTcxEnc->L_frameTCX, n_sb ); /* Q0 */ FOR( n = 0; n <= ( ( sts[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ) - 1; n++ ) { q_com = L_norm_arr( sts[ch]->hTcxEnc->spectrum_fx[n], L_subframeTCX ); - Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[n], L_subframeTCX, q_com ); + Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[n], L_subframeTCX, q_com ); /* Q31 - sts[ch]->hTcxEnc->spectrum_e + q_com */ sts[ch]->hTcxEnc->spectrum_e[n] = sub( sts[ch]->hTcxEnc->spectrum_e[n], q_com ); } } @@ -760,7 +760,7 @@ void stereo_mdct_core_enc_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - sts[ch]->total_brate = imult3216( L_deposit_l( add( sts[ch]->bits_frame_channel, sts[ch]->side_bits_frame_channel ) ), FRAMES_PER_SEC ); + sts[ch]->total_brate = imult3216( L_deposit_l( add( sts[ch]->bits_frame_channel, sts[ch]->side_bits_frame_channel ) ), FRAMES_PER_SEC ); /* Q0 */ move32(); } stereo_bits = add( stereo_bits, SMDCT_NBBITS_SPLIT_RATIO ); diff --git a/lib_enc/ivas_stereo_mdct_igf_enc.c b/lib_enc/ivas_stereo_mdct_igf_enc.c index c200a748caf06abb39b9164a83d085cd4ea0f4c8..190255fd9be4f9e4b839cfdf2dc91f3f421be480 100644 --- a/lib_enc/ivas_stereo_mdct_igf_enc.c +++ b/lib_enc/ivas_stereo_mdct_igf_enc.c @@ -64,10 +64,10 @@ static Word16 calcCoh_fx( // Q15 const Word32 *sig1_fx, // Q( q_sig ) const Word32 *sig2_fx, // Q( q_sig ) const Word16 q_sig, - const Word16 nSamples, - Word32 *corr, + const Word16 nSamples, /* Q0 */ + Word32 *corr, /* Q31-corr_e */ Word16 *corr_e, - Word16 *predCoeff, + Word16 *predCoeff, /* Q31-predCoeff_e */ Word16 *predCoeff_e ) { Word32 ener1_fx, ener2_fx, cEner_fx, cc_fx; @@ -82,13 +82,13 @@ static Word16 calcCoh_fx( // Q15 move16(); q_cc = q_ener1; move16(); - ener1_fx = dotp_fixed_o( sig1_fx, sig1_fx, nSamples, gB, &q_ener1 ); - ener2_fx = dotp_fixed_o( sig2_fx, sig2_fx, nSamples, gB, &q_ener2 ); - cEner_fx = Mpy_32_32( ener1_fx, ener2_fx ); + ener1_fx = dotp_fixed_o( sig1_fx, sig1_fx, nSamples, gB, &q_ener1 ); /* q_ener1 */ + ener2_fx = dotp_fixed_o( sig2_fx, sig2_fx, nSamples, gB, &q_ener2 ); /* q_ener2 */ + cEner_fx = Mpy_32_32( ener1_fx, ener2_fx ); /* q_ener1+q_ener2-31 */ q_cEner = sub( 62, add( q_ener1, q_ener2 ) ); - cEner_fx = Sqrt32( cEner_fx, &q_cEner ); + cEner_fx = Sqrt32( cEner_fx, &q_cEner ); /* Q31-q_cEner */ q_cEner = sub( Q31, q_cEner ); - cc_fx = dotp_fixed_o( sig1_fx, sig2_fx, nSamples, gB, &q_cc ); + cc_fx = dotp_fixed_o( sig1_fx, sig2_fx, nSamples, gB, &q_cc ); /* q_cc */ IF( corr != NULL ) { @@ -100,7 +100,7 @@ static Word16 calcCoh_fx( // Q15 IF( cEner_fx > 0 ) { - coh_fx = BASOP_Util_Divide3232_Scale( cc_fx, cEner_fx, &coh_e ); + coh_fx = BASOP_Util_Divide3232_Scale( cc_fx, cEner_fx, &coh_e ); /* Q15-coh_e */ coh_e = add( coh_e, sub( q_cEner, q_cc ) ); coh_fx = shl_sat( coh_fx, coh_e ); // Q15 } @@ -111,7 +111,7 @@ static Word16 calcCoh_fx( // Q15 move32(); IF( ener1_fx > 0 ) { - *predCoeff = BASOP_Util_Divide3232_Scale( cc_fx, ener1_fx, predCoeff_e ); + *predCoeff = BASOP_Util_Divide3232_Scale( cc_fx, ener1_fx, predCoeff_e ); /* Q31-predCoeff_e */ move32(); *predCoeff_e = add( *predCoeff_e, sub( q_ener1, q_cc ) ); move16(); @@ -131,12 +131,12 @@ static Word16 calcCoh_fx( // Q15 static void IGF_MsStereoDecision_fx( STEREO_MDCT_BAND_PARAMETERS *sfbParam, H_IGF_GRID hGrid, - const Word32 *specL_fx, - const Word32 *specR_fx, + const Word32 *specL_fx, /* q_spec */ + const Word32 *specR_fx, /* q_spec */ Word16 q_spec, - Word16 *igfStereoMode, /* output*/ - Word16 *msMask, /* output*/ - const Word16 mdct_stereo_mode ) + Word16 *igfStereoMode, /* output Q0*/ + Word16 *msMask, /* output Q0*/ + const Word16 mdct_stereo_mode /* Q0 */ ) { Word16 sfb; Word16 msMaskTrueSomewhere, msMaskFalseSomewhere; @@ -150,18 +150,18 @@ static void IGF_MsStereoDecision_fx( if ( EQ_16( mdct_stereo_mode, SMDCT_MS_FULL ) ) { - thresh = 13762; /* lower threshold if core is already MS */ + thresh = 13762; /* lower threshold if core is already MS TARGET_COH_THRESHOLD_FX*(0.7 in Q15)*/ move16(); } FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { - strt_cpy = hGrid->sbWrap[tile_idx]; + strt_cpy = hGrid->sbWrap[tile_idx]; /* Q0 */ move16(); FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { - Word16 width = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); + Word16 width = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); /* Q0 */ Word32 cc_src_fx, cc_target_fx; Word16 cc_src_e, cc_target_e; Word16 pc_target_fx, pc_src_fx; @@ -177,10 +177,10 @@ static void IGF_MsStereoDecision_fx( Word16 coh_src = calcCoh_fx( &specL_fx[strt_cpy], &specR_fx[strt_cpy], q_spec, width, &cc_src_fx, &cc_src_e, &pc_src_fx, &pc_src_e ); Word16 coh_target = calcCoh_fx( &specL_fx[hGrid->swb_offset[sfb]], &specR_fx[hGrid->swb_offset[sfb]], q_spec, width, &cc_target_fx, &cc_target_e, &pc_target_fx, &pc_target_e ); - tmp1_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, negate( pc_src_fx ), pc_src_e, &tmp1 ); - tmp2_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, -16384, 1, &tmp2 ); + tmp1_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, negate( pc_src_fx ), pc_src_e, &tmp1 ); /* Q15-tmp1_e */ + tmp2_e = BASOP_Util_Add_MantExp( pc_target_fx, pc_target_e, -16384, 1, &tmp2 ); /* Q15-tmp2_e */ - strt_cpy = add( strt_cpy, width ); + strt_cpy = add( strt_cpy, width ); /* Q0 */ IF( GT_16( abs_s( coh_target ), thresh ) ) { /* target is very coherent */ @@ -236,14 +236,14 @@ static void IGF_MsStereoDecision_fx( case IGF_PATCH_LR: msMask[sfb] = 0; move16(); - numMsMaskFalse = add( numMsMaskFalse, 1 ); + numMsMaskFalse = add( numMsMaskFalse, 1 ); /* Q0 */ msMaskFalseSomewhere = 1; move16(); break; case IGF_PATCH_MS: msMask[sfb] = 1; move16(); - numMsMaskTrue = add( numMsMaskTrue, 1 ); + numMsMaskTrue = add( numMsMaskTrue, 1 ); /* Q0 */ msMaskTrueSomewhere = 1; move16(); break; @@ -302,14 +302,14 @@ static void IGF_MsStereoDecision_fx( void IGFEncStereoEncoder_fx( STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel */ const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : IGF handle */ - const Word32 *mdctSpectrumL_fx, /* i : left spectrum */ - const Word32 *mdctSpectrumR_fx, /* i : right spectrum */ + const Word32 *mdctSpectrumL_fx, /* i : left spectrum q_mdctSpectrum*/ + const Word32 *mdctSpectrumR_fx, /* i : right spectrum q_mdctSpectrum*/ Word16 q_mdctSpectrum, - Word16 *msMask, /* i/o: MS mask */ - Word16 *igfStereoMode, /* o : IGF stereo mode */ - const Word16 mdct_stereo_mode, /* i : MDCT stereo mode */ - const Word16 isTCX20, /* i : flag for indicating TCX20 */ - const Word16 isTransition /* i : flag for transtition */ + Word16 *msMask, /* i/o: MS mask Q0*/ + Word16 *igfStereoMode, /* o : IGF stereo mode Q0*/ + const Word16 mdct_stereo_mode, /* i : MDCT stereo mode Q0*/ + const Word16 isTCX20, /* i : flag for indicating TCX20 Q0*/ + const Word16 isTransition /* i : flag for transtition Q0*/ ) { Word16 igfGridIdx; diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index b69883930fbdca711d76911d6d5aef4cfc62c2a5..b0a5f85c4ae41f72696ab498d3f4a5c708a6fe64 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -77,7 +77,7 @@ static void MsStereoDecision_fx( STEREO_MDCT_BAND_PARAMETERS *sfbParam, Word32 * static void dft_ana_init_fx( DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ - const Word32 input_Fs /*i : Input sampling frequency */ + const Word32 input_Fs /*i : Input sampling frequency Q0*/ ) { hDft_ana->N = extract_l( Mpy_32_16_1( input_Fs, 656 /* STEREO_DFT_HOP_MAX_ENC / 48000 in Q15 */ ) ); @@ -89,29 +89,29 @@ static void dft_ana_init_fx( hDft_ana->dft_zp = extract_l( Mpy_32_16_1( input_Fs, 185 /* STEREO_DFT_ZP_MAX_ENC / 48000 in Q15 */ ) ); move16(); - hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; /* Q15 */ IF( EQ_32( input_Fs, 16000 ) ) { - hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; move16(); - hDft_ana->win_ana_fx = win_ana_16k_fx; + hDft_ana->win_ana_fx = win_ana_16k_fx; /* Q15 */ } ELSE IF( EQ_32( input_Fs, 32000 ) ) { - hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; /* Q15 */ hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; move16(); - hDft_ana->win_ana_fx = win_ana_32k_fx; + hDft_ana->win_ana_fx = win_ana_32k_fx; /* Q15 */ } ELSE { assert( input_Fs == 48000 ); - hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; + hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; /* Q15 */ hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; move16(); - hDft_ana->win_ana_fx = win_ana_48k_fx; + hDft_ana->win_ana_fx = win_ana_48k_fx; /* Q15 */ } return; @@ -139,7 +139,7 @@ static void write_itd_data_fx( IF( hItd->itd_fx[k_offset] != 0 ) { - itd = hItd->itd_index[k_offset]; + itd = hItd->itd_index[k_offset]; /* Q0 */ IF( GT_16( itd, 255 ) ) { itd = sub( itd, 256 ); @@ -184,14 +184,14 @@ static void write_itd_data_fx( void stereo_coder_tcx_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: encoder state structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) - const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ Word16 q_spec ) { STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; @@ -208,7 +208,7 @@ void stereo_coder_tcx_fx( set16_fx( nAvailBitsMS, 0, NB_DIV ); nSubframes = ( sts[0]->core == TCX_20_CORE && sts[1]->core == TCX_20_CORE ) ? 1 : NB_DIV; - L_frameTCX = sts[0]->hTcxEnc->L_frameTCX / nSubframes; + L_frameTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); set16_fx( &ms_mask[0][0], 0, MAX_SFB ); set16_fx( &ms_mask[1][0], 0, MAX_SFB ); @@ -224,7 +224,7 @@ void stereo_coder_tcx_fx( hStereoMdct->global_ild[k] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, round_fx( L_mult( SMDCT_ILD_RANGE, nonQNrgRatio_fx[k] ) ) ) ); move16(); - nrgRatio_fx[k] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[k] ), hStereoMdct->global_ild[k], &nrgRatio_e[k] ) ); + nrgRatio_fx[k] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[k] ), hStereoMdct->global_ild[k], &nrgRatio_e[k] ) ); /* Q31-nrgRatio_e[k] */ move32(); /*nonQNrgRatio[k] = max( 0.5f / SMDCT_ILD_RANGE, min( ( SMDCT_ILD_RANGE - 0.5f ) / SMDCT_ILD_RANGE, nonQNrgRatio[k] ) ); nonQNrgRatio[k] = 1.0f / nonQNrgRatio[k] - 1.0f;*/ @@ -233,11 +233,11 @@ void stereo_coder_tcx_fx( } ELSE { - nonQNrgRatio_fx[0] = nonQNrgRatio_fx[1] = GetChannelEnergyRatio_fx( sts, 0, nSubframes - 1, 1 ); + nonQNrgRatio_fx[0] = nonQNrgRatio_fx[1] = GetChannelEnergyRatio_fx( sts, 0, nSubframes - 1, 1 ); /* Q15 */ move16(); hStereoMdct->global_ild[0] = s_max( 1, s_min( SMDCT_ILD_RANGE - 1, round_fx( L_mult( SMDCT_ILD_RANGE, nonQNrgRatio_fx[0] ) ) ) ); move16(); - nrgRatio_fx[0] = nrgRatio_fx[1] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[0] ), hStereoMdct->global_ild[0], &nrgRatio_e[0] ) ); /* nrgRatio = nrg[1]/nrg[0] */ + nrgRatio_fx[0] = nrgRatio_fx[1] = L_deposit_h( BASOP_Util_Divide1616_Scale( sub( SMDCT_ILD_RANGE, hStereoMdct->global_ild[0] ), hStereoMdct->global_ild[0], &nrgRatio_e[0] ) ); /* nrgRatio = nrg[1]/nrg[0] (Q31-nrgRatio_e[0])*/ move32(); nrgRatio_e[1] = nrgRatio_e[0]; move16(); @@ -250,24 +250,24 @@ void stereo_coder_tcx_fx( { IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[k], nrgRatio_e[k], ONE_IN_Q27, 4 ), 1 ) && LT_16( k, ( EQ_16( sts[1]->core, TCX_20_CORE ) ? 1 : NB_DIV ) ) ) { - L_frameTCX = add( sts[1]->hTcxEnc->L_frameTCX, ( ( sts[1]->last_core == 0 ) ? shr( sts[1]->hTcxEnc->L_frameTCX, 2 ) : 0 ) ); - L_frameTCX = idiv1616( L_frameTCX, ( sts[1]->core == TCX_20_CORE ) ? 1 : NB_DIV ); + L_frameTCX = add( sts[1]->hTcxEnc->L_frameTCX, ( ( sts[1]->last_core == 0 ) ? shr( sts[1]->hTcxEnc->L_frameTCX, 2 ) : 0 ) ); /* Q0 */ + L_frameTCX = idiv1616( L_frameTCX, ( sts[1]->core == TCX_20_CORE ) ? 1 : NB_DIV ); /* Q0 */ e_tmp = nrgRatio_e[k]; - tmp = Inv16( extract_h( nrgRatio_fx[k] ), &e_tmp ); - tmp = shl( tmp, e_tmp ); + tmp = Inv16( extract_h( nrgRatio_fx[k] ), &e_tmp ); /* Q15-e_tmp */ + tmp = shl( tmp, e_tmp ); /* Q15 */ - v_multc_fixed_16( sts[1]->hTcxEnc->spectrum_fx[k], tmp, sts[1]->hTcxEnc->spectrum_fx[k], L_frameTCX ); - v_multc_fixed_16( mdst_spectrum_fx[1][k], tmp, mdst_spectrum_fx[1][k], L_frameTCX ); + v_multc_fixed_16( sts[1]->hTcxEnc->spectrum_fx[k], tmp, sts[1]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* Q31-spectrum_e[k] */ + v_multc_fixed_16( mdst_spectrum_fx[1][k], tmp, mdst_spectrum_fx[1][k], L_frameTCX ); /* q_spec */ } ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[k], nrgRatio_e[k], ONE_IN_Q27, 4 ), -1 ) && LT_16( k, EQ_16( sts[0]->core, TCX_20_CORE ) ? 1 : NB_DIV ) ) { - L_frameTCX = add( sts[0]->hTcxEnc->L_frameTCX, EQ_16( sts[0]->last_core, 0 ) ? shr( sts[0]->hTcxEnc->L_frameTCX, 2 ) : 0 ); - L_frameTCX = idiv1616( L_frameTCX, ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV ); + L_frameTCX = add( sts[0]->hTcxEnc->L_frameTCX, EQ_16( sts[0]->last_core, 0 ) ? shr( sts[0]->hTcxEnc->L_frameTCX, 2 ) : 0 ); /* Q0 */ + L_frameTCX = idiv1616( L_frameTCX, ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV ); /* Q0 */ /* This operation is resulting in some high MLDs in fixed point. */ - v_multc_fixed_16( sts[0]->hTcxEnc->spectrum_fx[k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), sts[0]->hTcxEnc->spectrum_fx[k], L_frameTCX ); - v_multc_fixed_16( mdst_spectrum_fx[0][k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), mdst_spectrum_fx[0][k], L_frameTCX ); + v_multc_fixed_16( sts[0]->hTcxEnc->spectrum_fx[k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), sts[0]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* Q31-spectrum_e[k] */ + v_multc_fixed_16( mdst_spectrum_fx[0][k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), mdst_spectrum_fx[0][k], L_frameTCX ); /* q_spec */ } } } @@ -352,9 +352,9 @@ void stereo_coder_tcx_fx( FOR( sfb--; sfb < sfbConf->nBandsStereoCore; sfb++ ) /* start one SFB early for the fade-in */ { - const Word16 startLine = sfbConf->sfbOffset[sfb]; + const Word16 startLine = sfbConf->sfbOffset[sfb]; /* Q0 */ move16(); - const Word16 endLine = sfbConf->sfbOffset[sfb + 1]; + const Word16 endLine = sfbConf->sfbOffset[sfb + 1]; /* Q0 */ move16(); const Word16 sfbWidth = sub( endLine, startLine ); @@ -362,9 +362,9 @@ void stereo_coder_tcx_fx( move16(); move16(); - nrgRatio_fx[0] = sum2_32_fx( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[0] ); + nrgRatio_fx[0] = sum2_32_fx( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ move32(); - nrgRatio_fx[1] = sum2_32_fx( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[1] ); + nrgRatio_fx[1] = sum2_32_fx( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ move32(); test(); @@ -373,29 +373,29 @@ void stereo_coder_tcx_fx( Word32 tmp_fx; Word16 tmp_e; tmp_e = sub( Q31, q_spec ); - tmp_fx = sum2_32_fx( &mdst_spectrum_fx[0][k][startLine], sfbWidth, &tmp_e ); - nrgRatio_fx[0] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], tmp_fx, tmp_e, &nrgRatio_e[0] ); + tmp_fx = sum2_32_fx( &mdst_spectrum_fx[0][k][startLine], sfbWidth, &tmp_e ); /* Q31-tmp_e */ + nrgRatio_fx[0] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], tmp_fx, tmp_e, &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ tmp_e = sub( Q31, q_spec ); - tmp_fx = sum2_32_fx( &mdst_spectrum_fx[1][k][startLine], sfbWidth, &tmp_e ); - nrgRatio_fx[1] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[1], nrgRatio_e[1], tmp_fx, tmp_e, &nrgRatio_e[1] ); + tmp_fx = sum2_32_fx( &mdst_spectrum_fx[1][k][startLine], sfbWidth, &tmp_e ); /* Q31-tmp_e */ + nrgRatio_fx[1] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[1], nrgRatio_e[1], tmp_fx, tmp_e, &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ } IF( ( nrgRatio_fx[0] > 0 ) && ( nrgRatio_fx[1] > 0 ) && BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], nrgRatio_fx[1], nrgRatio_e[1] ) ) { Word16 fTemp_e, tmp_e; - Word32 fTemp_fx = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], nrgRatio_fx[1], nrgRatio_e[1], &fTemp_e ); + Word32 fTemp_fx = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], nrgRatio_fx[1], nrgRatio_e[1], &fTemp_e ); /* Q31-fTemp_e */ fTemp_e = sub( fTemp_e, 1 ); - nrgRatio_fx[0] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[0], &tmp_e ); + nrgRatio_fx[0] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[0], &tmp_e ); /* Q31 - tmp_e - fTemp_e + nrgRatio_e[0] */ move32(); nrgRatio_e[0] = add( tmp_e, sub( fTemp_e, nrgRatio_e[0] ) ); move16(); - nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); + nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ move32(); - nrgRatio_fx[1] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[1], &tmp_e ); + nrgRatio_fx[1] = BASOP_Util_Divide3232_Scale_cadence( fTemp_fx, nrgRatio_fx[1], &tmp_e ); /* Q31 - tmp_e - fTemp_e + nrgRatio_e[1] */ move32(); nrgRatio_e[1] = add( tmp_e, sub( fTemp_e, nrgRatio_e[1] ) ); move16(); - nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); + nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ move32(); nrgRatio_fx[0] = L_max( ONE_IN_Q27, L_shl_sat( nrgRatio_fx[0], sub( nrgRatio_e[0], 2 ) ) ); // max( 0.25f, min( 4.f, nrgRatio[0] ) ); @@ -409,16 +409,16 @@ void stereo_coder_tcx_fx( IF( ( LT_16( sfbWidth, 12 ) && LT_16( add( sfb, 1 ), sfbConf->nBandsStereoCore ) ) || GT_32( sts[0]->element_brate, IVAS_48k ) ) /* attenuate ILD alignment in the first SFB or at 64k */ { - nrgRatio_fx[0] = BASOP_Util_fPow( nrgRatio_fx[0], nrgRatio_e[0], ONE_IN_Q29, 0, &nrgRatio_e[0] ); + nrgRatio_fx[0] = BASOP_Util_fPow( nrgRatio_fx[0], nrgRatio_e[0], ONE_IN_Q29, 0, &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ move32(); - nrgRatio_fx[1] = BASOP_Util_fPow( nrgRatio_fx[1], nrgRatio_e[1], ONE_IN_Q29, 0, &nrgRatio_e[1] ); + nrgRatio_fx[1] = BASOP_Util_fPow( nrgRatio_fx[1], nrgRatio_e[1], ONE_IN_Q29, 0, &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ move32(); } ELSE { - nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); + nrgRatio_fx[0] = Sqrt32( nrgRatio_fx[0], &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ move32(); - nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); + nrgRatio_fx[1] = Sqrt32( nrgRatio_fx[1], &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ move32(); } @@ -428,15 +428,15 @@ void stereo_coder_tcx_fx( move32(); - v_multc_fixed( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[0], &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); - v_multc_fixed( &mdst_spectrum_fx[0][k][startLine], nrgRatio_fx[0], &mdst_spectrum_fx[0][k][startLine], sfbWidth ); - scale_sig32( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec - scale_sig32( &mdst_spectrum_fx[0][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + v_multc_fixed( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[0], &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* q_spec+30-31 */ + v_multc_fixed( &mdst_spectrum_fx[0][k][startLine], nrgRatio_fx[0], &mdst_spectrum_fx[0][k][startLine], sfbWidth ); /* q_spec+30-31 */ + scale_sig32( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + scale_sig32( &mdst_spectrum_fx[0][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec - v_multc_fixed( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[1], &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); - v_multc_fixed( &mdst_spectrum_fx[1][k][startLine], nrgRatio_fx[1], &mdst_spectrum_fx[1][k][startLine], sfbWidth ); - scale_sig32( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec - scale_sig32( &mdst_spectrum_fx[1][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + v_multc_fixed( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[1], &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* q_spec+30-31 */ + v_multc_fixed( &mdst_spectrum_fx[1][k][startLine], nrgRatio_fx[1], &mdst_spectrum_fx[1][k][startLine], sfbWidth ); /* q_spec+30-31 */ + scale_sig32( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + scale_sig32( &mdst_spectrum_fx[1][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec } } } @@ -445,30 +445,30 @@ void stereo_coder_tcx_fx( set16_fx( &ms_mask[k][0], 0, MAX_SFB ); IF( mct_on ) { - nAvailBitsMS[k] = shl( sts[0]->bits_frame_channel, 1 ); + nAvailBitsMS[k] = shl( sts[0]->bits_frame_channel, 1 ); /* Q0 */ move16(); } ELSE { - nAvailBitsMS[k] = sts[0]->bits_frame_nominal; + nAvailBitsMS[k] = sts[0]->bits_frame_nominal; /* Q0 */ move16(); } - nAvailBitsMS[k] = sub( nAvailBitsMS[k], add( sts[0]->side_bits_frame_channel, sts[1]->side_bits_frame_channel ) ); + nAvailBitsMS[k] = sub( nAvailBitsMS[k], add( sts[0]->side_bits_frame_channel, sts[1]->side_bits_frame_channel ) ); /* Q0 */ move16(); IF( EQ_16( nSubframes, 2 ) ) { - nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX10 ); + nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX10 ); /* Q0 */ move16(); } ELSE { - nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX20 ); + nAvailBitsMS[k] = sub( nAvailBitsMS[k], OFFSET_BITS_TCX20 ); /* Q0 */ move16(); } - nAvailBitsMS[k] = idiv1616( nAvailBitsMS[k], nSubframes ); + nAvailBitsMS[k] = idiv1616( nAvailBitsMS[k], nSubframes ); /* Q0 */ move16(); MsStereoDecision_fx( sfbConf, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], inv_spectrum_fx[0][k], inv_spectrum_fx[1][k], q_spec, &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); @@ -512,21 +512,21 @@ void stereo_coder_tcx_fx( FOR( k = 0; k < nSubframes; k++ ) { sfbConf = EQ_16( sts[0]->core, TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; - ms_bands[k] = sum_s( ms_mask[k], sfbConf->nBandsStereoCore ); + ms_bands[k] = sum_s( ms_mask[k], sfbConf->nBandsStereoCore ); /* Q0 */ move16(); - sw_uncorr[k] = sub( 32767, div_s( ms_bands[k], sfbConf->nBandsStereoCore ) ); + sw_uncorr[k] = sub( 32767 /*Q15*/, div_s( ms_bands[k], sfbConf->nBandsStereoCore ) ); /* Q15 */ move16(); } IF( EQ_16( sts[0]->core, TCX_20_CORE ) ) { - sw_uncorr_mean = sw_uncorr[0]; + sw_uncorr_mean = sw_uncorr[0]; /* Q15 */ move16(); } ELSE { - sw_uncorr_mean = add( shr( sw_uncorr[0], 1 ), shr( sw_uncorr[1], 1 ) ); + sw_uncorr_mean = add( shr( sw_uncorr[0], 1 ), shr( sw_uncorr[1], 1 ) ); /* Q15 */ } - hStereoMdct->sw_uncorr = extract_l( GT_16( sw_uncorr_mean, 19661 ) ); + hStereoMdct->sw_uncorr = extract_l( GT_16( sw_uncorr_mean, 19661 /*0.6 in Q15*/ ) ); move16(); } @@ -543,13 +543,13 @@ void stereo_coder_tcx_fx( void ms_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t iSubframe, /* i : subframe number */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + const Word16 iSubframe, /* i : subframe number Q0*/ Word32 x_0_fx[], /* i/o: spectrum 1 */ // Q( q_x ) Word32 x_1_fx[], /* i/o: spectrum 1 */ // Q( q_x ) - Word16 maxSfb /* i : number of stereo frequency bands*/ + Word16 maxSfb /* i : number of stereo frequency bands Q0*/ ) { Word16 sfb; @@ -565,7 +565,7 @@ void ms_processing_fx( if ( EQ_16( maxSfb, -1 ) ) { - maxSfb = sfbConf->sfbCnt; + maxSfb = sfbConf->sfbCnt; /* Q0 */ move16(); } @@ -589,8 +589,8 @@ void ms_processing_fx( void ms_inv_mask_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const Word16 iSubframe, /* i : subframe number */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + const Word16 iSubframe, /* i : subframe number Q0*/ const Word32 x_0_fx[], /* i : spectrum 1 */ // Q( q_x ) const Word32 x_1_fx[], @@ -599,7 +599,7 @@ void ms_inv_mask_processing_fx( /* o : inverse spectrum 1 */ // Q( q_x ) Word32 x_inv_1_fx[], /* o : inverse spectrum 2 */ // Q( q_x ) - Word16 maxSfb /* i : number of stereo frequency bands*/ + Word16 maxSfb /* i : number of stereo frequency bands Q0*/ ) { Word16 sfb; @@ -607,7 +607,7 @@ void ms_inv_mask_processing_fx( Word16 nSubframes, L_subframeTCX; nSubframes = ( sts[0]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - L_subframeTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); + L_subframeTCX = idiv1616( sts[0]->hTcxEnc->L_frameTCX, nSubframes ); /* Q0 */ sfbConf = ( sts[0]->core == TCX_20_CORE ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) @@ -618,14 +618,14 @@ void ms_inv_mask_processing_fx( IF( EQ_16( maxSfb, -1 ) ) { - maxSfb = sfbConf->sfbCnt; + maxSfb = sfbConf->sfbCnt; /* Q0 */ move16(); } FOR( sfb = 0; sfb < maxSfb; sfb++ ) { - Copy32( &x_0_fx[sfbConf->sfbOffset[sfb]], &x_inv_0_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); - Copy32( &x_1_fx[sfbConf->sfbOffset[sfb]], &x_inv_1_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + Copy32( &x_0_fx[sfbConf->sfbOffset[sfb]], &x_inv_0_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); /* q_x */ + Copy32( &x_1_fx[sfbConf->sfbOffset[sfb]], &x_inv_1_fx[sfbConf->sfbOffset[sfb]], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); /* q_x */ IF( EQ_16( ms_mask[iSubframe][sfb], 0 ) ) { @@ -650,12 +650,12 @@ void ms_inv_mask_processing_fx( * *-------------------------------------------------------------------*/ -Word16 write_stereo_to_bitstream( - STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ - Encoder_State **sts, /* i/o: Encoder state structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0)*/ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +Word16 write_stereo_to_bitstream_fx( + STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ + Encoder_State **sts, /* i/o: Encoder state structure */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ) { Word16 i, k, nSubframes; @@ -787,8 +787,8 @@ Word16 write_stereo_to_bitstream( *-------------------------------------------------------------------*/ static void convertToBwMS_fx( - const Word16 startLine, /* i : start line of sfb */ - const Word16 stopLine, /* i : stop line of sfb */ + const Word16 startLine, /* i : start line of sfb Q0*/ + const Word16 stopLine, /* i : stop line of sfb Q0*/ Word32 x0[], /* i/o: mid/left channel coefficients */ /* Q_x */ Word32 x1[], @@ -801,11 +801,11 @@ static void convertToBwMS_fx( FOR( j = startLine; j < stopLine; j++ ) { - tmpValue_fx = x0[j]; + tmpValue_fx = x0[j]; /*Q_x*/ move32(); - x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); + x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); /* Q_x */ move32(); - x1[j] = Mpy_32_32( L_sub( tmpValue_fx, x1[j] ), norm_fac ); + x1[j] = Mpy_32_32( L_sub( tmpValue_fx, x1[j] ), norm_fac ); /* Q_x */ move32(); } @@ -819,12 +819,10 @@ static void convertToBwMS_fx( *-------------------------------------------------------------------*/ void convertToMS_fx( - const Word16 L_frame, /* i : frame length */ - Word32 x0[], - /* i/o: mid/left channel coefficients */ // Q(q_x) - Word32 x1[], - /* i/o: side/right channel coefficients */ // Q(q_x) - const Word32 norm_fac /* i : normalization factor */ // Q31 + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Q(q_x)*/ + Word32 x1[], /* i/o: side/right channel coefficients Q(q_x)*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { convertToBwMS_fx( 0, L_frame, x0, x1, norm_fac ); @@ -840,14 +838,12 @@ void convertToMS_fx( /*! r: SQ gain */ static Word32 SQ_gain_estimate_stereo_fx( // e_res - Word32 xL_fx[], - /* i : L vector to quantize */ // e_xL + Word32 xL_fx[], /* i : L vector to quantize Q31-e_xL*/ Word16 e_xL, - Word32 xR_fx[], - /* i : R vector to quantize */ // e_xR + Word32 xR_fx[], /* i : R vector to quantize Q31-e_xR*/ Word16 e_xR, - const Word16 nbitsSQ, /* i : number of bits targeted */ - const Word16 lg, /* i : vector size (2048 max) */ + const Word16 nbitsSQ, /* i : number of bits targeted Q0*/ + const Word16 lg, /* i : vector size (2048 max) Q0*/ Word16 *e_res ) { Word16 i, q, iter, e_ener, e_tmp; @@ -855,24 +851,24 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res Word32 en_fx[N_MAX / 2]; // Q(26) Word16 lg2, lg_4, lg2_4; - lg_4 = shr( lg, 2 ); - lg2_4 = shl( lg_4, 1 ); - lg2 = shl( lg2_4, 2 ); + lg_4 = shr( lg, 2 ); /* Q0 */ + lg2_4 = shl( lg_4, 1 ); /* Q0 */ + lg2 = shl( lg2_4, 2 ); /* Q0 */ i = 0; move16(); - set32_fx( en_fx, 21474836 /* 0.01 in Q31 */, N_MAX / 2 ); + set32_fx( en_fx, 21474836 /* 0.01 in Q31 */, idiv1616( N_MAX, 2 ) ); /* energy of quadruples with 9dB offset */ /* ignore that we may take no all lines into account, max. 3 lines at the upper end of the spectrum can be missed (if lg is not a multiple of 4, happens also in SQGain()*/ FOR( q = 0; q < lg_4; q++ ) { - ener_fx = BASOP_Util_Add_Mant32Exp( 21474836, 0, Mpy_32_32( xL_fx[i], xL_fx[i] ), e_xL * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 1], xL_fx[i + 1] ), e_xL * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 2], xL_fx[i + 2] ), e_xL * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 3], xL_fx[i + 3] ), e_xL * 2, &e_ener ); - en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ + ener_fx = BASOP_Util_Add_Mant32Exp( 21474836 /*0.01 in Q15*/, 0, Mpy_32_32( xL_fx[i], xL_fx[i] ), e_xL * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 1], xL_fx[i + 1] ), e_xL * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 2], xL_fx[i + 2] ), e_xL * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xL_fx[i + 3], xL_fx[i + 3] ), e_xL * 2, &e_ener ); /* Q31-e_ener */ + en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ move32(); en_fx[q] = Mpy_32_16_1( L_add( e_ener * ONE_IN_Q25, en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) move32(); @@ -881,11 +877,11 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res i = 0; FOR( ; q < lg2_4; q++ ) { - ener_fx = BASOP_Util_Add_Mant32Exp( 21474836, 0, Mpy_32_32( xR_fx[i], xR_fx[i] ), e_xR * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 1], xR_fx[i + 1] ), e_xR * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 2], xR_fx[i + 2] ), e_xR * 2, &e_ener ); - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 3], xR_fx[i + 3] ), e_xR * 2, &e_ener ); - en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ + ener_fx = BASOP_Util_Add_Mant32Exp( 21474836 /*0.01 Q15*/, 0, Mpy_32_32( xR_fx[i], xR_fx[i] ), e_xR * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 1], xR_fx[i + 1] ), e_xR * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 2], xR_fx[i + 2] ), e_xR * 2, &e_ener ); /* Q31-e_ener */ + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, Mpy_32_32( xR_fx[i + 3], xR_fx[i + 3] ), e_xR * 2, &e_ener ); /* Q31-e_ener */ + en_fx[q] = BASOP_Util_Log2( ener_fx ); /* saves a MAC */ move32(); en_fx[q] = Mpy_32_16_1( L_add( e_ener * ONE_IN_Q25, en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) move32(); @@ -896,14 +892,14 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res target_fx = L_mult( 19660 /* 0.15 in Q17 */, sub( nbitsSQ, shr( lg2, 4 ) ) ); // Q(18) fac_fx = 429496729; /* 12.8 in Q25 */ move32(); - offset_fx = fac_fx; + offset_fx = fac_fx; /* Q25 */ move32(); /* find offset (0 to 128 dB with step of 0.125dB) */ FOR( iter = 0; iter < 10; iter++ ) { - fac_fx = L_shr( fac_fx, 1 ); - offset_fx = L_sub( offset_fx, fac_fx ); + fac_fx = L_shr( fac_fx, 1 ); /* Q25 */ + offset_fx = L_sub( offset_fx, fac_fx ); /* Q25 */ ener_fx = 0; move32(); e_ener = 0; @@ -911,19 +907,19 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res FOR( i = 0; i < lg2_4; i++ ) { - tmp_32 = L_sub( en_fx[i], offset_fx ); + tmp_32 = L_sub( en_fx[i], offset_fx ); /* Q25 */ e_tmp = 6; move16(); /* avoid SV with 1 bin of amp < 0.5f */ - IF( GT_32( tmp_32, 10066329 ) ) + IF( GT_32( tmp_32, 10066329 /*0.3 Q25*/ ) ) { - ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, tmp_32, e_tmp, &e_ener ); + ener_fx = BASOP_Util_Add_Mant32Exp( ener_fx, e_ener, tmp_32, e_tmp, &e_ener ); /* Q31-e_ener */ /* if ener is above target -> break and increase offset */ IF( L_shl_sat( ener_fx, sub( e_ener, Q13 ) ) > target_fx ) { - offset_fx = L_add( offset_fx, fac_fx ); + offset_fx = L_add( offset_fx, fac_fx ); /* Q25 */ BREAK; } } @@ -933,7 +929,7 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res /* return gain */ tmp_32 = L_add( 12539858, Mpy_32_16_1( offset_fx, 13606 ) ); // Q23 - return BASOP_util_Pow2( tmp_32, Q8, e_res ); + return BASOP_util_Pow2( tmp_32, Q8, e_res ); /* Q31-e_res */ } /*-------------------------------------------------------------------* @@ -943,23 +939,23 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res *-------------------------------------------------------------------*/ static Word16 QuantSpecEstimateBits_fx( - Word32 *spec_fx, + Word32 *spec_fx, /* Q15-spec_e */ Word16 spec_e, - Word16 G_fx, + Word16 G_fx, /* Q15-G_e */ Word16 G_e, - const Word16 length, - const Word16 nBitsAvailable, - Word16 sqQ[] ) + const Word16 length, /* Q0 */ + const Word16 nBitsAvailable, /* Q0 */ + Word16 sqQ[] /* Q0 */ ) { Word16 stop, sqBits, nEncoded; Word16 lastnz; - tcx_scalar_quantization_ivas_fx( spec_fx, spec_e, sqQ, length, G_fx, G_e, 16384, NULL, 1 ); + tcx_scalar_quantization_ivas_fx( spec_fx, spec_e, sqQ, length, G_fx, G_e, 16384 /*Q15*/, NULL, 1 ); stop = 0; move16(); - sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, length, &lastnz, &nEncoded, nBitsAvailable, &stop, 0, NULL ); + sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, length, &lastnz, &nEncoded, nBitsAvailable, &stop, 0, NULL ); /*Q0*/ if ( stop != 0 ) { @@ -976,15 +972,15 @@ static Word16 QuantSpecEstimateBits_fx( * *-------------------------------------------------------------------*/ -static void context_update( +static void context_update_fx( HANDLE_RC_CONTEXT_MEM ctxSrc, HANDLE_RC_CONTEXT_MEM ctxTarget, - const Word16 endLine ) + const Word16 endLine /*Q0*/ ) { Word16 last_nz; /* check if last_nz of target is smaller than endLine, save and update */ - last_nz = s_max( ctxTarget->lastnz, endLine ); + last_nz = s_max( ctxTarget->lastnz, endLine ); /* Q0 */ mvc2c( (UWord8 *) ctxSrc, (UWord8 *) ctxTarget, sizeof( RC_CONTEXT_MEM ) ); ctxTarget->lastnz = last_nz; @@ -1003,7 +999,7 @@ static Word16 GetChannelEnergyRatio_fx( // Q15 Encoder_State **sts, /* i/o: Encoder state structure */ const Word16 iFirstSubframe, const Word16 iLastSubframe, - const UWord8 ratioInRmsDomain ) + const UWord8 ratioInRmsDomain /* Q0 */ ) { Word16 ch, n, i; Word32 nrg_fx[2]; @@ -1023,11 +1019,11 @@ static Word16 GetChannelEnergyRatio_fx( // Q15 move16(); } - Word16 L_subframeTCX = shr( st->hTcxEnc->L_frameTCX, sub( nSubframes, 1 ) ); + Word16 L_subframeTCX = shr( st->hTcxEnc->L_frameTCX, sub( nSubframes, 1 ) ); /* Q0 */ if ( st->last_core == ACELP_CORE ) { - L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); + L_subframeTCX = add( L_subframeTCX, shr( L_subframeTCX, 2 ) ); /* Q0 */ } assert( iFirstSubframe >= 0 && ( iFirstSubframe <= iLastSubframe ) ); @@ -1040,28 +1036,28 @@ static Word16 GetChannelEnergyRatio_fx( // Q15 { FOR( i = 0; i < L_subframeTCX; i++ ) { - nrg_fx[ch] = BASOP_Util_Add_Mant32Exp( nrg_fx[ch], nrg_e[ch], Mpy_32_32( st->hTcxEnc->spectrum_fx[n][i], st->hTcxEnc->spectrum_fx[n][i] ), shl( st->hTcxEnc->spectrum_e[n], 1 ), &nrg_e[ch] ); + nrg_fx[ch] = BASOP_Util_Add_Mant32Exp( nrg_fx[ch], nrg_e[ch], Mpy_32_32( st->hTcxEnc->spectrum_fx[n][i], st->hTcxEnc->spectrum_fx[n][i] ), shl( st->hTcxEnc->spectrum_e[n], 1 ), &nrg_e[ch] ); /* Q31-nrg_e */ move32(); } } IF( ratioInRmsDomain && nrg_fx[ch] ) { - nrg_fx[ch] = Sqrt32( nrg_fx[ch], &nrg_e[ch] ); + nrg_fx[ch] = Sqrt32( nrg_fx[ch], &nrg_e[ch] ); /* Q31-nrg_e */ move32(); } } IF( L_add_sat( nrg_fx[0], nrg_fx[1] ) ) { - nrg_fx[1] = BASOP_Util_Add_Mant32Exp( nrg_fx[0], nrg_e[0], nrg_fx[1], nrg_e[1], &nrg_e[1] ); + nrg_fx[1] = BASOP_Util_Add_Mant32Exp( nrg_fx[0], nrg_e[0], nrg_fx[1], nrg_e[1], &nrg_e[1] ); /* Q31-nrg_e[1] */ move32(); IF( NE_16( nrg_e[1], nrg_e[0] ) ) { - nrg_fx[0] = L_shr( nrg_fx[0], sub( nrg_e[1], nrg_e[0] ) ); + nrg_fx[0] = L_shr( nrg_fx[0], sub( nrg_e[1], nrg_e[0] ) ); /* Q31-nrg_e[1] */ move32(); } - return divide3232( nrg_fx[0], nrg_fx[1] ); + return divide3232( nrg_fx[0], nrg_fx[1] ); /* Q15 */ } return MIN_16; @@ -1090,21 +1086,21 @@ void FindSplitRatio_fx( IF( ratio_fx >= 0 ) { - hCPE->hStereoMdct->split_ratio = round_fx( L_mult( SMDCT_BITRATE_RATIO_RANGE, ratio_fx ) ); + hCPE->hStereoMdct->split_ratio = round_fx( L_mult( SMDCT_BITRATE_RATIO_RANGE, ratio_fx ) ); /* Q0 */ move16(); /* Tuning to get closer to the optimal split ratio */ IF( LT_32( L_mult0( 9, ratio_fx ), 8 * ONE_IN_Q15 ) && GT_16( hCPE->hStereoMdct->split_ratio, SMDCT_EQUAL_RATIO_RANGE + ( SMDCT_BITRATE_RATIO_RANGE >> 4 ) ) ) { - hCPE->hStereoMdct->split_ratio = sub( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); + hCPE->hStereoMdct->split_ratio = sub( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); /* Q0 */ move16(); } IF( GT_32( L_mult0( 9, ratio_fx ), 1 * ONE_IN_Q15 ) && LT_16( hCPE->hStereoMdct->split_ratio, SMDCT_EQUAL_RATIO_RANGE - ( SMDCT_BITRATE_RATIO_RANGE >> 4 ) ) ) { - hCPE->hStereoMdct->split_ratio = add( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); + hCPE->hStereoMdct->split_ratio = add( hCPE->hStereoMdct->split_ratio, SMDCT_BITRATE_RATIO_RANGE >> 3 ); /* Q0 */ move16(); } - hCPE->hStereoMdct->split_ratio = s_min( SMDCT_BITRATE_RATIO_RANGE - 1, s_max( 1, hCPE->hStereoMdct->split_ratio ) ); + hCPE->hStereoMdct->split_ratio = s_min( SMDCT_BITRATE_RATIO_RANGE - 1, s_max( 1, hCPE->hStereoMdct->split_ratio ) ); /* Q0 */ move16(); } @@ -1126,11 +1122,11 @@ static void MsStereoDecision_fx( Word32 *specS_fx, /* scratch buffer for M, use buffer for inverse MS mask spectrum */ /* Q( q_spec ) */ Word16 q_spec, - Word16 *mdct_stereo_mode, /* output */ - Word16 *msMask, /* output */ - const Word16 nBitsAvailable ) + Word16 *mdct_stereo_mode, /* output Q0*/ + Word16 *msMask, /* output Q0*/ + const Word16 nBitsAvailable /*Q0*/ ) { - Word16 length = sfbParam->sfbOffset[sfbParam->nBandsStereoCore]; + Word16 length = sfbParam->sfbOffset[sfbParam->nBandsStereoCore]; /* Q0 */ Word16 bitsL, bitsR, bitsM, bitsS; Word16 bitsBW, bitsLR, bitsMS; @@ -1163,7 +1159,7 @@ static void MsStereoDecision_fx( specM_e = sub( Q31, q_spec ); specS_e = sub( Q31, q_spec ); - GLR_fx = SQ_gain_estimate_stereo_fx( specL_fx, specL_e, specR_fx, specR_e, nBitsAvailable, length, &e_GLR ); + GLR_fx = SQ_gain_estimate_stereo_fx( specL_fx, specL_e, specR_fx, specR_e, nBitsAvailable, length, &e_GLR ); /* Q31-e_GLR */ FOR( i = 0; i < length; i++ ) { @@ -1173,12 +1169,12 @@ static void MsStereoDecision_fx( move32(); } - G_fx = extract_h( GLR_fx ); /* seems to be favourable to underestimate a bit */ + G_fx = extract_h( GLR_fx ); /* seems to be favourable to underestimate a bit Q15-e_GLR*/ G_e = sub( e_GLR, 1 ); /* do the full spectrum estimates already here, as side effect we get the quantized spectra... */ - bitsLR = add( QuantSpecEstimateBits_fx( specL_fx, specL_e, G_fx, G_e, length, nBitsAvailable, quantSpecL ), QuantSpecEstimateBits_fx( specR_fx, specR_e, G_fx, G_e, length, nBitsAvailable, quantSpecR ) ); - bitsMS = add( QuantSpecEstimateBits_fx( specM_fx, specM_e, G_fx, G_e, length, nBitsAvailable, quantSpecM ), QuantSpecEstimateBits_fx( specS_fx, specS_e, G_fx, G_e, length, nBitsAvailable, quantSpecS ) ); + bitsLR = add( QuantSpecEstimateBits_fx( specL_fx, specL_e, G_fx, G_e, length, nBitsAvailable, quantSpecL ), QuantSpecEstimateBits_fx( specR_fx, specR_e, G_fx, G_e, length, nBitsAvailable, quantSpecR ) ); /* Q0 */ + bitsMS = add( QuantSpecEstimateBits_fx( specM_fx, specM_e, G_fx, G_e, length, nBitsAvailable, quantSpecM ), QuantSpecEstimateBits_fx( specS_fx, specS_e, G_fx, G_e, length, nBitsAvailable, quantSpecS ) ); /* Q0 */ /* clean-up MS scratch buffers */ set32_fx( specM_fx, 0, length ); @@ -1192,8 +1188,8 @@ static void MsStereoDecision_fx( RCcontextMapping_encode2_estimate_bandWise_start( quantSpecL, length, nBitsAvailable, ctxL ); RCcontextMapping_encode2_estimate_bandWise_start( quantSpecR, length, nBitsAvailable, ctxR ); - bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecM, length, nBitsAvailable, ctxM ) ); - bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecS, length, nBitsAvailable, ctxS ) ); + bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecM, length, nBitsAvailable, ctxM ) ); /* Q0 */ + bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecS, length, nBitsAvailable, ctxS ) ); /* Q0 */ /*find_max_lastnz(ctxL,ctxR,ctxM,ctxS);*/ @@ -1214,22 +1210,22 @@ static void MsStereoDecision_fx( msMask[sfb] = 1; move16(); nMSOn = add( nMSOn, 1 ); - context_update( ctxM, ctxL, endline ); - context_update( ctxS, ctxR, endline ); - bitsBW = add( bitsBW, add( bitsM, bitsS ) ); + context_update_fx( ctxM, ctxL, endline ); + context_update_fx( ctxS, ctxR, endline ); + bitsBW = add( bitsBW, add( bitsM, bitsS ) ); /* Q0 */ } ELSE { msMask[sfb] = 0; move16(); - context_update( ctxL, ctxM, endline ); - context_update( ctxR, ctxS, endline ); - bitsBW = add( bitsBW, add( bitsL, bitsR ) ); + context_update_fx( ctxL, ctxM, endline ); + context_update_fx( ctxR, ctxS, endline ); + bitsBW = add( bitsBW, add( bitsL, bitsR ) ); /* Q0 */ } } - bitsBW = add( bitsBW, sfbParam->nBandsStereoCore ); /* Signaling bits */ + bitsBW = add( bitsBW, sfbParam->nBandsStereoCore ); /* Signaling bits Q0*/ IF( LT_16( bitsLR, bitsBW ) ) { @@ -1273,17 +1269,17 @@ static void MsStereoDecision_fx( void initMdctStereoEncData_fx( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element mode */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 igf, /* i : flag indicating IGF activity */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ - const Word16 mem_init /* i : initialize memory after malloc */ + const Word16 mem_init /* i : initialize memory after malloc Q0*/ ) { Word16 tcx_coded_lines; - tcx_coded_lines = getNumTcxCodedLines( bwidth ); + tcx_coded_lines = getNumTcxCodedLines( bwidth ); /* Q0 */ /*initialize mdct stereo mode*/ set16_fx( hStereoMdct->mdct_stereo_mode, -1, 2 ); @@ -1301,7 +1297,7 @@ void initMdctStereoEncData_fx( set16_fx( hStereoMdct->IGFStereoMode, -1, 2 ); - hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Q0 */ move16(); set16_fx( hStereoMdct->global_ild, SMDCT_ILD_RANGE >> 1, 2 ); @@ -1340,9 +1336,11 @@ void initMdctStereoEncData_fx( ivas_error initMdctItdHandling_fx( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word32 input_Fs /* i : input sampling rate */ + const Word32 input_Fs /* i : input sampling rate Q0*/ ) { + test(); + test(); IF( hStereoMdct->hItd == NULL ) { IF( ( hStereoMdct->hItd = (ITD_DATA_HANDLE) malloc( sizeof( ITD_DATA ) ) ) == NULL ) @@ -1351,6 +1349,8 @@ ivas_error initMdctItdHandling_fx( } } + test(); + test(); IF( hStereoMdct->hDft_ana == NULL ) { IF( ( hStereoMdct->hDft_ana = (DFT_ANA_HANDLE) malloc( sizeof( DFT_ANA ) ) ) == NULL ) diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 63a44ab5e5d4fdffc356b5a2a554b82cbf6a9346..469392661508cb4df008ea92bc2d5555b9f299b3 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -54,7 +54,7 @@ static ivas_error allocate_CoreCoder_enc_fx( ENC_CORE_HANDLE st /* i/o: Core encoder state structure */ ) { - IF( st->hLPDmem == NULL && st->element_mode != IVAS_CPE_MDCT ) + IF( st->hLPDmem == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) { @@ -63,7 +63,7 @@ static ivas_error allocate_CoreCoder_enc_fx( LPDmem_enc_init_ivas_fx( st->hLPDmem ); } - IF( st->hGSCEnc == NULL && st->element_mode != IVAS_CPE_MDCT ) + IF( st->hGSCEnc == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) { @@ -221,10 +221,10 @@ static void deallocate_CoreCoder_enc_fx( ivas_error stereo_memory_enc_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 max_bwidth, /* i : maximum audio bandwidth */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + const Word16 max_bwidth, /* i : maximum audio bandwidth Q0*/ const IVAS_FORMAT ivas_format, /* i : ivas format */ - const Word16 nchan_transport /* i : number transport chans */ + const Word16 nchan_transport /* i : number transport chans Q0*/ ) { Encoder_State *st; @@ -526,8 +526,8 @@ ivas_error stereo_memory_enc_fx( // st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; // st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; - st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; - st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; /* Q31-st->hTcxEnc->spectrum_e[0] */ + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; /* Q31-st->hTcxEnc->spectrum_e[1] */ st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; move16(); move16(); @@ -536,6 +536,8 @@ ivas_error stereo_memory_enc_fx( set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); st->hTcxEnc->spectrum_long_e = 0; st->hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ + move16(); + move32(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { @@ -569,6 +571,7 @@ ivas_error stereo_memory_enc_fx( test(); hCPE->hStereoMdct->isSBAStereoMode = ( EQ_32( ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport, 2 ) ); + move16(); test(); test(); @@ -634,17 +637,17 @@ ivas_error stereo_memory_enc_fx( } static void v_multc_fixed_32_16( - const Word16 x[], /* i : Input vector */ - const Word32 c, /* i : Constant */ - Word32 y[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ + const Word16 x[], /* i : Input vector Qx*/ + const Word32 c, /* i : Constant Q31*/ + Word32 y[], /* o : Output vector that contains c*x Qx*/ + const Word16 N /* i : Vector length Q0*/ ) { Word16 i; FOR( i = 0; i < N; i++ ) { - y[i] = Mpy_32_16_1( c, x[i] ); + y[i] = Mpy_32_16_1( c, x[i] ); /* Q16+Qx */ move32(); } @@ -658,8 +661,8 @@ static void v_multc_fixed_32_16( void stereo_switching_enc_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - Word16 old_input_signal_pri[], /* i : old input signal of primary channel */ - const Word16 input_frame, /* i : input frame length */ + Word16 old_input_signal_pri[], /* i : old input signal of primary channel q_inp*/ + const Word16 input_frame, /* i : input frame length Q0*/ const Word16 q_inp ) { Word16 i, n, dft_ovl, offset; @@ -677,16 +680,16 @@ void stereo_switching_enc_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy( sts[n]->input_fx + input_frame - dft_ovl, hCPE->input_mem_fx[n], dft_ovl ); + Copy( sts[n]->input_fx + input_frame - dft_ovl, hCPE->input_mem_fx[n], dft_ovl ); /* sts[n]->q_inp */ } } /* save original stereo input (MDCT overlap part) for both channels in unused old input of right channel for possible DFT->MDCT transition */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - Copy( sts[0]->input_fx + sub( (Word16) Mpy_32_32( sts[0]->input_Fs, 42949673 /* 1/50 in Q31*/ ), sts[0]->encoderLookahead_FB ), sts[1]->input_fx - shl( sts[0]->encoderLookahead_FB, 1 ), sts[0]->encoderLookahead_FB ); + Copy( sts[0]->input_fx + sub( (Word16) Mpy_32_32( sts[0]->input_Fs, 42949673 /* 1/50 in Q31*/ ), sts[0]->encoderLookahead_FB ), sts[1]->input_fx - shl( sts[0]->encoderLookahead_FB, 1 ), sts[0]->encoderLookahead_FB ); /* sts[0]->q_inp */ - Copy( sts[1]->input_fx + sub( (Word16) Mpy_32_32( sts[1]->input_Fs, 42949673 /* 1/50 in Q31*/ ), sts[1]->encoderLookahead_FB ), sts[1]->input_fx - sts[1]->encoderLookahead_FB, sts[1]->encoderLookahead_FB ); + Copy( sts[1]->input_fx + sub( (Word16) Mpy_32_32( sts[1]->input_Fs, 42949673 /* 1/50 in Q31*/ ), sts[1]->encoderLookahead_FB ), sts[1]->input_fx - sts[1]->encoderLookahead_FB, sts[1]->encoderLookahead_FB ); /* sts[1]->q_inp */ } @@ -719,7 +722,7 @@ void stereo_switching_enc_fx( tmp_fx = usdequant_fx( hCPE->hStereoTCA->indx_ica_gD, STEREO_TCA_GDMIN_FX, STEREO_TCA_GDSTEP_FX ); FOR( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) { - hCPE->hStereoDft->side_gain_fx[STEREO_DFT_BAND_MAX + i] = L_deposit_h( tmp_fx ); + hCPE->hStereoDft->side_gain_fx[STEREO_DFT_BAND_MAX + i] = L_deposit_h( tmp_fx ); /* Q31 */ move32(); } } @@ -731,7 +734,7 @@ void stereo_switching_enc_fx( /* update DFT synthesis overlap memory @12.8kHz */ FOR( i = 0; i < STEREO_DFT_OVL_12k8; i++ ) { - hCPE->hStereoDft->output_mem_dmx_12k8_fx[i] = L_shr( Mpy_32_16_r( hCPE->hStereoDft->win_12k8_fx[STEREO_DFT_OVL_12k8 - 1 - i], sts[0]->buf_speech_enc[L_FRAME32k + L_FRAME - STEREO_DFT_OVL_12k8 + i] ), q_inp ); + hCPE->hStereoDft->output_mem_dmx_12k8_fx[i] = L_shr( Mpy_32_16_r( hCPE->hStereoDft->win_12k8_fx[STEREO_DFT_OVL_12k8 - 1 - i], sts[0]->buf_speech_enc[L_FRAME32k + L_FRAME - STEREO_DFT_OVL_12k8 + i] ), q_inp ); /* Q16 */ move32(); } Word16 q_dmx = Q16; @@ -791,7 +794,8 @@ void stereo_switching_enc_fx( set_zero_fx( sts[1]->input32_fx - input_frame, input_frame ); set16_zero_fx( sts[1]->input_fx - input_frame, input_frame ); sts[1]->q_old_inp = Q15; - hCPE->hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[LRTD_STEREO_LEFT_IS_PRIM]; + hCPE->hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[LRTD_STEREO_LEFT_IS_PRIM]; /* Q31 */ + move16(); move32(); hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; @@ -799,9 +803,9 @@ void stereo_switching_enc_fx( test(); test(); - IF( LT_32( hCPE->hStereoTCA->instTargetGain_fx, 26843546 ) && ( hCPE->hCoreCoder[0]->vad_flag || hCPE->hCoreCoder[1]->vad_flag ) ) /* but if there is no content in the L channel -> the primary channel is forced to right */ + IF( LT_32( hCPE->hStereoTCA->instTargetGain_fx, 26843546 /*Q29*/ ) && ( hCPE->hCoreCoder[0]->vad_flag || hCPE->hCoreCoder[1]->vad_flag ) ) /* but if there is no content in the L channel -> the primary channel is forced to right */ { - hCPE->hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[LRTD_STEREO_RIGHT_IS_PRIM]; + hCPE->hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[LRTD_STEREO_RIGHT_IS_PRIM]; /* Q31 */ move32(); hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; move16(); @@ -815,10 +819,10 @@ void stereo_switching_enc_fx( { IF( sts[0]->cldfbAnaEnc != NULL ) { - offset = sub( sts[0]->cldfbAnaEnc->p_filter_length, sts[0]->cldfbAnaEnc->no_channels ); + offset = sub( sts[0]->cldfbAnaEnc->p_filter_length, sts[0]->cldfbAnaEnc->no_channels ); /* Q0 */ FOR( i = 0; i < offset; i++ ) { - sts[0]->cldfbAnaEnc->cldfb_state_fx[i] = L_deposit_h( old_input_signal_pri[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ); + sts[0]->cldfbAnaEnc->cldfb_state_fx[i] = L_deposit_h( old_input_signal_pri[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ); /* Q16+q_inp */ move32(); } sts[0]->cldfbAnaEnc->Q_cldfb_state = add( Q16, q_inp ); @@ -828,7 +832,7 @@ void stereo_switching_enc_fx( IF( sts[0]->cldfbSynTd != NULL ) { cldfb_reset_memory_fx( sts[0]->cldfbSynTd ); - sts[0]->currEnergyLookAhead_fx = 130996; + sts[0]->currEnergyLookAhead_fx = 130996; /* Q31 */ move32(); } @@ -840,7 +844,7 @@ void stereo_switching_enc_fx( test(); IF( hCPE->hStereoTD != NULL && EQ_16( hCPE->hStereoTD->tdm_last_ratio_idx, LRTD_STEREO_LEFT_IS_PRIM ) ) { - v_multc_fixed_32_16( hCPE->hCoreCoder[1]->old_input_signal_fx + sub( input_frame, add( offset, NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) ) ), -MAX_32, sts[1]->cldfbAnaEnc->cldfb_state_fx, offset ); + v_multc_fixed_32_16( hCPE->hCoreCoder[1]->old_input_signal_fx + sub( input_frame, add( offset, NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) ) ), -MAX_32, sts[1]->cldfbAnaEnc->cldfb_state_fx, offset ); /* Q16+q_inp */ sts[1]->cldfbAnaEnc->Q_cldfb_state = add( Q16, q_inp ); move16(); } @@ -848,7 +852,7 @@ void stereo_switching_enc_fx( { FOR( i = 0; i < offset; i++ ) { - sts[1]->cldfbAnaEnc->cldfb_state_fx[i] = L_shr( L_deposit_h( hCPE->hCoreCoder[1]->old_input_signal_fx[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ), 5 ); + sts[1]->cldfbAnaEnc->cldfb_state_fx[i] = L_shr( L_deposit_h( hCPE->hCoreCoder[1]->old_input_signal_fx[input_frame - offset - NS2SA( input_frame * FRAMES_PER_SEC, L_MEM_RECALC_TBE_NS ) + i] ), 5 ); /* Q11+q_inp */ move32(); } sts[1]->cldfbAnaEnc->Q_cldfb_state = add( Q16 - 5, q_inp ); @@ -858,7 +862,7 @@ void stereo_switching_enc_fx( IF( sts[1]->cldfbSynTd != NULL ) { cldfb_reset_memory_fx( sts[1]->cldfbSynTd ); - sts[1]->currEnergyLookAhead_fx = 130996; + sts[1]->currEnergyLookAhead_fx = 130996; /* Q31 */ move32(); } } @@ -918,32 +922,32 @@ void stereo_switching_enc_fx( { Copy( sts[0]->hLPDmem->old_exc, sts[1]->hLPDmem->old_exc, L_EXC_MEM ); } - Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); - Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); - Copy( sts[0]->lsf_old1_fx, sts[1]->lsf_old1_fx, M ); - Copy( sts[0]->lsp_old1_fx, sts[1]->lsp_old1_fx, M ); + Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); /* Qlog2(2.56) */ + Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); /* Q15 */ + Copy( sts[0]->lsf_old1_fx, sts[1]->lsf_old1_fx, M ); /* Qlog2(2.56) */ + Copy( sts[0]->lsp_old1_fx, sts[1]->lsp_old1_fx, M ); /* Q15 */ sts[1]->GSC_noisy_speech = 0; move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { /* cross-fade overlap region of DFT Stereo downmix and original stereo channels */ - tmp_fx = div_s( 64, shl( sts[0]->encoderLookahead_FB, Q6 ) ); + tmp_fx = div_s( 64, shl( sts[0]->encoderLookahead_FB, Q6 ) ); /* Q15 */ FOR( i = 0; i < sts[0]->encoderLookahead_FB; i++ ) { - sts[1]->input32_fx[-sts[0]->encoderLookahead_FB + i] = L_shr( Mpy_32_16_1( L_add( Mpy_32_16_1( sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i], sts[0]->encoderLookahead_FB - i ), Mpy_32_16_1( sts[1]->input32_fx[-sts[0]->encoderLookahead_FB + i], i ) ), tmp_fx ), 13 ); + sts[1]->input32_fx[-sts[0]->encoderLookahead_FB + i] = L_shr( Mpy_32_16_1( L_add( Mpy_32_16_1( sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i], sts[0]->encoderLookahead_FB - i ), Mpy_32_16_1( sts[1]->input32_fx[-sts[0]->encoderLookahead_FB + i], i ) ), tmp_fx ), 13 ); /* q_inp32+0-15+15-15-13 */ move32(); - sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i] = L_shr( Mpy_32_16_1( L_add( Mpy_32_16_1( sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i], sts[0]->encoderLookahead_FB - i ), Mpy_32_16_1( sts[1]->input32_fx[-2 * sts[0]->encoderLookahead_FB + i], i ) ), tmp_fx ), 13 ); + sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i] = L_shr( Mpy_32_16_1( L_add( Mpy_32_16_1( sts[0]->input32_fx[-sts[0]->encoderLookahead_FB + i], sts[0]->encoderLookahead_FB - i ), Mpy_32_16_1( sts[1]->input32_fx[-2 * sts[0]->encoderLookahead_FB + i], i ) ), tmp_fx ), 13 ); /* q_inp32+0-15+15-15-13 */ move32(); } /* restore continuous signal in right channel (part of old_output was used to store original left channel) */ - Copy32( sts[0]->input32_fx - sts[0]->hTcxEnc->L_frameTCX, sts[1]->input32_fx - sts[0]->hTcxEnc->L_frameTCX, sts[0]->hTcxEnc->L_frameTCX - sts[0]->encoderLookahead_FB ); + Copy32( sts[0]->input32_fx - sts[0]->hTcxEnc->L_frameTCX, sts[1]->input32_fx - sts[0]->hTcxEnc->L_frameTCX, sub( sts[0]->hTcxEnc->L_frameTCX, sts[0]->encoderLookahead_FB ) ); /* sts[0]->q_inp32 */ - sts[1]->last_core = sts[0]->last_core; + sts[1]->last_core = sts[0]->last_core; /* Q0 */ move16(); - sts[1]->last_coder_type = sts[0]->last_coder_type; + sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); - sts[1]->last_bwidth = sts[0]->last_bwidth; + sts[1]->last_bwidth = sts[0]->last_bwidth; /* Q0 */ move16(); } } @@ -958,7 +962,7 @@ void stereo_switching_enc_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { - sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; /* Q0 */ move16(); sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; move16(); diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index fdf53370e97239e1b7f5e94d5c0e0c55d6db3c51..58e72c91e38992ca05fab77506bbfdfa492344d5 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -114,23 +114,23 @@ * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 stereo_tdm_ener_analysis_SM_fx( CPE_ENC_HANDLE hCPE, Encoder_State **sts, const Word16 input_frame, Word16 *tdm_SM_flag ); +static Word16 stereo_tdm_ener_analysis_SM_fx( CPE_ENC_HANDLE hCPE, Encoder_State **sts, const Word16 input_frame /*Q0*/, Word16 *tdm_SM_flag /*Q0*/ ); -static void Get_corr_n_fx( const Word16 L[], const Word16 R[], Word32 *ic_Lm, Word16 *q_ic_Lm, Word32 *ic_Rm, Word16 *q_ic_Rm, const Word16 len, Word32 *es_em, const Word16 tdm_SM_calc_flag ); +static void Get_corr_n_fx( const Word16 L[] /*q_in*/, const Word16 R[] /*q_in*/, Word32 *ic_Lm, Word16 *q_ic_Lm, Word32 *ic_Rm, Word16 *q_ic_Rm, const Word16 len, Word32 *es_em, const Word16 tdm_SM_calc_flag ); static Word16 stereo_smooth_LR_transition_fx( Word16 *tdm_prev_stable_idx, Word16 *tdm_ratio_transition_mov_flag, Word16 tdm_last_ratio_idx, Word16 *tdm_prev_desired_idx, Word16 *tdm_ratio_transition_cnt, const Word16 tdm_SM_flag, Word16 desired_idx ); -static Word16 limit_idx_Dwnmix_fx( const Word16 idx_in, const Word16 unclr_decision, const Word16 inst_idx, const Word16 previous_idx, const Word16 tdm_last_LRTD_PriCh_cnt, const Word16 tdm_last_LRTD_frame_cnt ); +static Word16 limit_idx_Dwnmix_fx( const Word16 idx_in /*Q0*/, const Word16 unclr_decision /*Q0*/, const Word16 inst_idx /*Q0*/, const Word16 previous_idx /*Q0*/, const Word16 tdm_last_LRTD_PriCh_cnt /*Q0*/, const Word16 tdm_last_LRTD_frame_cnt /*Q0*/ ); -static Word16 limit_idx_NoDwnmix_fx( const Word16 idx_in, const Word16 side_can_change, const Word32 d_lt_corr_raw, const Word16 q_d_lt_corr_raw ); +static Word16 limit_idx_NoDwnmix_fx( const Word16 idx_in /*Q0*/, const Word16 side_can_change /*Q0*/, const Word32 d_lt_corr_raw, const Word16 q_d_lt_corr_raw ); -static void Get_LR_rms_fx( const Word16 *Left_in, const Word16 *Right_in, const Word16 input_frame, Word32 *rms_L, Word16 *q_rms_L, Word32 *rms_R, Word16 *q_rms_R ); +static void Get_LR_rms_fx( const Word16 *Left_in /*q_inp*/, const Word16 *Right_in /*q_inp*/, const Word16 input_frame, Word32 *rms_L, Word16 *q_rms_L, Word32 *rms_R, Word16 *q_rms_R ); -static Word16 Get_dt_lt_ener_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono, const Word16 input_frame, const Word16 tdm_last_SM_flag, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, Word32 *tdm_lt_rms_L, Word32 *tdm_lt_rms_R, Word32 *tdm_last_ener_lt_L, Word32 *tdm_last_ener_lt_R, Word32 *tdm_LT_es_em, Word16 *tdm_hyst_cnt, Word16 *tdm_NOOP_SM_flag_loc, Word32 *ener_R_dt, Word32 *ener_L_dt, Word32 *corr_LM, Word16 *q_corr_LM, Word32 *corr_RM, Word16 *q_corr_RM ); +static Word16 Get_dt_lt_ener_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono, const Word16 input_frame, const Word16 tdm_last_SM_flag, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, Word32 *tdm_lt_rms_L /*Q16*/, Word32 *tdm_lt_rms_R /*Q16*/, Word32 *tdm_last_ener_lt_L /*Q16*/, Word32 *tdm_last_ener_lt_R /*Q16*/, Word32 *tdm_LT_es_em /*Q21*/, Word16 *tdm_hyst_cnt, Word16 *tdm_NOOP_SM_flag_loc, Word32 *ener_R_dt /*Q16*/, Word32 *ener_L_dt /*Q16*/, Word32 *corr_LM, Word16 *q_corr_LM, Word32 *corr_RM, Word16 *q_corr_RM ); -static void NOOP_decision_fx( CPE_ENC_HANDLE hCPE, const Word16 tdm_NOOP_flag_loc, const Word16 tmp_SM_flag, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, Word16 *tdm_SM_flag_loc ); +static void NOOP_decision_fx( CPE_ENC_HANDLE hCPE, const Word16 tdm_NOOP_flag_loc /*Q0*/, const Word16 tmp_SM_flag /*Q0*/, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, Word16 *tdm_SM_flag_loc /*Q0*/ ); -static Word32 Comp_diff_lt_corr_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, const Word32 ener_L_dt, const Word32 ener_R_dt, Word32 corr_LM, Word16 q_corr_LM, Word32 corr_RM, Word16 q_corr_RM, const Word32 tdm_lt_rms_L, const Word32 tdm_lt_rms_R, Word32 *tdm_lt_corr_LM, Word32 *tdm_lt_corr_RM, Word32 *tdm_last_diff_lt_corr, Word16 *q_tdm_last_diff_lt_corr, Word32 *inst_ratio_L_out, Word32 *diff_lt_corr, Word16 *q_d_lt_corr_raw ); +static Word32 Comp_diff_lt_corr_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono /*Q0*/, const Word32 rms_L, const Word16 q_rms_L, const Word32 rms_R, const Word16 q_rms_R, const Word32 ener_L_dt /*Q16*/, const Word32 ener_R_dt /*Q16*/, Word32 corr_LM, Word16 q_corr_LM, Word32 corr_RM, Word16 q_corr_RM, const Word32 tdm_lt_rms_L /*Q16*/, const Word32 tdm_lt_rms_R /*Q16*/, Word32 *tdm_lt_corr_LM /*Q24*/, Word32 *tdm_lt_corr_RM /*Q24*/, Word32 *tdm_last_diff_lt_corr, Word16 *q_tdm_last_diff_lt_corr, Word32 *inst_ratio_L_out /*Q24*/, Word32 *diff_lt_corr, Word16 *q_d_lt_corr_raw ); /*-------------------------------------------------------------------* @@ -140,9 +140,9 @@ static Word32 Comp_diff_lt_corr_fx( CPE_ENC_HANDLE hCPE, const Word16 IsSideMono Word16 stereo_tdm_ener_analysis_fx( const Word16 ivas_format, /* i : IVAS format */ CPE_ENC_HANDLE hCPE, /* i : CPE structure */ - const Word16 input_frame, /* i : Number of samples */ - Word16 *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ - Word16 *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ + const Word16 input_frame, /* i : Number of samples Q0*/ + Word16 *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel Q0*/ + Word16 *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode Q0*/ ) { Word32 diff_lt_corr_fx /*Q24*/; @@ -189,7 +189,7 @@ Word16 stereo_tdm_ener_analysis_fx( * - evolution of the L and R to Mono gain *----------------------------------------------------------------*/ - tdm_SM_flag_loc = hStereoTD->tdm_last_SM_flag; + tdm_SM_flag_loc = hStereoTD->tdm_last_SM_flag; /* Q0 */ move16(); tmp_SM_flag = Get_dt_lt_ener_fx( hCPE, 0, input_frame, hStereoTD->tdm_last_SM_flag, rms_L_fx, q_rms_L, rms_R_fx, q_rms_R, @@ -218,7 +218,7 @@ Word16 stereo_tdm_ener_analysis_fx( IF( GT_16( q_d_lt_corr_raw, 31 ) ) { - d_lt_corr_raw_fx = L_shr( d_lt_corr_raw_fx, sub( q_d_lt_corr_raw, Q31 ) ); + d_lt_corr_raw_fx = L_shr( d_lt_corr_raw_fx, sub( q_d_lt_corr_raw, Q31 ) ); /* Q31 */ q_d_lt_corr_raw = Q31; move16(); } @@ -232,7 +232,7 @@ Word16 stereo_tdm_ener_analysis_fx( xtalk_classifier_td_fx( hCPE ); /* switch to LRTD on cross-talk segments where two speakers are weakly correlated */ - hStereoTD->prev_fr_LRTD_TD_dec = hCPE->hStereoClassif->lrtd_mode; + hStereoTD->prev_fr_LRTD_TD_dec = hCPE->hStereoClassif->lrtd_mode; /* Q0 */ move16(); /*----------------------------------------------------------------* @@ -251,7 +251,7 @@ Word16 stereo_tdm_ener_analysis_fx( } } - rms_thd_fx = RMS_MIN_Q16; + rms_thd_fx = RMS_MIN_Q16; /* Q16 */ move32(); IF( EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) ) { @@ -326,7 +326,7 @@ Word16 stereo_tdm_ener_analysis_fx( move16(); } - if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { side_can_change = 1; move16(); @@ -353,8 +353,8 @@ Word16 stereo_tdm_ener_analysis_fx( test(); test(); test(); - if ( ( ( LT_32( rms_L_fx, RMS_THR_Q16 ) && LT_32( rms_R_fx, RMS_THR_Q16 ) && LT_32( L_abs( L_sub( rms_R_fx, rms_L_fx ) ), RMS_THR_Q16 / 2 ) && GT_32( L_abs( d_lt_corr_raw_fx ), L_shr( 644245094 /*0.3f in Q31*/, sub( Q31, q_d_lt_corr_raw ) ) ) ) || - ( LT_16( abs_s( sub( sts[0]->old_corr_fx, sts[1]->old_corr_fx ) ), 4915 /*0.15f in Q15*/ ) && GT_16( sts[0]->old_corr_fx, 22937 /*0.7f in Q15*/ ) && LT_16( sts[0]->old_corr_fx, 27853 /*0.85f in Q15*/ ) && LT_32( L_abs( L_sub( rms_L_fx, rms_R_fx ) ), rms_thd_fx ) && GT_32( L_abs( d_lt_corr_raw_fx ), L_shr( 644245094 /*0.3f in Q31*/, sub( Q31, q_d_lt_corr_raw ) ) ) ) ) /* Both channels are low energy, clean background switching is allowed */ + IF( ( ( LT_32( rms_L_fx, RMS_THR_Q16 ) && LT_32( rms_R_fx, RMS_THR_Q16 ) && LT_32( L_abs( L_sub( rms_R_fx, rms_L_fx ) ), RMS_THR_Q16 / 2 ) && GT_32( L_abs( d_lt_corr_raw_fx ), L_shr( 644245094 /*0.3f in Q31*/, sub( Q31, q_d_lt_corr_raw ) ) ) ) || + ( LT_16( abs_s( sub( sts[0]->old_corr_fx, sts[1]->old_corr_fx ) ), 4915 /*0.15f in Q15*/ ) && GT_16( sts[0]->old_corr_fx, 22937 /*0.7f in Q15*/ ) && LT_16( sts[0]->old_corr_fx, 27853 /*0.85f in Q15*/ ) && LT_32( L_abs( L_sub( rms_L_fx, rms_R_fx ) ), rms_thd_fx ) && GT_32( L_abs( d_lt_corr_raw_fx ), L_shr( 644245094 /*0.3f in Q31*/, sub( Q31, q_d_lt_corr_raw ) ) ) ) ) /* Both channels are low energy, clean background switching is allowed */ ) { side_can_change = 1; @@ -388,7 +388,7 @@ Word16 stereo_tdm_ener_analysis_fx( test(); test(); - if ( GE_32( hCPE->hStereoClassif->xtalk_wscore_fx, 107374182 /*0.05f in Q31*/ ) && hStereoTD->prev_fr_LRTD_TD_dec == 0 && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) ) + IF( GE_32( hCPE->hStereoClassif->xtalk_wscore_fx, 107374182 /*0.05f in Q31*/ ) && hStereoTD->prev_fr_LRTD_TD_dec == 0 && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) ) { side_can_change = 0; move16(); @@ -478,9 +478,9 @@ Word16 stereo_tdm_ener_analysis_fx( { test(); test(); - if ( GE_32( hCPE->element_brate, IVAS_48k ) && sts[0]->hVAD->hangover_cnt != 0 && LT_32( L_max( hStereoTD->tdm_lt_rms_L_fx, hStereoTD->tdm_lt_rms_R_fx ), 33554432 /* 512.0f */ ) ) + IF( GE_32( hCPE->element_brate, IVAS_48k ) && sts[0]->hVAD->hangover_cnt != 0 && LT_32( L_max( hStereoTD->tdm_lt_rms_L_fx, hStereoTD->tdm_lt_rms_R_fx ), 33554432 /* 512.0f */ ) ) { - ratio_L_fx = check_bounds_l( ratio_L_fx, 644245094 /*0.3f in Q31*/, 1503238554 /*0.7f in Q31*/ ); + ratio_L_fx = check_bounds_l( ratio_L_fx, 644245094 /*0.3f in Q31*/, 1503238554 /*0.7f in Q31*/ ); /* Q31 */ } test(); @@ -512,7 +512,7 @@ Word16 stereo_tdm_ener_analysis_fx( } } - idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx, &hStereoTD->tdm_ratio_transition_mov_flag, hStereoTD->tdm_last_ratio_idx, &hStereoTD->tdm_prev_desired_idx, &hStereoTD->tdm_ratio_transition_cnt, tdm_SM_flag_loc, desired_idx ); + idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx, &hStereoTD->tdm_ratio_transition_mov_flag, hStereoTD->tdm_last_ratio_idx, &hStereoTD->tdm_prev_desired_idx, &hStereoTD->tdm_ratio_transition_cnt, tdm_SM_flag_loc, desired_idx ); /* Q0 */ /* Change the switching level in case of dual mono (in case the scenario still accept left right switching */ /* This logic is needed in case the content is exactly the same in the 2 channel and it is expected to get back to LRTD, to prevent the secondary channel to be completely empty */ @@ -577,19 +577,19 @@ Word16 stereo_tdm_ener_analysis_fx( Word16 idx_offet; idx_offet = 5; move16(); - if ( GT_16( desired_idx, LRTD_STEREO_MID_IS_PRIM ) ) /* slightly Favor the 2nd channel */ + IF( GT_16( desired_idx, LRTD_STEREO_MID_IS_PRIM ) ) /* slightly Favor the 2nd channel */ { idx_offet = negate( idx_offet ); } desired_idx = add( desired_idx, idx_offet ); - desired_idx = check_bounds_s_fx( desired_idx, 0, 30 ); + desired_idx = check_bounds_s_fx( desired_idx, 0, 30 ); /* Q0 */ } } test(); IF( sts[1]->clas != UNVOICED_CLAS || sts[0]->clas != UNVOICED_CLAS ) { - desired_idx = check_bounds_s_fx( desired_idx, 5, 25 ); + desired_idx = check_bounds_s_fx( desired_idx, 5, 25 ); /* Q0 */ } hStereoTD->tdm_inst_ratio_idx = desired_idx; @@ -673,9 +673,9 @@ Word16 stereo_tdm_ener_analysis_fx( move32(); hStereoTD->tdm_lt_corr_LM_SM_fx = 167772 /*0.01f Q24*/; move32(); - hStereoTD->tdm_last_ratio_SM_fx = hStereoTD->tdm_last_ratio_fx; + hStereoTD->tdm_last_ratio_SM_fx = hStereoTD->tdm_last_ratio_fx; /* Q31 */ move32(); - hStereoTD->tdm_last_ratio_idx_SM = hStereoTD->tdm_last_ratio_idx; + hStereoTD->tdm_last_ratio_idx_SM = hStereoTD->tdm_last_ratio_idx; /* Q0 */ move16(); hStereoTD->tdm_lt_rms_L_SM_fx = 2621440; // 40.0f Q16 move32(); @@ -706,7 +706,7 @@ Word16 stereo_tdm_ener_analysis_fx( move16(); } - *tdm_ratio_idx_SM = stereo_tdm_ener_analysis_SM_fx( hCPE, sts, input_frame, &tdm_NOOP_flag ); + *tdm_ratio_idx_SM = stereo_tdm_ener_analysis_SM_fx( hCPE, sts, input_frame, &tdm_NOOP_flag ); /* Q0 */ move16(); } ELSE @@ -723,15 +723,15 @@ Word16 stereo_tdm_ener_analysis_fx( move16(); /* set channel combination scheme flag */ - *tdm_SM_or_LRTD_Pri = tdm_SM_flag_loc; + *tdm_SM_or_LRTD_Pri = tdm_SM_flag_loc; /* Q0 */ move16(); if ( EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) { - *tdm_SM_or_LRTD_Pri = tdm_LRTD_pri_side; + *tdm_SM_or_LRTD_Pri = tdm_LRTD_pri_side; /* Q0 */ move16(); } - hCPE->hStereoClassif->ratio_L_fx = ratio_L_fx; + hCPE->hStereoClassif->ratio_L_fx = ratio_L_fx; /* Q15 */ move32(); return idx; @@ -744,12 +744,12 @@ Word16 stereo_tdm_ener_analysis_fx( *-------------------------------------------------------------------*/ static void Get_LR_rms_fx( - const Word16 *Left_in, - const Word16 *Right_in, - const Word16 input_frame, - Word32 *rms_L, + const Word16 *Left_in, /* q_inp */ + const Word16 *Right_in, /* q_inp */ + const Word16 input_frame, /* Q0 */ + Word32 *rms_L, /* q_rms_L */ Word16 *q_rms_L, - Word32 *rms_R, + Word32 *rms_R, /* q_rms_R */ Word16 *q_rms_R ) { Word32 ener_l, ener_r; @@ -763,9 +763,9 @@ static void Get_LR_rms_fx( move64(); W_ener_r_tmp = 0; move64(); - ener_l = ONE_BY_100_Q31; + ener_l = ONE_BY_100_Q31; /* Q31 */ move32(); - ener_r = ONE_BY_100_Q31; + ener_r = ONE_BY_100_Q31; /* Q31 */ move32(); guard_bits = sub( 32, find_guarded_bits_fx( input_frame ) ); @@ -778,12 +778,12 @@ static void Get_LR_rms_fx( ener_l_tmp = W_extract_h( W_shl( W_ener_l_tmp, guard_bits ) ); // guard_bits - 32 ener_r_tmp = W_extract_h( W_shl( W_ener_r_tmp, guard_bits ) ); // guard_bits - 32 - ener_l = BASOP_Util_Add_Mant32Exp( ener_l, 0, ener_l_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_l ); - ener_r = BASOP_Util_Add_Mant32Exp( ener_r, 0, ener_r_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_r ); + ener_l = BASOP_Util_Add_Mant32Exp( ener_l, 0, ener_l_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_l ); /* Q31-exp_out_l */ + ener_r = BASOP_Util_Add_Mant32Exp( ener_r, 0, ener_r_tmp, sub( Q31, sub( guard_bits, 32 ) ), &exp_out_r ); /* Q31-exp_out_r */ - ener_l_tmp = BASOP_Util_Divide3232_Scale( ener_l, input_frame, &exp_diff ); + ener_l_tmp = BASOP_Util_Divide3232_Scale( ener_l, input_frame, &exp_diff ); /* Q31- exp_out_l*/ exp_out_l = sub( add( exp_diff, exp_out_l ), Q15 ); - ener_r_tmp = BASOP_Util_Divide3232_Scale( ener_r, input_frame, &exp_diff ); + ener_r_tmp = BASOP_Util_Divide3232_Scale( ener_r, input_frame, &exp_diff ); /* Q31-exp_out_r */ exp_out_r = sub( add( exp_diff, exp_out_r ), Q15 ); *rms_L = Sqrt32( ener_l_tmp, &exp_out_l ); // Q31 - exp_out_l @@ -811,25 +811,25 @@ static void Get_LR_rms_fx( static Word16 Get_dt_lt_ener_fx( CPE_ENC_HANDLE hCPE, - const Word16 IsSideMono, - const Word16 input_frame, - const Word16 tdm_last_SM_flag, - const Word32 rms_L, + const Word16 IsSideMono, /* Q0 */ + const Word16 input_frame, /* Q0 */ + const Word16 tdm_last_SM_flag, /* Q0 */ + const Word32 rms_L, /* q_rms_L */ const Word16 q_rms_L, - const Word32 rms_R, + const Word32 rms_R, /* q_rms_R */ const Word16 q_rms_R, - Word32 *tdm_lt_rms_L, - Word32 *tdm_lt_rms_R, - Word32 *tdm_last_ener_lt_L, - Word32 *tdm_last_ener_lt_R, - Word32 *tdm_LT_es_em, - Word16 *tdm_hyst_cnt, - Word16 *tdm_NOOP_SM_flag_loc, - Word32 *ener_R_dt, - Word32 *ener_L_dt, - Word32 *corr_LM, + Word32 *tdm_lt_rms_L, /* Q16 */ + Word32 *tdm_lt_rms_R, /* Q16 */ + Word32 *tdm_last_ener_lt_L, /* Q16 */ + Word32 *tdm_last_ener_lt_R, /* Q16 */ + Word32 *tdm_LT_es_em, /* Q21 */ + Word16 *tdm_hyst_cnt, /* Q0 */ + Word16 *tdm_NOOP_SM_flag_loc, /* Q0 */ + Word32 *ener_R_dt, /* Q16 */ + Word32 *ener_L_dt, /* Q16 */ + Word32 *corr_LM, /* q_corr_LM */ Word16 *q_corr_LM, - Word32 *corr_RM, + Word32 *corr_RM, /* q_corr_RM */ Word16 *q_corr_RM ) { Encoder_State **sts; @@ -841,27 +841,27 @@ static Word16 Get_dt_lt_ener_fx( sts = hCPE->hCoreCoder; - Left_in_fx = sts[0]->input_fx; /* Left channel */ - Right_in_fx = sts[1]->input_fx; /* Right channel */ + Left_in_fx = sts[0]->input_fx; /* Left channel sts[0]->q_inp*/ + Right_in_fx = sts[1]->input_fx; /* Right channel sts[1]->q_inp*/ tmp = sub( getScaleFactor16( sts[0]->input_fx, input_frame ), 1 ); - Scale_sig( sts[0]->input_fx, input_frame, tmp ); + Scale_sig( sts[0]->input_fx, input_frame, tmp ); /* sts[0]->q_inp + tmp */ sts[0]->q_inp = add( tmp, sts[0]->q_inp ); move16(); tmp = getScaleFactor16( sts[1]->input_fx, input_frame ); - Scale_sig( sts[1]->input_fx, input_frame, tmp ); + Scale_sig( sts[1]->input_fx, input_frame, tmp ); /* sts[1]->q_inp + tmp */ sts[1]->q_inp = add( tmp, sts[1]->q_inp ); move16(); - Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[0]->q_inp ) ); - Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[1]->q_inp ) ); + Scale_sig( sts[0]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[0]->q_inp ) ); /* s_min( sts[0]->q_inp, sts[1]->q_inp ) */ + Scale_sig( sts[1]->input_fx, input_frame, sub( s_min( sts[0]->q_inp, sts[1]->q_inp ), sts[1]->q_inp ) ); /* s_min( sts[0]->q_inp, sts[1]->q_inp ) */ sts[1]->q_inp = s_min( sts[0]->q_inp, sts[1]->q_inp ); move16(); sts[0]->q_inp = sts[1]->q_inp; move16(); - tdm_SM_flag_loc = tdm_last_SM_flag; + tdm_SM_flag_loc = tdm_last_SM_flag; /* Q0 */ move16(); test(); @@ -916,7 +916,7 @@ static Word16 Get_dt_lt_ener_fx( Get_corr_n_fx( Left_in_fx, Right_in_fx, corr_LM, q_corr_LM, corr_RM, q_corr_RM, input_frame, &es_em_fx, IsSideMono ); - hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM] = BASOP_Util_Add_Mant32Exp( *corr_LM, sub( Q31, *q_corr_LM ), L_negate( *corr_RM ), sub( Q31, *q_corr_RM ), &exp_diff ); + hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM] = BASOP_Util_Add_Mant32Exp( *corr_LM, sub( Q31, *q_corr_LM ), L_negate( *corr_RM ), sub( Q31, *q_corr_RM ), &exp_diff ); /* Q31-exp_diff */ move32(); hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM] = L_shl( hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM], sub( Q15, sub( Q31, exp_diff ) ) ); // Q15 move32(); @@ -937,8 +937,15 @@ static Word16 Get_dt_lt_ener_fx( tmp_SM_flag = 0; move16(); - if ( LT_16( s_min( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 27853 /* 0.85f in Q15 */ ) && LT_16( s_max( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 30147 /* 0.92f in Q15 */ ) && - ( GT_32( *tdm_LT_es_em, ONE_IN_Q22 /* 2.0f in Q21 */ ) || GT_32( es_em_fx, 5242880 /* 2.5f in Q21 */ ) ) && ( LE_16( sts[0]->hVAD->hangover_cnt, 1 ) && LE_16( sts[1]->hVAD->hangover_cnt, 3 ) && sts[0]->tdm_LRTD_flag == 0 ) ) + + test(); + test(); + test(); + test(); + test(); + test(); + IF( LT_16( s_min( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 27853 /* 0.85f in Q15 */ ) && LT_16( s_max( sts[0]->old_corr_fx, sts[1]->old_corr_fx ), 30147 /* 0.92f in Q15 */ ) && + ( GT_32( *tdm_LT_es_em, ONE_IN_Q22 /* 2.0f in Q21 */ ) || GT_32( es_em_fx, 5242880 /* 2.5f in Q21 */ ) ) && ( LE_16( sts[0]->hVAD->hangover_cnt, 1 ) && LE_16( sts[1]->hVAD->hangover_cnt, 3 ) && sts[0]->tdm_LRTD_flag == 0 ) ) { tmp_SM_flag = 1; move16(); @@ -951,6 +958,9 @@ static Word16 Get_dt_lt_ener_fx( IF( NE_16( tmp_SM_flag, tdm_SM_flag_loc ) ) { + test(); + test(); + test(); IF( GE_16( *tdm_hyst_cnt, 2 ) && EQ_16( tmp_SM_flag, 1 ) && ( GT_16( sts[0]->tdm_pc, PC_LIMIT ) || GT_16( sts[1]->tdm_pc, PC_LIMIT ) ) ) { tdm_hyst_cnt++; @@ -975,7 +985,7 @@ static Word16 Get_dt_lt_ener_fx( move16(); } - return tmp_SM_flag; + return tmp_SM_flag; /* Q0 */ } @@ -987,13 +997,13 @@ static Word16 Get_dt_lt_ener_fx( static void NOOP_decision_fx( CPE_ENC_HANDLE hCPE, - const Word16 tdm_NOOP_flag_loc, - const Word16 tmp_SM_flag, - const Word32 rms_L, + const Word16 tdm_NOOP_flag_loc, /* Q0 */ + const Word16 tmp_SM_flag, /* Q0 */ + const Word32 rms_L, /* q_rms_L */ const Word16 q_rms_L, - const Word32 rms_R, + const Word32 rms_R, /* q_rms_R */ const Word16 q_rms_R, - Word16 *tdm_SM_flag_loc ) + Word16 *tdm_SM_flag_loc /* Q0 */ ) { Word16 tdm_NOOP_switch_flag; STEREO_TD_ENC_DATA_HANDLE hStereoTD; @@ -1008,6 +1018,14 @@ static void NOOP_decision_fx( move16(); IF( hCPE->hCoreCoder[0]->sp_aud_decision0 == 0 ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( ( GT_16( hStereoTD->tdm_SM_last2_clas[0], VOICED_TRANSITION ) && ( hStereoTD->tdm_SM_last_clas[0] == UNVOICED_CLAS || EQ_16( hStereoTD->tdm_SM_last_clas[0], VOICED_TRANSITION ) ) ) || ( GT_16( hStereoTD->tdm_SM_last2_clas[1], VOICED_TRANSITION ) && ( hStereoTD->tdm_SM_last_clas[1] == UNVOICED_CLAS || EQ_16( hStereoTD->tdm_SM_last_clas[1], VOICED_TRANSITION ) ) ) ) && ( !( EQ_16( sts[0]->last_coder_type_raw, VOICED ) || EQ_16( sts[1]->last_coder_type_raw, VOICED ) ) && GT_16( hStereoTD->tdm_NOOP_cnt, 5 ) ) ) @@ -1082,6 +1100,8 @@ static void NOOP_decision_fx( } } + test(); + test(); IF( GT_16( hStereoTD->tdm_SM_flag, 0 ) && EQ_16( tdm_NOOP_switch_flag, 1 ) && NE_16( *tdm_SM_flag_loc, tmp_SM_flag ) ) { *tdm_SM_flag_loc = !( *tdm_SM_flag_loc ); @@ -1130,25 +1150,25 @@ static void NOOP_decision_fx( static Word32 Comp_diff_lt_corr_fx( CPE_ENC_HANDLE hCPE, - const Word16 IsSideMono, - const Word32 rms_L, + const Word16 IsSideMono, /* Q0 */ + const Word32 rms_L, /* q_rms_L */ const Word16 q_rms_L, - const Word32 rms_R, + const Word32 rms_R, /* q_rms_R */ const Word16 q_rms_R, - const Word32 ener_L_dt, - const Word32 ener_R_dt, - Word32 corr_LM, + const Word32 ener_L_dt, /* Q16 */ + const Word32 ener_R_dt, /* Q16 */ + Word32 corr_LM, /* q_corr_LM */ Word16 q_corr_LM, - Word32 corr_RM, + Word32 corr_RM, /* q_corr_RM */ Word16 q_corr_RM, - const Word32 tdm_lt_rms_L, - const Word32 tdm_lt_rms_R, - Word32 *tdm_lt_corr_LM, - Word32 *tdm_lt_corr_RM, - Word32 *tdm_last_diff_lt_corr, + const Word32 tdm_lt_rms_L, /* Q16 */ + const Word32 tdm_lt_rms_R, /* Q16 */ + Word32 *tdm_lt_corr_LM, /* Q24 */ + Word32 *tdm_lt_corr_RM, /* Q24 */ + Word32 *tdm_last_diff_lt_corr, /* q_tdm_last_diff_lt_corr */ Word16 *q_tdm_last_diff_lt_corr, - Word32 *inst_ratio_L_out, - Word32 *diff_lt_corr, + Word32 *inst_ratio_L_out, /* Q24 */ + Word32 *diff_lt_corr, /* q_d_lt_corr_raw */ Word16 *q_d_lt_corr_raw ) { Encoder_State **sts; @@ -1177,7 +1197,9 @@ static Word32 Comp_diff_lt_corr_fx( * adaptation rate factor is lower. This prevent stereo image * move on speech offset *----------------------------------------------------------------*/ - + test(); + test(); + test(); IF( IsSideMono == 0 && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) && ( GT_32( L_shr( tdm_lt_rms_R, Q1 ), tdm_lt_rms_L ) || GT_32( L_shr( tdm_lt_rms_L, Q1 ), tdm_lt_rms_R ) ) ) { adaprate_fx = L_add( Mpy_32_32( M_ADAP_FX_Q31, L_max( tdm_lt_rms_R, tdm_lt_rms_L ) ), B_ADAP_FX_Q16 ); // Q16 @@ -1193,7 +1215,10 @@ static Word32 Comp_diff_lt_corr_fx( * In case of unvoiced content (expect when it is part of an onset), * the adaptation rate is minimal. *----------------------------------------------------------------*/ - + test(); + test(); + test(); + test(); IF( GT_16( sts[0]->ini_frame, 2 ) && ( ( LE_16( sts[0]->last_clas, VOICED_TRANSITION ) && sts[0]->hVAD->hangover_cnt == 0 ) || ( LE_16( sts[1]->last_clas, VOICED_TRANSITION ) && sts[1]->hVAD->hangover_cnt == 0 ) ) ) @@ -1203,9 +1228,14 @@ static Word32 Comp_diff_lt_corr_fx( d_lt_corr_raw_fx = 0; move32(); + IF( IsSideMono == 0 ) { - if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) || ( ( LT_32( tdm_lt_rms_R, ONE_IN_Q16 ) || LT_32( tdm_lt_rms_L, ONE_IN_Q16 ) ) && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) && LT_32( L_max( tdm_lt_rms_R, tdm_lt_rms_L ), TEN_IN_Q16 ) ) ) + test(); + test(); + test(); + test(); + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) || ( ( LT_32( tdm_lt_rms_R, ONE_IN_Q16 ) || LT_32( tdm_lt_rms_L, ONE_IN_Q16 ) ) && EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) && LT_32( L_max( tdm_lt_rms_R, tdm_lt_rms_L ), TEN_IN_Q16 ) ) ) { adaprate_fx = 64225; /* 0.98f in Q16 */ /* speed up the adaptation of the long term values to the current values after coming from DFT */ move32(); @@ -1242,13 +1272,13 @@ static Word32 Comp_diff_lt_corr_fx( corr_LM = BASOP_Util_Add_Mant32Exp( Mpy_32_32( adaprate_fx, corr_LM ), sub( Q31, sub( q_corr_LM, Q15 ) ), Mpy_32_32( madaprate_fx, *tdm_lt_corr_LM ), Q31 - Q9, &exp_diff ); // Q31 - exp_diff q_corr_LM = sub( Q31, exp_diff ); - L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_LM ); // Q24 - L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_LM ); // q_corr_LM - diff_lt_corr_LM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_LM ), &exp_diff ); + L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_LM ); // Q24 + L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_LM ); // q_corr_LM + diff_lt_corr_LM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_LM ), &exp_diff ); /* Q31-exp_diff */ q_diff_lt_corr_LM_tmp = sub( Q31, exp_diff ); - L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_RM ); // Q24 - L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_RM ); // q_corr_RM - diff_lt_corr_RM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_RM ), &exp_diff ); + L_tmp = Mpy_32_32( ALP_REF_FX_Q31, *tdm_lt_corr_RM ); // Q24 + L_tmp1 = Mpy_32_32( BET_REF_FX_Q31, corr_RM ); // q_corr_RM + diff_lt_corr_RM_tmp_fx = BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q24, L_tmp1, sub( Q31, q_corr_RM ), &exp_diff ); /* Q31-exp_diff */ q_diff_lt_corr_RM_tmp = sub( Q31, exp_diff ); diff_lt_corr_tmp_fx = BASOP_Util_Add_Mant32Exp( diff_lt_corr_LM_tmp_fx, sub( Q31, q_diff_lt_corr_LM_tmp ), L_negate( diff_lt_corr_RM_tmp_fx ), sub( Q31, q_diff_lt_corr_RM_tmp ), &exp_diff ); // (Q31 - exp_diff) q_diff_lt_corr_tmp = sub( Q31, exp_diff ); @@ -1267,7 +1297,7 @@ static Word32 Comp_diff_lt_corr_fx( move16(); shift = sub( q_d_lt_corr, Q31 ); } - *tdm_last_diff_lt_corr = diff_lt_corr_tmp_fx; + *tdm_last_diff_lt_corr = diff_lt_corr_tmp_fx; /* q_tdm_last_diff_lt_corr */ move32(); *q_tdm_last_diff_lt_corr = q_diff_lt_corr_tmp; move16(); @@ -1275,7 +1305,18 @@ static Word32 Comp_diff_lt_corr_fx( /*----------------------------------------------------------------* * Correct the estimation depending of channels energies evolution *----------------------------------------------------------------*/ - + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( IsSideMono, 1 ) && ( ( LT_32( L_shl( rms_L, sub( Q21, q_rms_L ) ), RMS_MIN2_FX_Q21 ) && LT_32( L_shl( rms_R, sub( Q21, q_rms_R ) ), RMS_MIN2_FX_Q21 ) ) && @@ -1307,9 +1348,9 @@ static Word32 Comp_diff_lt_corr_fx( ) { /* Use estimated results */ - *tdm_lt_corr_LM = L_shl( diff_lt_corr_LM_tmp_fx, sub( Q24, q_diff_lt_corr_LM_tmp ) ); + *tdm_lt_corr_LM = L_shl( diff_lt_corr_LM_tmp_fx, sub( Q24, q_diff_lt_corr_LM_tmp ) ); /* Q24 */ move32(); - *tdm_lt_corr_RM = L_shl( diff_lt_corr_RM_tmp_fx, sub( Q24, q_diff_lt_corr_RM_tmp ) ); + *tdm_lt_corr_RM = L_shl( diff_lt_corr_RM_tmp_fx, sub( Q24, q_diff_lt_corr_RM_tmp ) ); /* Q24 */ move32(); } ELSE @@ -1340,23 +1381,26 @@ static Word32 Comp_diff_lt_corr_fx( *-------------------------------------------------------------------*/ static Word16 limit_idx_Dwnmix_fx( - const Word16 idx_in, - const Word16 unclr_decision, - const Word16 inst_idx, - const Word16 previous_idx, - const Word16 tdm_last_LRTD_PriCh_cnt, - const Word16 tdm_last_LRTD_frame_cnt ) + const Word16 idx_in, /* Q0 */ + const Word16 unclr_decision, /* Q0 */ + const Word16 inst_idx, /* Q0 */ + const Word16 previous_idx, /* Q0 */ + const Word16 tdm_last_LRTD_PriCh_cnt, /* Q0 */ + const Word16 tdm_last_LRTD_frame_cnt /* Q0 */ ) { Word16 idx; idx = idx_in; move16(); - idx = check_bounds_s_fx( idx, 1, 29 ); + idx = check_bounds_s_fx( idx, 1, 29 ); /* Q0 */ + test(); IF( EQ_16( unclr_decision, 1 ) && GT_16( tdm_last_LRTD_frame_cnt, 1 ) ) { IF( tdm_last_LRTD_PriCh_cnt > 0 ) { + test(); + test(); IF( LE_16( idx, LRTD_STEREO_MID_IS_PRIM ) && LT_16( inst_idx, LRTD_STEREO_MID_IS_PRIM + 2 ) ) { idx = s_min( 1, idx ); @@ -1386,7 +1430,7 @@ static Word16 limit_idx_Dwnmix_fx( } } - return idx; + return idx; /* Q0 */ } @@ -1396,9 +1440,9 @@ static Word16 limit_idx_Dwnmix_fx( *-------------------------------------------------------------------*/ static Word16 limit_idx_NoDwnmix_fx( - const Word16 idx_in, /* i : Index */ - const Word16 side_can_change, /* i : Primary and secondary channel allowed to change ? */ - const Word32 d_lt_corr_raw, /* i : Raw corrrelation differences */ + const Word16 idx_in, /* i : Index Q0*/ + const Word16 side_can_change, /* i : Primary and secondary channel allowed to change ? Q0*/ + const Word32 d_lt_corr_raw, /* i : Raw corrrelation differences q_d_lt_corr_raw*/ const Word16 q_d_lt_corr_raw /* i : Q-factor of Raw corrrelation differences */ ) { @@ -1406,11 +1450,14 @@ static Word16 limit_idx_NoDwnmix_fx( idx = idx_in; move16(); + + test(); + test(); IF( side_can_change == 0 && GT_16( idx_in, 10 ) && LT_16( idx_in, 20 ) ) { idx = 30; move16(); - if ( LT_32( d_lt_corr_raw, L_negate( L_shl( 214748365 /* 0.1f in Q31 */, sub( q_d_lt_corr_raw, Q31 ) ) ) ) ) + IF( LT_32( d_lt_corr_raw, L_negate( L_shl( 214748365 /* 0.1f in Q31 */, sub( q_d_lt_corr_raw, Q31 ) ) ) ) ) { idx = 0; move16(); @@ -1430,7 +1477,7 @@ static Word16 limit_idx_NoDwnmix_fx( } } - return idx; + return idx; /* Q0 */ } @@ -1443,8 +1490,8 @@ static Word16 limit_idx_NoDwnmix_fx( static Word16 stereo_tdm_ener_analysis_SM_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ Encoder_State **sts, /* i/o: Encoder static variables structure */ - const Word16 input_frame, /* i : Number of samples */ - Word16 *tdm_SM_flag /* i/o: channel combination scheme flag */ + const Word16 input_frame, /* i : Number of samples Q0*/ + Word16 *tdm_SM_flag /* i/o: channel combination scheme flag Q0*/ ) { Word32 rms_R_fx, rms_L_fx; @@ -1473,7 +1520,7 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( *----------------------------------------------------------------*/ /* Simple logic to set SM flag, should be done in the frequency domain for low SM correlation signal, especially for music item such as Music_1_org_s */ - tdm_SM_flag_loc = hStereoTD->tdm_last_SM_flag_noop; + tdm_SM_flag_loc = hStereoTD->tdm_last_SM_flag_noop; /* Q0 */ move16(); /*----------------------------------------------------------------* @@ -1515,27 +1562,38 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( * When the energies of channels are low enough, compute the ratio * of L and R needed to create new mono/side signals *----------------------------------------------------------------*/ - + test(); + test(); + test(); IF( ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q20 - Q24 ), RMS_MIN_FX_Q20 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q19 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN_FX_Q20 ) ) || - ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q20 - Q24 ), RMS_MIN_FX_Q20 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q19 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN_FX_Q20 ) ) ) + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q20 - Q24 ), RMS_MIN_FX_Q20 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q19 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN_FX_Q20 ) ) ) /* Q20 */ { - if ( ( LT_16( sts[0]->old_corr_fx, CORR_THRES_FX_Q15 ) && LT_16( sts[1]->old_corr_fx, CORR_THRES_FX_Q15 ) ) || - ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) ) ) + test(); + test(); + test(); + IF( ( LT_16( sts[0]->old_corr_fx, CORR_THRES_FX_Q15 ) && LT_16( sts[1]->old_corr_fx, CORR_THRES_FX_Q15 ) ) || + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) ) ) { side_can_change = 1; move16(); } } + test(); + test(); + test(); IF( ( LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q20 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN2_FX_Q21 ) ) || - ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q20 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN2_FX_Q21 ) ) ) + ( LE_32( L_shl( hStereoTD->tdm_lt_rms_R_SM_fx, Q21 - Q24 ), RMS_MIN2_FX_Q21 ) && LE_32( L_shl( hStereoTD->tdm_lt_rms_L_SM_fx, Q20 /* adjusted for 2 in RHS */ - Q24 ), RMS_MIN2_FX_Q21 ) ) ) /* Q21 */ { + test(); + test(); + test(); IF( ( ( NE_16( hStereoTD->tdm_last_SM_flag_noop, tdm_SM_flag_loc ) ) && hStereoTD->tdm_noop_cnt == 0 ) || EQ_16( hStereoTD->tdm_noop_mov_flag, 1 ) || NE_16( hStereoTD->tdm_prev_desired_idx_SM, hStereoTD->tdm_prev_stable_idx_SM ) ) { hStereoTD->tdm_noop_mov_flag = 1; move16(); - if ( hStereoTD->tdm_last_ratio_idx_SM != 0 && NE_16( hStereoTD->tdm_last_ratio_idx_SM, ( TDM_NQ - 1 ) ) ) + IF( hStereoTD->tdm_last_ratio_idx_SM != 0 && NE_16( hStereoTD->tdm_last_ratio_idx_SM, ( TDM_NQ - 1 ) ) ) { side_can_change = 1; move16(); @@ -1543,7 +1601,8 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( } } - if ( side_can_change == 0 && EQ_16( tdm_SM_flag_loc, 1 ) && GT_32( es_em_fx, 31457280 /* 15.0f in Q21 */ ) ) + test(); + IF( side_can_change == 0 && EQ_16( tdm_SM_flag_loc, 1 ) && GT_32( es_em_fx, 31457280 /* 15.0f in Q21 */ ) ) { side_can_change = 1; move16(); @@ -1584,7 +1643,7 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( } } - idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx_SM, &hStereoTD->tdm_noop_mov_flag, hStereoTD->tdm_last_ratio_idx_SM, &hStereoTD->tdm_prev_desired_idx_SM, &hStereoTD->tdm_noop_cnt, tdm_SM_flag_loc, desired_idx ); + idx = stereo_smooth_LR_transition_fx( &hStereoTD->tdm_prev_stable_idx_SM, &hStereoTD->tdm_noop_mov_flag, hStereoTD->tdm_last_ratio_idx_SM, &hStereoTD->tdm_prev_desired_idx_SM, &hStereoTD->tdm_noop_cnt, tdm_SM_flag_loc, desired_idx ); /* Q0 */ idx = extract_l( L_add( Mpy_32_32( 1717986918 /* 0.8f in Q31 */, idx ), Mpy_32_32( 429496729 /* 0.2f in Q31 */, hStereoTD->tdm_last_ratio_idx_SM ) ) ); // (Q31, Q0) -> Q0 @@ -1598,6 +1657,9 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( move16(); } + test(); + test(); + test(); IF( ( EQ_16( hStereoTD->tdm_noop_mov_flag, 1 ) && GE_16( hStereoTD->tdm_noop_cnt, 31 ) ) || ( ( EQ_16( hStereoTD->tdm_last_SM_flag_noop, tdm_SM_flag_loc ) ) && ( EQ_16( idx, hStereoTD->tdm_prev_stable_idx_SM ) ) ) ) { hStereoTD->tdm_noop_cnt = 0; @@ -1606,6 +1668,7 @@ static Word16 stereo_tdm_ener_analysis_SM_fx( move16(); } + test(); if ( hStereoTD->tdm_noop_mov_flag == 0 || tdm_SM_flag_loc == 0 ) { hStereoTD->tdm_prev_stable_idx_SM = idx; @@ -1634,11 +1697,11 @@ Word16 tdm_lp_comparison_fx( Word32 *speech_buff, /* i : Current speech frame Q_speech */ const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ - const Word16 m, /* i : filter length */ + const Word16 m, /* i : filter length Q0*/ const Word16 *isp_PCh_fx, /* i : primary channel LSPs Q15 */ const Word16 *isp_SCh_fx, /* i : secondary channel LSPs Q15 */ - const Word16 L_frame, /* i : frame length */ - const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ + const Word16 L_frame, /* i : frame length Q0*/ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata Q0*/ Word16 Q_speech ) { Word32 ener_sig_fx, pred_gain_reuse_PCh_fx, log10_fx, predgain_SCh_fx; @@ -1657,7 +1720,7 @@ Word16 tdm_lp_comparison_fx( // residu( A_SCh, m, speech, res, L_frame ); Word16 gb = find_guarded_bits_fx( L_frame ); - scale_sig32( speech_buff, L_FRAME + M, gb1 ); + scale_sig32( speech_buff, L_FRAME + M, gb1 ); /* Q_speech + gb1 */ Word16 exp = sub( 31, Q_speech ); Word32 sum2_value = sum2_32_exp_fx( speech_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb IF( LT_16( exp, -5 ) ) /*maximum q to prevent 0.01 from saturating is 37, since we are adding it headroom of 1 is required*/ @@ -1666,28 +1729,28 @@ Word16 tdm_lp_comparison_fx( exp = -5; move16(); } - sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q31 - Q15, &exp ); - Word32 temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); - ener_sig_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q16, &exp ); /* Q31-exp */ + Word32 temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); /* Q25 */ + ener_sig_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 // ener_sig = log10f( sum2_f( speech, L_frame ) + 0.01f ); exp = sub( 31, sub( Q_speech, gb1 ) ); - sum2_value = sum2_32_exp_fx( res_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb - sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q31 - Q15, &exp ); - temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); - log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 - predgain_SCh_fx = Mpy_32_32( L_sub( ener_sig_fx, log10_fx ), 1342177280 ); // Q27+Q25-31 = Q21 + sum2_value = sum2_32_exp_fx( res_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb + sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q16, &exp ); /* Q31-exp */ + temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); /* Q25 */ + log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + predgain_SCh_fx = Mpy_32_32( L_sub( ener_sig_fx, log10_fx ), 1342177280 ); // Q27+Q25-31 = Q21 // pred_gain_reuse_PCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); // predgain_SCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); /* Find prediction gain when resuing the Primary Channel LP filter */ // residu( A_PCh, m, speech, res, L_frame ); - scale_sig32( speech_buff, L_FRAME + M, negate( gb1 ) ); + scale_sig32( speech_buff, L_FRAME + M, negate( gb1 ) ); /* Q_speech */ residu_ivas_fx( A_PCh_fx, sub( 14, norm_s( A_PCh_fx[0] ) ), m, speech_fx, res_fx, L_frame ); exp = sub( 31, sub( Q_speech, gb1 ) ); sum2_value = sum2_32_exp_fx( res_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb - sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q31 - Q15, &exp ); - temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); - log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + sum2_value = BASOP_Util_Add_Mant32Exp( sum2_value, exp, 328, Q16, &exp ); + temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); /* Q25 */ + log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 pred_gain_reuse_PCh_fx = Mpy_32_32( L_sub( ener_sig_fx, log10_fx ), 1342177280 ); // Q27+Q25-31 = Q21 // pred_gain_reuse_PCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); @@ -1699,7 +1762,7 @@ Word16 tdm_lp_comparison_fx( FOR( i = 0; i < m; i++ ) { // ftmp = isp_SCh[i] - isp_PCh[i]; - ftmp_fx = L_deposit_h( sub( isp_SCh_fx[i], isp_PCh_fx[i] ) ); + ftmp_fx = L_deposit_h( sub( isp_SCh_fx[i], isp_PCh_fx[i] ) ); /* Q31 */ // dist += ftmp * ftmp; dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( ftmp_fx, ftmp_fx ), gb ) ); // Q31-gb } @@ -1738,9 +1801,9 @@ Word16 tdm_lp_comparison_fx( test(); test(); - if ( ( GE_32( element_brate_wo_meta, IVAS_48k ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb ) ) ) ) || - ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && LT_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, add( gb, 1 ) ) ) ) ) || - ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && GE_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_LRTD_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb + 2 ) ) ) ) || st->tc_cnt > 0 ) + IF( ( GE_32( element_brate_wo_meta, IVAS_48k ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb ) ) ) ) || + ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && LT_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, add( gb, 1 ) ) ) ) ) || + ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && GE_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_LRTD_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb + 2 ) ) ) ) || st->tc_cnt > 0 ) { LP_mode = 0; move16(); @@ -1776,14 +1839,14 @@ void tdm_ol_pitch_comparison_fx( st0 = hCPE->hCoreCoder[0]; /* Encoder structure - primary channel */ st1 = hCPE->hCoreCoder[1]; /* Encoder structure - secondary channel */ - if ( GT_32( hCPE->element_brate, IVAS_13k2 ) ) + IF( GT_32( hCPE->element_brate, IVAS_13k2 ) ) { diff_thr = 3; move16(); } test(); - if ( GE_32( hCPE->element_brate, IVAS_48k ) || EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) + IF( GE_32( hCPE->element_brate, IVAS_48k ) || EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) { diff_thr = 1; move16(); @@ -1819,12 +1882,12 @@ void tdm_ol_pitch_comparison_fx( test(); IF( GE_16( voicmin[0], 29491 /* 0.9f in Q15 */ ) && GE_16( voicmin[1], 29491 /* 0.9f in Q15 */ ) && GE_16( voicmin[2], 27853 /* 0.85f in Q15 */ ) && GE_16( voicmin[3], 27853 /* 0.85f in Q15 */ ) ) { - tmp_diff = add( abs_s( sub( st0->pitch[0], st1->pitch[0] ) ), add( abs_s( sub( st0->pitch[1], st1->pitch[1] ) ), abs_s( sub( st0->pitch[2], st1->pitch[2] ) ) ) ); + tmp_diff = add( abs_s( sub( st0->pitch[0], st1->pitch[0] ) ), add( abs_s( sub( st0->pitch[1], st1->pitch[1] ) ), abs_s( sub( st0->pitch[2], st1->pitch[2] ) ) ) ); /* Q0 */ } } ELSE { - tmp_diff = abs_s( sub( add( st0->pitch[0], add( st0->pitch[1], st0->pitch[2] ) ), add( st1->pitch[0], add( st1->pitch[1], st1->pitch[2] ) ) ) ); + tmp_diff = abs_s( sub( add( st0->pitch[0], add( st0->pitch[1], st0->pitch[2] ) ), add( st1->pitch[0], add( st1->pitch[1], st1->pitch[2] ) ) ) ); /* Q0 */ } IF( LE_16( tmp_diff, diff_thr ) ) @@ -1833,23 +1896,23 @@ void tdm_ol_pitch_comparison_fx( move16(); /* 1/4 pitch precision update*/ - Copy( st0->pitch, st1->pitch, 3 ); - Copy( st0->voicing_fx, st1->voicing_fx, 3 ); + Copy( st0->pitch, st1->pitch, 3 ); /* Q0 */ + Copy( st0->voicing_fx, st1->voicing_fx, 3 ); /* Q15 */ /* Update some parameters accordingly */ - st1->old_corr_fx = st0->old_corr_fx; - st1->old_thres_fx = st0->old_thres_fx; - st1->delta_pit = st0->delta_pit; + st1->old_corr_fx = st0->old_corr_fx; /* Q15 */ + st1->old_thres_fx = st0->old_thres_fx; /* Q15 */ + st1->delta_pit = st0->delta_pit; /* Q0 */ move16(); move16(); move16(); /* Updates for adaptive lag window memory */ - st1->old_pitch_la = st0->old_pitch_la; + st1->old_pitch_la = st0->old_pitch_la; /* Q0 */ move16(); /* 1/4 pitch precision update*/ - Copy( pitch_fr[0], pitch_fr[1], NB_SUBFR ); - Copy( voicing_fr[0], voicing_fr[1], NB_SUBFR ); + Copy( pitch_fr[0], pitch_fr[1], NB_SUBFR ); /* Q6 */ + Copy( voicing_fr[0], voicing_fr[1], NB_SUBFR ); /* Q15 */ } } @@ -1863,15 +1926,15 @@ void tdm_ol_pitch_comparison_fx( *-------------------------------------------------------------------*/ static void Get_corr_n_fx( - const Word16 L[], /* i : Left signal */ - const Word16 R[], /* i : Right signal */ - Word32 *ic_Lm, /* o : Left signal */ + const Word16 L[], /* i : Left signal q_in*/ + const Word16 R[], /* i : Right signal q_in*/ + Word32 *ic_Lm, /* o : Left signal q_ic_Lm*/ Word16 *q_ic_Lm, /* o : Q factor of Left signal */ - Word32 *ic_Rm, /* o : Right signal */ + Word32 *ic_Rm, /* o : Right signal q_ic_Rm*/ Word16 *q_ic_Rm, /* o : Q factor of Right signal */ - const Word16 len, /* i : segment length */ + const Word16 len, /* i : segment length Q0*/ Word32 *es_em, /* o : return the difference between the side and mono energy */ - const Word16 tdm_SM_calc_flag /* i : Flag that indicates that it is for SM mode */ + const Word16 tdm_SM_calc_flag /* i : Flag that indicates that it is for SM mode Q0*/ ) { Word32 corrL, corrR, ener; @@ -1892,7 +1955,7 @@ static void Get_corr_n_fx( move64(); W_ener_side = EPSILON_FX; move64(); - guard_bits = sub( 32, find_guarded_bits_fx( len ) ); + guard_bits = sub( 32, find_guarded_bits_fx( len ) ); /* Q0 */ /*----------------------------------------------------------------* * Find the normalized correlation between: left/mono and right/mono based @@ -1910,8 +1973,8 @@ static void Get_corr_n_fx( W_ener_side = W_mac0_16_16( W_ener_side, side_i, side_i ); // (q_in + q_in ) } /* Scaling back to the original proposal */ - corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); - corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); + corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); /* 2*q_in + guard_bits - 32 */ + corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); /* 2*q_in + guard_bits - 32 */ ener = W_extract_h( W_shl( W_ener, guard_bits ) ); ener_side = W_extract_h( W_shl( W_ener_side, guard_bits ) ); } @@ -1927,8 +1990,8 @@ static void Get_corr_n_fx( W_ener_side = W_mac0_16_16( W_ener_side, side_i, side_i ); // (q_in + q_in ) } /* Scaling back to the original proposal */ - corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); - corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); + corrL = W_extract_h( W_shl( W_corrL, guard_bits ) ); /* 2*q_in + guard_bits - 32 */ + corrR = W_extract_h( W_shl( W_corrR, guard_bits ) ); /* 2*q_in + guard_bits - 32 */ ener = W_extract_h( W_shl( W_ener, guard_bits ) ); ener_side = W_extract_h( W_shl( W_ener_side, guard_bits ) ); } @@ -1976,9 +2039,9 @@ static void Get_corr_n_fx( /* *es_em = 10 * ( log10f( sqrtf( ener_side / len ) ) - log10f( sqrtf( ener / len ) ) ); is simplified to *es_em = 10 * ( log10f( sqrtf( ener_side / ener ) ) ); */ - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ener_side, ener, &exp_diff ); // (Q31 - exp_diff) - L_tmp = Sqrt32( L_tmp, &exp_diff ); - L_tmp = BASOP_Util_Log2( L_tmp ); + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ener_side, ener, &exp_diff ); // (Q31 - exp_diff) + L_tmp = Sqrt32( L_tmp, &exp_diff ); /* (Q31 - exp_diff) */ + L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ *es_em = Mpy_32_32( Mpy_32_32( L_add( L_tmp, L_shl( exp_diff, Q25 ) ), LOG10_2_Q31 ), TEN_IN_Q27 ); // (Q25, Q27) -> Q21 move32(); } @@ -1994,24 +2057,24 @@ static void Get_corr_n_fx( /*! r: smoothed position */ static Word16 stereo_smooth_LR_transition_fx( - Word16 *tdm_prev_stable_idx, /* i/o: Previous Transmitted ratio index */ - Word16 *tdm_ratio_transition_mov_flag, /* i/o: Flag that indicates that L-R energy is changing */ - Word16 tdm_last_ratio_idx, /* i : last TDM ratio index */ - Word16 *tdm_prev_desired_idx, /* i/o: Previous Transmitted ratio index */ - Word16 *tdm_ratio_transition_cnt, /* i/o: Counter */ - const Word16 tdm_SM_flag, /* i : channel combination scheme flag for current frame */ - Word16 desired_idx /* i : desired final position */ + Word16 *tdm_prev_stable_idx, /* i/o: Previous Transmitted ratio index Q0*/ + Word16 *tdm_ratio_transition_mov_flag, /* i/o: Flag that indicates that L-R energy is changing Q0*/ + Word16 tdm_last_ratio_idx, /* i : last TDM ratio index Q0*/ + Word16 *tdm_prev_desired_idx, /* i/o: Previous Transmitted ratio index Q0*/ + Word16 *tdm_ratio_transition_cnt, /* i/o: Counter Q0*/ + const Word16 tdm_SM_flag, /* i : channel combination scheme flag for current frame Q0*/ + Word16 desired_idx /* i : desired final position Q0*/ ) { Word16 idx; - if ( EQ_16( tdm_SM_flag, 1 ) ) + IF( EQ_16( tdm_SM_flag, 1 ) ) { desired_idx = 15; move16(); } - if ( NE_16( desired_idx, *tdm_prev_stable_idx ) ) + IF( NE_16( desired_idx, *tdm_prev_stable_idx ) ) { *tdm_ratio_transition_mov_flag = 1; move16(); diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 5b19a7a0a61873379c440eaa96fce14dc49afe90..c8709db475c613663de4d79c1ec64b4dc06681b9 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1060,6 +1060,8 @@ Word16 ivas_acelp_tcx20_switching_fx( ener = Mpy_32_16_1( Mpy_32_16_1( ener, 0x78AE ), getInvFrameLen( L_frame ) ); /* 0x78AE -> sqrt(2)/12 (Q18) */ ener_e = sub( s, 9 ); + x_fx = hTcxEnc->spectrum_long_fx; + IF( !flag_16k_smc ) { const Word16 *bands; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1fabebb7bb04ad820e9eced488964c77675696f0..1bc7536b8851c331dbc33f200d48995814949b4a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1275,6 +1275,13 @@ Word16 SQ_gain_fx( /* o : SQ gain */ Word16 lg, /* i : vector size (2048 max) */ Word16 *gain_e ); /* o : SQ gain exponent */ +Word16 SQ_gain_ivas_fx( /* o : SQ gain */ + Word32 x[], /* i : vector to quantize */ + Word16 x_e, /* i : exponent */ + Word16 nbitsSQ, /* i : number of bits targeted */ + Word16 lg, /* i : vector size (2048 max) */ + Word16 *gain_e ); /* o : SQ gain exponent */ + Word16 SQ_gain_estimate_fx( /* o : SQ gain */ Word32 x[], /* i : vector to quantize */ Word16 x_e, /* i : exponent */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index ad19753b5a397f61db9b7e46621daeeed71d4533..c85c7236e01c1d112ad50ba9b9294d4b6ebed104 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -693,6 +693,121 @@ Word16 SQ_gain_fx( /* output: SQ gain */ return tmp16; } +Word16 SQ_gain_ivas_fx( /* output: SQ gain */ + Word32 x[], /* input: vector to quantize */ + Word16 x_e, /* input: exponent */ + Word16 nbitsSQ, /* input: number of bits targeted */ + Word16 lg, /* input: vector size (2048 max) */ + Word16 *gain_e ) /* output: SQ gain exponent */ +{ + Word16 i, iter, lg_4, s, tmp16; + Word32 ener, tmp32; + Word32 target, fac, offset; + Word32 en[N_MAX / 4]; + + + lg_4 = shr( lg, 2 ); + + /* energy of quadruples with 9dB offset */ + FOR( i = 0; i < lg_4; i++ ) + { + /* normalization */ + s = 15; + move16(); + + tmp16 = norm_l( x[0] ); + if ( x[0] != 0 ) + s = s_min( s, tmp16 ); + + tmp16 = norm_l( x[1] ); + if ( x[1] != 0 ) + s = s_min( s, tmp16 ); + + tmp16 = norm_l( x[2] ); + if ( x[2] != 0 ) + s = s_min( s, tmp16 ); + + tmp16 = norm_l( x[3] ); + if ( x[3] != 0 ) + s = s_min( s, tmp16 ); + + s = sub( s, 2 ); /* 2 bits headroom */ + + /* calc quadruple energy */ + ener = L_deposit_l( 1 ); + + tmp16 = extract_h( L_shl( x[0], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); + + tmp16 = extract_h( L_shl( x[1], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); + + tmp16 = extract_h( L_shl( x[2], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); + + tmp16 = extract_h( L_shl( x[3], s ) ); + ener = L_mac( ener, tmp16, tmp16 ); + + s = shl( sub( x_e, s ), 1 ); + + /* log */ + IF( EQ_16( ener, 1 ) ) + { + en[i] = -131072; /* log10(0.01) in Q16 */ + move32(); + } + ELSE + { + tmp32 = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( s ), 25 ) ); /* log2, 6Q25 */ + en[i] = L_shr( tmp32, 9 ); /* 15Q16 */ + move32(); + } + x += 4; + } + + /* SQ scale: 4 bits / 6 dB per quadruple */ + target = L_mult( 0x3FC8, sub( nbitsSQ, shr( lg, 4 ) ) ); /* 0x3FC8 -> 0.15*log2(10) */ + fac = L_add( 0x2A854B, 0 ); /* -> 12.8f*log2(10); */ + offset = L_add( fac, 0 ); + + /* find offset (0 to 128 dB with step of 0.125dB) */ + FOR( iter = 0; iter < 10; iter++ ) + { + fac = L_shr( fac, 1 ); + offset = L_sub( offset, fac ); + ener = L_deposit_l( 0 ); + + FOR( i = 0; i < lg_4; i++ ) + { + tmp32 = L_sub( en[i], offset ); + + /* avoid SV with 1 bin of amp < 0.5f */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ + { + ener = L_add( ener, tmp32 ); + } + + /* if ener is above target -> break and increase offset */ + IF( GT_32( ener, target ) ) + { + offset = L_add( offset, fac ); + BREAK; + } + } + } + + offset = L_add( L_shr( offset, 1 ), 0x17EB0 ); /* 0x17EB0 -> 0.45*log2(10) */ + + *gain_e = add( extract_h( offset ), 1 ); + move16(); + offset = L_sub( L_and( offset, 0xFFFF ), 0x10000 ); + tmp16 = extract_h( BASOP_Util_InvLog2( L_shl( offset, 9 ) ) ); + + /* return gain */ + + return tmp16; +} + Word16 SQ_gain_estimate_fx( /* output: SQ gain */ Word32 x[], /* input: vector to quantize */ Word16 x_e, /* input: exponent */