diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b554072343587a06c5f450f124676b3763827869..03bc3d6e5761cb47156dd15f849625fe99545cea 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3535,12 +3535,12 @@ void distribute_evenly_ism( ); -int16_t ivas_qmetadata_encode_extended_gr_length( +int16_t ivas_qmetadata_encode_extended_gr_length_fx( const uint16_t value, const uint16_t alphabet_size, const int16_t gr_param); -void ivas_qmetadata_encode_extended_gr( +void ivas_qmetadata_encode_extended_gr_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */ const uint16_t value, /* i : value to be encoded */ const uint16_t alphabet_size, /* i : alphabet size */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 3a22c5c721726926b0ade11621d4e478342ebbec..dd7191b3f61cfa26bdcae640ff4b286227e79268 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4633,13 +4633,12 @@ Word32 logsumexp_fx( const Word16 N /* i : number of elements in array x */ ); Word32 lin_interp32_fx( - const Word32 x, /* i : the value to be mapped */ - const Word32 x1, /* i : source range interval: low end */ - const Word32 y1, /* i : source range interval: high end */ - const Word32 x2, /* i : target range interval: low */ - const Word32 y2, /* i : target range interval: high */ - const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ - Word16 *Q_io /*i/o : i/o Q factor of the output*/ + const Word32 x, /* i : the value to be mapped */ + const Word32 x1, /* i : source range interval: low end */ + const Word32 y1, /* i : source range interval: high end */ + const Word32 x2, /* i : target range interval: low */ + const Word32 y2, /* i : target range interval: high */ + const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ ); void v_addc_fx( diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 73b85c7a529daaf94a6641cbf2a69d89c9621cc4..85d4332e0d8806efd57e95234d109bd47bf7a92a 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -280,8 +280,8 @@ void ivas_qmetadata_close_fx( /*! r: codeword index */ Word16 masa_sq_fx( - const Word32 in, /* i : input value */ - const Word32 *threshold, /* i : partition */ + const Word32 in, /* i : input value Q30*/ + const Word32 *threshold, /* i : partition Q30*/ const Word16 cb_sz /* i : codebook size */ ) { diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index 499585221bbb9c682fea3d63886c15bc0e54d5f9..c3608d2483461da35ca25d976d69b74c104eb179 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -668,15 +668,7 @@ Word16 quantize_phi_chan_compand_fx( delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); // Q22 // id_phi = (int16_t) round_f( ( phi / (float) delta_phi ) ); id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); // Q15 - IF( GE_16( abs_s( id_phi ), shl_sat( 1, sub( 15, tmp_e ) ) ) ) - { - id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0 - } - ELSE - { - id_phi = 0; - move16(); - } + id_phi = round_fx( L_shl( id_phi, add( tmp_e, 1 ) ) ); // Q0 IF( add( id_phi, shr( n, 1 ) ) < 0 ) { diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 5738b6feb7715c9474c06907d2ae9b6e3e46186a..8d486df04dd62d69e843008e92faa6cc86770729 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -834,21 +834,18 @@ Word32 logsumexp_fx( *---------------------------------------------------------------------*/ /*! r: mapped output value */ Word32 lin_interp32_fx( - const Word32 x, /* i : the value to be mapped Qin*/ - const Word32 x1, /* i : source range interval: low end Qin*/ - const Word32 y1, /* i : source range interval: high end Qin*/ - const Word32 x2, /* i : target range interval: low Qin*/ - const Word32 y2, /* i : target range interval: high Qin*/ - const Word16 flag_sat, /* i : flag to indicate whether to apply saturation Q0*/ - Word16 *Q_io /*i/o : i/o Q factor of the output*/ + const Word32 x, /* i : the value to be mapped Qx */ + const Word32 x1, /* i : source range interval: low end Qx */ + const Word32 y1, /* i : source range interval: high end Q31 */ + const Word32 x2, /* i : target range interval: low Qx */ + const Word32 y2, /* i : target range interval: high Q31 */ + const Word16 flag_sat /* i : flag to indicate whether to apply saturation */ ) { Word32 temp32; Word32 temp_div; - Word16 temp_e = 0; - Word16 exp_out = 0; - move16(); - move16(); + Word16 exp_out; + IF( L_sub( x2, x1 ) == 0 ) { return y1; @@ -865,12 +862,12 @@ Word32 lin_interp32_fx( } } - temp32 = Mpy_32_32( L_sub( x, x1 ), L_sub( y2, y1 ) ); // Qin*2 -31 - temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, L_sub( x2, x1 ), &temp_e ) ); // 31-temp_e + 2*Qin -31 - Qin = Qin-temp_e - temp32 = BASOP_Util_Add_Mant32Exp( y1, sub( 31, *Q_io ), temp_div, sub( 31, sub( *Q_io, temp_e ) ), &exp_out ); // Qin-temp_e - *Q_io = sub( 31, exp_out ); - move16(); - return temp32; /*Q_io*/ + temp32 = Mpy_32_32( L_sub( x, x1 ), L_sub( y2, y1 ) ); /* Qx */ + temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, L_sub( x2, x1 ), &exp_out ) ); + temp32 = BASOP_Util_Add_Mant32Exp( y1, 0, temp_div, exp_out, &exp_out ); + temp32 = L_shl_sat( temp32, exp_out ); /* Q31 */ + + return temp32; } /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 372afad233e312d4891c6e30483a298916c1dabf..4157ae1420742d5e885d7dfdfc7a878a56b1d6bc 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -281,7 +281,7 @@ ivas_error ivas_cpe_enc_fx( move16(); FOR( n = 0; n < CPE_CHANNELS; n++ ) { - scale_inp = s_min( sts[n]->q_inp, hCPE->hFrontVad[n]->q_mem_decim ); + scale_inp = s_min( scale_inp, s_min( sts[n]->q_inp, hCPE->hFrontVad[n]->q_mem_decim ) ); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index d14088e272d7fea289b0a16ba7e3e210876edaf4..543897b8542fc9365bc5a48b127ea9427ef03c4d 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -4167,7 +4167,7 @@ static void transform_index_and_GR_encode_ivas_fx( /* GR encoding */ FOR( i = 0; i < len; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, idx[i], 100, GR_order ); } return; @@ -4216,7 +4216,7 @@ static Word16 try_differential_fx( /* GR encoding */ FOR( i = 0; i < nchan_ism - 1; i++ ) { - nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length_fx( diff_idx[i], 100, 0 ) ); } } } @@ -4337,8 +4337,8 @@ static void estimate_bits_subband_ism_ratio_fx( /* GR encoding */ FOR( i = 0; i < nchan_ism - 1 - shift_one; i++ ) { - nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); - nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ) ); + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length_fx( diff_idx[i], 100, 0 ) ); + nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length_fx( diff_idx[i], 100, 1 ) ); } *p_nbits0 = nbits0; diff --git a/lib_enc/ivas_mct_enc_mct.c b/lib_enc/ivas_mct_enc_mct.c index 863e39b84022453f6f2e3f4c8c5cf21135c0f598..7729bbff5b2d88eb5517f4f3a1dc2bbc21ea4c3c 100644 --- a/lib_enc/ivas_mct_enc_mct.c +++ b/lib_enc/ivas_mct_enc_mct.c @@ -97,7 +97,7 @@ void getChannelEnergies_fx( move32(); FOR( n = 0; n < nSubframes; n++ ) { - sum2 = sum2_32_exp_fx( st->hTcxEnc->spectrum_fx[n], L_subframe, &sum2_e, gb ); + sum2 = sum2_32_exp_fx( st->hTcxEnc->spectrum_fx[n], L_subframe, &sum2_e, gb ); // 31 - sum2_e nrg[ch] = BASOP_Util_Add_Mant32Exp( nrg[ch], nrg_e[ch], sum2, sum2_e, &nrg_e[ch] ); move32(); @@ -106,7 +106,7 @@ void getChannelEnergies_fx( move16(); } - nrg[ch] = Sqrt32( nrg[ch], &nrg_e[ch] ); + nrg[ch] = Sqrt32( nrg[ch], &nrg_e[ch] ); // nrg_e move32(); } } @@ -145,7 +145,7 @@ static void getNextBestCorrelation_fx( IF( L_abs( xCorrMatrix[ch1][ch2] ) > 0 ) { assert( i < ( MCT_MAX_CHANNELS * ( MCT_MAX_CHANNELS - 1 ) ) / 2 ); - tmp_corrVals[i] = L_abs( xCorrMatrix[ch1][ch2] ); + tmp_corrVals[i] = L_abs( xCorrMatrix[ch1][ch2] ); // Qx move32(); i = add( i, 1 ); } @@ -158,7 +158,7 @@ static void getNextBestCorrelation_fx( v_sort_ind_fixed( tmp_corrVals, tmp_org, add( tmp_idx, 1 ) ); /* get max, or 2nd max and so on depending on sortInd value */ - *max_corr = tmp_corrVals[sub( tmp_idx, sortInd )]; + *max_corr = tmp_corrVals[( tmp_idx - sortInd )]; // Qx move32(); /*find channel pair for this max_corr*/ @@ -170,7 +170,7 @@ static void getNextBestCorrelation_fx( { *_ch1 = ch1; *_ch2 = ch2; - *max_corr = xCorrMatrix[ch1][ch2]; /* assign to max_corr its actual value */ + *max_corr = xCorrMatrix[ch1][ch2]; /* assign to max_corr its actual value */ // Qx move16(); move16(); move32(); @@ -252,9 +252,9 @@ static void getCorrelationMatrix_fx( FOR( ch2 = ch1 + 1; ch2 < nchan; ch2++ ) { // tmp = sqrtf( xCorrMatrix[ch1][ch1] * xCorrMatrix[ch2][ch2] ); - W_tmp = W_mult0_32_32( xCorrMatrix[ch1][ch1], xCorrMatrix[ch2][ch2] ); + W_tmp = W_mult0_32_32( xCorrMatrix[ch1][ch1], xCorrMatrix[ch2][ch2] ); // ( 31 - xCorrMatrix_exp[ch1][ch1] ) + ( 31 - xCorrMatrix_exp[ch2][ch2] ) s = W_norm( W_tmp ); - L_tmp = W_extract_h( W_shl( W_tmp, s ) ); + L_tmp = W_extract_h( W_shl( W_tmp, s ) ); // s + ( 31 - xCorrMatrix_exp[ch1][ch1] ) + ( 31 - xCorrMatrix_exp[ch2][ch2] ) - 32 s = sub( add( s, 30 ), add( xCorrMatrix_exp[ch1][ch1], xCorrMatrix_exp[ch2][ch2] ) ); // s = s + ( 31 - xCorrMatrix_exp[ch1][ch1] ) + ( 31 - xCorrMatrix_exp[ch2][ch2] ) - 32; s = sub( 31, s ); @@ -296,7 +296,7 @@ static void getCorrelationMatrix_fx( { FOR( ch2 = ch1 + 1; ch2 < nchan; ch2++ ) { - xCorrMatrix[ch1][ch2] = L_shl_sat( xCorrMatrix[ch1][ch2], add( s, sub( xCorrMatrix_exp[ch1][ch2], *xCorrMatrix_e ) ) ); + xCorrMatrix[ch1][ch2] = L_shl_sat( xCorrMatrix[ch1][ch2], add( s, sub( xCorrMatrix_exp[ch1][ch2], *xCorrMatrix_e ) ) ); // xCorrMatrix_e - s move32(); } } @@ -334,7 +334,7 @@ static void getBestCorrelation_fx( { IF( LT_32( L_abs( *max_corr ), L_abs( xCorrMatrix[ch1][ch2] ) ) ) { - *max_corr = xCorrMatrix[ch1][ch2]; + *max_corr = xCorrMatrix[ch1][ch2]; // Qx move32(); *_ch1 = ch1; @@ -377,12 +377,12 @@ static void getBlockValues_fx( /* map vectors to current block channels */ FOR( n = 0; n < 2; n++ ) { - p_mdst_spectrum[0][n] = mdst_spectrum[ch1][n]; - p_mdst_spectrum[1][n] = mdst_spectrum[ch2][n]; - p_inv_spectrum[0][n] = inv_spectrum[ch1][n]; - p_inv_spectrum[1][n] = inv_spectrum[ch2][n]; - p_inv_mdst_spectrum[0][n] = inv_mdst_spectrum[ch1][n]; - p_inv_mdst_spectrum[1][n] = inv_mdst_spectrum[ch2][n]; + p_mdst_spectrum[0][n] = mdst_spectrum[ch1][n]; // q_spec + p_mdst_spectrum[1][n] = mdst_spectrum[ch2][n]; // q_spec + p_inv_spectrum[0][n] = inv_spectrum[ch1][n]; // q_spec + p_inv_spectrum[1][n] = inv_spectrum[ch2][n]; // q_spec + p_inv_mdst_spectrum[0][n] = inv_mdst_spectrum[ch1][n]; // q_spec + p_inv_mdst_spectrum[1][n] = inv_mdst_spectrum[ch2][n]; // q_spec } p_st[0] = sts[ch1]; p_st[1] = sts[ch2]; @@ -604,8 +604,8 @@ static void getGlobalILD_fx( FOR( k = 0; k < nSubframes; k++ ) { - v_multc_fixed( sts[ch]->hTcxEnc->spectrum_fx[k], L_deposit_h( qratio ), sts[ch]->hTcxEnc->spectrum_fx[k], L_subframe ); - v_multc_fixed( mdst_spectrum[ch][k], L_deposit_h( qratio ), mdst_spectrum[ch][k], L_subframe ); + v_multc_fixed( sts[ch]->hTcxEnc->spectrum_fx[k], L_deposit_h( qratio ), sts[ch]->hTcxEnc->spectrum_fx[k], L_subframe ); // sts[ch]->hTcxEnc->spectrum_e + v_multc_fixed( mdst_spectrum[ch][k], L_deposit_h( qratio ), mdst_spectrum[ch][k], L_subframe ); // sts[ch]->hTcxEnc->spectrum_e } } } @@ -623,9 +623,9 @@ static void getGlobalILD_fx( void apply_MCT_enc_fx( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ Encoder_State **sts, /* i/o: encoder state structure */ - Word32 *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum */ - Word32 *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ - Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ + Word32 *mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: MDST spectrum Qx*/ + Word32 *inv_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse spectrum Qx*/ + Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum Qx*/ const Word16 nchan /* i : number of channels */ ) { @@ -734,7 +734,7 @@ void apply_MCT_enc_fx( move16(); move16(); currBlockDataCnt = 0; - WHILE( LT_16( currBlockDataCnt, hMCT->nchan_out_woLFE ) ) + WHILE( ( currBlockDataCnt < hMCT->nchan_out_woLFE ) ) { /* find best fitting channel pair: */ ch1 = -1; @@ -1034,7 +1034,7 @@ void mctStereoIGF_enc_fx( sts[ch2]->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } - p_powerSpec_fx[0] = powerSpec_fx[ch1]; + p_powerSpec_fx[0] = powerSpec_fx[ch1]; // q_powerSpec p_powerSpec_fx[1] = powerSpec_fx[ch2]; /* Band-wise M/S for MDST */ @@ -1048,9 +1048,9 @@ void mctStereoIGF_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { - p_orig_spectrum_fx[0][n] = orig_spectrum_fx[ch1][n]; + p_orig_spectrum_fx[0][n] = orig_spectrum_fx[ch1][n]; // q_origSpec p_orig_spectrum_fx[1][n] = orig_spectrum_fx[ch2][n]; - p_powerSpecMsInv_fx[0][n] = powerSpecMsInv_fx[ch1][n]; + p_powerSpecMsInv_fx[0][n] = powerSpecMsInv_fx[ch1][n]; // q_powerSpec p_powerSpecMsInv_fx[1][n] = powerSpecMsInv_fx[ch2][n]; p_inv_spectrum_fx[0][n] = inv_spectrum_fx[ch1][n]; p_inv_spectrum_fx[1][n] = inv_spectrum_fx[ch2][n]; diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index a2bf4e40f95552eb5557cda648e324b3f3bc5e4f..a64cf60b3c9ecba13952cca09725e100798cb8b5 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -130,10 +130,10 @@ static void enc_prm_pre_mdct_fx( *---------------------------------------------------------------*/ static Word16 kernel_switch_detect_fx( - Word32 *sigR0, /* i/o: MDCT samples of the 1st (left) channel */ - Word32 *sigR1, /* i/o: MDCT samples of the 2nd (right) channel */ - Word32 *sigI0, /* i/o: MDST samples of the 1st (left) channel */ - Word32 *sigI1, /* i/o: MDST samples of the 2nd (right) channel */ + Word32 *sigR0, /* i/o: MDCT samples of the 1st (left) channel q_in*/ + Word32 *sigR1, /* i/o: MDCT samples of the 2nd (right) channel q_in*/ + Word32 *sigI0, /* i/o: MDST samples of the 1st (left) channel q_in*/ + Word32 *sigI1, /* i/o: MDST samples of the 2nd (right) channel q_in*/ const Word16 q_in, /* i : common Q for MDCT and MDST samples */ const Word16 nSamplesCore, /* i : number of core-coded samples below IGF */ const Word16 nSamplesMax, /* i : transform length (number of MCLT lines) */ @@ -658,26 +658,26 @@ static void applyStereoPreProcessingCplx( { IF( sign < 0 ) { - dmxR1_fx = L_add( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); - dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); + dmxR1_fx = L_add( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 + dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxR1_fx = L_sub( Mpy_32_32( valR2_fx, factIn_fx ), Mpy_32_32( valR1_fx, factDe_fx ) ); - dmxI1_fx = L_sub( Mpy_32_32( valI2_fx, factIn_fx ), Mpy_32_32( valI1_fx, factDe_fx ) ); + dmxR1_fx = L_sub( Mpy_32_32( valR2_fx, factIn_fx ), Mpy_32_32( valR1_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 + dmxI1_fx = L_sub( Mpy_32_32( valI2_fx, factIn_fx ), Mpy_32_32( valI1_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 } } ELSE { IF( sign < 0 ) { - dmxR1_fx = L_add( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); - dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); + dmxR1_fx = L_add( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 + dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxR1_fx = L_sub( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); - dmxI1_fx = L_sub( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); + dmxR1_fx = L_sub( Mpy_32_32( valR1_fx, factDe_fx ), Mpy_32_32( valR2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 + dmxI1_fx = L_sub( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } } } @@ -685,40 +685,40 @@ static void applyStereoPreProcessingCplx( { IF( sign < 0 ) { - dmxI1_fx = L_sub( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); + dmxI1_fx = L_sub( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); + dmxI1_fx = L_add( Mpy_32_32( valI1_fx, factDe_fx ), Mpy_32_32( valI2_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } } IF( LT_32( L_abs( dmxR2_fx ), L_shr( L_add( absR1_fx, absR2_fx ), 9 ) ) ) /* avoid destructive summations */ { - IF( Mpy_32_32( absR1_fx, factIn_fx ) < Mpy_32_32( absR2_fx, factDe_fx ) ) + IF( LT_32( Mpy_32_32( absR1_fx, factIn_fx ), Mpy_32_32( absR2_fx, factDe_fx ) ) ) { IF( sign < 0 ) { - dmxR2_fx = L_add( Mpy_32_32( valR2_fx, factDe_fx ), Mpy_32_32( valR1_fx, factIn_fx ) ); - dmxI2_fx = L_add( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); + dmxR2_fx = L_add( Mpy_32_32( valR2_fx, factDe_fx ), Mpy_32_32( valR1_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 + dmxI2_fx = L_add( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxR2_fx = L_sub( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); - dmxI2_fx = L_sub( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); + dmxR2_fx = L_sub( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 + dmxI2_fx = L_sub( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 } } ELSE { IF( sign < 0 ) { - dmxR2_fx = L_add( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); - dmxI2_fx = L_add( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); + dmxR2_fx = L_add( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 + dmxI2_fx = L_add( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxR2_fx = L_sub( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); - dmxI2_fx = L_sub( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); + dmxR2_fx = L_sub( Mpy_32_32( valR1_fx, factIn_fx ), Mpy_32_32( valR2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 + dmxI2_fx = L_sub( Mpy_32_32( valI1_fx, factIn_fx ), Mpy_32_32( valI2_fx, factDe_fx ) ); // Q = q_com + Q22 - 31 } } } @@ -726,11 +726,11 @@ static void applyStereoPreProcessingCplx( { IF( sign < 0 ) { - dmxI2_fx = L_sub( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); + dmxI2_fx = L_sub( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } ELSE { - dmxI2_fx = L_add( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); + dmxI2_fx = L_add( Mpy_32_32( valI2_fx, factDe_fx ), Mpy_32_32( valI1_fx, factIn_fx ) ); // Q = q_com + Q22 - 31 } } temp1 = norm_l( valR1_fx ); @@ -969,7 +969,7 @@ static uint16_t enc_ste_pre_mdct( sumR_fx = BASOP_Util_Add_Mant32Exp( sumPrdRR_fx, sumPrdRR_e, temp3, shl( sumMagnR_e, 1 ), &sumR_e ); test(); - IF( LE_32( corr_fx, 0 ) || LE_32( Mpy_32_32( sumL_fx, sumR_fx ), 0 ) ) + IF( ( corr_fx <= 0 ) || ( Mpy_32_32( sumL_fx, sumR_fx ) <= 0 ) ) { corr_fx = 0; move32(); @@ -985,14 +985,14 @@ static uint16_t enc_ste_pre_mdct( test(); test(); test(); - IF( ( GT_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev == 0 ) || ( LE_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev > 0 ) ) + IF( ( GT_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736 /*0.75.Q31*/, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev == 0 ) || ( LE_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736 /*0.75.Q31*/, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev > 0 ) ) { stepWeightI_fx = ONE_IN_Q22; move32(); stepWeightD_fx = L_sub( ONE_IN_Q24, stepWeightI_fx ); } test(); - IF( LE_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev == 0 ) /* bypass all processing, just return */ + IF( LE_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736 /*0.75.Q31*/, sub( 0, s_max( corr_e, 0 ) ) ) ) && corrIdxPrev == 0 ) /* bypass all processing, just return */ { return 0; } @@ -1005,7 +1005,7 @@ static uint16_t enc_ste_pre_mdct( xTalkI_fx = stepWeightI_fx; // Q22 xTalkD_fx = imult3216( stepWeightD_fx, sub( shl( fadeInLen, 1 ), 1 ) ); // Q22 - for ( s = sub( fadeInLen, 1 ); s > 0; s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) + FOR( s = ( fadeInLen - 1 ); s > 0; ( s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) ) { applyStereoPreProcessingCplx( sigR0_fx, sigR1_fx, sigI0_fx, sigI1_fx, *q_com, xTalkI_fx, xTalkD_fx, chanCorrSign_fx, &x1, &x2, &x3, &x4 ); mdct_exp1[tmp] = x1; @@ -1020,7 +1020,7 @@ static uint16_t enc_ste_pre_mdct( xTalkD_fx = L_sub( xTalkD_fx, stepWeightD_fx ); } - for ( s = preproLen - fadeInLen; s > 0; s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) + FOR( s = preproLen - fadeInLen; s > 0; ( s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) ) { applyStereoPreProcessingCplx( sigR0_fx, sigR1_fx, sigI0_fx, sigI1_fx, *q_com, xTalkI_fx, xTalkD_fx, chanCorrSign_fx, &x1, &x2, &x3, &x4 ); mdct_exp1[tmp] = x1; @@ -1035,7 +1035,7 @@ static uint16_t enc_ste_pre_mdct( IF( LT_16( nSampProc, nSamplesMax ) ) /* fade-out of processing at start of IGF range */ { - for ( s = s_min( fadeInLen, nSamplesMax - nSampProc ) - 1; s > 0; s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) + FOR( s = s_min( fadeInLen, nSamplesMax - nSampProc ) - 1; s > 0; ( s--, sigR0_fx++, sigR1_fx++, sigI0_fx++, sigI1_fx++, tmp++ ) ) { xTalkI_fx = L_sub( xTalkI_fx, stepWeightI_fx ); xTalkD_fx = L_add( xTalkD_fx, stepWeightD_fx ); @@ -1068,18 +1068,18 @@ static uint16_t enc_ste_pre_mdct( FOR( s = 0; s < s_max( nSamplesCore, nSamplesMax ); s++ ) { - sigR0_fx[s] = L_shl( sigR0_fx[s], sub( mdct_exp1[s], shift_r ) ); + sigR0_fx[s] = L_shl( sigR0_fx[s], sub( mdct_exp1[s], shift_r ) ); // mdct_exp1 move32(); - sigI0_fx[s] = L_shl( sigI0_fx[s], sub( mdst_exp1[s], shift_r ) ); + sigI0_fx[s] = L_shl( sigI0_fx[s], sub( mdst_exp1[s], shift_r ) ); // mdct_exp1 move32(); - sigR1_fx[s] = L_shl( sigR1_fx[s], sub( mdct_exp2[s], shift_r ) ); + sigR1_fx[s] = L_shl( sigR1_fx[s], sub( mdct_exp2[s], shift_r ) ); // mdct_exp2 move32(); - sigI1_fx[s] = L_shl( sigI1_fx[s], sub( mdst_exp2[s], shift_r ) ); + sigI1_fx[s] = L_shl( sigI1_fx[s], sub( mdst_exp2[s], shift_r ) ); // mdct_exp2 move32(); } *q_com = sub( 31, shift_r ); move16(); - IF( GT_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736, sub( 0, s_max( corr_e, 0 ) ) ) ) ) + IF( GT_32( L_shl( corr_fx, sub( corr_e, s_max( corr_e, 0 ) ) ), L_shl( 1610612736 /*0.75.Q31*/, sub( 0, s_max( corr_e, 0 ) ) ) ) ) { ans = 1; } @@ -1133,12 +1133,12 @@ void enc_prm_igf_mdct( void ivas_mdct_core_whitening_enc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - Word16 new_samples_fx[CPE_CHANNELS][L_INP], /* i : new samples */ - Word16 old_wsp_fx[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 */ - Word32 *mdst_spectrum_long_fx[CPE_CHANNELS], /* o : buffer for MDST spectrum */ + Word16 new_samples_fx[CPE_CHANNELS][L_INP], /* i : new samples Q0*/ + Word16 old_wsp_fx[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 *mdst_spectrum_long_fx[CPE_CHANNELS], /* o : buffer for MDST spectrum mdst_spectrum_e*/ Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* o : buffer TNS bits */ - Word32 *orig_spectrum_long[CPE_CHANNELS], /* o : origingal spectrum w/o whitening */ + Word32 *orig_spectrum_long[CPE_CHANNELS], /* o : origingal spectrum w/o whitening orig_spectrum_e*/ Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* o : number of tns parameters put into prm */ Word16 p_param[CPE_CHANNELS][NB_DIV], /* o : pointer to the parameter table */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -1185,7 +1185,7 @@ void ivas_mdct_core_whitening_enc_fx( { FOR( i = 0; i < NB_DIV; i++ ) { - set32_fx( scf_fx[ch][i], 0, M ); + set32_fx( scf_fx[ch][i], 0, M ); // scf_q_fx set32_fx( scf_q_fx[ch][i], 0, M ); } set16_fx( A_q_fx[ch][0], 0, M + 1 ); @@ -1256,7 +1256,7 @@ void ivas_mdct_core_whitening_enc_fx( 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(); @@ -1407,10 +1407,10 @@ void ivas_mdct_core_whitening_enc_fx( q_com = s_min( Q31, add( q_min, q_com ) ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc0->spectrum_e[n] ) ) ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc1->spectrum_e[n] ) ) ); - Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[0][n] ) ) ); - Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[1][n] ) ) ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc0->spectrum_e[n] ) ) ); // q_com + Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc1->spectrum_e[n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[0][n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[1][n] ) ) ); // q_com const Word16 switchKernel = /* these 4 transform types can be applied: 0 = MDCT-IV, 1 = MDST-II, 2 = MDCT-II, 3 = MDST-IV */ kernel_switch_detect_fx( hTcxEnc0->spectrum_fx[n], hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[0][n], mdst_spectrum_fx[1][n], q_com, nSampCore / nSubframes, @@ -1476,7 +1476,7 @@ void ivas_mdct_core_whitening_enc_fx( hTcxEnc0->kernel_type[n] = 0; move16(); - if ( hTcxEnc0->kernel_symmetry_past ) + IF( hTcxEnc0->kernel_symmetry_past ) { hTcxEnc0->kernel_type[n] = 3; move16(); @@ -1484,7 +1484,7 @@ void ivas_mdct_core_whitening_enc_fx( hTcxEnc1->kernel_type[n] = 0; move16(); - if ( hTcxEnc1->kernel_symmetry_past ) + IF( hTcxEnc1->kernel_symmetry_past ) { hTcxEnc1->kernel_type[n] = 3; move16(); @@ -1501,8 +1501,8 @@ void ivas_mdct_core_whitening_enc_fx( q_com = s_min( L_norm_arr( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/ ), L_norm_arr( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/ ) ); q_com = s_min( Q31, add( q_min, q_com ) ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc0->spectrum_e[n] ) ) ); - Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[0][n] ) ) ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc0->spectrum_e[n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /*hTcxEnc0->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[0][n] ) ) ); // q_com speech = NULL; if ( NE_16( n, 1 ) ) @@ -1522,8 +1522,8 @@ void ivas_mdct_core_whitening_enc_fx( q_com = s_min( L_norm_arr( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/ ), L_norm_arr( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/ ) ); q_com = s_min( Q31, add( q_min, q_com ) ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc1->spectrum_e[n] ) ) ); - Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[1][n] ) ) ); + Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc1->spectrum_e[n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /*hTcxEnc1->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[1][n] ) ) ); // q_com speech = NULL; if ( NE_16( n, 1 ) ) @@ -1572,10 +1572,10 @@ void ivas_mdct_core_whitening_enc_fx( q_com = sub( s_min( Q31, add( sub( Q31, exp_max ), exp_com ) ), 6 ); // 6 guarded bits exp_com = sub( Q31, q_com ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( hTcxEnc0->spectrum_e[n], exp_com ) ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( hTcxEnc1->spectrum_e[n], exp_com ) ); - Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[0][n], exp_com ) ); - Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[1][n], exp_com ) ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( hTcxEnc0->spectrum_e[n], exp_com ) ); // hTcxEnc0->spectrum_e + Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( hTcxEnc1->spectrum_e[n], exp_com ) ); // hTcxEnc1->spectrum_e + Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[0][n], exp_com ) ); // mdst_spectrum_e + Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[1][n], exp_com ) ); // mdst_spectrum_e Word16 q_com_orig = q_com; move16(); @@ -1590,10 +1590,10 @@ void ivas_mdct_core_whitening_enc_fx( IF( NE_16( q_com_orig, q_com ) ) { Word16 scale = sub( q_com, q_com_orig ); - Scale_sig32( hTcxEnc0->spectrum_fx[n] + length, offset2, scale ); - Scale_sig32( hTcxEnc1->spectrum_fx[n] + length, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[0][n] + length, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[1][n] + length, offset2, scale ); + Scale_sig32( hTcxEnc0->spectrum_fx[n] + length, offset2, scale ); // q_com + Scale_sig32( hTcxEnc1->spectrum_fx[n] + length, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n] + length, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n] + length, offset2, scale ); // q_com } exp_max = sub( Q31, q_com ); @@ -1606,10 +1606,10 @@ void ivas_mdct_core_whitening_enc_fx( q_com = sub( s_min( Q31, add( q_com, exp_com ) ), 6 ); exp_com = sub( Q31, q_com ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); - Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); - Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); // exp_max + Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); // exp_max + Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); // exp_max + Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( exp_max, exp_com ) ); // exp_max q_com_orig = q_com; move16(); @@ -1621,15 +1621,15 @@ void ivas_mdct_core_whitening_enc_fx( IF( NE_16( q_com_orig, q_com ) ) { Word16 scale = sub( q_com, q_com_orig ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], tcx5SizeFB, scale ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], tcx5SizeFB, scale ); - Scale_sig32( mdst_spectrum_fx[0][n], tcx5SizeFB, scale ); - Scale_sig32( mdst_spectrum_fx[1][n], tcx5SizeFB, scale ); - - Scale_sig32( hTcxEnc0->spectrum_fx[n] + offset1, offset2, scale ); - Scale_sig32( hTcxEnc1->spectrum_fx[n] + offset1, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[0][n] + offset1, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[1][n] + offset1, offset2, scale ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], tcx5SizeFB, scale ); // q_com + Scale_sig32( hTcxEnc1->spectrum_fx[n], tcx5SizeFB, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n], tcx5SizeFB, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n], tcx5SizeFB, scale ); // q_com + + Scale_sig32( hTcxEnc0->spectrum_fx[n] + offset1, offset2, scale ); // q_com + Scale_sig32( hTcxEnc1->spectrum_fx[n] + offset1, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n] + offset1, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n] + offset1, offset2, scale ); // q_com } mdst_spectrum_e[0][n] = sub( Q31, q_com ); hTcxEnc0->spectrum_e[n] = sub( Q31, q_com ); @@ -1656,10 +1656,10 @@ void ivas_mdct_core_whitening_enc_fx( q_com = sub( s_min( Q31, add( sub( Q31, exp_max ), exp_com ) ), 6 ); exp_com = sub( Q31, q_com ); - Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( hTcxEnc0->spectrum_e[n], exp_com ) ); - Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( hTcxEnc1->spectrum_e[n], exp_com ) ); - Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[0][n], exp_com ) ); - Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[1][n], exp_com ) ); + Scale_sig32( hTcxEnc0->spectrum_fx[n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( hTcxEnc0->spectrum_e[n], exp_com ) ); // hTcxEnc0->spectrum_e + Scale_sig32( hTcxEnc1->spectrum_fx[n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( hTcxEnc1->spectrum_e[n], exp_com ) ); // hTcxEnc0->spectrum_e + Scale_sig32( mdst_spectrum_fx[0][n], shr( hTcxEnc0->L_frameTCX, shift ) /* hTcxEnc0->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[0][n], exp_com ) ); // mdst_spectrum_e + Scale_sig32( mdst_spectrum_fx[1][n], shr( hTcxEnc1->L_frameTCX, shift ) /* hTcxEnc1->L_frameTCX/nSubframes */, sub( mdst_spectrum_e[1][n], exp_com ) ); // mdst_spectrum_e Word16 q_com_orig = q_com; move16(); @@ -1670,10 +1670,10 @@ void ivas_mdct_core_whitening_enc_fx( IF( NE_16( q_com_orig, q_com ) ) { Word16 scale = sub( q_com, q_com_orig ); - Scale_sig32( hTcxEnc0->spectrum_fx[n] + length, offset2, scale ); - Scale_sig32( hTcxEnc1->spectrum_fx[n] + length, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[0][n] + length, offset2, scale ); - Scale_sig32( mdst_spectrum_fx[1][n] + length, offset2, scale ); + Scale_sig32( hTcxEnc0->spectrum_fx[n] + length, offset2, scale ); // q_com + Scale_sig32( hTcxEnc1->spectrum_fx[n] + length, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[0][n] + length, offset2, scale ); // q_com + Scale_sig32( mdst_spectrum_fx[1][n] + length, offset2, scale ); // q_com } exp_com = sub( Q31, q_com ); mdst_spectrum_e[0][n] = exp_com; @@ -1748,8 +1748,8 @@ void ivas_mdct_core_whitening_enc_fx( q_com = s_min( Q31, add( q_min, q_com ) ); - Scale_sig32( hTcxEncCh->spectrum_fx[n], shr( hTcxEncCh->L_frameTCX, shift ) /*hTcxEncCh->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEncCh->spectrum_e[n] ) ) ); - Scale_sig32( mdst_spectrum_fx[ch][n], shr( hTcxEncCh->L_frameTCX, shift ) /*hTcxEncCh->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[ch][n] ) ) ); + Scale_sig32( hTcxEncCh->spectrum_fx[n], shr( hTcxEncCh->L_frameTCX, shift ) /*hTcxEncCh->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEncCh->spectrum_e[n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[ch][n], shr( hTcxEncCh->L_frameTCX, shift ) /*hTcxEncCh->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[ch][n] ) ) ); // q_com speech = hTcxEncCh->speech_TCX; if ( n != 0 ) @@ -1811,7 +1811,7 @@ void ivas_mdct_core_whitening_enc_fx( } FOR( n = 0; n < nSubframes; n++ ) { - Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc->spectrum_e[n] ) ) ); + Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc->spectrum_e[n] ) ) ); // q_com hTcxEnc->spectrum_e[n] = sub( Q31, q_com ); move16(); } @@ -1869,8 +1869,8 @@ void ivas_mdct_core_whitening_enc_fx( } FOR( n = 0; n < nSubframes; n++ ) { - Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc->spectrum_e[n] ) ) ); - Scale_sig32( mdst_spectrum_fx[ch][n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[ch][n] ) ) ); + Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, hTcxEnc->spectrum_e[n] ) ) ); // q_com + Scale_sig32( mdst_spectrum_fx[ch][n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( Q31, mdst_spectrum_e[ch][n] ) ) ); // q_com hTcxEnc->spectrum_e[n] = sub( Q31, q_com ); move16(); mdst_spectrum_e[ch][n] = sub( Q31, q_com ); @@ -2189,7 +2189,7 @@ void ivas_mdct_core_whitening_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { - Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( 31, hTcxEnc->spectrum_e[n] ) ) ); + Scale_sig32( hTcxEnc->spectrum_fx[n], shr( hTcxEnc->L_frameTCX, shift ) /*hTcxEnc->L_frameTCX / nSubframes*/, sub( q_com, sub( 31, hTcxEnc->spectrum_e[n] ) ) ); // q_com hTcxEnc->spectrum_e[n] = sub( 31, q_com ); move16(); } @@ -2477,7 +2477,7 @@ void ivas_mdct_core_whitening_enc_fx( } ELSE { - set16_fx( pitch_buf_fx[ch], L_SUBFR << Q6, NB_SUBFR16k ); + set16_fx( pitch_buf_fx[ch], L_SUBFR << Q6, NB_SUBFR16k ); // Q6 } } @@ -2507,11 +2507,11 @@ void ivas_mdct_quant_coder_fx( Word16 nbits_start, total_nbbits; Word16 fac_ns_fx[CPE_CHANNELS][NB_DIV]; /* noise filling level */ - Word32 ener_fx[CPE_CHANNELS][NB_DIV]; /* energy of the quantized spectrum */ - Word16 gain_tcx_fx[CPE_CHANNELS][NB_DIV]; /* global gain */ + Word32 ener_fx[CPE_CHANNELS][NB_DIV]; /* energy of the quantized spectrum ener_e*/ + Word16 gain_tcx_fx[CPE_CHANNELS][NB_DIV]; /* global gain gain_tcx_e*/ Word16 gain_tcx_e[CPE_CHANNELS][NB_DIV]; Word32 quantized_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ - Word32 *quantized_spectrum_fx[CPE_CHANNELS][NB_DIV]; + Word32 *quantized_spectrum_fx[CPE_CHANNELS][NB_DIV]; // quantized_spectrum_e Word16 quantized_spectrum_e[CPE_CHANNELS][NB_DIV]; Word16 ener_e[CPE_CHANNELS][NB_DIV]; @@ -2619,11 +2619,11 @@ void ivas_mdct_quant_coder_fx( FOR( n = 0; n < nSubframes; n++ ) { temp_scale = getScaleFactor32( quantized_spectrum_fx[ch][n], L_spec[ch][n] ); - scale_sig32( quantized_spectrum_fx[ch][n], L_spec[ch][n], temp_scale ); + scale_sig32( quantized_spectrum_fx[ch][n], L_spec[ch][n], temp_scale ); // quantized_spectrum_e quantized_spectrum_e[ch][n] = sub( quantized_spectrum_e[ch][n], temp_scale ); min_shift = s_max( min_shift, quantized_spectrum_e[ch][n] ); temp_scale = getScaleFactor32( st->hTcxEnc->spectrum_fx[n], L_spec[ch][n] ); - scale_sig32( st->hTcxEnc->spectrum_fx[n], L_spec[ch][n], temp_scale ); + scale_sig32( st->hTcxEnc->spectrum_fx[n], L_spec[ch][n], temp_scale ); // st->hTcxEnc->spectrum_e st->hTcxEnc->spectrum_e[n] = sub( st->hTcxEnc->spectrum_e[n], temp_scale ); min_shift = s_max( min_shift, st->hTcxEnc->spectrum_e[n] ); } @@ -2732,7 +2732,8 @@ void ivas_mdct_quant_coder_fx( writeTCXparam_fx( st, st->hBstr, NULL, param_core[ch], 0, 0, 0, NULL, p_param[ch], target_bitsTCX10[ch], 1 ); - total_nbbits = st->hBstr->nb_bits_tot - nbits_start - nSubframes * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + total_nbbits = sub( sub( st->hBstr->nb_bits_tot, nbits_start ), imult1616( nSubframes, ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ) ) ); + // total_nbbits = st->hBstr->nb_bits_tot - nbits_start - nSubframes * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); assert( st->bits_frame_channel == total_nbbits ); } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index bf87179a3766c474821a04b040c385f17b036d38..a9ebf8ec3bc278e472a912fd03cf1d92ba509ab1 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -291,7 +291,7 @@ ivas_error ivas_omasa_enc_config_fx( k = 0; move16(); - WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) + WHILE( ( k < SIZE_IVAS_BRATE_TBL ) && ( ivas_total_brate != ivas_brate_tbl[k] ) ) { test(); k = add( k, 1 ); @@ -458,7 +458,7 @@ void ivas_omasa_set_config_fx( } } - Copy( DirAC_block_grouping, hOMasa->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( DirAC_block_grouping, hOMasa->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); // Q0 IF( EQ_16( hOMasa->nSubframes, 1 ) ) { hOMasa->block_grouping[1] = hOMasa->block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -478,7 +478,7 @@ void ivas_omasa_enc_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in[], /* i/o: Input / transport audio signals */ + Word32 *data_in[], /* i/o: Input / transport audio signals q_data*/ Word16 q_data, /* i : Q0 Stores the q for data_in */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ @@ -756,8 +756,8 @@ void ivas_omasa_enc_fx( /* Move the ISM metadata to the first entry for encoding in the MASA_ONE_OBJ mode */ IF( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - hIsmMeta[0]->azimuth_fx = hIsmMeta[*idx_separated_object]->azimuth_fx; - hIsmMeta[0]->elevation_fx = hIsmMeta[*idx_separated_object]->elevation_fx; + hIsmMeta[0]->azimuth_fx = hIsmMeta[*idx_separated_object]->azimuth_fx; // Q22 + hIsmMeta[0]->elevation_fx = hIsmMeta[*idx_separated_object]->elevation_fx; // Q22 move32(); move32(); } @@ -815,6 +815,7 @@ void ivas_set_ism_importance_interformat_fx( } ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + move16(); st->low_rate_mode = 0; move16(); @@ -920,7 +921,7 @@ void ivas_set_surplus_brate_enc( Word16 ivas_omasa_ener_brate_fx( const Word16 nchan_ism, /* i : number of ISMs */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word32 *data_f[], /* i : Input / transport audio signals */ + Word32 *data_f[], /* i : Input / transport audio signals data_e*/ const Word16 input_frame, /* i : Input frame size */ Word16 data_e /*i:exponent for data_f */ ) @@ -973,7 +974,7 @@ Word16 ivas_omasa_ener_brate_fx( energy_ism = Mpy_32_16_1( energy_ism, temp ); IF( energy_ism_e < 0 ) { - energy_ism = L_shl( energy_ism, energy_ism_e ); + energy_ism = L_shl( energy_ism, energy_ism_e ); // Q31 energy_ism_e = 0; move16(); } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index f018f250a9f7e980b6db552c8a5b639278879213..9d7c92dd092af32dd24a5726fb402d117eb5b317 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -63,9 +63,9 @@ static void ivas_osba_render_ism_to_sba_fx( * Merge SBA transport channels *-------------------------------------------------------------------*/ static void ivas_merge_sba_transports_fx( - Word32 data_in_f1[][L_FRAME48k], - Word32 *data_in_f2[], - Word32 *data_out_f[], + Word32 data_in_f1[][L_FRAME48k], // Q_f1 + Word32 *data_in_f2[], // Q_f2 + Word32 *data_out_f[], // Q_out const Word16 input_frame, const Word16 sba_analysis_order, Word16 Q_f1, @@ -133,10 +133,10 @@ ivas_error ivas_osba_enc_open_fx( tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); input_frame = extract_l( tmp32 ); - for ( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame; i++ ) { tmp32 = L_deposit_h( BASOP_Util_Divide1616_Scale( i, input_frame, &tmp_e ) ); - hOSba->interpolator_fx[i] = L_shl( tmp32, tmp_e ); + hOSba->interpolator_fx[i] = L_shl( tmp32, tmp_e ); // Q31 move32(); } st_ivas->hOSba = hOSba; @@ -408,7 +408,7 @@ ivas_error ivas_osba_enc_reconfig( void ivas_osba_enc_fx( OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in_fx[], /* i/o: Input / transport audio signals */ + Word32 *data_in_fx[], /* i/o: Input / transport audio signals q_data*/ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ const ISM_MODE ism_mode, /* i : ISM mode */ @@ -427,7 +427,7 @@ void ivas_osba_enc_fx( /*keep the delay buffer up to date*/ FOR( n = 0; n < nchan_ism; n++ ) { - MVR2R_WORD32( &data_in_fx[n][input_frame - delay_s], hOSba->input_data_mem_fx[n], delay_s ); + MVR2R_WORD32( &data_in_fx[n][input_frame - delay_s], hOSba->input_data_mem_fx[n], delay_s ); // Q_data } /* Convert ISM to SBA */ @@ -450,8 +450,8 @@ void ivas_osba_enc_fx( { delay_signal_fx( data_in_fx[n], input_frame, hOSba->input_data_mem_fx[n], delay_s ); - azimuth_fx = extract_l( L_shr( L_add( hIsmMeta[n]->azimuth_fx, 2097152 ), Q22 ) ); - elevation_fx = extract_l( L_shr( L_add( hIsmMeta[n]->elevation_fx, 2097152 ), Q22 ) ); + azimuth_fx = extract_l( L_shr( L_add( hIsmMeta[n]->azimuth_fx, 2097152 /*0.5.Q22*/ ), Q22 ) ); // Q0 + elevation_fx = extract_l( L_shr( L_add( hIsmMeta[n]->elevation_fx, 2097152 /*0.5.Q22*/ ), Q22 ) ); // Q0 ivas_dirac_dec_get_response_fx( azimuth_fx, elevation_fx, hOSba->prev_object_dm_gains_fx[n], sba_analysis_order, Q30 ); } } @@ -467,14 +467,14 @@ void ivas_osba_enc_fx( *--------------------------------------------------------------------------*/ /* Render ISMs to SBA */ static void ivas_osba_render_ism_to_sba_fx( - Word32 *data_in_fx[], - Word32 data_out_fx[][L_FRAME48k], + Word32 *data_in_fx[], // Q_data + Word32 data_out_fx[][L_FRAME48k], // Q_data const Word16 input_frame, const Word16 sba_analysis_order, const Word16 nchan_ism, ISM_METADATA_HANDLE hIsmMeta[], - Word32 prev_gains_fx[][MAX_INPUT_CHANNELS], - const Word32 interpolator_fx[L_FRAME48k], + Word32 prev_gains_fx[][MAX_INPUT_CHANNELS], // Q30 + const Word32 interpolator_fx[L_FRAME48k], // Q31 Word16 *Q_data ) { Word16 i, j, k; @@ -495,31 +495,32 @@ static void ivas_osba_render_ism_to_sba_fx( FOR( i = 0; i < nchan_ism; i++ ) { // azimuth = (int16_t) floorf( hIsmMeta[i]->azimuth + 0.5f ); - azimuth_fx = extract_l( L_shr( L_add( hIsmMeta[i]->azimuth_fx, 2097152 ), Q22 ) ); + azimuth_fx = extract_l( L_shr( L_add( hIsmMeta[i]->azimuth_fx, 2097152 /*0.5.Q22*/ ), Q22 ) ); // Q0 // elevation = (int16_t) floorf( hIsmMeta[i]->elevation + 0.5f ); - elevation_fx = extract_l( L_shr( L_add( hIsmMeta[i]->elevation_fx, 2097152 ), Q22 ) ); + elevation_fx = extract_l( L_shr( L_add( hIsmMeta[i]->elevation_fx, 2097152 /*0.5.Q22*/ ), Q22 ) ); // Q0 ivas_dirac_dec_get_response_fx( azimuth_fx, elevation_fx, gains_fx, sba_analysis_order, Q30 ); /* Render using the sh gains */ FOR( j = 0; j < nchan_sba; j++ ) { + test(); IF( L_abs( gains_fx[j] ) > 0 || L_abs( prev_gains_fx[i][j] ) > 0 ) { FOR( k = 0; k < input_frame; k++ ) { // g1 = interpolator[k]; - g1_fx = interpolator_fx[k]; + g1_fx = interpolator_fx[k]; // Q31 move32(); // g2 = 1.0f - g1; - g2_fx = L_sub( ONE_IN_Q31, g1_fx ); + g2_fx = L_sub( ONE_IN_Q31, g1_fx ); // Q31 move32(); // data_out_f[j][k] += ( g1 * gains[j] + g2 * prev_gains[i][j] ) * data_in_f[i][k]; data_out_fx[j][k] = L_add( data_out_fx[j][k], L_shr( Mpy_32_32( L_add( Mpy_32_32( g1_fx, gains_fx[j] ), Mpy_32_32( g2_fx, prev_gains_fx[i][j] ) ), data_in_fx[i][k] ), 1 ) ); // Q_data-2 move32(); } } - prev_gains_fx[i][j] = gains_fx[j]; + prev_gains_fx[i][j] = gains_fx[j]; // Q30 move32(); } } diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index fccef003672e81c07cc1b37862f3bb6d6a26bcea..4e133567c762b3b113274d78ffc6dfe50e2724e1 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -98,7 +98,7 @@ static void pca_enc_reset_fx( } static void pca_transform_sub_fx( - Word16 *eigVec, + Word16 *eigVec, // Q15 Word32 *transformed_data[8], /* i : input/transformed audio channels Q11 */ const Word16 start, const Word16 len, @@ -112,7 +112,7 @@ static void pca_transform_sub_fx( { FOR( k = 0; k < n_channels; k++ ) { - buffer_data[k] = transformed_data[k][j + start]; + buffer_data[k] = transformed_data[k][j + start]; // Q11 move32(); } FOR( k = 0; k < n_channels; k++ ) @@ -121,10 +121,10 @@ static void pca_transform_sub_fx( move32(); FOR( i = 0; i < n_channels; i++ ) { - temp2 = Mpy_32_16_1( buffer_data[i], eigVec[k * IVAS_PCA_INTERP + i] ); + temp2 = Mpy_32_16_1( buffer_data[i], eigVec[k * IVAS_PCA_INTERP + i] ); // Q11 temp = L_add( temp, temp2 ); } - transformed_data[k][add( j, start )] = temp; + transformed_data[k][( j + start )] = temp; // Q11 move32(); } } @@ -142,7 +142,7 @@ static void pca_enc_transform_fx( { Word16 time_slot; Word16 slot_len; - Word16 eigVec_interp_fx[FOA_CHANNELS * FOA_CHANNELS]; /* eigenvectors in current frame */ + Word16 eigVec_interp_fx[FOA_CHANNELS * FOA_CHANNELS]; /* eigenvectors in current frame Q15*/ Word16 ql_interp_fx[IVAS_PCA_LEN_INTERP_Q], qr_interp_fx[IVAS_PCA_LEN_INTERP_Q]; quat_shortestpath_fx( hPCA->prev_ql_fx, ql_fx, hPCA->prev_qr_fx, qr_fx ); @@ -167,9 +167,9 @@ static void pca_update_state_fx( Word16 *eigVec, // Q15 const Word16 n_channels ) { - Copy( qr, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); - Copy( ql, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); - Copy( eigVec, hPCA->prev_eigVec_fx, imult1616( n_channels, n_channels ) ); + Copy( qr, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); // Q15 + Copy( ql, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); // Q15 + Copy( eigVec, hPCA->prev_eigVec_fx, imult1616( n_channels, n_channels ) ); // Q15 return; } @@ -356,7 +356,7 @@ void ivas_pca_enc_fx( { FOR( k = 0; k < FOA_CHANNELS; k++ ) { - ptr_sig_fx[k] = &data_fx[k][i]; + ptr_sig_fx[k] = &data_fx[k][i]; // Q11 } @@ -388,7 +388,7 @@ void ivas_pca_enc_fx( FOR( Word16 idx = 0; idx < FOA_CHANNELS * FOA_CHANNELS; idx++ ) { - r_fx[idx] = L_shr( r_fx[idx], ( sub( tmp_q[idx], q ) ) ); + r_fx[idx] = L_shr( r_fx[idx], ( sub( tmp_q[idx], q ) ) ); // q move32(); } @@ -401,10 +401,10 @@ void ivas_pca_enc_fx( FOR( k = 0; k < FOA_CHANNELS * FOA_CHANNELS; k++ ) { - L_tmp = L_shr( Mpy_32_32( alpha_fx, r_fx[k] ), sub( q, min_q ) ); - L_tmp1 = L_shr( Mpy_32_32( one_minus_alpha_fx, hPCA->old_r_sm_fx[k] ), sub( hPCA->old_r_sm_q, min_q ) ); - r_sm_fx[k] = L_add( L_tmp, L_tmp1 ); - hPCA->old_r_sm_fx[k] = r_sm_fx[k]; + L_tmp = L_shr( Mpy_32_32( alpha_fx, r_fx[k] ), sub( q, min_q ) ); // min_q + L_tmp1 = L_shr( Mpy_32_32( one_minus_alpha_fx, hPCA->old_r_sm_fx[k] ), sub( hPCA->old_r_sm_q, min_q ) ); // min_q + r_sm_fx[k] = L_add( L_tmp, L_tmp1 ); // min_q + hPCA->old_r_sm_fx[k] = r_sm_fx[k]; // min_q move32(); move32(); } @@ -415,13 +415,13 @@ void ivas_pca_enc_fx( /* conditioning */ FOR( k = 0; k < FOA_CHANNELS; k++ ) { - temp_fx32 = r_sm_fx[k * FOA_CHANNELS + k]; + temp_fx32 = r_sm_fx[k * FOA_CHANNELS + k]; // min_q move32(); IF( LT_32( temp_fx32, L_shr( 64424, sub( 31, hPCA->old_r_sm_q ) ) ) ) // IVAS_PCA_COV_THRES in Q31 { - temp_fx32 = L_shr( 64424, sub( 31, hPCA->old_r_sm_q ) ); // IVAS_PCA_COV_THRES in Q31 + temp_fx32 = L_shr( 64424, sub( 31, hPCA->old_r_sm_q ) ); // IVAS_PCA_COV_THRES in Q31 /*hPCA->old_r_sm_q */ } - r_sm_fx[k * FOA_CHANNELS + k] = temp_fx32; /* pointer reuse */ + r_sm_fx[k * FOA_CHANNELS + k] = temp_fx32; /* pointer reuse */ // hPCA->old_r_sm_q move32(); } @@ -539,7 +539,7 @@ void ivas_pca_enc_fx( /* copy j-th column to column k */ FOR( l = 0; l < n_channels; l++ ) { - eigVec_tmp_fx[l * n_channels + k] = eigVec_fx[l * n_channels + j]; + eigVec_tmp_fx[l * n_channels + k] = eigVec_fx[l * n_channels + j]; // Q31 move16(); } D_tmp_fx[k] = extract_l( D_fx[j] ); @@ -548,7 +548,7 @@ void ivas_pca_enc_fx( FOR( k = 0; k < n_channels * n_channels; k++ ) { - eigVec_fx[k] = eigVec_tmp_fx[k]; + eigVec_fx[k] = eigVec_tmp_fx[k]; // Q31 move32(); } @@ -571,14 +571,14 @@ void ivas_pca_enc_fx( { FOR( i = 0; i < n_channels; i++ ) { - eigVec_fx[i * n_channels + k] = L_negate( eigVec_fx[i * n_channels + k] ); + eigVec_fx[i * n_channels + k] = L_negate( eigVec_fx[i * n_channels + k] ); // Q31 move32(); } } } /* force rotation matrix(det = +1) */ - Copy_Scale_sig32_16( eigVec_fx, eigVec_fx16, FOA_CHANNELS * FOA_CHANNELS, -16 ); + Copy_Scale_sig32_16( eigVec_fx, eigVec_fx16, FOA_CHANNELS * FOA_CHANNELS, -16 ); // Q15 det_fx = mat_det4_fx( eigVec_fx16 ); IF( det_fx < 0 ) { @@ -603,29 +603,29 @@ void ivas_pca_enc_fx( *-----------------------------------------------------------------*/ /* convert frrm rotation matrix to double quaternion */ - Copy_Scale_sig_32_16( eigVec_fx, eigVec_fx16, FOA_CHANNELS * FOA_CHANNELS, -16 ); + Copy_Scale_sig_32_16( eigVec_fx, eigVec_fx16, FOA_CHANNELS * FOA_CHANNELS, -16 ); // Q15 mat2dquat_fx( eigVec_fx16, ql_fx, qr_fx ); - dotl_fx = Dot_product( hPCA->prev_ql_fx, ql_fx, 4 ); - dotr_fx = Dot_product( hPCA->prev_qr_fx, qr_fx, 4 ); + dotl_fx = Dot_product( hPCA->prev_ql_fx, ql_fx, 4 ); // Q31 + dotr_fx = Dot_product( hPCA->prev_qr_fx, qr_fx, 4 ); // Q31 IF( LT_32( dotl_fx, dotr_fx ) ) { - min_dot_fx = dotl_fx; + min_dot_fx = dotl_fx; // Q31 move32(); } ELSE { - min_dot_fx = dotr_fx; + min_dot_fx = dotr_fx; // Q31 move32(); } IF( LT_16( ql_fx[0], qr_fx[0] ) ) { - min_dot2_fx = L_deposit_h( ql_fx[0] ); + min_dot2_fx = L_deposit_h( ql_fx[0] ); // Q31 } ELSE { - min_dot2_fx = L_deposit_h( qr_fx[0] ); + min_dot2_fx = L_deposit_h( qr_fx[0] ); // Q31 } bypass_decision = PCA_MODE_ACTIVE; diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index df92d4e7687103f42345b74da3115494c4998274..00b62f2f6d07e86fe3432dfd0f3df07229fe2c28 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -51,7 +51,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *needed_bits, int16_t *nbits_diff, int16_t *dfRatioBits, const int16_t hodirac_flag ); +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, Word16 *needed_bits, Word16 *nbits_diff, Word16 *dfRatioBits, const Word16 hodirac_flag ); static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( BSTR_ENC_HANDLE hMetaData, @@ -88,11 +88,11 @@ static Word16 ivas_qmetadata_get_optimal_gr_param_fx( const Word16 gr_param_count, Word16 *opt_gr_size ); -Word16 ivas_qmetadata_encode_extended_gr_length( const UWord16 value, const UWord16 alphabet_size, const Word16 gr_param ); +Word16 ivas_qmetadata_encode_extended_gr_length_fx( const UWord16 value, const UWord16 alphabet_size, const Word16 gr_param ); -static Word16 ivas_qmetadata_encode_quasi_uniform_length( const UWord16 value, const UWord16 alphabet_size ); +static Word16 ivas_qmetadata_encode_quasi_uniform_length_fx( const UWord16 value, const UWord16 alphabet_size ); -static void ivas_qmetadata_encode_quasi_uniform( BSTR_ENC_HANDLE hMetaData, const UWord16 value, const UWord16 alphabet_size ); +static void ivas_qmetadata_encode_quasi_uniform_fx( BSTR_ENC_HANDLE hMetaData, const UWord16 value, const UWord16 alphabet_size ); static Word16 ivas_qmetadata_reorder_elevation_index_fx( const Word16 elevation_index, @@ -131,16 +131,16 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( ); static void dct4_transform_fx( - uint8_t *v, /* i : input 4D vector */ + UWord8 *v, /* i : input 4D vector */ Word32 *dct_v /* o : output transformed vector Q31 */ ); static Word32 quantize_DCT_0_coh_fx( // o:Q21 const Word16 x, /* i : input value Q14 */ - const int16_t j, /* i : subband index */ + const Word16 j, /* i : subband index */ const Word16 *coherence_cb, /* i : coherence codebook Q14 */ const Word16 delta_var, /* i : azimuth variance threshold Q6 */ - const int16_t no_cb, /* i : maximum number of codewords */ + const Word16 no_cb, /* i : maximum number of codewords */ IVAS_QDIRECTION *q_direction, /* i : quantized metadata */ UWord16 *idx_x, /* o : codewords index */ Word16 *p_no_cb, /* o : actual number of codewords dependent on energy ratio value */ @@ -162,7 +162,7 @@ static Word16 encode_coherence_indexesDCT1_fx( BSTR_ENC_HANDLE hMetaData /* i : metadata handle */ ); -static UWord64 create_combined_index( uint16_t *idx_dct, const int16_t len, const int16_t *no_cb_vec ); +static UWord64 create_combined_index_fx( uint16_t *idx_dct, const Word16 len, const Word16 *no_cb_vec ); static Word16 encode_surround_coherence_fx( IVAS_QMETADATA *hQMetaData, /* i : quantized metadata */ @@ -186,9 +186,9 @@ static void ivas_diffuseness_huff_ec_prepare_fx( UWord16 *avr_idx, Word16 *diffuseness_bits_huff ); -static int16_t coherence_coding_length( const uint16_t *idx_sur_coh_shift, const uint8_t idx_shift_len, const int16_t coding_subbands, const int16_t *no_cv, uint16_t *mr_idx, int16_t *no_cv_shift, int16_t *p_min_idx, int16_t *GR_ord, int16_t *nbits_fr, int16_t *nbits_fr1 ); +static Word16 coherence_coding_length( const uint16_t *idx_sur_coh_shift, const UWord8 idx_shift_len, const Word16 coding_subbands, const Word16 *no_cv, uint16_t *mr_idx, Word16 *no_cv_shift, Word16 *p_min_idx, Word16 *GR_ord, Word16 *nbits_fr, Word16 *nbits_fr1 ); -static int16_t write_2dir_info( BSTR_ENC_HANDLE hMetaData, uint8_t *twoDirBands, const int16_t n, const int16_t k ); +static Word16 write_2dir_info( BSTR_ENC_HANDLE hMetaData, UWord8 *twoDirBands, const Word16 n, const Word16 k ); static void transform_azimuth_dir2_fx( IVAS_QMETADATA_HANDLE hQMetaData, @@ -289,9 +289,9 @@ ivas_error ivas_qmetadata_enc_encode_fx( { IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[i].energy_ratio_fx, hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].cfg.nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q22 + Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q22 + Copy32( hQMetaData->q_direction[1].band_data[i].energy_ratio_fx, hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q30 dir2_bands[d] = i; move16(); @@ -646,7 +646,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( /* finalize writing coherence */ test(); test(); - IF( GT_16( bits_coherence[d], 0 ) && EQ_16( all_coherence_zero, 0 ) && GT_16( nblocks, 1 ) ) + IF( ( bits_coherence[d] > 0 ) && ( all_coherence_zero == 0 ) && GT_16( nblocks, 1 ) ) { bit_pos_start = hMetaData->nb_bits_tot; hMetaData->nb_bits_tot = bit_pos_start_coh; @@ -716,7 +716,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( { push_next_indice( hMetaData, 1, 1 ); /* write the number of inactive higher bands */ - ivas_qmetadata_encode_extended_gr( hMetaData, sub( hQMetaData->q_direction->cfg.inactiveBands, 1 ), MASA_MAXIMUM_CODING_SUBBANDS, 1 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( hQMetaData->q_direction->cfg.inactiveBands, 1 ), MASA_MAXIMUM_CODING_SUBBANDS, 1 ); } ELSE { @@ -741,9 +741,9 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( { IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[i].energy_ratio_fx, hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].cfg.nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q22 + Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q22 + Copy32( hQMetaData->q_direction[1].band_data[i].energy_ratio_fx, hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].cfg.nblocks ); // Q30 IF( hQMetaData->coherence_flag ) { @@ -827,16 +827,16 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( { FOR( i = start_band; i < nbands; i++ ) { - Copy32( azimuth_orig_fx[i], q_direction->band_data[i].azimuth_fx, nblocks ); - Copy32( elevation_orig_fx[i], q_direction->band_data[i].elevation_fx, nblocks ); + Copy32( azimuth_orig_fx[i], q_direction->band_data[i].azimuth_fx, nblocks ); // Q22 + Copy32( elevation_orig_fx[i], q_direction->band_data[i].elevation_fx, nblocks ); // Q22 } } ELSE { FOR( i = start_band; i < nbands; i++ ) { - Copy32( q_direction->band_data[i].azimuth_fx, q_direction->band_data[i].q_azimuth_fx, nblocks ); - Copy32( q_direction->band_data[i].elevation_fx, q_direction->band_data[i].q_elevation_fx, nblocks ); + Copy32( q_direction->band_data[i].azimuth_fx, q_direction->band_data[i].q_azimuth_fx, nblocks ); // Q22 + Copy32( q_direction->band_data[i].elevation_fx, q_direction->band_data[i].q_elevation_fx, nblocks ); // Q22 } } } @@ -945,7 +945,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { q_direction->band_data[b].energy_ratio_index[0] = s_max( q_direction->band_data[b].energy_ratio_index[0], 4 ); move16(); - bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); + bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length_fx( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; move16(); @@ -953,7 +953,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); move16(); - bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); + bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length_fx( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } ELSE { @@ -1016,7 +1016,7 @@ void ivas_qmetadata_enc_sid_encode_fx( FOR( b = start_band; b < nbands; b++ ) { q_direction->band_data[b].energy_ratio_index[0] = s_max( q_direction->band_data[b].energy_ratio_index[0], 4 ); - bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); + bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length_fx( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; move16(); move16(); @@ -1025,7 +1025,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); - bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); + bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length_fx( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } ELSE { @@ -1061,7 +1061,7 @@ void ivas_qmetadata_enc_sid_encode_fx( /*Code diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ); } /* Compute and Quantize an average direction per band*/ @@ -1117,14 +1117,14 @@ void ivas_qmetadata_enc_sid_encode_fx( { FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); } } /* fill bits*/ assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); - WHILE( LT_16( ( sub( hMetaData->nb_bits_tot, bit_pos_start ) ), metadata_sid_bits ) ) + WHILE( ( ( ( hMetaData->nb_bits_tot - bit_pos_start ) ) < metadata_sid_bits ) ) { push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ } @@ -1165,7 +1165,7 @@ void reset_metadata_spatial_fx( metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; move16(); - WHILE( LT_16( hMetaData->nb_bits_tot, metadata_sid_bits ) ) + WHILE( ( hMetaData->nb_bits_tot < metadata_sid_bits ) ) { push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ } @@ -1177,9 +1177,9 @@ void reset_metadata_spatial_fx( next_ind_sid = hMetaData->nb_ind_tot; move16(); move16(); - WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + WHILE( ( hMetaData->nb_bits_tot > nb_bits_metadata ) ) { - next_ind_sid--; + next_ind_sid = sub( next_ind_sid, 1 ); hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[next_ind_sid].nb_bits ); move16(); } @@ -1221,9 +1221,9 @@ void reset_metadata_spatial_fx( ELSE IF( NE_32( ivas_format, SBA_FORMAT ) ) { /* Reset SID metadata bits*/ - WHILE( GT_16( hMetaData->nb_bits_tot, nb_bits_metadata ) ) + WHILE( ( hMetaData->nb_bits_tot > nb_bits_metadata ) ) { - hMetaData->nb_ind_tot--; + hMetaData->nb_ind_tot = sub( hMetaData->nb_ind_tot, 1 ); hMetaData->nb_bits_tot = sub( hMetaData->nb_bits_tot, hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits ); hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits = -1; move16(); @@ -1381,10 +1381,10 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512_fx( push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; move16(); - hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] = W_extract_h( W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[index] ) ); + hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] = W_extract_h( W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[index] ) ); // Q30 move32(); - ratioSum = L_add( hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio_fx[k], hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] ); + ratioSum = L_add( hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio_fx[k], hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] ); // Q30 IF( GT_32( ratioSum, ONE_IN_Q30 /*1.0f*/ ) ) { @@ -1672,9 +1672,9 @@ static void ivas_diffuseness_huff_ec_prepare_fx( { av = add( av, q_direction->band_data[b].energy_ratio_index[0] ); } - // av = (int16_t) ( 0.5f + av / (float) nbands ); + // av = (Word16) ( 0.5f + av / (float) nbands ); av = BASOP_Util_Divide1616_Scale( av, nbands, &av_e ); - av = shr_r( av, sub( 15, av_e ) ); + av = shr_r( av, sub( 15, av_e ) ); // Q0 *best_av = av; move16(); @@ -1769,7 +1769,7 @@ static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( move16(); FOR( b = start_band; b < nbands; b++ ) { - diffuseness_bits_raw = add( diffuseness_bits_raw, ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ) ); + diffuseness_bits_raw = add( diffuseness_bits_raw, ivas_qmetadata_encode_quasi_uniform_length_fx( q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ) ); } min_diffuseness_m_index = q_direction->band_data[start_band].energy_ratio_index[0]; @@ -1798,15 +1798,15 @@ static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( /* one bit is used to indicate whether diffuseness values are entropy coded or coded raw */ IF( EQ_16( min_diffuseness_m_index, max_diffuseness_m_index ) ) /* all values are equal */ { - push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ - push_next_indice( hMetaData, 1, 1 ); /* dif_have_unique_value */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ + push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ + push_next_indice( hMetaData, 1, 1 ); /* dif_have_unique_value */ + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ } ELSE IF( EQ_16( add( min_diffuseness_m_index, 1 ), max_diffuseness_m_index ) ) /* only two consecutive values are present */ { - push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ - push_next_indice( hMetaData, 0, 1 ); /* dif_have_unique_value */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ + push_next_indice( hMetaData, 0, 1 ); /* dif_have_unique_value */ + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ FOR( b = start_band; b < nbands; b++ ) { @@ -1819,7 +1819,7 @@ static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ } } } @@ -1850,7 +1850,7 @@ static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( push_next_indice( hMetaData, 1, 1 ); FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ } } } @@ -1858,7 +1858,7 @@ static Word16 ivas_qmetadata_entropy_encode_diffuseness_fx( *diffuseness_index_max_ec_frame = 5; move16(); /* adaptively select the diffuseness_index_max_ec threshold */ - if ( GT_16( min_diffuseness_m_index, 5 ) ) + IF( GT_16( min_diffuseness_m_index, 5 ) ) { *diffuseness_index_max_ec_frame = DIRAC_DIFFUSE_LEVELS - 1; move16(); @@ -1961,13 +1961,13 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ } - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, min_index, max_alphabet_size ); } ELSE IF( EQ_16( add( min_index, 1 ), max_index ) && GT_16( ec_mode, 1 ) ) /* only two consecutive values are present */ { push_next_indice( hMetaData, 0, 1 ); push_next_indice( hMetaData, 1, 1 ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, sub( max_alphabet_size, 1 ) ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, min_index, sub( max_alphabet_size, 1 ) ); FOR( b = start_band; b < nbands; b++ ) { @@ -1983,7 +1983,7 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], shl( 1, df_ratio_bits[b] ) ); /* dif_values */ + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[b].energy_ratio_index[0], shl( 1, df_ratio_bits[b] ) ); /* dif_values */ } } @@ -2016,11 +2016,11 @@ void restore_metadata_buffer_fx( } /*------------------------------------------------------------------------- - * ivas_qmetadata_encode_quasi_uniform() + * ivas_qmetadata_encode_quasi_uniform_fx() * * encode value using a quasi-uniform code of b or b + 1 bits, where b = floor(log2(alphabet_size)) *------------------------------------------------------------------------*/ -static void ivas_qmetadata_encode_quasi_uniform( +static void ivas_qmetadata_encode_quasi_uniform_fx( BSTR_ENC_HANDLE hMetaData, const UWord16 value, const UWord16 alphabet_size ) @@ -2048,12 +2048,12 @@ static void ivas_qmetadata_encode_quasi_uniform( * GR encoder function definitions *-----------------------------------------------------------------------*/ /*------------------------------------------------------------------------- - * GR_bits_new() + * GR_bits_new_fx() * * *------------------------------------------------------------------------*/ /*! r: number of bits using Golomb Rice code */ -static Word16 GR_bits_new( +static Word16 GR_bits_new_fx( UWord16 *data, /* i : data to encode with GR */ Word16 *no_symb, /* i : number of symbols for each component*/ const Word16 no_data, /* i : number of input data */ @@ -2070,7 +2070,7 @@ static Word16 GR_bits_new( FOR( i = 0; i < no_data; i++ ) { - nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order ); + nb = ivas_qmetadata_encode_extended_gr_length_fx( data[i], no_symb[i], GR_order ); nbits = add( nbits, nb ); } @@ -2078,7 +2078,7 @@ static Word16 GR_bits_new( { FOR( i = 0; i < no_data; i++ ) { - nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order - 1 ); + nb = ivas_qmetadata_encode_extended_gr_length_fx( data[i], no_symb[i], GR_order - 1 ); nbits1 = add( nbits1, nb ); } @@ -2111,8 +2111,8 @@ static Word16 GR_bits_new( * Encoding azimuth indexes with GR code using context *------------------------------------------------------------------------*/ /*! r: numer of bits used for coding */ -static Word16 GR_bits_azimuth_context( - UWord16 *data_in, /* i : data to be encoded */ +static Word16 GR_bits_azimuth_context_fx( + UWord16 *data_in, /* i : data to be encoded Qx*/ Word16 *no_symb, /* i : number of symbols for each component */ const Word16 no_data_in, /* i : number of input data */ const Word16 GR_order, /* i : GR order (GR_order or GR_order-1 are used ) */ @@ -2135,7 +2135,7 @@ static Word16 GR_bits_azimuth_context( { no_symb_local[no_data] = no_symb[i]; move16(); - data[no_data++] = data_in[i]; + data[no_data++] = data_in[i]; // Qx move16(); } } @@ -2163,7 +2163,7 @@ static Word16 GR_bits_azimuth_context( { *real_GR_ord = sub( GR_order, (Word16) EQ_16( bits_dir[i], 2 ) ); move16(); - nbits = add( nbits, ivas_qmetadata_encode_extended_gr_length( data[i], no_symb_local[i], *real_GR_ord ) ); + nbits = add( nbits, ivas_qmetadata_encode_extended_gr_length_fx( data[i], no_symb_local[i], *real_GR_ord ) ); } } @@ -2171,27 +2171,27 @@ static Word16 GR_bits_azimuth_context( move16(); IF( use_context == 0 ) { - nbits = GR_bits_new( data, no_symb_local, no_data, GR_order, 1, real_GR_ord ); + nbits = GR_bits_new_fx( data, no_symb_local, no_data, GR_order, 1, real_GR_ord ); nbits1 = nbits; move16(); - min_val = data[0]; + min_val = data[0]; // Qx move16(); FOR( i = 1; i < no_data; i++ ) { if ( LT_32( data[i], min_val ) ) { - min_val = data[i]; + min_val = data[i]; // Qx move16(); } } FOR( i = 0; i < no_data; i++ ) { - cdata[i] = (UWord16) L_sub( data[i], min_val ); + cdata[i] = (UWord16) L_sub( data[i], min_val ); // Qx move16(); } maximum_s( no_symb_local, no_data, &max_val ); - nbits1 = add( GR_bits_new( cdata, no_symb_local, no_data, sub( GR_order, 1 ), 1, &real_GR_ord1 ), ivas_qmetadata_encode_extended_gr_length( min_val, max_val, MASA_GR_ORD_AZ ) ); + nbits1 = add( GR_bits_new_fx( cdata, no_symb_local, no_data, sub( GR_order, 1 ), 1, &real_GR_ord1 ), ivas_qmetadata_encode_extended_gr_length_fx( min_val, max_val, MASA_GR_ORD_AZ ) ); IF( LT_16( nbits1, nbits ) ) { @@ -2220,7 +2220,7 @@ static Word16 GR_bits_azimuth_context( * Golomb Rice encoding with mean removing *------------------------------------------------------------------------*/ /*! r: number of bits used */ -static Word16 mean_removed_GR_new( +static Word16 mean_removed_GR_new_fx( const UWord16 *idx, /* i : data to encode */ const Word16 max_no_symb, const Word16 len, /* i : number of data */ @@ -2235,7 +2235,7 @@ static Word16 mean_removed_GR_new( Word16 max_ns[MASA_MAXIMUM_CODING_SUBBANDS]; /* av = (Word16) ( 0.5f + sum_s( (const Word16 *) idx, len ) / (float) len ); */ - av = div_l( L_add( L_shl( sum16_fx( (const Word16 *) idx, len ), 1 ), 1 ), len ); + av = shr( add( 1, idiv1616U( shl( sum16_fx( (const Word16 *) idx, len ), 1 ), len ) ), 1 ); // Q0 *p_av = av; move16(); @@ -2251,7 +2251,7 @@ static Word16 mean_removed_GR_new( { IF( sh_idx[i] < 0 ) { - sh_idx[i] = -2 * sh_idx[i]; + sh_idx[i] = imult1616( -2, sh_idx[i] ); } ELSE IF( sh_idx[i] > 0 ) { @@ -2267,16 +2267,16 @@ static Word16 mean_removed_GR_new( move16(); } - nbits = GR_bits_new( mr_idx, max_ns, len, *GR_ord, adapt_GR, GR_ord ); + nbits = GR_bits_new_fx( mr_idx, max_ns, len, *GR_ord, adapt_GR, GR_ord ); return nbits; } /*------------------------------------------------------------------------- - * ivas_qmetadata_encode_quasi_uniform_length() + * ivas_qmetadata_encode_quasi_uniform_length_fx() * *------------------------------------------------------------------------*/ -static Word16 ivas_qmetadata_encode_quasi_uniform_length( +static Word16 ivas_qmetadata_encode_quasi_uniform_length_fx( const UWord16 value, const UWord16 alphabet_size ) { @@ -2392,7 +2392,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { FOR( j = 0; j < nblocks; j++ ) { - direction_bits_ec = add( direction_bits_ec, ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); + direction_bits_ec = add( direction_bits_ec, ivas_qmetadata_encode_quasi_uniform_length_fx( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); } } } @@ -2415,24 +2415,24 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; // Q0 move16(); - avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane Q0*/ move16(); } ELSE { - avg_elevation_alphabet = sub( shl( no_theta_masa[bits_direction_masa[diff_idx_min] - 3], 1 ), 1 ); - avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + avg_elevation_alphabet = sub( shl( no_theta_masa[bits_direction_masa[diff_idx_min] - 3], 1 ), 1 ); // Q0 + avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane Q0*/ move16(); } - no_th = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + no_th = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; // Q0 move16(); FOR( i = 0; i < no_th; i++ ) { - theta_cb[i] = imult1616( i, round_fx( delta_theta_masa_fx[bits_direction_masa[diff_idx_min] - 3] ) ); + theta_cb[i] = imult1616( i, round_fx( delta_theta_masa_fx[bits_direction_masa[diff_idx_min] - 3] ) ); // Q6 move16(); } @@ -2444,13 +2444,13 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( IF( avg_elevation < 0 ) { - abs_theta = L_negate( avg_elevation ); + abs_theta = L_negate( avg_elevation ); // Q22 sign_th = -1; move16(); } ELSE { - abs_theta = avg_elevation; + abs_theta = avg_elevation; // Q22 move32(); sign_th = 1; move16(); @@ -2477,7 +2477,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( // avg_elevation *= sign_th; if ( sign_th < 0 ) { - avg_elevation = L_negate( avg_elevation ); + avg_elevation = L_negate( avg_elevation ); // Q22 } } @@ -2512,11 +2512,11 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( move16(); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( avg_elevation_index, avg_elevation_alphabet ); + elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length_fx( avg_elevation_index, avg_elevation_alphabet ); } ELSE { - elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic_fx( sub( avg_elevation_index, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); + elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length_fx( ivas_qmetadata_reorder_generic_fx( sub( avg_elevation_index, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); } idx = 0; move16(); @@ -2529,11 +2529,11 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( /* project the quantized average elevation to the same grid as the current sample */ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index_fx( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); + avg_elevation_index_projected = ivas_chan_project_elevation_index_fx( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); // Q0 } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index_fx( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index_fx( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); // Q0 } IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) @@ -2586,23 +2586,23 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } ELSE { - gr_param_elevation = ivas_qmetadata_get_optimal_gr_param_fx( dist_elevation_indexes, idx, 4, &gr_size_elevation ); + gr_param_elevation = ivas_qmetadata_get_optimal_gr_param_fx( dist_elevation_indexes, idx, 4, &gr_size_elevation ); // Q0 egr_size_elevation = 0; move16(); FOR( i = 0; i < idx; i++ ) { - egr_size_elevation = add( egr_size_elevation, ivas_qmetadata_encode_extended_gr_length( dist_elevation_indexes[i], dist_elevation_alphabets[i], gr_param_elevation ) ); + egr_size_elevation = add( egr_size_elevation, ivas_qmetadata_encode_extended_gr_length_fx( dist_elevation_indexes[i], dist_elevation_alphabets[i], gr_param_elevation ) ); // Q0 } } - elevation_bits_ec = add( elevation_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length( gr_param_elevation, 4 + 1 ), egr_size_elevation ) ); + elevation_bits_ec = add( elevation_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length_fx( gr_param_elevation, 4 + 1 ), egr_size_elevation ) ); // Q0 IF( LT_16( elevation_bits_ec, elevation_bits_ec_best ) ) { - elevation_bits_ec_best = elevation_bits_ec; + elevation_bits_ec_best = elevation_bits_ec; // Q0 move16(); - avg_elevation_index_best = avg_elevation_index; + avg_elevation_index_best = avg_elevation_index; // Q0 move16(); - gr_param_elevation_best = gr_param_elevation; + gr_param_elevation_best = gr_param_elevation; // Q0 move16(); FOR( idx = 0; idx < dist_count; idx++ ) { @@ -2642,7 +2642,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( avg_azimuth_index = (UWord16) ( add( avg_azimuth_index, avg_azimuth_alphabet ) % avg_azimuth_alphabet ); all_zero_dist_azimuth_indexes = 1; move16(); - azimuth_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic_fx( sub( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); + azimuth_bits_ec = ivas_qmetadata_encode_quasi_uniform_length_fx( ivas_qmetadata_reorder_generic_fx( sub( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); idx = 0; move16(); @@ -2724,11 +2724,11 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( move16(); FOR( i = 0; i < idx; i++ ) { - egr_size_azimuth = add( egr_size_azimuth, ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes[i], dist_azimuth_alphabets[i], gr_param_azimuth ) ); + egr_size_azimuth = add( egr_size_azimuth, ivas_qmetadata_encode_extended_gr_length_fx( dist_azimuth_indexes[i], dist_azimuth_alphabets[i], gr_param_azimuth ) ); } } - azimuth_bits_ec = add( azimuth_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length( gr_param_azimuth, 5 + 1 ), egr_size_azimuth ) ); + azimuth_bits_ec = add( azimuth_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length_fx( gr_param_azimuth, 5 + 1 ), egr_size_azimuth ) ); IF( LT_16( azimuth_bits_ec, azimuth_bits_ec_best ) ) { @@ -2778,7 +2778,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { FOR( j = 0; j < nblocks; j++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); } } } @@ -2797,28 +2797,28 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( /* encode the ExtendedGR part for elevation */ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, avg_elevation_index_best, avg_elevation_alphabet ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, avg_elevation_index_best, avg_elevation_alphabet ); } ELSE { - ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic_fx( sub( avg_elevation_index_best, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, ivas_qmetadata_reorder_generic_fx( sub( avg_elevation_index_best, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); } - ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_elevation_best, 4 + 1 ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, gr_param_elevation_best, 4 + 1 ); IF( NE_16( gr_param_elevation_best, 4 ) ) /* not all zero */ { FOR( idx = 0; idx < dist_count; idx++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_elevation_indexes_best[idx], dist_elevation_alphabets[idx], gr_param_elevation_best ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dist_elevation_indexes_best[idx], dist_elevation_alphabets[idx], gr_param_elevation_best ); } } } /* encode the ExtendedGR part for azimuth */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic_fx( sub( avg_azimuth_index_best, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, ivas_qmetadata_reorder_generic_fx( sub( avg_azimuth_index_best, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_azimuth_best, 5 + 1 ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, gr_param_azimuth_best, 5 + 1 ); IF( NE_16( gr_param_azimuth_best, 5 ) ) /* not all zero */ { @@ -2830,24 +2830,24 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { IF( GT_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), - ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length_fx( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length_fx( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } ELSE IF( EQ_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), - ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length_fx( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length_fx( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } ELSE { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } ELSE { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } @@ -2866,24 +2866,24 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { IF( GT_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), - ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length_fx( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length_fx( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } ELSE IF( EQ_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), - ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length_fx( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length_fx( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } ELSE { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } ELSE { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } } @@ -2950,18 +2950,18 @@ static Word16 ivas_qmetadata_raw_encode_dir_fx( { IF( hMetaData != NULL ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); } ELSE { direction_bits_raw = add( direction_bits_raw, - ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); + ivas_qmetadata_encode_quasi_uniform_length_fx( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); } } } } - if ( hMetaData != NULL ) + IF( hMetaData != NULL ) { direction_bits_raw = sub( hMetaData->nb_bits_tot, start_bits ); } @@ -3013,12 +3013,12 @@ static Word16 ivas_qmetadata_get_optimal_gr_param_fx( } /*------------------------------------------------------------------------- - * ivas_qmetadata_encode_extended_gr_length() + * ivas_qmetadata_encode_extended_gr_length_fx() * * *------------------------------------------------------------------------*/ Word16 -ivas_qmetadata_encode_extended_gr_length( +ivas_qmetadata_encode_extended_gr_length_fx( const UWord16 value, const UWord16 alphabet_size, const Word16 gr_param ) @@ -3033,7 +3033,7 @@ ivas_qmetadata_encode_extended_gr_length( IF( LE_32( msb_alphabet_size, 3 ) ) { /* EncodeQuasiUniform is always equal or better than Limited GR with up to 3 msb values */ - bits = ivas_qmetadata_encode_quasi_uniform_length( value, alphabet_size ); + bits = ivas_qmetadata_encode_quasi_uniform_length_fx( value, alphabet_size ); } ELSE { @@ -3048,7 +3048,7 @@ ivas_qmetadata_encode_extended_gr_length( ELSE { lsb = (UWord16) L_and( value, L_sub( L_shl( 1U, gr_param ), 1 ) ); - bits = add( bits, ivas_qmetadata_encode_quasi_uniform_length( lsb, (UWord16) L_sub( alphabet_size, L_shl( L_sub( msb_alphabet_size, 1 ), gr_param ) ) ) ); + bits = add( bits, ivas_qmetadata_encode_quasi_uniform_length_fx( lsb, (UWord16) L_sub( alphabet_size, L_shl( L_sub( msb_alphabet_size, 1 ), gr_param ) ) ) ); } } @@ -3133,11 +3133,11 @@ static Word16 ivas_qmetadata_reorder_azimuth_index_fx( } /*------------------------------------------------------------------------- - * ivas_qmetadata_encode_extended_gr() + * ivas_qmetadata_encode_extended_gr_fx() * * *------------------------------------------------------------------------*/ -void ivas_qmetadata_encode_extended_gr( +void ivas_qmetadata_encode_extended_gr_fx( BSTR_ENC_HANDLE hMetaData, const UWord16 value, const UWord16 alphabet_size, @@ -3152,7 +3152,7 @@ void ivas_qmetadata_encode_extended_gr( IF( LE_32( msb_alphabet_size, 3 ) ) { /* EncodeQuasiUniform is always equal or better than Limited GR with up to 3 msb values */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, value, alphabet_size ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, value, alphabet_size ); } ELSE { @@ -3175,7 +3175,7 @@ void ivas_qmetadata_encode_extended_gr( } ELSE { - ivas_qmetadata_encode_quasi_uniform( hMetaData, lsb, (UWord16) L_sub( alphabet_size, L_shl( L_sub( msb_alphabet_size, 1 ), gr_param ) ) ); + ivas_qmetadata_encode_quasi_uniform_fx( hMetaData, lsb, (UWord16) L_sub( alphabet_size, L_shl( L_sub( msb_alphabet_size, 1 ), gr_param ) ) ); } } @@ -3253,7 +3253,7 @@ static Word16 truncGR0_fx( move32(); data_idx[i] = remap3b[data_idx[i]]; move16(); - bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 8, 0 ) ); + bits = add( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[i], 8, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[i] - data_hat[i] ) ); /*(data[i] - data_hat[i])*(data[i] - data_hat[i]);*/ L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 @@ -3269,7 +3269,7 @@ static Word16 truncGR0_fx( { IF( GT_32( data_idx[indx[i]], 3 ) ) { - bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); + bits = sub( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[indx[i]], 8, 0 ) ); // data_idx[indx[i]] = quantize_phi( data[indx[i]] + 180, 0, &data_hat[indx[i]], 4 ); data_idx[indx[i]] = quantize_phi_enc_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); move16(); @@ -3278,7 +3278,7 @@ static Word16 truncGR0_fx( move32(); data_idx[indx[i]] = remap2b[data_idx[indx[i]]]; move16(); - bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); + bits = add( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[indx[i]], 8, 0 ) ); // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 @@ -3300,7 +3300,7 @@ static Word16 truncGR0_fx( IF( GT_16( data_idx[indx[i]], 1 ) ) { - bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); + bits = sub( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[indx[i]], 8, 0 ) ); IF( LE_32( L_abs( data_fx[indx[i]] ), 377487360 ) ) // 90 in Q22 { @@ -3319,7 +3319,7 @@ static Word16 truncGR0_fx( move32(); } - bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); + bits = add( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[indx[i]], 8, 0 ) ); // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 @@ -3412,14 +3412,14 @@ static Word16 truncGR0_chan_fx( { data_idx[i] = quantize_phi_chan_lbr_fx( data_fx[i], &data_hat_fx[i], 9 ); move16(); - bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 9, 0 ) ); + bits = add( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[i], 9, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( ( data[i] - data_hat[i] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } - WHILE( GT_16( bits, bits_allowed ) ) + WHILE( ( bits > bits_allowed ) ) { // min_diff = 1000.0f; min_diff_fx = 2097152000; // 1000 in Q21 @@ -3454,10 +3454,10 @@ static Word16 truncGR0_chan_fx( IF( GT_16( idx_crt, -1 ) ) { - bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[idx_crt], 9, 0 ) ); + bits = sub( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[idx_crt], 9, 0 ) ); data_idx[idx_crt] = quantize_phi_chan_lbr_fx( data_fx[idx_crt], &data_hat_fx[idx_crt], add( data_idx[idx_crt], 1 ) ); move16(); - bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[idx_crt], 9, 0 ) ); + bits = add( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[idx_crt], 9, 0 ) ); // diff[idx_crt] = -st[idx_crt] - ct[idx_crt] * cosf( ( data[idx_crt] - data_hat[idx_crt] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[idx_crt], data_hat_fx[idx_crt] ), 91 ), 7 ) ) ) ); // Q31 @@ -3481,7 +3481,7 @@ static Word16 truncGR0_chan_fx( move16(); IF( data_idx[idx_crt] > 0 ) { - bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[idx_crt], 9, 0 ) ); + bits = sub( bits, ivas_qmetadata_encode_extended_gr_length_fx( data_idx[idx_crt], 9, 0 ) ); data_idx[idx_crt] = 0; move16(); data_hat_fx[idx_crt] = 0; @@ -3705,14 +3705,14 @@ static Word16 common_direction_fx( { FOR( i = 0; i < len; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_direction->band_data[band_idx].azimuth_index[i], 9, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_direction->band_data[band_idx].azimuth_index[i], 9, 0 ); } } ELSE { FOR( i = 0; i < len; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_direction->band_data[band_idx].azimuth_index[i], 8, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_direction->band_data[band_idx].azimuth_index[i], 8, 0 ); } } } @@ -3734,8 +3734,9 @@ static Word16 encode_directions_subband_fx( const Word16 no_subframes, const Word16 last_subband, Word16 *p_diff, - Word32 *elevation_orig_fx, - Word32 *azimuth_orig_fx ) + Word32 *elevation_orig_fx, // Q22 + Word32 *azimuth_orig_fx // Q22 +) { Word16 allowed_bits, use_vq, max_nb_idx, k; Word16 diff; @@ -3807,8 +3808,8 @@ static Word16 encode_directions_subband_fx( IF( last_subband == 0 ) { - Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); // Q22 + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); // Q22 joint_encoding_fx( q_direction, j, next_j, coding_subbands, bits_dir0, allowed_bits, hMetaData, &diff ); } ELSE @@ -3831,8 +3832,8 @@ static Word16 encode_directions_subband_fx( ELSE { /* there is only joint coding */ - Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); // Q22 + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); // Q22 IF( last_subband == 0 ) { @@ -3859,8 +3860,8 @@ static Word16 encode_directions_subband_fx( { /* 1 subframe case */ /* there is only joint coding */ - Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); // Q22 + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); // Q22 IF( last_subband == 0 ) { @@ -3983,8 +3984,8 @@ static ivas_error requantize_direction_EC_3_fx( IVAS_QDIRECTION *q_direction, const Word16 coding_subbands, BSTR_ENC_HANDLE hMetaData, - Word32 elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word16 *ind_order ) { /* gradually increase the bits following the performance of the EC layer*/ @@ -4090,7 +4091,7 @@ static ivas_error requantize_direction_EC_3_fx( { FOR( k = 0; k < no_subframes; k++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ? 9 : 8, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ? 9 : 8, 0 ); } } } @@ -4240,7 +4241,7 @@ static void joint_encoding_fx( IF( len_data > 0 ) { - nbits = GR_bits_new( data, no_symb_ele, len_data, MASA_GR_ORD_EL, 1, &GR_ord_elevation ); + nbits = GR_bits_new_fx( data, no_symb_ele, len_data, MASA_GR_ORD_EL, 1, &GR_ord_elevation ); } ELSE { @@ -4273,9 +4274,9 @@ static void joint_encoding_fx( nbits = add( nbits, 1 ); } - nbits = add( nbits, GR_bits_azimuth_context( q_direction->band_data[j].azimuth_index, - q_direction->band_data[j].azimuth_m_alphabet, q_direction->cfg.nblocks, MASA_GR_ORD_AZ, - q_direction->band_data[j].bits_sph_idx, &GR_ord_azimuth, &use_context ) ); + nbits = add( nbits, GR_bits_azimuth_context_fx( q_direction->band_data[j].azimuth_index, + q_direction->band_data[j].azimuth_m_alphabet, q_direction->cfg.nblocks, MASA_GR_ORD_AZ, + q_direction->band_data[j].bits_sph_idx, &GR_ord_azimuth, &use_context ) ); IF( allowed_bits == 0 ) { @@ -4507,7 +4508,7 @@ static ivas_error write_ec_direction_fx( { bits_crt = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, data, qdirection->band_data[j_idx].elevation_m_alphabet[i], GR_ord_elevation ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, data, qdirection->band_data[j_idx].elevation_m_alphabet[i], GR_ord_elevation ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); } } @@ -4532,7 +4533,7 @@ static ivas_error write_ec_direction_fx( { bits_crt = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], GR_ord_azimuth ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], GR_ord_azimuth ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); } } @@ -4562,7 +4563,7 @@ static ivas_error write_ec_direction_fx( bits_crt = hMetaData->nb_bits_tot; move16(); maximum_s( qdirection->band_data[j_idx].azimuth_m_alphabet, len, &max_val ); - ivas_qmetadata_encode_extended_gr( hMetaData, min_val, max_val, MASA_GR_ORD_AZ ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, min_val, max_val, MASA_GR_ORD_AZ ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); FOR( i = 0; i < len; i++ ) @@ -4572,7 +4573,7 @@ static ivas_error write_ec_direction_fx( { bits_crt = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], GR_ord_azimuth ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], GR_ord_azimuth ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); } } @@ -4596,13 +4597,13 @@ static ivas_error write_ec_direction_fx( case 2: bits_crt = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], MASA_GR_ORD_AZ - 1 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], MASA_GR_ORD_AZ - 1 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); BREAK; default: bits_crt = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], MASA_GR_ORD_AZ ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, data, qdirection->band_data[j_idx].azimuth_m_alphabet[i], MASA_GR_ORD_AZ ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_crt ) ); BREAK; } @@ -4619,7 +4620,7 @@ static ivas_error write_ec_direction_fx( * Local functions (coherence Q and coding) *-----------------------------------------------------------------------*/ /*! r: index */ -static UWord64 create_combined_index( +static UWord64 create_combined_index_fx( UWord16 *idx_dct, /* i : indexes to combine */ const Word16 len, /* i : number of indexes */ const Word16 *no_cb_vec /* i : how many codewords for each position */ @@ -4665,12 +4666,12 @@ static Word16 encode_coherence_indexesDCT0_fx( IF( nbits1 > 0 ) { half_len = shr( len, 1 ); - idx = create_combined_index( idx_dct, half_len, no_cb_vec ); - idx1 = create_combined_index( &idx_dct[half_len], half_len, &no_cb_vec[half_len] ); + idx = create_combined_index_fx( idx_dct, half_len, no_cb_vec ); + idx1 = create_combined_index_fx( &idx_dct[half_len], half_len, &no_cb_vec[half_len] ); } ELSE { - idx = create_combined_index( idx_dct, len, no_cb_vec ); + idx = create_combined_index_fx( idx_dct, len, no_cb_vec ); idx1 = 0; move16(); } @@ -4682,7 +4683,7 @@ static Word16 encode_coherence_indexesDCT0_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits, ONE_IN_Q3 ), 4 ); } @@ -4708,7 +4709,7 @@ static Word16 encode_coherence_indexesDCT0_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits1 / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits1 / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits1, ONE_IN_Q3 ), 4 ); } @@ -4765,7 +4766,7 @@ static Word16 coherence_coding_length( { no_cb = no_cb * no_cv[j]; } - //*nbits_fr = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + //*nbits_fr = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { *nbits_fr = 0; @@ -4781,7 +4782,7 @@ static Word16 coherence_coding_length( { no_cb = no_cb * no_cv[j]; } - //*nbits_fr1 = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + //*nbits_fr1 = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { *nbits_fr1 = 0; @@ -4799,7 +4800,7 @@ static Word16 coherence_coding_length( { no_cb = no_cb * no_cv[j]; } - //*nbits_fr = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + //*nbits_fr = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { *nbits_fr = 0; @@ -4814,7 +4815,7 @@ static Word16 coherence_coding_length( } - minimum_s( (const Word16 *) idx_sur_coh_shift, (int16_t) idx_shift_len, &min_idx ); + minimum_s( (const Word16 *) idx_sur_coh_shift, (Word16) idx_shift_len, &min_idx ); FOR( j = 0; j < idx_shift_len; j++ ) { mr_idx[j] = sub( idx_sur_coh_shift[j], min_idx ); @@ -4822,7 +4823,7 @@ static Word16 coherence_coding_length( no_cv_shift[j] = sub( no_cv_shift[j], min_idx ); move16(); } - nbits = add( add( min_idx, 1 ), GR_bits_new( mr_idx, no_cv_shift, idx_shift_len, *GR_ord, 1, GR_ord ) ); + nbits = add( add( min_idx, 1 ), GR_bits_new_fx( mr_idx, no_cv_shift, idx_shift_len, *GR_ord, 1, GR_ord ) ); *p_min_idx = min_idx; move16(); @@ -4876,7 +4877,7 @@ static Word16 encode_spread_coherence_1sf_fx( move16(); extra_cv = -1; move16(); - WHILE( LE_16( tmp, coding_subbands ) ) + WHILE( ( tmp <= coding_subbands ) ) { tmp = add( tmp, 6 ); extra_cv = add( extra_cv, 1 ); @@ -4897,7 +4898,7 @@ static Word16 encode_spread_coherence_1sf_fx( // idx_sp_coh[j] = (uint16_t) roundf( q_direction->coherence_band_data[j].spread_coherence[0] / ( 255.0f / (float) idx_ER ) ); idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 /* 1/255.f in Q31 */ ) ); move16(); - // q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( idx_sp_coh[j] * ( 255.0f / (float) idx_ER ) ); + // q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) roundf( idx_sp_coh[j] * ( 255.0f / (float) idx_ER ) ); IF( idx_sp_coh[j] ) { q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) idiv1616( imult1616( idx_sp_coh[j], 255 ), idx_ER ); @@ -4966,19 +4967,19 @@ static Word16 encode_spread_coherence_1sf_fx( /* write max value*/ bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, add( sub( sub( MASA_MAX_NO_CV_SUR_COH, max_val ), 1 ), extra_cv ), add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMasaMetaData, add( sub( sub( MASA_MAX_NO_CV_SUR_COH, max_val ), 1 ), extra_cv ), add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); } IF( nbits_fr1 > 0 ) { half_coding_subbands = shr( coding_subbands, 1 ); - idx = create_combined_index( idx_sp_coh, half_coding_subbands, no_cv ); - idx1 = create_combined_index( &idx_sp_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); + idx = create_combined_index_fx( idx_sp_coh, half_coding_subbands, no_cv ); + idx1 = create_combined_index_fx( &idx_sp_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); } ELSE { - idx = create_combined_index( idx_sp_coh, coding_subbands, no_cv ); + idx = create_combined_index_fx( idx_sp_coh, coding_subbands, no_cv ); } // if ( nbits_fr % 16 == 0 ) @@ -4988,7 +4989,7 @@ static Word16 encode_spread_coherence_1sf_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits_fr / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits_fr / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 ); } @@ -5012,7 +5013,7 @@ static Word16 encode_spread_coherence_1sf_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits_fr1, ONE_IN_Q3 ), 4 ); } @@ -5044,7 +5045,7 @@ static Word16 encode_spread_coherence_1sf_fx( /* write the min */ bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMasaMetaData, min_idx, add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -5052,7 +5053,7 @@ static Word16 encode_spread_coherence_1sf_fx( { bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, mr_idx_sp_coh[j], no_cv_shift[j], GR_ord ); + ivas_qmetadata_encode_extended_gr_fx( hMasaMetaData, mr_idx_sp_coh[j], no_cv_shift[j], GR_ord ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); } } @@ -5118,11 +5119,11 @@ static Word16 encode_surround_coherence_fx( { k = add( k, hQMetaData->twoDirBands[j] ); idx16 = s_max( sub( k, 1 ), 0 ); - error_ratio_surr = W_sat_l( W_sub( W_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), W_mult0_32_32( q_direction[1].band_data[idx16].energy_ratio_fx[0], hQMetaData->twoDirBands[j] ) ) ); + error_ratio_surr = W_sat_l( W_sub( W_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), W_mult0_32_32( q_direction[1].band_data[idx16].energy_ratio_fx[0], hQMetaData->twoDirBands[j] ) ) ); // Q30 } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); // Q30 } IF( error_ratio_surr <= 0 ) @@ -5193,18 +5194,18 @@ static Word16 encode_surround_coherence_fx( /* write max value*/ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } IF( nbits_fr1 > 0 ) { - idx = create_combined_index( idx_sur_coh, half_coding_subbands, no_cv ); - idx1 = create_combined_index( &idx_sur_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); + idx = create_combined_index_fx( idx_sur_coh, half_coding_subbands, no_cv ); + idx1 = create_combined_index_fx( &idx_sur_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); } ELSE { - idx = create_combined_index( idx_sur_coh, coding_subbands, no_cv ); + idx = create_combined_index_fx( idx_sur_coh, coding_subbands, no_cv ); } // if ( nbits_fr % 16 == 0 ) @@ -5214,7 +5215,7 @@ static Word16 encode_surround_coherence_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits_fr / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits_fr / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 ); } @@ -5238,7 +5239,7 @@ static Word16 encode_surround_coherence_fx( } ELSE { - // no_idx16 = (int16_t) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); + // no_idx16 = (Word16) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); no_idx16 = shr_r( add( nbits_fr1, ONE_IN_Q3 ), 4 ); } @@ -5271,7 +5272,7 @@ static Word16 encode_surround_coherence_fx( /* write the min */ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -5280,7 +5281,7 @@ static Word16 encode_surround_coherence_fx( bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, mr_idx_sur_coh[j], no_cv_shift[j], GR_ord ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, mr_idx_sur_coh[j], no_cv_shift[j], GR_ord ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } @@ -5303,7 +5304,7 @@ static Word16 encode_surround_coherence_hr_fx( UWord64 idx, idx1; Word16 no_idx16; Word16 no_cv[MASA_MAXIMUM_CODING_SUBBANDS]; - Word32 error_ratio_surr; + Word32 error_ratio_surr; // Q30 IVAS_QDIRECTION *q_direction; Word16 half_coding_subbands, nbits_fr1, coding_subbands; Word16 all_coherence_zero; @@ -5343,15 +5344,15 @@ static Word16 encode_surround_coherence_hr_fx( { k = add( k, hQMetaData->twoDirBands[j] ); idx16 = s_max( sub( k, 1 ), 0 ); - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[sf] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[sf] ); // Q30 IF( hQMetaData->twoDirBands[j] ) { - error_ratio_surr = L_sub( error_ratio_surr, q_direction[1].band_data[idx16].energy_ratio_fx[sf] ); + error_ratio_surr = L_sub( error_ratio_surr, q_direction[1].band_data[idx16].energy_ratio_fx[sf] ); // Q30 } } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[sf] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[sf] ); // Q30 } /* if ( error_ratio_surr <= 0 ) Restricting precision to 7 decimal places */ @@ -5424,18 +5425,18 @@ static Word16 encode_surround_coherence_hr_fx( /* write max value*/ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } IF( nbits_fr1 > 0 ) { - idx = create_combined_index( idx_sur_coh, half_coding_subbands, no_cv ); - idx1 = create_combined_index( &idx_sur_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); + idx = create_combined_index_fx( idx_sur_coh, half_coding_subbands, no_cv ); + idx1 = create_combined_index_fx( &idx_sur_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); } ELSE { - idx = create_combined_index( idx_sur_coh, coding_subbands, no_cv ); + idx = create_combined_index_fx( idx_sur_coh, coding_subbands, no_cv ); } IF( nbits_fr % 16 == 0 ) @@ -5497,7 +5498,7 @@ static Word16 encode_surround_coherence_hr_fx( /* write the min */ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -5506,7 +5507,7 @@ static Word16 encode_surround_coherence_hr_fx( bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, mr_idx_sur_coh[j], no_cv_shift[j], GR_ord ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, mr_idx_sur_coh[j], no_cv_shift[j], GR_ord ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } @@ -5527,10 +5528,10 @@ static Word16 encode_surround_coherence_hr_fx( /*! r: quantized value */ static Word32 quantize_DCT_0_coh_fx( // o:Q21 const Word16 x, /* i : input value Q14 */ - const int16_t j, /* i : subband index */ + const Word16 j, /* i : subband index */ const Word16 *coherence_cb, /* i : coherence codebook Q14 */ const Word16 delta_var, /* i : azimuth variance threshold Q6 */ - const int16_t no_cb, /* i : maximum number of codewords */ + const Word16 no_cb, /* i : maximum number of codewords */ IVAS_QDIRECTION *q_direction, /* i : quantized metadata */ UWord16 *idx_x, /* o : codewords index */ Word16 *p_no_cb, /* o : actual number of codewords dependent on energy ratio value */ @@ -5596,11 +5597,11 @@ static Word16 encode_coherence_indexesDCT1_fx( nbits = 0; move16(); - nbits = mean_removed_GR_new( idx_dct, MASA_NO_CV_COH1, len, 0, &GR_ord, &av, mr_idx_dct ); + nbits = mean_removed_GR_new_fx( idx_dct, MASA_NO_CV_COH1, len, 0, &GR_ord, &av, mr_idx_dct ); FOR( i = 0; i < len; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, mr_idx_dct[i], 2 * MASA_NO_CV_COH1, GR_ord ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, mr_idx_dct[i], 2 * MASA_NO_CV_COH1, GR_ord ); } nbits = add( nbits, len_huf_masa[av] ); @@ -5616,7 +5617,7 @@ static Word16 encode_coherence_indexesDCT1_fx( * 4D implementation of DCT transform *-------------------------------------------------------------------*/ static void dct4_transform_fx( - uint8_t *v, /* i : input 4D vector */ + UWord8 *v, /* i : input 4D vector */ Word32 *dct_v /* o : output transformed vector Q21 */ ) { @@ -5629,11 +5630,11 @@ static void dct4_transform_fx( dct_v[0] = L_add( a, b ); // 0.5f * (a + b); move32(); - dct_v[1] = L_add( Mpy_32_32_r( 1402911301 /*0.653281482438188f*/, c ), Mpy_32_32_r( 581104888 /*0.270598050073099f*/, d ) ); + dct_v[1] = L_add( Mpy_32_32_r( 1402911301 /*0.653281482438188f.Q31*/, c ), Mpy_32_32_r( 581104888 /*0.270598050073099f.Q31*/, d ) ); move32(); dct_v[2] = L_sub( a, b ); // 0.5f * (a - b); move32(); - dct_v[3] = L_sub( Mpy_32_32_r( 581104888 /*0.270598050073099f*/, c ), Mpy_32_32_r( 1402911301 /*0.653281482438188f*/, d ) ); + dct_v[3] = L_sub( Mpy_32_32_r( 581104888 /*0.270598050073099f.Q31*/, c ), Mpy_32_32_r( 1402911301 /*0.653281482438188f.Q31*/, d ) ); move32(); return; @@ -5679,7 +5680,7 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( cbsize = shl( 1, bits_coh ); // delta = 256.0f / cbsize; - delta = div_l( 256, shr( cbsize, 1 ) ); + delta = div_l( 256, shr( cbsize, 1 ) ); // Q15 FOR( k = 0; k < nblocks; k++ ) { @@ -5689,7 +5690,7 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( { idx_coh[j] = usquant_fx( (Word16) ( q_direction->coherence_band_data[j].spread_coherence[k] ), &tmp, shr( delta, 1 ), shr( delta, 1 ) /* Q-1 */, cbsize ); move16(); - q_direction->coherence_band_data[j].spread_coherence[k] = (UWord8) add( imult1616( idx_coh[j], delta ), shr( delta, 1 ) ); + q_direction->coherence_band_data[j].spread_coherence[k] = (UWord8) add( imult1616( idx_coh[j], delta ), shr( delta, 1 ) /*delta/2*/ ); // Q15 if ( LT_16( idx_coh[j], min_idx ) ) { min_idx = idx_coh[j]; @@ -5706,8 +5707,8 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( { idx_coh[j] = sub( idx_coh[j], min_idx ); move16(); - nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( idx_coh[j], sub( cbsize, min_idx ), 0 ) ); - nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length( idx_coh[j], sub( cbsize, min_idx ), 1 ) ); + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length_fx( idx_coh[j], sub( cbsize, min_idx ), 0 ) ); + nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length_fx( idx_coh[j], sub( cbsize, min_idx ), 1 ) ); } IF( nbits0 < nbits1 ) { @@ -5724,7 +5725,7 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( GR_param_av = 1; move16(); - nbits_av = mean_removed_GR_new( idx_coh, cbsize, nbands, 1, &GR_param_av, &av, mr_idx ); + nbits_av = mean_removed_GR_new_fx( idx_coh, cbsize, nbands, 1, &GR_param_av, &av, mr_idx ); IF( LT_16( nbits_av, nbits1 ) ) { @@ -5744,7 +5745,7 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( FOR( j = 0; j < nbands; j++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, mr_idx[j], imult1616( 2, cbsize ), GR_param ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, mr_idx[j], imult1616( 2, cbsize ), GR_param ); } } ELSE @@ -5760,7 +5761,7 @@ static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( FOR( j = 0; j < nbands; j++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, idx_coh[j], sub( cbsize, min_idx ), GR_param ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, idx_coh[j], sub( cbsize, min_idx ), GR_param ); } } } @@ -5893,7 +5894,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( IF( write_flag ) { /* quantize first DCT parameter */ - dct_coh[j][0] = quantize_DCT_0_coh_fx( extract_l( L_shr_r( dct_coh[j][0], 7 ) ), j, coherence_cb0_masa_Q14, MASA_DELTA_AZI_DCT0 << Q6, MASA_NO_CV_COH, q_direction, &idx_dct[k], &no_cb_vec[j], hrmasa_flag ); + dct_coh[j][0] = quantize_DCT_0_coh_fx( extract_l( L_shr_r( dct_coh[j][0], 7 ) ), j, coherence_cb0_masa_Q14, MASA_DELTA_AZI_DCT0 << Q6, MASA_NO_CV_COH, q_direction, &idx_dct[k], &no_cb_vec[j], hrmasa_flag ); // Q21 move32(); } @@ -5930,7 +5931,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( no_cb = no_cb * no_cb_vec[j]; } - // nbits = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + // nbits = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { nbits = 0; @@ -5947,7 +5948,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( { no_cb = no_cb * no_cb_vec[j]; } - // nbits1 = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + // nbits1 = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { nbits1 = 0; @@ -5968,7 +5969,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( no_cb = no_cb * no_cb_vec[j]; } - // nbits = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + // nbits = (Word16) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); IF( LE_64( no_cb, 1 ) ) { nbits = 0; @@ -6064,7 +6065,7 @@ static void ivas_qmetadata_reorder_2dir_bands_fx( hQMetaData->q_direction[1].band_data[band].spherical_index[sf] = uint16_tmp; move16(); - fx_tmp = hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf]; + fx_tmp = hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf]; // Q22 move32(); hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[1].band_data[band].azimuth_fx[sf]; move32(); @@ -6073,7 +6074,7 @@ static void ivas_qmetadata_reorder_2dir_bands_fx( fx_tmp = hQMetaData->q_direction[0].band_data[band].elevation_fx[sf]; move32(); - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[1].band_data[band].elevation_fx[sf]; + hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[1].band_data[band].elevation_fx[sf]; // Q22 move32(); hQMetaData->q_direction[1].band_data[band].elevation_fx[sf] = fx_tmp; move32(); @@ -6099,7 +6100,7 @@ static void ivas_qmetadata_reorder_2dir_bands_fx( { fx_tmp = hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0]; move32(); - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0] = hQMetaData->q_direction[1].band_data[band].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0] = hQMetaData->q_direction[1].band_data[band].energy_ratio_fx[0]; // Q30 move32(); hQMetaData->q_direction[1].band_data[band].energy_ratio_fx[0] = fx_tmp; move32(); @@ -6153,7 +6154,7 @@ static Word16 write_2dir_info( move16(); FOR( i = 0; i < k; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dif_p[i], 24, 0 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, dif_p[i], 24, 0 ); } nbits = sub( hMetaData->nb_bits_tot, j ); @@ -6179,7 +6180,7 @@ static void transform_azimuth_dir2_fx( FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nblocks; b++ ) { Word64 azimuth; - azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), DEGREE_180_Q_22 ); + azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), DEGREE_180_Q_22 ); // Q22 IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { @@ -6227,11 +6228,11 @@ static Word16 divide_GR_orders_fx( FOR( j = 0; j <= i; j++ ) { - nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR1 ) ); } FOR( j = i + 1; j < len; j++ ) { - nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR2 ) ); } IF( LT_16( nb_GR, nb_GR_min ) ) @@ -6261,8 +6262,8 @@ static Word16 find_optimal_GR_order_fx( move16(); FOR( i = 0; i < len; i++ ) { - nb_GR_0 = add( nb_GR_0, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 0 ) ); - nb_GR_1 = add( nb_GR_1, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 1 ) ); + nb_GR_0 = add( nb_GR_0, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[i], 100, 0 ) ); + nb_GR_1 = add( nb_GR_1, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[i], 100, 1 ) ); } IF( LT_16( nb_GR_0, nb_GR_1 ) ) @@ -6410,7 +6411,7 @@ static Word16 write_stream_dct_coeffs_omasa_fx( update_needed = 0; move16(); move16(); - WHILE( GE_16( len_stream, 8 ) && GT_16( nb_GR_min, max_bits ) && GE_16( changed, 1 ) ) + WHILE( ( len_stream >= 8 ) && ( nb_GR_min > max_bits ) && ( changed >= 1 ) ) { test(); test(); @@ -6427,19 +6428,19 @@ static Word16 write_stream_dct_coeffs_omasa_fx( { changed = 1; move16(); - nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR2 ) ); q_idx[j] = sub( q_idx[j], 2 ); move16(); - nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR2 ) ); } ELSE { changed = 1; move16(); - nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR1 ) ); q_idx[j] = sub( q_idx[j], 2 ); move16(); - nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, 0 ) ); } } ELSE IF( EQ_16( q_idx[j], 1 ) ) @@ -6448,20 +6449,20 @@ static Word16 write_stream_dct_coeffs_omasa_fx( { changed = 1; move16(); - nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR2 ) ); q_idx[j] = sub( q_idx[j], 1 ); move16(); - nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR2 ) ); } ELSE { changed = 1; move16(); - nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, GR1 ) ); q_idx[j] = sub( q_idx[j], 1 ); move16(); - nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length_fx( q_idx[j], 100, 0 ) ); } } IF( LT_16( nb_GR_min, max_bits ) ) @@ -6495,12 +6496,12 @@ static Word16 write_stream_dct_coeffs_omasa_fx( /* write GR data */ FOR( i = 1; i <= i_min; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_idx[i], 100, GR1 ); } FOR( i = i_min + 1; i < len_stream; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR2 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_idx[i], 100, GR2 ); } } ELSE @@ -6511,7 +6512,7 @@ static Word16 write_stream_dct_coeffs_omasa_fx( nb_bits = add( nb_bits, 1 ); FOR( i = 1; i < len_stream; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + ivas_qmetadata_encode_extended_gr_fx( hMetaData, q_idx[i], 100, GR1 ); } } @@ -6727,7 +6728,7 @@ void ivas_omasa_encode_masa_to_total_fx( FOR( j = 0; j < nbands; j++ ) { masa_to_total_energy_ratio[i][j] = L_max( 0, q_dct_data[k] ); - masa_to_total_energy_ratio[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio[i][j] ); // Q30 move32(); move32(); k = add( k, 1 ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 5e661f0f43cdd6bc92227ce3235bc1e877c7658c..c05ce1ed02dffdf13a0b7b20bc37fa7ae0d5cdaa 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -592,11 +592,10 @@ typedef struct ivas_stereo_classifier_data_structure Word32 Etot_up_fx; /* average energy in dB - upper bound */ Word16 Etot_up_e; /* average energy in dB - upper bound */ Word32 relE_buf_fx[UNCLR_L_RELE]; /* running buffer for relative energy Q31 */ - Word16 relE_buf_e; /* running buffer for relative energy Q31 */ Word32 Etot_buf_fx[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ Word16 e_Etot_buf_fx; /* exponent for Etot_buf_fx*/ Word32 relE_0_1_fx; /* relative energy in the current frame normalized to (0,1) Q31 */ - Word32 relE_0_1_LT_fx; // Q31 + Word32 relE_0_1_LT_fx; /* Q31 */ Word32 unclr_relE_0_1_LT_fx[UNCLR_RC_ORDER]; // Q31 Word32 unclr_wscore_fx; // Q31 Word32 unclr_fv_fx[SSC_MAX_NFEA]; /* UNCLR - feature vector */ // Q15 diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 6e9165a05c7d385983370eb98e148d8a9e8ffce2..4ef371572a71cabeb96736ef5fecad35e4188d48 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -365,8 +365,6 @@ void stereo_classifier_init_fx( move16(); set_zero_fx( hStereoClassif->relE_buf_fx, UNCLR_L_RELE ); - hStereoClassif->relE_buf_e = 0; - move16(); set_zero_fx( hStereoClassif->Etot_buf_fx, UNCLR_L_ETOT ); hStereoClassif->e_Etot_buf_fx = 0; move16(); @@ -425,15 +423,12 @@ void stereo_classifier_init_fx( *-----------------------------------------------------------------*/ /* Information on ouputs: hStereoClassif->Etot_buf_fx has expoenent hStereoClassif->e_Etot_buf_fx -hStereoClassif->relE_buf_fx has expoenent hStereoClassif->relE_buf_e hStereoClassif->lsf_ch1_fx has Q1*1.28 hStereoClassif->xtalk_fv_fx has exponent 16 hStereoClassif->voicing_ch1_fx has Q-factor Q15 hStereoClassif->lepsP_ch1_fx has exponent 16 hStereoClassif->Etot_up_fx has exponent hStereoClassif->Etot_up_e hStereoClassif->Etot_dn_fx has exponent hStereoClassif->Etot_dn_e -hStereoClassif->relE_0_1_fx has exponent hStereoClassif->relE_buf_e -hStereoClassif->relE_0_1_LT_fx has exponent hStereoClassif->relE_buf_e hStereoClassif->cor_map_sum_ch1_fx has exponent hStereoClassif->cor_map_sum_ch1_e hStereoClassif->non_sta_ch1_fx has exponent hStereoClassif->non_sta_ch1_e hStereoClassif->sp_div_ch1_fx has exponent sp_div_e @@ -466,7 +461,6 @@ void stereo_classifier_features_ivas_fx( ) { Word16 i, clas_ch2; - Word16 e_relE_0_1_fx; Word16 ener_e; Word32 lepsP_ch2_fx, ener_l_fx, ener_r_fx; @@ -585,30 +579,26 @@ void stereo_classifier_features_ivas_fx( } /* normalize Etot to (0,1) */ - e_relE_0_1_fx = sub( 31, hStereoClassif->e_Etot_buf_fx ); - hStereoClassif->relE_0_1_fx = lin_interp32_fx( hStereoClassif->Etot_buf_fx[0], hStereoClassif->Etot_dn_fx, 0, hStereoClassif->Etot_up_fx, L_shr( 1932735283, hStereoClassif->e_Etot_buf_fx /*0.9f exp:Etot_buf_fx*/ ), 1, &e_relE_0_1_fx ); /*e_relE_0_1_fx is ouput exp*/ - e_relE_0_1_fx = sub( 31, e_relE_0_1_fx ); + hStereoClassif->relE_0_1_fx = lin_interp32_fx( hStereoClassif->Etot_buf_fx[0], hStereoClassif->Etot_dn_fx, 0, hStereoClassif->Etot_up_fx, 1932735283 /* 0.9 in Q31 */, 1 ); move32(); /* update relE_buf */ Copy32( &hStereoClassif->relE_buf_fx[0], &hStereoClassif->relE_buf_fx[1], UNCLR_L_RELE - 1 ); - hStereoClassif->relE_0_1_fx = L_shr( hStereoClassif->relE_0_1_fx, sub( hStereoClassif->relE_buf_e, e_relE_0_1_fx ) ); /*scaling down to exponent of e_relE_buf_fx*/ - hStereoClassif->relE_buf_fx[0] = hStereoClassif->relE_0_1_fx; /*scaling down to exponent of e_relE_buf_fx*/ - move32(); + hStereoClassif->relE_buf_fx[0] = hStereoClassif->relE_0_1_fx; move32(); IF( GE_32( hStereoClassif->relE_0_1_fx, hStereoClassif->relE_buf_fx[1] ) ) { - hStereoClassif->relE_0_1_LT_fx = Mpy_32_16_1( hStereoClassif->relE_0_1_LT_fx, 29491 /*0.9f q15*/ ) + Mpy_32_16_1( hStereoClassif->relE_0_1_fx, 3277 /*0.1f q15*/ ); + hStereoClassif->relE_0_1_LT_fx = L_add( Mpy_32_16_1( hStereoClassif->relE_0_1_LT_fx, 29491 /* 0.9f in Q15 */ ), Mpy_32_16_1( hStereoClassif->relE_0_1_fx, 3277 /* 0.1f in Q15 */ ) ); } ELSE { - hStereoClassif->relE_0_1_LT_fx = Mpy_32_16_1( hStereoClassif->relE_0_1_LT_fx, 31129 /*0.95f q15*/ ) + Mpy_32_16_1( hStereoClassif->relE_0_1_fx, 1638 /*0.05f0 q15*/ ); + hStereoClassif->relE_0_1_LT_fx = L_add( Mpy_32_16_1( hStereoClassif->relE_0_1_LT_fx, 31129 /* 0.95f in Q15 */ ), Mpy_32_16_1( hStereoClassif->relE_0_1_fx, 1638 /* 0.05f in Q15 */ ) ); } move32(); /* estimate VAD flag based on relative energy */ - IF( LT_32( hStereoClassif->relE_0_1_LT_fx, L_shr( 214748365, hStereoClassif->relE_buf_e ) ) ) + IF( LT_32( hStereoClassif->relE_0_1_LT_fx, 214748365 /* 0.1f in Q31 */ ) ) { hStereoClassif->vad_relE = 0; } diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 81a83c7f3d59407d852000ce35e30bbd4c48c61c..9ea1af949121921157f3952fb153362c7ddb243a 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -135,16 +135,18 @@ Word16 peak_vq_enc_ivas_fx( logqnorm_ivas_fx( &nf_gains[i], 12, &indx, 32, 1, &thren_HQ_fx[0] ); /* De-quantization */ - acc = L_add( dicn_fx[indx], 0 ); /* Q14 */ + acc = dicn_fx[indx]; /* Q14 */ + move32(); nf_gains[i] = L_shr( acc, 1 + 2 ); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ move32(); - push_indice( hBstr, IND_HVQ_NF_GAIN, (int) indx, 5 ); + + push_indice( hBstr, IND_HVQ_NF_GAIN, indx, 5 ); bits = add( bits, 5 ); } /* Signal number of peaks */ i = sub( max_peaks, vq_peaks ); - push_indice( hBstr, IND_NUM_PEAKS, (int) i, 5 ); + push_indice( hBstr, IND_NUM_PEAKS, i, 5 ); bits = add( bits, 5 ); /* Identify position of first peak and arrange peak gains by position */ @@ -258,8 +260,8 @@ Word16 peak_vq_enc_ivas_fx( move16(); } - push_indice( hBstr, IND_FLAGN, (int) FlagN, 1 ); - push_indice( hBstr, IND_PG_IDX, (int) pgain_difidx[0], GAIN0_BITS ); + push_indice( hBstr, IND_FLAGN, FlagN, 1 ); + push_indice( hBstr, IND_PG_IDX, pgain_difidx[0], GAIN0_BITS ); IF( FlagN ) { @@ -273,7 +275,7 @@ Word16 peak_vq_enc_ivas_fx( r = pgain_huffsizn[j]; move16(); - push_indice( hBstr, IND_PG_IDX, (int) m, r ); + push_indice( hBstr, IND_PG_IDX, m, r ); } } ELSE @@ -281,7 +283,7 @@ Word16 peak_vq_enc_ivas_fx( pPgainDifIdx = &pgain_difidx[1]; FOR( i = 0; i < vqPeaksMinus1; i++ ) { - push_indice( hBstr, IND_PG_IDX, (int) ( *pPgainDifIdx++ ), GAINI_BITS ); + push_indice( hBstr, IND_PG_IDX, ( *pPgainDifIdx++ ), GAINI_BITS ); } } @@ -298,6 +300,7 @@ Word16 peak_vq_enc_ivas_fx( IF( pos_vec[indx] < 0 ) { peak_gains[i] = L_negate( peak_gains[i] ); /* Q12 */ + move32(); } } @@ -307,13 +310,13 @@ Word16 peak_vq_enc_ivas_fx( num_overlap_bins = sub( 5, sub( vq_peak_idx[i + 1], vq_peak_idx[i] ) ); indx = sub( vq_peak_idx[i], 2 ); quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); - push_indice( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); } indx = sub( vq_peak_idx[i], 2 ); quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); - push_indice( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ @@ -392,6 +395,7 @@ Word16 peak_vq_enc_ivas_fx( FOR( k = 0; k < pvq_bands; k++ ) { indx = pvq_norm[k]; + move16(); tmp1 = ratio( gopt[k], fg_pred[k], &exp1 ); tmp1 = shr( tmp1, sub( 1, exp1 ) ); /* Q13 */ Mpy_32_16_ss( dicn_fx[indx], tmp1, &normq, &dontCare16 ); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ @@ -412,7 +416,8 @@ Word16 peak_vq_enc_ivas_fx( move16(); indx = pvq_norm[k]; move16(); - normq = L_add( dicn_fx[indx], 0 ); /* in Q14 */ + normq = dicn_fx[indx]; /* in Q14 */ + move32(); j = 0; move16(); IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) @@ -551,15 +556,17 @@ Word16 peak_vq_enc_fx( logqnorm_fx( &nf_gains[i], 12, &indx, 32, 1, 0 ); /* De-quantization */ - acc = L_add( dicn_fx[indx], 0 ); /* Q14 */ + acc = dicn_fx[indx]; /* Q14 */ + move32(); nf_gains[i] = L_shr( acc, 1 + 2 ); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ - push_indice_fx( hBstr, IND_HVQ_NF_GAIN, (int) indx, 5 ); + move32(); + push_indice_fx( hBstr, IND_HVQ_NF_GAIN, indx, 5 ); bits = add( bits, 5 ); } /* Signal number of peaks */ i = sub( max_peaks, vq_peaks ); - push_indice_fx( hBstr, IND_NUM_PEAKS, (int) i, 5 ); + push_indice_fx( hBstr, IND_NUM_PEAKS, i, 5 ); bits = add( bits, 5 ); /* Identify position of first peak and arrange peak gains by position */ @@ -650,6 +657,7 @@ Word16 peak_vq_enc_fx( /* Huffman coding */ hcode_l = 0; + move16(); pPgainDifIdx = &pgain_difidx[1]; FOR( i = 0; i < vqPeaksMinus1; i++ ) { @@ -670,8 +678,8 @@ Word16 peak_vq_enc_fx( move16(); } - push_indice_fx( hBstr, IND_FLAGN, (int) FlagN, 1 ); - push_indice_fx( hBstr, IND_PG_IDX, (int) pgain_difidx[0], GAIN0_BITS ); + push_indice_fx( hBstr, IND_FLAGN, FlagN, 1 ); + push_indice_fx( hBstr, IND_PG_IDX, pgain_difidx[0], GAIN0_BITS ); IF( FlagN ) { @@ -685,7 +693,7 @@ Word16 peak_vq_enc_fx( r = pgain_huffsizn[j]; move16(); - push_indice_fx( hBstr, IND_PG_IDX, (int) m, r ); + push_indice_fx( hBstr, IND_PG_IDX, m, r ); } } ELSE @@ -693,7 +701,7 @@ Word16 peak_vq_enc_fx( pPgainDifIdx = &pgain_difidx[1]; FOR( i = 0; i < vqPeaksMinus1; i++ ) { - push_indice_fx( hBstr, IND_PG_IDX, (int) ( *pPgainDifIdx++ ), GAINI_BITS ); + push_indice_fx( hBstr, IND_PG_IDX, ( *pPgainDifIdx++ ), GAINI_BITS ); } } @@ -710,6 +718,7 @@ Word16 peak_vq_enc_fx( IF( pos_vec[indx] < 0 ) { peak_gains[i] = L_negate( peak_gains[i] ); /* Q12 */ + move32(); } } @@ -719,13 +728,13 @@ Word16 peak_vq_enc_fx( num_overlap_bins = sub( 5, sub( vq_peak_idx[i + 1], vq_peak_idx[i] ) ); indx = sub( vq_peak_idx[i], 2 ); quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); - push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); } indx = sub( vq_peak_idx[i], 2 ); quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); - push_indice_fx( hBstr, IND_HVQ_PEAKS, (UWord16) vq_cb_idx, 8 ); + push_indice_fx( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ @@ -757,6 +766,7 @@ Word16 peak_vq_enc_fx( pCoefsOut = coefs_out + i; } k_sort[k] = k; + move16(); j = 0; move16(); pPvqVectorBandStart = pPvqVector; @@ -803,12 +813,14 @@ Word16 peak_vq_enc_fx( FOR( k = 0; k < pvq_bands; k++ ) { indx = pvq_norm[k]; + move16(); tmp1 = ratio( gopt[k], fg_pred[k], &exp1 ); tmp1 = shr( tmp1, sub( 1, exp1 ) ); /* Q13 */ Mpy_32_16_ss( dicn_fx[indx], tmp1, &normq, &dontCare16 ); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ logqnorm_fx( &normq, 12, &pvq_norm[k], 40, 1, 0 ); /* normq in Q(14+(16+13)+1-32)=Q12 */ pvq_norm[k] = sub( pvq_norm[k], 8 ); + move16(); IF( pvq_norm[k] < 0 ) { pvq_norm[k] = 0; @@ -819,7 +831,7 @@ Word16 peak_vq_enc_fx( pvq_bits = add( pvq_bits, HVQ_PVQ_GAIN_BITS ); pvq_norm[k] = add( pvq_norm[k], 8 ); - + move16(); indx = pvq_norm[k]; move16(); normq = L_add( dicn_fx[indx], 0 ); /* in Q14 */ @@ -839,6 +851,7 @@ Word16 peak_vq_enc_fx( tmp16 = extract_h( acc ); /* in Q(28 - 16 = 12) */ Mpy_32_16_ss( normq, tmp16, &acc, &dontCare16 ); /* acc(Q11), normq(Q14), tmp16(Q12) */ *pCoefsOut = L_shl( acc, 12 - 11 ); /* Q12 */ + move32(); j = add( j, 1 ); } pCoefsOut++; @@ -1064,12 +1077,14 @@ static void quant_peaks_fx( x[i] = div_s( manIn, manPeakGain ); /* in Q(15+expIn-expPeakGain) */ Qx_vec[i] = add( 15, sub( expIn, expPeakGain ) ); + move16(); Qx = s_min( Qx, Qx_vec[i] ); /* Restore the sign destroyed by abs operations. */ if ( L_xor( vectIn, *peak_gain ) < 0 ) /* Check the sign bits (MSB). */ { x[i] = negate( x[i] ); + move16(); } } FOR( i = 0; i < 4; i++ ) @@ -1077,6 +1092,7 @@ static void quant_peaks_fx( IF( NE_16( Qx_vec[i], Qx ) ) { x[i] = shr( x[i], sub( Qx_vec[i], Qx ) ); /* Qx */ + move16(); } } absPeakGain = L_abs( peak_gain[0] ); @@ -1132,25 +1148,31 @@ static void quant_peaks_fx( IF( cb_class == 0 ) { *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0 ); + move16(); push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } ELSE IF( EQ_16( cb_class, 1 ) ) { indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0 ); + move16(); *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); + move16(); push_indice_fx( hBstr, IND_HVQ_PEAKS, 0, 1 ); } ELSE IF( EQ_16( cb_class, 2 ) ) { indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1 ); + move16(); *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); + move16(); push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } ELSE { *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1 ); + move16(); push_indice_fx( hBstr, IND_HVQ_PEAKS, 1, 1 ); } @@ -1239,7 +1261,7 @@ static Word16 sparse_code_pos_fx( FOR( i = 0; i < HVQ_CP_MAP_IDX_LEN; i++ ) { result[bits++] = shr( s_and( idx, mask ), sub( HVQ_CP_MAP_IDX_LEN - 1, i ) ); - mask >>= 1; + mask = shr( mask, 1 ); } } } @@ -1409,6 +1431,7 @@ static Word16 hvq_code_pos_fx( FOR( i = 1; i < num_peaks; i++ ) { delta[i] = sub( sub( peak_idx[i], peak_idx[i - 1] ), HVQ_CP_HUFF_OFFSET ); + move16(); if ( LT_16( delta_max, delta[i] ) ) { delta_max = delta[i]; diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index f0c37afe5b6220786030c58cb28ef4b486006411..c91f34e96c680ae91e98b812a76ea1a192ff8898 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -90,11 +90,14 @@ Word16 pit_encode_fx( /* o : Fractional pitc if ( EQ_16( L_subfr, 2 * L_SUBFR ) ) { L_sufr_sft = 7; + move16(); } /*----------------------------------------------------------------* * convert pitch values to 16kHz domain *----------------------------------------------------------------*/ + test(); + test(); IF( EQ_16( L_frame, L_FRAME ) || ( tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0 ) ) { Copy( pitch, T_op, 2 ); @@ -183,7 +186,8 @@ Word16 pit_encode_fx( /* o : Fractional pitc move16(); IF( NE_16( coder_type, AUDIO ) ) { - nBits = pitch_bits[shr( i_subfr, L_sufr_sft )]; + nBits = pitch_bits[i_subfr >> L_sufr_sft]; + move16(); } IF( EQ_16( coder_type, AUDIO ) ) { @@ -196,7 +200,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc move16(); test(); test(); - if ( EQ_16( L_subfr, L_frame / 2 ) && i_subfr != 0 && EQ_16( L_frame, L_FRAME ) ) + if ( EQ_16( L_subfr, shr( L_frame, 1 ) ) && i_subfr != 0 && EQ_16( L_frame, L_FRAME ) ) { pit_flag = L_SUBFR; move16(); @@ -225,7 +229,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - + move16(); pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( coder_type, VOICED ) ) @@ -249,7 +253,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc } /* search and encode the closed loop pitch period */ - test(); + test(); IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 5 ) ) { @@ -336,10 +340,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc IF( *limit_flag == 0 ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR ); + move16(); } } ELSE IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) @@ -347,15 +353,18 @@ Word16 pit_encode_fx( /* o : Fractional pitc IF( *limit_flag == 0 ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR ); + move16(); } } ELSE IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); + move16(); } pit_Q_enc_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -366,10 +375,12 @@ Word16 pit_encode_fx( /* o : Fractional pitc IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR ); + move16(); } - ELSE IF( nBits == 10 ) + ELSE IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + move16(); } pit16k_Q_enc_fx( hBstr, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -410,6 +421,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { @@ -432,6 +444,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE { @@ -458,6 +471,7 @@ Word16 pit_encode_fx( /* o : Fractional pitc /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } pit_Q_enc_fx( hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -505,11 +519,14 @@ Word16 pit_encode_ivas_fx( /* o : Fractional if ( EQ_16( L_subfr, 2 * L_SUBFR ) ) { L_sufr_sft = 7; + move16(); } /*----------------------------------------------------------------* * convert pitch values to 16kHz domain *----------------------------------------------------------------*/ + test(); + test(); IF( EQ_16( L_frame, L_FRAME ) || ( tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0 ) ) { Copy( pitch, T_op, 2 ); @@ -598,7 +615,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional move16(); IF( NE_16( coder_type, AUDIO ) ) { - nBits = pitch_bits[shr( i_subfr, L_sufr_sft )]; + nBits = pitch_bits[i_subfr >> L_sufr_sft]; } IF( EQ_16( coder_type, AUDIO ) ) { @@ -640,7 +657,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - + move16(); pit_Q_enc_ivas_fx( hBstr, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( coder_type, VOICED ) ) @@ -665,7 +682,6 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ test(); - test(); IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 5 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR ); @@ -716,6 +732,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional { /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); IF( EQ_16( delta, 8 ) ) { *T0_frac = 0; @@ -762,10 +779,12 @@ Word16 pit_encode_ivas_fx( /* o : Fractional IF( *limit_flag == 0 ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR ); + move16(); } } ELSE IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) @@ -773,10 +792,12 @@ Word16 pit_encode_ivas_fx( /* o : Fractional IF( *limit_flag == 0 ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR ); + move16(); } } ELSE IF( EQ_16( nBits, 10 ) ) @@ -792,10 +813,12 @@ Word16 pit_encode_ivas_fx( /* o : Fractional IF( EQ_16( nBits, 9 ) || EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR ); + move16(); } - ELSE IF( nBits == 10 ) + ELSE IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + move16(); } pit16k_Q_enc_ivas_fx( hBstr, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -836,6 +859,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { @@ -858,6 +882,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } ELSE { @@ -884,6 +909,7 @@ Word16 pit_encode_ivas_fx( /* o : Fractional /* search and encode the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } pit_Q_enc_ivas_fx( hBstr, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -1105,6 +1131,7 @@ Word16 delta_pit_enc_fx( /* o : pitch index ) { Word16 pitch_index = 0; + move16(); IF( fr_steps == 0 ) { @@ -1385,8 +1412,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag t_min = sub( t0_min, L_INTERPOL1 ); t_max = add( t0_max, L_INTERPOL1 ); corr = &corr_v[-t_min]; - move16(); - move16(); /* corr[t_min..t_max] */ + /* corr[t_min..t_max] */ norm_corr_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); @@ -1399,9 +1425,9 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag t0 = t0_min; move16(); - FOR( i = add( t0_min, 1 ); i <= t0_max; i++ ) + FOR( i = t0_min + 1; i <= t0_max; i++ ) { - if ( corr[i] >= max_val ) + if ( GE_16( corr[i], max_val ) ) { t0 = i; move16(); @@ -1416,7 +1442,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag IF( ( i_subfr == 0 ) && ( GE_16( t0, t0_fr2 ) ) ) { i = shl( shr( t0, 1 ), 1 ); /* 2 samples resolution */ - if ( GT_16( add( i, 2 ), PIT_MAX ) ) + IF( GT_16( add( i, 2 ), PIT_MAX ) ) { i = sub( i, 2 ); } @@ -1477,7 +1503,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag { t0 = sub( t0, 1 ); cor_max = Interpol_4( &corr[t0], fraction ); - FOR( i = add( fraction, step ); i <= 3; i = (Word16) ( i + step ) ) + FOR( i = fraction + step; i <= 3; i = ( i + step ) ) { temp = Interpol_4( &corr[t0], i ); IF( GT_16( temp, cor_max ) ) @@ -1490,7 +1516,7 @@ Word16 pitch_fr4_fx( /* o : chosen integer pitch lag } } - FOR( i = 0; i <= 3; i = (Word16) ( i + step ) ) + FOR( i = 0; i <= 3; i = ( i + step ) ) { temp = Interpol_4( &corr[t1], i ); IF( GT_16( temp, cor_max ) ) @@ -1649,6 +1675,7 @@ void norm_corr_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif k = negate( t_min ); @@ -1733,7 +1760,7 @@ void norm_corr_fx( IF( NE_16( t, t_max ) ) { k--; - FOR( i = (Word16) ( L_subfr - 1 ); i > 0; i-- ) + FOR( i = ( L_subfr - 1 ); i > 0; i-- ) { /* saturation can occur in add() */ /*excf[i] = add(mult(exc[k], h[i]), excf[i - 1]); move16(); */ @@ -1742,6 +1769,7 @@ void norm_corr_fx( #else excf[i] = round_fx( L_mac( L_mult( excf[i - 1], 32767 ), exc[k], h[i] ) ); #endif + move16(); } excf[0] = mult_r( exc[k], h[0] ); move16(); @@ -2202,7 +2230,7 @@ void Mode2_pit_encode_fx( { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16( pit_min, PIT_MIN_16k ) ) + IF( EQ_16( pit_min, PIT_MIN_16k ) ) { pit_res_max2 = shr( pit_res_max, 1 ); } @@ -2231,7 +2259,7 @@ void Mode2_pit_encode_fx( ELSE IF( coder_type == 4 ) /* 9/6/9/6 (AMRWB) */ { Word16 pit_res_max2 = pit_res_max; - if ( EQ_16( pit_min, PIT_MIN_16k ) ) + IF( EQ_16( pit_min, PIT_MIN_16k ) ) { pit_res_max2 = shr( pit_res_max, 1 ); } @@ -2246,6 +2274,7 @@ void Mode2_pit_encode_fx( } *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, pit_flag, pit_min, pit_fr2, pit_fr1, L_SUBFR ); + move16(); IF( pit_flag == 0 ) /* if 1st/3rd/5th subframe */ { Mode2_abs_pit_enc_fx( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); @@ -2267,6 +2296,7 @@ void Mode2_pit_encode_fx( } *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + move16(); IF( i_subfr == 0 ) { @@ -2289,6 +2319,7 @@ void Mode2_pit_encode_fx( } *T0 = E_GAIN_closed_loop_search_fx( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr( pit_res_max, 1 ), T0_frac, T0_res, pit_res_max, i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + move16(); IF( i_subfr == 0 ) { @@ -2349,6 +2380,7 @@ static void limit_T0_voiced2( if ( LT_16( temp1, t ) ) { temp1 = t; + move16(); } temp2 = mult( temp1, inv_T0_res[res2] ); @@ -2395,16 +2427,19 @@ static void limit_T0_voiced2( move16(); *T0_max_frac = sub( temp1, i_mult2( temp2, res ) ); + move16(); IF( GT_16( *T0_max, pit_max ) ) { *T0_max = pit_max; *T0_max_frac = sub( res, 1 ); + move16(); + move16(); temp1 = add( sub( i_mult2( *T0_max, res ), 64 ), res ); temp2 = mult( temp1, inv_T0_res[res2] ); - if ( EQ_16( res, 6 ) ) + IF( EQ_16( res, 6 ) ) { temp2 = shr( temp2, 1 ); } @@ -2440,14 +2475,17 @@ void Mode2_abs_pit_enc_fx( IF( LT_16( T0, pit_fr2 ) ) { **pt_indice = add( i_mult2( T0, pit_res_max ), sub( T0_frac, i_mult2( pit_min, pit_res_max ) ) ); + move16(); } ELSE IF( LT_16( T0, pit_fr1 ) ) { **pt_indice = add( sub( add( i_mult2( T0, pit_res_max_half ), T0_frac ), i_mult2( pit_fr2, pit_res_max_half ) ), i_mult2( sub( pit_fr2, pit_min ), pit_res_max ) ); + move16(); } ELSE { **pt_indice = add( add( sub( T0, pit_fr1 ), i_mult2( sub( pit_fr2, pit_min ), pit_res_max ) ), i_mult2( sub( pit_fr1, pit_fr2 ), pit_res_max_half ) ); + move16(); } ( *pt_indice )++; diff --git a/lib_enc/pitch_ol2.c b/lib_enc/pitch_ol2.c index f3087f1b9b7e22a33581767e85befddb09fc0cb8..05b32c716f172c695f7bc36fc4297784f39c48f3 100644 --- a/lib_enc/pitch_ol2.c +++ b/lib_enc/pitch_ol2.c @@ -66,17 +66,18 @@ void StableHighPitchDetect_ivas_fx( Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ + const Word16 voicing[], /* i : OL pitch gains Q15 */ + const Word16 wsp[], /* i : weighted speech Qx */ const Word16 localVAD, /* i : local VAD flag */ Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ - Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ + Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy Q7*/ Word16 *predecision_flag, /* i/o: predecision flag */ - Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ - Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency */ + Word32 *diff_sm, /* i/o: smoothed pitch frequency difference Q7*/ + Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency Q7*/ Word16 Q_new, - Word16 EspecdB[] ) + Word16 EspecdB[] /*Q8*/ +) { Word16 i, pitch_freq_point; Word16 T, Tp, pit_min; @@ -92,16 +93,16 @@ void StableHighPitchDetect_ivas_fx( #endif /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ - L_tmp = L_mult( voicing[0], 10923 ); - L_tmp = L_mac( L_tmp, voicing[1], 10923 ); - L_tmp = L_mac( L_tmp, voicing[2], 10923 ); + L_tmp = L_mult( voicing[0], 10923 /*1/3 in Q15*/ ); + L_tmp = L_mac( L_tmp, voicing[1], 10923 /*1/3 in Q15*/ ); + L_tmp = L_mac( L_tmp, voicing[2], 10923 /*1/3 in Q15*/ ); #ifdef BASOP_NOGLOB voicing_m = round_fx_sat( L_tmp ); #else voicing_m = round_fx( L_tmp ); #endif /**voicing_sm = 0.75f*(*voicing_sm) + 0.25f*voicing;*/ - *voicing_sm = round_fx( L_mac( L_mult( *voicing_sm, 24576 ), voicing_m, 8192 ) ); + *voicing_sm = round_fx( L_mac( L_mult( *voicing_sm, 24576 /*0.75f Q15*/ ), voicing_m, 8192 /*0.25f Q15*/ ) ); move16(); /* pitch_freq_point = (short)(L_FFT/(mult_fact*T_op[1])+0.5f);*/ @@ -131,10 +132,10 @@ void StableHighPitchDetect_ivas_fx( L_tmp = Mult_32_16( sum_energy, tmp1 ); sum_energy = L_shl( L_tmp, sub( exp, 14 ) ); /**diff_sm = 0.2f * diff + 0.8f * *diff_sm;*/ - *diff_sm = L_add( Mult_32_16( diff, 6554 ), Mult_32_16( *diff_sm, 26214 ) ); + *diff_sm = L_add( Mult_32_16( diff, 6554 /*.2f Q15*/ ), Mult_32_16( *diff_sm, 26214 /*.8f Q15*/ ) ); move32(); /**energy_sm = 0.2f * sum_energy + 0.8f * *energy_sm;*/ - *energy_sm = L_add( Mult_32_16( sum_energy, 6554 ), Mult_32_16( *energy_sm, 26214 ) ); + *energy_sm = L_add( Mult_32_16( sum_energy, 6554 /*.2f Q15*/ ), Mult_32_16( *energy_sm, 26214 /*.8f Q15*/ ) ); move32(); /*diff /= sum_energy;*/ @@ -187,14 +188,14 @@ void StableHighPitchDetect_ivas_fx( } test(); test(); - IF( LT_32( *diff_sm, -1280 ) && LT_32( *energy_sm, 4928 ) && LT_16( diff16, -26214 ) ) + IF( LT_32( *diff_sm, -1280 /*-10.0f Q7*/ ) && LT_32( *energy_sm, 4928 /*38.5f Q7*/ ) && LT_16( diff16, -26214 /*-.8f Q15*/ ) ) { *predecision_flag = 1; move16(); } test(); test(); - if ( GT_32( *diff_sm, 1280 ) && GT_32( *energy_sm, 10624 ) && GT_16( diff16, 16384 ) ) + if ( GT_32( *diff_sm, 1280 /*10.0f Q7*/ ) && GT_32( *energy_sm, 10624 /*83.0f Q7*/ ) && GT_16( diff16, 16384 /*.5 Q15*/ ) ) { *predecision_flag = 0; move16(); @@ -222,13 +223,13 @@ void StableHighPitchDetect_ivas_fx( *LF_EnergyRatio_sm = round_fx( L_tmp ); move16(); test(); - if ( GT_16( *LF_EnergyRatio_sm, 4480 ) || GT_16( ratio, 6400 ) ) + if ( GT_16( *LF_EnergyRatio_sm, 4480 /*35.0f Q7*/ ) || GT_16( ratio, 6400 /*50.0f Q7*/ ) ) { *predecision_flag = 1; move16(); } - if ( LT_16( *LF_EnergyRatio_sm, 2048 ) ) + if ( LT_16( *LF_EnergyRatio_sm, 2048 /*16.0f Q7*/ ) ) { *predecision_flag = 0; move16(); @@ -275,7 +276,7 @@ void StableHighPitchDetect_ivas_fx( cor_max16 = round_fx( L_shl( cor_max, exp ) ); /*Q15*/ #endif /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ - *voicing0_sm = round_fx( L_mac( L_mult( 24576, *voicing0_sm ), 8192, cor_max16 ) ); + *voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) ); move16(); /* final short pitch detection */ @@ -285,7 +286,7 @@ void StableHighPitchDetect_ivas_fx( *flag_spitch = 0; move16(); IF( ( EQ_16( localVAD, 1 ) ) && ( EQ_16( *predecision_flag, 1 ) ) && - ( GT_16( *voicing0_sm, 21299 ) ) && ( GT_16( *voicing0_sm, mult_r( *voicing_sm, 22938 ) ) ) ) + ( GT_16( *voicing0_sm, 21299 /*.65f in Q15*/ ) ) && ( GT_16( *voicing0_sm, mult_r( *voicing_sm, 22938 /*.7f in Q15*/ ) ) ) ) { *flag_spitch = 1; move16(); diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index bd66fda139e28f53c4564560776f148ba8d5e4d2..83ea36b176275ced8b30b9596aac27069f09f4e7 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -51,6 +51,7 @@ void pitch_ol2_fx( Word16 pit_max; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* initialization */ @@ -87,6 +88,7 @@ void pitch_ol2_fx( t0 = L_shl( *pt_cor_32++, exp3 ); *pt_cor_fx++ = round_fx( t0 ); #endif + move16(); } pt_cor_fx = cor_fx + L_INTERPOL1; @@ -94,7 +96,7 @@ void pitch_ol2_fx( move16(); t1s = t0_min; move16(); - FOR( t = add( t0_min, 1 ); t <= t0_max; t++ ) + FOR( t = t0_min + 1; t <= t0_max; t++ ) { if ( GT_16( *pt_cor_fx, cor_max_fx ) ) { @@ -123,8 +125,7 @@ void pitch_ol2_fx( { t0s = sub( t0s, 1 ); cor_max_fx = Interpol_4( &pt_cor_fx[t0s], fraction ); - move16(); - FOR( i = add( fraction, step ); i <= 3; i += step ) + FOR( i = fraction + step; i <= 3; i += step ) { temp_fx = Interpol_4( &pt_cor_fx[t0s], i ); if ( GT_16( temp_fx, cor_max_fx ) ) @@ -145,7 +146,6 @@ void pitch_ol2_fx( FOR( i = 0; i <= 3; i += step ) /* Process positive fractions */ { temp_fx = Interpol_4( &pt_cor_fx[t1s], i ); - move16(); IF( GT_16( temp_fx, cor_max_fx ) ) { @@ -218,6 +218,7 @@ void pitch_ol2_fx( #else /* BASOP_NOGLOB */ *voicing_fr_fx = round_fx( L_shl( R1, exp_R0 ) ); /*Q15*/ #endif /* BASOP_NOGLOB */ + move16(); } ELSE { @@ -258,22 +259,24 @@ void StableHighPitchDetect_fx( Word16 Top; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ - L_tmp = L_mult( voicing[0], 10923 ); - L_tmp = L_mac( L_tmp, voicing[1], 10923 ); - L_tmp = L_mac( L_tmp, voicing[2], 10923 ); + L_tmp = L_mult( voicing[0], 10923 /*1/3 in Q15*/ ); + L_tmp = L_mac( L_tmp, voicing[1], 10923 /*1/3 in Q15*/ ); + L_tmp = L_mac( L_tmp, voicing[2], 10923 /*1/3 in Q15*/ ); #ifdef BASOP_NOGLOB voicing_m = round_fx_sat( L_tmp ); #else voicing_m = round_fx( L_tmp ); #endif /**voicing_sm = 0.75f*(*voicing_sm) + 0.25f*voicing;*/ - *voicing_sm = round_fx( L_mac( L_mult( *voicing_sm, 24576 ), voicing_m, 8192 ) ); - + *voicing_sm = round_fx( L_mac( L_mult( *voicing_sm, 24576 /*0.75f Q15*/ ), voicing_m, 8192 /*0.25f Q15*/ ) ); + move16(); /* pitch_freq_point = (short)(L_FFT/(mult_fact*T_op[1])+0.5f);*/ Top = pitch[1]; + move16(); exp = norm_s( Top ); tmp = div_s( shl( 1, sub( 14, exp ) ), Top ); /*Q(29 - exp)*/ L_tmp = L_mult0( tmp, L_FFT ); /*Q(29 - exp)*/ @@ -348,14 +351,14 @@ void StableHighPitchDetect_fx( } test(); test(); - IF( LT_32( *diff_sm, -1280 ) && LT_32( *energy_sm, 4928 ) && LT_16( diff16, -26214 ) ) + if ( LT_32( *diff_sm, -1280 /*-10.0f Q7*/ ) && LT_32( *energy_sm, 4928 /*38.5f Q7*/ ) && LT_16( diff16, -26214 /*-.8f Q15*/ ) ) { *predecision_flag = 1; move16(); } test(); test(); - if ( GT_32( *diff_sm, 1280 ) && GT_32( *energy_sm, 10624 ) && GT_16( diff16, 16384 ) ) + if ( GT_32( *diff_sm, 1280 /*10.0f Q7*/ ) && GT_32( *energy_sm, 10624 /*83.0f Q7*/ ) && GT_16( diff16, 16384 /*.5 Q15*/ ) ) { *predecision_flag = 0; move16(); @@ -372,14 +375,15 @@ void StableHighPitchDetect_fx( L_tmp = L_mult( ratio, 2048 ); L_tmp = L_mac( L_tmp, *LF_EnergyRatio_sm, 30720 ); *LF_EnergyRatio_sm = round_fx( L_tmp ); + move16(); test(); - if ( GT_16( *LF_EnergyRatio_sm, 4480 ) || GT_16( ratio, 6400 ) ) + if ( GT_16( *LF_EnergyRatio_sm, 4480 /*35.0f Q7*/ ) || GT_16( ratio, 6400 /*50.0f Q7*/ ) ) { *predecision_flag = 1; move16(); } - if ( LT_16( *LF_EnergyRatio_sm, 2048 ) ) + if ( LT_16( *LF_EnergyRatio_sm, 2048 /*16.0f Q7*/ ) ) { *predecision_flag = 0; move16(); @@ -426,7 +430,8 @@ void StableHighPitchDetect_fx( cor_max16 = round_fx( L_shl( cor_max, exp ) ); /*Q15*/ #endif /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ - *voicing0_sm = round_fx( L_mac( L_mult( 24576, *voicing0_sm ), 8192, cor_max16 ) ); + *voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) ); + move16(); /* final short pitch detection */ test(); diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 65c28d26019e28e7d8c847c865226e71afeb4038..52cd3ad5d93007dc1ff0cca8a09a261bace769fc 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -262,9 +262,9 @@ void pitch_ol_fx( tmp_mem[2] = mem_decim2[2]; move16(); - LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[shr( L_FRAME, 1 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ + LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[( L_FRAME / 2 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ - Copy( &old_wsp2[shr( L_FRAME, 1 )], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + Copy( &old_wsp2[L_FRAME / 2], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); /*-----------------------------------------------------------------* * Attenuate the correlation correction factor due to noise. @@ -1208,9 +1208,9 @@ void pitch_ol_ivas_fx( tmp_mem[2] = mem_decim2[2]; move16(); - LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[shr( L_FRAME, 1 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ + LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[L_FRAME / 2], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ - Copy( &old_wsp2[shr( L_FRAME, 1 )], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + Copy( &old_wsp2[L_FRAME / 2], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); /*-----------------------------------------------------------------* * Attenuate the correlation correction factor due to noise. @@ -1321,7 +1321,7 @@ void pitch_ol_ivas_fx( temp1 = temp; move64(); - FOR( k = add( k, len1[j] ); k > 0; k-- ) + FOR( k = ( k + len1[j] ); k > 0; k-- ) { temp1 = W_mac0_16_16( temp1, *pt5, *pt5 ); // 2*qwsp pt5++; @@ -1934,8 +1934,8 @@ void pitch_ol_ivas_fx( /* all Q15 here */ /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult( voicing[0], 16384 ); - Ltmp = L_mac( Ltmp, voicing[1], 16384 ); + Ltmp = L_mult( voicing[0], 16384 /*.5 Q15*/ ); + Ltmp = L_mac( Ltmp, voicing[1], 16384 /*.5 Q15*/ ); cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); /* pitch unstable in present frame or from previous frame or normalized correlation too low */ @@ -2020,13 +2020,13 @@ void pitch_ol_ivas_fx( /* *delta_pit /= 3; */ if ( k < 0 ) { - *delta_pit = mult( *delta_pit, -32768 ); + *delta_pit = mult( *delta_pit, -32768 /*-1 Q15*/ ); move16(); } - tmp16 = mult( *delta_pit, 10923 ); + tmp16 = mult( *delta_pit, 10923 /*1/3 Q15*/ ); if ( k < 0 ) { - tmp16 = mult( tmp16, -32768 ); + tmp16 = mult( tmp16, -32768 /*-1 Q15*/ ); } *delta_pit = tmp16; move16(); @@ -2080,7 +2080,7 @@ static void find_mult_fx( L_tmp = L_shl( L_mult( *corr, *fac ), 3 ); /* if ( *old_corr < 0.6f || (float)pitch0 > (float)*old_pitch * 0.4f ) */ - IF( s_max( sub( 19660, *old_corr ), sub( pitch0, mult( *old_pitch, 13107 ) ) ) > 0 ) + IF( s_max( sub( 19660 /*.6 Q15*/, *old_corr ), sub( pitch0, mult( *old_pitch, 13107 /*.4 Q15*/ ) ) ) > 0 ) { /* reinforce the normalized correlation */ /* operands are Q12, result is Q12 */ @@ -2151,7 +2151,7 @@ static void pitch_neighbour_fx( { /* corr[i][k] *= ( -thres1[j]/DELTA1 * 0.625f * delta + 0.625f * thres1[j] +1.0f ); */ fac = mult( negate( thres1[j] ), 20479 / DELTA_COH ); - fac = add( i_mult2( fac, delta ), mult( 20479, thres1[j] ) ); + fac = add( i_mult2( fac, delta ), mult( 20479 /*.625 Q15*/, thres1[j] ) ); } corr[i][k] = add_sat( corr[i][k], mult( fac, corr[i][k] ) ); move16(); @@ -2274,7 +2274,7 @@ static void LP_Decim2_Copy( *p_x++ = x[i]; move16(); } - if ( l & 1 ) /* Fix for valgrind error in case l is odd. Anyway this function will be removed. */ + if ( s_and( l, 1 ) ) /* Fix for valgrind error in case l is odd. Anyway this function will be removed. */ { *p_x = *( p_x - 1 ); move16(); @@ -2298,6 +2298,7 @@ static void LP_Decim2_Copy( p_x += 2; y[j++] = round_fx( L_tmp ); + move16(); } } /*---------------------------------------------------------------------* @@ -2360,7 +2361,7 @@ static Word32 Dot_product12_OL( /* o : Q31: normalized result move16(); /* exponent = 0..30 */ *sum1 = extract_h( L_shr( L_sum2, 1 ) ); - + move16(); return L_sum; } @@ -2424,7 +2425,7 @@ static Word32 Dot_product12_OL_back( /* o : Q31: normalized r move16(); /* exponent = 0..30 */ *sum1 = extract_h( L_shr( L_sum2, 1 ) ); - + move16(); return L_sum; } diff --git a/lib_enc/plc_enc_ext_fx.c b/lib_enc/plc_enc_ext_fx.c index 56598be2f5ab0342173145bfc314929340d29f4e..97e3fd4bc44ca91ab63acb69b5f914d01f747e93 100644 --- a/lib_enc/plc_enc_ext_fx.c +++ b/lib_enc/plc_enc_ext_fx.c @@ -82,6 +82,9 @@ void init_PLC_enc_fx( hPlcExt->lsf_con[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); hPlcExt->last_lsf_ref[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); hPlcExt->last_lsf_con[itr] = add( lsf_init_fx[itr], shr( lsf_init_fx[itr], 2 ) ); + move16(); + move16(); + move16(); } } diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 8884f2624ff983c9d16cdf73df57b9fba1760658..b088e6efd0570dff4fca9ad48b2d51c7d9592d9a 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2380,10 +2380,7 @@ Word16 ivas_smc_gmm_fx( dec = (Word16) GT_32( dlp_fx, 0 ); /* calculate weight based on relE (higher relE -> lower weight, lower relE -> higher weight) */ - Word16 Qio = Q24; - move16(); - wrelE_fx = lin_interp32_fx( L_deposit_h( relE_fx ), 15 << 24, 15099494 /*0.9 q24*/, -( 15 << 24 ), 16609443 /*0.99 q24*/, 1, &Qio ); // Q25 - wrelE_fx = L_shr( wrelE_fx, sub( Qio, 25 ) ); + wrelE_fx = lin_interp32_fx( L_deposit_h( relE_fx ), 15 << 24, 1932735283 /*0.9 in Q31*/, -( 15 << 24 ), 2126008812 /*0.99 in Q31*/, 1 ); // Q31 /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ // hSpMusClas->dlp_mean_ST = 0.8f * hSpMusClas->dlp_mean_ST + 0.2f * dlp; hSpMusClas->dlp_mean_ST_fx = L_add( Mpy_32_32( 1717986918, hSpMusClas->dlp_mean_ST_fx ), Mpy_32_32( 429496729, dlp_fx ) ); @@ -2405,10 +2402,7 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->wdrop_fx = 0; move16(); } - Qio = Q25; - move16(); - wdrop_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wdrop_fx ), 503316480, 23488102, 0, ONE_IN_Q25, 1, &Qio ); - wdrop_fx = L_shr( wdrop_fx, sub( Qio, 25 ) ); + wdrop_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wdrop_fx ), 503316480, 1503238554 /* 0.7 in Q31 */, 0, ONE_IN_Q31 /* 1.0f in Q31 */, 1 ); /* Q31 */ test(); test(); /* calculate weight based on rises of dlp (close to 1 during sudden rise of dlp, close to 0 otherwise) */ @@ -2430,13 +2424,10 @@ Word16 ivas_smc_gmm_fx( } - Qio = Q25; - move16(); - wrise_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wrise_fx ), 167772160, 31876710, 0, ONE_IN_Q25, 1, &Qio ); - wrise_fx = L_shr( wrise_fx, sub( Qio, 25 ) ); + wrise_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wrise_fx ), 167772160, 2040109466 /* 0.95 in Q31 */, 0, ONE_IN_Q31 /* 1.0f in Q31 */, 1 ); /* Q31 */ /* combine weights into one */ // wght = wrelE * wdrop * wrise; - wght_fx = Mpy_32_32( Mpy_32_32( wrelE_fx, wdrop_fx ), wrise_fx ); // Q13 + wght_fx = Mpy_32_32( Mpy_32_32( wrelE_fx, wdrop_fx ), wrise_fx ); /* Q31 */ test(); /* ratio of delta means vs. delta variances */ IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) @@ -2490,29 +2481,28 @@ Word16 ivas_smc_gmm_fx( IF( GT_32( L_deposit_l( dlp_mean2var_fx ), L_shl( 15, dlp_mean2var_q ) ) ) { /* decrease the weight little bit when the classifier indicates "strong speech" or "strong music" */ - // wght *= 0.9f; - wght_fx = Mpy_32_32( wght_fx, 1932735283 ); // Q13 + wght_fx = Mpy_32_32( wght_fx, 1932735283 /* 0.9f in Q31 */ ); /* Q31 */ } - IF( GT_32( wght_fx, ONE_IN_Q13 ) ) + IF( GT_32( wght_fx, ONE_IN_Q31 ) ) { - wght_fx = ONE_IN_Q13; + wght_fx = ONE_IN_Q31; /* 1.0f in Q31 */ } - ELSE IF( LT_32( wght_fx, 82 ) ) + ELSE IF( LT_32( wght_fx, 21474836 /* 0.01f in Q31 */ ) ) { - wght_fx = 82; + wght_fx = 21474836; /* 0.01f in Q31 */ } move32(); - if ( LT_16( Etot_fx, 2560 ) ) + if ( LT_16( Etot_fx, 2560 /* 10f in Q8 */ ) ) { /* silence */ - wght_fx = 7537; + wght_fx = 1975684956; /* 0.92f in Q31 */ move32(); } /* calculate weighted decision */ // hSpMusClas->wdlp_0_95_sp = wght * hSpMusClas->wdlp_0_95_sp + ( 1 - wght ) * dlp; - hSpMusClas->wdlp_0_95_sp_32fx = L_add( Mpy_32_32( L_shl( wght_fx /*q13*/, 18 ), hSpMusClas->wdlp_0_95_sp_32fx /*q24*/ ), Mpy_32_32( L_shl( L_sub( ONE_IN_Q13, wght_fx /*q13*/ ), Q18 ), L_shl( dlp_fx /*q19*/, 5 ) ) ); // Q24 + hSpMusClas->wdlp_0_95_sp_32fx = L_add( Mpy_32_32( wght_fx, hSpMusClas->wdlp_0_95_sp_32fx /*q24*/ ), Mpy_32_32( L_sub( ONE_IN_Q31, wght_fx ), L_shl( dlp_fx /*q19*/, 5 ) ) ); // Q24 move32(); /* xtalk classifier: apply long hysteresis to prevent LRTD on music */