From a40470201a978eb8397f16c103276b9f1cbc25f7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 11:36:50 +0530 Subject: [PATCH] Encoder LTV crash fix, MSAN/ASAN error fix and Q-info updates --- lib_com/ivas_mdct_imdct_fx.c | 162 +++++----- lib_com/ivas_prot.h | 7 + lib_com/ivas_prot_fx.h | 8 + lib_com/ivas_qmetadata_com.c | 15 +- lib_com/ivas_qspherical_com.c | 78 +++++ lib_com/ivas_rom_com_fx.c | 106 +++---- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_spar_com.c | 19 +- lib_com/ivas_stat_com.h | 14 +- lib_com/modif_fs_fx.c | 6 +- lib_com/prot_fx.h | 86 +++--- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/hq_lr_dec_fx.c | 357 +++++++++++----------- lib_dec/lsf_dec_fx.c | 270 ++++++++--------- lib_dec/lsf_msvq_ma_dec_fx.c | 100 ++++--- lib_dec/nelp_dec_fx.c | 48 +-- lib_enc/init_enc.c | 4 + lib_enc/ivas_core_enc.c | 4 +- lib_enc/ivas_core_pre_proc.c | 4 +- lib_enc/ivas_dirac_enc.c | 118 ++++---- lib_enc/ivas_enc.c | 88 +++--- lib_enc/ivas_init_enc.c | 26 -- lib_enc/ivas_masa_enc.c | 175 ++++++++--- lib_enc/ivas_mc_param_enc.c | 4 + lib_enc/ivas_mcmasa_enc.c | 28 +- lib_enc/ivas_mct_enc.c | 26 -- lib_enc/ivas_qmetadata_enc.c | 12 +- lib_enc/ivas_qspherical_enc.c | 8 +- lib_enc/ivas_spar_encoder.c | 9 +- lib_enc/ivas_stat_enc.h | 13 +- lib_enc/ivas_stereo_cng_enc.c | 33 +- lib_rend/ivas_efap.c | 514 +++++++++++++++++--------------- 32 files changed, 1254 insertions(+), 1094 deletions(-) diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index c25f4fab4..37c525109 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -63,9 +63,9 @@ *-----------------------------------------------------------------------------------------*/ void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ) { Word16 i; @@ -74,9 +74,9 @@ void ivas_tda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); /* Q10*/ move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( i_mult( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); /* Q10*/ move32(); } @@ -91,32 +91,32 @@ void ivas_tda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, - Word32 *pTemp_lfe ) + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 + Word32 *pTemp_lfe ) // Q10 { Word16 i; Word16 rem_len; rem_len = 0; move16(); - Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); + Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); // Q10 - Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); + Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); // Q10 set32_fx( pOut_buf, 0, zero_pad_len ); - Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); + Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); // Q10 FOR( i = 0; i < fade_len; i++ ) { - pOut_buf[add( zero_pad_len, i )] = Mult_32_32( pOut_buf[add( zero_pad_len, i )], pWindow_coeffs[i] ); + pOut_buf[zero_pad_len + i] = Mult_32_32( pOut_buf[zero_pad_len + i], pWindow_coeffs[i] ); // Q10 move32(); } @@ -124,7 +124,7 @@ void ivas_dct_windowing_fx( FOR( i = 0; i < rem_len; i++ ) { - pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )] = Mult_32_32( pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )], pWindow_coeffs[sub( sub( fade_len, i ), 1 )] ); + pOut_buf[zero_pad_len * 3 + fade_len + i] = Mult_32_32( pOut_buf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q10 move32(); } @@ -141,9 +141,9 @@ void ivas_dct_windowing_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -152,23 +152,23 @@ void ivas_mdct_fx( Word32 ivas_mdct_scaling_gain; len_by_2 = shr( length, 1 ); - ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); + ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); // Q46 ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); // q_out move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( imult1616( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_im[i] ) ) ); + re[i] = L_negate( L_add( Mpy_32_16_1( pOut[2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_im[i] ) ) ); // q_out move32(); - im[i] = L_sub( Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); + im[i] = L_sub( Mpy_32_16_1( pOut[length - 1 - 2 * i], pTwid_re[i] ), Mpy_32_16_1( pOut[2 * i], pTwid_im[i] ) ); // q_out move32(); } @@ -176,9 +176,9 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); + re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); // q_out+15 move32(); - im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); + im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); // q_out +15 move32(); } *q_out = add( *q_out, Q15 ); @@ -186,18 +186,18 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_sub( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // q_out + im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // q_out move32(); - re[i] = tmp; + re[i] = tmp; // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[sub( sub( length, imult1616( 2, i ) ), 1 )] = re[i]; + pOut[length - 2 * i - 1] = re[i]; // q_out move32(); - pOut[2 * i] = im[i]; + pOut[2 * i] = im[i]; // q_out move32(); } @@ -212,33 +212,33 @@ void ivas_mdct_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx( - Word32 *re, - Word32 *im, - const Word16 length ) + Word32 *re, /*Q24*/ + Word32 *im, /*Q24*/ + const Word16 length /*Q0*/ ) { Word16 i; Word32 ivas_imdct_one_by_powergain; - ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; + ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; // Q16 move32(); /*re-arrange inputs to use fft as ifft */ - re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); + re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); + im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - FOR( i = 1; i <= shr( length, 1 ); i++ ) + FOR( i = 1; i <= ( length / 2 ); i++ ) { Word32 tmp; - tmp = Mult_32_32( re[sub( length, i )], ivas_imdct_one_by_powergain ); - re[sub( length, i )] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( re[length - i], ivas_imdct_one_by_powergain ); // Q9 + re[length - i] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; //-Q6 move32(); - tmp = Mult_32_32( im[sub( length, i )], ivas_imdct_one_by_powergain ); - im[sub( length, i )] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( im[length - i], ivas_imdct_one_by_powergain ); // Q9 + im[length - i] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[i] = tmp; + im[i] = tmp; // Q9 move32(); } @@ -255,9 +255,9 @@ static void ivas_ifft_cplx( *-----------------------------------------------------------------------------------------*/ void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ) { Word16 i; @@ -266,13 +266,13 @@ void ivas_itda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); /*Q24 */ move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[add( len_by_2, i )] = re[i]; /*Q24 */ move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[add( length, i )] = re[len_by_2 + i]; /*Q24 */ move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; /*Q24 */ move32(); } @@ -287,9 +287,9 @@ void ivas_itda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -303,9 +303,9 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ + re[i] = L_add( Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); - im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_im[i] ) ); /*stl_arr_index*/ + im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[length - 2 * i - 1], pTwid_im[i] ) ); /*stl_arr_index Q24*/ move32(); } @@ -319,30 +319,30 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { Word32 tmp; - tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); - im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); + tmp = L_add( Mpy_32_16_1( re[i], pTwid_re[i] ), Mpy_32_16_1( im[i], pTwid_im[i] ) ); // Q9 + im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; // Q9 move32(); } FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { - re[add( shl( i, 1 ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; + re[2 * i + 1] = im[( len_by_2 - 1 ) - i]; // Q9 move32(); - re[2 * i] = L_negate( re[i] ); + re[2 * i] = L_negate( re[i] ); // Q9 move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); // Q9 move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[len_by_2 + i] = re[i]; // Q9 move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[length + i] = re[len_by_2 + i]; // Q9 move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; // Q9 move32(); } @@ -356,29 +356,29 @@ void ivas_imdct_fx( * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, - const Word16 **pTwid_im ) + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 + const Word16 **pTwid_im ) // Q15 { IF( EQ_16( length, 480 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_480_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; // Q15 } ELSE IF( EQ_16( length, 320 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_320_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; // Q15 } ELSE IF( EQ_16( length, 160 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_160_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; // Q15 } ELSE IF( EQ_16( length, 80 ) ) { - *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; - *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; + *pTwid_re = (const Word16 *) &ivas_cos_twiddle_80_fx[0]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; // Q15 } ELSE { @@ -405,19 +405,19 @@ Word32 ivas_get_mdct_scaling_gain_fx( { case L_FRAME48k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME32k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME16k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; /*Q46*/ move32(); BREAK; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5e1214c42..a2aada6a9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4610,6 +4610,13 @@ Word16 quantize_phi_fx( Word32 *phi_hat, /* o : quantized azimuth */ const Word16 n /* i : azimuth codebook size */ ); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); #endif /*! r: decoded elevation value */ float deindex_elevation( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 121570bc3..a9ca1f48d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3516,4 +3516,12 @@ void ivas_omasa_enc_close_fx( ivas_error ivas_omasa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bcec831e..3bb90ec8d 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,13 +177,20 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { +#ifndef IVAS_FLOAT_FIXED set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED - set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif +#else + set32_fx( hQMetaData->q_direction[dir].band_data[j].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef MSAN_FIX + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif #endif set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index ab10cd57c..db931df0f 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -495,6 +495,84 @@ ELSE move32(); id_phi = add( id_phi, shr( n, 1 ) ); +return id_phi; +} + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value, Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth, Q22 */ + const Word16 n /* i : azimuth codebook size */ +) +{ + Word16 id_phi; + Word32 dd_fx; + Word32 delta_phi_fx; + Word32 inv_delta_phi_fx; + Word32 temp_res; + Word16 temp_e; + + delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( 360, n, &temp_e ); + delta_phi_fx = L_shl( delta_phi_fx, sub( temp_e, 9 ) ); + inv_delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( n, 360, &temp_e ); + + IF( EQ_16( n, 1 ) ) + { + *phi_hat = 0; + move32(); + + return 0; + } + + test(); + IF( EQ_16( flag_delta, 1 ) && GT_16( n, 2 ) ) + { + dd_fx = dd_val[n]; + move32(); + } + ELSE + { + dd_fx = 0; + move32(); + } + + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); + temp_res = L_shl( temp_res, temp_e ); + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + + assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); + + + IF( add( id_phi, shr( n, 1 ) ) < 0 ) + { + id_phi = add( id_phi, 1 ); + } + + IF( sub( id_phi, shr( n, 1 ) ) >= 0 ) + { + id_phi = negate( shr( n, 1 ) ); + } + + IF( EQ_16( id_phi, negate( add( shr( n, 1 ), ( n % 2 ) ) ) ) ) + { + id_phi = add( id_phi, ( n % 2 ) ); + } + ELSE{ + IF( EQ_16( id_phi, add( shr( n, 1 ), ( n % 2 ) ) ) ){ + IF( n % 2 ){ + id_phi = sub( id_phi, 1 ); +} +ELSE +{ + id_phi = negate( id_phi ); +} +} +} + +*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +move32(); +id_phi = add( id_phi, shr( n, 1 ) ); + return id_phi; } #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 200c376cb..269c62d28 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,76 +1634,46 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[257] = { - 0, - 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, - 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, - 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, - 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, - 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, - 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, - 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, - 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, - 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, - 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, - 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, - 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, - 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, - 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, - 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, - 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, - 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, - 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, - 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, - 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, - 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, - 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, - 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, - 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, - 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, - 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, - 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, - 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, - 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, - 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 +const Word32 delta_phi_val[90] = { + 0, 1509949440, 754974720, 503316480, 377487360, 301989888, + 251658240, 215707056, 188743680, 167772160, 150994944, + 137268128, 125829120, 116149960, 107853528, 100663296, + 94371840, 88820552, 83886080, 79471024, 75497472, + 71902352, 68634064, 65649976, 62914560, 60397976, + 58074980, 55924052, 53926764, 52067224, 50331648, + 48708048, 47185920, 45756044, 44410276, 43141412, + 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, + 32824988, 32126584, 31457280, 30815294, 30198988, + 29606852, 29037490, 28489612, 27962026, 27453626, + 26963382, 26490342, 26033612, 25592364, 25165824, + 24753270, 24354024, 23967452, 23592960, 23229992, + 22878022, 22536558, 22205138, 21883326, 21570706, + 21266894, 20971520, 20684238, 20404722, 20132660, + 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, + 17557552, 17355740, 17158516, 16965724 }; -const Word32 inv_delta_phi_val[257] = { - 0, - 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, - 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, - 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, - 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, - 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, - 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, - 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, - 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, - 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, - 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, - 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, - 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, - 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, - 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, - 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, - 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, - 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, - 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, - 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, - 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, - 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, - 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, - 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, - 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, - 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, - 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, - 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, - 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, - 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, - 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, - 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, - 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 +const Word32 inv_delta_phi_val[90] = { + 0, 5965232, 11930464, 17895697, 23860929, 29826161, + 35791394, 41756626, 47721858, 53687091, 59652323, + 65617555, 71582788, 77548020, 83513252, 89478485, + 95443717, 101408950, 107374182, 113339414, 119304647, + 125269879, 131235111, 137200344, 143165576, 149130808, + 155096041, 161061273, 167026505, 172991738, 178956970, + 184922203, 190887435, 196852667, 202817900, 208783132, + 214748364, 220713597, 226678829, 232644061, 238609294, + 244574526, 250539758, 256504991, 262470223, 268435456, + 274400688, 280365920, 286331153, 292296385, 298261617, + 304226850, 310192082, 316157314, 322122547, 328087779, + 334053011, 340018244, 345983476, 351948708, 357913941, + 363879173, 369844406, 375809638, 381774870, 387740103, + 393705335, 399670567, 405635800, 411601032, 417566264, + 423531497, 429496729, 435461961, 441427194, 447392426, + 453357659, 459322891, 465288123, 471253356, 477218588, + 483183820, 489149053, 495114285, 501079517, 507044750, + 513009982, 518975214, 524940447, 530905679 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 6d4f50fa8..4cf61f9ae 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[257]; -extern const Word32 inv_delta_phi_val[257]; +extern const Word32 delta_phi_val[90]; +extern const Word32 inv_delta_phi_val[90]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 1cea89b76..9d21cfbb4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1341,24 +1341,23 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp64 = W_shl( tmp64, tmp_shift ); } - L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); - val_e = sub( 31, sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ) ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, shl( dm_beta_re_q, 1 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), sub( 31, sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( sub( 31, dm_beta_re_q ), 4 ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); @@ -1366,7 +1365,7 @@ static void ivas_get_pred_coeffs_enc_fx( move16(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); move32(); - DM_F_q[b] = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); + DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); } } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index a4d1065f4..4fde550bd 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -537,11 +537,12 @@ typedef struct typedef struct ivas_qdirection_band_data_struct { uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -557,11 +558,12 @@ typedef struct ivas_qdirection_band_data_struct uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 9c490a012..3cf2b645d 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1709,8 +1709,8 @@ void decimate_2_over_3_allpass_fx( Word16 out, tmp; Word16 mem_fx_11, mem_fx_7, mem_fx_3; Word16 sc, input_fx[960]; - sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 6 ), 2 ) ); - Scale_sig( lp_mem_fx, 6, sc ); + sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 3 ), 2 ) ); + Scale_sig( lp_mem_fx, 3, sc ); Copy_Scale_sig( input, input_fx, len, sc ); Scale_sig( mem_fx, 12, sc ); out1 = out1_buff; @@ -1843,7 +1843,7 @@ void decimate_2_over_3_allpass_fx( Scale_sig( mem_fx, 12, negate( sc ) ); Scale_sig( out_fx, loop_len, negate( sc ) ); - Scale_sig( lp_mem_fx, 6, negate( sc ) ); + Scale_sig( lp_mem_fx, 3, negate( sc ) ); return; } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index da45e5743..70d2f94b0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5860,17 +5860,17 @@ void td_bwe_dec_init_fx( // lsf_dec_fx.c void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); @@ -5998,26 +5998,26 @@ Word32 dotp_me_fx( #endif void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); // cng_dec_fx.c @@ -7299,14 +7299,13 @@ void pvq_decode_fx( #ifdef IVAS_FLOAT_FIXED // nelp_dec_fx.c void nelp_decoder_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 *exc_nelp, /* o : adapt. excitation/total exc */ - Word16 *exc, /* o : adapt. excitation exc */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 *exc_nelp, /* o : adapt. excitation/total exc Q0 */ + Word16 *exc, /* o : adapt. excitation exc Q_exc */ Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , - Word16 *gain_buf /*Q14*/ + Word16 bfi, /* i : frame error rate Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + Word16 *gain_buf /* Q14 */ ); #endif @@ -8623,27 +8622,30 @@ void tcx_hm_decode( ); // lsf_msvq_ma_dec_fx.c -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ); +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +); Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc + Word16 *param_lpc /* Q0 */ ); Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ); Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ); // lsf_msvq_ma_fx.c diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f72017940..fdac07f56 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1739,7 +1739,7 @@ Word32 encode_position_ari_fx( /* Estimate TCQ bits */ bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ); bits_fx = L_add( bits_fx, L_sub( btcq_fx, L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( size, nz ), 1 )] ) ) ) ); - bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[add( pulses, sub( nz, 1 ) )] ) ) ); + bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[pulses - ( nz - 1 )] ) ) ); bits_fx = L_sub( bits_fx, nz ); *est_bits_frame_fx = L_add( *est_bits_frame_fx, bits_fx ); move32(); diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 887f37d5c..c51a2fde5 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -36,7 +36,7 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); *exp = 0; move16(); @@ -51,16 +51,16 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) *--------------------------------------------------------------------------*/ static void spt_shorten_domain_set_dec_fx( - Decoder_State *st_fx, /* i: encoder state structure */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* o: band start position */ - Word16 band_end[], /* o: band end position */ - Word16 band_width[], /* o: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + Decoder_State *st_fx, /* i: encoder state structure */ + const Word16 p2a_flags[], /* i: p2a anlysis information Q0*/ + const Word16 new_band_start[], /* i: new band start position Q0*/ + const Word16 new_band_end[], /* i: new band end position Q0*/ + const Word16 new_band_width[], /* i: new subband band width Q0*/ + const Word16 bands, /* i: total number of subbands Q0*/ + Word16 band_start[], /* o: band start position Q0*/ + Word16 band_end[], /* o: band end position Q0*/ + Word16 band_width[], /* o: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 j, k; @@ -68,27 +68,28 @@ static void spt_shorten_domain_set_dec_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { spt_shorten_flag[j] = 0; move16(); IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); - *bit_budget = sub( *bit_budget, 1 ); + spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ + move16(); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ move16(); IF( EQ_16( spt_shorten_flag[j], 1 ) ) { - band_start[k] = new_band_start[j]; + band_start[k] = new_band_start[j]; /* Q0 */ move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; /* Q0 */ move16(); - band_width[k] = new_band_width[j]; + band_width[k] = new_band_width[j]; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; @@ -131,12 +132,12 @@ void hq_lr_dec_fx( Word32 L_qint; /*Word16 Qqint=29;*/ - Word16 eref_fx /*, Qeref=10*/; - Word16 bit_alloc_weight_fx /*, Qbaw=13*/; - Word16 ld_slope_fx /*, Qldslope=15*/; - Word16 p2a_th_fx /*, Qp2ath=11*/; - Word16 pd_thresh_fx /*, Qpdth=15*/; - Word16 ni_coef_fx /*, Qnicoef=14*/; + Word16 eref_fx /* Qeref=10 */; + Word16 bit_alloc_weight_fx /* Qbaw=13 */; + Word16 ld_slope_fx /* Qldslope=15 */; + Word16 p2a_th_fx /* Qp2ath=11 */; + Word16 pd_thresh_fx /* Qpdth=15 */; + Word16 ni_coef_fx /* Qnicoef=14 */; Word32 L_Rk[BANDS_MAX]; Word16 bit_budget_fx; @@ -203,32 +204,32 @@ void hq_lr_dec_fx( test(); IF( EQ_16( st_fx->bwidth, SWB ) && ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) ) { - hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); - num_bits = sub( num_bits, 2 ); + hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ + num_bits = sub( num_bits, 2 ); /* Q0 */ *is_transient_fx = 0; move16(); if ( EQ_16( hqswb_clas_fx, HQ_TRANSIENT ) ) { - *is_transient_fx = 1; + *is_transient_fx = 1; /* Q0 */ move16(); } } ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice_fx( st_fx, 1 ); + *is_transient_fx = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } /* Configure decoder for different bandwidths, bit rates, etc. */ hq2_core_configure_fx( inner_frame, num_bits, *is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[bands_fx - 1]; + highlength_fx = band_end[bands_fx - 1]; /* Q0 */ move16(); - har_bands_fx = bands_fx; + har_bands_fx = bands_fx; /* Q0 */ move16(); test(); @@ -240,11 +241,11 @@ void hq_lr_dec_fx( test(); IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { - num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); + num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); /* Q0 */ } if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - flag_spt_fx = 1; + flag_spt_fx = 1; /* Q0 */ move16(); } } @@ -257,26 +258,26 @@ void hq_lr_dec_fx( { j = 0; move16(); - FOR( k = sub( bands_fx, SPT_SHORTEN_SBNUM ); k < bands_fx; k++ ) + FOR( k = bands_fx - SPT_SHORTEN_SBNUM; k < bands_fx; k++ ) { hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); - j = add( j, 1 ); + j++; } } } /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); + ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); /* Q0 */ /* simple check: band_energy is too large, Abnormal Situation of bit errors */ FOR( k = 0; k < bands_fx; k++ ) { /* Max: 45.0(737279,Q14) at 32kHz, highest band, Min: -6.600037(-108135,Q14) at 8kHz(NB),8kbps, is_transient (-6.7f(-109772,Q14) is safty-threshold) */ test(); - IF( GT_32( L_band_energy[k], 737279L ) || LT_32( L_band_energy[k], -109772L ) ) + IF( GT_32( L_band_energy[k], 737279L /* 45.0 in Q14 */ ) || LT_32( L_band_energy[k], -109772L /* -6.7 in Q14 */ ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0L, inner_frame ); return; @@ -285,9 +286,9 @@ void hq_lr_dec_fx( /* First pass bit budget for TCQ of spectral band information */ exp_norm = norm_s( gqlevs_fx ); - gqbits_fx = sub( 14, exp_norm ); + gqbits_fx = sub( 14, exp_norm ); /* Q0 */ - bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits_fx = 0; @@ -302,8 +303,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { @@ -313,8 +314,8 @@ void hq_lr_dec_fx( } ELSE { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub( bit_budget_fx, pbits_fx ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ } IF( EQ_16( flag_spt_fx, 1 ) ) @@ -328,7 +329,7 @@ void hq_lr_dec_fx( /* safety check in case of bit errors */ IF( LT_16( bit_budget_fx, 2 ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0, inner_frame ); return; @@ -347,13 +348,13 @@ void hq_lr_dec_fx( Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ move32(); #else - Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ + Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif } FOR( i = 0; i < bands_fx; i++ ) { - L_tmp2 = Ep_fx[i]; + L_tmp2 = Ep_fx[i]; /* Q -6 */ move32(); L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); @@ -375,7 +376,7 @@ void hq_lr_dec_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ @@ -395,20 +396,20 @@ void hq_lr_dec_fx( move16(); FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } - lowband = 6; + lowband = 6; /* Q0 */ move16(); - trans_bit_fx = 2; + trans_bit_fx = 2; /* Q0 */ move16(); - bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); + bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); /* Q0 */ gama_fx = 27852; move16(); /*Q15 0.85f; */ beta_fx = 17203; move16(); /*Q14 1.05f; */ - set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], 0, 2 ); + set16_fx( &p2a_flags_tmp[bands_fx - trans_bit_fx], 0, 2 ); IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { @@ -416,7 +417,7 @@ void hq_lr_dec_fx( move16(); /*14 1.25f; */ gama_fx = 31130; move16(); /*0.95f; */ - Copy( &p2a_flags_fx[sub( bands_fx, trans_bit_fx )], &p2a_flags_tmp[sub( bands_fx, trans_bit_fx )], trans_bit_fx ); + Copy( &p2a_flags_fx[bands_fx - trans_bit_fx], &p2a_flags_tmp[bands_fx - trans_bit_fx], trans_bit_fx ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ @@ -429,11 +430,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -441,7 +442,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { @@ -479,7 +480,7 @@ void hq_lr_dec_fx( } ELSE { - FOR( i = sub( bands_fx, trans_bit_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - trans_bit_fx; i < bands_fx; i++ ) { alpha_fx = 16384; move16(); /*Q14 */ @@ -554,7 +555,7 @@ void hq_lr_dec_fx( move32(); } } - lowband = 3; + lowband = 3; /* Q0 */ move16(); Ep_avrg_fx = L_deposit_l( 0 ); Ep_avrgL_fx = L_deposit_l( 0 ); @@ -605,17 +606,17 @@ void hq_lr_dec_fx( } ELSE IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME16k ) ) { - bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ #else Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif @@ -623,21 +624,21 @@ void hq_lr_dec_fx( } IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 15; + highband = 15; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } ELSE { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 16; + highband = 16; /* Q0 */ move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ enerL_fx = L_deposit_l( 0 ); @@ -650,11 +651,11 @@ void hq_lr_dec_fx( IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { #ifdef BASOP_NOGLOB - Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #else - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ + Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } @@ -663,7 +664,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerH_fx = L_add_sat( enerH_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } ELSE IF( GE_16( i, lowband ) ) @@ -671,7 +672,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB enerL_fx = L_add_sat( enerL_fx, L_shl_sat( Ep_fx[i], 2 ) ); /*Q0 */ #else - enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ + enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ #endif } } @@ -685,7 +686,7 @@ void hq_lr_dec_fx( L_tmp = Mult_32_16( L_shl( enerH_fx, i ), shl( bw_low, j ) ); /* i + j -15 */ L_tmp2 = Mult_32_16( L_shl( enerL_fx, i ), shl( bw_high, j ) ); /*i + j -15 */ L_tmp2 = L_sub( L_tmp, L_tmp2 ); - FOR( i = sub( bands_fx, p2a_bands_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - p2a_bands_fx; i < bands_fx; i++ ) { test(); IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) @@ -696,7 +697,7 @@ void hq_lr_dec_fx( #ifdef BASOP_NOGLOB tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ #else - tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ + tmp1 = extract_h( L_shl( Ep_avrg_fx, 1 ) ); /*Q0 */ #endif IF( tmp1 != 0 ) { @@ -734,7 +735,7 @@ void hq_lr_dec_fx( IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) { tmp = sub( bands_fx, p2a_bands_fx ); - IF( EQ_16( last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) + IF( EQ_16( last_bitalloc_max_band[i - ( tmp + 1 )], 1 ) ) { tmp = sub( tmp, lowband ); L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ @@ -887,11 +888,11 @@ void hq_lr_dec_fx( spt_shorten_domain_band_restore_fx( bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); } - Copy32( L_y2, L_y2_org, L_FRAME32k ); + Copy32( L_y2, L_y2_org, L_FRAME32k ); /* Q12 */ /* Inject noise into components having relatively low pulse energy per band */ ni_seed_fx = add( add( add( npulses_fx[0], npulses_fx[1] ), npulses_fx[2] ), npulses_fx[3] ); - Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); /* Q12 */ hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, @@ -924,16 +925,16 @@ void hq_lr_dec_fx( } } } - Copy32( L_y2_ni, L_y2, lowlength_fx ); + Copy32( L_y2_ni, L_y2, lowlength_fx ); /* Q12 */ } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ } test(); @@ -942,7 +943,7 @@ void hq_lr_dec_fx( k1_fx = sub( bands_fx, 2 ); if ( NE_16( *is_transient_fx, 1 ) ) { - k1_fx = sub( bands_fx, 6 ); + k1_fx = sub( bands_fx, 6 ); /* Q1 */ } L_tmp = L_deposit_l( 0 ); FOR( i = k1_fx; i < bands_fx; i++ ) @@ -950,7 +951,7 @@ void hq_lr_dec_fx( tmp = div_s( 1, sub( bands_fx, k1_fx ) ); /*Q15 */ L_tmp = L_add( L_tmp, Mult_32_16( Ep_tmp_fx[i], tmp ) ); /*Q15 */ } - st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); + st_fx->prev_ener_shb_fx = extract_l( L_shr( L_tmp, 14 ) ); /* Q1 */ move16(); } test(); @@ -972,26 +973,26 @@ void hq_lr_dec_fx( *--------------------------------------------------------------------------------------*/ static Word16 small_symbol_dec_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ - const Word16 is_transient /* i : transient flag */ + Decoder_State *st_fx, /* i/o: decoder state structure Q0*/ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; /* Decoding differential energies*/ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* converting to original values */ FOR( i = 0; i < bands; i++ ) { - qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); + qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -1005,41 +1006,41 @@ static Word16 small_symbol_dec_tran_fx( * Huffman decoding of differential energies (MSB and LSB) *--------------------------------------------------------------------------*/ -static Word16 small_symbol_dec_fx( /* o : bits */ +static Word16 small_symbol_dec_fx( /* o : bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ const Word16 is_transient ) { Word16 i, LSB, bits; Word16 difidx[BANDS_MAX]; /* Decoding MSB bits */ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* Decoding LSB bit packing */ FOR( i = 0; i < bands; ++i ) { - LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); - difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); + LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); /* Q0 */ + difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); /* Q0 */ move16(); } /* counting bits for LSB */ - bits = add( bits, bands ); + bits = add( bits, bands ); /* Q0 */ /* converting to original values */ FOR( i = 1; i < bands; ++i ) { - qbidx[i] = sub( difidx[i], DE_OFFSET1 ); + qbidx[i] = sub( difidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } - qbidx[0] = sub( difidx[0], DE_OFFSET0 ); + qbidx[0] = sub( difidx[0], DE_OFFSET0 ); /* Q0 */ move16(); return ( bits ); @@ -1048,18 +1049,19 @@ static Word16 small_symbol_dec_fx( /* o : bits static Word16 decode_huff_8s_fx( Decoder_State *st_fx, - const Word16 *hufftab, - Word16 *rbits ) + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 bit; WHILE( *hufftab > 0 ) { - *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); + *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); + bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - hufftab += add( shr( *hufftab, 4 ), bit ); + hufftab += add( shr( *hufftab, 4 ), bit ); /* Q0 */ } return negate( *hufftab ); @@ -1067,8 +1069,8 @@ static Word16 decode_huff_8s_fx( static Word16 large_symbol_dec_fx( /* o : bits */ Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands /* i : number of bands */ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands /* i : number of bands Q0*/ ) { Word16 i, bits; @@ -1077,29 +1079,29 @@ static Word16 large_symbol_dec_fx( /* o : bits Word16 pos_outlyer; Word16 ns2mode0, ns2mode1; - cntbits = BITS_DE_8SMODE; + cntbits = BITS_DE_8SMODE; /* Q0 */ move16(); - ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); + ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); /* Q0 */ IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); - ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); - cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); + ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); /* Q0 */ + ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); /* Q0 */ IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { - pos_outlyer = -1; + pos_outlyer = -1; /* Q0 */ move16(); } @@ -1107,84 +1109,84 @@ static Word16 large_symbol_dec_fx( /* o : bits { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < bands; ++i ) + FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } ELSE { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { pos_outlyer = 0; move16(); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } } ELSE { - basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); - cntbits = add( cntbits, BITS_MAX_DEPTH ); + basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); /* Q0 */ + cntbits = add( cntbits, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - qbidx[i] = shl( qbidx[i], basic_shift ); + qbidx[i] = shl( qbidx[i], basic_shift ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = 0; i < bands; ++i ) { - LSB[0] = get_next_indice_fx( st_fx, basic_shift ); + LSB[0] = get_next_indice_fx( st_fx, basic_shift ); /* Q0 */ move16(); - qbidx[i] = add( qbidx[i], LSB[0] ); + qbidx[i] = add( qbidx[i], LSB[0] ); /* Q0 */ move16(); - cntbits = add( cntbits, basic_shift ); + cntbits = add( cntbits, basic_shift ); /* Q0 */ } } @@ -1199,12 +1201,13 @@ static Word16 large_symbol_dec_fx( /* o : bits *--------------------------------------------------------------------------*/ static Word16 band_energy_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 L_band_energy[], /* o : Q14 band energy */ - const Word16 bands_fx, - const Word32 L_qint, - const Word16 eref_fx, - const Word16 is_transient_fx ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 L_band_energy[], /* o : band energy Q14*/ + const Word16 bands_fx, /* Q0 */ + const Word32 L_qint, /* Q0 */ + const Word16 eref_fx, /* Q0 */ + const Word16 is_transient_fx /* Q0 */ +) { Word16 k; Word16 deng_cmode; @@ -1221,28 +1224,28 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ - deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); + deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); /* Q0 */ IF( deng_cmode == 0 ) { - deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); + deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); /* Q0 */ /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } ELSE { IF( is_transient_fx ) { - deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } ELSE { - deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } exp_normd = norm_l( L_qint ); @@ -1281,10 +1284,10 @@ static Word16 band_energy_dequant_fx( *--------------------------------------------------------------------------*/ static Word16 p2a_threshold_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator */ - const Word16 bands, /* i : number of subbands */ - const Word16 p2a_bands /* i : number of subbnads for computing tonality */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *p2a_flags, /* o : tonaly indicator Q0*/ + const Word16 bands, /* i : number of subbands Q0*/ + const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ ) { Word16 j, k; @@ -1292,17 +1295,17 @@ static Word16 p2a_threshold_dequant_fx( j = sub( bands, p2a_bands ); FOR( k = 0; k < j; k++ ) { - p2a_flags[k] = 1; + p2a_flags[k] = 1; /* Q0 */ move16(); } j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = bands - p2a_bands; k < bands; k++ ) { - p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); + p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - j = add( j, 1 ); + j++; } return ( j ); @@ -1348,11 +1351,11 @@ static void mdct_spectrum_fine_gain_dec_fx( exp_normn = norm_l( L_qint ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( gqlevs ); - delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); - Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); /* Q15 */ + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /* Q18 - Qdelta */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q -1*/ FOR( i = 0; i < gqlevs; i++ ) { @@ -1369,9 +1372,9 @@ static void mdct_spectrum_fine_gain_dec_fx( move16(); } - FOR( k = sub( bands, Ngq ); k < bands; k++ ) + FOR( k = bands - Ngq; k < bands; k++ ) { - imin_fx = get_next_indice_fx( st_fx, gqbits ); + imin_fx = get_next_indice_fx( st_fx, gqbits ); /* Q0 */ /*gamma = gain_table[imin]; */ gamma_fx = gain_table_fx[imin_fx]; @@ -1382,12 +1385,12 @@ static void mdct_spectrum_fine_gain_dec_fx( /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ IF( L_y2[i] >= 0x0 ) { - L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); + L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); /* Q12 */ move32(); } ELSE { - L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); + L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); /* Q12 */ move32(); } } diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 5d7313b21..a81e22f25 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -29,32 +29,32 @@ static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); ----------------------------------------------------------------------------------------*/ static void dqlsf_CNG_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q /* o : decoded LSFs */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lsf_q /* o : decoded LSFs Q9*/ ) { Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); /* Q0 */ move16(); - indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); /* Q0 */ move16(); - indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); /* Q0 */ move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ IF( st_fx->element_mode == EVS_MONO ) { ber_flag = - deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0] ); /* Q0 */ } ELSE { ber_flag = - deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); + deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */ } - st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); + st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */ move16(); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). @@ -67,7 +67,7 @@ static void dqlsf_CNG_fx( test(); IF( ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( LE_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) || ( ( LT_16( st_fx->L_frame, L_FRAME16k ) ) && ( GT_16( lsf_q[M - 1], WB_LIMIT_LSF_FX ) ) ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } @@ -102,17 +102,17 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -132,13 +132,13 @@ void lsf_dec_fx( coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - coder_type = INACTIVE; + coder_type = INACTIVE; /* Q0 */ move16(); } test(); if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) { - coder_type = GENERIC; + coder_type = GENERIC; /* Q0 */ move16(); } no_param_lpc = 0; @@ -149,7 +149,7 @@ void lsf_dec_fx( /* Find the number of bits for LSF quantization */ IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - nBits = LSF_BITS_CNG; + nBits = LSF_BITS_CNG; /* Q0 */ move16(); } ELSE @@ -157,25 +157,25 @@ void lsf_dec_fx( test(); IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) { - nBits = st_fx->acelp_cfg.lsf_bits; + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ move16(); } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { IF( EQ_16( coder_type, UNVOICED ) ) { - nBits = 30; + nBits = 30; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - nBits = 32; + nBits = 32; /* Q0 */ move16(); } } } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nBits = 26; + nBits = 26; /* Q0 */ move16(); } } @@ -197,10 +197,10 @@ void lsf_dec_fx( { st_fx->seed_acelp = 0; move16(); - FOR( i = sub( no_param_lpc, 1 ); i >= 0; i-- ) + FOR( i = no_param_lpc - 1; i >= 0; i-- ) { /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L ) ); + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ move16(); // PMTE() /*IVAS_CODE to be completed */ } @@ -240,7 +240,7 @@ void lsf_dec_fx( FOR( i = 1; i < M; i++ ) { - st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); + st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ move16(); } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); @@ -252,8 +252,8 @@ void lsf_dec_fx( IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); - Copy( lsf_new, st_fx->lsf_old_fx, M ); + Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ } { /* Mid-frame LSF decoding */ @@ -267,10 +267,10 @@ void lsf_dec_fx( { /* check, if LSP interpolation can be relaxed */ E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); - enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) { @@ -293,8 +293,8 @@ void lsf_dec_fx( IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) { /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ } test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) @@ -302,9 +302,9 @@ void lsf_dec_fx( // PMT("To be verified") IF( EQ_16( st_fx->active_cnt, 1 ) ) { - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); - Copy( lsp_new, lsp_mid, M ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ @@ -326,7 +326,7 @@ void lsf_dec_fx( } ELSE { - st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ move16(); } @@ -369,18 +369,18 @@ void lsf_dec_fx( /*========================================================================*/ void lsf_end_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *lpc_param, /* i : LPC parameters */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *nb_indices /* o : number of indices */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -409,9 +409,9 @@ void lsf_end_dec_fx( #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */ - nBits = nBits_in; + nBits = nBits_in; /* Q0 */ *nb_indices = 0; move16(); move16(); @@ -427,18 +427,18 @@ void lsf_end_dec_fx( #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16) get_next_indice_fx( st, 1 ); - coder_type = add( coder_type, 2 ); + coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ + coder_type = add( coder_type, 2 ); /* Q0 */ test(); test(); if ( EQ_16( coder_type, GENERIC ) || ( EQ_16( coder_type, VOICED ) && EQ_16( flag_1bit_gran, 1 ) ) ) { - nBits = sub( nBits, 1 ); + nBits = sub( nBits, 1 ); /* Q0 */ } } ELSE { - coder_type = coder_type_org; + coder_type = coder_type_org; /* Q0 */ move16(); } @@ -475,16 +475,16 @@ void lsf_end_dec_fx( { /* if secondary channel predmode is set to be > 2 */ /*predmode += 3;*/ - predmode = add( predmode, 3 ); + predmode = add( predmode, 3 ); /* Q0 */ } #endif - p_lpc_param = lpc_param; + p_lpc_param = lpc_param; /* Q0 */ move16(); IF( predmode == 0 ) { - safety_net = 1; + safety_net = 1; /* Q0 */ move16(); } ELSE IF( predmode == 1 ) @@ -499,18 +499,18 @@ void lsf_end_dec_fx( IF( EQ_16( mode2_flag, 1 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { /* read from param_lpc */ - safety_net = p_lpc_param[0]; + safety_net = p_lpc_param[0]; /* Q0 */ move16(); p_lpc_param++; - *nb_indices = add( *nb_indices, 1 ); + *nb_indices = add( *nb_indices, 1 ); /* Q0 */ } ELSE { - safety_net = (Word16) get_next_indice_fx( st, 1 ); + safety_net = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ } } - st->safety_net = safety_net; + st->safety_net = safety_net; /* Q0 */ move16(); /*--------------------------------------------------------------------------* @@ -523,9 +523,9 @@ void lsf_end_dec_fx( { /* use same AR prediction bit allocation for intra and inter modes*/ lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); - stages0 = stages1; - Copy( levels1, levels0, stages0 ); - Copy( bits1, bits0, stages0 ); + stages0 = stages1; /* Q0 */ + Copy( levels1, levels0, stages0 ); /* Q0 */ + Copy( bits1, bits0, stages0 ); /* Q0 */ } #endif @@ -538,24 +538,24 @@ void lsf_end_dec_fx( test(); IF( EQ_16( st->codec_mode, MODE2 ) || EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { - *nb_indices = 10; + *nb_indices = 10; /* Q0 */ move16(); - TCQIdx[0] = safety_net; + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 1; i < *nb_indices; i++ ) { - TCQIdx[i] = *p_lpc_param++; + TCQIdx[i] = *p_lpc_param++; /* Q0 */ move16(); } } ELSE { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; /* Q0 */ + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); + TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); /* Q0 */ move16(); } } @@ -564,20 +564,20 @@ void lsf_end_dec_fx( { IF( safety_net ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - levels = levels0; + levels = levels0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - levels = levels1; + levels = levels1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } test(); @@ -586,19 +586,19 @@ void lsf_end_dec_fx( { FOR( i = 0; i < sub( stages, 1 ); i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); } - cumleft = levels[stages - 1]; + cumleft = levels[stages - 1]; /* Q0 */ move16(); WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ } ELSE { @@ -606,43 +606,43 @@ void lsf_end_dec_fx( move16(); } - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); - i = add( i, 1 ); + i++; } - *nb_indices = add( *nb_indices, i ); + *nb_indices = add( *nb_indices, i ); /* Q0 */ move16(); } ELSE { FOR( i = 0; i < stages - 1; i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); } - cumleft = levels[sub( stages, 1 )]; + cumleft = levels[stages - 1]; /* Q0 */ WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); - num_bits = LEN_INDICE; + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ + num_bits = LEN_INDICE; /* Q0 */ move16(); } ELSE { - num_bits = (Word16) cumleft; + num_bits = (Word16) cumleft; /* Q0 */ move16(); cumleft = 0; move16(); } - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); - i = add( i, 1 ); + i++; } } } @@ -650,7 +650,7 @@ void lsf_end_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; + st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; /* Q2.56 */ move16(); } st->reset_mem_AR = 0; @@ -661,7 +661,7 @@ void lsf_end_dec_fx( * De-quantize LSF vector *------------------------------------------------------------------------------------------*/ - *LSF_Q_prediction = SAFETY_NET; + *LSF_Q_prediction = SAFETY_NET; /* Q0 */ move16(); /* VOICED_WB@16kHz */ test(); @@ -669,14 +669,14 @@ void lsf_end_dec_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) { /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Q0 */ /* Update mem_MA */ - Copy( qlsf, st->mem_MA_fx, M ); + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ IF( safety_net ) { - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ } ELSE { @@ -685,7 +685,7 @@ void lsf_end_dec_fx( pred0[i] = add( ModeMeans_fx[mode_lvq][i], mult( Predictors_fx[mode_lvq_p][i], ( sub( st->mem_AR_fx[i], ModeMeans_fx[mode_lvq][i] ) ) ) ); /* Q(x2.56)*/ move16(); } - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } Vr_add( qlsf, pred0, qlsf, M ); @@ -694,11 +694,11 @@ void lsf_end_dec_fx( { /* Safety-net */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ /* for mem_MA update */ FOR( i = 0; i < M; i++ ) { - pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */ move16(); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE @@ -719,7 +719,7 @@ void lsf_end_dec_fx( /* intra mode*/ st->BER_detect = s_or( st->BER_detect, - vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ move16(); Vr_add( qlsf, pred3, qlsf, M ); @@ -730,15 +730,15 @@ void lsf_end_dec_fx( { IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -757,15 +757,15 @@ void lsf_end_dec_fx( #endif IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1], &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); @@ -774,9 +774,9 @@ void lsf_end_dec_fx( IF( EQ_16( predmode, 1 ) ) /* MA only */ #endif { - Copy( qlsf, st->mem_MA_fx, M ); - Vr_add( qlsf, pred1, qlsf, M ); - *LSF_Q_prediction = MOVING_AVERAGE; + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ + Vr_add( qlsf, pred1, qlsf, M ); /* Q2.56 */ + *LSF_Q_prediction = MOVING_AVERAGE; /* Q0 */ move16(); } ELSE @@ -784,12 +784,12 @@ void lsf_end_dec_fx( /* AR */ FOR( i = 0; i < M; i++ ) { - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); + pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); /* Q2.56 */ move16(); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } } @@ -807,9 +807,9 @@ void lsf_end_dec_fx( /* Verify stability */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update predictor memory */ - Copy( qlsf, st->mem_AR_fx, M ); + Copy( qlsf, st->mem_AR_fx, M ); /* Q2.56 */ - st->mode_lvq = mode_lvq; + st->mode_lvq = mode_lvq; /* Q0 */ move16(); @@ -839,10 +839,10 @@ void lsf_end_dec_fx( /* _ None */ /*========================================================================*/ void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -862,19 +862,19 @@ void lsf_mid_dec_fx( /* Codebook selection */ IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nb_bits = 1; + nb_bits = 1; /* Q0 */ move16(); - ratio = &tbl_mid_voi_wb_1b_fx[0]; + ratio = &tbl_mid_voi_wb_1b_fx[0]; /* Q13 */ } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { - nb_bits = 4; + nb_bits = 4; /* Q0 */ move16(); - ratio = &tbl_mid_unv_wb_4b_fx[0]; + ratio = &tbl_mid_unv_wb_4b_fx[0]; /* Q13 */ } ELSE { - nb_bits = st_fx->acelp_cfg.mid_lsf_bits; + nb_bits = st_fx->acelp_cfg.mid_lsf_bits; /* Q0 */ move16(); /* codebook selection */ @@ -885,24 +885,24 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_voi_wb_5b_fx; + ratio = tbl_mid_voi_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_voi_wb_4b_fx; + ratio = tbl_mid_voi_wb_4b_fx; /* Q13 */ BREAK; } case 1: { - ratio = tbl_mid_voi_wb_1b_fx; + ratio = tbl_mid_voi_wb_1b_fx; /* Q13 */ break; } } } - ELSE IF( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { - ratio = tbl_mid_unv_wb_5b_fx; + ratio = tbl_mid_unv_wb_5b_fx; /* Q13 */ } ELSE { @@ -911,17 +911,17 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_gen_wb_5b_fx; + ratio = tbl_mid_gen_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_gen_wb_4b_fx; + ratio = tbl_mid_gen_wb_4b_fx; /* Q13 */ break; } case 2: { - ratio = tbl_mid_gen_wb_2b_fx; + ratio = tbl_mid_gen_wb_2b_fx; /* Q13 */ BREAK; } } @@ -929,7 +929,7 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Q0 */ /* Calculation of mid-LSF vector */ FOR( j = 0; j < M; j++ ) @@ -947,7 +947,7 @@ void lsf_mid_dec_fx( { IF( LT_16( qlsf[j], qlsf[j - 1] ) ) { - bad_spacing = 1; + bad_spacing = 1; /* Q0 */ move16(); BREAK; } @@ -970,7 +970,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -984,7 +984,7 @@ void lsf_mid_dec_fx( test(); IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); + qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); /* Q2.56 */ move16(); } } @@ -993,7 +993,7 @@ void lsf_mid_dec_fx( if ( st_fx->prev_bfi ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - st_fx->mid_lsf_int = 1; + st_fx->mid_lsf_int = 1; /* Q0 */ move16(); } diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 167f71d4d..f57aee0e1 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -26,7 +26,10 @@ * *---------------------------------------------------------------------*/ -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc, tmp; Word16 bits_midlpc; @@ -34,7 +37,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits; Word16 predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc = 5; + bits_midlpc = 5; /* Q0 */ move16(); test(); @@ -63,54 +66,54 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( EQ_16( predmode, 2 ) ) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice_fx( st, 1 ); + safety_net = get_next_indice_fx( st, 1 ); /* Q0 */ IF( EQ_16( safety_net, 1 ) ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - *param_lpc = safety_net; + *param_lpc = safety_net; /* Q0 */ move16(); param_lpc++; - nbits_lpc++; + nbits_lpc = add( nbits_lpc, 1 ); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - tmp = sub( stages, 1 ); + tmp = sub( stages, 1 ); /* Q0 */ FOR( i = 0; i < tmp; i++ ) { - *param_lpc = get_next_indice_fx( st, bits[i] ); + *param_lpc = get_next_indice_fx( st, bits[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits[i] ); + nbits_lpc = add( nbits_lpc, bits[i] ); /* Q0 */ } - *param_lpc = get_next_indice_fx( st, LEN_INDICE ); + *param_lpc = get_next_indice_fx( st, LEN_INDICE ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, LEN_INDICE ); + nbits_lpc = add( nbits_lpc, LEN_INDICE ); /* Q0 */ - *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); + *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); + nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); /* Q0 */ test(); @@ -118,9 +121,9 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( NE_16( st->coder_type, VOICED ) && st->core == 0 && st->acelp_cfg.midLpc ) { - *param_lpc = get_next_indice_fx( st, bits_midlpc ); + *param_lpc = get_next_indice_fx( st, bits_midlpc ); /* Q0 */ move16(); - nbits_lpc = add( nbits_lpc, bits_midlpc ); + nbits_lpc = add( nbits_lpc, bits_midlpc ); /* Q0 */ } return nbits_lpc; @@ -129,15 +132,16 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc ) + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc; Word16 num_par; const Word16 *bits1; - num_par = 10; + num_par = 10; /* Q0 */ move16(); - bits1 = BC_TCVQ_BIT_ALLOC_40B; + bits1 = BC_TCVQ_BIT_ALLOC_40B; /* Q0 */ nbits_lpc = 0; move16(); @@ -145,10 +149,10 @@ Word16 lsf_bctcvq_decprm( FOR( i = 0; i < num_par; i++ ) { - *param_lpc = get_next_indice_fx( st, bits1[i] ); + *param_lpc = get_next_indice_fx( st, bits1[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits1[i] ); + nbits_lpc = add( nbits_lpc, bits1[i] ); /* Q0 */ } return nbits_lpc; @@ -156,12 +160,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices */ - Word16 lsf_q[], /* o : quantized LSF */ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk, /* i : codebook selector */ - Word16 mem_MA[] /* i : MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ) { Word16 i; @@ -171,7 +175,7 @@ Word16 D_lsf_tcxlpc( const Word16 *means; Word16 lsf_rem_q_ind[M]; - NumIndices = 1; + NumIndices = 1; /* Q0 */ move16(); msvq_dec( @@ -187,7 +191,7 @@ Word16 D_lsf_tcxlpc( #endif lsf_q ); - NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); /* Q0 */ FOR( i = 0; i < M; ++i ) { @@ -209,32 +213,32 @@ Word16 D_lsf_tcxlpc( 0, NULL, #endif lsf_rem_q_ind ); - NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); /* Q0 */ /* Add to MA-removed vector */ FOR( i = 0; i < M; ++i ) { - lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); /* Q1 */ move16(); } } /* Inter-frame prediction */ move16(); - means = lsf_means[narrowband]; + means = lsf_means[narrowband]; /* Q1 */ FOR( i = 0; i < M; ++i ) { - pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /* Q1 */ move16(); } /* Add prediction */ FOR( i = 0; i < M; ++i ) { - lsf_q[i] = add( lsf_q[i], pred[i] ); + lsf_q[i] = add( lsf_q[i], pred[i] ); /* Q1 */ move16(); - lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); /* Q1 */ move16(); } @@ -251,26 +255,26 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits read */ Word16 dec_lsf_tcxlpc( - Decoder_State *st, /* i/o: Decoder state */ - Word16 **indices, /* o : Ptr to VQ indices */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk /* i : codebook selector */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ) { Word16 i, start_bit_pos; Word16 lsf_q_ind[M]; Word16 *flag; - flag = *indices; /* Save pointer */ + flag = *indices; /* Save pointer Q0*/ *flag = 0; move16(); /* Set flag to disabled */ ++*indices; - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); FOR( i = 0; i < TCXLPC_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_numbits[i] ); /* Q0 */ ++*indices; move16(); } @@ -290,13 +294,13 @@ Word16 dec_lsf_tcxlpc( lsf_q_ind ); /* Update flag */ - *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); + *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); /* Q0 */ move16(); IF( *flag ) { FOR( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); /* Q0 */ ++*indices; move16(); } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 1f103223e..a1e2bbf39 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -86,7 +86,15 @@ static void normalize_arr( Word16 *arr, Word16 *qf, Word16 size, Word16 hdr ) /* _ None */ /*===================================================================*/ -void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type, Word16 *gain_buf ) +void nelp_decoder_fx( + Decoder_State *st_fx, + Word16 *exc_nelp, /* Q0 */ + Word16 *exc, /* Q_exc */ + Word16 *Q_exc, + Word16 bfi, /* Q0 */ + const Word16 coder_type, /* Q0 */ + Word16 *gain_buf /* Q14 */ +) { Word16 i, fid = 0; move16(); @@ -126,7 +134,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER * 2 ); @@ -134,7 +142,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 } ELSE IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { @@ -154,21 +162,21 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - iG1 = st_fx->rf_indx_nelp_iG1; + iG1 = st_fx->rf_indx_nelp_iG1; /* Q0 */ move16(); - iG2[0] = st_fx->rf_indx_nelp_iG2[0]; + iG2[0] = st_fx->rf_indx_nelp_iG2[0]; /* Q0 */ move16(); - iG2[1] = st_fx->rf_indx_nelp_iG2[1]; + iG2[1] = st_fx->rf_indx_nelp_iG2[1]; /* Q0 */ move16(); } ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); + iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); /* Q0 */ move16(); - iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); - iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); } @@ -179,12 +187,12 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) && EQ_16( st_fx->use_partial_copy, 1 ) ) { - fid = st_fx->rf_indx_nelp_fid; + fid = st_fx->rf_indx_nelp_fid; /* Q0 */ move16(); } ELSE { - fid = (Word16) get_next_indice_fx( st_fx, 2 ); + fid = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); } } @@ -202,7 +210,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 max_exc_sqr = L_deposit_l( 0 ); FOR( i = 0; i < L_SUBFR; i++ ) { - max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); + max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); /*2*Q_exc */ } IF( max_exc_sqr != 0 ) { @@ -231,7 +239,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 n = norm_l( Gain ); frac = round_fx( L_shl( Gain, n ) ); n = sub( add( n, 24 ), 30 ); - frac = div_s( 16384, frac ); + frac = div_s( 16384, frac ); /* Q15 */ Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ tmp = round_fx( L_shl( Gain, sub( add( n, exp ), 15 ) ) ); /*Q0 */ } @@ -272,7 +280,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), qGain ); /* bring filter prev memory from Q0 to qGain */ pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_wb_dec_fx, @@ -280,18 +288,18 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), negate( qGain ) ); /* bring filter prev memory from qGain to Q0 */ Scale_sig( ptr_tmp, L_FRAME, -qGain ); /* bring nelp_exc to Q0 */ - Copy( ptr_tmp, ptr, L_FRAME ); + Copy( ptr_tmp, ptr, L_FRAME ); /* Q0 */ } test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); FOR( i = 0; i < L_FRAME; i++ ) { - max_val = s_max( ptr[i], max_val ); + max_val = s_max( ptr[i], max_val ); /* Q0 */ } tmp = shl( BP1_ORDER, 1 ); FOR( i = 0; i < tmp; i++ ) @@ -306,13 +314,13 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 IF( norm_val > 0 ) { - Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); - Scale_sig( ptr, L_FRAME, norm_val ); + Scale_sig32( hSC_VBR->bp1_filt_mem_nb_dec_fx, shl( BP1_ORDER, 1 ), norm_val ); /* norm_val */ + Scale_sig( ptr, L_FRAME, norm_val ); /* norm_val + Q_exc */ *Q_exc = add( norm_val, *Q_exc ); move16(); } - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, hSC_VBR->bp1_filt_mem_nb_dec_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index cb326efb2..6e051302f 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -902,6 +902,10 @@ ivas_error init_encoder( st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef MSAN_FIX + set32_fx( st->hTcxEnc->spectrum_fx[0], 0, N_TCX10_MAX ); + set32_fx( st->hTcxEnc->spectrum_fx[1], 0, N_TCX10_MAX ); +#endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); /* MDCT selector */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 48e175a43..20ac14fb6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -1101,9 +1101,11 @@ ivas_error ivas_core_enc( fb_tbe_enc( st, st->input, fb_exc ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifndef MSAN_FIX Q_fb_exc = Q_factor_arr( fb_exc, L_FRAME16k ); floatToFixed_arr( fb_exc, fb_exc_fx, Q_fb_exc, L_FRAME16k ); - // Q_input is being calculated inside already +#endif + // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 9e8ba1410..7902d1cf8 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1138,7 +1138,9 @@ ivas_error ivas_compute_core_buffers( Word16 inp16k_out_buf_fx[2][L_FRAME16k]; Word16 **inp16k_out_fx = (Word16 **) inp16k_out_buf_fx; Word16 new_inp_resamp16k_out_fx[L_FRAME16k]; - +#ifdef MSAN_FIX + set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); +#endif signal_in_32fx = st->input32_fx; signal_in_fx = st->input_fx; diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 2a10d92d7..beeec44b7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -625,12 +625,8 @@ ivas_error ivas_dirac_enc( { for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); if ( hodirac_flag ) { - hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); } else @@ -682,18 +678,51 @@ ivas_error ivas_dirac_enc( #endif - if ( hQMetaData->q_direction->cfg.nbands > 0 ) + IF( hQMetaData->q_direction->cfg.nbands > 0 ) { orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ - if ( hQMetaData->dirac_mono_flag ) + IF( hQMetaData->dirac_mono_flag ) { +#ifdef IVAS_FLOAT_FIXED + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + ELSE + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < 1; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + +#else for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) @@ -703,6 +732,7 @@ ivas_error ivas_dirac_enc( hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; } } +#endif } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -711,8 +741,6 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -720,7 +748,7 @@ ivas_error ivas_dirac_enc( } } #endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -730,17 +758,14 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif } - else + ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; + move16(); /* compute directions */ for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) @@ -753,11 +778,6 @@ ivas_error ivas_dirac_enc( for ( j = 0; j < orig_dirac_bands - 1; j++ ) { #ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].azimuth[i], Q22 ); - hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].elevation[i], Q22 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); /*==========================================fix-2-flt======================================================*/ @@ -784,18 +804,18 @@ ivas_error ivas_dirac_enc( /*==========================================flt-2-fix======================================================*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); - - /*==========================================fix-2-flt======================================================*/ - hQMetaData->q_direction[0].band_data[0].azimuth[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], Q22 ); - hQMetaData->q_direction[0].band_data[0].elevation[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].elevation_fx[i], Q22 ); - /*==========================================fix-2-flt======================================================*/ #else ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); #endif hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; + hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; +#else hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; +#endif hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; } @@ -804,62 +824,58 @@ ivas_error ivas_dirac_enc( /* encode SID parameters */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif #else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); #endif } - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; + hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; +#else hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; +#endif hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; } } - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } } hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + move16(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 978bb371f..c41736176 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -863,19 +863,27 @@ ivas_error ivas_enc( if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) { - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ - #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } +#endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif +#else + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -885,13 +893,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -951,32 +955,47 @@ ivas_error ivas_enc( float *data_separated_object; Word32 *data_separated_object_fx; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; + Word16 idx_separated_object; + Word16 flag_omasa_ener_brate; flag_omasa_ener_brate = 0; + move16(); /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) + { + v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); + Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - + ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#endif +#else + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -986,13 +1005,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1017,7 +1032,6 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - MASA_ENCODER_HANDLE hMasa = st_ivas->hMasa; int16_t j; int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; @@ -1040,23 +1054,9 @@ ivas_error ivas_enc( { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - } - } #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - } - } for ( i = 0; i < nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); @@ -1379,8 +1379,6 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth_fx[jj], Q22 ); - st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation_fx[jj], Q22 ); st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); } } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1d77e746c..b40665a98 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1203,15 +1203,6 @@ ivas_error ivas_init_encoder( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1222,13 +1213,9 @@ ivas_error ivas_init_encoder( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1878,15 +1865,6 @@ ivas_error ivas_init_encoder_fx( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1897,13 +1875,9 @@ ivas_error ivas_init_encoder_fx( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 97101e412..5438bc921 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -397,37 +397,15 @@ ivas_error ivas_masa_encode( ivas_error error; Word16 guard_bits, tmp; + guard_bits = find_guarded_bits_fx( 24 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - hMasa->data.q_energy = Q31; - // guard_bits = find_guarded_bits_fx( 9 ); - guard_bits = find_guarded_bits_fx( 24 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_e[i][j] = 31 - hMasa->data.q_energy; - } - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } #endif masa_sid_descriptor = -1; @@ -487,28 +465,29 @@ ivas_error ivas_masa_encode( /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes_fx( hMasa ); + } - /* aligning the exponents */ - s = 0; - move16(); - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); - s = s_max( s, tmp ); - } - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + /* aligning the exponents of energy_fx */ + s = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); + s = s_max( s, tmp ); + } + s = add( s, guard_bits ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); - hMasa->data.energy_e[i][j] = s; - move32(); - move16(); - } + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_e[i][j] = s; + move32(); + move16(); } - hMasa->data.q_energy = sub( 31, s ); - move16(); } + hMasa->data.q_energy = sub( 31, s ); + move16(); test(); test(); @@ -881,19 +860,11 @@ ivas_error ivas_masa_encode( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif @@ -1265,8 +1236,113 @@ ivas_error ivas_masa_encode( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------* + * ivas_masa_estimate_energy_fx() + * + * + *-----------------------------------------------------------------------*/ +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +) +{ + Word32 Input_RealBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 Input_ImagBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 block_m_idx, band_m_idx; + Word16 mrange[2], brange[2]; + Word16 i, j, ts, l_ts, maxBin; + Word64 energy_fx_temp[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 scale = 63; + move16(); + Word16 q_buf; + maxBin = extract_l( Mpy_32_32( 134217728 /*CLDFB_NO_CHANNELS_MAX / L_FRAME48k in Q31*/, input_frame ) ); + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + energy_fx_temp[i][j] = 0; + move64(); + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + mrange[0] = hMasa->config.block_grouping[block_m_idx]; + move16(); + mrange[1] = hMasa->config.block_grouping[block_m_idx + 1]; + move16(); + set_zero_fx( hMasa->data.energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); + set16_fx( hMasa->data.energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + q_buf = q_data; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i], &q_buf ); // (q_data - 5) for Input_RealBuffer[i], Input_ImagBuffer[i] + } + + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + brange[0] = hMasa->config.band_grouping[band_m_idx]; + move16(); + brange[1] = hMasa->config.band_grouping[band_m_idx + 1]; + move16(); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( GT_16( brange[0], maxBin ) ) + { + hMasa->data.energy_fx[block_m_idx][band_m_idx] = 0; + move32(); + CONTINUE; + } + ELSE IF( GE_16( brange[1], maxBin ) ) + { + brange[1] = maxBin; + move16(); + } + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_add( energy_fx_temp[block_m_idx][band_m_idx], W_mac_32_32( W_mult_32_32( Input_RealBuffer[i][j], Input_RealBuffer[i][j] ), Input_ImagBuffer[i][j], Input_ImagBuffer[i][j] ) ); // Q: 2 * (q_data - 5) + 1 for energy_fx_temp + move64(); + } + IF( energy_fx_temp[block_m_idx][band_m_idx] != 0 ) + { + scale = s_min( scale, W_norm( energy_fx_temp[block_m_idx][band_m_idx] ) ); // scale calculates minimum shift can be done across a buffer + } + } + } + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_shl( energy_fx_temp[block_m_idx][band_m_idx], scale ); // Q: 2 * (q_data - 5) + 1 + scale + move64(); + hMasa->data.energy_fx[block_m_idx][band_m_idx] = W_extract_h( energy_fx_temp[block_m_idx][band_m_idx] ); // Q: 2 * (q_data - 5) + 1 + scale - 32 + move32(); + hMasa->data.energy_e[block_m_idx][band_m_idx] = sub( 31, add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ) ); + move16(); + } + } + hMasa->data.q_energy = add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ); + move16(); + + return; +} +#else /*-----------------------------------------------------------------------* * ivas_masa_estimate_energy() * @@ -1332,6 +1408,7 @@ void ivas_masa_estimate_energy( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index f74174689..024532450 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -887,7 +887,11 @@ void ivas_param_mc_enc_fx( { Word16 cpe_idx = shr( ch, 1 ); +#ifndef MSAN_FIX Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], -Q1 - Q11, input_frame ); // Q11 -> Q(-1) +#else + Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], input_frame, -Q1 - Q11 ); // Q11 -> Q(-1) +#endif RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 821450296..57de41384 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -1696,6 +1696,20 @@ void ivas_mcmasa_param_est_enc_fx( p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; } + /* initialising energy_fx */ + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.energy_fx[block_m_idx][i] = 0; + move32(); + hMasa->data.energy_e[block_m_idx][i] = 31; + move16(); + } + } + hMasa->data.q_energy = 0; + move16(); + /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { @@ -1767,25 +1781,11 @@ void ivas_mcmasa_param_est_enc_fx( } /* Store energies for guiding metadata encoding */ - hMasa->data.energy_fx[block_m_idx][i] = 0; - move32(); - hMasa->data.energy_e[block_m_idx][i] = 31; - move16(); FOR( j = 0; j < numAnalysisChannels; j++ ) { move32(); hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hMasa->data.energy_e[block_m_idx][i] < 31 ) - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] / (float) ( 1 << ( 31 - hMasa->data.energy_e[block_m_idx][i] ) ); - } - ELSE - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] * (float) ( 1 << ( hMasa->data.energy_e[block_m_idx][i] - 31 ) ); - } -#endif } IF( !hMcMasa->separateChannelEnabled ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f326b1a32..aaa3dd260 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -1771,15 +1771,6 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1789,13 +1780,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1812,15 +1799,6 @@ static ivas_error ivas_mc_enc_reconfig( { /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1830,13 +1808,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 79a32e4a4..bde299111 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -2231,7 +2231,7 @@ Word16 quantize_direction2D_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); } *phi_q = L_sub( *phi_q, 180 << Q22 ); move32(); @@ -4257,7 +4257,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4400,7 +4400,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4478,7 +4478,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - avg_azimuth_index_upd = quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); + avg_azimuth_index_upd = quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); } idx = add( idx, 1 ); } @@ -5772,7 +5772,7 @@ static Word16 truncGR0_fx( FOR( i = 0; i < len; i++ ) { - data_idx[i] = quantize_phi_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); + data_idx[i] = quantize_phi_enc_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); move16(); data_hat_fx[i] = L_sub( data_hat_fx[i], DEGREE_180_Q_22 ); move32(); @@ -5796,7 +5796,7 @@ static Word16 truncGR0_fx( { bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( 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_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[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(); // data_hat[indx[i]] -= 180; data_hat_fx[indx[i]] = L_sub( data_hat_fx[indx[i]], DEGREE_180_Q_22 ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 74a787b2c..d2804108a 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -812,7 +812,7 @@ UWord16 quantize_direction_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); idx_sph = id_phi; *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); id_phi_remap = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_phi_masa[no_bits - 1][0], 1 ) ) ); @@ -1339,7 +1339,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } ELSE @@ -1362,7 +1362,7 @@ static Word32 quantize_theta_phi_fx( // Q22 theta_hat1 = theta_cb[id_th1]; move32(); - id_ph1 = quantize_phi_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); + id_ph1 = quantize_phi_enc_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); d_fx = direction_distance_cp_fx( abs_theta, theta_hat, theta_hat1, phi, *phi_hat, phi_hat1, &d1_fx ); @@ -1389,7 +1389,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ba611679..d7857435a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -1132,7 +1132,11 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } +#ifdef MSAN_FIX + FOR( Word16 m = 0; m < nchan_fb_in; m++ ) +#else FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) +#endif { IF( data_f[m] != NULL ) { @@ -1294,11 +1298,6 @@ static ivas_error ivas_spar_enc_process( for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) { Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) - { - hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts], Q22 ); - hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts], Q22 ); - } hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 4c3eca4d9..8e8dc8f84 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1296,16 +1296,17 @@ typedef struct ivas_masa_sync_struct typedef struct ivas_masa_encoder_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 q_energy; // Common Q for all energy_fx elements + Word16 q_energy; // Common Q for all energy_fx elements #endif - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; - int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; - uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; + Word16 band_mapping[MASA_FREQUENCY_BANDS + 1]; + UWord8 twoDirBands[MASA_FREQUENCY_BANDS]; SPHERICAL_GRID_DATA Sph_Grid16; #ifdef IVAS_FLOAT_FIXED Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ @@ -1319,7 +1320,7 @@ typedef struct ivas_masa_encoder_data_struct #else Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 #endif - int16_t prevq_lfeIndex; + Word16 prevq_lfeIndex; #ifndef IVAS_FLOAT_FIXED float onset_detector_1; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 91799b60a..a9dc30e44 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -325,12 +325,11 @@ void stereo_dft_enc_sid_coh_fx( Word16 zeropad; Word16 nr_of_sid_stereo_bits; Word16 coh_pred_index; - Word16 min_pred_err; - Word16 min_pred_err_e; + Word64 min_pred_err; Word16 pred_err; // Q13 Word16 res_index; Word16 i; - Word16 tmp; + Word32 tmp; const Word16 *pptr; Word16 pred; // Q13 Word16 cohBandq[STEREO_DFT_BAND_MAX / 2]; /* Reconstructed coherence values for intra-frame prediction Q15 */ @@ -355,37 +354,33 @@ void stereo_dft_enc_sid_coh_fx( IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS + STEREO_DFT_PRED_NBITS ) > 0 ) { - min_pred_err = 31250; - move32(); - min_pred_err_e = 20; - move16(); + min_pred_err = 134217728000000; // 1e6 in Q27 + move64(); coh_pred_index = -1; move16(); pptr = dft_cng_coh_pred_fx[0]; // Q13 FOR( k = 0; k < STEREO_DFT_N_COH_PRED; k++ ) { - pred_err = 0; - move16(); + Word64 pred_err64 = 0; + move64(); FOR( b = 1; b < nbands; b++ ) /* Set b=1 to skip first coefficient (same error would otherwise be added for all predictors: (cohBand[0] - 0).^2) */ { - pred = 0; - move16(); + Word64 pred64 = 0; + move64(); FOR( i = 0; i < b; i++ ) { // pred += ( *pptr++ ) * cohBand[i]; - pred = add( pred, mult_r( extract_h( cohBand[i] ), ( *pptr++ ) ) ); // Q13 + pred64 = W_mac_32_16( pred64, cohBand[i], *pptr++ ); // Q45 (31+13+1) } - tmp = sub( shr_r( extract_h( cohBand[b] ), 2 ), pred ); // Q13 + tmp = L_sub( L_shr( cohBand[b], 18 ), W_extract_h( pred64 ) ); // Q13 // pred_err += tmp * tmp; - pred_err = add( pred_err, shl( mult_r( tmp, tmp ), 2 ) ); // Q13 + pred_err64 = W_mac_32_32( pred_err64, tmp, tmp ); // Q27 } // if ( pred_err < min_pred_err ) /* Store best candidate */ - IF( BASOP_Util_Cmp_Mant32Exp( pred_err, 16, min_pred_err, add( min_pred_err_e, 16 ) ) < 0 ) /* Store best candidate */ + IF( LT_64( pred_err64, min_pred_err ) ) /* Store best candidate */ { - min_pred_err = pred_err; - move32(); - min_pred_err_e = 0; - move16(); + min_pred_err = pred_err64; // Q27 + move64(); coh_pred_index = k; move16(); } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index e9f7d3d33..2d0b9e08d 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -55,8 +55,8 @@ #ifndef IVAS_FLOAT_FIXED #define POLY_THRESH 1e-4f #else -#define POLY_THRESH_Q29 53687 // Q29 -#define POLY_THRESH_Q28 26843 // Q28 +#define POLY_THRESH_Q29 53687LL // Q29 +#define POLY_THRESH_Q28 26843 // Q28 #endif #ifdef IVAS_FLOAT_FIXED #define Q22_1 4194304 @@ -83,7 +83,7 @@ static void sort_vertices( const EFAP_VERTEX *vertexArray, const int16_t *numVtx static void visible_edges( const EFAP_LS_TRIANGLE *triArray, const int16_t *visible, const int16_t numSurface, int16_t *numEdges, int16_t *edges ); #else static ivas_error poly_init_fx( EFAP *efap, const Word16 efip_flag ); -static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose, Word16 *numTot, const Word16 efip_flag ); +static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose /*q31*/, Word16 *numTot, const Word16 efip_flag ); static void initial_polyeder_fx( EFAP_VERTEX_DATA *vtxData, EFAP_LS_TRIANGLE *triArray, Word16 *numTri, Word16 *vtxInHull ); static void add_ghost_speakers_fx( EFAP_VERTEX *vertexArray, Word16 *numVtx, const Word16 efip_flag ); static void add_vertex_to_convex_hull_fx( const EFAP_VERTEX_DATA *vtxData, const Word16 vtxIdx, Word16 *vtxInHull, EFAP_LS_TRIANGLE *triArray, Word16 *szTri ); @@ -100,12 +100,12 @@ static void efap_panning( const float azi, const float ele, const EFAP_POLYSET_D static void get_poly_gains( const float azi, const float ele, const float aziPoly[EFAP_MAX_CHAN_NUM], const float elePoly[EFAP_MAX_CHAN_NUM], const int16_t numChan, float *buffer ); static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); #else -static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] ); -static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix ); -static void vertex_init_fx( const Word32 *aziSpk, const Word32 *eleSpk, EFAP_VERTEX_DATA *efapVtxData ); -static void efap_panning_fx( const Word32 azi, const Word32 ele, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL ); -static void get_poly_gains_fx( const Word32 azi, const Word32 ele, const Word32 aziPoly[EFAP_MAX_CHAN_NUM], const Word32 elePoly[EFAP_MAX_CHAN_NUM], const Word16 numChan, Word32 *buffer ); -static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word32 C[2], const Word32 P_minus_A[2] ); +static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] /*q31*/ ); +static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix /*q31*/ ); +static void vertex_init_fx( const Word32 *aziSpk /*q22*/, const Word32 *eleSpk /*q22*/, EFAP_VERTEX_DATA *efapVtxData ); +static void efap_panning_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL /*q31*/ ); +static void get_poly_gains_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word32 aziPoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word32 elePoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word16 numChan, Word32 *buffer /*q31*/ ); +static Word32 get_tri_gain_fx( const Word32 A[2] /*q22*/, const Word32 B[2] /*q22*/, const Word32 C[2] /*q22*/, const Word32 P_minus_A[2] /*q22*/ ); #endif /*-----------------------------------------------------------------------* @@ -116,7 +116,7 @@ static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word3 static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); #else -static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi, const Word32 ele, const Word16 pos, const EFAP_VTX_DMX_TYPE ); +static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); #endif @@ -131,9 +131,9 @@ static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16 static int16_t get_neighbours( const EFAP_LS_TRIANGLE *triArray, const int16_t vtxIdx, const int16_t numTri, int16_t *neighbours ); #else static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const Word16 vtxIdx ); -static Word32 point_plane_distance_fx( const Word32 P1[3], const Word32 P2[3], const Word32 P3[3], const Word32 X[3] ); -static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] ); -static void efap_crossp_fx( const Word32 *v1, const Word32 *v2, Word32 *v ); +static Word32 point_plane_distance_fx( const Word32 P1[3] /*q31*/, const Word32 P2[3] /*q31*/, const Word32 P3[3] /*q31*/, const Word32 X[3] /*q31*/ ); +static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] /*q31*/ ); +static void efap_crossp_fx( const Word32 *v1 /*q30*/, const Word32 *v2 /*q30*/, Word32 *v /*q29*/ ); static Word16 find_int_in_tri_fx( const EFAP_LS_TRIANGLE *tri, const Word16 n, const Word16 r, Word16 *pos ); static void remove_vertex_fx( EFAP_VERTEX *vtxArray, const Word16 idx, const Word16 L ); static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 vtxIdx, const Word16 numTri, Word16 *neighbours ); @@ -145,7 +145,7 @@ static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TM static void tri_to_poly( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET] ); static int16_t compare_poly( int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew ); #else -static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], const Word32 *vec, const Word16 L, Word32 *out ); +static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF] /*q31*/, const Word32 *vec /*q31*/, const Word16 L, Word32 *out /*q31*/ ); static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET] ); static Word16 compare_poly_fx( Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew ); #endif @@ -160,11 +160,11 @@ static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); static void sph2cart( const float azi, const float ele, float *pos ); #else static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); -static Word32 efap_32mod32( const Word32 x, const Word32 y ); -static Word16 get_poly_num_fx( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); -static Word16 in_poly_fx( const Word32 P[2], const EFAP_POLYSET poly ); -static Word16 in_tri_fx( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); -static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); +static Word32 efap_32mod32( const Word32 x /*q22*/, const Word32 y /*q22*/ ); +static Word16 get_poly_num_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET_DATA *polyData ); +static Word16 in_poly_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET poly ); +static Word16 in_tri_fx( Word32 A[2] /*q22*/, Word32 B[2] /*q22*/, Word32 C[2] /*q22*/, Word32 P_minus_A[2] /*q22*/ ); +static void sph2cart_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, Word32 *pos /*q31*/ ); #endif /*-----------------------------------------------------------------------* @@ -245,8 +245,8 @@ ivas_error efap_init_data_fx( move16(); /* Loudspeaker configuration */ - Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); - Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); + Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); // Q22 + Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); // Q22 /* Initialization of the vertex */ vertex_init_fx( efap->aziSpk, efap->eleSpk, &efap->vtxData ); @@ -384,10 +384,10 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); // ouputs in q22 /* Panning */ - efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); + efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); // hEFAPdata->bufferLong_fx q31 IF( efap_mode == EFAP_MODE_EFAP ) { @@ -407,11 +407,11 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = ISqrt32( normBuffer, &exp ); + normBuffer = ISqrt32( normBuffer, &exp ); // Q=(31-exp) FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); + hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); // Q=(30+31-exp-31)=>(30-exp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); /* Q30 */ move32(); @@ -435,12 +435,12 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); + normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); /*Q=(15-exp)*/ FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { Word16 exp_temp = add( exp, 1 ); - hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); + hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], extract_l( normBuffer ) ) /*Q(30-exp)*/, &exp_temp ); // Q=(31-exp_temp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); /* Q30 */ move32(); @@ -683,8 +683,8 @@ static ivas_error poly_init_fx( FOR( n = 0; n < efap->vtxData.numVtx; ++n ) { test(); - if ( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || - LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) + if ( GT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( Q22_90_DEG /*90.0 Q22*/ - 4 /*1e-6 Q22*/ ) ) || + LT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( 4 /*1e-6 Q22*/ - Q22_90_DEG /*90.0 Q22*/ ) ) ) { efap->vtxData.vertexArray[n].isNaN = 1; move16(); @@ -722,35 +722,35 @@ static ivas_error poly_init_fx( maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); minimum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); - IF( GT_32( L_sub( tmpMax, tmpMin ), Q22_180_DEG ) /*180 in Q22*/ ) + IF( GT_32( L_sub( tmpMax /*q22*/, tmpMin /*q22*/ ), Q22_180_DEG /*180 in Q22*/ ) ) { FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ - efap->polyData.polysetArray[add( m, 1 )].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].polyAzi[j] = L_sub( efap->polyData.polysetArray[add( m, 1 )].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 2].polyAzi[j] = L_sub( efap->polyData.polysetArray[m + 1].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); /* Copy the rest of the fields */ - efap->polyData.polysetArray[add( m, 1 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 1].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 1 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 1].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 1].numChan = lengthTri2PolySorted[n]; move16(); - efap->polyData.polysetArray[add( m, 2 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 2].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 2].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 2].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 2].numChan = lengthTri2PolySorted[n]; move16(); } finalLength = add( finalLength, 2 ); @@ -928,7 +928,7 @@ static ivas_error sphere_triangulation_fx( *dmTranspose_fx = (Word32 **) p_dmTranspose; /* Remap Ghosts */ -remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); +remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 return IVAS_ERR_OK; } @@ -1161,9 +1161,11 @@ static void initial_polyeder_fx( } /* 1. attempt to create an edge with nonzero length */ - WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi, vtxData->vertexArray[tetrahedron[1]].azi ) && - EQ_32( vtxData->vertexArray[tetrahedron[0]].ele, vtxData->vertexArray[tetrahedron[1]].ele ) ) + test(); + WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi /*q22*/, vtxData->vertexArray[tetrahedron[1]].azi /*q22*/ ) && + EQ_32( vtxData->vertexArray[tetrahedron[0]].ele /*q22*/, vtxData->vertexArray[tetrahedron[1]].ele /*q22*/ ) ) { + test(); tetrahedron[1] = add( tetrahedron[1], 1 ); move16(); assert( tetrahedron[1] < numVtx && "EFAP: convex hull construction failed, vertices are coincident!" ); @@ -1172,16 +1174,16 @@ static void initial_polyeder_fx( /* 2. attempt to create a triangle with nonzero area */ tmp = 0; move32(); - v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); + v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); // tmp1 Q(31-1) WHILE( LT_16( tetrahedron[2], numVtx ) ) { - v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); - efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 + v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); // tmp2 Q(31-1) + efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 FOR( i = 0; i < 3; i++ ) { tmp = L_add( tmp, Mpy_32_32( tmpCross[i], tmpCross[i] ) ); // tmp Q27 } - IF( GT_32( L_abs( tmp ), Mpy_32_32( POLY_THRESH_Q29, POLY_THRESH_Q29 ) ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ + IF( GT_32( L_abs( tmp ), ( POLY_THRESH_Q29 /*1e-4f Q29*/ * POLY_THRESH_Q29 /*1e-4f Q29*/ ) >> 31 ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ { BREAK; } @@ -1197,7 +1199,7 @@ static void initial_polyeder_fx( { v_sub_fixed( vtxData->vertexArray[tetrahedron[3]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp3, 3, 1 ); // tmp3 Q30 tmp = dotp_fixed( tmp3, tmpCross, 3 ); // tmp Q28 - IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 ) ) + IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 /*1e-4f Q28*/ ) ) { BREAK; } @@ -1211,11 +1213,11 @@ static void initial_polyeder_fx( { vtxInHull[tetrahedron[i]] = 1; /* set vertex as added to hull*/ move16(); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); // Q29 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); // Q29 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); // Q29 move32(); } /* Executed below float operation @@ -1460,33 +1462,34 @@ static void add_ghost_speakers_fx( Word32 tmpAngleDiff[EFAP_MAX_SIZE_TMP_BUFF]; /* tmp array of angles differences */ Word32 sectors[EFAP_MAX_SIZE_TMP_BUFF]; /* Help us determine the zone where we should extend LS */ EFAP_VTX_DMX_TYPE vtxDmxType; + Word16 new_diff_e; vtxDmxType = EFAP_DMX_INTENSITY; move32(); numVertex = *numVtx; move16(); - maxAngle = 13421773; - move32(); //(1.f / 160.0f) in Q31 + maxAngle = 13421773; //(1.f / 160.0f) in Q31 + move32(); /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; + ele[i] = vertexArray[i].ele; // q22 move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ a = 0; move16(); - maximum_l( ele, numVertex, &tmpEle ); + maximum_l( ele, numVertex, &tmpEle ); // tmpEle q22 lengthVertGhst = 0; move16(); - IF( LT_32( tmpEle, Q22_90_DEG ) ) + IF( LT_32( tmpEle, Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( GT_32( tmpEle, Q22_45_DEG ) ) + IF( GT_32( tmpEle, Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1497,18 +1500,18 @@ static void add_ghost_speakers_fx( move32(); } } - add_vertex_fx( vertexArray, 0, Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); } /* ADD VOH IF NECESSERAY (i.e. if the elevation of the lowest LS is > -90 deg) */ - minimum_l( ele, numVertex, &tmpEle ); - IF( GT_32( tmpEle, -Q22_90_DEG ) ) + minimum_l( ele, numVertex, &tmpEle ); /*tmpEle q22*/ + IF( GT_32( tmpEle, -Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( LT_32( tmpEle, -Q22_45_DEG ) ) + IF( LT_32( tmpEle, -Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1520,7 +1523,7 @@ static void add_ghost_speakers_fx( } } - add_vertex_fx( vertexArray, 0, -Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, -Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); @@ -1532,9 +1535,9 @@ static void add_ghost_speakers_fx( FOR( i = 0; i < numVertex; ++i ) { - IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG ) ) + IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG /*45 q22*/ ) ) { - tmpAzi[k] = vertexArray[i].azi; + tmpAzi[k] = vertexArray[i].azi; // q22 move32(); k = add( k, 1 ); } @@ -1542,44 +1545,44 @@ static void add_ghost_speakers_fx( lengthHorGhst = 0; move16(); - IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ + IF( k == 0 ) /* no speakers found: add a triangle of ghost speakers */ { add_vertex_fx( vertexArray, 0, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_120_DEG, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_240_DEG, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_120_DEG /*120 q22*/, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG /*240 q22*/, 0, add( add( numVertex, a ), 2 ), EFAP_DMX_INTENSITY ); a = add( a, 3 ); lengthHorGhst = add( lengthHorGhst, 3 ); } ELSE IF( EQ_16( k, 1 ) ) /* only one speaker found: add two ghost speakers to complete a triangle */ { - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG ), 0, numVertex + a, EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG ), 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG /*120 q22*/ ), 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG /*240 q22*/ ), 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); a = add( a, 2 ); lengthHorGhst = add( lengthHorGhst, 2 ); } ELSE /* fill gaps greater than maxAngle */ { /* Here, k correspond to the number of LS whose ele is < 45 deg, should be = numVertex */ - sort_l( tmpAzi, k ); + sort_l( tmpAzi, k ); // tmpAzi q22 /* The next lines correspond to angle_diff = [azi(2:end), azi(1) + 360] - azi; in Matlab */ FOR( i = 0; i < k - 1; ++i ) { - tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); + tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); // q22 move32(); - sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); + sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); // q22 move32(); - IF( GT_32( sectors[i], Q22_1 ) ) + if ( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } } - tmpAngleDiff[sub( k, 1 )] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[sub( k, 1 )] ); + tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG /*360 q22*/ ), tmpAzi[k - 1] ); // q22 - sectors[sub( k, 1 )] = ceil_fixed( Mpy_32_32( tmpAngleDiff[sub( k, 1 )], maxAngle ), Q22 ); + sectors[k - 1] = ceil_fixed( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); // q22 - IF( GT_32( sectors[sub( k, 1 )], Q22_1 ) ) + if ( GT_32( sectors[k - 1], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1587,19 +1590,20 @@ static void add_ghost_speakers_fx( /* Adding new virtual speakers */ FOR( i = 0; i < k; ++i ) { - IF( GT_32( sectors[i], Q22_1 ) ) + IF( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { - newDiff = tmpAngleDiff[i] / sectors[i]; - num_new = (Word16) L_shr( L_sub( sectors[i], Q22_1 ), Q22 ); + newDiff = BASOP_Util_Divide3232_Scale( tmpAngleDiff[i], sectors[i], &new_diff_e ); // Q=15-new_diff_e + newDiff = L_shl( newDiff, add( new_diff_e, 7 ) ); // q22 + num_new = extract_l( L_shr( L_sub( sectors[i], Q22_1 /*1 q22*/ ), Q22 ) ); // q0 FOR( j = 0; j < num_new; ++j ) { - newAzi = L_add( tmpAzi[i], L_shl( ( j + 1 ) * newDiff, Q22 ) ); + newAzi = L_add( tmpAzi[i], imult3216( newDiff, add( j, 1 ) ) ); // q22 add_vertex_fx( vertexArray, newAzi, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); a = add( a, 1 ); - IF( j > 0 ) + if ( j > 0 ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1784,8 +1788,8 @@ static void add_vertex_to_convex_hull_fx( Word16 surface[3]; Word32 numHullVtx; Word32 centroid[3]; - const Word32 threshold = -268; - move32(); // -1e-6f in Q28 + const Word32 threshold = -268; // -1e-6f in Q28 + move32(); Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; Word16 tmp16, tmp_e; @@ -1806,30 +1810,30 @@ static void add_vertex_to_convex_hull_fx( IF( vtxInHull[i] ) { numHullVtx = L_add( numHullVtx, 1 ); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); // q27 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); // q27 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); // q27 move32(); } } /* numHullVtx = 1.0f / numHullVtx; */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); - tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); // q15-tmp_e + tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ - centroid[0] = Mpy_32_32( centroid[0], tmp32 ); + centroid[0] = Mpy_32_32( centroid[0], tmp32 ); // q27 move32(); - centroid[1] = Mpy_32_32( centroid[1], tmp32 ); + centroid[1] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[2] = Mpy_32_32( centroid[1], tmp32 ); + centroid[2] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[0] = L_shl( centroid[0], 4 ); + centroid[0] = L_shl( centroid[0], 4 ); // q31 move32(); - centroid[1] = L_shl( centroid[1], 4 ); + centroid[1] = L_shl( centroid[1], 4 ); // q31 move32(); - centroid[2] = L_shl( centroid[2], 4 ); + centroid[2] = L_shl( centroid[2], 4 ); // q31 move32(); /* Processing */ @@ -1920,13 +1924,13 @@ static void visible_edges_fx( /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; + tmpMax[i] = triArray[visible[i]].LS[0]; // q0 move16(); FOR( j = 1; j < 3; ++j ) { if ( LT_16( tmpMax[i], triArray[visible[i]].LS[j] ) ) { - tmpMax[i] = triArray[visible[i]].LS[j]; + tmpMax[i] = triArray[visible[i]].LS[j]; // q0 move16(); } } @@ -1977,7 +1981,7 @@ static void visible_edges_fx( { edges[k] = a; move16(); - edges[add( k, 1 )] = b; + edges[k + 1] = b; move16(); k = add( k, 2 ); } @@ -2117,7 +2121,7 @@ static void flip_plane( static void flip_plane_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ Word16 *surface, /* i/o: Surface/vertices to be flipped */ - const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward */ + const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward q31*/ ) { Word16 tmp; @@ -2127,7 +2131,7 @@ static void flip_plane_fx( vtxArray[surface[0]].pos, vtxArray[surface[1]].pos, vtxArray[surface[2]].pos, - centroid ); + centroid ); // q31 IF( dist > 0 ) { @@ -2319,9 +2323,10 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpDist; - const Word32 thresh = 214748; + Word16 tmpDist_e; + const Word32 thresh = 214748; // 1e-4f in Q31 Word16 tmp16, tmp_e; - move32(); // 1e-4f in Q31 + move32(); set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2333,7 +2338,7 @@ static void remap_ghosts_fx( IF( find_int_in_tri_fx( triArray, g, numTri, posFound ) == 0 ) { remove_vertex_fx( vtxArray, g, numVtx ); - --numVtx; + numVtx = sub( numVtx, 1 ); FOR( i = 0; i < numTri; ++i ) { FOR( j = 0; j < 3; ++j ) @@ -2361,9 +2366,9 @@ static void remap_ghosts_fx( set32_fx( tmpMat[i], 0, numTot ); set32_fx( tmpNewMat[i], 0, numTot ); - tmpMat[i][i] = ONE_IN_Q31; + tmpMat[i][i] = ONE_IN_Q31; // q31 move32(); - tmpNewMat[i][i] = ONE_IN_Q31; + tmpNewMat[i][i] = ONE_IN_Q31; // q31 move32(); } @@ -2382,8 +2387,8 @@ static void remap_ghosts_fx( } /* The neighbours are set to 1.0/tmpL */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); - inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); // Q=15-tmp_e + inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ FOR( j = 0; j < tmpL; ++j ) { tmpMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ @@ -2405,18 +2410,22 @@ static void remap_ghosts_fx( FOR( i = numSpk; i < numTot; ++i ) { - Copy32( tmpNewMat[i], tmpVec, numTot ); + Copy32( tmpNewMat[i], tmpVec, numTot ); // q31 - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); // Q=31-tmpDist_e - WHILE( GT_32( tmpDist, thresh ) ) + WHILE( EQ_16( BASOP_Util_Cmp_Mant32Exp( tmpDist, tmpDist_e, thresh, 0 ), 1 ) ) { - matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); - Copy32( tmpVec2, tmpVec, numTot ); + matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); // tmpVec2 Q31 + Copy32( tmpVec2, tmpVec, numTot ); // Q31 set32_fx( tmpVec2, 0, numTot ); - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); } - Copy32( tmpVec, tmpNewMat[i], numTot ); + Copy32( tmpVec, tmpNewMat[i], numTot ); // q31 } FOR( i = 0; i < numSpk; ++i ) @@ -2425,7 +2434,7 @@ static void remap_ghosts_fx( FOR( j = 0; j < numSpk; ++j ) { test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2434,9 +2443,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*q31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } } @@ -2456,7 +2465,7 @@ static void remap_ghosts_fx( case EFAP_DMX_INTENSITY: default: test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2465,9 +2474,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } BREAK; @@ -2515,8 +2524,8 @@ static void vertex_init( *-------------------------------------------------------------------------*/ static void vertex_init_fx( - const Word32 *aziSpk, /* i : Azimuths of the LS setup */ - const Word32 *eleSpk, /* i : Elevations of the LS setup */ + const Word32 *aziSpk, /* i : Azimuths of the LS setup q22 */ + const Word32 *eleSpk, /* i : Elevations of the LS setup q22 */ EFAP_VERTEX_DATA *efapVtxData /* i/o: Vertex data structure that will be updated */ ) { @@ -2606,10 +2615,10 @@ static void efap_panning( *-------------------------------------------------------------------------*/ static void efap_panning_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ const EFAP_POLYSET_DATA *polyData, /* i : Polygon data */ - Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i; @@ -2622,9 +2631,9 @@ static void efap_panning_fx( Word32 normTmpBuff; Word32 P[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); @@ -2644,32 +2653,32 @@ static void efap_panning_fx( { chan[i] = polyData->polysetArray[polyIdx].chan[i]; move16(); - aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; // q22 move32(); if ( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) { - aziPoly[i] = P[0]; + aziPoly[i] = P[0]; // q22 move32(); } - elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; // q22 move32(); } /* Computing the gain for the polygon */ - get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); + get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); + normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 Word16 exp = 0; move16(); - normTmpBuff = ISqrt32( normTmpBuff, &exp ); + normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp /* Updating the buffer structure */ FOR( i = 0; i < numChan; ++i ) { - bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); + bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); // 31+(31-exp)-31=>31-exp move32(); bufferL[chan[i]] = L_shl( bufferL[chan[i]], exp ); // Q31 move32(); @@ -2742,12 +2751,12 @@ static void get_poly_gains( *-------------------------------------------------------------------------*/ static void get_poly_gains_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ - const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons */ - const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ + const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons q22 */ + const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons q22 */ const Word16 numChan, /* i : Length of aziPoly & elePoly */ - Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i, j; @@ -2756,39 +2765,39 @@ static void get_poly_gains_fx( Word32 A[2], B[2], C[2]; Word32 P_minus_A[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); /* Processing, we search for the triangle in which belong P, then we compute the gain */ FOR( i = 1; i < numChan + 1; ++i ) { - A[0] = aziPoly[i - 1]; + A[0] = aziPoly[i - 1]; // q22 move32(); - A[1] = elePoly[i - 1]; + A[1] = elePoly[i - 1]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( j = i; j < numChan - 2 + i; ++j ) { idx1 = add( 1, ( j % numChan ) ); idx2 = add( 1, ( idx1 % numChan ) ); - B[0] = aziPoly[sub( idx1, 1 )]; + B[0] = aziPoly[idx1 - 1]; // q22 move32(); - B[1] = elePoly[sub( idx1, 1 )]; + B[1] = elePoly[idx1 - 1]; // q22 move32(); - C[0] = aziPoly[sub( idx2, 1 )]; + C[0] = aziPoly[idx2 - 1]; // q22 move32(); - C[1] = elePoly[sub( idx2, 1 )]; + C[1] = elePoly[idx2 - 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { - buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q12 ); + buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q18 ); // q13+q18->q31 move32(); BREAK; } @@ -2847,10 +2856,10 @@ static float get_tri_gain( *-------------------------------------------------------------------------*/ static Word32 get_tri_gain_fx( - const Word32 A[2], /* i : Coordinate of one apex of the triangle */ - const Word32 B[2], /* i : Coordinate of one apex of the triangle */ - const Word32 C[2], /* i : Coordinate of one apex of the triangle */ - const Word32 P_minus_A[2] /* i : Value of (P - A) */ + const Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 P_minus_A[2] /* i : Value of (P - A) q22 */ ) { Word32 N[2], tmpN[2]; @@ -2859,32 +2868,38 @@ static Word32 get_tri_gain_fx( Word32 gain; /* Processing */ - tmpN[0] = L_sub( B[1], C[1] ); + tmpN[0] = L_sub( B[1], C[1] ); // q22 move32(); - tmpN[1] = L_sub( C[0], B[0] ); + tmpN[1] = L_sub( C[0], B[0] ); // q22 move32(); - v_sub_fixed( B, A, tmpSub1, 2, 0 ); + v_sub_fixed( B, A, tmpSub1, 2, 0 ); // tmpSub1 q22 tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; + Word16 exp = Q18; move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); exp = sub( exp, norm_l( tmpDot1 ) ); - Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); - v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); + Word16 inv_tmpDot1 = Inv16( extract_h( inv_tmpDot2 ), &exp ); // 15-exp + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); // 22+31-31->22 - tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 + tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // 22+22-31->13 - gain = L_sub( 0x00040000, tmpDot2 ); + if ( EQ_32( tmpDot2, 8191 ) ) + { + tmpDot2 = 8192; // Q13 + move32(); + } + + gain = L_sub( 8192, tmpDot2 ); // Q13 /* Set gains <= -60dB to 0 to avoid problems in SVD */ - if ( LT_32( L_abs( gain ), 1 ) ) + if ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( gain ), 18, 2147 /*1e-6 q31*/, 0 ), -1 ) ) { gain = 0; move32(); } - return gain; // Q18 + return gain; // Q13 } #endif @@ -2964,32 +2979,39 @@ static void add_vertex_fx( /* Updating the vertex array */ - tmp = efap_32mod32( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); - vtxArray[pos].azi = L_sub( Q22_180_DEG, tmp ); + tmp = efap_32mod32( L_sub( Q22_180_DEG /*180 q22*/, azi ), Q22_360_DEG /*360 q22*/ ); // q22 + vtxArray[pos].azi = L_sub( Q22_180_DEG /*180 q22*/, tmp ); // q22 move32(); - tmp = ( LT_32( Q22_180_DEG, ele ) ? Q22_180_DEG : ele ); + IF( LT_32( Q22_180_DEG /*180 q22*/, ele ) ) + tmp = Q22_180_DEG /*180 q22*/; + ELSE + tmp = ele; // Q22 move32(); - vtxArray[pos].ele = ( GT_32( -Q22_180_DEG, tmp ) ? -Q22_180_DEG : tmp ); + IF( GT_32( -Q22_180_DEG /*180 q22*/, tmp ) ) + vtxArray[pos].ele = -Q22_180_DEG /*180 q22*/; + ELSE + vtxArray[pos] + .ele = tmp; // q22 move32(); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ - sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); + sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); // vtxArray[pos].pos[0] q31 /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ /* IdxAziTmp */ - tmp = L_abs( L_sub( Q22_90_DEG, L_abs( vtxArray[pos].azi ) ) ); // Q22 - idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); + tmp = L_abs( L_sub( Q22_90_DEG /*90 q22*/, L_abs( vtxArray[pos].azi ) ) ); // Q22 + idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); // q22-q22->q0 /* IdxEleTmp */ - tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; + tmp = L_abs( vtxArray[pos].ele ); // q22 + idxEleTmp = tmp; // q22 move16(); - idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); + idxEleTmp = L_sub( Q22_90_DEG /*90 q22*/, idxEleTmp ); // q22 /* Final Idx */ - vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); + vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); // q0 /* Setting the nan flag to 0 */ vtxArray[pos].isNaN = 0; @@ -3033,8 +3055,10 @@ static void efap_sort_s_fx( move16(); tempi = idx[i]; move16(); + test(); FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { + test(); x[j - 1] = x[j]; move16(); idx[j - 1] = idx[j]; @@ -3122,18 +3146,18 @@ static Word32 vertex_distance_fx( /* Assigning the coordinates to the vector */ FOR( i = 0; i < 3; ++i ) { - A[i] = vtxArray[tri.LS[0]].pos[i]; + A[i] = vtxArray[tri.LS[0]].pos[i]; // q31 move32(); - B[i] = vtxArray[tri.LS[1]].pos[i]; + B[i] = vtxArray[tri.LS[1]].pos[i]; // q31 move32(); - C[i] = vtxArray[tri.LS[2]].pos[i]; + C[i] = vtxArray[tri.LS[2]].pos[i]; // q31 move32(); - P[i] = vtxArray[vtxIdx].pos[i]; + P[i] = vtxArray[vtxIdx].pos[i]; // q31 move32(); } - return point_plane_distance_fx( A, B, C, P ); + return point_plane_distance_fx( A, B, C, P ); // q28 } #endif @@ -3166,16 +3190,16 @@ static float point_poly_distance( static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ - const Word32 X[3] /* i : Cartesian coordinates of the point of interest */ + const Word32 X[3] /* i : Cartesian coordinates of the point of interest q31*/ ) { Word32 P1[3], P2[3], P3[3]; - sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); - sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); - sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); + sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); // P1[0] q31 + sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); // P2[0] q31 + sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); // P3[0] q31 - return point_plane_distance_fx( P1, P2, P3, X ); + return point_plane_distance_fx( P1, P2, P3, X ); // q28 } #endif @@ -3232,10 +3256,10 @@ static float point_plane_distance( *-------------------------------------------------------------------------*/ static Word32 point_plane_distance_fx( // returns output in Q28 - const Word32 P1[3], /* i : First point of the triangle that defines the planes */ - const Word32 P2[3], /* i : Second point of the triangle */ - const Word32 P3[3], /* i : Third point of the triangle */ - const Word32 X[3] /* i : The point of interest */ + const Word32 P1[3], /* i : First point of the triangle that defines the planes q31*/ + const Word32 P2[3], /* i : Second point of the triangle q31*/ + const Word32 P3[3], /* i : Third point of the triangle q31*/ + const Word32 X[3] /* i : The point of interest q31*/ ) { Word32 tmpCross1[3], tmpCross2[3]; @@ -3261,8 +3285,8 @@ static Word32 point_plane_distance_fx( // returns output in Q28 } /* Cross Product */ - v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); - v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); + v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); // tmpCross1 q30 + v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); // tmpCross2 q30 /* resultCross = cross(P1-P2,P1-P3) */ efap_crossp_fx( tmpCross1, tmpCross2, resultCross ); // Q29 @@ -3616,10 +3640,10 @@ static void matrix_times_row( *-------------------------------------------------------------------------*/ static void matrix_times_row_fx( - Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix */ - const Word32 *vec, /* i : The input row vector */ + Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix q31 */ + const Word32 *vec, /* i : The input row vector q31*/ const Word16 L, /* i : Row length */ - Word32 *out /* o : Output vector */ + Word32 *out /* o : Output vector q31 */ ) { Word16 i, j; @@ -3628,7 +3652,7 @@ static void matrix_times_row_fx( { FOR( j = 0; j < L; ++j ) { - out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); + out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); /*31+31-31=>31*/ move32(); } } @@ -3684,7 +3708,7 @@ static void tri_to_poly_fx( vtxArray[triArray[i].LS[2]].pos, vtxArray[j].pos ) ); // Q28 - IF( LT_32( dist, 268435 ) /* 1e-3f in Q28 */ ) + IF( LT_32( dist, 268435 /* 1e-3f in Q28 */ ) ) { assert( lenPoly < EFAP_MAX_CHAN_NUM && "EFAP: exceeded max polygon vertices!" ); poly[lenPoly] = j; @@ -4068,7 +4092,7 @@ static void sort_channels_vertex_fx( v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 Word16 exp1 = 2; move16(); - normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); + normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ) /*q29*/, &exp1 ); /*q=31-exp1*/ // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -4078,21 +4102,21 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; i++ ) { - tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); + tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); // q30 move32(); } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 Word16 exp2 = 2; move16(); - normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); + normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ) /*q29*/, &exp2 ); // q=31-exp2 v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 /* Center of the first Triangle */ FOR( i = 0; i < 3; ++i ) { - MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); + MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); // q29+2=>q31 move32(); } @@ -4101,7 +4125,7 @@ static void sort_channels_vertex_fx( { FOR( j = 0; j < 3; ++j ) { - tmpP[j] = vtxArray[channels[i]].pos[j]; + tmpP[j] = vtxArray[channels[i]].pos[j]; // q31 move32(); } @@ -4156,19 +4180,19 @@ static float efap_fmodf( *-------------------------------------------------------------------------*/ static Word32 efap_32mod32( - const Word32 x, /* i : Dividend */ - const Word32 y /* i : Divisor */ + const Word32 x, /* i : Dividend q22*/ + const Word32 y /* i : Divisor q22 */ ) { - Word32 result = x % y; + Word32 result = x % y; // q22 move32(); IF( result >= 0 ) { - return result; + return result; // q22 } ELSE { - return L_add( result, y ); + return L_add( result, y ); // q22 } } #endif @@ -4238,7 +4262,7 @@ static int16_t get_poly_num( } #else static Word16 get_poly_num_fx( - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ ) { @@ -4253,7 +4277,7 @@ static Word16 get_poly_num_fx( num_poly = 0; move16(); - sph2cart_fx( P[0], P[1], &pos[0] ); + sph2cart_fx( P[0], P[1], &pos[0] ); // pos[0] q31 /* Filter the polygon list with a fast 2d check */ FOR( i = 0; i < polyData->numPoly; ++i ) @@ -4261,7 +4285,7 @@ static Word16 get_poly_num_fx( IF( in_poly_fx( P, polyData->polysetArray[i] ) ) { /* select only polygons which are visible from the point */ - dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); + dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); // q28 IF( dist_tmp == 0 ) { return i; @@ -4270,7 +4294,7 @@ static Word16 get_poly_num_fx( { poly_tmp[num_poly] = i; move16(); - poly_dist[num_poly] = dist_tmp; + poly_dist[num_poly] = dist_tmp; // q28 move32(); num_poly = add( num_poly, 1 ); } @@ -4284,7 +4308,7 @@ static Word16 get_poly_num_fx( /* select the polygon with the smallest distance */ found_poly = poly_tmp[0]; move16(); - dist_tmp = poly_dist[0]; + dist_tmp = poly_dist[0]; // q28 move32(); FOR( i = 1; i < num_poly; i++ ) { @@ -4292,7 +4316,7 @@ static Word16 get_poly_num_fx( { found_poly = poly_tmp[i]; move16(); - dist_tmp = poly_dist[i]; + dist_tmp = poly_dist[i]; // q28 move32(); } } @@ -4374,7 +4398,7 @@ static int16_t in_poly( } #else static Word16 in_poly_fx( /* Angles are in Q22 */ - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET poly /* i : Polyset struct */ ) { @@ -4397,45 +4421,45 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; + A[0] = P[0]; // q22 move32(); } ELSE { - A[0] = poly.polyAzi[0]; + A[0] = poly.polyAzi[0]; // q22 move32(); } - A[1] = poly.polyEle[0]; + A[1] = poly.polyEle[0]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( n = 1; n < sub( numVertices, 1 ); ++n ) { IF( poly.isNaN[n] ) { - B[0] = P[0]; + B[0] = P[0]; // q22 move32(); } ELSE { - B[0] = poly.polyAzi[n]; + B[0] = poly.polyAzi[n]; // q22 move32(); } - B[1] = poly.polyEle[n]; + B[1] = poly.polyEle[n]; // q22 move32(); IF( poly.isNaN[n + 1] ) { - C[0] = P[0]; + C[0] = P[0]; // q22 move32(); } ELSE { - C[0] = poly.polyAzi[n + 1]; + C[0] = poly.polyAzi[n + 1]; // q22 move32(); } - C[1] = poly.polyEle[n + 1]; + C[1] = poly.polyEle[n + 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) @@ -4509,10 +4533,10 @@ static int16_t in_tri( } #else static Word16 in_tri_fx( - Word32 A[2], /* i : Coordinate of one apex of the triangle */ - Word32 B[2], /* i : Coordinate of one apex of the triangle */ - Word32 C[2], /* i : Coordinate of one apex of the triangle */ - Word32 P_minus_A[2] /* i : Value of (P - A) */ + Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 P_minus_A[2] /* i : Value of (P - A) q22*/ ) { Word32 tmpDot1[2], tmpDot2[2]; @@ -4521,7 +4545,7 @@ static Word16 in_tri_fx( Word16 tmp16, tmp_e; Word64 S[2]; /* Threshold adjusted */ - Word64 thresh_int = 21475; // 1e-6f in Q32 + Word64 thresh_int = 4295; // 1e-6f in Q32 move64(); /* @@ -4531,11 +4555,11 @@ static Word16 in_tri_fx( I'll just compute the determinant and if it's equal to 0, that means the two vectors are colinear */ - v_sub_fixed( B, A, tmpDot1, 2, 0 ); - v_sub_fixed( C, A, tmpDot2, 2, 0 ); + v_sub_fixed( B, A, tmpDot1, 2, 0 ); // tmpDot1 q22 + v_sub_fixed( C, A, tmpDot2, 2, 0 ); // tmpDot 2q22 /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ - invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); /*q22+q22-q31->q13*/ IF( invFactor == 0 ) { @@ -4543,20 +4567,20 @@ static Word16 in_tri_fx( } /* invFactor = 1.f / invFactor; */ - tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); - invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); /*15-tmp_e*/ + invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); - invFactor = L_shl( invFactor, invFactor_exp ); + invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp // Q22 = Q22 * Q31 - matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); // q=22+invFactor_exp move32(); - matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); // q=22+invFactor_exp move32(); /* Computing S (Q13 + matInv_exp_final[i] + P_minus_A_exp_final + invFactor_exp - 1 ) = @@ -4588,35 +4612,37 @@ static Word16 in_tri_fx( P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[0]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); S[1] = L_add( L_shr( Mpy_32_32( L_shl( matInv[1][0], matInv_exp_final[1] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[1]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ // Q32 S IF( sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } IF( sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } + test(); + test(); IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( W_add( S[0], S[1] ), W_add( W_shl( 1, 32 ), thresh_int ) ) ) { return 0; -- GitLab