diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f9b6183739b7e2caab5aed74f56df5d7f09d82b3..ccca93784a001c3c9d164659c790dfdd3f772164 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -2843,6 +2843,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 10; hs->da = 10; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2857,6 +2859,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 40; hs->da = -20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2884,6 +2888,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 20; hs->da = 20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2898,6 +2904,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 80; hs->da = -40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2932,6 +2940,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 20; hs->da = 20; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2946,6 +2956,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 80; hs->da = -40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -2979,6 +2991,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 30; hs->da = 30; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -2991,6 +3005,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 120; hs->da = -60; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -3018,6 +3034,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 32; hs->da = 32; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -3032,6 +3050,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 160; hs->da = -80; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; @@ -3065,6 +3085,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 40; hs->da = 40; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = NULL; hs->rot_vec_ana_delay_im_fx = NULL; hs->rot_vec_syn_delay_re_fx = NULL; @@ -3079,6 +3101,8 @@ static void cldfb_init_proto_and_twiddles_enc_fx( { hs->ds = 160; hs->da = -80; + move16(); + move16(); hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 37a10990b0e070daaec3a30949736145ef61869b..d81159ddee920f9eb9424aa99a20d290a6ed6382 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -50,9 +50,9 @@ /*------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ); - +#endif static void getmidbands( int16_t *part, const int16_t npart, int16_t *midband, float *psize_flt, float *psize_inv_flt ); @@ -85,11 +85,12 @@ ivas_error createFdCngCom_flt( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const float scale ) { + /* Calculate FFT scaling factor */ hFdCngCom->scalingFactor_flt = 1 / ( scale * scale * 8.f ); @@ -100,28 +101,20 @@ void initFdCngCom_flt( /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); - set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); + set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); /* Initialize quantizer */ set_f( hFdCngCom->sidNoiseEst_flt, 0.0f, NPART ); set_f( hFdCngCom->A_cng_flt, 0.0f, M + 1 ); hFdCngCom->A_cng_flt[0] = 1.f; -#ifdef IVAS_FLOAT_FIXED - set16_fx( hFdCngCom->A_cng, 0, M + 1 ); - hFdCngCom->A_cng[0] = MAX_16; -#endif /* Set some counters and flags */ hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ hFdCngCom->active_frame_counter = 0; hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; -#ifndef IVAS_FLOAT_FIXED hFdCngCom->likelihood_noisy_speech_flt = 0.f; -#else - hFdCngCom->likelihood_noisy_speech = 0; -#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; @@ -136,33 +129,24 @@ void initFdCngCom_flt( set_f( hFdCngCom->periodog_flt, 0.0f, PERIODOGLEN ); mhvals_flt( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win_flt ) ); mhvals_flt( MSSUBFRLEN, &( hFdCngCom->msM_subwin_flt ) ); - set_f( hFdCngCom->msPeriodogSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msPsdSum_flt, 0.0f, 2 ); -#ifndef IVAS_FLOAT_FIXED + set_f( hFdCngCom->msPeriodogSum_flt, 0.0f, 2 ); set_f( hFdCngCom->msSlope_flt, 0.0f, 2 ); set_f( hFdCngCom->msQeqInvAv_flt, 0.0f, 2 ); -#else - set16_fx( hFdCngCom->msSlope, 0, 2 ); - set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); -#endif hFdCngCom->init_old_flt = 0; + hFdCngCom->msFrCnt_init_counter = 0; hFdCngCom->msFrCnt_init_thresh = 1; hFdCngCom->offsetflag = 0; hFdCngCom->msFrCnt = MSSUBFRLEN; hFdCngCom->msMinBufferPtr = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngCom->msAlphaCor_flt, 0.3f, 2 ); hFdCngCom->coherence_flt = 0.5f; -#else - set32_fx( hFdCngCom->msAlphaCor, 644245120l /*0.3f Q31*/, 2 ); - - hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ -#endif return; } +#endif /*------------------------------------------------------------------- @@ -1238,7 +1222,7 @@ void SynthesisSTFT_dirac_fx( * * Compute some values used in the bias correction of the minimum statistics algorithm *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ) @@ -1278,6 +1262,7 @@ static void mhvals_flt( return; } +#endif /*------------------------------------------------------------------- * rand_gauss_flt() diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 5ce39824715e87b581e27a607693d7a4f8da1d4e..d849735112f779539e576b03b37964324290ae39 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -60,8 +60,8 @@ static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_o void hq_swb_harmonic_calc_norm_envelop_fx( const Word32 *L_SWB_signal, /* i : input signal Q=12*/ Word32 *L_envelope, /* o : output envelope Q=12*/ - const Word16 L_swb_norm, /* i : length of normaliztion */ - const Word16 SWB_flength /* i : length of input signal */ + const Word16 L_swb_norm, /* i : length of normaliztion Q0*/ + const Word16 SWB_flength /* i : length of input signal Q0*/ ) { @@ -73,7 +73,7 @@ void hq_swb_harmonic_calc_norm_envelop_fx( Word16 i; Word32 L_tmp; - lookback = shr( L_swb_norm, 1 ); + lookback = shr( L_swb_norm, 1 ); /*Q0*/ env_index = 0; move16(); FOR( n_freq = 0; n_freq < lookback; n_freq++ ) @@ -86,9 +86,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[n_lag] ); + L_tmp = L_abs( L_SWB_signal[n_lag] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -97,7 +97,7 @@ void hq_swb_harmonic_calc_norm_envelop_fx( env_index = add( env_index, 1 ); } - n_lag_now = L_swb_norm; + n_lag_now = L_swb_norm; /*Q0*/ move16(); FOR( n_freq = 0; n_freq < SWB_flength - L_swb_norm; n_freq++ ) @@ -107,9 +107,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( move16(); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); + L_tmp = L_abs( L_SWB_signal[( n_freq + n_lag )] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -129,9 +129,9 @@ void hq_swb_harmonic_calc_norm_envelop_fx( move32(); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_abs( L_SWB_signal[add( n_freq, n_lag )] ); + L_tmp = L_abs( L_SWB_signal[( n_freq + n_lag )] ); /*Q12*/ #ifdef BASOP_NOGLOB - L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); + L_envelope[env_index] = L_add_sat( L_envelope[env_index], L_tmp ); /*Q12*/ #else L_envelope[env_index] = L_add( L_envelope[env_index], L_tmp ); #endif @@ -152,10 +152,10 @@ void hq_swb_harmonic_calc_norm_envelop_fx( *--------------------------------------------------------------------------*/ void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ + const Word16 *wnorm, /* i : reordered norm of sub-vectors Q0*/ + Word16 *limit, /* o : highest band of bit allocation Q0*/ + const Word32 core_brate, /* i : bit rate Q0*/ + Word16 *noise_level /* o : noise level Q15*/ ) { Word16 ener_limit, ener_sum; @@ -164,7 +164,7 @@ void limit_band_noise_level_calc_fx( Word32 fact; Word16 tmp; - nb_sfm = *limit; + nb_sfm = *limit; /*Q0*/ move16(); ener_limit = 0; move16(); @@ -172,37 +172,37 @@ void limit_band_noise_level_calc_fx( move16(); FOR( i = 0; i < 10; i++ ) { - ener_limit = add( ener_limit, wnorm[i] ); - *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + ener_limit = add( ener_limit, wnorm[i] ); /*Q0*/ + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); /*Q15*/ move16(); } - ener_sum = ener_limit; + ener_sum = ener_limit; /*Q0*/ move16(); tmp = sub( nb_sfm, 1 ); FOR( i = 10; i < tmp; i++ ) { - ener_sum = add( ener_sum, wnorm[i] ); - *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); + ener_sum = add( ener_sum, wnorm[i] ); /*Q0*/ + *noise_level = add( *noise_level, abs_s( sub( wnorm[i + 1], wnorm[i] ) ) ); /*Q15*/ move16(); } - ener_sum = add( ener_sum, wnorm[nb_sfm - 1] ); + ener_sum = add( ener_sum, wnorm[nb_sfm - 1] ); /*Q0*/ - fact = 2022929597; + fact = 2022929597; /*Q31*/ move32(); if ( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - fact = L_add( 1900523029, 1 ); + fact = L_add( 1900523029, 1 ); /*Q31*/ } - fact = Mult_32_16( fact, ener_sum ); + fact = Mult_32_16( fact, ener_sum ); /*Q16*/ i = 9; move16(); test(); WHILE( LT_32( L_deposit_h( ener_limit ), fact ) && LT_16( add( i, 1 ), nb_sfm ) ) { - ener_limit = add( ener_limit, wnorm[++i] ); + ener_limit = add( ener_limit, wnorm[++i] ); /*Q0*/ test(); } *limit = i; @@ -224,11 +224,11 @@ void limit_band_noise_level_calc_fx( { IF( ener_sum != 0 ) { - *noise_level = sub( 8192, div_s( *noise_level, ener_sum ) ); + *noise_level = sub( 8192 /*Q15*/, div_s( *noise_level, ener_sum ) ); } ELSE { - *noise_level = 8192; + *noise_level = 8192; /*Q15*/ } move16(); } @@ -273,7 +273,7 @@ Word16 build_nf_codebook_fx( /* o : Number of coe IF( flag_32K_env_ho ) { /* Build compressed (+/- 1) noise-fill codebook */ - sfm_base = sfm_start[sfm]; + sfm_base = sfm_start[sfm]; /*Q0*/ move16(); FOR( i = 0; i < sfmsize[sfm] / 8; i++ ) { @@ -283,14 +283,14 @@ Word16 build_nf_codebook_fx( /* o : Number of coe { IF( coeff[j] > 0 ) { - CodeBook_mod[cb_size] = 1 << 12; - move16(); /* set to 1, Q value 12 */ + CodeBook_mod[cb_size] = 1 << 12; /*Q12*/ + move16(); E_cb_vec = add( E_cb_vec, 1 ); } ELSE IF( coeff[j] < 0 ) { - CodeBook_mod[cb_size] = -1 * ( 1 << 12 ); - move16(); /* set to -1, Q value 12 */ + CodeBook_mod[cb_size] = -1 * ( 1 << 12 ); /*Q12*/ + move16(); E_cb_vec = add( E_cb_vec, 1 ); } ELSE @@ -311,7 +311,7 @@ Word16 build_nf_codebook_fx( /* o : Number of coe { FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { - CodeBook[cb_size] = coeff[j]; + CodeBook[cb_size] = coeff[j]; /*Q12*/ move16(); cb_size = add( cb_size, 1 ); } @@ -326,29 +326,29 @@ Word16 build_nf_codebook_fx( /* o : Number of coe IF( CodeBook_mod[j] != 0 ) { /* Densify codebook */ - CodeBook[j] = -4096; - move16(); /* -1 in Q12 */ + CodeBook[j] = -4096; /*Q12*/ + move16(); if ( CodeBook_mod[j] > 0 ) { - CodeBook[j] = 4096; - move16(); /* 1 in Q12 */ + CodeBook[j] = 4096; /*Q12*/ + move16(); } IF( CodeBook_mod[cb_size - j - 1] != 0 ) { - CodeBook[j] = shl( CodeBook[j], 1 ); - move16(); /* Mult by 2 */ + CodeBook[j] = shl( CodeBook[j], 1 ); /*Q12*/ + move16(); /* Mult by 2 */ } } ELSE { - CodeBook[j] = CodeBook_mod[cb_size - j - 1]; + CodeBook[j] = CodeBook_mod[cb_size - j - 1]; /*Q12*/ move16(); } } } - return cb_size; + return cb_size; /*Q0*/ } @@ -359,25 +359,25 @@ Word16 build_nf_codebook_fx( /* o : Number of coe *--------------------------------------------------------------------------*/ Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ + const Word16 *bitalloc, /* i : bit allocation Q0*/ + const Word16 nb_sfm /* i : number of possibly coded bands Q0*/ ) { Word16 sfm, core_sfm; - core_sfm = sub( nb_sfm, 1 ); + core_sfm = sub( nb_sfm, 1 ); /*Q0*/ FOR( sfm = nb_sfm - 1; sfm >= 0; sfm-- ) { IF( bitalloc[sfm] != 0 ) { - core_sfm = sfm; + core_sfm = sfm; /*Q0*/ move16(); BREAK; } } - return core_sfm; + return core_sfm; /*Q0*/ } /*--------------------------------------------------------------------------* @@ -429,7 +429,7 @@ void apply_noisefill_HQ_fx( { FOR( i = 0; i < sfmsize[sfm]; i++ ) { - cb_buff[i] = CodeBook_mod[cb_pos++]; + cb_buff[i] = CodeBook_mod[cb_pos++]; /*Q12*/ move16(); L_E_cb_vec = L_mac0_sat( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ @@ -444,7 +444,7 @@ void apply_noisefill_HQ_fx( { FOR( i = 0; i < sfmsize[sfm]; i++ ) { - cb_buff[i] = CodeBook[cb_pos++]; + cb_buff[i] = CodeBook[cb_pos++]; /*Q12*/ move16(); L_E_cb_vec = L_mac0_sat( L_E_cb_vec, cb_buff[i], cb_buff[i] ); /*Q24 (12+12) */ @@ -464,7 +464,7 @@ void apply_noisefill_HQ_fx( L_E_corr = Isqrt( L_E_corr ); /*Q19 (31-24/2) */ E_corr = extract_h( L_shl( L_E_corr, 10 ) ); /*Q13 (13-(19-16)) */ - istart = sfm_start[sfm]; + istart = sfm_start[sfm]; /*Q0*/ move16(); FOR( j = istart; j < sfm_end[sfm]; j++ ) { @@ -477,7 +477,7 @@ void apply_noisefill_HQ_fx( { FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { - coeff[j] = CodeBook[cb_pos++]; + coeff[j] = CodeBook[cb_pos++]; /*Q12*/ move16(); if ( GE_16( cb_pos, cb_size ) ) { @@ -500,17 +500,17 @@ void apply_noisefill_HQ_fx( *--------------------------------------------------------------------------*/ void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *coeff_fine /* o : BWE fine structure */ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 high_sfm, /* i : higher transition band to BWE Q0*/ + const Word16 num_sfm, /* i : total number of bands Q0*/ + const Word16 *norm, /* i : quantization indices for norms Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ + Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum Q12*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + Word16 *coeff_fine /* o : BWE fine structure Q15*/ ) { Word16 sfm; @@ -530,7 +530,7 @@ void harm_bwe_fine_fx( { IF( R[sfm] != 0 ) { - normq = dicn_fx[norm[sfm]]; + normq = dicn_fx[norm[sfm]]; /*Q14*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) @@ -543,14 +543,14 @@ void harm_bwe_fine_fx( { FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_deposit_l( 0 ); + coeff_out[i] = L_deposit_l( 0 ); /*Q12*/ move16(); } } } /* excitation replication */ - Copy32( coeff_out, L_signal, L_HARMONIC_EXC ); + Copy32( coeff_out, L_signal, L_HARMONIC_EXC ); /*Q12*/ calc_normal_length_fx_32( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm ); hq_swb_harmonic_calc_norm_envelop_fx( L_signal, envelope, norm_width, L_HARMONIC_EXC ); @@ -560,10 +560,10 @@ void harm_bwe_fine_fx( IF( L_signal[i] > 0 ) { norm_signal = norm_l( envelope[i] ); - enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); - L_signal[i] = Div_32( L_signal[i], enve_hi[i], enve_lo[i] ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); /*Q12+norm_signal-16*/ + L_signal[i] = Div_32( L_signal[i], enve_hi[i], enve_lo[i] ); /*Q31 - norm_signal*/ #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); /*Q15*/ #else SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif @@ -574,10 +574,10 @@ void harm_bwe_fine_fx( ELSE { norm_signal = norm_l( envelope[i] ); - enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); - L_signal[i] = L_negate( Div_32( L_negate( L_signal[i] ), enve_hi[i], enve_lo[i] ) ); + enve_lo[i] = L_Extract_lc( L_shl( envelope[i], norm_signal ), &enve_hi[i] ); /*Q12+norm_signal-16*/ + L_signal[i] = L_negate( Div_32( L_negate( L_signal[i] ), enve_hi[i], enve_lo[i] ) ); /*Q31 - norm_signal*/ #ifdef BASOP_NOGLOB - SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); + SWB_signal[i] = round_fx_sat( L_shl_sat( L_signal[i], norm_signal ) ); /*Q15*/ #else SWB_signal[i] = round_fx( L_shl( L_signal[i], norm_signal ) ); #endif @@ -587,16 +587,16 @@ void harm_bwe_fine_fx( } } - dst = coeff_fine + sfm_end[last_sfm]; - end = coeff_fine + sfm_end[num_sfm - 1]; + dst = coeff_fine + sfm_end[last_sfm]; /*Q15*/ + end = coeff_fine + sfm_end[num_sfm - 1]; /*Q15*/ IF( LE_16( sub( sfm_end[last_sfm], sfm_end[high_sfm] ), ( L_HARMONIC_EXC - START_EXC ) ) ) { - src = SWB_signal + START_EXC + sub( sfm_end[last_sfm], sfm_end[high_sfm] ); + src = SWB_signal + START_EXC + sub( sfm_end[last_sfm], sfm_end[high_sfm] ); /*Q15*/ } ELSE { - src = SWB_signal + L_HARMONIC_EXC - 1; + src = SWB_signal + L_HARMONIC_EXC - 1; /*Q15*/ } WHILE( dst < end ) @@ -604,7 +604,7 @@ void harm_bwe_fine_fx( logic32(); WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) { - *dst++ = *src++; + *dst++ = *src++; /*Q15*/ move16(); } src--; @@ -612,7 +612,7 @@ void harm_bwe_fine_fx( logic32(); WHILE( dst < end && src >= &SWB_signal[START_EXC] ) { - *dst++ = *src--; + *dst++ = *src--; /*Q15*/ move16(); } src++; @@ -676,17 +676,17 @@ void hvq_bwe_fine_fx( tmp = div_s( 1 << 14, tmp ); /* 15+14-(-4+s)=Q(33-s) */ Mpy_32_16_ss( L_coeff[i], tmp, &L_tmp, &lsb ); /* 12+33-s+1-16=Q(30-s) */ shift2 = add( shift, 1 ); - tmp = round_fx( L_shl( L_tmp, shift2 ) ); /* 30-s+s+1-16=Q(15) */ - SWB_signal[i] = add( tmp, extract_l( L_shr( lsb, sub( 32, shift2 ) ) ) ); - move16(); /* Q15 */ - /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ + tmp = round_fx( L_shl( L_tmp, shift2 ) ); /* 30-s+s+1-16=Q(15) */ + SWB_signal[i] = add( tmp, extract_l( L_shr( lsb, sub( 32, shift2 ) ) ) ); /* Q15 */ + move16(); + /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ } - dst = coeff_fine; - end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; + dst = coeff_fine; /*Q15*/ + end = coeff_fine + sfm_end[num_sfm - 1] - sfm_end[last_sfm]; /*Q15*/ - src = SWB_signal + START_EXC; - peak_src = peak_pos + START_EXC; + src = SWB_signal + START_EXC; /*Q15*/ + peak_src = peak_pos + START_EXC; /*Q0*/ FOR( i = 0; i < Npeaks; i++ ) { @@ -718,29 +718,29 @@ void hvq_bwe_fine_fx( move16(); } - peak_dst = bwe_peaks + sfm_end[last_sfm]; + peak_dst = bwe_peaks + sfm_end[last_sfm]; /*Q0*/ WHILE( dst < end ) { test(); WHILE( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) { - *dst++ = *src++; + *dst++ = *src++; /*Q15*/ move16(); - *peak_dst++ = *peak_src++; + *peak_dst++ = *peak_src++; /*Q0*/ move16(); } - peak_src--; + peak_src--; /*Q0*/ src--; test(); WHILE( dst < end && src >= &SWB_signal[START_EXC] ) { - *dst++ = *src--; + *dst++ = *src--; /*Q15*/ move16(); - *peak_dst++ = *peak_src--; + *peak_dst++ = *peak_src--; /*Q0*/ move16(); } - peak_src++; + peak_src++; /*Q0*/ src++; } @@ -764,27 +764,30 @@ void hq_fold_bwe_fx( Word16 first_coeff; Word16 *src, *dst, *end; - low_coeff = shr( sfm_end[last_sfm], 1 ); - src = coeff + sfm_end[last_sfm] - 1; + low_coeff = shr( sfm_end[last_sfm], 1 ); /*Q0*/ + src = coeff + sfm_end[last_sfm] - 1; /*Q12*/ - first_coeff = sfm_end[last_sfm]; + first_coeff = sfm_end[last_sfm]; /*Q0*/ move16(); - dst = coeff + sfm_end[last_sfm]; - end = coeff + sfm_end[num_sfm - 1]; + dst = coeff + sfm_end[last_sfm]; /*Q12*/ + end = coeff + sfm_end[num_sfm - 1]; /*Q12*/ WHILE( dst < end ) { + test(); WHILE( dst < end && src >= &coeff[low_coeff] ) { - *dst++ = *src--; + test(); + *dst++ = *src--; /*Q12*/ move16(); } src++; - + test(); WHILE( dst < end && src < &coeff[first_coeff] ) { - *dst++ = *src++; + test(); + *dst++ = *src++; /*Q12*/ move16(); } } @@ -816,7 +819,7 @@ void apply_nf_gain_fx( FOR( j = sfm_start[sfm]; j < sfm_end[sfm]; j++ ) { /* Scale NoiseFill */ - coeff[j] = shr( coeff[j], nf_idx ); + coeff[j] = shr( coeff[j], nf_idx ); /*Q12*/ move16(); } } @@ -834,20 +837,20 @@ void apply_nf_gain_fx( #ifdef IVAS_FLOAT_FIXED void ivas_harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ + const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_hq_mode, /* i : previous hq mode Q0*/ + Word16 *norm, /* i/o: quantization indices for norms Q0*/ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15*/ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, j; @@ -871,35 +874,35 @@ void ivas_harm_bwe_fx( FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); - move32(); /*12 Q(14 +12+1-16 +1) */ + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*Q12*/ + move32(); } } } - noise_level[1] = noise_level[0]; + noise_level[1] = noise_level[0]; /*Q15*/ move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ - L_tmp = L_mult( 29491, prev_noise_level[0] ); /* 15 +1 +15 */ - noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[0] ); /* 15 +1 +15 */ + noise_level[0] = round_fx( L_mac( L_tmp, 3277 /*0.1 in Q15*/, noise_level[0] ) ); /*15 */ move16(); - L_tmp = L_mult( 29491, prev_noise_level[1] ); - noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[1] ); /*Q31*/ + noise_level[1] = round_fx( L_mac( L_tmp, 3277 /*0.1 in Q15*/, noise_level[1] ) ); /*Q15*/ move16(); test(); - IF( EQ_16( prev_hq_mode, HQ_NORMAL ) || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) + IF( ( prev_hq_mode == HQ_NORMAL ) || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) { IF( LT_16( noise_level[0], 8192 ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } IF( LT_16( noise_level[1], 8192 ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -914,18 +917,18 @@ void ivas_harm_bwe_fx( E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ } - normq = dicn_fx[norm[i]]; + normq = dicn_fx[norm[i]]; /*Q14*/ move32(); - alfa = noise_level[0]; + alfa = noise_level[0]; /*Q15*/ move16(); IF( GT_16( i, 27 ) ) { - alfa = noise_level[1]; + alfa = noise_level[1]; /*Q15*/ move16(); } - band_width = sub( sfm_end[i], sfm_start[i] ); /* */ + band_width = sub( sfm_end[i], sfm_start[i] ); /* Q0 */ exp1 = norm_l( E_L ); IF( EQ_16( exp1, 0 ) ) { @@ -946,7 +949,7 @@ void ivas_harm_bwe_fx( } exp1 = norm_s( alfa ); - tmp1 = shl( alfa, exp1 ); + tmp1 = shl( alfa, exp1 ); /*Q15+exp1*/ IF( EQ_16( element_mode, EVS_MONO ) ) { exp1 = add( 1, exp1 ); @@ -960,11 +963,11 @@ void ivas_harm_bwe_fx( tmp1 = s_max( tmp1, 16384 ); tmp1 = div_s( 16384, tmp1 ); L_tmp2 = L_deposit_h( tmp1 ); - L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); + L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); /*Q31 - exp1*/ #ifdef BASOP_NOGLOB - beta = round_fx_sat( L_shl_sat( L_tmp2, exp1 ) ); - beta = shr( beta, 1 ); /*Q15 */ + beta = round_fx_sat( L_shl_sat( L_tmp2, exp1 ) ); /*Q15 */ + beta = shr( beta, 1 ); /*Q15*/ #else beta = round_fx( L_shl( L_tmp2, exp1 ) ); beta = shr( beta, 1 ); /*Q15 */ @@ -993,14 +996,14 @@ void ivas_harm_bwe_fx( } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - src = &coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /*Q12 */ + src = &coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /*Q12 */ - dst = src - 1; + dst = src - 1; /*Q12*/ FOR( i = 0; i < 16; i++ ) { *src = Mult_32_16( *src, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ @@ -1019,20 +1022,20 @@ void ivas_harm_bwe_fx( #endif void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ + const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ + const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_hq_mode, /* i : previous hq mode Q0*/ + Word16 *norm, /* i/o: quantization indices for norms Q0*/ + Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15*/ + Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 i, j; @@ -1056,12 +1059,12 @@ void harm_bwe_fx( FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); - move32(); /*12 Q(14 +12+1-16 +1) */ + coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*12 Q(14 +12+1-16 +1) */ + move32(); } } } - noise_level[1] = noise_level[0]; + noise_level[1] = noise_level[0]; /*Q15*/ move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ @@ -1069,22 +1072,22 @@ void harm_bwe_fx( noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ move16(); - L_tmp = L_mult( 29491, prev_noise_level[1] ); - noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); + L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[1] ); /*Q31*/ + noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); /*Q15*/ move16(); test(); IF( prev_hq_mode == HQ_NORMAL || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) { - IF( LT_16( noise_level[0], 8192 ) ) + IF( LT_16( noise_level[0], 8192 /*Q15*/ ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } - IF( LT_16( noise_level[1], 8192 ) ) + IF( LT_16( noise_level[1], 8192 /*Q15*/ ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -1099,14 +1102,14 @@ void harm_bwe_fx( E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ } - normq = dicn_fx[norm[i]]; + normq = dicn_fx[norm[i]]; /*Q14*/ move32(); - alfa = noise_level[0]; + alfa = noise_level[0]; /*Q15*/ move16(); if ( GT_16( i, 27 ) ) { - alfa = noise_level[1]; + alfa = noise_level[1]; /*Q15*/ move16(); } @@ -1143,12 +1146,12 @@ void harm_bwe_fx( } #endif tmp1 = s_max( tmp1, 16384 ); - tmp1 = div_s( 16384, tmp1 ); - L_tmp2 = L_deposit_h( tmp1 ); - L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); + tmp1 = div_s( 16384, tmp1 ); /*Q15*/ + L_tmp2 = L_deposit_h( tmp1 ); /*Q31*/ + L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); /*Q31 - exp1*/ - beta = round_fx( L_shl( L_tmp2, exp1 ) ); - beta = shr( beta, 1 ); /*Q15 */ + beta = round_fx( L_shl( L_tmp2, exp1 ) ); /*Q15*/ + beta = shr( beta, 1 ); /*Q15 */ FOR( sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++ ) @@ -1173,12 +1176,12 @@ void harm_bwe_fx( } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - src = &coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /*Q12 */ + src = &coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /*Q12 */ dst = src - 1; FOR( i = 0; i < 16; i++ ) @@ -1236,7 +1239,7 @@ void hvq_bwe_fx( Word16 norm_ind; Word32 *L_src, *L_dst; Word16 istart, iend; - Word16 offset = sfm_end[last_sfm]; + Word16 offset = sfm_end[last_sfm]; /*Q0*/ /* Fx specific variables */ Word32 L_tmp0, L_tmp1; @@ -1251,13 +1254,13 @@ void hvq_bwe_fx( move32(); /* L_tmp_norm */ move16(); /* bwe_noise_th */ - bwe_noise_th = add( bin_th, shr( sub( sfm_end[sub( num_sfm, 1 )], bin_th ), 1 ) ); + bwe_noise_th = add( bin_th, shr( sub( sfm_end[( num_sfm - 1 )], bin_th ), 1 ) ); logqnorm_fx( &L_coeff_out[sfm_start[last_sfm]], qout, &norm[last_sfm], 40, sfm_len[last_sfm], 0 ); move16(); /* shaping the BWE spectrum further by envelopes and noise factors */ - noise_level[0] = round_fx( L_mac( L_mult( 29491, prev_noise_level[0] ), 3277, noise_level[0] ) ); /* Q15 (15+15+1-16) */ - noise_level[1] = round_fx( L_mac( L_mult( 29491, prev_noise_level[1] ), 3277, noise_level[1] ) ); /* Q15 (15+15+1-16) */ + noise_level[0] = round_fx( L_mac( L_mult( 29491 /*0.9 Q15*/, prev_noise_level[0] ), 3277 /*0.1 Q15*/, noise_level[0] ) ); /* Q15 (15+15+1-16) */ + noise_level[1] = round_fx( L_mac( L_mult( 29491 /*0.9 Q15*/, prev_noise_level[1] ), 3277 /*0.1 Q15*/, noise_level[1] ) ); /* Q15 (15+15+1-16) */ move16(); move16(); @@ -1266,13 +1269,13 @@ void hvq_bwe_fx( { IF( LT_16( noise_level[0], 8192 /* 0.25f */ ) ) { - noise_level[0] = shl( noise_level[0], 2 ); + noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ move16(); } IF( LT_16( noise_level[1], 8192 /* 0.25f */ ) ) { - noise_level[1] = shl( noise_level[1], 2 ); + noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ move16(); } } @@ -1287,7 +1290,7 @@ void hvq_bwe_fx( move16(); FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind + 1]; i++ ) { - tmp2 = abs_s( coeff_fine[i - offset] ); + tmp2 = abs_s( coeff_fine[i - offset] ); /*Qin*/ tmp = s_max( tmp, tmp2 ); } band_size = sub( sfm_end[norm_ind + 1], sfm_start[norm_ind] ); @@ -1303,9 +1306,9 @@ void hvq_bwe_fx( move16(); } /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl( coeff_fine[i - offset], shift ); - move16(); /* Q15 + shift */ - L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(qin + shift) */ + coeff_s[i] = shl( coeff_fine[i - offset], shift ); /*Qin*/ + move16(); /* Q15 + shift */ + L_E = L_mac0( L_E, coeff_s[i], coeff_s[i] ); /* Q2*(qin + shift) */ } power_shift = shl( shift, 1 ); @@ -1322,8 +1325,8 @@ void hvq_bwe_fx( /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ /* tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; */ - L_tmp0 = L_add( dicn_fx[norm[norm_ind]], 0 ); - L_tmp1 = L_add( dicn_fx[norm[norm_ind + 1]], 0 ); + L_tmp0 = L_add( dicn_fx[norm[norm_ind]], 0 ); /*Q14*/ + L_tmp1 = L_add( dicn_fx[norm[norm_ind + 1]], 0 ); /*Q14*/ L_normq = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp0, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind - 1]], 3277 /* Q15, 0.1f */ ), L_tmp1, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ move16(); L_tmp_norm = Madd_32_16( Madd_32_16( Mult_32_16( L_tmp1, 26214 /* Q15, 0.8f */ ), dicn_fx[norm[norm_ind + 2]], 3277 /* Q15, 0.1f */ ), L_tmp0, 3277 /* Q15, 0.1f */ ); /* Q14 (14+15+1-16) */ @@ -1366,26 +1369,26 @@ void hvq_bwe_fx( IF( L_tmp0 != 0 ) { /* Normalize with 1 bit headroom for addition */ - tmp = 30 - ( qin + 2 ); /* Assuming fixed Q values */ + tmp = sub( 30, add( qin, 2 ) ); /* Assuming fixed Q values */ tmp = s_min( norm_l( L_tmp0 ), tmp ); tmp = sub( tmp, 1 ); L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ - L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level[0], Random( bwe_seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ - tmp = round_fx( L_shl( L_tmp0, 27 - ( qin + 2 ) - tmp ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level[0], Random( bwe_seed ) ), sub( sub( 30, add( qin, 2 ) ), tmp ) ) ); /* Qin+2+tmp */ + tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_shr( lsb, 10 + 16 - qout ) ); - move32(); /* Qout (10+qout-10) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, sub( qout, 10 ) ), L_shr( lsb, add( 10, sub( 16, qout ) ) ) ); /*Qout*/ + move32(); } ELSE { L_tmp0 = L_mult0( noise_level[0], Random( bwe_seed ) ); /* Q30 (15+15) */ tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ Mpy_32_16_ss( L_tmp1, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); - move32(); /* Qout (13-(13-qout)) */ + L_coeff_out[i] = L_shr( L_tmp0, sub( 13, qout ) ); /*Qout*/ + move32(); } } @@ -1451,7 +1454,7 @@ void hvq_bwe_fx( } power_shift = shl( shift, 1 ); - L_E = L_shr( L_E, sub( power_shift, 28 - 2 * qin ) ); /* Q28 */ + L_E = L_shr( L_E, sub( power_shift, sub( 28, imult1616( 2, qin ) ) ) ); /* Q28 */ /* E_L = (float)sqrt((iend - istart)/E_L); */ L_E = Mult_32_16( L_E, inv_tbl_fx[band_size] ); /* Q28 (28+15+1-16) */ @@ -1487,17 +1490,17 @@ void hvq_bwe_fx( move16(); high = s_min( add( norm_ind, 1 ), last_norm_ind ); move16(); - sel_norm = norm[norm_ind - 1]; + sel_norm = norm[norm_ind - 1]; /*Q0*/ move16(); FOR( j = low; j <= high; j++ ) { if ( GT_16( norm[j], sel_norm ) ) { - sel_norm = norm[j]; + sel_norm = norm[j]; /*Q0*/ move16(); } } - L_normq = dicn_fx[sel_norm]; + L_normq = dicn_fx[sel_norm]; /*Q14*/ move16(); } @@ -1523,26 +1526,26 @@ void hvq_bwe_fx( { FOR( i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++ ) { - L_coeff_out[i] = L_coeff[i]; /* Scaling already applied */ + L_coeff_out[i] = L_coeff[i]; /* Scaling already applied Q12*/ move32(); } } } - prev_noise_level[0] = noise_level[0]; + prev_noise_level[0] = noise_level[0]; /*Q15*/ move16(); - prev_noise_level[1] = noise_level[1]; + prev_noise_level[1] = noise_level[1]; /*Q15*/ move16(); - L_src = &L_coeff_out[add( sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC )]; /* Address initialization */ - L_dst = L_src - 1; /* Address computation */ + L_src = &L_coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /* Address initialization Qout*/ + L_dst = L_src - 1; /* Address computation Qout*/ FOR( i = 0; i < 16; i++ ) { - *L_src = Mult_32_16( *L_src, hvq_bwe_fac_fx[i] ); - L_src++; /* Qout (Qout+15+1-16) */ + *L_src = Mult_32_16( *L_src, hvq_bwe_fac_fx[i] ); /* Qout (Qout+15+1-16) */ + L_src++; /* Qout (Qout+15+1-16) */ move32(); - *L_dst = Mult_32_16( *L_dst, hvq_bwe_fac_fx[i] ); - L_dst--; /* Qout (Qout+15+1-16) */ + *L_dst = Mult_32_16( *L_dst, hvq_bwe_fac_fx[i] ); /* Qout (Qout+15+1-16) */ + L_dst--; /* Qout (Qout+15+1-16) */ move32(); } @@ -1555,12 +1558,12 @@ void hvq_bwe_fx( * Compute the band limits for concatenated bands for PVQ target signal in HVQ *--------------------------------------------------------------------------*/ void hvq_concat_bands_fx( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ + const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target Q0*/ + const Word16 *sel_bnds, /* i : Array of selected high bands Q0*/ + const Word16 n_sel_bnds, /* i : Number of selected high bands Q0*/ + Word16 *hvq_band_start, /* i : Band start indices Q0*/ + Word16 *hvq_band_width, /* i : Band widths Q0*/ + Word16 *hvq_band_end /* i : Band end indices Q0*/ ) { Word16 k, k_1; @@ -1573,20 +1576,21 @@ void hvq_concat_bands_fx( IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) { k_1 = sub( k, 1 ); - hvq_band_start[k] = hvq_band_end[k_1]; + hvq_band_start[k] = hvq_band_end[k_1]; /*Q0*/ move16(); - hvq_band_width[k] = band_len_harm[*pSelBnds++]; + hvq_band_width[k] = band_len_harm[*pSelBnds++]; /*Q0*/ move16(); move16(); - hvq_band_end[k] = add( hvq_band_end[k_1], hvq_band_width[k] ); + hvq_band_end[k] = add( hvq_band_end[k_1], hvq_band_width[k] ); /*Q0*/ move16(); } ELSE { - hvq_band_start[k] = extract_l( L_mult0( k, HVQ_PVQ_COEFS ) ); - hvq_band_width[k] = HVQ_PVQ_COEFS; + hvq_band_start[k] = extract_l( L_mult0( k, HVQ_PVQ_COEFS ) ); /*Q0*/ move16(); - hvq_band_end[k] = add( hvq_band_start[k], HVQ_PVQ_COEFS ); + hvq_band_width[k] = HVQ_PVQ_COEFS; /*Q0*/ + move16(); + hvq_band_end[k] = add( hvq_band_start[k], HVQ_PVQ_COEFS ); /*Q0*/ move16(); } } @@ -1627,21 +1631,21 @@ void noise_mix_fx( tmp = s_min( norm_l( L_tmp0 ), tmp ); tmp = sub( tmp, 1 ); - L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ - L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level, Random( seed ) ), sub( 30 - ( qin + 2 ), tmp ) ) ); /* Qin+2+tmp */ + L_tmp0 = L_add( L_shl( L_tmp0, tmp ), L_shr( lsb, sub( 16, tmp ) ) ); /* Qin+2+tmp */ + L_tmp0 = L_add( L_tmp0, L_shr( L_mult0( noise_level, Random( seed ) ), sub( sub( 30, add( qin, 2 ) ), tmp ) ) ); /* Qin+2+tmp */ - tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add( L_shl( L_tmp0, qout - 10 ), L_shr( lsb, 10 + 16 - qout ) ); - move32(); /* Qout (10+qout-10) */ + tmp = round_fx( L_shl( L_tmp0, sub( sub( 27, add( qin, 2 ) ), tmp ) ) ); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q10 (14+11+1-16) */ + L_coeff_out[i] = L_add( L_shl( L_tmp0, sub( qout, 10 ) ), L_shr( lsb, add( 10, sub( 16, qout ) ) ) ); /* Qout (10+qout-10) */ + move32(); } ELSE { - L_tmp0 = L_mult0( noise_level, Random( seed ) ); /* Q30 (15+15) */ - tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ - Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr( L_tmp0, 13 - qout ); - move32(); /* Qout (13-(13-qout)) */ + L_tmp0 = L_mult0( noise_level, Random( seed ) ); /* Q30 (15+15) */ + tmp = round_fx( L_tmp0 ); /* Q14 (30-16) */ + Mpy_32_16_ss( L_normq, tmp, &L_tmp0, &lsb ); /* Q13 (14+14+1-16) */ + L_coeff_out[i] = L_shr( L_tmp0, sub( 13, qout ) ); /* Qout (13-(13-qout)) */ + move32(); } } } @@ -1653,12 +1657,12 @@ void noise_mix_fx( * Prepare HQ GENERIC HF fine structure *--------------------------------------------------------------------------*/ void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ GENERIC input */ + Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 last_sfm, /* i : Last coded band Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word16 *coeff_out1 /* o : HQ GENERIC input Q12*/ ) { Word16 sfm; @@ -1670,17 +1674,17 @@ void hq_generic_fine_fx( { IF( coeff[i] == 0 ) { - coeff_out1[i] = -2048; + coeff_out1[i] = -2048; /*Q12*/ move16(); if ( Random( bwe_seed ) > 0 ) { - coeff_out1[i] = 2048; + coeff_out1[i] = 2048; /*Q12*/ move16(); } } ELSE { - coeff_out1[i] = coeff[i]; + coeff_out1[i] = coeff[i]; /*Q12*/ move16(); } } @@ -1695,23 +1699,23 @@ void hq_generic_fine_fx( * Overlapping at the boundary between HQ core and BWE *--------------------------------------------------------------------------*/ static void overlap_hq_bwe_fx( - const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core */ - Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output */ - const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping */ - const Word16 n_swb_overlap, /* i : length of overlapping */ - const Word16 *R, - const Word16 num_env_bands, - const Word16 num_sfm, - const Word16 *sfm_end ) + const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core Q12*/ + Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output Q12*/ + const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping Q0*/ + const Word16 n_swb_overlap, /* i : length of overlapping Q0*/ + const Word16 *R, /*Q0*/ + const Word16 num_env_bands, /*Q0*/ + const Word16 num_sfm, /*Q0*/ + const Word16 *sfm_end /*Q0*/ ) { Word16 i; Word16 weighting; Word16 step; Word16 exp, tmp, n_band; - IF( R[sub( num_env_bands, 1 )] != 0 ) + IF( R[( num_env_bands - 1 )] != 0 ) { - Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); + Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); /*Q12*/ } ELSE { @@ -1723,8 +1727,8 @@ static void overlap_hq_bwe_fx( move16(); FOR( i = 0; i < n_swb_overlap; i++ ) { - coeff_out[add( n_swb_overlap_offset, i )] = L_add( coeff_out[add( n_swb_overlap_offset, i )], - Mult_32_16( L_sub( hq_swb_overlap_buf[i], coeff_out[add( n_swb_overlap_offset, i )] ), weighting ) ); + coeff_out[( n_swb_overlap_offset + i )] = L_add( coeff_out[( n_swb_overlap_offset + i )], + Mult_32_16( L_sub( hq_swb_overlap_buf[i], coeff_out[( n_swb_overlap_offset + i )] ), weighting ) ); /*Q12*/ move32(); weighting = sub( weighting, step ); } @@ -1734,9 +1738,9 @@ static void overlap_hq_bwe_fx( { IF( R[n_band] != 0 ) { - FOR( i = sfm_end[sub( n_band, 1 )]; i < sfm_end[n_band]; ++i ) + FOR( i = sfm_end[( n_band - 1 )]; i < sfm_end[n_band]; ++i ) { - coeff_out[i] = hq_swb_overlap_buf[sub( i, n_swb_overlap_offset )]; + coeff_out[i] = hq_swb_overlap_buf[( i - n_swb_overlap_offset )]; /*Q12*/ move32(); } } @@ -1750,65 +1754,65 @@ static void overlap_hq_bwe_fx( * mapping high frequency envelope to high band norm *--------------------------------------------------------------------------*/ void map_hq_generic_fenv_norm_fx( - const Word16 hqswb_clas, + const Word16 hqswb_clas, /*Q0*/ const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ - Word16 *ynrm, - Word16 *normqlg2, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 hq_generic_offset ) + Word16 *ynrm, /*Q0*/ + Word16 *normqlg2, /*Q0*/ + const Word16 num_env_bands, /*Q0*/ + const Word16 nb_sfm, /*Q0*/ + const Word16 hq_generic_offset /*Q0*/ ) { - Word32 env_fl[17]; /*Q10 */ + Word32 env_fl[17]; /*Q8 */ Word16 i; set32_fx( env_fl, 0, 17 ); IF( EQ_16( hq_generic_offset, 144 ) ) { - env_fl[0] = L_shl( hq_generic_fenv[1], 7 ); + env_fl[0] = L_shl( hq_generic_fenv[1], 7 ); /*Q8*/ move32(); - env_fl[1] = L_add( L_mult0( hq_generic_fenv[2], 85 ), L_mult0( hq_generic_fenv[3], 43 ) ); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[2], 85 ), L_mult0( hq_generic_fenv[3], 43 ) ); /*Q8*/ move32(); - env_fl[2] = L_add( L_mult0( hq_generic_fenv[3], 85 ), L_mult0( hq_generic_fenv[4], 43 ) ); + env_fl[2] = L_add( L_mult0( hq_generic_fenv[3], 85 ), L_mult0( hq_generic_fenv[4], 43 ) ); /*Q8*/ move32(); - env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 43 ), L_mult0( hq_generic_fenv[5], 85 ) ); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 43 ), L_mult0( hq_generic_fenv[5], 85 ) ); /*Q8*/ move32(); - env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 43 ), L_mult0( hq_generic_fenv[6], 85 ) ); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 43 ), L_mult0( hq_generic_fenv[6], 85 ) ); /*Q8*/ move32(); - env_fl[5] = L_shl( hq_generic_fenv[7], 7 ); + env_fl[5] = L_shl( hq_generic_fenv[7], 7 ); /*Q8*/ move32(); - env_fl[6] = L_add( L_mult0( hq_generic_fenv[8], 96 ), L_mult0( hq_generic_fenv[9], 32 ) ); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[8], 96 ), L_mult0( hq_generic_fenv[9], 32 ) ); /*Q8*/ move32(); - env_fl[7] = L_add( L_mult0( hq_generic_fenv[9], 96 ), L_mult0( hq_generic_fenv[10], 32 ) ); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[9], 96 ), L_mult0( hq_generic_fenv[10], 32 ) ); /*Q8*/ move32(); - env_fl[8] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); /*Q8*/ move32(); } ELSE { - env_fl[0] = L_add( L_mult0( hq_generic_fenv[0], 43 ), L_mult0( hq_generic_fenv[1], 85 ) ); + env_fl[0] = L_add( L_mult0( hq_generic_fenv[0], 43 ), L_mult0( hq_generic_fenv[1], 85 ) ); /*Q8*/ move32(); - env_fl[1] = L_add( L_mult0( hq_generic_fenv[1], 43 ), L_mult0( hq_generic_fenv[2], 85 ) ); + env_fl[1] = L_add( L_mult0( hq_generic_fenv[1], 43 ), L_mult0( hq_generic_fenv[2], 85 ) ); /*Q8*/ move32(); - env_fl[2] = L_shl( hq_generic_fenv[3], 7 ); + env_fl[2] = L_shl( hq_generic_fenv[3], 7 ); /*Q8*/ move32(); - env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 85 ), L_mult0( hq_generic_fenv[5], 43 ) ); + env_fl[3] = L_add( L_mult0( hq_generic_fenv[4], 85 ), L_mult0( hq_generic_fenv[5], 43 ) ); /*Q8*/ move32(); - env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 85 ), L_mult0( hq_generic_fenv[6], 43 ) ); + env_fl[4] = L_add( L_mult0( hq_generic_fenv[5], 85 ), L_mult0( hq_generic_fenv[6], 43 ) ); /*Q8*/ move32(); - env_fl[5] = L_add( L_mult0( hq_generic_fenv[6], 43 ), L_mult0( hq_generic_fenv[7], 85 ) ); + env_fl[5] = L_add( L_mult0( hq_generic_fenv[6], 43 ), L_mult0( hq_generic_fenv[7], 85 ) ); /*Q8*/ move32(); - env_fl[6] = L_add( L_mult0( hq_generic_fenv[7], 43 ), L_mult0( hq_generic_fenv[8], 85 ) ); + env_fl[6] = L_add( L_mult0( hq_generic_fenv[7], 43 ), L_mult0( hq_generic_fenv[8], 85 ) ); /*Q8*/ move32(); - env_fl[7] = L_add( L_mult0( hq_generic_fenv[8], 43 ), L_mult0( hq_generic_fenv[9], 85 ) ); + env_fl[7] = L_add( L_mult0( hq_generic_fenv[8], 43 ), L_mult0( hq_generic_fenv[9], 85 ) ); /*Q8*/ move32(); - env_fl[8] = L_add( L_mult0( hq_generic_fenv[9], 43 ), L_mult0( hq_generic_fenv[10], 85 ) ); + env_fl[8] = L_add( L_mult0( hq_generic_fenv[9], 43 ), L_mult0( hq_generic_fenv[10], 85 ) ); /*Q8*/ move32(); - env_fl[9] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); + env_fl[9] = L_add( L_mult0( hq_generic_fenv[10], 32 ), L_mult0( hq_generic_fenv[11], 96 ) ); /*Q8*/ move32(); - env_fl[10] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[10] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[11] = L_shl( hq_generic_fenv[13], 7 ); + env_fl[11] = L_shl( hq_generic_fenv[13], 7 ); /*Q8*/ move32(); } @@ -1816,28 +1820,28 @@ void map_hq_generic_fenv_norm_fx( { IF( EQ_16( hq_generic_offset, 144 ) ) { - env_fl[9] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[9] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[10] = L_add( L_mult0( hq_generic_fenv[12], 32 ), L_mult0( hq_generic_fenv[13], 96 ) ); + env_fl[10] = L_add( L_mult0( hq_generic_fenv[12], 32 ), L_mult0( hq_generic_fenv[13], 96 ) ); /*Q8*/ move32(); - env_fl[11] = L_add( L_mult0( hq_generic_fenv[13], 64 ), L_mult0( hq_generic_fenv[14], 64 ) ); + env_fl[11] = L_add( L_mult0( hq_generic_fenv[13], 64 ), L_mult0( hq_generic_fenv[14], 64 ) ); /*Q8*/ move32(); - env_fl[12] = L_shl( hq_generic_fenv[12], 7 ); + env_fl[12] = L_shl( hq_generic_fenv[12], 7 ); /*Q8*/ move32(); - env_fl[13] = env_fl[12]; + env_fl[13] = env_fl[12]; /*Q8*/ move32(); } ELSE { - env_fl[12] = L_shl( hq_generic_fenv[14], 7 ); + env_fl[12] = L_shl( hq_generic_fenv[14], 7 ); /*Q8*/ move32(); - env_fl[13] = L_add( L_mult0( hq_generic_fenv[14], 32 ), L_mult0( hq_generic_fenv[15], 96 ) ); + env_fl[13] = L_add( L_mult0( hq_generic_fenv[14], 32 ), L_mult0( hq_generic_fenv[15], 96 ) ); /*Q8*/ move32(); - env_fl[14] = L_add( L_mult0( hq_generic_fenv[15], 64 ), L_mult0( hq_generic_fenv[16], 64 ) ); + env_fl[14] = L_add( L_mult0( hq_generic_fenv[15], 64 ), L_mult0( hq_generic_fenv[16], 64 ) ); /*Q8*/ move32(); - env_fl[15] = L_shl( hq_generic_fenv[16], 7 ); + env_fl[15] = L_shl( hq_generic_fenv[16], 7 ); /*Q8*/ move32(); - env_fl[16] = env_fl[15]; + env_fl[16] = env_fl[15]; /*Q8*/ move32(); } } @@ -1846,15 +1850,15 @@ void map_hq_generic_fenv_norm_fx( FOR( i = num_env_bands; i < nb_sfm; ++i ) { - normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; + normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; /*Q0*/ move16(); } return; } -static void update_rsubband_fx( const Word16 nb_sfm, - Word16 *Rsubband, /* Q3 */ - Word16 b_add_bits_denv ) +static void update_rsubband_fx( const Word16 nb_sfm, /*Q0*/ + Word16 *Rsubband, /* Q3 */ + Word16 b_add_bits_denv /*Q0*/ ) { Word16 i; @@ -1862,13 +1866,14 @@ static void update_rsubband_fx( const Word16 nb_sfm, WHILE( b_add_bits_denv > 0 ) { i = sub( nb_sfm, 1 ); + test(); WHILE( b_add_bits_denv > 0 && i >= 0 ) { IF( GT_16( Rsubband[i], 24 ) ) { - Rsubband[i] = sub( Rsubband[i], 8 ); + Rsubband[i] = sub( Rsubband[i], 8 ); /*Q3*/ move16(); - b_add_bits_denv = sub( b_add_bits_denv, 1 ); + b_add_bits_denv = sub( b_add_bits_denv, 1 ); /*Q0*/ } i = sub( i, 1 ); } @@ -1879,11 +1884,11 @@ static void update_rsubband_fx( const Word16 nb_sfm, Word16 get_nor_delta_hf_fx( Decoder_State *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm ) + Word16 *ynrm, /*Q0*/ + Word16 *Rsubband, /* Q3 */ + const Word16 num_env_bands, /*Q0*/ + const Word16 nb_sfm, /*Q0*/ + const Word16 core_sfm /*Q0*/ ) { Word16 i; Word16 delta, bitsforDelta, add_bits_denv; @@ -1892,7 +1897,7 @@ Word16 get_nor_delta_hf_fx( move16(); IF( GE_16( core_sfm, num_env_bands ) ) { - bitsforDelta = (Word16) get_next_indice_fx( st, 2 ); + bitsforDelta = (Word16) get_next_indice_fx( st, 2 ); /*Q0*/ bitsforDelta = add( bitsforDelta, 2 ); add_bits_denv = add( add_bits_denv, 2 ); @@ -1900,13 +1905,13 @@ Word16 get_nor_delta_hf_fx( { IF( Rsubband[i] != 0 ) { - delta = (Word16) get_next_indice_fx( st, bitsforDelta ); - ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); + delta = (Word16) get_next_indice_fx( st, bitsforDelta ); /*Q0*/ + ynrm[i] = add( ynrm[i], sub( delta, ( shl( 1, sub( bitsforDelta, 1 ) ) ) ) ); /*Q0*/ move16(); /* safety check in case of bit errors */ test(); - if ( ynrm[i] < 0 || GT_16( ynrm[i], 39 ) ) + IF( ynrm[i] < 0 || GT_16( ynrm[i], 39 ) ) { ynrm[i] = 39; move16(); @@ -1930,13 +1935,13 @@ Word16 get_nor_delta_hf_fx( Word16 calc_nor_delta_hf_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ - Word16 *ynrm, /* i/o: norm indices */ - Word16 *Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16 *sfmsize, /* i : band length */ - const Word16 *sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + Word16 *ynrm, /* i/o: norm indices Q0*/ + Word16 *Rsubband, /* i/o: sub-band bit allocation Q0*/ + const Word16 num_env_bands, /* i : Number coded envelope bands Q0*/ + const Word16 nb_sfm, /* i : Number of envelope bands Q0*/ + const Word16 *sfmsize, /* i : band length Q0*/ + const Word16 *sfm_start, /* i : Start index of bands Q0*/ + const Word16 core_sfm /* i : index of the end band for core Q0*/ ) { Word16 i; @@ -1952,18 +1957,18 @@ Word16 calc_nor_delta_hf_ivas_fx( { IF( Rsubband[i] != 0 ) { - delta = sub( ynrm_t[i], ynrm[i] ); + delta = sub( ynrm_t[i], ynrm[i] ); /*Q0*/ IF( delta > 0 ) { - delta = add( delta, 1 ); + delta = add( delta, 1 ); /*Q0*/ } ELSE { - delta = negate( delta ); + delta = negate( delta ); /*Q0*/ } if ( GT_16( delta, max_delta ) ) { - max_delta = delta; + max_delta = delta; /*Q0*/ move16(); } } @@ -1976,7 +1981,7 @@ Word16 calc_nor_delta_hf_ivas_fx( move16(); FOR( ; max_delta >= 2; max_delta >>= 1 ) { - bitsforDelta = add( bitsforDelta, 1 ); + bitsforDelta = add( bitsforDelta, 1 ); /*Q0*/ } } ELSE @@ -1984,8 +1989,8 @@ Word16 calc_nor_delta_hf_ivas_fx( bitsforDelta = 5; move16(); } - max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); - min_delta = negate( add( max_delta, 1 ) ); + max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); /*Q0*/ + min_delta = negate( add( max_delta, 1 ) ); /*Q0*/ /* updating norm & storing delta norm */ add_bits_denv = 2; @@ -1998,16 +2003,16 @@ Word16 calc_nor_delta_hf_ivas_fx( delta = sub( ynrm_t[i], ynrm[i] ); IF( GT_16( delta, max_delta ) ) { - delta = max_delta; + delta = max_delta; /*Q0*/ move16(); } ELSE IF( LT_16( delta, min_delta ) ) { - delta = min_delta; + delta = min_delta; /*Q0*/ move16(); } push_indice( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); - ynrm[i] = add( ynrm[i], delta ); + ynrm[i] = add( ynrm[i], delta ); /*Q0*/ move16(); add_bits_denv = add( add_bits_denv, bitsforDelta ); } @@ -2026,14 +2031,14 @@ Word16 calc_nor_delta_hf_ivas_fx( *--------------------------------------------------------------------------*/ Word16 calc_nor_delta_hf_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *t_audio, /* i : transform-domain coefficients */ - Word16 *ynrm, /* i/o: norm indices */ - Word16 *Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16 *sfmsize, /* i : band length */ - const Word16 *sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ + const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ + Word16 *ynrm, /* i/o: norm indices Q0*/ + Word16 *Rsubband, /* i/o: sub-band bit allocation Q0*/ + const Word16 num_env_bands, /* i : Number coded envelope bands Q0*/ + const Word16 nb_sfm, /* i : Number of envelope bands Q0*/ + const Word16 *sfmsize, /* i : band length Q0*/ + const Word16 *sfm_start, /* i : Start index of bands Q0*/ + const Word16 core_sfm /* i : index of the end band for core Q0*/ ) { Word16 i; @@ -2052,15 +2057,15 @@ Word16 calc_nor_delta_hf_fx( delta = sub( ynrm_t[i], ynrm[i] ); IF( delta > 0 ) { - delta = add( delta, 1 ); + delta = add( delta, 1 ); /*Q0*/ } ELSE { - delta = negate( delta ); + delta = negate( delta ); /*Q0*/ } if ( GT_16( delta, max_delta ) ) { - max_delta = delta; + max_delta = delta; /*Q0*/ move16(); } } @@ -2073,7 +2078,7 @@ Word16 calc_nor_delta_hf_fx( move16(); FOR( ; max_delta >= 2; max_delta >>= 1 ) { - bitsforDelta = add( bitsforDelta, 1 ); + bitsforDelta = add( bitsforDelta, 1 ); /*Q0*/ } } ELSE @@ -2081,8 +2086,8 @@ Word16 calc_nor_delta_hf_fx( bitsforDelta = 5; move16(); } - max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); - min_delta = negate( add( max_delta, 1 ) ); + max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); /*Q0*/ + min_delta = negate( add( max_delta, 1 ) ); /*Q0*/ /* updating norm & storing delta norm */ add_bits_denv = 2; @@ -2092,19 +2097,19 @@ Word16 calc_nor_delta_hf_fx( { IF( Rsubband[i] != 0 ) { - delta = sub( ynrm_t[i], ynrm[i] ); + delta = sub( ynrm_t[i], ynrm[i] ); /*Q0*/ IF( GT_16( delta, max_delta ) ) { - delta = max_delta; + delta = max_delta; /*Q0*/ move16(); } ELSE IF( LT_16( delta, min_delta ) ) { - delta = min_delta; + delta = min_delta; /*Q0*/ move16(); } push_indice_fx( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); - ynrm[i] = add( ynrm[i], delta ); + ynrm[i] = add( ynrm[i], delta ); /*Q0*/ move16(); add_bits_denv = add( add_bits_denv, bitsforDelta ); } @@ -2123,27 +2128,27 @@ Word16 calc_nor_delta_hf_fx( * HQ GENERIC *--------------------------------------------------------------------------*/ void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 num_env_bands, /* i : Number of coded envelope bands */ - const Word16 *R /* i : Bit allocation */ + const Word16 HQ_mode, /* i : HQ mode Q0*/ + Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ + Word32 *coeff_out, /* o : SWB signal in MDCT domain Q12*/ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic Q0*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ + const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class Q0*/ + const Word16 *sfm_end, /* i : End of bands Q0*/ + const Word16 num_sfm, /* i : Number of bands Q0*/ + const Word16 num_env_bands, /* i : Number of coded envelope bands Q0*/ + const Word16 *R /* i : Bit allocation Q0*/ ) { Word16 n_swb_overlap_offset, n_swb_overlap; Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; n_swb_overlap_offset = add( swb_bwe_subband[0], hq_generic_offset ); - n_swb_overlap = sub( sfm_end[sub( num_env_bands, 1 )], n_swb_overlap_offset ); + n_swb_overlap = sub( sfm_end[( num_env_bands - 1 )], n_swb_overlap_offset ); /*Q0*/ - Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[sub( num_sfm, 1 )] ), sfm_end[sub( num_env_bands, 1 )] ) ); + Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[( num_sfm - 1 )] ), sfm_end[( num_env_bands - 1 )] ) ); /*Q12*/ hq_generic_decoding_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); @@ -2159,23 +2164,23 @@ void hq_bwe_fx( *--------------------------------------------------------------------------*/ void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ + const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum Q12*/ + const Word16 is_transient, /*Q0*/ + const Word16 prev_bfi, /* i : previous bad frame indicator Q0*/ + const Word32 *L_normq_v, /*Q14*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ + const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ + const Word16 *sfmsize, /* i : Subband band width Q0*/ + const Word16 last_sfm, /* i : last coded subband Q0*/ + const Word16 *R, /* i : bit allocation Q0*/ + const Word16 prev_is_transient, /* i : previous transient flag Q0*/ + Word32 *prev_normq_fx, /* i/o: previous norms Q14*/ + Word32 *prev_env_fx, /* i/o: previous noise envelopes prev_env_Q*/ + Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ + Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame Q12*/ + Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0*/ + Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Q12*/ Word16 *prev_env_Q ) { Word16 i; @@ -2184,7 +2189,10 @@ void hq_wb_nf_bwe_fx( Word16 num; Word32 env_fx, peak_fx, fabs_coeff_out_fx, min_coef_fx; Word32 L_tmp1, L_tmp2 = 0, L_tmp3, L_tmp4; + move32(); Word16 tmp1, exp = 0, exp1, exp2, exp3, harm_para_fx, sharp_fx, step_fx, alfa_fx = 4096; + move16(); + move16(); Word32 avrg_norm_fx, prev_avrg_norm_fx; Word16 bitalloc_var_fx; Word16 tmp; @@ -2195,7 +2203,7 @@ void hq_wb_nf_bwe_fx( { IF( EQ_16( prev_bfi, 1 ) ) { - Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); /*Q14*/ } /* the variance of bit allocation */ @@ -2206,9 +2214,9 @@ void hq_wb_nf_bwe_fx( FOR( sfm = 8; sfm <= last_sfm; sfm++ ) { - tmp = abs_s( sub( R[sfm], R[sub( sfm, 1 )] ) ); + tmp = abs_s( sub( R[sfm], R[( sfm - 1 )] ) ); /*Q0*/ bitalloc_var_fx = add( bitalloc_var_fx, tmp ); - total_bit = add( total_bit, R[sfm] ); + total_bit = add( total_bit, R[sfm] ); /*Q0*/ } test(); IF( GT_16( last_sfm, 8 ) && total_bit > 0 ) @@ -2249,7 +2257,7 @@ void hq_wb_nf_bwe_fx( move16(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); /*Q12*/ #ifdef BASOP_NOGLOB mean_fx = L_add_sat( mean_fx, fabs_coeff_out_fx ); /*Q12 */ #else @@ -2294,11 +2302,11 @@ void hq_wb_nf_bwe_fx( } ELSE { - sharp_fx = 16384; - move16(); /*Q14 = 1 */ + sharp_fx = 16384; /*Q14 = 1 */ + move16(); } - harm_para_fx = sharp_fx; - move16(); /*Q14 */ + harm_para_fx = sharp_fx; /*Q14 */ + move16(); IF( last_sfm == 0 ) { @@ -2317,8 +2325,8 @@ void hq_wb_nf_bwe_fx( #else step_fx = round_fx( L_shl( L_tmp, 16 ) ); /*Q15 */ #endif - alfa_fx = 20480; - move16(); /*Q13 = 2.5 */ + alfa_fx = 20480; /*Q13 = 2.5 */ + move16(); /* fill noise for the insaturable subbands */ FOR( sfm = 0; sfm < num_sfm; sfm++ ) { @@ -2336,21 +2344,21 @@ void hq_wb_nf_bwe_fx( L_tmp1 = Mult_32_32( L_tmp4, L_tmp4 ); /*2*exp1-3 14+exp1+14+exp1 -31 */ L_tmp2 = L_deposit_l( 0 ); peak_fx = L_deposit_l( 0 ); - min_coef_fx = 0x7fffffff; + min_coef_fx = 0x7fffffff; /*Q31*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { - fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); + fabs_coeff_out_fx = L_abs( L_coeff_out[i] ); /*Q12*/ test(); if ( LT_32( fabs_coeff_out_fx, min_coef_fx ) && L_coeff_out[i] != 0 ) { - min_coef_fx = fabs_coeff_out_fx; + min_coef_fx = fabs_coeff_out_fx; /*Q12*/ move32(); } if ( GT_32( fabs_coeff_out_fx, peak_fx ) ) { - peak_fx = fabs_coeff_out_fx; + peak_fx = fabs_coeff_out_fx; /*Q12*/ move32(); } } @@ -2400,10 +2408,10 @@ void hq_wb_nf_bwe_fx( } ELSE { - avrg_norm_fx = L_add( L_shr( L_normq_v[sub( sfm, 1 )], 1 ), L_shr( L_normq_v[sfm], 1 ) ); /*13 */ - avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[sfm + 1], 1 ) ); /*13 */ - prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[sub( sfm, 1 )], 1 ), L_shr( prev_normq_fx[sfm], 1 ) ); /*13 */ - prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[add( sfm, 1 )], 1 ) ); /*13 */ + avrg_norm_fx = L_add( L_shr( L_normq_v[( sfm - 1 )], 1 ), L_shr( L_normq_v[sfm], 1 ) ); /*13 */ + avrg_norm_fx = L_add( avrg_norm_fx, L_shr( L_normq_v[sfm + 1], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( L_shr( prev_normq_fx[( sfm - 1 )], 1 ), L_shr( prev_normq_fx[sfm], 1 ) ); /*13 */ + prev_avrg_norm_fx = L_add( prev_avrg_norm_fx, L_shr( prev_normq_fx[( sfm + 1 )], 1 ) ); /*13 */ } test(); @@ -2413,13 +2421,13 @@ void hq_wb_nf_bwe_fx( Word16 exp_p; exp_p = norm_l( peak_fx ); exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ L_tmp1 = Mult_32_32( env_fx, L_shl( peak_fx, exp_p ) ); /*12+exp2-exp 31-exp+12+exp1-31 */ L_tmp2 = Mult_32_16( avrg_norm_fx, harm_para_fx ); /*12 13 + 14 + 1 -16 */ exp1 = norm_l( L_tmp1 ); L_tmp1 = L_shl( L_tmp1, exp1 ); /* 12+exp2-exp+exp1 */ exp = add( sub( 12, exp ), add( exp1, exp_p ) ); - L_tmp2 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); + L_tmp2 = Div_32( L_tmp2, extract_h( L_tmp1 ), extract_l( L_tmp1 ) ); /*Q31 - (43-exp)*/ exp = sub( 43, exp ); } ELSE @@ -2428,11 +2436,11 @@ void hq_wb_nf_bwe_fx( IF( LT_32( L_tmp1, peak_fx ) ) { exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ exp1 = norm_l( env_fx ); env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ exp = add( sub( 31, exp ), exp1 ); - L_tmp1 = (Word32) sharp_fx; + L_tmp1 = L_deposit_l( sharp_fx ); /*Q14*/ L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ exp = sub( 45, exp ); exp1 = norm_l( peak_fx ); @@ -2444,17 +2452,17 @@ void hq_wb_nf_bwe_fx( ELSE { exp = sub( 31, exp ); - env_fx = Isqrt_lc( env_fx, &exp ); + env_fx = Isqrt_lc( env_fx, &exp ); /*Q31 - exp*/ exp1 = norm_l( env_fx ); env_fx = L_shl( env_fx, exp1 ); /* 31-exp+exp1 */ exp = add( sub( 31, exp ), exp1 ); - L_tmp1 = (Word32) ( sharp_fx ); + L_tmp1 = L_deposit_l( sharp_fx ); /*Q14*/ L_tmp2 = Div_32( L_tmp1, extract_h( env_fx ), extract_l( env_fx ) ); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ exp = sub( 45, exp ); } #ifdef BASOP_NOGLOB - sharp_fx = add_sat( sharp_fx, shr( step_fx, 1 ) ); + sharp_fx = add_sat( sharp_fx, shr( step_fx, 1 ) ); /*Q14*/ #else sharp_fx = add( sharp_fx, shr( step_fx, 1 ) ); #endif @@ -2504,10 +2512,10 @@ void hq_wb_nf_bwe_fx( { IF( coeff_fx[i] == 0 ) { - tmp1 = Random( bwe_seed ); /*Q15 */ - L_tmp1 = Mult_32_16( L_tmp2, tmp1 ); /*exp exp+15+1 -16 */ - L_tmp1 = L_shl( L_tmp1, sub( 12, exp ) ); - L_coeff_out[i] = L_tmp1; + tmp1 = Random( bwe_seed ); /*Q15 */ + L_tmp1 = Mult_32_16( L_tmp2, tmp1 ); /*exp exp+15+1 -16 */ + L_tmp1 = L_shl( L_tmp1, sub( 12, exp ) ); /*Q12*/ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } @@ -2528,12 +2536,12 @@ void hq_wb_nf_bwe_fx( { tmp1 = Random( bwe_seed ); /*Q15 */ L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ - L_tmp1 = L_shr( L_tmp1, 2 ); /* */ - L_coeff_out[i] = L_tmp1; + L_tmp1 = L_shr( L_tmp1, 2 ); /*Q12 */ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } - L_tmp2 = L_normq_v[sfm]; + L_tmp2 = L_normq_v[sfm]; /*Q14*/ move32(); exp = 14; move16(); @@ -2549,7 +2557,7 @@ void hq_wb_nf_bwe_fx( IF( EQ_16( sfm, sub( SFM_N_WB, 1 ) ) && prev_is_transient == 0 && GT_32( prev_normq_fx[sfm], L_shr( L_normq_v[sfm], 1 ) ) && LT_32( prev_normq_fx[sfm], L_shl( L_normq_v[sfm], 1 ) ) && LE_16( bitalloc_var_fx, 4915 ) ) #endif { - Word32 *p_prev_coeff_out = prev_coeff_out_fx; + Word32 *p_prev_coeff_out = prev_coeff_out_fx; /*Q12*/ FOR( i = add( sfm_start[sfm], 12 ); i < sfm_end[sfm]; i++ ) { test(); @@ -2563,18 +2571,18 @@ void hq_wb_nf_bwe_fx( #endif { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); + L_tmp = L_add_sat( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); /*Q12*/ #else L_tmp = L_add( L_shr( L_abs( L_coeff_out[i] ), 1 ), L_shr( L_abs( *p_prev_coeff_out ), 1 ) ); #endif if ( L_coeff_out[i] <= 0 ) { - L_tmp = L_negate( L_tmp ); + L_tmp = L_negate( L_tmp ); /*Q12*/ } - L_coeff_out[i] = L_tmp; + L_coeff_out[i] = L_tmp; /*Q12*/ move32(); } - p_prev_coeff_out++; + p_prev_coeff_out++; /*Q12*/ } } prev_env_Q[sfm] = exp; @@ -2594,8 +2602,8 @@ void hq_wb_nf_bwe_fx( { tmp1 = Random( bwe_seed ); /*Q15 */ L_tmp1 = Mult_32_16( L_normq_v[sfm], tmp1 ); /*14 14+15+1 -16 */ - L_tmp1 = L_shr( L_tmp1, 2 ); /* */ - L_coeff_out[i] = L_tmp1; + L_tmp1 = L_shr( L_tmp1, 2 ); /*Q12*/ + L_coeff_out[i] = L_tmp1; /*Q12*/ move32(); } } @@ -2604,9 +2612,9 @@ void hq_wb_nf_bwe_fx( set32_fx( prev_env_fx, 0, SFM_N_WB ); } - Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); - Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); - *prev_R = R[SFM_N_WB - 1]; + Copy32( L_normq_v, prev_normq_fx, SFM_N_WB ); /*Q14*/ + Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); /*Q12*/ + *prev_R = R[SFM_N_WB - 1]; /*Q0*/ move16(); return; @@ -2636,7 +2644,7 @@ void enforce_zero_for_min_envelope_fx( { FOR( j = sfm_start[0]; j < sfm_end[0]; j++ ) { - L_coefsq[j] = L_deposit_l( 0 ); + L_coefsq[j] = L_deposit_l( 0 ); /*Q12*/ move32(); } } @@ -2647,7 +2655,7 @@ void enforce_zero_for_min_envelope_fx( { FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) { - L_coefsq[j] = L_deposit_l( 0 ); + L_coefsq[j] = L_deposit_l( 0 ); /*Q12*/ move32(); } } @@ -2680,15 +2688,15 @@ void apply_envelope_enc_ivas_fx( FOR( sfm = 0; sfm < num_sfm; sfm++ ) { - normq = dicn_fx[norm[sfm]]; + normq = dicn_fx[norm[sfm]]; /*Q14*/ move16(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /*Q12*/ + move32(); } } @@ -2731,14 +2739,14 @@ void apply_envelope_fx( test(); if ( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) { - len = add( last_sfm, 1 ); + len = add( last_sfm, 1 ); /*Q0*/ } IF( EQ_16( length, L_FRAME16k ) ) { FOR( sfm = 0; sfm < num_sfm; sfm++ ) { - normq_v[sfm] = dicn_fx[norm[sfm]]; + normq_v[sfm] = dicn_fx[norm[sfm]]; /*Q14*/ move16(); move32(); /*normq = normq_v[sfm] * norm_adj[sfm]; */ @@ -2748,8 +2756,8 @@ void apply_envelope_fx( { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } } @@ -2757,21 +2765,21 @@ void apply_envelope_fx( { FOR( sfm = 0; sfm < len; sfm++ ) { - normq_v[sfm] = dicn_fx[norm[sfm]]; + normq_v[sfm] = dicn_fx[norm[sfm]]; /*Q14*/ move16(); move32(); /*normq_v[sfm] *= norm_adj[sfm]; */ - Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb ); - move32(); /* Q14 (14+15+1-16) */ + Mpy_32_16_ss( normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb ); /* Q14 (14+15+1-16) */ + move32(); - normq = normq_v[sfm]; + normq = normq_v[sfm]; /*Q14*/ move32(); FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) { /*coeff_out[i] = coeff[i]*normq; */ Mpy_32_16_ss( normq, coeff[i], &L_tmp, &lsb ); - coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } @@ -2786,8 +2794,8 @@ void apply_envelope_fx( { /*coeff_out1[i] = coeff_out1[i]*normq; */ Mpy_32_16_ss( normq, coeff1[i], &L_tmp, &lsb ); - coeff_out1[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); - move32(); /* Q12 (14+12+1-16)+1 */ + coeff_out1[i] = L_add( L_shl( L_tmp, 1 ), L_shr( lsb, 15 ) ); /* Q12 (14+12+1-16)+1 */ + move32(); } } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a22e45e87c4aeb373024124b416525a39e7adf05..4296a51fd1751cf926565b9c3992fa3b09dfa574 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -280,6 +280,7 @@ ivas_error pre_proc_ivas( const int32_t last_element_brate, /* i : last element bitrate */ const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ float *ener, /* o : residual energy from Levinson-Durbin */ @@ -290,7 +291,7 @@ ivas_error pre_proc_ivas( float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ - const float old_wsp[], /* i : weighted input signal buffer */ + float old_wsp[], /* i : weighted input signal buffer */ const int16_t loc_harm, /* i : harmonicity flag */ #ifndef IVAS_FLOAT_FIXED const float cor_map_sum, /* i : speech/music clasif. parameter */ @@ -313,32 +314,6 @@ ivas_error pre_proc_ivas( #endif ); -ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ -#ifndef IVAS_FLOAT_FIXED - float A[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ -#else - Word16 A_fx[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_Fx[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ -#endif - float epsP[M + 1], /* i/o: LP prediction errors */ -#ifndef IVAS_FLOAT_FIXED - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ -#else - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ -#endif -); - /*! r: number of clipped samples */ uint32_t ivas_syn_output( float *synth[], /* i/o: float synthesis signal */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 2cf76473c1b3a33bcbf31ce6135ac049b1766374..e0c66f4604f1d1396a04bf2be2aa611ae6ca1caf 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5820,6 +5820,23 @@ ivas_error ivas_mct_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); +ivas_error ivas_compute_core_buffers_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ + Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const Word16 input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 sr_core, /* i : core-coder sampling rate */ + Word32 *ener, /* o : residual energy from Levinson-Durbin */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + Word32 epsP[M + 1], /* i/o: LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + Word16 Q_old_inp_16k, + Word16 Q_r[2] ); + ivas_error ivas_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 *data, /* i : input signal Q0 */ diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 5bc57cc4b2a67c1e6fe646fda15a8e2ec84fb185..f0b9b45e886ed843f58366796b3cf943bdc2f77e 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -534,11 +534,11 @@ void Interpolate_allpass_steep( void Interpolate_allpass_steep_32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ - const int16_t N, /* i : number of input samples */ + const Word16 N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N Qx */ ) { - int16_t n, k; + Word16 n, k; Word32 temp_fx[ALLPASSSECTIONS_STEEP - 1]; #ifdef IVAS_ENH32_CADENCE_CHANGES @@ -890,12 +890,12 @@ void interpolate_3_over_2_allpass( #ifdef IVAS_FLOAT_FIXED void interpolate_3_over_2_allpass_32( const Word32 *input, /* i : input signal Qx*/ - const int16_t len, /* i : number of input samples */ + const Word16 len, /* i : number of input samples */ Word32 *out, /* o : output signal Qx*/ Word32 *mem /* i/o: memory Qx*/ ) { - int16_t i, loop_len; + Word16 i, loop_len; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 out1_buff[L_FRAME32k * 3]; Word32 *out1; diff --git a/lib_com/prot.h b/lib_com/prot.h index 6c5655f991675ba1aa05a4d46ef7e6bbcce03c9c..d0f46467a6f8ed5f4f03e81e39c5deadf7385fd7 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2027,6 +2027,7 @@ void ar_encoder_done( void ar_decoder_done( PARCODEC arInst ); +#ifndef IVAS_FLOAT_FIXED float GetISCScale( float *quants, int16_t size, @@ -2042,6 +2043,7 @@ float GetISCScale( float *abuffer, float *mbuffer, float *sbuffer ); +#endif Word32 Mult_32_16( Word32 a, @@ -2051,13 +2053,16 @@ Word32 Mult_32_32( Word32 a, Word32 b ); +#ifndef IVAS_FLOAT_FIXED void decode_position_ari_fx_ivas( PARCODEC pardec, Word16 size, Word16 npulses, Word16 *nz, Word32 *position ); +#endif +#ifndef IVAS_FLOAT_FIXED void decode_magnitude_usq_fx_ivas( ARCODEC *pardec, Word16 size, @@ -2065,6 +2070,7 @@ void decode_magnitude_usq_fx_ivas( Word16 nzpos, Word32 *positions, Word32 *out ); +#endif void decode_mangitude_tcq_fx_ivas( ARCODEC *pardec, @@ -2086,11 +2092,13 @@ void srt_vec_ind_fx_ivas( Word16 *I, Word16 length ); +#ifndef IVAS_FLOAT_FIXED Word16 GetScale_fx_ivas( Word16 blen, Word32 bits_fx /*Q16*/, Word32 *surplus_fx /*Q16*/ ); +#endif void bit_allocation_second_fx2( Word32 *Rk, @@ -2104,11 +2112,13 @@ void bit_allocation_second_fx2( const Word16 *last_bitalloc, const Word16 input_frame ); +#ifndef IVAS_FLOAT_FIXED Word32 encode_position_ari_fx_ivas( PARCODEC parenc, float *quants, Word16 size, Word32 *est_bits_frame_fx ); +#endif Word32 encode_magnitude_tcq_fx_ivas( ARCODEC *parenc, @@ -2171,8 +2181,10 @@ void tcq_core_LR_dec( const int16_t adjustFlag, const int16_t *is_transient ); +#ifndef IVAS_FLOAT_FIXED void InitLSBTCQ( int16_t *bcount ); +#endif void TCQLSB( int16_t bcount, @@ -3719,12 +3731,8 @@ void find_wsp( ); void pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#else - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#endif - int16_t *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ + int16_t *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ ); @@ -8741,10 +8749,11 @@ ivas_error createFdCngCom_flt( void deleteFdCngCom_flt( HANDLE_FD_CNG_COM *hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); - +#ifndef IVAS_FLOAT_FIXED void initFdCngCom_flt( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ const float scale ); +#endif void initPartitions_flt( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c95597fd73bfc97deeb3c37191cae1e4db705fc8..be0a12fa6a8b85c74a01babdad01092493365304 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8336,15 +8336,15 @@ void hr_bwe_dec_init( // swb_bwe_com_hr_fx.c void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb, /* i : tilt of wideband signal */ - const Word16 pitch, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio, /* i/o: mdct spectrum */ + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb, /* i : tilt of wideband signal Q11 */ + const Word16 pitch, /* i : pitch value Q15 */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio, /* i/o: mdct spectrum Q_audio */ Word16 Q_audio ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index b6e68bd59472ee420219c83293c1baa1b091b6db..1bbd51a5ffaf37d62c0d95d402d52a0745249955 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -402,6 +402,37 @@ typedef struct { FD_CNG_SETUP FdCngSetup; +#ifndef IVAS_FLOAT_FIXED + float timeDomainBuffer_flt[L_FRAME16k]; + float fftBuffer_flt[FFTLEN]; + float olapBufferAna_flt[FFTLEN]; + float olapBufferSynth_flt[FFTLEN]; + float olapBufferSynth2_flt[FFTLEN]; + const float *olapWinAna_flt; + const float *olapWinSyn_flt; + const float *fftSineTab_flt; + float msM_win_flt; + float msM_subwin_flt; + float init_old_flt; + float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ + float msSlope_flt[2]; + float msQeqInvAv_flt[2]; + float msPsdSum_flt[2]; + float msPeriodogSum_flt[2]; + float periodog_flt[PERIODOGLEN]; /* Periodogram */ + float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + float psize_flt[NPART]; /* Partition sizes */ + float psize_inv_flt[NPART]; /* Inverse of partition sizes */ + float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + float scalingFactor_flt; + float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ + float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ + float[NPART]; + float A_cng_flt[M + 1]; + float exc_cng_flt[L_FRAME16k]; + float likelihood_noisy_speech_flt; + float coherence_flt; /* inter-channel coherence of noise */ +#endif Word16 numSlots; /* Number of time slots in CLDFB matrix */ Word16 regularStopBand; /* Number of CLDFB bands to be considered */ @@ -414,29 +445,14 @@ typedef struct Word16 fftlenShift; // Q0 Word16 fftlenFac; // Q0 - float timeDomainBuffer_flt[L_FRAME16k]; Word16 timeDomainBuffer[L_FRAME16k]; /*Q15*/ + Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ + Word32 olapBufferSynth2_fx[FFTLEN]; /*Q_olapBufferSynth2*/ - float fftBuffer_flt[FFTLEN]; - float olapBufferAna_flt[FFTLEN]; - float olapBufferSynth_flt[FFTLEN]; -#ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ -#endif - float olapBufferSynth2_flt[FFTLEN]; -#ifdef IVAS_FLOAT_FIXED - Word32 olapBufferSynth2_fx[FFTLEN]; /*Q_olapBufferSynth2*/ -#endif -#ifndef IVAS_FLOAT_FIXED - const float *olapWinAna_flt; - const float *olapWinSyn_flt; - const float *fftSineTab_flt; -#else - const Word32 *olapWinAna_fx; /* Q30 */ - const Word16 *olapWinSyn_fx; /* Q15 */ - const Word16 *fftSineTab_fx; /* Q15 */ -#endif - Word32 fftBuffer[FFTLEN]; // Q31-fftBuffer_exp + const Word32 *olapWinAna_fx; /* Q30 */ + const Word16 *olapWinSyn_fx; /* Q15 */ + const Word16 *fftSineTab_fx; /* Q15 */ + Word32 fftBuffer[FFTLEN]; // Q31-fftBuffer_exp Word16 fftBuffer_exp; Word16 *olapBufferAna; /* q_olapBufferAna */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ Word16 olapBufferAna_fx[FFTLEN]; /* q_olapBufferAna_fx */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ @@ -445,109 +461,69 @@ typedef struct const PWord16 *olapWinAna; const PWord16 *olapWinSyn; - - float msM_win_flt; - float msM_subwin_flt; Word16 msM_win; // Q8 Word16 msM_subwin; // Q11 Word16 msFrCnt_init_counter; /* Frame counter at initialization */ Word16 msFrCnt_init_thresh; - float init_old_flt; Word16 init_old; // Q15 - Word16 msFrCnt; /* Frame counter */ -#ifndef IVAS_FLOAT_FIXED - float msAlphaCor_flt[2]; /* Correction factor (smoothed) */ - float msSlope_flt[2]; - float msQeqInvAv_flt[2]; -#else - Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ - Word16 msSlope[2]; /* Q14 */ - Word32 msQeqInvAv[2]; /* Q31- msQeqInvAv_exp*/ + Word16 msFrCnt; /* Frame counter */ + Word32 msAlphaCor[2]; /* Correction factor (smoothed) Q31 */ + Word16 msSlope[2]; /* Q14 */ + Word32 msQeqInvAv[2]; /* Q31- msQeqInvAv_exp*/ Word16 msQeqInvAv_exp[2]; -#endif Word16 msMinBufferPtr; - float msPsdSum_flt[2]; - float msPeriodogSum_flt[2]; Word32 msPsdSum[2]; /* 16Q15 */ Word32 msPeriodogSum[2]; /* Q31- msPeriodogSum_exp*/ Word16 msPeriodogSum_exp[2]; // Q0 Word16 offsetflag; - - float periodog_flt[PERIODOGLEN]; /* Periodogram */ - float cngNoiseLevel_flt[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - Word32 periodog[PERIODOGLEN]; /* Periodogram Q31 - periodog_exp*/ - Word16 periodog_exp; // Q0 - Word16 exp_cldfb_periodog; // Q0 + Word32 periodog[PERIODOGLEN]; /* Periodogram Q31 - periodog_exp*/ + Word16 periodog_exp; // Q0 + Word16 exp_cldfb_periodog; // Q0 Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band Q31 - cngNoiseLevelExp*/ - // Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; Word16 seed; /* Seed memory (for random function) */ Word16 seed2; /* Seed for second noise source in MDCT-Stereo DTX */ Word16 seed3; /* Seed for third noise source in MDCT-Stereo DTX */ - Word16 npart; /* Number of partitions */ - Word16 midband[NPART]; /* Central band of each partition */ - Word16 nFFTpart; /* Number of hybrid spectral partitions */ - Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ - float psize_flt[NPART]; /* Partition sizes */ - float psize_inv_flt[NPART]; /* Inverse of partition sizes */ - float FFTscalingFactor_flt; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - float scalingFactor_flt; - Word16 psize[NPART]; /* Partition sizes 6Q9 */ - Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ - Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ - // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; // Q15 - Word16 invScalingFactor; // Q15 - Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ - Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ - float CLDFBpsize_inv_flt[NPARTCLDFB]; /* Inverse of CLDFB partition sizes */ - Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes Q15*/ + Word16 npart; /* Number of partitions */ + Word16 midband[NPART]; /* Central band of each partition */ + Word16 nFFTpart; /* Number of hybrid spectral partitions */ + Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 psize[NPART]; /* Partition sizes 6Q9 */ + Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ + Word16 psize_norm[NPART]; /* Partition sizes, fractional variable Q15-psize_norm_exp*/ + Word16 psize_inv[NPART]; /* Inverse of partition sizes Q15*/ + // Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + Word16 scalingFactor; // Q15 + Word16 invScalingFactor; // Q15 + Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ + Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ + Word16 CLDFBpsize_inv[NPARTCLDFB]; /* Inverse of CLDFB partition sizes Q15*/ Word16 inactive_frame_counter; Word16 sid_frame_counter; Word16 active_frame_counter; /* Active frame counter limited to MSBUFLEN in stereo decoder */ - - float sidNoiseEst_flt[NPART]; /* Transmitted noise level */ - Word32 sidNoiseEst[NPART]; /* Transmitted noise level Q31-sidNoiseEstExp*/ + Word32 sidNoiseEst[NPART]; /* Transmitted noise level Q31-sidNoiseEstExp*/ Word16 sidNoiseEstExp; - - float sidNoiseEstLp_flt[NPART]; Word32 sidNoiseEstLp[NPART]; // Q(31-sidNoiseEstExp) - Word16 frame_type_previous; - - float A_cng_flt[M + 1]; - float exc_cng_flt[L_FRAME16k]; - Word16 A_cng[M + 1]; // Qx - Word16 exc_cng[L_FRAME16k]; // Q_new -#ifdef IVAS_FLOAT_FIXED + Word16 A_cng[M + 1]; // Qx + Word16 exc_cng[L_FRAME16k]; // Q_new Word32 exc_cng_32fx[L_FRAME16k]; // Q_qexc_cng_32fx -#endif Word32 CngBitrate; Word16 CngBandwidth; Word16 flag_noisy_speech; -#ifndef IVAS_FLOAT_FIXED - float likelihood_noisy_speech_flt; -#else - Word16 likelihood_noisy_speech; /* Q15 */ -#endif - -#ifndef IVAS_FLOAT_FIXED - float coherence_flt; /* inter-channel coherence of noise */ -#else - Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ -#endif - Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ + Word16 likelihood_noisy_speech; /* Q15 */ + Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ + Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -705,7 +681,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float scale_flt; #else - Word16 scale; /* Q15 */ + Word16 scale; /* Q15 */ #endif } SCALE_TCX_SETUP; @@ -752,8 +728,8 @@ typedef struct cldfb_filter_bank_struct const float *rot_vec_syn_re; const float *rot_vec_syn_im; #else - const Word32 *rot_vec_syn_re_fx; // Q29 - const Word32 *rot_vec_syn_im_fx; // Q29 + const Word32 *rot_vec_syn_re_fx; // Q29 + const Word32 *rot_vec_syn_im_fx; // Q29 const Word32 *rot_vec_syn_delay_re_fx; // Q31 const Word32 *rot_vec_syn_delay_im_fx; // Q31 diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index d56f1b78492c6673943ec37aac7463f606da4145..08c72e016754548aef7c7d52f6bfc758d9400e03 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -64,18 +64,19 @@ /*==========================================================================*/ Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn, /* i : synthesis scaling */ - Word16 last_extl_fx, /* i : extl. layer for last frame */ - Word16 tilt_wb_fx ) + Word16 *WB_fenv, /* o : WB frequency envelopes Q3 */ + const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal Q_syn */ + const Word16 coder_type, /* i : coding type */ + Word16 prev_coder_type, /* i : coding type of last frame */ + Word16 prev_WB_fenv, /* i : envelope for last frame Q3 */ + Word16 *voice_factors, /* i : voicing factors Q15 */ + const Word16 pitch_buf[], /* i : pitch buffer Q6 */ + Word32 last_core_brate, /* i : previous frame core bitrate */ + Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy Q3 */ + Word16 Q_syn, /* i : synthesis scaling */ + Word16 last_extl_fx, /* i : extl. layer for last frame */ + Word16 tilt_wb_fx /* Q4 */ +) { Word32 enerL; Word16 n_freq, mode, pitch; @@ -89,7 +90,7 @@ Word16 WB_BWE_gain_pred_fx( Word32 L_tmp; Word32 L_WB_fenv0, L_WB_fenv1; Word16 pitch_buf_tmp[4]; - Word16 alfa = 32767; + Word16 alfa = MAX_16; move16(); mode = NORMAL; @@ -133,7 +134,7 @@ Word16 WB_BWE_gain_pred_fx( L_tmp = L_shr( enerL, 4 ); test(); - IF( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856, pitch ) ) + if ( GT_32( L_max( L_WB_fenv1, L_WB_fenv0 ), L_tmp ) && GT_16( 9856 /* 308 in Q5 */, pitch ) ) { ener_var_flag = 1; move16(); @@ -148,11 +149,11 @@ Word16 WB_BWE_gain_pred_fx( { exp = norm_l( L_WB_fenv0 ); tmp = extract_h( L_shl( L_WB_fenv0, exp ) ); - tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */ L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv1, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ /*L_tmp Q15 */ tmp = extract_l( L_tmp ); - alfa = s_max( tmp, 3277 ); /*Q15 */ + alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */ L_WB_fenv0 = Mult_32_16( L_WB_fenv0, alfa ); /*2*Q_syn+15-15->2*Q_syn */ } #ifdef BASOP_NOGLOB @@ -163,11 +164,11 @@ Word16 WB_BWE_gain_pred_fx( { exp = norm_l( L_WB_fenv1 ); tmp = extract_h( L_shl( L_WB_fenv1, exp ) ); - tmp = div_s( 16384, tmp ); /*Q(15+14-2*Q_syn-exp) */ + tmp = div_s( 16384 /* 1 in Q14 */, tmp ); /*Q(15+14-2*Q_syn-exp) */ L_tmp = L_shr( Mult_32_16( L_shl( L_WB_fenv0, 1 ), tmp ), sub( 15, exp ) ); /*2*Q_syn+15+exp-15->2*Q_syn+exp */ /*L_tmp Q15 */ tmp = extract_l( L_tmp ); - alfa = s_max( tmp, 3277 ); /*Q15 */ + alfa = s_max( tmp, 3277 /* 0.1 in Q15 */ ); /*Q15 */ L_WB_fenv1 = Mult_32_16( L_WB_fenv1, alfa ); /*2*Q_syn+15-15->2*Q_syn */ } @@ -211,9 +212,9 @@ Word16 WB_BWE_gain_pred_fx( IF( NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && ener_var_flag == 0 ) { #ifdef BASOP_NOGLOB - WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 ) ); + WB_fenv[0] = add_sat( WB_fenv[0], mult_r_sat( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); #else - WB_fenv[0] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); + WB_fenv[0] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); #endif move16(); } @@ -230,7 +231,7 @@ Word16 WB_BWE_gain_pred_fx( #else enerL_16 = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /* Q0 */ #endif - enerL_40 = mult_r( 6554, enerL_16 ); /*1/40 in Q18 ->Q3 */ + enerL_40 = mult_r( 6554 /* 0.2 in Q15 */, enerL_16 ); /*1/40 in Q18 ->Q3 */ test(); test(); @@ -239,7 +240,7 @@ Word16 WB_BWE_gain_pred_fx( test(); test(); IF( NE_16( coder_type, TRANSITION ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, UNVOICED ) && - GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) ) + GT_16( enerL_40, WB_fenv[0] ) && GT_16( alfa, 29491 /*0.9 in Q15*/ ) && !( EQ_16( coder_type, prev_coder_type ) && GT_16( WB_fenv[0], prev_WB_fenv ) ) ) { IF( WB_fenv[0] != 0 ) { @@ -251,7 +252,7 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min( tmp, 16384 ); + tmp = s_min( tmp, 16384 /*4 in Q12*/ ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q15 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ move16(); @@ -260,7 +261,7 @@ Word16 WB_BWE_gain_pred_fx( IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.5 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */ move16(); } } @@ -276,8 +277,8 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, add( exp, 6 ) ) ); /*14 */ #endif - tmp1 = s_max( tmp, 8192 ); - alfa = s_min( 24576, tmp1 ); /*Q14 */ + tmp1 = s_max( tmp, 8192 /* 0.5 in Q14 */ ); + alfa = s_min( 24576 /* 1.5 in Q14 */, tmp1 ); /*Q14 */ L_tmp = L_mult0( alfa, WB_fenv[0] ); /*Q14+Q3->Q17 */ L_tmp = L_shr( L_tmp, 14 ); /*Q3 */ @@ -309,14 +310,14 @@ Word16 WB_BWE_gain_pred_fx( #else tmp = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q12 */ #endif - tmp = s_min( tmp, 16384 ); + tmp = s_min( tmp, 16384 /*4 in Q12*/ ); L_tmp = L_shr( L_mult0( tmp, WB_fenv[0] ), 12 ); /*Q3 */ WB_fenv[0] = extract_l( L_tmp ); /*Q3 */ move16(); IF( GT_16( WB_fenv[0], prev_WB_fenv ) ) { /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 9830, WB_fenv[0] ), 22938, prev_WB_fenv ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 9830 /* 0.3 in Q15 */, WB_fenv[0] ), 22938 /* 0.7 in Q15 */, prev_WB_fenv ) ); /*Q3 */ move16(); } } @@ -330,18 +331,18 @@ Word16 WB_BWE_gain_pred_fx( IF( NE_16( coder_type, AUDIO ) ) { - tmp = mult_r( voice_factor, 19661 ); /*Q12 */ - tmp = s_max( tmp, 4096 ); + tmp = mult_r( voice_factor, 19661 /* 1.2 in Q14 */ ); /*Q12 */ + tmp = s_max( tmp, 4096 /* 1 in Q12 */ ); exp = norm_s( tmp ); tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*Q(29-exp-12) */ L_tmp = L_mult( WB_fenv[0], tmp ); /*Q(21-exp) */ WB_fenv[0] = round_fx( L_shl( L_tmp, sub( exp, 2 ) ) ); /*Q3 */ move16(); - tmp1 = mult_r( 328, pitch ); /*Q7 */ - tmp = s_min( s_max( tmp1, 16 ), 256 ); /*Q7 */ - L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ + tmp1 = mult_r( 328 /* (1/400) in Q17 */, pitch ); /*Q7 */ + tmp = s_min( s_max( tmp1, 16 /* 0.125 in Q7 */ ), 256 /* 1 in Q7 */ ); /*Q7 */ + L_tmp = L_shr( L_mult0( WB_fenv[0], tmp ), 7 ); /*Q3 */ + /*WB_fenv[0] = saturate(L_tmp); //Q3 */ #ifdef BASOP_NOGLOB WB_fenv[0] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Q3 */ move16(); @@ -353,21 +354,21 @@ Word16 WB_BWE_gain_pred_fx( IF( GT_32( last_core_brate, ACELP_8k00 ) && GT_16( WB_fenv[0], last_wb_bwe_ener ) ) { /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ - WB_fenv[0] = round_fx( L_mac( L_mult( 29491, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ + WB_fenv[0] = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, last_wb_bwe_ener ), 3277, WB_fenv[0] ) ); /*Q3 */ move16(); } - IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 ) ) + IF( NE_16( last_extl_fx, WB_BWE ) && LT_16( tilt_wb_fx, 128 /* 8 in Q4 */ ) ) { - WB_fenv[0] = mult_r( s_min( 16384, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); + WB_fenv[0] = mult_r( s_min( 16384 /* 0.5 in Q15 */, shl( tilt_wb_fx, 8 ) ), WB_fenv[0] ); move16(); } IF( EQ_16( env_var_flag, 1 ) ) { - WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 ) ); + WB_fenv[1] = add( WB_fenv[0], mult_r( WB_fenv[0], 16384 /* 0.5 in Q15 */ ) ); move16(); - WB_fenv[0] = mult_r( 24576, WB_fenv[0] ); + WB_fenv[0] = mult_r( 24576 /* 0.75 in Q15 */, WB_fenv[0] ); move16(); /*Q3 */ } ELSE @@ -471,9 +472,9 @@ static void calc_norm_envelop_lf_fx( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); + L_tmp = L_add_sat( L_tmp, L_abs( SWB_signal[n_freq - lookback + n_lag] ) ); #else - L_tmp = L_add( L_tmp, L_abs( SWB_signal[add( sub( n_freq, lookback ), n_lag )] ) ); + L_tmp = L_add( L_tmp, L_abs( SWB_signal[n_freq - lookback + n_lag] ) ); #endif } @@ -490,12 +491,12 @@ static void calc_norm_envelop_lf_fx( *-------------------------------------------------------------------*/ void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + const Word16 core, /* i : core */ + const Word16 *sp, /* i : input signal Q_syn */ + const Word16 mode, /* i : input mode */ + const Word16 extl, /* i : extension layer */ + Word16 *L_swb_norm, /* o : normalize length */ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ Word16 Q_syn ) { Word16 i, n_freq, n_band, THRES; @@ -562,8 +563,8 @@ void calc_normal_length_fx( IF( EQ_16( core, ACELP_CORE ) ) { - L_swb_norm_trans = add( 4, mult( n_band, 8192 ) ); - L_swb_norm_norm = add( 8, mult( n_band, 16384 ) ); + L_swb_norm_trans = add( 4, mult( n_band, 8192 /* 0.25 in Q15 */ ) ); + L_swb_norm_norm = add( 8, mult( n_band, 16384 /* 0.5 in Q15 */ ) ); L_tmp = L_add( 65536, L_mult0( n_band, 4096 ) ); /*Q16 */ L_swb_norm_harm = s_max( round_fx( L_shl( L_tmp, 5 ) ), 24 ); /* Q0 */ @@ -593,7 +594,7 @@ void calc_normal_length_fx( test(); IF( EQ_16( mode, HQ_HARMONIC ) || EQ_16( mode, HQ_HVQ ) ) { - L_tmp = L_add( 65536, L_mult( n_band, 2560 ) ); + L_tmp = L_add( 65536, L_mult( n_band, 2560 /* 2.5 in Q10*/ ) ); L_swb_norm_cur = round_fx( L_shl( L_tmp, 5 ) ); /*Q0 */ } ELSE @@ -603,7 +604,7 @@ void calc_normal_length_fx( } /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ - *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 ), *prev_L_swb_norm, 29491 ) ); + *L_swb_norm = round_fx( L_mac( L_mult( L_swb_norm_cur, 3277 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ) ); move16(); *prev_L_swb_norm = L_swb_norm_cur; move16(); @@ -617,10 +618,10 @@ void calc_normal_length_fx( * calculate tilt parameter *-------------------------------------------------------------------*/ -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word16 *sp, /* i : input signal Q(15 - exp_sp) */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -648,20 +649,20 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* Divide Frame Length by 32 */ FOR( j = shr( N, 5 ); j > 0; j-- ) { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ +#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ + tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */ #else - tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ + tmp1 = mult_r( *ptr++, 8192 /*0.25 in Q15 */ ); /* Divide by 4 */ #endif L_ener = L_mult0( tmp1, tmp1 ); /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ FOR( i = 1; i < 32; i++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - tmp1 = mult_ro( *ptr++, 8192, &Overflow ); /* Divide by 4 */ +#ifdef BASOP_NOGLOB /* Critical Overflow */ + tmp1 = mult_ro( *ptr++, 8192 /*0.25 in Q15 */, &Overflow ); /* Divide by 4 */ L_ener = L_mac0_o( L_ener, tmp1, tmp1, &Overflow ); #else - tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ + tmp1 = mult_r( *ptr++, 8192 ); /* Divide by 4 */ L_ener = L_mac0( L_ener, tmp1, tmp1 ); #endif } @@ -743,10 +744,10 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ return L_temp; } #ifdef IVAS_FLOAT_FIXED -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ + const Word32 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal Q(15 - exp_sp) */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -855,7 +856,7 @@ Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ void calc_norm_envelop_fx( const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ + const Word16 L_swb_norm, /* i : length of envelope Q0 */ const Word16 SWB_flength, /* i : Length of input/output */ const Word16 st_offset /* i : offset */ ) @@ -1005,11 +1006,11 @@ void WB_BWE_decoding_fx( IF( NE_16( mode, HARMONIC ) ) { tmp = add( shl( inv_L_wb_norm, 1 ), inv_L_wb_norm ); - weight = s_max( s_min( tmp, 16384 ), 8192 ); + weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 8192 /*0.25 in Q15 */ ); } ELSE { - weight = 8192; + weight = 8192; /*0.25 in Q15 */ move16(); } FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) @@ -1113,7 +1114,7 @@ void WB_BWE_decoding_fx( } EnergyL = L_deposit_l( 0 ); - IF( core_type == 1 ) + IF( EQ_16( core_type, 1 ) ) { test(); IF( NE_16( prev_coder_type, AUDIO ) && LE_32( total_brate, ACELP_8k00 ) ) @@ -1290,17 +1291,17 @@ void WB_BWE_decoding_fx( test(); IF( EQ_16( last_extl, WB_BWE ) && GT_32( EnergyL, L_shr( *prev_Energy, 1 ) ) && GT_32( *prev_Energy, L_shr( EnergyL, 1 ) ) ) { - L_tmp1 = L_mac( L_mult( 8192, wfenv[0] ), 12288, prev_WB_fenv[0] ); - wfenv[0] = round_fx( L_mac( L_tmp1, 12288, prev_WB_fenv[1] ) ); + L_tmp1 = L_mac( L_mult( 8192 /* 0.25 in Q15 */, wfenv[0] ), 12288 /* 0.375 in Q15 */, prev_WB_fenv[0] ); /* Q3 */ + wfenv[0] = round_fx( L_mac( L_tmp1, 12288 /* 0.375 in Q15 */, prev_WB_fenv[1] ) ); /* Q3 */ } FOR( n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++ ) { WB_signal_32[n_freq] = Mult_32_16( WB_signal_32[n_freq], wfenv[0] ); move32(); /* Q_syn+3+1 */ } - prev_WB_fenv[0] = wfenv[0]; + prev_WB_fenv[0] = wfenv[0]; /* Q3 */ move16(); - prev_WB_fenv[1] = wfenv[0]; + prev_WB_fenv[1] = wfenv[0]; /* Q3 */ move16(); } @@ -1312,9 +1313,9 @@ void WB_BWE_decoding_fx( FOR( n_freq = 0; n_freq < 16; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 1638 ) ); /*Q15 */ - tmp2 = add( 6554, tmp1 ); /*Q15 */ - L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ + tmp1 = extract_l( L_mult0( n_freq, 1638 /* 0.05 in Q15 */ ) ); /*Q15 */ + tmp2 = add( 6554 /* 0.2 in Q15 */, tmp1 ); /*Q15 */ + L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; move32(); } @@ -1324,7 +1325,7 @@ void WB_BWE_decoding_fx( pit1 = &WB_signal_32[280]; FOR( n_freq = 0; n_freq < 40; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 655 ) ); /*Q15 */ + tmp1 = extract_l( L_mult0( n_freq, 655 /* 0.02 in Q15 */ ) ); /*Q15 */ tmp2 = sub( 32767, tmp1 ); L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; @@ -1336,7 +1337,7 @@ void WB_BWE_decoding_fx( pit1 = &WB_signal_32[300]; FOR( n_freq = 0; n_freq < 20; n_freq++ ) { - tmp1 = extract_l( L_mult0( n_freq, 1311 ) ); /*Q15 */ + tmp1 = extract_l( L_mult0( n_freq, 1311 /* 0.04 in Q15 */ ) ); /*Q15 */ tmp2 = sub( 32767, tmp1 ); L_tmp1 = Mult_32_16( *pit1, tmp2 ); /*Q_syn+3+1 */ *( pit1++ ) = L_tmp1; @@ -1516,7 +1517,7 @@ void SWB_BWE_decoding_fx( exp = norm_l( envelope[n_freq] ); tmp = extract_h( L_shl( envelope[n_freq], exp ) ); exp = sub( sub( 30, exp ), Q_syn ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+exp) */ L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /*Q15 */ SWB_signal[n_freq] = extract_l( L_tmp ); /*Q15 */ move16(); @@ -1590,7 +1591,7 @@ void SWB_BWE_decoding_fx( move16(); } - *prev_weight = 16384; + *prev_weight = 16384 /* 0.5 in Q15 */; move16(); } ELSE @@ -1622,21 +1623,23 @@ void SWB_BWE_decoding_fx( #endif } + test(); IF( NE_16( last_extl, SWB_BWE ) && NE_16( last_extl, FB_BWE ) ) { - IF( Energy_16 < shr( EnergyL_16, 4 ) && EQ_16( extl, FB_BWE ) ) + test(); + IF( LT_16( Energy_16, shr( EnergyL_16, 4 ) ) && EQ_16( extl, FB_BWE ) ) { FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], 6554 /* 0.2 in Q15 */ ); move16(); } - fenvL_16 = mult_r( fenvL_16, 6554 ); + fenvL_16 = mult_r( fenvL_16, 6554 /* 0.2 in Q15 */ ); } Copy( SWB_fenv, prev_SWB_fenv, SWB_FENV ); } - IF( mode == HARMONIC ) + IF( EQ_16( mode, HARMONIC ) ) { Copy( core_dec_freq, &SWB_signal[240 + st_offset], 240 ); Copy( &core_dec_freq[128], &SWB_signal[480 + st_offset], 80 ); @@ -1651,9 +1654,9 @@ void SWB_BWE_decoding_fx( test(); test(); test(); - IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) || - GT_16( tilt_nb, 24576 ) ) && - GT_16( Energy_16, 600 ) && GT_16( fenvL_16, 200 ) ) ) + IF( EQ_16( mode, NOISE ) || ( ( GT_16( Energy_16, EnergyL_16 ) || ( GT_16( tilt_nb, 14336 /*7 in Q11*/ ) && GT_16( Energy_16, shr( EnergyL_16, 1 ) ) ) || + GT_16( tilt_nb, 24576 /*12 in Q11*/ ) ) && + GT_16( Energy_16, 600 /* 75 in Q3*/ ) && GT_16( fenvL_16, 200 /* 25 in Q3*/ ) ) ) { tmp = add( swb_bwe_subband[SWB_FENV], st_offset ); FOR( n_freq = add( swb_bwe_subband[0], st_offset ); n_freq < tmp; n_freq++ ) @@ -1674,16 +1677,16 @@ void SWB_BWE_decoding_fx( /* modify SHB frequency envelopes when SHB spectrum is unflat */ FOR( n_band = 0; n_band < 13; n_band++ ) { - IF( GT_16( mult_r( SWB_fenv[n_band], 29491 ), SWB_fenv[n_band + 1] ) ) + IF( GT_16( mult_r( SWB_fenv[n_band], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band + 1] ) ) { - tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ SWB_fenv[n_band + 1] = mult_r( SWB_fenv[n_band + 1], tmp ); move16(); /*Q1 */ } - IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 ), SWB_fenv[n_band] ) ) + IF( GT_16( mult_r( SWB_fenv[n_band + 1], 29491 /* 0.9 in Q15 */ ), SWB_fenv[n_band] ) ) { - tmp = extract_l( L_mac0( 26214, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ + tmp = extract_l( L_mac0( 26214 /* 0.8 in Q15 */, n_band, 492 ) ); /*Q15; 0.015 in Q15 = 492 */ SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); move16(); /*Q1 */ } @@ -1703,7 +1706,7 @@ void SWB_BWE_decoding_fx( move16(); test(); - IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15*/ ) ) ) ) { tmp3 = 9830; move16(); /*0.3 in Q15 */ @@ -1713,9 +1716,9 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #endif } } @@ -1734,7 +1737,7 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15*/ ); /*Q15 */ #else tmp3 = add( tmp3, 3277 ); /*Q15 */ #endif @@ -1743,7 +1746,7 @@ void SWB_BWE_decoding_fx( pit1 = &SWB_signal[367 + st_offset]; - IF( GT_16( mult_r( tmp1, 6554 ), tmp2 ) ) + IF( GT_16( mult_r( tmp1, 6554 /*0.2 in Q15*/ ), tmp2 ) ) { /*20480 = 5 in Q12 */ FOR( tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048 ) @@ -1768,7 +1771,7 @@ void SWB_BWE_decoding_fx( pit1 = &SWB_signal[496 + st_offset]; test(); - IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 ) ) ) ) + IF( ( tmp2 == 0 ) || ( LT_16( tmp2, mult_r( tmp1, 9830 /* 0.3 in Q15 */ ) ) ) ) { tmp3 = 9830; move16(); /*0.3 in Q15 */ @@ -1778,9 +1781,9 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #endif } } @@ -1799,24 +1802,24 @@ void SWB_BWE_decoding_fx( move16(); /*Q_syn */ pit1++; #ifdef BASOP_NOGLOB - tmp3 = add_sat( tmp3, 3277 ); /*Q15 */ + tmp3 = add_sat( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #else - tmp3 = add( tmp3, 3277 ); /*Q15 */ + tmp3 = add( tmp3, 3277 /* 0.1 in Q15 */ ); /*Q15 */ #endif } } pit1 = &SWB_signal[495 + st_offset]; - L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */ - L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q17 */ + L_tmp3 = L_deposit_h( tmp1 ); /*Q17 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15*/ ); /*Q17 */ exp = 14; move16(); IF( tmp2 != 0 ) { exp = norm_s( tmp2 ); - tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */ - L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ - L_tmp4 = Mult_32_16( L_tmp3, 1638 ); /*Q(30-exp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), tmp2 ); /*Q(29-exp) */ + L_tmp3 = L_shr( L_mult( tmp1, tmp ), 1 ); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ + L_tmp4 = Mult_32_16( L_tmp3, 1638 /* 0.05 in Q15 */ ); /*Q(30-exp) */ } L_tmp1 = L_shl( 1L, sub( 30, exp ) ); @@ -1844,15 +1847,15 @@ void SWB_BWE_decoding_fx( IF( NE_16( mode, HARMONIC ) ) { tmp = add( shl( inv_L_swb_norm, 1 ), inv_L_swb_norm ); - weight = s_max( s_min( tmp, 16384 ), 6554 ); + weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); } ELSE { - weight = 6554; + weight = 6554; /* 0.2 in Q15 */ move16(); } - weight = mac_r( L_mult( 13107, weight ), 19661, ( *prev_weight ) ); + weight = mac_r( L_mult( 13107 /* 0.4 in Q15 */, weight ), 19661 /* 0.6 in Q15 */, ( *prev_weight ) ); FOR( n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++ ) { @@ -1892,7 +1895,7 @@ void SWB_BWE_decoding_fx( exp = norm_l( envelope[n_freq] ); tmp = extract_h( L_shl( envelope[n_freq], exp ) ); exp = sub( sub( 30, exp ), Q_syn ); - tmp = div_s( 16384, tmp ); /* Q(15+exp) */ + tmp = div_s( 16384 /* 0.5 in Q15*/, tmp ); /* Q(15+exp) */ L_tmp = L_shr( L_mult0( SWB_signal[n_freq], tmp ), add( exp, Q_syn ) ); /* Q15 */ SWB_signal[n_freq] = extract_l( L_tmp ); move16(); /* Q15 */ @@ -1911,7 +1914,7 @@ ELSE exp = norm_s( L_swb_norm ); tmp = shl( div_s( shl( 1, sub( 14, exp ) ), L_swb_norm ), sub( exp, 14 ) ); /* Q15 */ tmp = add( shl( tmp, 1 ), tmp ); - *prev_weight = s_max( s_min( tmp, 16384 ), 6554 ); /* Q15 */ + *prev_weight = s_max( s_min( tmp, 16384 /* 0.5 in Q15 */ ), 6554 /* 0.2 in Q15 */ ); /* Q15 */ move16(); } @@ -1927,13 +1930,13 @@ IF( EQ_16( mode, HARMONIC ) ) L_mean = L_add( L_mean, abs_s( *pit1 ) ); /*Q15 */ pit1++; } - mean = extract_l( Mult_32_16( L_mean, 2048 ) ); /*Q15 */ + mean = extract_l( Mult_32_16( L_mean, 2048 /* 1/16 in Q15 */ ) ); /*Q15 */ pit1 -= 16; FOR( n_freq = 0; n_freq < 16; n_freq++ ) { IF( LT_16( abs_s( *pit1 ), mean ) ) { - *pit1 = mult_r( *pit1, 6554 ); /*Q15*/ + *pit1 = mult_r( *pit1, 6554 /* 0.2 in Q15 */ ); /*Q15*/ move16(); } pit1++; @@ -2023,15 +2026,15 @@ IF( GT_16( tmp, 4 ) ) tmp = 12; move16(); factor = fenvL_16; - move16(); /*Q3 */ - factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 ); /*Q3 */ + move16(); /*Q3 */ + factor1 = mult_r( sub( shl( wfenv, 2 ), fenvL_16 ), 4096 /* 0.125 in Q15 */ ); /*Q3 */ } ELSE { tmp = 14; move16(); - factor = shr( fenvL_16, 2 ); /*Q1 */ - factor1 = mult_r( sub( wfenv, factor ), 4096 ); /*Q1 */ + factor = shr( fenvL_16, 2 ); /*Q1 */ + factor1 = mult_r( sub( wfenv, factor ), 4096 /* 0.125 in Q15 */ ); /*Q1 */ } tmp2 = add( add( swb_bwe_subband[0], 8 ), st_offset ); @@ -2131,7 +2134,7 @@ FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */ FOR( n_freq = 0; n_freq < 4; n_freq++ ) { - L_tmp1 = Mult_32_16( *pit1_32, 16384 ); /*15+Qsyn */ + L_tmp1 = Mult_32_16( *pit1_32, 16384 /* 0.5 in Q15 */ ); /*15+Qsyn */ *( pit1_32++ ) = L_tmp1; move32(); } @@ -2209,9 +2212,9 @@ void time_envelop_shaping_fx( test(); #ifdef BASOP_NOGLOB - IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) ) + IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl_sat( SWB_tenv[i], sub( 16, exp ) ) ) ) #else - IF( LT_32( SWB_tenv[i], 65536 ) && LT_32( Energy, L_shl( SWB_tenv[i], sub( 16, exp ) ) ) ) + IF( LT_32( SWB_tenv[i], 65536 /* 2 in Q15 */ ) && LT_32( Energy, L_shl( SWB_tenv[i], sub( 16, exp ) ) ) ) #endif { *Q_synth = add( *Q_synth, 3 ); @@ -2323,8 +2326,8 @@ void time_reduce_pre_echo_fx( FOR( i = 0; i < 3; i++ ) { - L_tmp = Mult_32_16( energyL[i], 29491 ); /*Q14 */ - IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 ) ) + L_tmp = Mult_32_16( energyL[i], 29491 /* 0.9 in Q15 */ ); /*Q14 */ + IF( GT_32( L_shr( energyL[i + 1], 1 ), L_tmp ) && GT_32( energyL[i + 1], 1638400 /* 100 in Q14 */ ) ) { pos = add( i, 1 ); move16(); @@ -2367,7 +2370,7 @@ void time_reduce_pre_echo_fx( energy_16 = round_fx( L_shl( energy, sub( exp, 15 ) ) ); /*Q0 */ } - tmp = mult_r( energy_16, 6554 ); /*Q0 */ + tmp = mult_r( energy_16, 6554 /* 0.2 in Q15 */ ); /*Q0 */ if ( LT_16( prev_td_energy, tmp ) ) { prev_td_energy = tmp; @@ -2525,7 +2528,7 @@ void calc_normal_length_fx_32( L_tmp1 = Mult_32_16( peak, shl( add( 15, THRES ), 10 ) ); L_tmp2 = Mult_32_16( mean, shl( THRES, 10 ) ); test(); - IF( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 ) ) + IF( GT_32( L_tmp1, L_tmp2 ) && GT_32( peak, 40960 /* 10 in Q12 */ ) ) { n_band = add( n_band, 1 ); } @@ -2570,7 +2573,7 @@ void calc_normal_length_fx_32( L_swb_norm_cur = add( 8, shr( n_band, 1 ) ); } - *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 ), *prev_L_swb_norm, 29491 ), 32768 ) ); + *L_swb_norm = extract_h( L_add( L_mac( L_mult( L_swb_norm_cur, 3276 /* 0.1 in Q15 */ ), *prev_L_swb_norm, 29491 /* 0.9 in Q15 */ ), 32768 /* 1 in Q15 */ ) ); *prev_L_swb_norm = L_swb_norm_cur; move16(); move16(); @@ -2609,9 +2612,9 @@ void calc_norm_envelop_fx_32( FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { #ifdef BASOP_NOGLOB - envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + envelope_fx[env_index] = L_add_sat( envelope_fx[env_index], L_abs( SWB_signal_fx[n_freq + n_lag] ) ); #else - envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + envelope_fx[env_index] = L_add( envelope_fx[env_index], L_abs( SWB_signal_fx[n_freq + n_lag] ) ); #endif move32(); } @@ -2630,7 +2633,7 @@ void calc_norm_envelop_fx_32( L_tmp = L_deposit_l( 0 ); FOR( n_lag = 0; n_lag < n_lag_now; n_lag++ ) { - L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[add( n_freq, n_lag )] ) ); + L_tmp = L_add( L_tmp, L_abs( SWB_signal_fx[n_freq + n_lag] ) ); } envelope_fx[env_index] = L_tmp; move32(); @@ -2941,23 +2944,23 @@ void hq_generic_decoding_fx( } } - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH0, hq_generic_offset )], HQ_GENERIC_LEN0 ); - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 ); IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )], sub( HQ_GENERIC_END_FREQ, HQ_GENERIC_HIGH2 ) ); + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); } IF( EQ_16( HQ_mode, HQ_GEN_FB ) ) { IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - Copy32( &coeff_out1_fx[sub( add( HQ_GENERIC_LOW0, HQ_GENERIC_END_FREQ ), HQ_GENERIC_HIGH2 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 ); } ELSE { - Copy32( &coeff_out1_fx[add( HQ_GENERIC_OFFSET, HQ_GENERIC_LEN0 )], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 ); } } @@ -2966,11 +2969,11 @@ void hq_generic_decoding_fx( L_tmp2 = L_deposit_l( 0 ); FOR( i = 0; i < 5; ++i ) { - L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH1, hq_generic_offset ), i )] ) ); - L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[sub( add( sub( HQ_GENERIC_HIGH1, 2 ), hq_generic_offset ), i )] ) ); + L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ) ); + L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ) ); } - pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH1, hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); L_tmp2 = L_max( L_tmp2, 1 ); exp1 = norm_l( L_tmp1 ); @@ -2980,9 +2983,9 @@ void hq_generic_decoding_fx( tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ - if ( LT_16( tmp3_fx, 307 ) ) + if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) ) { - tmp3_fx = 307; + tmp3_fx = 307 /*0.3 in Q10 */; move16(); } FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) @@ -2992,7 +2995,7 @@ void hq_generic_decoding_fx( pit1_fx++; } - pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH1, 1 ), hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset]; exp1 = sub( norm_l( L_tmp1 ), 1 ); exp2 = norm_l( L_tmp2 ); @@ -3014,11 +3017,11 @@ void hq_generic_decoding_fx( IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { - L_tmp1 = L_add( L_abs( coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )] ), L_abs( coeff_out_fx[add( add( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ); - L_tmp2 = L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 4 ), hq_generic_offset )] ), L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 3 ), hq_generic_offset )] ), - L_add( L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 2 ), hq_generic_offset )] ), L_abs( coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )] ) ) ) ); + L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) ); + L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ), + L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) ); - pit1_fx = &coeff_out_fx[add( HQ_GENERIC_HIGH2, hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); L_tmp2 = L_max( L_tmp2, 1 ); @@ -3032,9 +3035,9 @@ void hq_generic_decoding_fx( #else tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ #endif - if ( LT_16( tmp3_fx, 307 ) ) + if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) ) { - tmp3_fx = 307; + tmp3_fx = 307; /* 0.3 in Q10*/ move16(); } FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) @@ -3044,7 +3047,7 @@ void hq_generic_decoding_fx( move32(); } - pit1_fx = &coeff_out_fx[add( sub( HQ_GENERIC_HIGH2, 1 ), hq_generic_offset )]; + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset]; exp1 = sub( norm_l( L_tmp1 ), 1 ); exp2 = norm_l( L_tmp2 ); @@ -3053,8 +3056,8 @@ void hq_generic_decoding_fx( tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ tmp3_fx = shr( tmp3_fx, 1 ); - tmp4_fx = mult_r( tmp3_fx, 1638 ); - WHILE( tmp3_fx > 1024 ) + tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ ); + WHILE( tmp3_fx > 1024 /* 1 in Q10*/ ) { #ifdef EVS_FUNC_MODIFIED L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ @@ -3092,10 +3095,10 @@ void hq_generic_decoding_fx( k = sub( nenv, 2 ); FOR( n_band = 0; n_band < k; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[add( n_band, 1 )]; + wfenv_fx = hq_generic_fenv_fx[n_band + 1]; move16(); /*1 */ - tmp2 = swb_bwe_sm_subband[add( n_band, 1 )] + hq_generic_offset; + tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset; FOR( i = 0; n_freq < tmp2; i++ ) { L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */ @@ -3111,14 +3114,14 @@ void hq_generic_decoding_fx( } } - wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; move16(); /*1 */ - tmp2 = add( swb_bwe_sm_subband[sub( nenv, 1 )], hq_generic_offset ); + tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset ); FOR( i = 0; n_freq < tmp2; i++ ) { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[sub( nenv, 2 )] ), smooth_factor_fx[sub( nenv, 2 )] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[sub( nenv, 2 )], 11 ) ); /*12 */ + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */ cs = norm_l( L_tmp1 ); tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ @@ -3134,7 +3137,7 @@ void hq_generic_decoding_fx( { wfenv_fx = hq_generic_fenv_fx[n_band]; move16(); /*1 */ - tmp2 = add( swb_bwe_subband[add( n_band, 1 )], hq_generic_offset ); + tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); FOR( ; n_freq < tmp2; n_freq++ ) { L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ @@ -3146,9 +3149,9 @@ void hq_generic_decoding_fx( ELSE { test(); - IF( hq_generic_fenv_fx[sub( nenv, 1 )] - hq_generic_fenv_fx[nenv] > 30 || hq_generic_fenv_fx[nenv] < 10 ) + IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) ) { - wfenv_fx = hq_generic_fenv_fx[sub( nenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; move16(); /*1 */ FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ ) { @@ -3160,9 +3163,9 @@ void hq_generic_decoding_fx( FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[add( n_band, nenv )]; + wfenv_fx = hq_generic_fenv_fx[n_band + nenv]; move16(); /*1 */ - tmp2 = fb_bwe_subband[add( n_band, 1 )]; + tmp2 = fb_bwe_subband[n_band + 1]; FOR( i = 0; n_freq < tmp2; i++ ) { L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ @@ -3176,14 +3179,14 @@ void hq_generic_decoding_fx( { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - wfenv_fx = hq_generic_fenv_fx[sub( add( n_band, nenv ), 1 )]; + wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1]; move16(); /*1 */ FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ ) { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[add( n_band, nenv )] ), fb_smooth_factor_fx[n_band] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[add( n_band, nenv )], 10 ) ); /*11 */ + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */ cs = norm_l( L_tmp1 ); tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */ @@ -3194,7 +3197,7 @@ void hq_generic_decoding_fx( } } - wfenv_fx = hq_generic_fenv_fx[sub( tenv, 1 )]; + wfenv_fx = hq_generic_fenv_fx[tenv - 1]; move16(); /*1 */ FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ ) diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index cac0ed123cd0d564bd19cd0b8ad47764dca36ea0..7755ec697b57343c855cfa39f012147fba2cc310 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -12,11 +12,11 @@ * SWB BWE HR noise filling of zero subbands *-------------------------------------------------------------------*/ static void swb_hr_nonzero_subband_noise_fill_fx( - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - const Word16 N, /* i : length of subband */ - const Word16 Nsv, /* i : number of subband */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal Q11 */ + Word16 *t_audio_fx, /* i/o: mdct spectrum Q_audio */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + const Word16 N, /* i : length of subband */ + const Word16 Nsv, /* i : number of subband */ Word16 Q_audio ) { Word16 i, j; @@ -24,18 +24,18 @@ static void swb_hr_nonzero_subband_noise_fill_fx( Word16 min_bwe_fx, max_bwe_fx, tmpF_fx; Word16 tmp; - IF( GT_16( tilt_wb_fx, 10240 ) ) + IF( GT_16( tilt_wb_fx, 10240 /* 5 in Q11 */ ) ) { FOR( i = 0; i < Nsv; i++ ) { - min_bwe_fx = 32767; + min_bwe_fx = MAX_16; move16(); max_bwe_fx = 0; move16(); tmp = i_mult2( i, N ); FOR( j = 0; j < N; j++ ) { - tmpF_fx = abs_s( t_audio_fx[tmp + j] ); + tmpF_fx = abs_s( t_audio_fx[tmp + j] ); // Q_audio max_bwe_fx = s_max( tmpF_fx, max_bwe_fx ); if ( tmpF_fx > 0 ) @@ -47,7 +47,7 @@ static void swb_hr_nonzero_subband_noise_fill_fx( test(); if ( EQ_16( max_bwe_fx, min_bwe_fx ) && GT_16( min_bwe_fx, shl( 1, Q_audio ) ) ) { - min_bwe_fx = mult_r( min_bwe_fx, 16384 ); + min_bwe_fx = mult_r( min_bwe_fx, 16384 /* 0.5 in Q15 */ ); // Q_audio + Q15 - Q15 -> Q_audio } ptr_fx = &t_audio_fx[tmp]; @@ -55,12 +55,12 @@ static void swb_hr_nonzero_subband_noise_fill_fx( { IF( *ptr_fx == 0 ) { - tmp = mult_r( min_bwe_fx, 16384 ); - if ( Random( bwe_highrate_seed ) <= 0 ) + tmp = mult_r( min_bwe_fx, 16384 /* 0.5 in Q15 */ ); + if ( Random( bwe_highrate_seed ) <= 0 ) // Q_audio + Q15 - Q15 -> Q_audio { tmp = negate( tmp ); } - *ptr_fx = tmp; + *ptr_fx = tmp; // Q_audio move16(); } ptr_fx++; @@ -77,15 +77,15 @@ static void swb_hr_nonzero_subband_noise_fill_fx( * SWB BWE HR noise filling *-------------------------------------------------------------------*/ void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - const Word16 pitch_fx, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ + const Word16 is_transient, /* i : transient flag */ + const Word16 spect_start, /* i : spectrum start point */ + const Word16 spect_end, /* i : spectrum end point */ + const Word16 tilt_wb_fx, /* i : tilt of wideband signal Q11 */ + const Word16 pitch_fx, /* i : pitch value Q4 */ + const Word16 nq[], /* i : AVQ nq index */ + Word16 Nsv, /* i : number of subband */ + Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ + Word16 *t_audio_fx, /* i/o: mdct spectrum Q_audio */ Word16 Q_audio ) { Word16 i, j, k; @@ -116,14 +116,14 @@ void swb_hr_noise_fill_fx( Nsv = shr( sub( spect_end, spect_start ), 3 ); alpha_fx = 8192; move16(); /*Q15 */ - IF( GT_16( tilt_wb_fx, 10240 ) ) + IF( GT_16( tilt_wb_fx, 10240 /* 5 in Q11 */ ) ) { beta_fx = 8192; move16(); /*Q15 */ } ELSE { - IF( GT_16( 6400, pitch_fx ) ) + IF( GT_16( 6400 /* 400 in Q4 */, pitch_fx ) ) { beta_fx = 8192; move16(); /*Q15 */ @@ -176,9 +176,9 @@ void swb_hr_noise_fill_fx( tmp1 = shl( incr, 3 ); FOR( k = 0; k < WIDTH_BAND; k++ ) { - tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); - tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); - t_audio_fx[tmp + k] = add( tmp2, tmp3 ); + tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); // Q_audio + Q15 - Q15 -> Q_audio + tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); // Q_audio + Q15 - Q15 -> Q_audio + t_audio_fx[tmp + k] = add( tmp2, tmp3 ); // Q_audio move16(); } @@ -234,9 +234,9 @@ void swb_hr_noise_fill_fx( tmp1 = shl( incr, 3 ); FOR( k = 0; k < WIDTH_BAND; k++ ) { - tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); - tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); - t_audio_fx[tmp + k] = add( tmp2, tmp3 ); + tmp2 = mult_r( alpha_fx, t_audio_fx[tmp1 + k] ); // // Q_audio + Q15 - Q15 -> Q_audio + tmp3 = mult_r( beta_fx, shr( Random( bwe_highrate_seed ), tmp_exp ) ); // // Q_audio + Q15 - Q15 -> Q_audio + t_audio_fx[tmp + k] = add( tmp2, tmp3 ); // Q_audio move16(); } /*incr = (incr == 0) ? sub(pos_start, 1) : sub(incr, 1); */ diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index c9b4a27fa9c1f827ce9425b0e3ee9145dfeda908..1e7112a02767090c08f24c538e896f995bd9221a 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2585,8 +2585,9 @@ void Gettonl_scalfact_fx( IF( L_est_ton_ene[k_fx] <= 0x0L ) { /* 1.0 */ - L_est_ton_ene[k_fx] = L_deposit_l( 32767 ); + L_est_ton_ene[k_fx] = L_deposit_l( MAX_16 ); QetEne = 15; + move16(); } /*ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]);*/ /* be_tonal: QbeL, est_ton_ene: (Qss-exp_safe)*2+1 */ @@ -3473,6 +3474,8 @@ void updat_prev_frm_fx( } } + test(); + test(); IF( ( EQ_32( L_bwe_br, HQ_16k40 ) || EQ_32( L_bwe_br, HQ_13k20 ) ) && EQ_16( bwidth_fx, SWB ) ) { *prev_hqswb_clas = hqswb_clas_fx; diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index ddb28532a18caf816b6380ab7ca446e107864af3..18e5b1f2a5ac463f40f3215a7566767ef6870b43 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1242,11 +1242,11 @@ void GenSHBSynth_fx_32( // shb_syn_speech_32k[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_32k[i] ) : ( speech_buf_32k[i] ); IF( i % 2 == 0 ) { - shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); + shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); // Qx } ELSE { - shb_syn_speech_32k[i] = speech_buf_32k[i]; + shb_syn_speech_32k[i] = speech_buf_32k[i]; // Qx } move32(); } @@ -1412,9 +1412,9 @@ void ScaleShapedSHB_32( FOR( k = 0; k < shr( length, 1 ); k++ ) { sum_gain_fx = mult_r( subwin_fx[2 * k + 2], subgain_fx[0] ); - mod_syn_fx[add( skip[0], k )] = Mpy_32_16_1( synSHB_fx[add( skip[0], k )], sum_gain_fx ); - move32(); // Qx - mod_syn_fx[add( add( skip[0], k ), shr( length, 1 ) )] = Mpy_32_16_1( synSHB_fx[add( add( skip[0], k ), shr( length, 1 ) )], subgain_fx[0] ); // Qx + mod_syn_fx[skip[0] + k] = Mpy_32_16_1( synSHB_fx[skip[0] + k], sum_gain_fx ); + move32(); // Qx + mod_syn_fx[skip[0] + k + length / 2] = Mpy_32_16_1( synSHB_fx[skip[0] + k + length / 2], subgain_fx[0] ); // Qx move32(); } FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) @@ -1423,14 +1423,14 @@ void ScaleShapedSHB_32( { L_tmp = L_mult0( subwin_fx[k + 1], subgain_fx[i] ); sum_gain_fx = round_fx( L_mac0( L_tmp, subwin_fx[length - k - 1], subgain_fx[i - 1] ) ); - mod_syn_fx[add( skip[i], k )] = L_shl( Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ), 1 ); // Qx + mod_syn_fx[skip[i] + k] = L_shl( Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ), 1 ); // Qx move32(); } } FOR( k = 0; k < shr( length, 1 ); k++ ) { - sum_gain_fx = mult_r( subwin_fx[sub( sub( length, shl( k, 1 ) ), 2 )], subgain_fx[i - 1] ); - mod_syn_fx[add( skip[i], k )] = Mpy_32_16_1( synSHB_fx[add( skip[i], k )], sum_gain_fx ); // Qx + sum_gain_fx = mult_r( subwin_fx[length - k * 2 - 2], subgain_fx[i - 1] ); + mod_syn_fx[skip[i] + k] = Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ); // Qx move32(); } } @@ -1451,15 +1451,15 @@ void ScaleShapedSHB_32( { FOR( k = 0; k < join_length - length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i_mult( i, num_join )] ); // Qx + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i * num_join] ); // Qx move32(); j = add( j, 1 ); } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i_mult( i, num_join )] ); - mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[i_mult( ( i + 1 ), num_join )] ) ) ), 1 ); // Qx + L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i * num_join] ); + mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[( i + 1 ) * num_join] ) ) ), 1 ); // Qx move32(); j = add( j, 1 ); } @@ -1472,7 +1472,7 @@ void ScaleShapedSHB_32( } FOR( k = 0; k < length; k++ ) { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[sub( sub( length, k ), 1 )], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[length - k - 1], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx move32(); j = add( j, 1 ); } diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index aa4a1e2bee1e70734ce8fcbfc62afab984c89e6d..95421581db4f86f14c31f70a962546bffdda39f1 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -131,8 +131,8 @@ void fb_tbe_reset_synth_fx( *-------------------------------------------------------------------*/ Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ const Word16 L_frame /* i : frame lenght */ ) { @@ -168,12 +168,12 @@ Word16 tbe_celp_exc_offset( * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ + Word16 *error_fx, /* i/o: Error Q5 */ + Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ ) { Word16 offset_fx, tmp_fx, i; @@ -198,7 +198,7 @@ void tbe_celp_exc( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; // Qx move16(); } tmp_fx = extract_l( L_mult( T0_frac_fx, 1 ) ); /*Q3; 0.25 in Q2*/ @@ -226,7 +226,7 @@ void tbe_celp_exc( FOR( i = 0; i < L_SUBFR * 2; i++ ) { - bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; + bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; // Qx move16(); } @@ -246,21 +246,23 @@ void tbe_celp_exc( * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ void tbe_celp_exc_ivas( - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ - const Word16 L_frame_fx, /* i : Frame lenght */ - const int16_t L_subfr, /* i : subframe length */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ - const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch Q0 */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ + Word16 *error_fx, /* i/o: Error Q5 */ + Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal Qx */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { Word16 offset_fx, tmp_fx, i; - if ( element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag ) + test(); + test(); + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { return; } @@ -584,7 +586,7 @@ void flip_and_downmix_generic_fx_32( Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); - if ( *phase_state >= period ) + if ( GE_16( *phase_state, period ) ) { *phase_state = 0; move16(); @@ -595,18 +597,20 @@ void flip_and_downmix_generic_fx_32( j = *phase_state; move16(); - WHILE( i < length ) + WHILE( LT_16( i, length ) ) { WHILE( ( j < period ) && ( i < length ) ) { + test(); L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ output[i] = L_tmp; /*Qx */ + move32(); i++; j++; } - if ( j >= period ) + if ( GE_16( j, period ) ) { j = 0; move16(); @@ -633,7 +637,7 @@ static void Hilbert_transform_fx( Word16 i, hb_filter_stage, offset; Word32 L_tmp; - hb_filter_stage = 2 * HB_stage_id; + hb_filter_stage = shl( HB_stage_id, 1 ); offset = 0; move16(); if ( HB_stage_id == 0 ) @@ -644,7 +648,7 @@ static void Hilbert_transform_fx( test(); test(); - IF( HB_stage_id == 0 || HB_stage_id == 2 ) + IF( HB_stage_id == 0 || EQ_16( HB_stage_id, 2 ) ) { FOR( i = 0; i < length; i++ ) { @@ -661,7 +665,7 @@ static void Hilbert_transform_fx( move32(); /*Qx+16 */ } } - ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 ) + ELSE IF( EQ_16( HB_stage_id, 1 ) || EQ_16( HB_stage_id, 3 ) ) { FOR( i = 0; i < length; i++ ) { @@ -788,7 +792,7 @@ void Calc_rc0_h( acf1 = extract_h( L_acc ); /* Compute 1st parcor */ - if ( acf0 == 0 ) + IF( acf0 == 0 ) { *rc0 = 0; move16(); @@ -803,7 +807,7 @@ void Calc_rc0_h( } *rc0 = div_s( abs_s( acf1 ), acf0 ); move16(); - if ( acf1 > 0 ) + IF( acf1 > 0 ) { *rc0 = negate( *rc0 ); move16(); @@ -1125,7 +1129,7 @@ void flip_spectrum_and_decimby4_fx( } Decimate_allpass_steep_fx( input_change, mem1, length, tmp ); - Decimate_allpass_steep_fx( tmp, mem2, length / 2, output ); + Decimate_allpass_steep_fx( tmp, mem2, shr( length, 1 ), output ); return; } @@ -1204,13 +1208,14 @@ void ivas_GenShapedWBExcitation_fx( Word16 avg_voice_fac; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mult( voice_factors[0], 8192 /* 0.25 in Q15 */ ); FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[i], 8192 /* 0.25 in Q15 */ ); } avg_voice_fac = round_fx( L_tmp ); @@ -1218,14 +1223,14 @@ void ivas_GenShapedWBExcitation_fx( test(); test(); test(); - IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/ + IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 /* 0.35 in Q15 */ ) ) ) /*Q15 -> 0.35f*/ { csfilt_num2[0] = 6554; move16(); /*Q15 -> 0.2f*/ neg_csfilt_den2[1] = 26214; move16(); /*Q15 -> 0.8f*/ } - ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/ + ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 /* 0.2 in Q15*/ ) ) ) /*Q15 -> 0.2f*/ { csfilt_num2[0] = 328; move16(); /*Q15 -> 0.01f*/ @@ -1375,7 +1380,7 @@ void ivas_GenShapedWBExcitation_fx( test(); test(); - IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) ) + IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB @@ -1506,10 +1511,10 @@ void GenShapedWBExcitation_fx( move16(); /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mult( voice_factors[0], 8192 /*0.25 in Q15 */ ); FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[i], 8192 /*0.25 in Q15 */ ); } avg_voice_fac = round_fx( L_tmp ); @@ -1517,14 +1522,14 @@ void GenShapedWBExcitation_fx( test(); test(); test(); - IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/ + IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 /* 0.35 in Q15 */ ) ) ) /*Q15 -> 0.35f*/ { csfilt_num2[0] = 6554; move16(); /*Q15 -> 0.2f*/ neg_csfilt_den2[1] = 26214; move16(); /*Q15 -> 0.8f*/ } - ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/ + ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) /*Q15 -> 0.2f*/ { csfilt_num2[0] = 328; move16(); /*Q15 -> 0.01f*/ @@ -1674,7 +1679,7 @@ void GenShapedWBExcitation_fx( test(); test(); - IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) ) + IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /*0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); #ifdef BASOP_NOGLOB @@ -1802,9 +1807,9 @@ void GenWBSynth_fx( Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, L_FRAME16k / 2, speech_buf_16k2 ); flip_spectrum_fx( speech_buf_16k2, shb_syn_speech_16k, L_FRAME16k ); - Scale_sig( shb_syn_speech_16k, L_FRAME16k, -nor ); - Scale_sig( state_lsyn_filt_shb1, 2 * ALLPASSSECTIONS_STEEP, -nor ); - Scale_sig( state_lsyn_filt_shb2, 2 * ALLPASSSECTIONS_STEEP, -nor ); + Scale_sig( shb_syn_speech_16k, L_FRAME16k, negate( nor ) ); + Scale_sig( state_lsyn_filt_shb1, 2 * ALLPASSSECTIONS_STEEP, negate( nor ) ); + Scale_sig( state_lsyn_filt_shb2, 2 * ALLPASSSECTIONS_STEEP, negate( nor ) ); return; } @@ -2694,6 +2699,7 @@ void GenShapedSHBExcitation_fx( { L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); } } /* i: L_tmp2 in (Q31-exp) */ @@ -2845,6 +2851,8 @@ void GenShapedSHBExcitation_ivas_fx( Word16 chk1, chk2; chk1 = 0; chk2 = 0; + move16(); + move16(); #if 1 // def ADD_IVAS_TBE_CODE Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; @@ -2939,28 +2947,29 @@ void GenShapedSHBExcitation_ivas_fx( } Q_pow1 = shl( *Q_bwe_exc, 1 ); + test(); +#if 1 // ADD_IVAS_TBE_CODE IF( flag_ACELP16k == 0 ) +#else + IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) ) +#endif { /* varEnvShape = mean_fx(voice_factors, 4); */ /* unroll the loop */ - L_tmp = L_mult( voice_factors[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - varEnvShape = mac_r_sat( L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ - /* varEnvShape is the mean value of voice_factors (Q15) - In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ + L_tmp = L_mult( voice_factors[0], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 /*0.25 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 /*0.25 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[3], 8192 /*0.25 in Q15 */ ); /* varEnvShape in Q15 */ } ELSE /* 16k core */ { /* varEnvShape = mean_fx(voice_factors, 5); */ /* unroll the loop */ - L_tmp = L_mult( voice_factors[0], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 6554 ); - L_tmp = L_mac( L_tmp, voice_factors[3], 6554 ); - varEnvShape = mac_r_sat( L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ - /* varEnvShape is the mean value of voice_factors (Q15) - In any case, varEnvShape is not expected to exceed 32767, hence saturation is added */ + L_tmp = L_mult( voice_factors[0], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[1], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[2], 6554 /*0.2 in Q15 */ ); + L_tmp = L_mac( L_tmp, voice_factors[3], 6554 /*0.2 in Q15 */ ); + varEnvShape = mac_r( L_tmp, voice_factors[4], 6554 /*0.2 in Q15 */ ); /* varEnvShape in Q15 */ } IF( EQ_16( extl, FB_TBE ) ) @@ -2990,6 +2999,7 @@ void GenShapedSHBExcitation_ivas_fx( test(); test(); #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) #else IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) ) @@ -3042,9 +3052,10 @@ void GenShapedSHBExcitation_ivas_fx( } test(); /* Track the low band envelope */ - IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) + IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) { - IF( extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75 ) + test(); + IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) { mem_csfilt_left = 0; mem_csfilt_right = 0; @@ -3137,9 +3148,9 @@ void GenShapedSHBExcitation_ivas_fx( { White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); move32(); - White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], *Q_bwe_exc - NOISE_QADJ ) ); // Q_bwe_exc - NOISE_QADJ + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], sub( *Q_bwe_exc, NOISE_QADJ ) ) ); // Q_bwe_exc - NOISE_QADJ move16(); - L_tmp = max( L_tmp, L_abs( White_exc16k_32[k] ) ); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } Q_temp = norm_l( L_tmp ); IF( L_tmp == 0 ) @@ -3468,6 +3479,7 @@ void GenShapedSHBExcitation_ivas_fx( } } #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) ) #endif { @@ -3484,6 +3496,7 @@ void GenShapedSHBExcitation_ivas_fx( } } #if 1 // def ADD_IVAS_TBE_CODE + test(); IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL ) { /* save buffers for IC-BWE */ @@ -3578,7 +3591,8 @@ void GenShapedSHBExcitation_ivas_fx( #endif { #if 1 // def ADD_IVAS_TBE_CODE - IF( coder_type == UNVOICED || MSFlag == 1 ) + test(); + IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) ) #else IF( EQ_16( coder_type, UNVOICED ) ) #endif @@ -3696,7 +3710,7 @@ void GenShapedSHBExcitation_ivas_fx( exp = 0; move16(); temp = Sqrt16( tempQ15, &exp ); - temp = shl( temp, exp - 1 ); + temp = shl( temp, sub( exp, 1 ) ); temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ temp = div_s( temp, temp2 ); /* Q15 */ @@ -3920,7 +3934,7 @@ void GenSHBSynth_fx( Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, shift ); Interpolate_allpass_steep_fx( input_synspeech_temp, allpass_mem, L_FRAME16k, speech_buf_32k ); /*modify_Fs_fx( input_synspeech, L_FRAME16k, 16000, speech_buf_32k, 32000, allpass_mem, 0);*/ - IF( L_frame == L_FRAME ) + IF( EQ_16( L_frame, L_FRAME ) ) { /* 12.8 k core flipping and downmixing */ flip_and_downmix_generic_fx( speech_buf_32k, shb_syn_speech_32k, L_FRAME32k, @@ -3941,9 +3955,9 @@ void GenSHBSynth_fx( } } - Scale_sig( shb_syn_speech_32k, L_FRAME32k, -shift ); - Scale_sig( allpass_mem, 2 * ALLPASSSECTIONS_STEEP, -shift ); - Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, -shift ); + Scale_sig( shb_syn_speech_32k, L_FRAME32k, negate( shift ) ); + Scale_sig( allpass_mem, 2 * ALLPASSSECTIONS_STEEP, negate( shift ) ); + Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, negate( shift ) ); return; } @@ -4258,6 +4272,7 @@ void ScaleShapedWB_fx( move16(); join_length = i_mult2( num_join, length ); j = 0; /* ptr*/ + move16(); FOR( k = 0; k < length; k++ ) { sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */ @@ -4277,8 +4292,8 @@ void ScaleShapedWB_fx( FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2( ( i + 1 ), num_join )] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2( i, num_join )] ) ); /*Q14 */ + L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2( ( i + 1 ), num_join )] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i * num_join] ) ); /*Q14 */ mod_syn[j] = L_shl( L_mult( sum_gain, synSHB[j] ), 1 ); move32(); /* Q_bwe_exc + 16 */ j++; @@ -4339,12 +4354,12 @@ void ScaleShapedWB_fx( /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 2 */ - min_shift = 2 - ( Q_bwe_exc + 3 - 16 ); - max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + min_shift = sub( 2, sub( add( Q_bwe_exc, 3 ), 16 ) ); + max_shift = sub( 13, sub( add( Q_bwe_exc, 3 ), 16 ) ); max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min( min_shift, max_shift2 ); - *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + *Qx = sub( add( add( Q_bwe_exc, 3 ), shift ), 16 ); move16(); } ELSE /* 16k core */ @@ -4353,21 +4368,21 @@ void ScaleShapedWB_fx( /* Qx = (Q_bwe_exc+3) + shift - 16 */ /* make sure 14 > Qx > 3 */ - min_shift = 3 - ( Q_bwe_exc + 3 - 16 ); + min_shift = sub( 3, sub( add( Q_bwe_exc, 3 ), 16 ) ); move16(); - max_shift = 13 - ( Q_bwe_exc + 3 - 16 ); + max_shift = sub( 13, sub( add( Q_bwe_exc, 3 ), 16 ) ); move16(); max_shift2 = s_min( max_shift, max_headroom ); /* avoid shifting more than the available max_val headroom to avoid overflow */ shift = s_min( min_shift, max_shift2 ); - *Qx = ( Q_bwe_exc + 3 ) + shift - 16; + *Qx = sub( add( add( Q_bwe_exc, 3 ), shift ), 16 ); move16(); } /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */ FOR( i = 0; i < l_shb_lahead; i++ ) { - overlap[i] = shl( overlap[i], ( *Qx - prev_Qx ) ); + overlap[i] = shl( overlap[i], sub( *Qx, prev_Qx ) ); move16(); } @@ -4381,6 +4396,7 @@ void ScaleShapedWB_fx( synSHB[i] = add_sat( synSHB[i], overlap[i] ); move16(); /* Qx */ synSHB[i + l_shb_lahead] = round_fx_sat( L_shl_sat( L_tmp, shift ) ); /* Qx */ + move16(); #else synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift ) ); /* Qx */ synSHB[i] = add( synSHB[i], overlap[i] ); @@ -4533,7 +4549,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4553,7 +4569,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4572,7 +4588,7 @@ static Word32 non_linearity_scaled_copy_ivas( test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4600,7 +4616,7 @@ static Word32 non_linearity_scaled_copy_ivas( L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ test(); test(); - IF( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) + if ( input[i] != 0 && prev_scale != 0 && L_tmp == 0 ) { /* NOTE: this is done to avoid the product to become zero for small non-zero input */ L_tmp = 1; @@ -4654,6 +4670,7 @@ void non_linearity_fx( { Word16 i, j; Word16 max_val = 0; + move16(); Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4664,6 +4681,8 @@ void non_linearity_fx( Word16 en_abs = 0; Word16 v_fac = 0; + move16(); + move16(); Word16 ths; Word16 nframes; Word32 prev_scale; @@ -4754,13 +4773,13 @@ void non_linearity_fx( e_tmp = norm_l( scale ); f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); e_tmp = sub( -1, e_tmp ); - L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + L_tmp = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ /* Computing log2(prev_scale) */ e_tmp = norm_l( prev_scale ); f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); e_tmp = negate( e_tmp ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ @@ -4808,7 +4827,7 @@ void non_linearity_fx( exp = norm_s( max_val ); tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ #ifdef BASOP_NOGLOB - scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ + scale = L_shl_o( L_mult( 21955 /* 0.67 in Q15 */, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ #else scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ #endif @@ -4923,6 +4942,7 @@ void non_linearity_ivas_fx( { Word16 i, j; Word16 max_val = 0; + move16(); Word32 scale; Word16 scale_step; Word16 exp, tmp; @@ -4933,12 +4953,15 @@ void non_linearity_ivas_fx( Word16 en_abs = 0; Word16 v_fac = 0; + move16(); + move16(); Word16 ths; Word16 nframes; Word32 prev_scale; Word16 length_half; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -5514,34 +5537,34 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { #ifdef BASOP_NOGLOB - L_tmpX = L_shr( L_mult( input_fx[sub( i, 4 )], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 3 )], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 2 )], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[sub( i, 1 )], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmp[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_shr( L_mult( input_fx[i - 4], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 3], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 2], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i - 1], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add_sat( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmp[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ move32(); #else - L_tmpX = L_shr( L_mult( input_fx[sub( i, 4 )], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 3 )], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 2 )], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[sub( i, 1 )], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_add( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ - L_tmp[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_shr( L_mult( input_fx [[i - 4]], full_band_bpf_fx[0][4] ), 3 ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 3], full_band_bpf_fx[0][3] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[3][1] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 2], full_band_bpf_fx[0][2] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[3][2] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i - 1], full_band_bpf_fx[0][1] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[3][3] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ + L_tmpX = L_add( L_shr( L_mult( input_fx[i], full_band_bpf_fx[0][0] ), 3 ), L_tmpX ); /*Q_input_fx + 13 + 1 - 3*/ + L_tmp[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[3][4] ), 2 ) ); /*Q_input_fx + 11 + 13 -15 +2*/ move32(); #endif } - memory_fx2[0][0] = input_fx[sub( L_FRAME48k, 4 )]; - memory_fx2[0][1] = input_fx[sub( L_FRAME48k, 3 )]; - memory_fx2[0][2] = input_fx[sub( L_FRAME48k, 2 )]; - memory_fx2[0][3] = input_fx[sub( L_FRAME48k, 1 )]; + memory_fx2[0][0] = input_fx[L_FRAME48k - 4]; + memory_fx2[0][1] = input_fx[L_FRAME48k - 3]; + memory_fx2[0][2] = input_fx[L_FRAME48k - 2]; + memory_fx2[0][3] = input_fx[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -5630,26 +5653,26 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { #ifdef BASOP_NOGLOB - L_tmpX = L_shr( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmp2[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_shr( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmp2[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ move32(); #else - L_tmpX = L_shr( Mult_32_16( L_tmp[sub( i, 4 )], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 3 )], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 2 )], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[sub( i, 1 )], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ - L_tmp2[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_shr( Mult_32_16( L_tmp[i - 4], full_band_bpf_fx[1][4] ), 3 ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 3], full_band_bpf_fx[1][3] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[4][1] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 2], full_band_bpf_fx[1][2] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[4][2] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i - 1], full_band_bpf_fx[1][1] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[4][3] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp[i], full_band_bpf_fx[1][0] ), 3 ), L_tmpX ); /*Q_input_fx + 11 + 13 - 15 -3*/ + L_tmp2[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[4][4] ), 2 ) ); /*Q_input_fx + 6 +13 -15 +2 */ move32(); #endif L_tmpMax = L_max( L_tmpMax, L_abs( L_tmp2[i] ) ); @@ -5659,10 +5682,10 @@ void elliptic_bpf_48k_generic_fx( Q_temp = sub( Q_temp, 4 ); Scale_sig32( L_tmp2, 960, Q_temp ); - memory_fx2[1][0] = L_tmp[sub( L_FRAME48k, 4 )]; - memory_fx2[1][1] = L_tmp[sub( L_FRAME48k, 3 )]; - memory_fx2[1][2] = L_tmp[sub( L_FRAME48k, 2 )]; - memory_fx2[1][3] = L_tmp[sub( L_FRAME48k, 1 )]; + memory_fx2[1][0] = L_tmp[L_FRAME48k - 4]; + memory_fx2[1][1] = L_tmp[L_FRAME48k - 3]; + memory_fx2[1][2] = L_tmp[L_FRAME48k - 2]; + memory_fx2[1][3] = L_tmp[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -5732,18 +5755,18 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { - L_tmpX = L_shr( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 1 )], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_shr( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 2 )], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 3 )], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_output[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[sub( i, 4 )], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add_sat( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_output[i] = L_sub_sat( L_tmpX, L_shl_sat( Mult_32_16( L_output[i - 4], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ move32(); L_tmpMax = L_max( L_tmpMax, L_abs( L_output[i] ) ); } @@ -5798,30 +5821,30 @@ void elliptic_bpf_48k_generic_fx( FOR( i = 4; i < L_FRAME48k; i++ ) { - L_tmpX = L_shr( Mult_32_16( L_tmp2[sub( i, 4 )], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 3 )], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 1 )], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_shr( Mult_32_16( L_tmp2[i - 4], full_band_bpf_fx[2][4] ), 3 ); /*Q_input_fx + 6 +Q_temp+13 -15 -3 */ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 3], full_band_bpf_fx[2][3] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 1], full_band_bpf_fx[5][1] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 2 )], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 2 )], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 2], full_band_bpf_fx[2][2] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp+13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 2], full_band_bpf_fx[5][2] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[sub( i, 1 )], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 3 )], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i - 1], full_band_bpf_fx[2][1] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_tmpX = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 3], full_band_bpf_fx[5][3] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ - L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ - L_output[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[sub( i, 4 )], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ + L_tmpX = L_add( L_shr( Mult_32_16( L_tmp2[i], full_band_bpf_fx[2][0] ), 3 ), L_tmpX ); /*Q_input_fx + 6 +Q_temp +13 -15 -3*/ + L_output[i] = L_sub( L_tmpX, L_shl( Mult_32_16( L_output[i - 4], full_band_bpf_fx[5][4] ), 2 ) ); /*Q_input_fx + 1 +Q_temp+13 -15 + 2*/ move32(); L_tmpMax = L_max( L_tmpMax, L_abs( L_output[i] ) ); } #endif - memory_fx2[2][0] = L_tmp2[sub( L_FRAME48k, 4 )]; - memory_fx2[2][1] = L_tmp2[sub( L_FRAME48k, 3 )]; - memory_fx2[2][2] = L_tmp2[sub( L_FRAME48k, 2 )]; - memory_fx2[2][3] = L_tmp2[sub( L_FRAME48k, 1 )]; - memory_fx2[3][0] = L_output[sub( L_FRAME48k, 4 )]; - memory_fx2[3][1] = L_output[sub( L_FRAME48k, 3 )]; - memory_fx2[3][2] = L_output[sub( L_FRAME48k, 2 )]; - memory_fx2[3][3] = L_output[sub( L_FRAME48k, 1 )]; + memory_fx2[2][0] = L_tmp2[L_FRAME48k - 4]; + memory_fx2[2][1] = L_tmp2[L_FRAME48k - 3]; + memory_fx2[2][2] = L_tmp2[L_FRAME48k - 2]; + memory_fx2[2][3] = L_tmp2[L_FRAME48k - 1]; + memory_fx2[3][0] = L_output[L_FRAME48k - 4]; + memory_fx2[3][1] = L_output[L_FRAME48k - 3]; + memory_fx2[3][2] = L_output[L_FRAME48k - 2]; + memory_fx2[3][3] = L_output[L_FRAME48k - 1]; move32(); move32(); move32(); @@ -6017,7 +6040,7 @@ void Estimate_mix_factors_fx( pow3 = Dot_product( shb_res_local, shb_res_local, L_FRAME16k ); /* (2*Q_shb+1) */ - pow3 += L_shl( 21475l /*0.00001f in Q31*/, 2 * Q_shb + 1 - 31 ); /* (2*Q_shb+1) */ + pow3 = L_add( pow3, L_shl( 21475l /*0.00001f in Q31*/, 2 * Q_shb + 1 - 31 ) ); /* (2*Q_shb+1) */ if ( pow3 == 0 ) { pow3 = 1; @@ -6031,10 +6054,8 @@ void Estimate_mix_factors_fx( temp_p1_p3 = root_a_over_b_fx( pow1, Q_pow1, pow3, ( 2 * Q_shb + 1 ), &exp2 ); /* temp_p1_p3 in (Q31+exp2) */ - sc1 = Q_bwe_exc - ( Q_frac - exp1 ); - sc2 = Q_bwe_exc - ( Q_shb - exp2 ); - move16(); - move16(); + sc1 = sub( Q_bwe_exc, sub( Q_frac, exp1 ) ); + sc2 = sub( Q_bwe_exc, sub( Q_shb, exp2 ) ); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( temp_p1_p2, WN_exc_local[i] ); /* (Q_frac - exp1) +16 */ @@ -6280,7 +6301,7 @@ void prep_tbe_exc_fx( tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); move16(); - tmp = 32767; + tmp = MAX_16; move16(); #ifdef BASOP_NOGLOB @@ -6291,7 +6312,7 @@ void prep_tbe_exc_fx( test(); test(); - IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) + IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 /* 115.5 in Q7 */ ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) { tmp = MAX_16; move16(); @@ -6351,16 +6372,17 @@ void prep_tbe_exc_fx( Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, 4 ) /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ -#else /* BASOP_NOGLOB */ + move16(); +#else /* BASOP_NOGLOB */ Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ Ltemp2 = L_shl( Ltemp2, Q_exc + 4 /*Q_exc+16-13*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( L_add( Ltemp1, Ltemp2 ) ); /* Q_exc */ -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ } } ELSE @@ -6370,8 +6392,9 @@ void prep_tbe_exc_fx( /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ #ifdef BASOP_NOGLOB - Ltemp1 = L_shl_o( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + move16(); #else Ltemp1 = L_shl( Ltemp1, Q_exc + 6 /*Q_exc+16-19*/ ); /*Q_exc+16 */ tmp_code_preInt_fx[i] = round_fx( Ltemp1 ); /* Q_exc */ @@ -6458,6 +6481,7 @@ void prep_tbe_exc_ivas_fx( Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; Word16 tmp_code_preInt_fx[L_SUBFR]; Word16 gain_code16 = 0; + move16(); Word16 tmp /*, tmp1, tmp2*/; /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ Word16 pitch; @@ -6470,6 +6494,7 @@ void prep_tbe_exc_ivas_fx( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; @@ -6479,8 +6504,9 @@ void prep_tbe_exc_ivas_fx( tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); + move16(); - tmp = 32767; + tmp = MAX_16; move16(); #ifdef BASOP_NOGLOB @@ -6502,8 +6528,11 @@ void prep_tbe_exc_ivas_fx( *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); move16(); #if 1 // def ADD_IVAS_TBE_CODE + test(); + test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) { + test(); IF( flag_TD_BWE && i_subfr_fx == 0 ) { set16_fx( bwe_exc_fx, 0, L_FRAME32k ); @@ -6645,12 +6674,12 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - IF( GT_16( formant_fac, 4096 ) ) + IF( GT_16( formant_fac, 4096 /* 1 in Q12 */ ) ) { - formant_fac = 4096; + formant_fac = 4096; /* 1 in Q12 */ move16(); } - ELSE if ( formant_fac < 0 ) + ELSE IF( formant_fac < 0 ) { formant_fac = 0; move16(); @@ -6658,9 +6687,9 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength /* now formant_fac in Q12 */ /* formant_fac = 1.0f - 0.5f*formant_fac */ - tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q12 */ + tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q15 */ #ifdef BASOP_NOGLOB - formant_fac = shl_o( sub( 4096, tmp ), 3, &Overflow ); + formant_fac = shl_o( sub( 4096 /* 1 in Q12 */, tmp ), 3, &Overflow ); #else formant_fac = shl( sub( 4096, tmp ), 3 ); #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 6d5bc99b05a9ad574d3bee004ce119fedcc75573..6b000db50e389e53aad286b4acd8512d83043f52 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -323,6 +323,26 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W } +/* + * E_UTIL_synthesis_fx + * + * Parameters: + * shift i : scaling to apply for a[0] Q0 + * a[] i : LP filter coefficients Qx + * x[] i : input signal Qx + * y[] o : output signal Qx-s + * lg i : size of filtering Q0 + * mem[] i/o: memory associated with this filtering. Qx-s + * update i : 0=no update, 1=update of memory. Q0 + * m i : order of LP filter Q0 + * + * Function: + * Perform the synthesis filtering 1/A(z). + * Memory size is always M. + * + * Returns: + * void + */ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[], const Word16 lg, Word32 mem[], const Word16 update, const Word16 m ) { Word16 i, j; @@ -331,6 +351,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] Word16 q; Word32 ( *syn_kern )( Word32 L_tmp, const Word32 a[], const Word32 y[] ) = NULL; Flag Overflow = 0; + move32(); if ( EQ_16( m, 6 ) ) { @@ -366,6 +387,7 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, mem ); L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = L_tmp; + move32(); /* Filtering from Input + Mix of Memory & Output Signal Past */ FOR( i = 1; i < m; i++ ) @@ -419,12 +441,12 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] #ifdef IVAS_FLOAT_FIXED void ivas_synth_mem_updt2_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ const Word16 dec #ifndef FIX_907_MEM_UPDATE_ISSUE , /* i : flag for decoder indication */ @@ -542,13 +564,13 @@ void ivas_synth_mem_updt2_fx( } #endif void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ + const Word16 L_frame, /* i : frame length */ + const Word16 last_L_frame, /* i : frame length */ + Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ + Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ + Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ + Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ + const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; diff --git a/lib_com/tcq_position_arith.c b/lib_com/tcq_position_arith.c index 7d26888d3bf4ce16e129befae546722d7d68f27f..9aff06057cc88d9601cccb9f53f08ae23b9886a7 100644 --- a/lib_com/tcq_position_arith.c +++ b/lib_com/tcq_position_arith.c @@ -44,6 +44,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED static void bitstream_save_bit( TCQ_PBITSTREAM pBS, const int16_t bit ); static uint32_t bitstream_load_bit( TCQ_PBITSTREAM pBS ); static void bitstream_rollback( TCQ_PBITSTREAM pBS, int16_t numBits ); @@ -2290,3 +2291,4 @@ void RestoreTCQ( return; } +#endif diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index fdac07f5633693e0705bfd7e2ed3aca01c6cba16..2cc28e853648d32567d24f72cf1a0b432d8a5043 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -276,7 +276,7 @@ static void ar_encode_fx( test(); IF( GE_32( low, AR_FIRST ) && LT_32( high, AR_THIRD ) ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); move16(); low = L_sub( low, AR_FIRST ); @@ -320,7 +320,7 @@ static void ar_encode_uniform_fx( void ar_encoder_done_fx( PARCODEC arInst ) { - arInst->bits_to_follow++; + arInst->bits_to_follow = add( arInst->bits_to_follow, 1 ); move16(); transmission_bits( arInst, arInst->low >= AR_FIRST ); @@ -1063,19 +1063,19 @@ Word32 GetISCScale_fx( Word32 L_tmp; IF( GT_32( 1952247030, scale_fx32 ) ) { - scale_fx32 = L_add( scale_fx32, Mult_32_16( scale_fx32, 3277 ) ); + scale_fx32 = L_add( scale_fx32, Mult_32_16( scale_fx32, 3277 /*0.1 in Q15*/ ) ); } ELSE { L_tmp = L_shr( scale_fx32, 1 ); - scale_fx32 = L_add( L_tmp, Mult_32_16( L_tmp, 3277 ) ); + scale_fx32 = L_add( L_tmp, Mult_32_16( L_tmp, 3277 /*0.1 in Q15*/ ) ); Qscale = sub( Qscale, 1 ); } } if ( LT_16( pulsesnum, pulsescurr ) ) { - scale_fx32 = Mult_32_16( scale_fx32, 29491 ); + scale_fx32 = Mult_32_16( scale_fx32, 29491 /*0.9 in Q15*/ ); } IF( GT_16( pulsesnum, pulsescurr ) ) { @@ -1100,7 +1100,7 @@ Word32 GetISCScale_fx( } ELSE { - magn_fx[i] = -abs_s( add( magn_fx[i], diff ) ); + magn_fx[i] = negate( abs_s( add( magn_fx[i], diff ) ) ); move16(); } @@ -1140,7 +1140,7 @@ Word32 GetISCScale_fx( } ELSE { - magn_fx[i] = -sub( abs_s( magn_fx[i] ), diff ); + magn_fx[i] = negate( sub( abs_s( magn_fx[i] ), diff ) ); move16(); } BREAK; @@ -1236,7 +1236,7 @@ Word32 GetISCScale_fx( } /* Update actual occurred surplus */ - tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[sub( pulsescurr, sub( nzposcurr, 1 ) )] ); + tcqmagnbits_fx = L_sub( L_sub( table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr] ), table_logcum_fx[pulsescurr - ( nzposcurr - 1 )] ); *surplus_fx = L_add( *surplus_fx, L_sub( tcqmagnbits_fx, L_shl( magnbits_fx, 1 ) ) ); move32(); *nzpout = nzposcurr; @@ -1427,36 +1427,36 @@ void TCQLSB_fx( /* decision */ IF( LT_32( L_add( curdist1_fx, newdist1_fx ), L_add( curdist2_fx, newdist2_fx ) ) ) { - path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][0]; + path[st][i / 2 + 1] = step_LSB[st][0]; move16(); - metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist1_fx, newdist1_fx ); + metric_fx[st][i / 2 + 1] = L_add( curdist1_fx, newdist1_fx ); move32(); - quant[st][add( shr( i, 1 ), 1 )] = 0; + quant[st][i / 2 + 1] = 0; move16(); - dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } ELSE { - path[st][add( shr( i, 1 ), 1 )] = step_LSB[st][1]; + path[st][i / 2 + 1] = step_LSB[st][1]; move16(); - metric_fx[st][add( shr( i, 1 ), 1 )] = L_add( curdist2_fx, newdist2_fx ); + metric_fx[st][i / 2 + 1] = L_add( curdist2_fx, newdist2_fx ); move32(); - quant[st][add( shr( i, 1 ), 1 )] = 1; + quant[st][i / 2 + 1] = 1; move16(); - dquant[st][add( shr( i, 1 ), 1 )] = dqnt_LSB[step_LSB[st][0]][st]; + dquant[st][i / 2 + 1] = dqnt_LSB[step_LSB[st][0]][st]; move16(); } - if ( GT_32( MaxPath, metric_fx[st][add( shr( i, 1 ), 1 )] ) ) + if ( GT_32( MaxPath, metric_fx[st][i / 2 + 1] ) ) { - MaxPath = L_add( metric_fx[st][add( shr( i, 1 ), 1 )], 0 ); + MaxPath = L_add( metric_fx[st][i / 2 + 1], 0 ); } } /* Metric renormalization to prevent overflow */ FOR( st = 0; st < 4; st++ ) { - metric_fx[st][add( shr( i, 1 ), 1 )] = L_sub( metric_fx[st][add( shr( i, 1 ), 1 )], MaxPath ); + metric_fx[st][i / 2 + 1] = L_sub( metric_fx[st][i / 2 + 1], MaxPath ); move32(); } } @@ -1481,9 +1481,9 @@ void TCQLSB_fx( FOR( ; i >= 0; i -= 2 ) { - qout[i / 2] = quant[position][add( shr( i, 1 ), 1 )]; + qout[i / 2] = quant[position][i / 2 + 1]; move16(); - dpath[i / 2] = dquant[position][add( shr( i, 1 ), 1 )]; + dpath[i / 2] = dquant[position][i / 2 + 1]; move16(); IF( s_and( denc_LSB[position][qout[i / 2]], 0x1 ) ) @@ -1507,7 +1507,7 @@ void TCQLSB_fx( move16(); } - position = path[position][add( shr( i, 1 ), 1 )]; + position = path[position][i / 2 + 1]; move16(); } @@ -1546,12 +1546,12 @@ void TCQLSBdec_fx( IF( s_and( ddec_LSB[state][dpath[i]], 0x2 ) ) { - mbuffer[add( shl( i, 1 ), 1 )] = q; + mbuffer[2 * i + 1] = q; move16(); } ELSE { - mbuffer[add( shl( i, 1 ), 1 )] = negate( q ); + mbuffer[2 * i + 1] = negate( q ); move16(); } @@ -1737,8 +1737,8 @@ Word32 encode_position_ari_fx( btcq_fx = GetBitsFromPulses_fx( pulses, size ); /* 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( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[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[size - 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 ); @@ -1748,10 +1748,10 @@ Word32 encode_position_ari_fx( FOR( i = 0; i < tmp; i++ ) { pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), - L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( pulses, i )] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[pulses - i] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ - IF( GT_32( pnzp_fx, 0 ) ) + IF( pnzp_fx > 0 ) { integer = extract_h( pnzp_fx ); frac = extract_l( L_shr( L_sub( pnzp_fx, L_deposit_h( integer ) ), 1 ) ); /*15 */ @@ -1786,7 +1786,7 @@ Word32 encode_position_ari_fx( BREAK; } - IF( nz == ( size - i ) ) + IF( EQ_16( nz, sub( size, i ) ) ) { cp = L_deposit_l( 0 ); } @@ -1799,7 +1799,7 @@ Word32 encode_position_ari_fx( move16(); test(); test(); - IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || model_num_nz[pos] == model_num_nz[pos + 1] ) + IF( ( model_num_nz[pos + 1] == 0 && scp > 0 ) || EQ_16( model_num_nz[pos], model_num_nz[pos + 1] ) ) { model_num_nz[pos + 1] = 0; move16(); @@ -1872,7 +1872,7 @@ Word32 encode_magnitude_usq_fx( /*estimate fac bits */ - bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[add( sub( npulses, nzpos ), 1 )] ) ); + bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, bits_fx ); test(); @@ -1930,7 +1930,7 @@ Word32 encode_magnitude_usq_fx( move16(); test(); test(); - IF( ( model_m[pos + 1] == 0 && scp > 0 ) || model_m[pos] == model_m[pos + 1] ) + IF( ( model_m[pos + 1] == 0 && scp > 0 ) || EQ_16( model_m[pos], model_m[pos + 1] ) ) { model_m[pos + 1] = 0; move16(); @@ -1988,7 +1988,7 @@ Word32 encode_magnitude_tcq_fx( move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos - 1] ) ); *est_frame_bits_fx = L_add( *est_frame_bits_fx, tcq_bits_fx ); move32(); @@ -2066,7 +2066,7 @@ Word32 encode_magnitude_tcq_fx( } } - leftnz--; + leftnz = sub( leftnz, 1 ); move16(); leftp = sub( leftp, abs_s( magn_fx[i] ) ); } @@ -2145,8 +2145,8 @@ void decode_position_ari_fx( /*calculate the probability of #nz */ pnzp_fx = L_sub( L_deposit_h( add( i, 1 ) ), btcq_fx ); - pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[sub( size, i )] ) ), - L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[sub( npulses, i )] ) ) ) ); + pnzp_fx = L_add( pnzp_fx, L_add( L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[i + 2], table_logcum_fx[size - i] ) ), + L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[i + 1], table_logcum_fx[npulses - i] ) ) ) ); pnzp_fx = L_add( pnzp_fx, 917498 ); /*16 */ IF( GT_32( pnzp_fx, 0 ) ) { @@ -2172,7 +2172,7 @@ void decode_position_ari_fx( move16(); nzp = *nz; move16(); - IF( nzp == 1 ) + IF( EQ_16( nzp, 1 ) ) { mode_num_nz[0] = MAX_AR_FREQ; move16(); @@ -2212,13 +2212,13 @@ void decode_position_ari_fx( cp = L_sub( fxone, div_l( L_deposit_h( nzp ), sub( size, i ) ) ); } scp = Mult_32_16( scp, extract_l( cp ) ); - mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = round_fx( L_shl( scp, 6 ) ); + mode_num_nz[i + 1 - storepos - stpos] = round_fx( L_shl( scp, 6 ) ); test(); test(); - IF( ( mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] == 0 && scp > 0 ) || EQ_16( mode_num_nz[sub( sub( i, storepos ), stpos )], mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] ) ) + IF( ( mode_num_nz[i + 1 - storepos - stpos] == 0 && scp > 0 ) || EQ_16( mode_num_nz[i - storepos - stpos], mode_num_nz[i + 1 - storepos - stpos] ) ) { - mode_num_nz[sub( sub( add( i, 1 ), storepos ), stpos )] = 0; + mode_num_nz[i + 1 - storepos - stpos] = 0; move16(); ovrflag = 1; move16(); @@ -2226,7 +2226,7 @@ void decode_position_ari_fx( storepos = add( storepos, temppos ); scp = L_add( fxp1, 0 ); - IF( temppos == sub( i, stpos ) ) /* esc transmitted */ + IF( EQ_16( temppos, sub( i, stpos ) ) ) /* esc transmitted */ { i = sub( i, 1 ); move16(); @@ -2358,17 +2358,17 @@ void decode_magnitude_usq_fx( cp = L_sub( fxone, div_l( L_deposit_h( magnzp ), sub( magnp, i ) ) ); } - IF( cp == fxone ) + IF( EQ_32( cp, fxone ) ) { BREAK; } scp = Mult_32_16( scp, extract_l( cp ) ); - mmodel[sub( add( i, 1 ), storemagn )] = round_fx( L_shl( scp, 6 ) ); + mmodel[i + 1 - storemagn] = round_fx( L_shl( scp, 6 ) ); move16(); test(); test(); - IF( ( mmodel[sub( add( i, 1 ), storemagn )] == 0 && scp > 0 ) || EQ_16( mmodel[sub( i, storemagn )], mmodel[sub( add( i, 1 ), storemagn )] ) ) + IF( ( mmodel[i + 1 - storemagn] == 0 && scp > 0 ) || EQ_16( mmodel[i - storemagn], mmodel[i + 1 - storemagn] ) ) { mmodel[sub( add( i, 1 ), storemagn )] = 0; move16(); @@ -2376,7 +2376,7 @@ void decode_magnitude_usq_fx( tempmagn = ar_decode_fx( pardec, mmodel ); storemagn = add( storemagn, tempmagn ); - IF( tempmagn < i ) + IF( LT_16( tempmagn, i ) ) { /* just magnitude */ ovrflag = 1; @@ -2394,12 +2394,12 @@ void decode_magnitude_usq_fx( IF( ovrflag ) { - out[magncout] = storemagn + 1; + out[magncout] = add( storemagn, 1 ); move16(); } ELSE { - out[magncout] = ar_decode_fx( pardec, mmodel ) + storemagn + 1; + out[magncout] = add( add( ar_decode_fx( pardec, mmodel ), storemagn ), 1 ); move16(); } magnp = sub( magnp, out[magncout] ); @@ -2425,7 +2425,7 @@ void decode_magnitude_usq_fx( } } } - ELSE IF( magnzp == magnp ) /* rest magnitudes generation */ + ELSE IF( EQ_16( magnzp, magnp ) ) /* rest magnitudes generation */ { FOR( pos = add( pos, 1 ); pos < size; pos++ ) { @@ -2471,7 +2471,7 @@ void decode_mangitude_tcq_fx( move16(); bits_fx = L_deposit_l( 0 ); - tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[sub( npulses, sub( nzpos, 1 ) )] ) ); + tcq_bits_fx = L_sub( table_logcum_fx[npulses], L_add( table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos - 1] ) ); IF( EQ_16( nzpos, npulses ) ) { @@ -2671,7 +2671,7 @@ Word16 GetScale_fx( ab = L_add( a, b ); - p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), ab & 0x7FFF ), 16 ) ); /* enable saturationof pow2 result */ + p_est = extract_h( L_shl( Pow2( extract_l( L_shr( ab, 15 ) ), L_and( ab, 0x7FFF ) ), 16 ) ); /* enable saturationof pow2 result */ pulses = s_min( p_est, MAX_PULSES ); diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index c45513511da81f94ea5a58cae8013809c1cda6ef..beb8ba489825bcf9c9bcfa52dcfcb4003ab7ea09 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -228,7 +228,7 @@ void TCX_MDST( } void TCX_MDCT_Inverse( - Word32 *x, /* exp(x_e) */ + Word32 *x, // Q( 31 - x_e ) Word16 x_e, Word16 *y, /* Qy */ const Word16 l, /* Q0 */ diff --git a/lib_com/tec_com.c b/lib_com/tec_com.c index 1d20ae9f65c8c130f49330006dc2309a2b06d672..c51a2cd02a77f6fe48b61088f16bf245fcc97304 100644 --- a/lib_com/tec_com.c +++ b/lib_com/tec_com.c @@ -64,9 +64,9 @@ void resetTecEnc_Fx( TEC_ENC_HANDLE hTecEnc, Word16 flag ) *-------------------------------------------------------------------*/ static Word32 calcVar_Fix( - const Word32 in[], - const Word32 len, - Word32 *x ) + const Word32 in[], /*Q7*/ + const Word32 len, /*Q0*/ + Word32 *x /*Q7*/ ) { Word32 xx; Word32 i; @@ -83,31 +83,31 @@ static Word32 calcVar_Fix( exp1 = norm_l( in[i] ); r_sft = sub( add( exp1, exp1 ), 24 ); - tmpX = L_shr( Mpy_32_32( L_shl( in[i], exp1 ), L_shl( in[i], exp1 ) ), r_sft ); - xx = L_add( xx, tmpX ); - *x = L_add( *x, in[i] ); + tmpX = L_shr( Mpy_32_32( L_shl( in[i], exp1 ), L_shl( in[i], exp1 ) ), r_sft ); /*Q7*/ + xx = L_add( xx, tmpX ); /*Q7*/ + *x = L_add( *x, in[i] ); /*Q7*/ move32(); } ans = L_deposit_l( 0 ); exp1 = norm_l( *x ); r_sft = sub( add( exp1, exp1 ), 24 ); - tmpX = Mpy_32_32( L_shl( *x, exp1 ), L_shl( *x, exp1 ) ); - tmpX = L_shr( tmpX, r_sft ); + tmpX = Mpy_32_32( L_shl( *x, exp1 ), L_shl( *x, exp1 ) ); /*2*(Q7 + exp1) - 31*/ + tmpX = L_shr( tmpX, r_sft ); /*Q7*/ IF( len == 0 ) { return 0; } ELSE IF( EQ_32( len, 16 ) ) { - ans = L_sub( xx, L_shr( tmpX, 4 ) ); + ans = L_sub( xx, L_shr( tmpX, 4 ) ); /*Q7*/ } ELSE { /* Len = 16 Only */ ans = L_deposit_l( 0 ); } - return ans; + return ans; /*Q7*/ } /*------------------------------------------------------------------- * calcCorrelationCoefficient2() @@ -116,13 +116,13 @@ static Word32 calcVar_Fix( *-------------------------------------------------------------------*/ static Word32 calcCorrelationCoefficient2_Fix( - const Word32 in_vec1[], - const Word32 in_vec2[], - const Word32 len, - Word32 var_x, - Word32 var_y, - Word32 x, - Word32 y ) + const Word32 in_vec1[], /*Q7*/ + const Word32 in_vec2[], /*Q7*/ + const Word32 len, /*Q0*/ + Word32 var_x, /*Q7*/ + Word32 var_y, /*Q7*/ + Word32 x, /*Q7*/ + Word32 y /*Q7*/ ) { Word16 i; @@ -146,8 +146,8 @@ static Word32 calcCorrelationCoefficient2_Fix( exp1 = norm_l( in_vec1[i] ); exp2 = norm_l( in_vec2[i] ); r_sft = sub( add( exp1, exp2 ), 24 ); - tmpXY = L_shr( Mpy_32_32( L_shl( in_vec1[i], exp1 ), L_shl( in_vec2[i], exp2 ) ), r_sft ); - xy = L_add( xy, tmpXY ); + tmpXY = L_shr( Mpy_32_32( L_shl( in_vec1[i], exp1 ), L_shl( in_vec2[i], exp2 ) ), r_sft ); /*Q7*/ + xy = L_add( xy, tmpXY ); /*Q7*/ } @@ -156,8 +156,8 @@ static Word32 calcCorrelationCoefficient2_Fix( exp1 = norm_l( x ); exp2 = norm_l( y ); r_sft = sub( add( exp1, exp2 ), 24 ); - xy2 = L_shr( Mpy_32_32( L_shl( x, exp1 ), L_shl( y, exp2 ) ), r_sft + 4 ); - Val1 = L_sub( xy, xy2 ); + xy2 = L_shr( Mpy_32_32( L_shl( x, exp1 ), L_shl( y, exp2 ) ), r_sft + 4 ); /*Q7*/ + Val1 = L_sub( xy, xy2 ); /*Q7*/ test(); IF( var_x == 0 || var_y == 0 ) @@ -170,26 +170,26 @@ static Word32 calcCorrelationCoefficient2_Fix( Word32 sqrtVal1; Word32 sqrtVal2; exp1 = norm_l( var_x ); - if ( ( exp1 & 0x1 ) != 0 ) + if ( s_and( exp1, 0x1 ) != 0 ) { exp1 = sub( exp1, 1 ); } exp2 = norm_l( var_y ); - if ( ( exp2 & 0x1 ) != 0 ) + if ( s_and( exp2, 0x1 ) != 0 ) { exp2 = sub( exp2, 1 ); } - sqrtVal1 = Sqrt_l( L_shl( var_x, exp1 ), &exp3 ); - sqrtVal1 = L_shr( sqrtVal1, ( shr( add( exp1, 24 ), 1 ) ) ); - sqrtVal2 = Sqrt_l( L_shl( var_y, exp2 ), &exp4 ); - sqrtVal2 = L_shr( sqrtVal2, ( shr( add( exp2, 24 ), 1 ) ) ); + sqrtVal1 = Sqrt_l( L_shl( var_x, exp1 ), &exp3 ); /*Q7 + exp1*/ + sqrtVal1 = L_shr( sqrtVal1, ( shr( add( exp1, 24 ), 1 ) ) ); /*Q7*/ + sqrtVal2 = Sqrt_l( L_shl( var_y, exp2 ), &exp4 ); /*Q7 + exp1*/ + sqrtVal2 = L_shr( sqrtVal2, ( shr( add( exp2, 24 ), 1 ) ) ); /*Q7*/ exp1 = norm_l( sqrtVal1 ); exp2 = norm_l( sqrtVal2 ); r_sft = sub( add( exp1, exp2 ), 24 ); - Val2 = L_shr( Mpy_32_32( L_shl( sqrtVal1, exp1 ), L_shl( sqrtVal2, exp2 ) ), r_sft ); + Val2 = L_shr( Mpy_32_32( L_shl( sqrtVal1, exp1 ), L_shl( sqrtVal2, exp2 ) ), r_sft ); /*Q7*/ exp1 = sub( norm_l( Val1 ), 1 ); exp2 = norm_l( Val2 ); @@ -197,11 +197,11 @@ static Word32 calcCorrelationCoefficient2_Fix( test(); if ( Val1 != 0 && Val2 != 0 ) { - tmpCor = divide3232( L_shl( Val1, exp1 ), L_shl( Val2, exp2 ) ); + tmpCor = divide3232( L_shl( Val1, exp1 ), L_shl( Val2, exp2 ) ); /*Q15 - (exp2 - exp1)*/ } r_sft = sub( 8, sub( exp2, exp1 ) ); - tmpCor = L_shr( tmpCor, r_sft ); + tmpCor = L_shr( tmpCor, r_sft ); /*Q7*/ ans = tmpCor; move16(); } @@ -213,7 +213,7 @@ static Word32 calcCorrelationCoefficient2_Fix( } - return ans; + return ans; /*Q7*/ } /*------------------------------------------------------------------- * calcLoBufferEnc() @@ -223,10 +223,10 @@ static Word32 calcCorrelationCoefficient2_Fix( static void calcLoBufferEnc_Fx( Word32 **pCldfbPow_Fx, /* Q31 */ const Word16 scale, - const Word16 startPos, - const Word16 stopPos, - const Word16 bandOffsetBottom, - Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 bandOffsetBottom, /*Q0*/ + Word16 *loBuffer /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ ) { Word16 lb; @@ -245,7 +245,7 @@ static void calcLoBufferEnc_Fx( FOR( lb = 0; lb < NBTECLOWBAND; lb++ ) { - li = TecLowBandTable[lb]; + li = TecLowBandTable[lb]; /*Q0*/ move16(); ui = sub( TecLowBandTable[lb + 1], 1 ); @@ -253,7 +253,7 @@ static void calcLoBufferEnc_Fx( /* sum up maximum of 2 nrg values, thus leave 1 bits headroom */ nrg = L_add( L_shr( pCldfbPow_Fx[slot][li + bandOffsetBottom], 1 ), - L_shr( pCldfbPow_Fx[slot][ui + bandOffsetBottom], 1 ) ); + L_shr( pCldfbPow_Fx[slot][ui + bandOffsetBottom], 1 ) ); /*Q31 - scale*/ /* assemble log2(EPS) */ @@ -263,7 +263,7 @@ static void calcLoBufferEnc_Fx( IF( nrg != 0 ) { /* assemble log2 value and shift factor */ - nrgLog = L_sub( L_shr( BASOP_Util_Log2( nrg ), 1 ), L_shl( scale, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + nrgLog = L_sub( L_shr( BASOP_Util_Log2( nrg ), 1 ), L_shl( scale, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31*/ /* /\* assemble log2 value and shift factor *\/ */ /* nrgLog = L_shr(BASOP_Util_Log2(nrg),1); */ @@ -273,7 +273,7 @@ static void calcLoBufferEnc_Fx( } /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ - loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); /* Q8 = Q(15 - (LD_DATA_SCALE + 1)) */ move16(); } } @@ -286,11 +286,11 @@ static void calcLoBufferEnc_Fx( static void calcHiTempEnv_Fx( Word32 **pCldfbPow, /* Q31 */ Word16 scale, - const Word16 startPos, - const Word16 stopPos, - const Word16 lowSubband, - const Word16 highSubband, - Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 lowSubband, /*Q0*/ + const Word16 highSubband, /*Q0*/ + Word16 *hiTempEnv /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ ) { Word16 k; @@ -305,7 +305,7 @@ static void calcHiTempEnv_Fx( s1 = 3; move16(); - bwHigh = sub( highSubband, lowSubband ); + bwHigh = sub( highSubband, lowSubband ); /*Q0*/ normFac = getNormReciprocalWord16( bwHigh ); @@ -318,7 +318,7 @@ static void calcHiTempEnv_Fx( FOR( k = lowSubband; k < highSubband; k++ ) { #ifdef BASOP_NOGLOB - nrg = L_add_sat( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); + nrg = L_add_sat( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); /*Q31 - s1*/ #else nrg = L_add( nrg, L_shr( pCldfbPow[timeIndex][k], s1 ) ); #endif @@ -326,7 +326,7 @@ static void calcHiTempEnv_Fx( s2 = norm_l( nrg ); - nrg = L_shl( nrg, s2 ); + nrg = L_shl( nrg, s2 ); /*Q31 - s1 + s2*/ /* assemble log2(EPS) */ nrgLog = -668792462l /*-0.31143075889 Q31*/; @@ -335,12 +335,12 @@ static void calcHiTempEnv_Fx( if ( nrg != 0 ) { /* assemble log2 value and shift factor */ - nrgLog = L_shr( BASOP_Util_Log2( Mpy_32_16_1( nrg, normFac ) ), 1 ); - nrgLog = L_sub( nrgLog, L_shl( add( scale, s2 ), ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + nrgLog = L_shr( BASOP_Util_Log2( Mpy_32_16_1( nrg, normFac ) ), 1 ); /*Q31 - ( scale + s2 )*/ + nrgLog = L_sub( nrgLog, L_shl( add( scale, s2 ), ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31 - ( LD_DATA_SCALE + 1 )*/ } /* 0.75257498916 = 10 * log10(2.0) / 4.0 */ - hiTempEnv[timeIndex] = extract_h( L_shr( L_shl( Mpy_32_16_1( nrgLog, 24660 /*0.75257498916 Q15*/ ), 2 ), 1 ) ); + hiTempEnv[timeIndex] = extract_h( L_shr( L_shl( Mpy_32_16_1( nrgLog, 24660 /*0.75257498916 Q15*/ ), 2 ), 1 ) ); /* Q7 = Q(15 - (LD_DATA_SCALE + 2)) */ move16(); } } @@ -351,12 +351,12 @@ static void calcHiTempEnv_Fx( *-------------------------------------------------------------------*/ static void calcLoBufferDec_Fx( - Word32 **pCldfbReal, - Word32 **pCldfbImag, - Word16 *loBuffer, - const Word16 startPos, - const Word16 stopPos, - const Word16 offset, + Word32 **pCldfbReal, /*scale*/ + Word32 **pCldfbImag, /*scale*/ + Word16 *loBuffer, /*Q15 - ( LD_DATA_SCALE + 1 )*/ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + const Word16 offset, /*Q0*/ const Word16 scale ) { Word16 k; @@ -378,9 +378,9 @@ static void calcLoBufferDec_Fx( Word16 li; Word16 ui; - li = TecLowBandTable[lb]; + li = TecLowBandTable[lb]; /*Q0*/ move16(); - ui = TecLowBandTable[lb + 1]; + ui = TecLowBandTable[lb + 1]; /*Q0*/ move16(); assert( ( ui - li ) == 2 ); @@ -405,26 +405,26 @@ static void calcLoBufferDec_Fx( { Word16 val; - val = extract_h( L_shl( pCldfbReal[slot][k + offset], s1 ) ); - nrg32 = L_mac( nrg32, val, val ); - val = extract_h( L_shl( pCldfbImag[slot][k + offset], s1 ) ); - nrg32 = L_mac( nrg32, val, val ); + val = extract_h( L_shl( pCldfbReal[slot][k + offset], s1 ) ); /*scale+s1-16*/ + nrg32 = L_mac( nrg32, val, val ); /*2*(scale+s1-16)*/ + val = extract_h( L_shl( pCldfbImag[slot][k + offset], s1 ) ); /*scale+s1-16*/ + nrg32 = L_mac( nrg32, val, val ); /*2*(scale+s1-16)*/ } /* square(scale) + square(s1) + 1(inv_bw = 0.5) */ s2 = add( shl( add( scale, s1 ), 1 ), 1 ); /* assemble log value */ - tmp = L_add( tmp, L_shr( BASOP_Util_Log2( nrg32 ), 1 ) ); + tmp = L_add( tmp, L_shr( BASOP_Util_Log2( nrg32 ), 1 ) ); /*s2*/ /* add shift factors */ - tmp = L_sub( tmp, L_shl( s2, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); + tmp = L_sub( tmp, L_shl( s2, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /*Q31 - ( LD_DATA_SCALE + 1 )*/ /* add scale of reference */ tmp = L_add( tmp, L_shl( 30, ( WORD32_BITS - 1 ) - ( LD_DATA_SCALE + 1 ) ) ); /* 0.50171665944 = 10 * log10(2.0) / NbTecLowBand / 2.0 */ - loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); + loBuffer[slot] = extract_h( L_shl( Mpy_32_16_1( tmp, 16440 /*0.50171665944 Q15*/ ), 1 ) ); /*Q15 - ( LD_DATA_SCALE + 1 )*/ move16(); } ELSE @@ -442,10 +442,10 @@ static void calcLoBufferDec_Fx( * *-------------------------------------------------------------------*/ static void calcLoTempEnv_Fx( - Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 adjFac_Fx ) + const Word16 adjFac_Fx /*Q15*/ ) { Word16 i; Word16 slot; @@ -454,13 +454,13 @@ static void calcLoTempEnv_Fx( /* TecSC_Fx values are scaled by factor 2.0 */ FOR( slot = 0; slot < noCols; slot++ ) { - accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot] ); + accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot] ); /*Q23*/ FOR( i = 1; i < TECSMOOTHINGDEG + 1; i++ ) { - accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[sub( slot, i )] ); + accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[( slot - i )] ); /*Q23*/ } /* adjFac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); /*Q7*/ move16(); } } @@ -471,7 +471,7 @@ static void calcLoTempEnv_Fx( *-------------------------------------------------------------------*/ static void calcLoTempEnv_ns_Fx( Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ ) { @@ -479,7 +479,7 @@ static void calcLoTempEnv_ns_Fx( FOR( slot = 0; slot < noCols; slot++ ) { - loTempEnv_Fx[slot] = shr( loBuffer_Fx[slot], 1 ); + loTempEnv_Fx[slot] = shr( loBuffer_Fx[slot], 1 ); /*Q7*/ move16(); } @@ -491,10 +491,10 @@ static void calcLoTempEnv_ns_Fx( * *-------------------------------------------------------------------*/ static void calcLoTempEnv_TBE_Fx( - Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 adjFac_Fx ) + const Word16 adjFac_Fx /*Q15*/ ) { Word16 i; Word16 slot; @@ -505,13 +505,13 @@ static void calcLoTempEnv_TBE_Fx( /* TecSC_Fx values are scaled by factor 2.0 */ FOR( slot = 0; slot < noCols; slot++ ) { - accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot - delay] ); + accu = L_mult0( TecSC_Fx[0], loBuffer_Fx[slot - delay] ); /*Q23*/ FOR( i = 1; i < TECSMOOTHINGDEG + 1; i++ ) { - accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[slot - i - delay] ); + accu = L_mac0( accu, TecSC_Fx[i], loBuffer_Fx[slot - i - delay] ); /*Q23*/ } /* adjFac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); + loTempEnv_Fx[slot] = extract_h( Mpy_32_16_1( accu, adjFac_Fx ) ); /*Q7*/ move16(); } } @@ -523,7 +523,7 @@ static void calcLoTempEnv_TBE_Fx( static void calcLoTempEnv_ns_TBE_Fx( Word16 *loBuffer_Fx, /* Q8 = Q(15 - (LD_DATA_SCALE+1)) */ - const Word16 noCols, + const Word16 noCols, /*Q0*/ Word16 *loTempEnv_Fx /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ ) { @@ -535,7 +535,7 @@ static void calcLoTempEnv_ns_TBE_Fx( FOR( slot = 0; slot < noCols; slot++ ) { /* fac is scaled by factor 0.5 */ - loTempEnv_Fx[slot] = mult_r( fac, loBuffer_Fx[sub( slot, delay )] ); + loTempEnv_Fx[slot] = mult_r( fac, loBuffer_Fx[( slot - delay )] ); /*Q7*/ move16(); } @@ -548,10 +548,10 @@ static void calcLoTempEnv_ns_TBE_Fx( *-------------------------------------------------------------------*/ static void calcGainLinear_TBE_Fx( const Word16 *loTempEnv_m, /* Q7 = Q(15 - (LD_DATA_SCALE+2)) */ - const Word16 startPos, - const Word16 stopPos, - Word16 *pGainTemp_m, /* Q0 */ - Word16 *pGainTemp_e /* Q0 */ + const Word16 startPos, /*Q0*/ + const Word16 stopPos, /*Q0*/ + Word16 *pGainTemp_m, /* Q0 */ + Word16 *pGainTemp_e /* Q0 */ ) { @@ -574,7 +574,7 @@ static void calcGainLinear_TBE_Fx( move16(); /* adapt scale to LD_DATA_SCALE */ - tmp32 = L_shl( L_mult( c, loTempEnv_m[slot] ), 1 ); + tmp32 = L_shl( L_mult( c, loTempEnv_m[slot] ), 1 ); /*Q31*/ IF( tmp32 > 0 ) { @@ -589,19 +589,19 @@ static void calcGainLinear_TBE_Fx( } /* scalefactor for logarithmic domain */ - logScaleFactor = L_shl( L_mult0( 512 /*1.0/(1< 0 ) { Word16 tmp; s = norm_l( nrg32 ); - tmp = extract_h( L_shl( nrg32, s ) ); + tmp = extract_h( L_shl( nrg32, s ) ); /*Q15 - 2*(exp_syn) - s2 + s*/ enr_m[i] = tmp; move16(); enr_e[i] = -s; @@ -778,7 +778,7 @@ static Word16 calcSubfrNrg_Fx( sum16_e = enr_e[i_offset]; move16(); - *sum16_m = enr_m[i_offset]; + *sum16_m = enr_m[i_offset]; /*Q15 - enr_e*/ move16(); FOR( i = i_offset + 1; i < N_TEC_TFA_SUBFR; i++ ) { @@ -808,13 +808,13 @@ static Word16 calcSubfrNrg_Fx( *-------------------------------------------------------------------*/ static Word16 procTec_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - exp_syn*/ Word16 exp_syn, - Word16 *gain_m, + Word16 *gain_m, /*Q15 - gain_e*/ Word16 *gain_e, - const Word16 i_offset, - const Word16 l_subfr, - const Word16 code ) + const Word16 i_offset, /*Q0*/ + const Word16 l_subfr, /*Q0*/ + const Word16 code /*Q0*/ ) { Word16 i, j, k; Word16 k_offset, n_subfr; @@ -863,7 +863,7 @@ static Word16 procTec_Fx( &enr_ave_m, l_subfr ); /* divided by n_subfr */ - enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); + enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ enr_ave_e = sub( enr_ave_e, 3 ); /* calculate the average of gain */ @@ -872,7 +872,7 @@ static Word16 procTec_Fx( n_subfr, &gain_ave_m ); - gain_ave_m = mult_r( gain_ave_m, inv_n_subfr ); + gain_ave_m = mult_r( gain_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ gain_ave_e = sub( gain_ave_e, 3 ); k = k_offset; @@ -895,7 +895,7 @@ static Word16 procTec_Fx( } s = norm_s( inv_curr_enr_m[i] ); - inv_curr_enr_m[i] = shl( inv_curr_enr_m[i], s ); + inv_curr_enr_m[i] = shl( inv_curr_enr_m[i], s ); /*Q15 - inv_curr_enr_e + s*/ move16(); inv_curr_enr_e[i] = sub( inv_curr_enr_e[i], s ); move16(); @@ -922,7 +922,7 @@ static Word16 procTec_Fx( { test(); test(); - IF( ( max_inv_curr_enr_e < inv_curr_enr_e[i] ) || ( max_inv_curr_enr_e == inv_curr_enr_e[i] && max_inv_curr_enr_m < inv_curr_enr_m[i] ) ) + IF( LT_16( max_inv_curr_enr_e, inv_curr_enr_e[i] ) || ( EQ_16( max_inv_curr_enr_e, inv_curr_enr_e[i] ) && LT_16( max_inv_curr_enr_m, inv_curr_enr_m[i] ) ) ) { max_inv_curr_enr_e = inv_curr_enr_e[i]; move16(); @@ -937,7 +937,7 @@ static Word16 procTec_Fx( &min_curr_enr_m, &min_curr_enr_e ); s = norm_s( min_curr_enr_m ); - min_curr_enr_m = shl( min_curr_enr_m, s ); + min_curr_enr_m = shl( min_curr_enr_m, s ); /*Q15 - min_curr_enr_e + s*/ min_curr_enr_e = sub( min_curr_enr_e, s ); lower_limit_gain_e = -3; @@ -978,19 +978,19 @@ static Word16 procTec_Fx( test(); IF( ( GT_16( lower_limit_gain_e, gain_e[i] ) ) || ( EQ_16( lower_limit_gain_e, gain_e[i] ) && GT_16( lower_limit_gain_m, gain_m[i] ) ) ) { - gain_m[i] = lower_limit_gain_m; + gain_m[i] = lower_limit_gain_m; /*Q15 - gain_e*/ move16(); gain_e[i] = lower_limit_gain_e; move16(); } - gain_m[i] = mult_r( gain_m[i], inv_curr_enr_m[i] ); + gain_m[i] = mult_r( gain_m[i], inv_curr_enr_m[i] ); /*Q15 - gain_e - inv_curr_enr_e*/ move16(); gain_e[i] = add( gain_e[i], inv_curr_enr_e[i] ); move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1000,16 +1000,16 @@ static Word16 procTec_Fx( IF( ( LT_16( upper_limit_gain_e, gain_e[i] ) ) || ( EQ_16( upper_limit_gain_e, gain_e[i] ) && LT_16( upper_limit_gain_m, gain_m[i] ) ) ) { - gain_m[i] = upper_limit_gain_m; + gain_m[i] = upper_limit_gain_m; /*Q15 - gain_e*/ move16(); gain_e[i] = upper_limit_gain_e; move16(); } - gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); + gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); /*Q15 - gain_e*/ move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1017,9 +1017,10 @@ static Word16 procTec_Fx( FOR( j = 0; j < l_subfr; j++ ) { s = norm_s( hb_synth_Fx[k] ); - hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); + hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); /*Q15 - gain_e - exp_syn + s*/ move16(); shift[k] = sub( s, gain_e[i] ); + move16(); if ( GT_16( min_shift, shift[k] ) ) { @@ -1058,7 +1059,7 @@ static Word16 procTec_Fx( if ( s > 0 ) { - hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); /*Q15 - exp_syn - s*/ move16(); } k = add( k, 1 ); @@ -1073,10 +1074,10 @@ static Word16 procTec_Fx( * *-------------------------------------------------------------------*/ static Word16 procTfa_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - exp_syn*/ Word16 exp_syn, - const Word16 i_offset, - const Word16 l_subfr ) + const Word16 i_offset, /*Q0*/ + const Word16 l_subfr /*Q0*/ ) { Word16 i, j, k; Word16 k_offset, n_subfr; @@ -1109,7 +1110,7 @@ static Word16 procTfa_Fx( k_offset, &enr_ave_m, l_subfr ); - enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); + enr_ave_m = mult_r( enr_ave_m, inv_n_subfr ); /*Q15 - enr_ave_e + 3*/ enr_ave_e = sub( enr_ave_e, 3 ); min_shift = 15; /* min_shift <= 15 */ @@ -1134,11 +1135,11 @@ static Word16 procTfa_Fx( move16(); } - gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); + gain_m[i] = Sqrt16( gain_m[i], &gain_e[i] ); /*Q15 - gain_e*/ move16(); s = norm_s( gain_m[i] ); - gain_m[i] = shl( gain_m[i], s ); + gain_m[i] = shl( gain_m[i], s ); /*Q15 - gain_e + s*/ move16(); gain_e[i] = sub( gain_e[i], s ); move16(); @@ -1146,7 +1147,7 @@ static Word16 procTfa_Fx( FOR( j = 0; j < l_subfr; j++ ) { s = norm_s( hb_synth_Fx[k] ); - hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); + hb_synth_Fx[k] = mult_r( gain_m[i], shl( hb_synth_Fx[k], s ) ); /*Q15 - gain_e - exp_syn + s*/ move16(); shift[k] = sub( s, gain_e[i] ); move16(); @@ -1188,7 +1189,7 @@ static Word16 procTfa_Fx( if ( s > 0 ) { - hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); + hb_synth_Fx[k] = shr( hb_synth_Fx[k], s ); /*Q15 - exp_syn - s*/ move16(); } k = add( k, 1 ); @@ -1203,14 +1204,14 @@ static Word16 procTfa_Fx( * *-------------------------------------------------------------------*/ Word16 procTecTfa_TBE_Fx( - Word16 *hb_synth_Fx, + Word16 *hb_synth_Fx, /*Q15 - hb_synth_fx_exp*/ Word16 hb_synth_fx_exp, - Word16 *gain_m, + Word16 *gain_m, /*Q15 - gain_e*/ Word16 *gain_e, - Word16 flat_flag, - Word16 last_core, - Word16 l_subfr, - Word16 code ) + Word16 flat_flag, /*Q0*/ + Word16 last_core, /*Q0*/ + Word16 l_subfr, /*Q0*/ + Word16 code /*Q0*/ ) { Word16 i_offset = 0; move16(); @@ -1226,7 +1227,7 @@ Word16 procTecTfa_TBE_Fx( } ELSE { - if ( NE_16( last_core, ACELP_CORE ) ) + if ( ( last_core != ACELP_CORE ) ) { i_offset = 1; move16(); @@ -1254,12 +1255,12 @@ Word16 procTecTfa_TBE_Fx( *-------------------------------------------------------------------*/ void calcHiEnvLoBuff_Fix( - const Word16 noCols, - const Word16 *pFreqBandTable, /*!< freqbandTable. */ - const Word16 nSfb, /*!< Number of scalefactors. */ - Word32 **pCldfbPow_Fix /*Word32** pCldfbPow*/, - Word16 *loBuffer_Fix /*Word32* loBuffer Q8*/, - Word16 *hiTempEnvOrig_Fix /*Word32* hiTempEnvOrig*/, + const Word16 noCols, /*Q0*/ + const Word16 *pFreqBandTable, /*!< freqbandTable. Q0*/ + const Word16 nSfb, /*!< Number of scalefactors. Q0*/ + Word32 **pCldfbPow_Fix /* pCldfbPow_FixScale*/, + Word16 *loBuffer_Fix /* Q8*/, + Word16 *hiTempEnvOrig_Fix /* Q7*/, Word16 pCldfbPow_FixScale ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; @@ -1271,7 +1272,7 @@ void calcHiEnvLoBuff_Fix( Word16 bandOffsetBottom; - Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; /*Q7*/ move16(); move16(); @@ -1304,18 +1305,18 @@ void calcHiEnvLoBuff_Fix( * *-------------------------------------------------------------------*/ void calcLoEnvCheckCorrHiLo_Fix( - const Word16 noCols, - const Word16 *pFreqBandTable, /*!< freqbandTable. */ + const Word16 noCols, /*Q0*/ + const Word16 *pFreqBandTable, /*!< freqbandTable. Q0*/ Word16 *loBuffer_Fix /*Word16* loBuffer Q8*/, Word16 *loTempEnv_Fix /*Word16* loTempEnv Q7*/, - Word16 *loTempEnv_ns_Fix /* Word16* loTempEnv_ns*/, - Word16 *hiTempEnvOrig_Fix /*Word16* hiTempEnvOrig*/, - Word16 *corrFlag /*int* corrFlag*/ + Word16 *loTempEnv_ns_Fix /* Word16* loTempEnv_ns Q7*/, + Word16 *hiTempEnvOrig_Fix /*Word16* hiTempEnvOrig Q7*/, + Word16 *corrFlag /*int* corrFlag Q0*/ ) { const Word16 BW_LO = TecLowBandTable[NBTECLOWBAND]; move16(); - const Word16 lowSubband = pFreqBandTable[0]; + const Word16 lowSubband = pFreqBandTable[0]; /*Q0*/ move16(); Word16 i; @@ -1337,7 +1338,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word32 loVar_ns_Fix; Word32 diff_hi_lo_sum_Fix; Word32 loSum_ns_Fix; - Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; + Word16 *hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; /*Q7*/ move16(); @@ -1351,10 +1352,10 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { - hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); + hiTempEnv32_Fix[i] = L_deposit_l( hiTempEnv[i] ); /*Q7*/ move32(); } - hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); + hiVar_Fix = calcVar_Fix( hiTempEnv32_Fix, (Word32) noCols, &hiSum_Fix ); /*Q7*/ /* ============================================================ */ @@ -1375,14 +1376,14 @@ void calcLoEnvCheckCorrHiLo_Fix( loTempEnv32_ns_Fix[i] = L_deposit_l( loTempEnv_ns_Fix[i] ); move32(); } - loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); + loVar_ns_Fix = calcVar_Fix( loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix ); /*Q7*/ diff_hi_lo_sum_Fix = L_sub( loSum_ns_Fix, hiSum_Fix ); - EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); - EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); + EQ4 = L_sub( L_shr( hiVar_Fix, 7 ), 800 ); /*Q0*/ + EQ5 = L_sub( L_shr( loVar_ns_Fix, 7 ), 720 ); /*Q0*/ - EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); + EQ6 = L_sub( L_shr( diff_hi_lo_sum_Fix, 7 ), 100 ); /*Q0*/ test(); test(); @@ -1406,9 +1407,9 @@ void calcLoEnvCheckCorrHiLo_Fix( Word16 maxPosHi, maxPosLo; Word16 maxHiFix, maxLoFix; - maxHiFix = hiTempEnv[0]; + maxHiFix = hiTempEnv[0]; /*Q7*/ move16(); - maxLoFix = loTempEnv_ns_Fix[0]; + maxLoFix = loTempEnv_ns_Fix[0]; /*Q7*/ move16(); maxPosHi = maxPosLo = 0; move16(); @@ -1447,7 +1448,7 @@ void calcLoEnvCheckCorrHiLo_Fix( Word16 j; Word16 len_window = EXT_DELAY_HI_TEMP_ENV + 1; move16(); - Word16 *curr_pos_Fix = hiTempEnv; + Word16 *curr_pos_Fix = hiTempEnv; /*Q7*/ move16(); move16(); @@ -1461,7 +1462,7 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < 16; i++ ) { - max_local_Fix = min_local_Fix = curr_pos_Fix[0]; + max_local_Fix = min_local_Fix = curr_pos_Fix[0]; /*Q7*/ move16(); move16(); @@ -1469,13 +1470,13 @@ void calcLoEnvCheckCorrHiLo_Fix( { if ( LT_16( max_local_Fix, curr_pos_Fix[-j] ) ) { - max_local_Fix = curr_pos_Fix[-j]; + max_local_Fix = curr_pos_Fix[-j]; /*Q7*/ move16(); } if ( GT_16( min_local_Fix, curr_pos_Fix[-j] ) ) { - min_local_Fix = curr_pos_Fix[-j]; + min_local_Fix = curr_pos_Fix[-j]; /*Q7*/ move16(); } } @@ -1494,7 +1495,7 @@ void calcLoEnvCheckCorrHiLo_Fix( IF( *corrFlag > 0 ) { test(); - if ( ( LE_16( feature_max_Fix, shl( 20, 7 ) ) || GE_16( abs_s( sub( pos_feature_max, maxPosHi ) ), 3 ) ) ) + if ( ( LE_16( feature_max_Fix, 2560 /*20 in Q7*/ ) || GE_16( abs_s( sub( pos_feature_max, maxPosHi ) ), 3 ) ) ) { *corrFlag = 0; move16(); @@ -1514,10 +1515,10 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < noCols; i++ ) { - loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); + loTempEnv32_Fix[i] = L_deposit_l( loTempEnv_Fix[i] ); /*Q7*/ move32(); } - loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); + loVar_Fix = calcVar_Fix( loTempEnv32_Fix, noCols, &loSum_Fix ); /*Q7*/ /* = = */ /* ============================================================ */ @@ -1531,9 +1532,9 @@ void calcLoEnvCheckCorrHiLo_Fix( /* ============================================================ */ - EQ1 = L_sub( L_shl( corrCoef_Fix, 8 ), 28819 /*thCorrCoef Q15*/ ); - EQ2 = L_sub( L_shl( hiVar_Fix, 0 ), Mpy_32_16_1( loVar_Fix, 11957 /*thRatio Q15*/ ) ); - EQ3 = L_sub( L_shr( hiVar_Fix, 2 ), Mpy_32_16_1( loVar_Fix, 16620 /*thRatio2 Q13*/ ) ); + EQ1 = L_sub( L_shl( corrCoef_Fix, 8 ), 28819 /*thCorrCoef Q15*/ ); /*Q15*/ + EQ2 = L_sub( L_shl( hiVar_Fix, 0 ), Mpy_32_16_1( loVar_Fix, 11957 /*thRatio Q15*/ ) ); /*Q7*/ + EQ3 = L_sub( L_shr( hiVar_Fix, 2 ), Mpy_32_16_1( loVar_Fix, 16620 /*thRatio2 Q13*/ ) ); /*Q5*/ test(); test(); @@ -1546,13 +1547,13 @@ void calcLoEnvCheckCorrHiLo_Fix( FOR( i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++ ) { - loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; + loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; /*Q8*/ move16(); } FOR( i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++ ) { - hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; + hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; /*Q7*/ move16(); } } @@ -1564,9 +1565,9 @@ void calcLoEnvCheckCorrHiLo_Fix( *-------------------------------------------------------------------*/ void tecEnc_TBE_fx( - Word16 *corrFlag, - const Word16 *voicing, - const Word16 coder_type ) + Word16 *corrFlag, /*Q0*/ + const Word16 *voicing, /*Q15*/ + const Word16 coder_type /*Q0*/ ) { Word16 voice_sum; Word16 voice_diff; @@ -1575,8 +1576,8 @@ void tecEnc_TBE_fx( * TEC updates *-----------------------------------------------------------------*/ - voice_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) ); /*voice_sum = voicing[0] + voicing[1];*/ - voice_diff = sub( voicing[0], voicing[1] ); /*voice_diff = voicing[0] - voicing[1];*/ + voice_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) ); /*voice_sum = voicing[0] + voicing[1];*/ /*Q15*/ + voice_diff = sub( voicing[0], voicing[1] ); /*voice_diff = voicing[0] - voicing[1]; Q15*/ if ( voice_diff < 0 ) { @@ -1589,7 +1590,7 @@ void tecEnc_TBE_fx( test(); test(); /*if( ((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2)) )*/ - if ( EQ_16( coder_type, INACTIVE ) || ( GT_16( voice_sum, 11469 /*0.35 Q15*/ ) && LT_16( voice_sum, 18022 /*0.55 Q15*/ ) && ( sub( voice_diff, 6554 /*0.2 Q15*/ ) < 0 ) ) ) + if ( ( coder_type == INACTIVE ) || ( GT_16( voice_sum, 11469 /*0.35 Q15*/ ) && LT_16( voice_sum, 18022 /*0.55 Q15*/ ) && ( sub( voice_diff, 6554 /*0.2 Q15*/ ) < 0 ) ) ) { *corrFlag = 0; move16(); @@ -1607,9 +1608,9 @@ void tecEnc_TBE_fx( * *-------------------------------------------------------------------*/ void set_TEC_TFA_code_fx( - const Word16 corrFlag, - Word16 *tec_flag, - Word16 *tfa_flag ) + const Word16 corrFlag, /*Q0*/ + Word16 *tec_flag, /*Q0*/ + Word16 *tfa_flag /*Q0*/ ) { *tec_flag = 0; move16(); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 2f37fb102e1445370d3330ceabeacc91c58f1918..5e16ff6c27270431af98c80796275d5221c020f4 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -220,13 +220,13 @@ void InitTnsConfiguration( #ifdef IVAS_FLOAT_FIXED void InitTnsConfiguration_ivas_fx( - const Word16 bwidth, - const Word16 frameLength, + const Word16 bwidth, /*Q0*/ + const Word16 frameLength, /*Q0*/ STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ) + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 is_mct /*Q0*/ ) { Word16 iFilter = 0; move16(); @@ -238,7 +238,7 @@ void InitTnsConfiguration_ivas_fx( nSampleRate = bwMode2fs[bwidth]; move32(); - startLineFilter = &pTnsConfig->iFilterBorders[1]; + startLineFilter = &pTnsConfig->iFilterBorders[1]; /*Q0*/ /* Sanity checks */ assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); @@ -257,7 +257,7 @@ void InitTnsConfiguration_ivas_fx( IF( LE_32( total_brate, ACELP_32k ) ) { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE @@ -265,7 +265,7 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } @@ -281,7 +281,7 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_16( element_mode, IVAS_SCE ) && GE_32( total_brate, L_tmp ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ move16(); IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { @@ -296,7 +296,7 @@ void InitTnsConfiguration_ivas_fx( { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters32kHz; @@ -311,13 +311,13 @@ void InitTnsConfiguration_ivas_fx( IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz; } } @@ -332,7 +332,7 @@ void InitTnsConfiguration_ivas_fx( assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f * nSampleRate ); assert( nSampleRate <= 96000 ); move16(); - startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); + startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); /*Q0*/ } IF( igfStopFreq > 0 ) @@ -342,12 +342,12 @@ void InitTnsConfiguration_ivas_fx( s2 = norm_l( nSampleRate ); move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); + pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); /*Q0*/ } ELSE { move16(); - pTnsConfig->iFilterBorders[0] = frameLength; + pTnsConfig->iFilterBorders[0] = frameLength; /*Q0*/ } pTnsConfig->allowTnsOnWhite = 0; @@ -368,8 +368,8 @@ void InitTnsConfiguration_ivas_fx( void ApplyTnsFilter( STnsConfig const *pTnsConfig, STnsData const *pTnsData, - Word32 spectrum[], - const Word8 fIsAnalysis ) + Word32 spectrum[], /*Qx*/ + const Word8 fIsAnalysis /*Q0*/ ) { TLinearPredictionFilter filter; Word32 state[TNS_MAX_FILTER_ORDER]; @@ -382,12 +382,11 @@ void ApplyTnsFilter( filter = IIRLattice; if ( fIsAnalysis ) { - move16(); filter = FIRLattice; } set32_fx( state, 0, TNS_MAX_FILTER_ORDER ); move16(); - pBorders = pTnsConfig->iFilterBorders; + pBorders = pTnsConfig->iFilterBorders; /*Q0*/ FOR( iFilter = pTnsConfig->nMaxFilters - 1; iFilter >= 0; iFilter-- ) { @@ -419,15 +418,15 @@ void ApplyTnsFilter( *-------------------------------------------------------------------*/ void ITF_Apply_fx( - Word32 spectrum[], - Word16 startLine, - Word16 stopLine, - const Word16 *A, + Word32 spectrum[], /*Qx*/ + Word16 startLine, /*Q0*/ + Word16 stopLine, /*Q0*/ + const Word16 *A, /*Q_A*/ Word16 Q_A, - Word16 order ) + Word16 order /*Q0*/ ) { - ITF_TnsFilter_fx( &spectrum[startLine], (Word16) ( stopLine - startLine ), A, Q_A, (Word16) order, &spectrum[startLine] ); + ITF_TnsFilter_fx( &spectrum[startLine], sub( stopLine, startLine ), A, Q_A, order, &spectrum[startLine] ); return /*TNS_NO_ERROR*/; } @@ -438,14 +437,14 @@ void ITF_Apply_fx( *-------------------------------------------------------------------*/ Word16 ITF_Detect_fx( - const Word32 pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16 *A, + const Word32 pSpectrum[], /*Q*/ + const Word16 startLine, /*Q0*/ + const Word16 stopLine, /*Q0*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /*Q_A*/ Word16 *Q_A, - Word16 *predictionGain, - Word16 *curr_order, + Word16 *predictionGain, /*Q7*/ + Word16 *curr_order, /*Q0*/ Word16 Q ) { @@ -484,25 +483,25 @@ Word16 ITF_Detect_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); tmp = sub( stopLine, startLine ); - iStartLine = imult1616( tmp, iSubdivisions ); + iStartLine = imult1616( tmp, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, tmp ); if ( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); if ( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /*Q31 - shift*/ /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); -#else /* BASOP_NOGLOB */ + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#else /* BASOP_NOGLOB */ tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -536,7 +535,7 @@ Word16 ITF_Detect_fx( /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ #ifdef BASOP_NOGLOB - facs[iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 */ + facs[iSubdivisions] = div_s( 0x2000, round_fx_sat( L_tmp ) ); /* L_tmp is >= 0x2000000 Q15*/ #else facs[iSubdivisions] = div_s( 0x2000, round_fx( L_tmp ) ); /* L_tmp is >= 0x2000000 */ #endif @@ -559,15 +558,15 @@ Word16 ITF_Detect_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616( spectrumLength, iSubdivisions ); - iEndLine = add( iStartLine, spectrumLength ); + iStartLine = imult1616( spectrumLength, iSubdivisions ); /*Q0*/ + iEndLine = add( iStartLine, spectrumLength ); /*Q0*/ if ( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); if ( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); @@ -578,7 +577,7 @@ Word16 ITF_Detect_fx( assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx_sat( L_shl_sat( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); + tmpbuf[i] = round_fx_sat( L_shl_sat( pSpectrum[iStartLine + i - IGF_START_MN], shift ) ); /*Q + shift - 16*/ move16(); } @@ -590,13 +589,13 @@ Word16 ITF_Detect_fx( Word64 tmp64 = 0; FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); /*2*(Q + shift) - 32*/ } - L_tmp = W_sat_l( tmp64 ); + L_tmp = W_sat_l( tmp64 ); /*2*(Q + shift) - 32*/ } - L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); - L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); /*2*(Q + shift) - 32*/ + L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); /*2*(Q + shift) - 32 + facs_e*/ rxx[lag] = L_add( rxx[lag], L_tmp ); move32(); @@ -608,7 +607,7 @@ Word16 ITF_Detect_fx( /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); - *curr_order = maxOrder; + *curr_order = maxOrder; /*Q0*/ move16(); } @@ -616,14 +615,14 @@ Word16 ITF_Detect_fx( } Word16 ITF_Detect_ivas_fx( - const Word32 pSpectrum[], - const Word16 startLine, - const Word16 stopLine, - const Word16 maxOrder, - Word16 *A, + const Word32 pSpectrum[], /*Q*/ + const Word16 startLine, /*Q0*/ + const Word16 stopLine, /*Q0*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /*Q_A*/ Word16 *Q_A, - Word16 *predictionGain, - Word16 *curr_order, + Word16 *predictionGain, /*Q7*/ + Word16 *curr_order, /*Q0*/ Word16 Q ) { @@ -661,25 +660,25 @@ Word16 ITF_Detect_ivas_fx( assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); tmp = sub( stopLine, startLine ); - iStartLine = imult1616( tmp, iSubdivisions ); + iStartLine = imult1616( tmp, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, tmp ); IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); headroom = getScaleFactor32( pSpectrum + iStartLine - IGF_START_MN, sub( iEndLine, iStartLine ) ); /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); + L_tmp = Norm32Norm( pSpectrum + iStartLine - IGF_START_MN, headroom, sub( iEndLine, iStartLine ), &shift ); /*Q31 - shift*/ /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB - tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); -#else /* BASOP_NOGLOB */ + tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, 24 - Q ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#else /* BASOP_NOGLOB */ tmp32 = L_sub( L_shl( L_tmp, sub( shift, 24 - Q ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); #endif BASOP_SATURATE_WARNING_ON_EVS; @@ -698,8 +697,8 @@ Word16 ITF_Detect_ivas_fx( if ( tmp32 > 0 ) { - facs[iSubdivisions] = 0x7FFF; - move16(); /* normalization not needed for one subdivision */ + facs[iSubdivisions] = 0x7FFF; /*Q15*/ + move16(); /* normalization not needed for one subdivision */ } IF( L_tmp > 0 ) @@ -711,10 +710,10 @@ Word16 ITF_Detect_ivas_fx( L_tmp = L_shl( L_tmp, sub( shift, tmp ) ); /* shift L_tmp to that exponent */ /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 */ + facs[iSubdivisions] = div_s( 0x2000, round_fx_o( L_tmp, &Overflow ) ); /* L_tmp is >= 0x2000000 Q15*/ move16(); } - norms[iSubdivisions] = sum2_32_fx( pSpectrum + sub( iStartLine, IGF_START_MN ), sub( iEndLine, iStartLine ), &norms_e[iSubdivisions] ); + norms[iSubdivisions] = sum2_32_fx( pSpectrum + sub( iStartLine, IGF_START_MN ), sub( iEndLine, iStartLine ), &norms_e[iSubdivisions] ); /*Q31 - norms_e*/ move16(); } @@ -722,21 +721,21 @@ Word16 ITF_Detect_ivas_fx( set32_fx( rxx, 0, ITF_MAX_FILTER_ORDER + 1 ); spectrumLength = sub( stopLine, startLine ); - + test(); FOR( iSubdivisions = 0; ( iSubdivisions < nSubdivisions ) && GT_64( norms[iSubdivisions], W_shl( HLM_MIN_NRG_FX, sub( 31, norms_e[iSubdivisions] ) ) ); iSubdivisions++ ) { test(); assert( ( nSubdivisions == 1 ) || ( nSubdivisions == 3 ) ); - iStartLine = imult1616( spectrumLength, iSubdivisions ); + iStartLine = imult1616( spectrumLength, iSubdivisions ); /*Q0*/ iEndLine = add( iStartLine, spectrumLength ); IF( EQ_16( nSubdivisions, 3 ) ) - iStartLine = mult( iStartLine, 0x2AAB ); + iStartLine = mult( iStartLine, 0x2AAB ); /*Q0*/ iStartLine = add( iStartLine, startLine ); IF( EQ_16( nSubdivisions, 3 ) ) - iEndLine = mult( iEndLine, 0x2AAB ); + iEndLine = mult( iEndLine, 0x2AAB ); /*Q0*/ iEndLine = add( iEndLine, startLine ); @@ -747,7 +746,7 @@ Word16 ITF_Detect_ivas_fx( assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); + tmpbuf[i] = round_fx_o( L_shl( pSpectrum[iStartLine + i - IGF_START_MN], shift ), &Overflow ); /*Q+shift-16*/ move16(); } @@ -759,15 +758,15 @@ Word16 ITF_Detect_ivas_fx( Word64 tmp64 = 0; FOR( i = 0; i < n; i++ ) { - tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); + tmp64 = W_mac0_16_16( tmp64, tmpbuf[i], tmpbuf[i + lag] ); /*2*( Q+shift-16)*/ } - L_tmp = W_sat_l( tmp64 ); + L_tmp = W_sat_l( tmp64 ); /*2*( Q+shift-16)*/ } - L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); + L_tmp = Mpy_32_16_1( L_tmp, facs[iSubdivisions] ); /*2*( Q+shift-16)*/ L_tmp = L_shl( L_tmp, facs_e[iSubdivisions] ); - rxx[lag] = L_add( rxx[lag], L_tmp ); + rxx[lag] = L_add( rxx[lag], L_tmp ); /*2*( Q+shift-16)*/ move32(); } } @@ -781,7 +780,7 @@ Word16 ITF_Detect_ivas_fx( /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); - *curr_order = maxOrder; + *curr_order = maxOrder; /*Q0*/ move16(); } @@ -793,31 +792,31 @@ Word16 ITF_Detect_ivas_fx( /** Get number of bits from a Huffman table. * The table must be sorted by values. */ -static Word16 GetBitsFromTable( const Word16 value, const Coding codes[], const Word16 nSize ) +static Word16 GetBitsFromTable( const Word16 value /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { (void) nSize; assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); cast16(); - return (Word16) codes[value].nBits; + return (Word16) codes[value].nBits; /*Q0*/ } /** Get the code for a value from a Huffman table. * The table must be sorted by values. */ -static Word16 EncodeUsingTable( const Word16 value, const Coding codes[], const Word16 nSize ) +static Word16 EncodeUsingTable( const Word16 value /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { (void) nSize; assert( ( value >= 0 ) && ( value < nSize ) && ( nSize >= 0 ) && ( nSize <= 256 ) ); move16(); - return codes[value].code; + return codes[value].code; /*Q0*/ } /** Decode a value from a bitstream using a Huffman table. */ -static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding codes[], const Word16 nSize ) +static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue /*Q0*/, const Coding codes[], const Word16 nSize /*Q0*/ ) { Word16 code = 0; Word16 nBits = 0; @@ -834,9 +833,10 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding WHILE( valueIndex == nSize ) { - code = add( shl( code, 1 ), get_next_indice_fx( st, 1 ) ); + code = add( shl( code, 1 ), get_next_indice_fx( st, 1 ) ); /*Q0*/ nBits = add( nBits, 1 ); - if ( nBits > nSize || nBits > 16 ) + test(); + IF( GT_16( nBits, nSize ) || GT_16( nBits, 16 ) ) { st->BER_detect = 1; move16(); @@ -855,12 +855,12 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding } } } - if ( valueIndex < nSize ) + IF( LT_16( valueIndex, nSize ) ) { - *pValue = (Word16) codes[valueIndex].value; + *pValue = (Word16) codes[valueIndex].value; /*Q0*/ move16(); } - else + ELSE { st->BER_detect = 1; move16(); @@ -869,20 +869,20 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue, const Coding return -1; } - return nBits; + return nBits; /*Q0*/ } /* TNS filter coefficients */ -void const *GetTnsFilterCoeff( void const *p, const Word16 index, Word16 *pValue ) +void const *GetTnsFilterCoeff( void const *p, const Word16 index /*Q0*/, Word16 *pValue /*Q0*/ ) { *pValue = ( (Word16 const *) p )[index] + INDEX_SHIFT; move16(); return NULL; } -void *SetTnsFilterCoeff( void *p, const Word16 index, const Word16 value ) +void *SetTnsFilterCoeff( void *p, const Word16 index /*Q0*/, const Word16 value /*Q0*/ ) { ( (Word16 *) p )[index] = sub( value, INDEX_SHIFT ); move16(); @@ -894,63 +894,63 @@ Word16 GetSWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeSWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 GetSWBTCX10TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeSWBTCX10TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); /*Q0*/ } Word16 GetWBTCX20TnsFilterCoeffBits( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 EncodeWBTCX20TnsFilterCoeff( const Word16 value, const Word16 index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); - return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); + return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); /*Q0*/ } @@ -959,82 +959,82 @@ Word16 DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const Word16 index, Word1 void const *GetTnsFilterOrder( void const *p, const Word16 index, Word16 *pValue ) { move16(); - *pValue = ( (STnsFilter const *) p )[index].order; + *pValue = ( (STnsFilter const *) p )[index].order; /*Q0*/ move16(); - return ( (STnsFilter const *) p )[index].coefIndex; + return ( (STnsFilter const *) p )[index].coefIndex; /*Q0*/ } void *SetTnsFilterOrder( void *p, const Word16 index, const Word16 value ) { move16(); - ( (STnsFilter *) p )[index].order = value; + ( (STnsFilter *) p )[index].order = value; /*Q0*/ move16(); - return ( (STnsFilter *) p )[index].coefIndex; + return ( (STnsFilter *) p )[index].coefIndex; /*Q0*/ } Word16 GetTnsFilterOrderBitsSWBTCX20( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrderSWBTCX20( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); /*Q0*/ } Word16 GetTnsFilterOrderBitsSWBTCX10( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrderSWBTCX10( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); /*Q0*/ } Word16 GetTnsFilterOrderBits( const Word16 value, const Word16 index ) { (void) index; - return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); + return GetBitsFromTable( sub( value, 1 ), codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } Word16 EncodeTnsFilterOrder( const Word16 value, const Word16 index ) { (void) index; - return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); + return EncodeUsingTable( sub( value, 1 ), codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; - return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); + return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); /*Q0*/ } /* Number of TNS filters */ @@ -1042,7 +1042,7 @@ Word16 DecodeTnsFilterOrder( Decoder_State *st, const Word16 index, Word16 *pVal void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValue ) { move16(); - *pValue = ( (STnsData const *) p )[index].nFilters; + *pValue = ( (STnsData const *) p )[index].nFilters; /*Q0*/ move16(); return ( (STnsData const *) p )[index].filter; } @@ -1050,7 +1050,7 @@ void const *GetNumOfTnsFilters( void const *p, const Word16 index, Word16 *pValu void *SetNumOfTnsFilters( void *p, const Word16 index, Word16 value ) { move16(); - ( (STnsData *) p )[index].nFilters = value; + ( (STnsData *) p )[index].nFilters = value; /*Q0*/ move16(); return ( (STnsData *) p )[index].filter; } @@ -1110,8 +1110,7 @@ void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ) { - move16(); - ( (STnsData *) p )[index].nFilters = value; + ( (STnsData *) p )[index].nFilters = value; /*Q0*/ move16(); return ( (STnsData *) p )[index].filter; } @@ -1135,11 +1134,11 @@ void ResetTnsData( STnsData *pTnsData ) STnsFilter *const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; move16(); - pTnsFilter->predictionGain = ONE_IN_Q7; + pTnsFilter->predictionGain = ONE_IN_Q7; /*Q7*/ move16(); pTnsFilter->avgSqrCoef = 0; move16(); - pTnsFilter->filterType = TNS_FILTER_OFF; + pTnsFilter->filterType = TNS_FILTER_OFF; /*Q0*/ move16(); ClearTnsFilterCoefficients( pTnsFilter ); } @@ -1180,18 +1179,18 @@ void ClearTnsFilterCoefficients( * @param parCoeff output reflection coefficients. * @param order number of coefficients/values. */ -static void Index2Parcor( const Word16 index[], Word16 parCoeff[], Word16 order ) +static void Index2Parcor( const Word16 index[] /*Q0*/, Word16 parCoeff[] /*Q15*/, Word16 order /*Q0*/ ) { const Word16 *values; Word16 i; move16(); - values = tnsCoeff4; + values = tnsCoeff4; /*Q15*/ FOR( i = 0; i < order; i++ ) { move16(); - parCoeff[i] = values[add( index[i], INDEX_SHIFT )]; + parCoeff[i] = values[( index[i] + INDEX_SHIFT )]; /*Q15*/ } return; } @@ -1199,10 +1198,10 @@ static void Index2Parcor( const Word16 index[], Word16 parCoeff[], Word16 order /* Linear prediction analysis filter. */ static Word32 FIRLattice( - const Word16 order, + const Word16 order, /*Q0*/ const Word16 *parCoeff /*Q15*/, - Word32 *state, - Word32 x /* Q0 */ + Word32 *state, /*Q0*/ + Word32 x /* Q0 */ ) { Word16 i; @@ -1213,40 +1212,40 @@ static Word32 FIRLattice( move32(); FOR( i = 0; i < order - 1; i++ ) { - tmp = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); - x = L_add( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); /* exponent: 31+0 */ - state[i] = tmpSave; + tmp = L_add( state[i], Mpy_32_16_1( x, parCoeff[i] ) ); /*Q0*/ + x = L_add( x, Mpy_32_16_1( state[i], parCoeff[i] ) ); /* exponent: 31+0 */ + state[i] = tmpSave; /*Q0*/ move32(); - tmpSave = tmp; + tmpSave = tmp; /*Q0*/ move32(); } /* last stage: only need half operations */ - x = L_add( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); - state[order - 1] = tmpSave; + x = L_add( x, Mpy_32_16_1( state[order - 1], parCoeff[order - 1] ) ); /*Q0*/ + state[order - 1] = tmpSave; /*Q0*/ move32(); - return x; + return x; /*Q0*/ } -static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x ) +static Word32 IIRLattice( Word16 order /*Q0*/, const Word16 *parCoeff /*Q15*/, Word32 *state /*Q0*/, Word32 x /*Q0*/ ) { Word16 i; /* first stage: no need to calculate state[order-1] */ - x = Msub_32_16( x, state[order - 1], parCoeff[order - 1] ); + x = Msub_32_16( x, state[order - 1], parCoeff[order - 1] ); /*Q0*/ FOR( i = order - 2; i >= 0; i-- ) { - x = Msub_32_16( x, state[i], parCoeff[i] ); - state[i + 1] = Madd_32_16( state[i], x, parCoeff[i] ); + x = Msub_32_16( x, state[i], parCoeff[i] ); /*Q0*/ + state[i + 1] = Madd_32_16( state[i], x, parCoeff[i] ); /*Q0*/ move32(); } move32(); - state[0] = x; - return x; + state[0] = x; /*Q0*/ + return x; /*Q0*/ } /** TNS analysis/synthesis filter. * @param spectrum input spectrum values. @@ -1259,13 +1258,13 @@ static Word32 IIRLattice( Word16 order, const Word16 *parCoeff, Word32 *state, W Inplace operation is supported, so it can be equal to spectrum. */ static void TnsFilter( - const Word32 spectrum[], - const Word16 numOfLines, - const Word16 parCoeff[], - const Word16 order, + const Word32 spectrum[], /*Qx*/ + const Word16 numOfLines, /*Q0*/ + const Word16 parCoeff[], /*Q15*/ + const Word16 order, /*Q0*/ TLinearPredictionFilter filter, - Word32 *state, - Word32 output[] ) + Word32 *state, /*Q0*/ + Word32 output[] /*Qx*/ ) { Word16 j; @@ -1279,7 +1278,7 @@ static void TnsFilter( test(); IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32( spectrum, output, numOfLines ); + Copy32( spectrum, output, numOfLines ); /*Qx*/ } } ELSE @@ -1289,7 +1288,7 @@ static void TnsFilter( FOR( j = 0; j < numOfLines; j++ ) { move32(); - output[j] = filter( order, parCoeff, state, spectrum[j] ); + output[j] = filter( order, parCoeff, state, spectrum[j] ); /*Qx*/ } } } @@ -1297,12 +1296,12 @@ static void TnsFilter( } static void ITF_TnsFilter_fx( - const Word32 spectrum[], - const Word16 numOfLines, - const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + const Word32 spectrum[], /*Qx*/ + const Word16 numOfLines, /*Q0*/ + const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ const Word16 Q_A, - const Word16 order, - Word32 output[] ) + const Word16 order, /*Q0*/ + Word32 output[] /*Qx*/ ) { Word16 i, j; Word32 buf[ITF_MAX_FILTER_ORDER + N_MAX]; @@ -1317,7 +1316,7 @@ static void ITF_TnsFilter_fx( test(); IF( s_and( ( spectrum != output ), numOfLines > 0 ) ) { - Copy32( spectrum, output, numOfLines ); + Copy32( spectrum, output, numOfLines ); /*Qx*/ } } ELSE @@ -1326,7 +1325,7 @@ static void ITF_TnsFilter_fx( p = buf + ITF_MAX_FILTER_ORDER; set32_fx( buf, 0, ITF_MAX_FILTER_ORDER ); - Copy32( spectrum, p, numOfLines ); + Copy32( spectrum, p, numOfLines ); /*Qx*/ FOR( j = 0; j < numOfLines; j++ ) { Word32 L_tmp; @@ -1334,9 +1333,9 @@ static void ITF_TnsFilter_fx( L_tmp = L_add( p[0], 0 ); FOR( i = 1; i < order; i++ ) { - L_tmp = L_add_sat( L_tmp, L_shl( Mpy_32_16_1( p[-i], A[i] ), shift ) ); + L_tmp = L_add_sat( L_tmp, L_shl( Mpy_32_16_1( p[-i], A[i] ), shift ) ); /*Qx*/ } - output[j] = L_tmp; + output[j] = L_tmp; /*Qx*/ move32(); ++p; } @@ -1345,11 +1344,11 @@ static void ITF_TnsFilter_fx( } static void ITF_GetFilterParameters_fx( - Word32 rxx[], - const Word16 maxOrder, - Word16 *A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ + Word32 rxx[], /*Qx*/ + const Word16 maxOrder, /*Q0*/ + Word16 *A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ Word16 *Q_A, - Word16 *predictionGain ) + Word16 *predictionGain /*Q7*/ ) { Word16 i, j, i_2, tmp; Word16 parCoeff[ITF_MAX_FILTER_ORDER]; @@ -1357,8 +1356,8 @@ static void ITF_GetFilterParameters_fx( /* compute filter in ParCor form with LeRoux-Gueguen algorithm */ L_tmp = E_LPC_schur( rxx, parCoeff, epsP, maxOrder ); - BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ - *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); + BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, this value is compared against a threshold. */ + *predictionGain = divide3232( L_shr( epsP[0], PRED_GAIN_E ), L_tmp ); /*Q7*/ move16(); BASOP_SATURATE_WARNING_ON_EVS @@ -1381,15 +1380,15 @@ static void ITF_GetFilterParameters_fx( { tmp1_l = L_Extract_lc( A32[i - 1 - j + 1], &tmp1_h ); tmp2_l = L_Extract_lc( A32[j + 1], &tmp2_h ); - A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp1_h, tmp1_l ); /*+= parCoeff[i] * a[i-1-j+1];*/ + A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp1_h, tmp1_l ); /*+= parCoeff[i] * a[i-1-j+1]; Q11+16*/ move32(); - A32[i - 1 - j + 1] = Mac_32( A32[i - 1 - j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * tmp;*/ + A32[i - 1 - j + 1] = Mac_32( A32[i - 1 - j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * tmp; Q11+16*/ move32(); } - if ( i & 1 ) + IF( s_and( i, 1 ) ) { tmp2_l = L_Extract_lc( A32[j + 1], &tmp2_h ); - A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * a[j+1];*/ + A32[j + 1] = Mac_32( A32[j + 1], parCoeff[i], 0, tmp2_h, tmp2_l ); /*+= parCoeff[i] * a[j+1]; Q11+16*/ move32(); } diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 82e2c981c7d80f4f60d45183e7a58ab5240b7fb2..d4792fb7517c940a9244a9cc51089d14137b636a 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -13,12 +13,12 @@ * Transformation of the signal to DCT domain *-------------------------------------------------------------------*/ void direct_transform_fx( - const Word32 in32_fx[], /* i : input signal */ - Word32 out32_fx[], /* o : transformation */ - const Word16 is_transient, /* i : is transient */ - const Word16 L, /* i : length */ + const Word32 in32_fx[], /* i : input signal Q*/ + Word32 out32_fx[], /* o : transformation Q*/ + const Word16 is_transient, /* i : is transient Q0*/ + const Word16 L, /* i : length Q0*/ Word16 *Q, - const Word16 element_mode /* i : IVAS element mode */ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { @@ -53,54 +53,54 @@ void direct_transform_fx( { IF( EQ_16( L, L_FRAME48k ) ) { - win_fx = wscw16q15_fx; + win_fx = wscw16q15_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME32k ) ) { - win_fx = wscw16q15_32_fx; + win_fx = wscw16q15_32_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME8k ) ) { - win_fx = wscw16q15_8_fx; + win_fx = wscw16q15_8_fx; /*Q15*/ } ELSE { - win_fx = wscw16q15_16_fx; + win_fx = wscw16q15_16_fx; /*Q15*/ } - sh_fx = &in32_fx[sub( L, 1 )]; - sl_fx = &in32_r16_fx[sub( L, 1 )]; + sh_fx = &in32_fx[( L - 1 )]; /*Q*/ + sl_fx = &in32_r16_fx[( L - 1 )]; /*Q*/ FOR( i = 0; i < segment_length; i++ ) { - in32_r16_fx[i] = ( *sh_fx-- ); + in32_r16_fx[i] = ( *sh_fx-- ); /*Q*/ move32(); - ( *sl_fx-- ) = in32_fx[i]; + ( *sl_fx-- ) = in32_fx[i]; /*Q*/ move32(); } - iseg_fx = &in32_r16_fx[-segment_length4]; - oseg_fx = out32_fx; + iseg_fx = &in32_r16_fx[-segment_length4]; /*Q*/ + oseg_fx = out32_fx; /*Q*/ - wh_fx = &win_fx[segment_length4]; - wl_fx = wh_fx - 1; + wh_fx = &win_fx[segment_length4]; /*Q15*/ + wl_fx = wh_fx - 1; /*Q15*/ - shift = extract_l( L_mult0( 3, segment_length4 ) ); - sh_fx = &iseg_fx[shift]; - sl_fx2 = sh_fx - 1; + shift = extract_l( L_mult0( 3, segment_length4 ) ); /*Q0*/ + sh_fx = &iseg_fx[shift]; /*Q*/ + sl_fx2 = sh_fx - 1; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); - move32(); /*Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); /*Q*/ + move32(); } - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - dctin32_fx[i] = L_negate( *sl_fx2-- ); + dctin32_fx[i] = L_negate( *sl_fx2-- ); /*Q*/ move32(); } @@ -114,27 +114,27 @@ void direct_transform_fx( FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { - wh_fx = &win_fx[segment_length4]; - wl_fx = wh_fx - 1; - sh_fx = &iseg_fx[shift]; - sl_fx2 = sh_fx - 1; + wh_fx = &win_fx[segment_length4]; /*Q15*/ + wl_fx = wh_fx - 1; /*Q15*/ + sh_fx = &iseg_fx[shift]; /*Q*/ + sl_fx2 = sh_fx - 1; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { L_tmp = L_negate( Mult_32_16( ( *sh_fx++ ), ( *wh_fx++ ) ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); - move32(); /*Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx-- ); /*Q*/ + move32(); } - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; - wh_fx = &win_fx[sub( segment_length2, 1 )]; - wl_fx = win_fx; + sh_fx = iseg_fx; /*Q*/ + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ + wh_fx = &win_fx[( segment_length2 - 1 )]; /*Q15*/ + wl_fx = win_fx; /*Q15*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( ( *sh_fx++ ), ( *wh_fx-- ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx++ ); - move32(); /*Q */ + L_tmp = Mult_32_16( ( *sh_fx++ ), ( *wh_fx-- ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sl_fx2--, *wl_fx++ ); /*Q*/ + move32(); } Qs[seg] = *Q; @@ -146,24 +146,24 @@ void direct_transform_fx( oseg_fx += segment_length2; } - sh_fx = &iseg_fx[sub( shift, 1 )]; + sh_fx = &iseg_fx[( shift - 1 )]; /*Q*/ FOR( i = 0; i < segment_length4; i++ ) { - dctin32_fx[i] = L_negate( *sh_fx-- ); + dctin32_fx[i] = L_negate( *sh_fx-- ); /*Q*/ move32(); } - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[sub( segment_length2, 1 )]; - wh_fx = &win_fx[sub( segment_length2, 1 )]; - wl_fx = win_fx; + sh_fx = iseg_fx; /*Q*/ + sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ + wh_fx = &win_fx[( segment_length2 - 1 )]; /*Q15*/ + wl_fx = win_fx; /*Q15*/ FOR( i = segment_length4; i < segment_length2; i++ ) { - L_tmp = Mult_32_16( ( *sl_fx2-- ), ( *wl_fx++ ) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16( L_tmp, *sh_fx++, *wh_fx-- ); - move32(); /*Q */ + L_tmp = Mult_32_16( ( *sl_fx2-- ), ( *wl_fx++ ) ); /*Q+15-15=Q */ + dctin32_fx[i] = Madd_32_16( L_tmp, *sh_fx++, *wh_fx-- ); /*Q*/ + move32(); } Qs[NUM_TIME_SWITCHING_BLOCKS - 1] = *Q; move16(); @@ -172,13 +172,13 @@ void direct_transform_fx( *Q = Qmin; move16(); - oseg_fx = out32_fx; + oseg_fx = out32_fx; /*Q*/ FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) { shift = sub( Qs[k], *Q ); FOR( i = 0; i < segment_length2; i++ ) { - *oseg_fx = L_shr( ( *oseg_fx ), shift ); + *oseg_fx = L_shr( ( *oseg_fx ), shift ); /*Q*/ move32(); oseg_fx++; } diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 6916a6cdbb3ae2220275ca8296d1eb2081fca8f4..5c41122fbdd79b81775ad846957056822ea95d67 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -111,7 +111,7 @@ void preecho_sb_fx( move16(); smooth_len = 4; move16(); - invsmoothlenp1_fx = 6554; + invsmoothlenp1_fx = 6554; /*0.2 in Q15*/ move16(); IF( EQ_16( nb_flag, 1 ) ) { @@ -123,7 +123,7 @@ void preecho_sb_fx( move16(); } - limmaxnzcr = mult( framelength, 1365 ); /*1/24*/ + limmaxnzcr = mult( framelength, 1365 ); /*1/24 in Q15*/ /*Q0*/ num_subsubframes = 8; move16(); log2_num_subsubframes = 3; @@ -137,15 +137,15 @@ void preecho_sb_fx( move16(); } - len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ + len3xLp20 = mult_r( framelength, 7168 ); /*7*framelength/32;*/ /*Q0*/ /* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/ fxptr1 = imdct_mem_fx; - fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; + fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; /*q_sig32*/ FOR( i = 0; i < len3xLp20; i++ ) { #ifdef BASOP_NOGLOB - *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, 15 - q_sig32 ) ) ); + *fxptr1++ = negate( extract_h( L_shl_sat( *fx32ptr1--, sub( 15, q_sig32 ) ) ) ); /*Q-1*/ #else *fxptr1++ = negate( extract_h( L_shl( *fx32ptr1--, 15 - q_sig32 ) ) ); #endif @@ -154,7 +154,7 @@ void preecho_sb_fx( FOR( i = 0; i < L_shr( framelength, 1 ); i++ ) { #ifdef BASOP_NOGLOB - *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], 15 - q_sig32 ) ) ); + *fxptr1++ = negate( extract_h( L_shl_sat( wtda_audio_fx[i], sub( 15, q_sig32 ) ) ) ); /*Q-1*/ #else *fxptr1++ = negate( extract_h( L_shl( wtda_audio_fx[i], 15 - q_sig32 ) ) ); #endif @@ -162,19 +162,19 @@ void preecho_sb_fx( } qmemp1 = 0; /*already in q-1*/ - subframelength = shr( framelength, LOG2_NUMSF ); - subsubframelength = shr( subframelength, log2_num_subsubframes ); - wmold_fx = *smoothmem_fx; + subframelength = shr( framelength, LOG2_NUMSF ); /*Q0*/ + subsubframelength = shr( subframelength, log2_num_subsubframes ); /*Q0*/ + wmold_fx = *smoothmem_fx; /*Q15*/ move16(); - subframelength_s2 = shr( subframelength, 1 ); - subframelength_s34 = mult( subframelength, 24576 ); + subframelength_s2 = shr( subframelength, 1 ); /*Q0*/ + subframelength_s34 = mult( subframelength, 24576 /*3/4 in Q15*/ ); /*Q0*/ cntnzcr = -1; move16(); - lim16_fx = 3277; + lim16_fx = 3277; /*Q15*/ move16(); - lim32_fx = 328; + lim32_fx = 328; /*Q15*/ move16(); savehalfe_fx = L_deposit_l( 0 ); savehalfe_hb_fx = L_deposit_l( 0 ); @@ -182,34 +182,34 @@ void preecho_sb_fx( IF( *pastpre == 0 ) { /* if past frame mean energies are not known (no preecho_sb in the past frame), limit max attenuation to 1*/ - lim16_fx = 32767; + lim16_fx = 32767; /*Q15*/ move16(); - lim32_fx = 32767; + lim32_fx = 32767; /*Q15*/ move16(); } *pastpre = 2; move16(); - fxptr1 = rec_sig_lb_fx; /*q_sig16*/ - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_fx + 1; - fxptr4 = rec_sig_fx + 2; + fxptr1 = rec_sig_lb_fx; /*q_sig16*/ + fxptr2 = rec_sig_fx; /*q_sig16*/ + fxptr3 = rec_sig_fx + 1; /*q_sig16*/ + fxptr4 = rec_sig_fx + 2; /*q_sig16*/ #ifdef BASOP_NOGLOB tmp_fxL1 = L_mult( shl_sat( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #else tmp_fxL1 = L_mult( shl( *memfilt_lb_fx, q_sig16 ), 8192 ); /* *memfilt_lb_fx in q0 */ #endif - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, 8192 /*Q15*/ ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*Q0*/ move16(); fxptr1++; FOR( j = 2; j < framelength; j++ ) { - tmp_fxL1 = L_mult( *fxptr2, 8192 ); - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mult( *fxptr2, 8192 /*Q15*/ ); /*Q16*/ + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, 8192 /*Q15*/ ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*Q0*/ move16(); fxptr1++; fxptr2++; @@ -217,8 +217,8 @@ void preecho_sb_fx( fxptr4++; } - tmp_fxL1 = L_mult( *fxptr2, 8192 ); - *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mult( *fxptr2, 8192 ); /*Q16*/ + *fxptr1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); /*Q0*/ move16(); fxptr1 = rec_sig_lb_fx; /*q_sig16*/ fxptr2 = rec_sig_fx; /*q_sig16*/ @@ -235,20 +235,20 @@ void preecho_sb_fx( fxptr2--; #ifdef BASOP_NOGLOB - *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); + *memfilt_lb_fx = shr_sat( *fxptr2, q_sig16 ); /*Q0*/ #else *memfilt_lb_fx = shr( *fxptr2, q_sig16 ); #endif move16(); /* *memfilt_lb_fx in q0 */ /* energy of low bands 8 present and 1 future sub-frames */ - sptr1 = zcr; + sptr1 = zcr; /*Q0*/ sptr1_loc = 0; move16(); - sptr2 = maxnzcr; + sptr2 = maxnzcr; /*Q0*/ - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_hb_fx; + fxptr2 = rec_sig_fx; /*q_sig16*/ + fxptr3 = rec_sig_hb_fx; /*q_sig16*/ fx32ptr1 = es_mdct_fx; fx32ptr5 = es_mdct_half_fx; fx32ptr6 = es_mdct_quart_fx; @@ -259,9 +259,9 @@ void preecho_sb_fx( { tmp_fx2 = sub( j, 1 ); #ifdef BASOP_NOGLOB - tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); - tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ + tmp_fxL2 = L_mac0_sat( 100, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/ #else tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); @@ -278,19 +278,19 @@ void preecho_sb_fx( { if ( EQ_16( i, subframelength_s2 ) ) { - *fx32ptr5 = tmp_fxL1; + *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/ move32(); } if ( EQ_16( i, subframelength_s34 ) ) { - *fx32ptr6 = tmp_fxL1; + *fx32ptr6 = tmp_fxL1; /*2*(Q-1)*/ move32(); } #ifdef BASOP_NOGLOB - tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); - tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); + tmp_fx1 = shr_sat( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ + tmp_fxL2 = L_mac0_sat( tmp_fxL2, *fxptr3, *fxptr3 ); /*2*(q_sig16)*/ #else tmp_fx1 = shr( *fxptr2, q16p1 ); /*q-1 to avoisd saturation in energy*/ tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); @@ -305,7 +305,7 @@ void preecho_sb_fx( test(); if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { - maxnzcr[tmp_fx2] = cntnzcr; + maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/ move16(); } @@ -322,12 +322,12 @@ void preecho_sb_fx( cntnzcr = add( cntnzcr, 1 ); } sptr2_loc = s_max( sptr2_loc, cntnzcr ); - *fx32ptr4 = tmp_fxL2; + *fx32ptr4 = tmp_fxL2; /*2*(q_sig16)*/ move32(); fx32ptr4++; - *sptr1 = sptr1_loc; + *sptr1 = sptr1_loc; /*Q0*/ move16(); - *sptr2 = sptr2_loc; + *sptr2 = sptr2_loc; /*Q0*/ move16(); sptr1++; sptr2++; @@ -335,7 +335,7 @@ void preecho_sb_fx( test(); if ( ( firstnzcr > 0 ) && ( GT_16( cntnzcr, maxnzcr[tmp_fx2] ) ) ) { - maxnzcr[tmp_fx2] = cntnzcr; + maxnzcr[tmp_fx2] = cntnzcr; /*Q0*/ move16(); } @@ -353,17 +353,17 @@ void preecho_sb_fx( move16(); } - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ move32(); if ( LT_32( *fx32ptr5, L_shr( *fx32ptr1, 1 ) ) ) { #ifdef BASOP_NOGLOB - tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); + tmp_fxL1 = L_shl_sat( L_sub_sat( *fx32ptr1, *fx32ptr5 ), 1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_shl( L_sub( *fx32ptr1, *fx32ptr5 ), 1 ); #endif } - *fx32ptr5 = tmp_fxL1; + *fx32ptr5 = tmp_fxL1; /*2*(Q-1)*/ move32(); fx32ptr1++; @@ -373,9 +373,9 @@ void preecho_sb_fx( fxptr2 = imdct_mem_fx; /* q_sig16 or q-1*/ j = NUMSF; - move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ - tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/ - tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); + move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ + tmp_fx1 = shr( *fxptr2, qmemp1 ); /* q-1 shr to avoid overflow in es_mdct_fx*/ + tmp_fxL1 = L_mac0( 25, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ sptr1_loc = 0; move16(); @@ -385,7 +385,7 @@ void preecho_sb_fx( { tmp_fx1 = shr( *fxptr2, qmemp1 ); /*q-1 to avoisd saturation in energy*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); #endif @@ -396,27 +396,27 @@ void preecho_sb_fx( fxptr2++; } - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ move32(); - *sptr1 = sptr1_loc; - fxptr2 = imdct_mem_fx; - fxptr3 = imdct_mem_fx + 1; - fxptr4 = imdct_mem_fx + 2; - tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 ); - tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); - tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 ); + *sptr1 = sptr1_loc; /*Q0*/ + fxptr2 = imdct_mem_fx; /*q_sig16*/ + fxptr3 = imdct_mem_fx + 1; /*q_sig16*/ + fxptr4 = imdct_mem_fx + 2; /*q_sig16*/ + tmp_fxL1 = L_mult( rec_sig_fx[framelength_m1], -8192 /*Q15*/ ); /*q_sig16+Q16*/ + tmp_fxL1 = L_mac( tmp_fxL1, *fxptr3, -8192 ); /*q_sig16+Q16*/ + tmp_fx1 = mac_r( tmp_fxL1, *fxptr2, 16384 /*Q15*/ ); /*q_sig16*/ tmp_fxL2 = L_deposit_l( 100 ); - tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ FOR( j = 1; j < tmp_fx3; j++ ) /* tmp_fx3 still contains subframelength*1.2-1 */ { - tmp_fxL1 = L_mult( *fxptr2, -8192 ); + tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); - tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); + tmp_fxL1 = L_mac_sat( tmp_fxL1, *fxptr4, -8192 ); /*q_sig16+Q16*/ + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/ - tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fxL2 = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ #else tmp_fxL1 = L_mac( tmp_fxL1, *fxptr4, -8192 ); tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); @@ -428,10 +428,10 @@ void preecho_sb_fx( fxptr4++; } - tmp_fxL1 = L_mult( *fxptr2, -8192 ); + tmp_fxL1 = L_mult( *fxptr2, -8192 /*Q15*/ ); /*q_sig16+Q16*/ #ifdef BASOP_NOGLOB - tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 ); - es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); + tmp_fx1 = mac_r_sat( tmp_fxL1, *fxptr3, 16384 /*Q15*/ ); /*q_sig16*/ + es_mdct_hb_fx[NUMSF] = L_mac0_sat( tmp_fxL2, tmp_fx1, tmp_fx1 ); /*2*(q_sig16)*/ #else tmp_fx1 = mac_r( tmp_fxL1, *fxptr3, 16384 ); es_mdct_hb_fx[NUMSF] = L_mac0( tmp_fxL2, tmp_fx1, tmp_fx1 ); @@ -481,11 +481,11 @@ void preecho_sb_fx( FOR( i = 0; i < maxind; i++ ) /* only subbands before max energy subband are handled */ { - g_fx = 32767; - move16(); /* default gain */ - min_g_fx[i] = 32767; + g_fx = 32767; /*Q15*/ + move16(); /* default gain */ + min_g_fx[i] = 32767; /*Q15*/ move16(); - min_g_hb_fx[i] = 32767; + min_g_hb_fx[i] = 32767; /*Q15*/ move16(); Mpy_32_16_ss( es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16 ); /* 328 for 1/100*/ @@ -515,13 +515,13 @@ void preecho_sb_fx( { IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 4 ) ) ) { - g_fx = lim16_fx; + g_fx = lim16_fx; /*Q15*/ move16(); cnt5 = add( cnt5, 1 ); IF( LT_32( es_mdct_fx[i], L_shr( max_es_fx, 5 ) ) ) { - g_fx = lim32_fx; + g_fx = lim32_fx; /*Q15*/ move16(); cnt2 = add( cnt2, 1 ); } @@ -550,14 +550,14 @@ void preecho_sb_fx( move16(); } test(); - IF( ( LT_16( zcr[i], limzcr / 2 ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) ) + IF( ( LT_16( zcr[i], shr( limzcr, 1 ) ) ) || ( GT_16( maxnzcr[i], limmaxnzcr ) ) ) { if ( LT_16( min_g_fx[i], 32767 ) ) /* *mean_prev < es_mdct[i]) */ { mean_prev_fx_loc = L_add( es_mdct_fx[i], 0 ); } - min_g_fx[i] = 32767; - move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ + min_g_fx[i] = 32767; /*Q15*/ + move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ } } ELSE @@ -572,21 +572,21 @@ void preecho_sb_fx( move16(); /* no preecho reduction after the first subframe with gain 1*/ } } - gt_fx[i] = g_fx; + gt_fx[i] = g_fx; /*Q15*/ move16(); - gt_hb_fx[i] = g_fx; + gt_hb_fx[i] = g_fx; /*Q15*/ move16(); } FOR( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ { - gt_fx[i] = 32767; + gt_fx[i] = 32767; /*Q15*/ move16(); - min_g_fx[i] = 32767; + min_g_fx[i] = 32767; /*Q15*/ move16(); - gt_hb_fx[i] = 32767; + gt_hb_fx[i] = 32767; /*Q15*/ move16(); - min_g_hb_fx[i] = 32767; + min_g_hb_fx[i] = 32767; /*Q15*/ move16(); } @@ -610,10 +610,10 @@ void preecho_sb_fx( ind2_m1 = sub( ind2, 1 ); ind2_sfl = i_mult( subframelength, ind2 ); numsf_ind2 = sub( NUMSF, ind2 ); - fxptr3 = gt_fx; - fxptr4 = gt_hb_fx; - fxptr5 = min_g_fx; - fxptr6 = min_g_hb_fx; + fxptr3 = gt_fx; /*Q15*/ + fxptr4 = gt_hb_fx; /*Q15*/ + fxptr5 = min_g_fx; /*Q15*/ + fxptr6 = min_g_hb_fx; /*Q15*/ fxptr1 = preechogain_fx + smooth_len; pre_g_ch_tab[0] = smooth_len; @@ -636,7 +636,7 @@ void preecho_sb_fx( fxptr1++; fxptr2++; } - pre_g_ch_tab[add( i, 1 )] = add( pre_g_ch_tab[i], subframelength ); + pre_g_ch_tab[( i + 1 )] = add( pre_g_ch_tab[i], subframelength ); fxptr3++; fxptr4++; fxptr5++; @@ -645,22 +645,23 @@ void preecho_sb_fx( max_plus_es_mdct_fx = L_deposit_l( 0 ); adv = smooth_len; - move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ - advmem = adv; + move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ + advmem = adv; /*Q0*/ move16(); test(); test(); IF( ind2 > 0 || LT_16( wmold_fx, 32767 ) || LT_16( *wmold_hb_fx, 32767 ) ) { - ptr_fx = imdct_mem_fx; + ptr_fx = imdct_mem_fx; /*q_sig16*/ qtmp = qmemp1; pluslim = num_subsubframes; move16(); /* if ind2 == NUMSF */ IF( numsf_ind2 > 0 ) { - ptr_fx = rec_sig_fx + ind2_sfl; + ptr_fx = rec_sig_fx + ind2_sfl; /*q_sig16*/ qtmp = q16p1; + move16(); pluslim = i_mult( numsf_ind2, num_subsubframes ); } @@ -670,21 +671,21 @@ void preecho_sb_fx( sum_plus_es_fx = L_add( mean_prev_nc_fx_loc, 0 ); /* 8 times mean sususb enenrgy (=maxcrit)*/ pluslim = num_subsubframes; move16(); - oldgain_fx = wmold_fx; + oldgain_fx = wmold_fx; /*Q15*/ move16(); - oldgain_hb_fx = *wmold_hb_fx; + oldgain_hb_fx = *wmold_hb_fx; /*Q15*/ move16(); } ELSE /* ind2 > 0*/ { sum_plus_es_fx = es_mdct_fx[ind2_m1]; - move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/ - oldgain_fx = gt_fx[ind2_m1]; + move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/ + oldgain_fx = gt_fx[ind2_m1]; /*Q15*/ move16(); - oldgain_hb_fx = gt_hb_fx[ind2_m1]; + oldgain_hb_fx = gt_hb_fx[ind2_m1]; /*Q15*/ move16(); - tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); + tmp_fx1 = mult_r( gt_fx[ind2_m1], gt_fx[ind2_m1] ); /*Q15*/ Mpy_32_16_ss( es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16 ); Mpy_32_16_ss( max_es_fx, 410, &tmp_fxL1, &tmp_u16 ); /* 410 for 1/80*/ @@ -705,7 +706,7 @@ void preecho_sb_fx( tmp_fx1 = shr( *ptr_fx, qtmp ); /* q-1, to have same shift as es_mdct_.. */ #ifdef BASOP_NOGLOB - tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); + tmp_fxL1 = L_mac0_sat( tmp_fxL1, tmp_fx1, tmp_fx1 ); /*2*(Q-1)*/ #else tmp_fxL1 = L_mac0( tmp_fxL1, tmp_fx1, tmp_fx1 ); #endif @@ -717,11 +718,11 @@ void preecho_sb_fx( } #ifdef BASOP_NOGLOB - sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); + sum_plus_es_fx = L_add_sat( sum_plus_es_fx, L_shl_sat( tmp_fxL1, 2 ) ); /*2*(Q-1)*/ #else sum_plus_es_fx = L_add( sum_plus_es_fx, L_shl( tmp_fxL1, 2 ) ); #endif - *fx32ptr1 = tmp_fxL1; + *fx32ptr1 = tmp_fxL1; /*2*(Q-1)*/ fx32ptr1++; Mpy_32_16_ss( sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16 ); /* 410 for 1/80*/ if ( LT_32( *fx32ptr4, maxcrit_fx ) ) @@ -732,18 +733,18 @@ void preecho_sb_fx( fx32ptr4++; } *fx32ptr4 = -1; - move32(); /*mean_plus_es_fx[pluslim] = -1; */ - *mean_plus_es_fx = *plus_es_mdct_fx; - move32(); /* index [0] */ + move32(); /*mean_plus_es_fx[pluslim] = -1; */ + *mean_plus_es_fx = *plus_es_mdct_fx; /*2*(Q-1)*/ + move32(); /* index [0] */ if ( LT_32( *mean_plus_es_fx, maxcrit_fx ) ) { - *mean_plus_es_fx = maxcrit_fx; + *mean_plus_es_fx = maxcrit_fx; /*2*(Q-1)*/ move32(); } j = 0; move16(); - WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], max_plus_es_mdct_fx / 8 ) ) ) + WHILE( ( LT_32( plus_es_mdct_fx[j], mean_plus_es_fx[j] ) ) && ( LT_32( plus_es_mdct_fx[j], L_shr( max_plus_es_mdct_fx, 3 ) ) ) ) { test(); j = add( j, 1 ); @@ -757,10 +758,10 @@ void preecho_sb_fx( FOR( i = 0; i < tmp_fx3; i++ ) { - *fxptr1 = oldgain_fx; - move16(); /*keep the gain of the previous subframe*/ - *fxptr2 = oldgain_hb_fx; - move16(); /*keep the gain of the previous subframe*/ + *fxptr1 = oldgain_fx; /*Q15*/ + move16(); /*keep the gain of the previous subframe*/ + *fxptr2 = oldgain_hb_fx; /*Q15*/ + move16(); /*keep the gain of the previous subframe*/ fxptr1++; fxptr2++; } @@ -777,16 +778,16 @@ void preecho_sb_fx( IF( ind4 > 0 ) { /* case of 3 points is simply */ - eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); + eshbmean2_fx = L_add( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/ sxyhb2_fx = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5] ); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ IF( GT_16( ind3, 2 ) ) { - tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); - Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ - sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ - tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/ + Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ + sxylb3_fx = L_sub( es_mdct_fx[ind4], es_mdct_fx[ind6] ); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6] ); /*2*(q_sig16)*/ test(); IF( ( LT_32( tmp_fxL1, eshbmean3_fx ) ) || ( sxylb3_fx < 0 ) ) { @@ -811,10 +812,10 @@ void preecho_sb_fx( } } - tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); + tmp_fxL1 = L_add( eshbmean2_fx, es_mdct_hb_fx[ind3] ); /*2*(q_sig16)*/ Mpy_32_16_ss( tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16 ); /*10922 : 1/3*/ - tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); + tmp_fxL1 = L_sub( es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5] ); /*2*(q_sig16)*/ IF( LT_32( tmp_fxL1, eshbmean3_fx ) ) { ind2 = 0; @@ -844,82 +845,82 @@ void preecho_sb_fx( } tmp_fx1 = add( stind, smooth_len ); - fxptr1 = preechogain_fx + tmp_fx1; - fxptr2 = preechogain_hb_fx + stind_hb; + fxptr1 = preechogain_fx + tmp_fx1; /*Q15*/ + fxptr2 = preechogain_hb_fx + stind_hb; /*Q15*/ FOR( i = tmp_fx1; i < framelength; i++ ) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ { - *( fxptr1++ ) = 32767; + *( fxptr1++ ) = 32767; /*Q15*/ move16(); } - pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); + pre_g_ch_tab[ind2] = s_min( tmp_fx1, framelength ); /*Q0*/ move16(); FOR( i = stind_hb; i < framelength; i++ ) /* rest of the gains*/ { - *( fxptr2++ ) = 32767; + *( fxptr2++ ) = 32767; /*Q15*/ move16(); } - fxptr1 = preechogain_fx; + fxptr1 = preechogain_fx; /*Q15*/ FOR( i = 0; i < smooth_len; i++ ) { - *( fxptr1++ ) = *smoothmem_fx; + *( fxptr1++ ) = *smoothmem_fx; /*Q15*/ move16(); } - fattnext_fx = 32767; + fattnext_fx = 32767; /*Q15*/ move16(); if ( GT_16( stind, framelength ) ) { - fattnext_fx = gt_fx[ind2_m1]; + fattnext_fx = gt_fx[ind2_m1]; /*Q15*/ move16(); } - fxptr1 = preechogain_fx + framelength; + fxptr1 = preechogain_fx + framelength; /*Q15*/ FOR( i = 0; i < smooth_len; i++ ) { - *( fxptr1++ ) = fattnext_fx; + *( fxptr1++ ) = fattnext_fx; /*Q15*/ move16(); } FOR( i = 0; i <= ind2; i++ ) { - tmp_fx1 = pre_g_ch_tab[i]; + tmp_fx1 = pre_g_ch_tab[i]; /*Q0*/ move16(); tmp_fx2 = sub( tmp_fx1, smooth_len ); /* any index in the previous subframe*/ - tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step*/ - tmp_fx1 = tmp_fx3; - move16(); /*cumulated step*/ - fxptr1 = preechogain_fx + tmp_fx2; + tmp_fx3 = mult_r( sub( preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2] ), invsmoothlenp1_fx ); /*step Q15*/ + tmp_fx1 = tmp_fx3; /*Q15*/ + move16(); /*cumulated step*/ + fxptr1 = preechogain_fx + tmp_fx2; /*Q15*/ FOR( j = 0; j < smooth_len; j++ ) { #ifdef BASOP_NOGLOB - *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); + *fxptr1 = add_sat( *fxptr1, tmp_fx1 ); /*Q15*/ #else *fxptr1 = add( *fxptr1, tmp_fx1 ); #endif move16(); - tmp_fx1 = add( tmp_fx1, tmp_fx3 ); + tmp_fx1 = add( tmp_fx1, tmp_fx3 ); /*Q15*/ fxptr1++; } } - *smoothmem_fx = fattnext_fx; + *smoothmem_fx = fattnext_fx; /*Q15*/ move16(); - *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; + *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; /*Q15*/ move16(); /* apply gain */ - fxptr1 = preechogain_fx; - fxptr2 = preechogain_hb_fx; - fxptr3 = rec_sig_fx; - fxptr4 = rec_sig_lb_fx; - fxptr5 = rec_sig_hb_fx; + fxptr1 = preechogain_fx; /*Q15*/ + fxptr2 = preechogain_hb_fx; /*Q15*/ + fxptr3 = rec_sig_fx; /*q_sig16*/ + fxptr4 = rec_sig_lb_fx; /*q_sig16*/ + fxptr5 = rec_sig_hb_fx; /*q_sig16*/ FOR( i = 0; i < framelength; i++ ) { - tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); - *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); + tmp_fxL1 = L_mult( *fxptr4, *fxptr1 ); /*q_sig16 + Q16*/ + *fxptr3 = mac_r( tmp_fxL1, *fxptr5, *fxptr2 ); /*q_sig16*/ move16(); fxptr1++; fxptr2++; @@ -928,16 +929,16 @@ void preecho_sb_fx( fxptr5++; } - mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains*/ + mean_prev_nc_fx_loc = L_add( es_mdct_fx[0], 0 ); /* compute mean not corrected by the actual gains 2*(Q-1)*/ FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { if ( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); + savehalfe_fx = L_add( mean_prev_nc_fx_loc, 0 ); /*2*(Q-1)*/ } #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); + mean_prev_nc_fx_loc = L_add_sat( mean_prev_nc_fx_loc, es_mdct_fx[i] ); /*2*(Q-1)*/ #else mean_prev_nc_fx_loc = L_add( mean_prev_nc_fx_loc, es_mdct_fx[i] ); #endif @@ -946,52 +947,52 @@ void preecho_sb_fx( if ( LT_32( savehalfe_fx, L_shr( mean_prev_nc_fx_loc, 1 ) ) ) { #ifdef BASOP_NOGLOB - mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); + mean_prev_nc_fx_loc = L_shl_sat( L_sub_sat( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); /*2*(Q-1)*/ #else mean_prev_nc_fx_loc = L_shl( L_sub( mean_prev_nc_fx_loc, savehalfe_fx ), 1 ); #endif } - mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint */ + mean_prev_nc_fx_loc = L_shr( mean_prev_nc_fx_loc, 3 ); /* >> LOG2_NUMSF in fixpoint 2*(Q-1)*/ FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ { - tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); + tmp_fx1 = mult_r( gt_fx[i], gt_fx[i] ); /*Q15*/ Mpy_32_16_ss( es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16 ); - tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); + tmp_fx1 = mult_r( gt_hb_fx[i], gt_hb_fx[i] ); /*Q15*/ Mpy_32_16_ss( es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16 ); } - mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ - mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain*/ + mean_prev_fx_loc = L_shr( es_mdct_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(Q-1)*/ + mean_prev_hb_fx_loc = L_shr( es_mdct_hb_fx[0], 3 ); /* compute mean used in next frame to limit gain 2*(q_sig16)*/ FOR( i = 1; i < NUMSF; i++ ) /* all present subbands */ { IF( EQ_16( i, NUMSF_S2 ) ) { - savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); - savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); + savehalfe_fx = L_add( mean_prev_fx_loc, 0 ); /*2*(Q-1)*/ + savehalfe_hb_fx = L_add( mean_prev_hb_fx_loc, 0 ); /*2*(q_sig16)*/ } - mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); - mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); + mean_prev_fx_loc = L_add( mean_prev_fx_loc, L_shr( es_mdct_fx[i], 3 ) ); /*2*(Q-1)*/ + mean_prev_hb_fx_loc = L_add( mean_prev_hb_fx_loc, L_shr( es_mdct_hb_fx[i], 3 ) ); /*2*(q_sig16)*/ } - tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); + tmp_fxL1 = L_sub( mean_prev_fx_loc, savehalfe_fx ); /*2*(Q-1)*/ if ( LT_32( savehalfe_fx, L_shr( mean_prev_fx_loc, 1 ) ) ) { - mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); + mean_prev_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(Q-1)*/ } - tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); + tmp_fxL1 = L_sub( mean_prev_hb_fx_loc, savehalfe_hb_fx ); /*2*(q_sig16)*/ if ( LT_32( savehalfe_hb_fx, L_shr( mean_prev_hb_fx_loc, 1 ) ) ) { - mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); + mean_prev_hb_fx_loc = L_shl( tmp_fxL1, 1 ); /*2*(q_sig16)*/ } #ifdef BASOP_NOGLOB - last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); - last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); + last2_fx = L_shr( L_add_sat( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); /*q_sig16*/ + last2_hb_fx = L_shr( L_add_sat( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); /*q_sig16*/ #else last2_fx = L_shr( L_add( es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2] ), 1 ); last2_hb_fx = L_shr( L_add( es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2] ), 1 ); @@ -1003,17 +1004,17 @@ void preecho_sb_fx( if ( GT_32( last2_hb_fx, mean_prev_hb_fx_loc ) ) { - mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); + mean_prev_hb_fx_loc = L_add( last2_hb_fx, 0 ); /*2*(q_sig16)*/ } - *mean_prev_fx = mean_prev_fx_loc; + *mean_prev_fx = mean_prev_fx_loc; /*2*(Q-1)*/ move32(); #ifdef BASOP_NOGLOB - *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); + *mean_prev_hb_fx = L_shr_sat( mean_prev_hb_fx_loc, shl_sat( q_sig16, 1 ) ); /*Q0*/ #else *mean_prev_hb_fx = L_shr( mean_prev_hb_fx_loc, shl( q_sig16, 1 ) ); #endif - move32(); /*save in Q0*/ - *mean_prev_nc_fx = mean_prev_nc_fx_loc; + move32(); /*save in Q0*/ + *mean_prev_nc_fx = mean_prev_nc_fx_loc; /*2*(Q-1)*/ move32(); } @@ -1027,13 +1028,13 @@ void preecho_sb_fx( *--------------------------------------------------------------------------*/ void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ + const Word32 *in_mdct, /* i : input MDCT vector Q */ Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner, /* i : length of the transform */ - const Word16 element_mode /* i : IVAS element mode */ + Word32 *out, /* o : output vector Q */ + const Word16 is_transient, /* i : transient flag Q0 */ + const Word16 L, /* i : output frame length Q0 */ + const Word16 L_inner, /* i : length of the transform Q0 */ + const Word16 element_mode /* i : IVAS element mode Q0 */ ) { Word16 ta, seg, tmp16; @@ -1064,30 +1065,30 @@ void Inverse_Transform( IF( EQ_16( L, L_FRAME48k ) ) { - win = short_window_48kHz_fx; + win = short_window_48kHz_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME32k ) ) { - win = short_window_32kHz_fx; + win = short_window_32kHz_fx; /*Q15*/ } ELSE IF( EQ_16( L, L_FRAME16k ) ) { - win = short_window_16kHz_fx; + win = short_window_16kHz_fx; /*Q15*/ } ELSE /* L == L_FRAME8k */ { - win = short_window_8kHz_fx; + win = short_window_8kHz_fx; /*Q15*/ } set32_fx( out_alias, 0, L ); - in_segment = in_mdct; + in_segment = in_mdct; /*Q*/ in_segment_modif = in_mdct_modif; tmp16 = sub( L, L_inner ); IF( tmp16 == 0 ) { - Copy32( in_mdct, in_mdct_modif, L ); + Copy32( in_mdct, in_mdct_modif, L ); /*Q*/ } ELSE IF( tmp16 > 0 ) { @@ -1095,7 +1096,7 @@ void Inverse_Transform( { FOR( ta = 0; ta < L_inner; ta += NUM_TIME_SWITCHING_BLOCKS ) { - *in_segment_modif++ = *in_segment++; + *in_segment_modif++ = *in_segment++; /*Q*/ move32(); } @@ -1112,16 +1113,16 @@ void Inverse_Transform( { FOR( ta = 0; ta < segment_length_div2; ta++ ) { - *in_segment_modif++ = *in_segment++; + *in_segment_modif++ = *in_segment++; /*Q*/ move32(); } - in_segment += shr( sub( L_inner, L ), 2 ); + in_segment += shr( sub( L_inner, L ), 2 ); /*Q*/ move32(); } } out_segment = out_alias - segment_length_div4; - in_segment = in_mdct_modif; + in_segment = in_mdct_modif; /*Q*/ tmp = *Q; /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ @@ -1139,21 +1140,21 @@ void Inverse_Transform( FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_shr( alias[ta], tmp ); + out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [0..seg_len_div4-1] */ - win2 = &win[segment_length_div2]; + win2 = &win[segment_length_div2]; /*Q15*/ FOR( ta = segment_length_div2; ta < segment_length; ta++ ) { - out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); + out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */ - out_segment += segment_length_div2; - in_segment += segment_length_div2; + out_segment += segment_length_div2; /*q_out*/ + in_segment += segment_length_div2; /*Q*/ FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { @@ -1165,17 +1166,17 @@ void Inverse_Transform( FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/ move32(); } FOR( ; ta < segment_length; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ) ); /*q_out*/ move32(); } - in_segment += segment_length_div2; - out_segment += segment_length_div2; + in_segment += segment_length_div2; /*Q*/ + out_segment += segment_length_div2; /*q_out*/ } tmp = *Q; @@ -1185,23 +1186,23 @@ void Inverse_Transform( FOR( ta = 0; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); + out_segment[ta] = L_add( out_segment[ta], L_shr( Mult_32_16( alias[ta], *win2++ ), tmp ) ); /*q_out*/ move32(); } - seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 */ + seg = add( segment_length_div2, shr( segment_length_div2, 1 ) ); /* seg = 3*segment_length/4 Q0*/ FOR( ta = segment_length_div2; ta < seg; ta++ ) { - out_segment[ta] = L_shr( alias[ta], tmp ); + out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/ move32(); } FOR( ta = 0; ta < segment_length; ta++ ) { L_temp = L_add( out_alias[ta], 0 ); - out[ta] = out_alias[L - 1 - ta]; + out[ta] = out_alias[L - 1 - ta]; /*q_out*/ move32(); - out[L - 1 - ta] = L_temp; + out[L - 1 - ta] = L_temp; /*q_out*/ move32(); } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index e5d162502f3e31eec3397f206b700dba1e7fe169..45e429430572bcc3d4ccb42bc492a7d3ce9caa1d 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -543,37 +543,43 @@ ivas_error acelp_core_enc( } else { - if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { FdCng_encodeSID_ivas_fx( st ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - me2f_buf( st->hFdCngEnc->hFdCngCom->sidNoiseEst, st->hFdCngEnc->hFdCngCom->sidNoiseEstExp, st->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, st->hFdCngEnc->npartDec ); - me2f_buf( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->A_cng, st->hFdCngEnc->hFdCngCom->A_cng_flt, 14 - norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ), M + 1 ); -#endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; + move16(); } + Word16 Q_cngNoise = Q31, zero_flag = 0; + move16(); + move16(); + FOR( Word16 j = 0; j < NPART; j++ ) + { + IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[j] != 0 ) + { + zero_flag = 1; + move16(); + BREAK; + } + } + IF( zero_flag ) + { + Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART ); + } + Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise ); + st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise ); + move16(); + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_cngNoise = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, st->hFdCngEnc->hFdCngCom->cngNoiseLevel, Q_cngNoise, FFTCLDFBLEN ); - st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( 31, Q_cngNoise ); st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 ); #endif - // generate_comfort_noise_enc( st ); generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->exc_cng, st->hFdCngEnc->hFdCngCom->exc_cng_flt, Q_new, st->L_frame ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->olapBufferSynth, st->hFdCngEnc->hFdCngCom->olapBufferSynth_flt, st->hFdCngEnc->hFdCngCom->fftlenShift, FFTLEN ); - fixedToFloat_arr( st->hFdCngEnc->hFdCngCom->timeDomainBuffer, st->hFdCngEnc->hFdCngCom->timeDomainBuffer_flt, Q_new, st->hFdCngEnc->hFdCngCom->frameSize ); fixedToFloat_arr( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq_flt, Q_new, ( L_FRAME32k / 2 + 64 ) ); #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->A_cng_flt, st->hFdCngEnc->hFdCngCom->A_cng, Q12, ( M + 1 ) ); - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame ); -#endif + Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( Aq_fx, Aq, Q12, ( st->L_frame / L_SUBFR ) * ( M + 1 ) ); @@ -716,17 +722,10 @@ ivas_error acelp_core_enc( st->mem_deemp_preQ_fx = (Word16) floatToFixed( st->mem_deemp_preQ, -1 ); IF( st->hLPDmem ) { - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); floatToFixed_arr( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], Q_new - 1, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 } floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - st->clip_var_fx[0] = (Word16) ( st->clip_var[0] * 2.56f ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], Q14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); FOR( Word16 idx = 0; idx < M; idx++ ) { IF( tdm_lsfQ_PCh ) @@ -750,9 +749,6 @@ ivas_error acelp_core_enc( st->hGSCEnc->Last_frame_ener_fx = floatToFixed_32( st->hGSCEnc->Last_frame_ener, Q4 ); f2me_buf_16( st->hGSCEnc->last_exc_dct_in, st->hGSCEnc->last_exc_dct_in_fx, &st->hGSCEnc->Q_last_exc_dct_in, L_FRAME16k ); st->hGSCEnc->Q_last_exc_dct_in = Q15 - st->hGSCEnc->Q_last_exc_dct_in; - st->hGSCEnc->last_ener_fx = (Word16) st->hGSCEnc->last_ener; - IF( st->hLPDmem ) - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); #endif /*-----------------------------------------------------------------* * Configure ACELP bit allocation @@ -1001,13 +997,6 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->mem_deemp_preQ = fixedToFloat( st->mem_deemp_preQ_fx, -1 ); - st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - fixedToFloat_arr( lsp_new_bck_fx, lsp_new_bck, Q15, M ); fixedToFloat_arr( lsp_mid_bck_fx, lsp_mid_bck, Q15, M ); fixedToFloat_arr( mem_syn_bck_fx, mem_syn_bck, Q_new, M ); @@ -1044,7 +1033,6 @@ ivas_error acelp_core_enc( fixedToFloat_arr( syn_fx, syn, Q_new - 1, L_FRAME16k ); fixedToFloat_arr( voice_factors_fx, voice_factors, Q15, NB_SUBFR16k ); fixedToFloat_arr( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); - st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); #endif /* update mem_syn1_flt for ACELP core switching */ @@ -1279,11 +1267,6 @@ ivas_error acelp_core_enc( floatToFixed_arr16( &old_bwe_exc[L_FRAME32k], &old_bwe_exc_fx[L_FRAME32k], q_old_bwe_exc, PIT16k_MAX * 2 ); st->Q_exc = q_old_bwe_exc; } - - IF( st->hGSCEnc != NULL ) - { - st->hGSCEnc->mid_dyn_fx = float_to_fix16( st->hGSCEnc->mid_dyn, Q7 ); - } #endif // IVAS_FLOAT_FIXED_CONVERSIONS updt_enc_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); @@ -1294,7 +1277,6 @@ ivas_error acelp_core_enc( { fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, q_old_bwe_exc, PIT16k_MAX * 2 ); } - st->hGSCEnc->mid_dyn = fixedToFloat( st->hGSCEnc->mid_dyn_fx, Q7 ); fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Q12 #endif #else diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index f7f1d45b681dcf87fe46e3fd1fd87c214e60220d..8fb74129723e6127d02c26efde383be94b41d343 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -224,6 +224,7 @@ void E_ACELP_conv_ivas( #else cn2[k] = round_fx( L_shl( L_tmp, 5 ) ); #endif + move16(); } } void E_ACELP_build_code( diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index c303d9ea5dee43cc0b22f622694ce04e6270df7b..094d3fd78340282c0991914c8ee18a9216c1a0b1 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -949,16 +949,9 @@ void AVQ_encmux_ivas_fx( } /*Compute AVQ code book number from unused Bits */ - // bit_tmp = add( unusedbitsFlag, unused_bits_idx ); + bit_tmp = add( unusedbitsFlag, unused_bits_idx ); /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ - // nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); - bit_tmp = sub( bits, imult1616( 5, add( unusedbitsFlag, unused_bits_idx ) ) ); - nq_est = 0; - WHILE( bit_tmp > 0 ) - { - nq_est = add( nq_est, 1 ); - bit_tmp = sub( bit_tmp, 5 ); - } + nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); assert( (int16_t) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); if ( EQ_16( nq_est, 1 ) ) diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index 04105f232b3c3e7aaddc0fc91fe535f3844e47f9..d933989970e0a6297977d86702570cf5eb5a6442 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -363,6 +363,7 @@ void acelp_2t32_ivas_fx( Word16 rrixiy[MSIZE]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* * Compute rrixix[][] needed for the codebook search. @@ -749,12 +750,12 @@ void acelp_1t64_ivas_fx( IF( dn[pos] < 0 ) { - sgn = -512; + sgn = -512; //-1 in Q9 move16(); } ELSE { - sgn = 512; + sgn = 512; // 1 in Q9 move16(); } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index b4837eecca4323d7d19a6b8b1832f833f1a7fc5b..ef2e5408b18e99e06ecb4d61c33b717a457580a3 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -1258,7 +1258,11 @@ static void init_acelp( st->rate_switching_reset = 1; if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; +#else + hLPDmem->tilt_code = TILT_CODE; +#endif set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); set_zero( hLPDmem->syn_flt, 1 + M ); hLPDmem->mem_w0_flt = 0.0f; @@ -1387,7 +1391,11 @@ static void init_acelp( /*reset partly some memories*/ if ( hLPDmem != NULL ) { +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = TILT_CODE_FLT; +#else + hLPDmem->tilt_code = TILT_CODE; +#endif set_zero( hLPDmem->old_exc_flt, L_EXC_MEM ); /*Resamp others memories*/ @@ -1449,10 +1457,20 @@ static void init_acelp( /* Post-processing */ if ( hLPDmem != NULL ) { - set_zero( hLPDmem->dispMem_flt, 8 ); #ifndef IVAS_FLOAT_FIXED + set_zero( hLPDmem->dispMem_flt, 8 ); hLPDmem->gc_threshold_flt = 0.0f; #else + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } hLPDmem->gc_threshold = 0; #endif } @@ -1739,7 +1757,16 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh if ( hLPDmem != NULL ) { - set32_fx( hLPDmem->dispMem, 0, 8 ); + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } hLPDmem->gc_threshold = 0; move16(); } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 0a90b3648dde68a535bbd6465c7a7ce0062f7a86..9e6ffbcf43eafa70b1ba7ab8b0919f79e233f17d 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -129,9 +129,6 @@ void core_coder_mode_switch_ivas_fx( /* switch IGF configuration */ IF( st->igf ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); -#endif IGFEncSetMode_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth ); diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 1422481121d012bf6b4f3e08894b52478d30d043..5bbd809683eb4404ec73cafa450e03deb736fca6 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -229,24 +229,36 @@ void core_switching_pre_enc( set_f( hLPDmem->mem_syn_flt, 0.0f, M ); set_f( hLPDmem->mem_syn1_flt, 0.0f, M ); hLPDmem->mem_w0_flt = 0.0f; - hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + hLPDmem->tilt_code = 0; hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->Nb_ACELP_frames = 0; #ifndef IVAS_FLOAT_FIXED set_zero( st->mem_MA, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); + init_gp_clip( st->clip_var ); #else set16_fx( st->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + init_gp_clip_fx( st->clip_var_fx ); #endif - init_gp_clip( st->clip_var ); st->last_coder_type = GENERIC; @@ -290,14 +302,29 @@ void core_switching_pre_enc( if ( hLPDmem != NULL ) { hLPDmem->mem_w0_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->tilt_code_flt = 0.0f; - init_gp_clip( st->clip_var ); +#else + hLPDmem->tilt_code = 0; +#endif #ifndef IVAS_FLOAT_FIXED + init_gp_clip( st->clip_var ); hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + init_gp_clip_fx( st->clip_var_fx ); hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->last_coder_type = GENERIC; @@ -867,15 +894,7 @@ void core_switching_post_enc( floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_new, L_INP_12k8 ); floatToFixed_arr( old_inp_16k, old_inp_16k_fx, Q_new, L_INP ); floatToFixed_arr( A, A_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - float temp = (float) st->clip_var[0] * ( 2.56f ); - st->clip_var_fx[0] = float_to_fix16( temp, 0 ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], 14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], 8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], 14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], 14 ); floatToFixed_arr( st->voicing, st->voicing_fx, 15, 3 ); - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, 15 ); floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, 12, M + 1 ); st->hLPDmem->mem_w0 = float_to_fix16( st->hLPDmem->mem_w0_flt, Q_new - 1 ); floatToFixed_arr( st->hLPDmem->mem_syn_flt, st->hLPDmem->mem_syn, Q_new - 1, M ); @@ -885,14 +904,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from fix to float fixedToFloat_arr( st->old_input_signal_fx, st->old_input_signal, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - temp = (float) fix16_to_float( st->clip_var_fx[0], 0 ) / 2.56f; - st->clip_var[0] = temp; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], 14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], 8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], 14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], 14 ); - st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, 15 ); st->hLPDmem->mem_w0_flt = fix16_to_float( st->hLPDmem->mem_w0, Q_new - 1 ); #endif #endif diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 92b3c7ebad9b20dbd5596582691419088ef22780..5c209460ded87e1e2852ec217ab31a69caf130cc 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -33,6 +33,7 @@ void corr_xh_fx( Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -81,34 +82,6 @@ void corr_xh_fx( return; } -void corr_xh_ivas_fx( - const Word16 *x, /* i : target signal Q_new - 1 */ - Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ - const Word16 *h, /* i : impulse response (of weighted synthesis filter) e(norm_s(h1[0])+1) */ - const Word16 L_subfr /* i : length of the subframe */ -) -{ - Word16 i, j, scale; - Word64 s64; - - Word16 shift = add( norm_s( h[0] ), 1 ); - scale = sub( sub( 15, shift ), 2 ); - FOR( i = 0; i < L_subfr; i++ ) - { - s64 = 0; - move16(); - FOR( j = i; j < L_subfr; j++ ) - { - s64 = W_mac0_16_16( s64, x[j], h[j - i] ); // Q_new - 1 + 15 - shift - } - - y[i] = extract_l( W_extract_l( W_shr( s64, scale ) ) ); // Q_new + 1 - move16(); - } - - return; -} - void corr_hh_ivas_fx( const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ @@ -120,6 +93,7 @@ void corr_hh_ivas_fx( Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -164,13 +138,15 @@ void corr_hh_ivas_fx( FOR( i = 0; i < L_subfr; i++ ) { y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16 + move16(); } *Qy = sub( add( shl( sub( 15, norm_s( h[0] ) ), 1 ), j ), 17 ); + move16(); return; } -void corr_xh_ivas_fx2( +void corr_xh_ivas_fx( const Word16 x[], /* i : target signal */ const Word16 Qx, Word16 dn[], /* o : correlation between x[] and h[] */ @@ -183,6 +159,7 @@ void corr_xh_ivas_fx2( Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -227,8 +204,10 @@ void corr_xh_ivas_fx2( FOR( i = 0; i < L_subfr; i++ ) { dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(15 - norm_s(h[0])) +j - 16 + move16(); } *Qdn = sub( add( add( Qx, sub( 15, norm_s( h[0] ) ) ), j ), 16 ); + move16(); return; } diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 43df35a55f4427071b76c8403dc9d413398a80ac..ae445a35b738bd738d32f69c07a85de777b40b58 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -647,15 +647,18 @@ void E_ACELP_4tsearchx_ivas_fx( Word16 nb_pulse, nb_pulse_m2; Word16 psk; Word16 val, index, track; + move16(); + move16(); psk = ps = 0; /* to avoid compilation warnings */ + move16(); + move16(); alp = config->alp; /* Q13 */ move16(); nb_pulse = config->nb_pulse; move16(); - move16(); nb_pulse_m2 = sub( nb_pulse, 2 ); /* Init to avoid crash when the search does not find a solution */ @@ -872,11 +875,14 @@ void E_ACELP_4tsearchx_ivas_fx( IF( L_mult0( val, psk ) > 0 ) { code[i] = add( code[i], ONE_IN_Q9 /*1.0f*/ ); + move16(); codvec[k] = add( codvec[k], 2 * L_SUBFR ); + move16(); } ELSE { code[i] = sub( code[i], ONE_IN_Q9 /*1.0f*/ ); + move16(); index = add( index, 16 ); } diff --git a/lib_enc/enc_gen_voic.c b/lib_enc/enc_gen_voic.c index 99c500a73c5a0b907fb85e1978eac974fc65827d..7339c7e7ce3b6fb71a3bfcffeafaf47564267c83 100644 --- a/lib_enc/enc_gen_voic.c +++ b/lib_enc/enc_gen_voic.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_gen_voic() * @@ -322,3 +323,4 @@ void encod_gen_voic( return; } +#endif diff --git a/lib_enc/enc_pit_exc.c b/lib_enc/enc_pit_exc.c index e419e092f7dfb7d12ef2a6ae5a7a4fbea069bbaf..791f5c59c7d53fbd180dc4cff9de9cb87dc11828 100644 --- a/lib_enc/enc_pit_exc.c +++ b/lib_enc/enc_pit_exc.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * enc_pit_exc() * @@ -412,3 +413,4 @@ void enc_pit_exc( return; } +#endif diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 03b02fe96737e5f5701c8600564d519de4240fcf..f9f50bb6524560fe4ee3697abf3ca84b609d8b36 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -910,11 +910,11 @@ void enc_pit_exc_ivas_fx( } ELSE { - Ltmp = L_mult( xn[L_subfr - 1], 16384 ); + Ltmp = L_mult( xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift #ifdef BASOP_NOGLOB - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ #else Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit ); Ltmp = L_shl( Ltmp, sub( 1, shift ) ); diff --git a/lib_enc/enc_tran.c b/lib_enc/enc_tran.c index 08e9d5c7f30d0d862a448f3651fb8a79d1a7dee4..206227c2f5fb88a7648e5c1c42d148f1446ce7c6 100644 --- a/lib_enc/enc_tran.c +++ b/lib_enc/enc_tran.c @@ -40,6 +40,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_tran() * @@ -340,3 +341,4 @@ int16_t encod_tran( return tc_subfr; } +#endif diff --git a/lib_enc/enc_uv.c b/lib_enc/enc_uv.c index c45c84f1d0c4ab143b8ffedfc68eff62e8b9dff6..8e080956d1007dd0296befec6cf8a234360f6253 100644 --- a/lib_enc/enc_uv.c +++ b/lib_enc/enc_uv.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_unvoiced() * @@ -238,3 +239,4 @@ void encod_unvoiced( return; } +#endif diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index f87220008b072e6485429c49e80d5b2bfb78db0e..7708c0e1c07dc86b9d00371f1618ef3eda9d1f3b 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -331,7 +331,6 @@ void encod_unvoiced_ivas_fx( p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; pt_pitch_fx = pitch_buf_fx; - move16(); Q_xn = add( sub( Q_new, 1 ), shift ); Q_new_p5 = add( Q_new, 5 ); @@ -353,7 +352,7 @@ void encod_unvoiced_ivas_fx( Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); + Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift /*----------------------------------------------------------------* * Unvoiced subframe processing *----------------------------------------------------------------*/ @@ -362,6 +361,7 @@ void encod_unvoiced_ivas_fx( *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); + move16(); } ELSE { @@ -387,7 +387,7 @@ void encod_unvoiced_ivas_fx( * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - // E_ACELP_innovative_codebook_ivas_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); + // E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate, st_fx->element_mode ); inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, st_fx->sharpFlag, i_subfr, -1, p_Aq_fx, gain_pit_fx, cn_fx, exc_fx, h1_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); @@ -398,6 +398,10 @@ void encod_unvoiced_ivas_fx( g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + move16(); + move16(); + move16(); + move16(); assert( gain_pit_fx == 0 ); gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); @@ -427,9 +431,10 @@ void encod_unvoiced_ivas_fx( *----------------------------------------------------------*/ E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); - IF( st_fx->Opt_RF_ON ) + if ( st_fx->Opt_RF_ON ) { st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; + move16(); } /*-----------------------------------------------------------------* * Update memory of the weighting filter @@ -442,7 +447,7 @@ void encod_unvoiced_ivas_fx( Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15 Ltmp = L_add( Ltmp, Ltmp2 ); - hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( Ltmp ) ); // Q_xn-1 + hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); // Q_xn move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB @@ -450,6 +455,7 @@ void encod_unvoiced_ivas_fx( #else hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); /*Qnew-1*/ #endif + move16(); BASOP_SATURATE_WARNING_ON_EVS; /*-------------------------------------------------------* @@ -489,6 +495,7 @@ void encod_unvoiced_ivas_fx( BASOP_SATURATE_WARNING_ON_EVS exc_fx[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } tmp2 = L_SUBFR; move16(); @@ -496,6 +503,7 @@ void encod_unvoiced_ivas_fx( } *tmp_noise_fx = extract_h( norm_gain_code_fx ); + move16(); voice_factors_fx[i_subfr / L_SUBFR] = 0; move16(); diff --git a/lib_enc/eval_pit_contr.c b/lib_enc/eval_pit_contr.c index e101a812b951d18685b056330ccdc1bc551d7afe..aee0b4a47ee6cf7c50ee5786c8dd6fbebc22c52a 100644 --- a/lib_enc/eval_pit_contr.c +++ b/lib_enc/eval_pit_contr.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constantes *-------------------------------------------------------------------*/ @@ -355,3 +356,4 @@ int16_t Pit_exc_contribution_len( return last_pit_bin; } +#endif diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index ab6c2efd1c2d37c0e566e7f9c9ea91ee3a404422..a947768a31ece5a4679ffb2fbcbd9af91c2bf001 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -136,7 +136,6 @@ void initFdCngEnc( } /* Initialize the Noise Estimator */ -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngEnc->msPeriodog, 0.0f, NPART ); set_f( hFdCngEnc->msBminWin, 0.0f, NPART ); set_f( hFdCngEnc->msBminSubWin, 0.0f, NPART ); @@ -156,7 +155,6 @@ void initFdCngEnc( set_f( hFdCngEnc->mem_coherence, EPSILON, 4 ); set_f( hFdCngEnc->msNoiseEst_old, 0.0f, NPART ); set_f( hFdCngEnc->msNoiseEst, 0.0f, NPART ); -#endif set_s( hFdCngEnc->msLocalMinFlag, 0, NPART ); set_s( hFdCngEnc->msNewMinFlag, 0, NPART ); hFdCngEnc->msPeriodogBufPtr = 0; @@ -1570,11 +1568,6 @@ void FdCngEncodeMDCTStereoSID_fx( Word16 size_value, temp_e, gb, shift; Word32 tmp32, t1, t2; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); -#endif - is_inp_ms = 0; move16(); IF( EQ_16( hCPE->hCoreCoder[0]->cng_sba_flag, 1 ) ) @@ -1843,11 +1836,7 @@ void FdCngEncodeMDCTStereoSID_fx( /* pad with zeros to reach common SID frame size */ push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); -#ifdef IVAS_FLOAT_FIXED - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); #endif @@ -2254,15 +2243,6 @@ void FdCngEncodeDiracMDCTStereoSID_fx( Word32 t1, t2, tmp32; /* set pointers and initialize */ - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[0]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, hCPE->hCoreCoder[1]->hFdCngEnc->npartDec ); - f2me_buf( hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); - f2me_buf( hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, &hCPE->hCoreCoder[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN ); -#endif - - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; @@ -2453,11 +2433,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( } push_indice( sts[0]->hBstr, IND_ENERGY, gain_idx[0], 7 ); -#ifdef IVAS_FLOAT_FIXED - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[0]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, sts[1]->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN ); - me2f_buf( sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngEnc->npartDec ); - me2f_buf( sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngEnc->npartDec ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS sts[0]->preemph_fac_flt = fixedToFloat( sts[0]->preemph_fac, Q15 ); sts[1]->preemph_fac_flt = fixedToFloat( sts[1]->preemph_fac, Q15 ); #endif diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 0821a3922fb3b859a05a8ff801ef3ee51cee7b3d..111cd2dc00a686b20583c97b1d255e4dd64331e0 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -57,9 +57,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; /* Initialize common */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - initFdCngCom_flt( hsCom, scale ); -#endif initFdCngCom( hsCom, scale ); /* Configure the Noise Estimator */ @@ -95,17 +92,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - initPartitions_flt( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); - - hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; - for ( j = 0; j < hsCom->nCLDFBpart; j++ ) - { - hsCom->CLDFBpart[j] = hsCom->part[j + hsCom->nFFTpart] - ( 256 - hsCom->startBand ); - hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; - } -#endif - initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); @@ -113,6 +99,8 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) { hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + move16(); + move16(); } /* Initialize noise estimation algorithm */ @@ -153,7 +141,6 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) set32_fx( hsEnc->mem_coherence_fx, EPSILON_FX, 4 ); set16_fx( hsEnc->mem_coherence_exp, 0, 4 ); - return; } diff --git a/lib_enc/find_tar.c b/lib_enc/find_tar.c index 244720947e5fe29333dc5a556077061558e7c1c6..bb172ebc289b0dab33552b9c903b913a0db00931 100644 --- a/lib_enc/find_tar.c +++ b/lib_enc/find_tar.c @@ -40,6 +40,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * find_targets() * @@ -118,3 +119,4 @@ void find_targets( return; } +#endif diff --git a/lib_enc/gaus_enc.c b/lib_enc/gaus_enc.c index 9a1334485f3347eb150bf8144419ab0966461c99..3b3b1e43c6e139b3d95478a6a907888be329f5e3 100644 --- a/lib_enc/gaus_enc.c +++ b/lib_enc/gaus_enc.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -458,3 +459,4 @@ static int16_t cod_2pos( return index; } +#endif diff --git a/lib_enc/gp_clip.c b/lib_enc/gp_clip.c index 51cbd2cabc69a03659ca1b21e170e1a74634b271..fecd64220d1a150e1167d343b022395385f26d43 100644 --- a/lib_enc/gp_clip.c +++ b/lib_enc/gp_clip.c @@ -41,6 +41,7 @@ #include "cnst.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -248,3 +249,4 @@ void gp_clip_test_gain_pit( return; } +#endif diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index 309c56a366054badfb5f3b4ac988b3f7ebefa63b..f60107866e135d367e283d7e0b56beb17e8f3d3e 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -42,7 +42,11 @@ #include "prot.h" #include "ivas_prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -639,6 +643,7 @@ static float edyn( return dyn; } +#endif /*-------------------------------------------------------------------* @@ -655,19 +660,38 @@ void GSC_enc_init( hGSCEnc->seed_tcx = 15687; hGSCEnc->cor_strong_limit = 1; set_f( hGSCEnc->last_exc_dct_in, 0, L_FRAME16k ); +#ifndef IVAS_FLOAT_FIXED hGSCEnc->last_ener = 0.0f; +#else + hGSCEnc->last_ener_fx = 0; +#endif set_s( hGSCEnc->last_bitallocation_band, 0, 6 ); hGSCEnc->mem_last_pit_band = BAND1k2 + 1; +#ifndef IVAS_FLOAT_FIXED hGSCEnc->lt_gpitch = 0.0f; +#else + hGSCEnc->lt_gpitch_fx = 0; +#endif hGSCEnc->pit_exc_hangover = 0; /* GSC - pitch excitation parameters */ +#ifndef IVAS_FLOAT_FIXED hGSCEnc->mem_w0_tmp = 0.0f; set_f( hGSCEnc->mem_syn_tmp, 0.0f, M ); +#else + hGSCEnc->mem_w0_tmp_fx = 0; + move16(); + set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); +#endif hGSCEnc->Last_frame_ener = (float) MAX_32; +#ifndef IVAS_FLOAT_FIXED hGSCEnc->mid_dyn = 40.0f; +#else + hGSCEnc->mid_dyn_fx = 5120; + move16(); /*40 -> Q7 */ +#endif hGSCEnc->noise_lev = NOISE_LEVEL_SP0; hGSCEnc->past_dyn_dec = 0; diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0573450d44d80eb9d6cc1601812386876d12c188..d0071ebebc412b8e3650be0416e0e9c857b75192 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -166,14 +166,13 @@ ivas_error init_encoder( set16_fx( st->mem_MA_fx, 0, M ); #endif - init_gp_clip( st->clip_var ); - pitch_ol_init( #ifndef IVAS_FLOAT_FIXED - &st->old_thres, + init_gp_clip( st->clip_var ); + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); #else - &st->old_thres_fx, + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); #endif - &st->old_pitch, &st->delta_pit, &st->old_corr ); set_f( st->old_wsp, 0, L_WSP_MEM ); #ifdef IVAS_FLOAT_FIXED set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); @@ -735,7 +734,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } +#ifndef IVAS_FLOAT_FIXED sc_vbr_enc_init( st->hSC_VBR ); +#else + sc_vbr_enc_init_fx( st->hSC_VBR ); +#endif } else { @@ -1301,16 +1304,6 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); -#if 1 // TODO: Float Initializations. To be removed later - init_gp_clip( st->clip_var ); - pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - &st->old_thres, -#else - &st->old_thres_fx, -#endif - &st->old_pitch, &st->delta_pit, &st->old_corr ); -#endif st->next_force_safety_net = 0; move16(); @@ -1892,9 +1885,6 @@ ivas_error init_encoder_ivas_fx( } sc_vbr_enc_init_fx( st->hSC_VBR ); -#if 1 - sc_vbr_enc_init( st->hSC_VBR ); -#endif } ELSE { @@ -2407,6 +2397,9 @@ void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ) { +#ifdef IVAS_FLOAT_FIXED + Word16 i; +#endif set_zero( hLPDmem->syn_flt, 1 + M ); set_f( hLPDmem->old_exc_flt, 0, L_EXC_MEM ); @@ -2417,13 +2410,24 @@ void LPDmem_enc_init( set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM ); set_f( hLPDmem->mem_syn3_flt, 0, M ); - hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + hLPDmem->tilt_code_flt = 0.0f; hLPDmem->gc_threshold_flt = 0.0f; + set_f( hLPDmem->dispMem_flt, 0, 8 ); #else + hLPDmem->tilt_code = 0; hLPDmem->gc_threshold = 0; + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } #endif - set_f( hLPDmem->dispMem_flt, 0, 8 ); return; } diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 5c9e1a7de6e6fca28f6da6eea9089c57ed496edc..30288b0dc15a45ce5b4e111c805da231f63bf4ac 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -457,9 +457,7 @@ Word16 inov_encode_ivas_fx( Word16 acelpautoc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; Word16 i, k; -#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void) last_L_frame; -#endif + Word16 Qxn, Rw_q, j; stack_pulses = 0; move16(); @@ -478,6 +476,8 @@ Word16 inov_encode_ivas_fx( move16(); } + Qxn = add( sub( Q_new, 1 ), shift ); + /*----------------------------------------------------------------* * Update target vector for codebook search in residual domain * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning) @@ -494,15 +494,14 @@ Word16 inov_encode_ivas_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR ); /* h2: Q11, Rw: (Rw_e)Q */ // Word16 Rw_e = E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); - Word16 Rw_q; corr_hh_ivas_fx( h2, Rw, &Rw_q, L_subfr ); // Q(Rw) = Q11-2 E_ACELP_conv_ivas( xn2, h2, cn ); // Qcn = Qxn2 /* dn_e -> Rw_e*Q_xn */ // Scale_sig(Rw, L_SUBFR, sub(5, Rw_e)); //Q9 - Word16 j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); - Qdn = add( add( Q_new - 1 + shift, Rw_q ), j + 1 ); + j = E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); + Qdn = add( add( Qxn, Rw_q ), add( j, 1 ) ); // Scale_sig(Rw, L_subfr, -3); //Q9->Q6 } ELSE @@ -514,7 +513,7 @@ Word16 inov_encode_ivas_fx( Scale_sig( cn, L_subfr, shift ); cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_ivas_fx2( xn2, Q_new - 1 + shift, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 + corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 } /*-----------------------------------------------------------------* @@ -666,11 +665,11 @@ Word16 inov_encode_ivas_fx( Word16 wordcnt, bitcnt; Word16 prm[8]; - test(); - test(); - test(); IF( st_fx->acelp_cfg.fixed_cdk_index[idx] >= 0 ) { + test(); + test(); + test(); IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { nBits = st_fx->acelp_cfg.fixed_cdk_index[idx]; @@ -724,7 +723,8 @@ Word16 inov_encode_ivas_fx( { FOR( k = 0; k < L_SUBFR - i; k++ ) { - y2[i + k] = add( y2[i + k], mult_r( code[i], shl_sat( h2[k], sh ) ) ); + y2[i + k] = add( y2[i + k], round_fx( L_shl( L_mult( code[i], h2[k] ), sh ) ) ); // Q9 + move16(); } } } @@ -746,7 +746,7 @@ Word16 inov_encode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6]; move16(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index a80c36ad4e73ffbaca846806e1acc899fe277109..5b1bf1f14b210bb89368990f8babe6aad7039d80 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -98,11 +98,7 @@ ivas_error ivas_core_enc( float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX]; float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; Word16 Q_new[CPE_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions float voice_factors[CPE_CHANNELS][NB_SUBFR16k] = { 0 }; -#else - float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; -#endif #ifdef IVAS_FLOAT_FIXED Word32 *new_swb_speech_fx; Word16 shb_speech_fx[L_FRAME16k]; // Q_shb_spch @@ -226,7 +222,7 @@ ivas_error ivas_core_enc( Word16 fft_buff_fx[2 * L_FFT]; Word32 cor_map_sum_fx = 0; Word16 exp_cor_map_sum = 0; - Word16 q_fft_buff; + Word16 e_fft_buff; Word16 e_enerBuffer; st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); @@ -242,27 +238,10 @@ ivas_error ivas_core_enc( f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); - q_fft_buff = Q_factor_arrL( fft_buff[n], ( 2 * L_FFT ) ); - - if ( q_fft_buff <= 16 ) - { - q_fft_buff = 0; - } - else - { - q_fft_buff = q_fft_buff - 16; - } - - if ( q_fft_buff >= 2 ) - { - q_fft_buff -= 3; - } - else - { - q_fft_buff -= 4; - } + f2me_buf_16( fft_buff[n], fft_buff_fx, &e_fft_buff, ( 2 * L_FFT ) ); + Scale_sig( fft_buff_fx, ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum + e_fft_buff += 1; - floatToFixed_arr( fft_buff[n], fft_buff_fx, q_fft_buff, ( 2 * L_FFT ) ); f2me_buf( enerBuffer[n], enerBuffer_fx, &e_enerBuffer, (Word32) CLDFB_NO_CHANNELS_MAX ); Word16 tmp_shift = find_guarded_bits_fx( 5 ); // Computing guraded bits necessary in the energyBuffer scale_sig32( enerBuffer_fx, CLDFB_NO_CHANNELS_MAX, -tmp_shift ); // Computing the shift as per guarded bits in the energyBuffer @@ -283,7 +262,11 @@ ivas_error ivas_core_enc( move16(); } #endif - if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 old_inp_12k8_fx[L_INP_12k8]; + floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, -1, L_INP_12k8 ); +#endif + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_12k8_fx, old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], #ifndef IVAS_FLOAT_FIXED cor_map_sum[n], @@ -446,15 +429,6 @@ ivas_error ivas_core_enc( // floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - - { - st->clip_var_fx[0] = (Word16) ( st->clip_var[0] * 2.56f ); - st->clip_var_fx[1] = float_to_fix16( st->clip_var[1], Q14 ); - st->clip_var_fx[2] = float_to_fix16( st->clip_var[2], Q8 ); - st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 ); - st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 ); - st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); - } st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); floatToFixed_arr( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq, -1, L_FRAME32k / 2 + 64 ); @@ -473,14 +447,6 @@ ivas_error ivas_core_enc( st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - { - st->clip_var[0] = (float) st->clip_var_fx[0] / 2.56f; - st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); - st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q8 ); - st->clip_var[3] = fix16_to_float( st->clip_var_fx[3], 0 ); - st->clip_var[4] = fix16_to_float( st->clip_var_fx[4], Q14 ); - st->clip_var[5] = fix16_to_float( st->clip_var_fx[5], Q14 ); - } for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index bef00f87a4120f5410f000c0cb07c1c104f5fab8..d8742856ca5b360668537beeb36db2df771cad4c 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -53,11 +53,12 @@ ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t element_brate, /* i : element bitrate */ - const int32_t last_element_brate, /* i : last element bitrate */ - const int16_t input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float **inp, /* o : ptr. to inp. signal in the current frame*/ float *ener, /* o : residual energy from Levinson-Durbin */ @@ -67,20 +68,13 @@ ivas_error pre_proc_ivas( float lsp_new[M], /* i/o: LSPs at the end of the frame */ float lsp_mid[M], /* i/o: LSPs in the middle of the frame */ float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - int16_t *Voicing_flag, /* o : voicing flag for HQ FEC */ - const float old_wsp[], /* i : weighted input signal buffer */ - const int16_t loc_harm, /* i : harmonicity flag */ -#ifndef IVAS_FLOAT_FIXED - const float cor_map_sum, /* i : speech/music clasif. parameter */ -#endif - const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ -#ifndef IVAS_FLOAT_FIXED - /*const*/ float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ - /*const*/ float fft_buff[2 * L_FFT], /* i : FFT buffer */ -#endif - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int16_t vad_hover_flag, /* i : VAD hangover flag */ - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ + float old_wsp[], /* i : weighted input signal buffer */ + const Word16 loc_harm, /* i : harmonicity flag */ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ #ifdef IVAS_FLOAT_FIXED , Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], @@ -91,21 +85,24 @@ ivas_error pre_proc_ivas( #endif ) { - int16_t L_look, element_mode, lMemRecalc_12k8; + Word16 L_look, element_mode, lMemRecalc_12k8; float *inp_12k8, *new_inp_12k8, *inp_16k; /* pointers to current frame and new data */ - const float *wsp; /* weighted input signal buffer */ - int32_t sr_core_tmp, total_brate_tmp; + Word16 *inp_16k_fx, *new_inp_12k8_fx; + float *wsp; /* weighted input signal buffer */ + Word32 sr_core_tmp, total_brate_tmp; ivas_error error; push_wmops( "pre_proc" ); error = IVAS_ERR_OK; + move32(); /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ element_mode = st->element_mode; + move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; @@ -119,52 +116,33 @@ ivas_error pre_proc_ivas( floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); #endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS1 - Word16 old_inp_16k_fx[L_INP_MEM]; - Word16 exp_old_inp_16k = 0; - Word16 old_inp_12k8_fx[496]; - Word16 exp_old_inp_12k8 = 0; - Word16 old_wsp_fx[L_WSP]; - Word16 exp_old_wsp = 0; - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], exp_Aw = 0; - Word16 lsp_new_fx[M], exp_lsp_new = 0; - Word16 lsp_mid_fx[M], exp_lsp_mid = 0; - Word16 epsP_fx[M + 1], exp_epsP = 0; - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 fft_buff_fx[2 * L_FFT]; - Word32 cor_map_sum_fx = 0; - Word16 exp_cor_map_sum = 0; - Word16 q_fft_buff; - Word16 e_enerBuffer; - - /*input buffers*/ - f2me_buf_16( st->old_inp_16k, old_inp_16k_fx, &exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &exp_old_inp_12k8, 496 ); - f2me_buf_16( old_wsp, old_wsp_fx, &exp_old_wsp, L_WSP ); - f2me_buf_16( epsP, epsP_fx, &exp_epsP, M + 1 ); - f2me( cor_map_sum, &cor_map_sum_fx, &exp_cor_map_sum ); -#endif - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ inp_12k8 = new_inp_12k8 - L_LOOK_12k8; - if ( element_mode != IVAS_CPE_DFT ) + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8 -= L_FILT; } + new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + new_inp_12k8_fx -= L_FILT; + } wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ lMemRecalc_12k8 = 0; - if ( element_mode == IVAS_CPE_TD ) + move16(); + if ( EQ_16( element_mode, IVAS_CPE_TD ) ) { lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); + move16(); } /*----------------------------------------------------------------* * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED test(); test(); test(); @@ -180,7 +158,7 @@ ivas_error pre_proc_ivas( test(); test(); test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; @@ -217,6 +195,7 @@ ivas_error pre_proc_ivas( test(); test(); Word16 flag_1 = 0; + move16(); IF( EQ_16( st->L_frame, L_FRAME16k ) ) { flag_1 = ACELP_16k40; @@ -232,7 +211,7 @@ ivas_error pre_proc_ivas( configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), flag_1 ); } - IF( st->ini_frame == 0 ) + if ( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; @@ -248,7 +227,6 @@ ivas_error pre_proc_ivas( } ELSE IF( EQ_16( st->L_frame, L_FRAME32k ) ) { - st->gamma = GAMMA16k; st->preemph_fac = PREEMPH_FAC_SWB; move16(); @@ -268,76 +246,12 @@ ivas_error pre_proc_ivas( move32(); move16(); move16(); -#else - if ( st->core_brate == FRAME_NO_DATA ) - { - /* prevent "L_frame" changes in CNG segments */ - st->L_frame = st->last_L_frame; - } - else if ( st->core_brate == SID_2k40 && st->bwidth >= WB && st->hDtxEnc->first_CNG && ( st->hTdCngEnc != NULL && st->hTdCngEnc->act_cnt2 < MIN_ACT_CNG_UPD ) ) - { - /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame = st->hDtxEnc->last_CNG_L_frame; - } - else if ( ( ( st->element_mode == IVAS_CPE_MDCT && st->element_brate >= IVAS_64k && st->bwidth >= SWB ) || ( element_mode == IVAS_SCE && st->total_brate > MAX_ACELP_BRATE && st->bwidth >= SWB ) ) && st->core_brate != SID_2k40 ) - { - st->L_frame = L_FRAME32k; - } - else if ( st->bwidth >= SWB && st->total_brate > MAX_ACELP_BRATE_ISM && st->total_brate <= MAX_ACELP_BRATE && element_mode == IVAS_SCE && st->is_ism_format && st->tcxonly && st->core_brate != SID_2k40 ) - { - st->L_frame = L_FRAME25_6k; - } - else if ( st->flag_ACELP16k ) - { - st->L_frame = L_FRAME16k; - } - else - { - st->L_frame = L_FRAME; - } - - if ( st->hFdCngEnc != NULL && st->element_mode != IVAS_CPE_MDCT && ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->input_bwidth ) ) ) - { -#ifdef IVAS_FLOAT_FIXED - configureFdCngEnc_ivas_fx( st->hFdCngEnc, max( st->input_bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); -#else - configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 ); -#endif - } - - if ( st->ini_frame == 0 ) - { - /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame = st->L_frame; - } - - if ( st->L_frame == L_FRAME ) - { - st->gamma_flt = GAMMA1_FLT; - st->preemph_fac_flt = PREEMPH_FAC_FLT; - } - else if ( st->L_frame == L_FRAME32k ) - { - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; - } - else - { - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - } - - st->sr_core = st->L_frame * FRAMES_PER_SEC; - st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; -#endif /*-----------------------------------------------------------------* * coder_type rewriting in case of switching * IC frames selection * enforce TC frames in case of switching *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED test(); test(); test(); @@ -415,60 +329,9 @@ ivas_error pre_proc_ivas( st->GSC_noisy_speech = 0; move16(); } -#else - /* enforce TRANSITION frames */ - if ( !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) && st->last_L_frame != st->L_frame && st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 && st->last_core_brate != FRAME_NO_DATA && st->last_core_brate != SID_2k40 && st->coder_type_raw != VOICED ) - { - /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ - st->coder_type = TRANSITION; - } - else if ( st->last_core == HQ_CORE && st->coder_type_raw != VOICED ) - { - /* enforce TC frame in case of HQ -> ACELP core switching */ - st->coder_type = TRANSITION; - } - else if ( st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG && !( element_mode == IVAS_CPE_TD ) ) - { - /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ - st->coder_type = TRANSITION; - } - /* select INACTIVE frames */ - else if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE && st->vad_flag == 0 && st->element_mode != IVAS_CPE_MDCT ) - { - /* inactive frames will be coded by GSC technology */ - /* except for the VBR mode. VBR mode uses NELP for that */ - if ( !( st->Opt_SC_VBR && vad_flag_dtx ) && ( st->idchan == 0 || element_mode != IVAS_CPE_TD ) ) - { - st->coder_type = INACTIVE; - st->hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - } - } - else if ( st->total_brate > MAX_GSC_INACTIVE_BRATE && ( ( st->vad_flag == 0 && st->bwidth >= SWB && st->max_bwidth >= SWB ) || ( st->localVAD == 0 && ( st->bwidth <= WB || st->max_bwidth <= WB ) ) ) ) - { - /* inactive frames will be coded by AVQ technology */ - st->coder_type = INACTIVE; - } - - - /*---------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *---------------------------------------------------------------------*/ - - st->mdct_sw = MODE1; - st->mdct_sw_enable = MODE1; - if ( ( st->total_brate <= MIN_BRATE_GSC_NOISY_FLAG || st->bwidth < SWB || st->flag_ACELP16k ) && st->GSC_IVAS_mode == 0 ) - { - st->GSC_noisy_speech = 0; - } -#endif /* core selection */ -#ifndef IVAS_FLOAT_FIXED - ivas_decision_matrix_enc( st, element_brate, fft_buff, enerBuffer, last_element_mode ); -#else ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode ); -#endif -#ifdef IVAS_FLOAT_FIXED test(); test(); IF( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ @@ -496,6 +359,7 @@ ivas_error pre_proc_ivas( move32(); st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); st->encoderLookahead_enc = NS2SA_FX2( st->sr_core, ACELP_LOOK_NS ); st->encoderPastSamples_enc = shr( ( imult1616( st->L_frame, 9 ) ), 4 ); move16(); @@ -674,352 +538,158 @@ ivas_error pre_proc_ivas( *Voicing_flag = 0; move16(); } -#else - if ( st->L_frame == L_FRAME16k && ( st->coder_type == VOICED || st->coder_type == UNVOICED ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ + + /*-----------------------------------------------------------------* + * Compute core-coder buffers at internal sampling rate + *-----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { - st->coder_type = GENERIC; + sr_core_tmp = INT_FS_16k; + move32(); } - - if ( st->core == TCX_20_CORE || st->core == HQ_CORE ) + ELSE { - st->Nb_ACELP_frames = 0; - /* Configure TCX with the same bitrate as given when (re-)initializing TCX */ - total_brate_tmp = st->total_brate; - st->total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; -#ifdef IVAS_FLOAT_FIXED + sr_core_tmp = L_max( INT_FS_16k, st->sr_core ); + } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_32( st->last_bits_frame_nominal * FRAMES_PER_SEC, st->total_brate ) ) || - ( NE_16( st->last_bwidth, st->bwidth ) ) || - ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || - ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || - ( NE_16( st->rf_mode_last, st->rf_mode ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) - { - Word16 bSwitchFromAmrwbIO = 0, switchWB = 0, fscale; - Word32 sr_core; - move16(); - move16(); + L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + move16(); + + inp_16k = old_inp_16k + L_INP_MEM - L_look; - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) - { - bSwitchFromAmrwbIO = 1; - move16(); - } - sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - fscale = sr2fscale_fx( sr_core ); - IF( EQ_32( fscale, st->fscale ) && !bSwitchFromAmrwbIO && !switchWB ) - { - st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); - } - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q14 ); - } - } -#endif - SetModeIndex_ivas_fx( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->envWeighted && !st->enableTcxLpc ) - { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); - } -#endif -#else - SetModeIndex( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag ); -#endif + Word16 old_inp_16k_fx[L_INP], Q_old_inp_16k = -1; + Word32 ener_fx = 0; + Word16 new_inp_resamp16k_fx[L_FRAME16k]; + Word16 Q_r[2] = { 0 }, exp_wsp; + Word32 epsP_fx[M + 1] = { 0 }; + Word16 old_wsp_fx[L_WSP], wsp_fx[L_FRAME + L_LOOK_12k8]; + floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; - st->sr_core = getCoreSamplerateMode2_flt( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - st->total_brate = total_brate_tmp; + st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); + st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); + st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); + st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); - st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC ); - st->encoderLookahead_enc = NS2SA( st->sr_core, ACELP_LOOK_NS ); - st->encoderPastSamples_enc = ( st->L_frame * 9 ) >> 4; + floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); + floatToFixed_arr16( wsp, wsp_fx, Q_old_inp_16k, (Word16) ( L_FRAME + L_LOOK_12k8 ) ); + f2me_buf_16( old_wsp, old_wsp_fx, &exp_wsp, L_WSP ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); + floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); + floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); + floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + // wspeech_enc - if ( st->sr_core == INT_FS_12k8 ) - { - st->preemph_fac_flt = PREEMPH_FAC_FLT; - st->gamma_flt = GAMMA1_FLT; - } - else if ( st->sr_core == INT_FS_16k ) - { - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - st->gamma_flt = GAMMA16k_FLT; - } - else /* st->sr_core >=25600 */ + if ( st->hBWE_FD != NULL ) + { + floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + st->Q_old_wtda = -1; // This reset needs to be looked into + } +#endif + IF( !flag_16k_smc ) + { + error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, &ener_fx, + A_fx, Aw_fx, + epsP_fx, + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r ); + IF( NE_32( error, IVAS_ERR_OK ) ) { - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; - st->gamma_flt = GAMMA16k_FLT; + return error; } + } + test(); + IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) + { + /* update signal buffers */ + Copy( new_inp_12k8_fx, st->buf_speech_enc_pe + st->L_frame, L_FRAME ); + Copy( st->buf_speech_enc + L_FRAME32k, st->buf_speech_enc + st->L_frame, L_FRAME ); - if ( st->vad_flag == 0 ) - { - st->coder_type = INACTIVE; - } - else if ( st->coder_type > GENERIC ) + test(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - st->coder_type = GENERIC; + Copy( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); } - if ( st->element_mode != IVAS_CPE_MDCT ) + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { - SetTCXModeInfo( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); + Copy( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); } - } - else if ( st->element_mode == IVAS_CPE_MDCT ) - { - st->hTcxEnc->tfm_mem = 0.75f; - } - else if ( element_brate != last_element_brate ) - { - if ( st->core_brate != FRAME_NO_DATA ) + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_32( imult1616( st->last_bits_frame_nominal, FRAMES_PER_SEC ), st->total_brate ) ) || - ( NE_16( st->last_bwidth, st->bwidth ) ) || - ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || - ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || - ( NE_16( st->rf_mode_last, st->rf_mode ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) - { - Word16 bSwitchFromAmrwbIO = 0, switchWB = 0, fscale; - Word32 sr_core; - move16(); - move16(); - - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) - { - bSwitchFromAmrwbIO = 1; - move16(); - } - sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - fscale = sr2fscale_fx( sr_core ); - IF( EQ_32( fscale, st->fscale ) && !bSwitchFromAmrwbIO && !switchWB ) - { - st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); - } - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q14 ); - } - } -#endif - SetModeIndex_ivas_fx( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->envWeighted && !st->enableTcxLpc ) - { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); - } -#endif -#else - SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); -#endif + Copy( st->buf_speech_enc + L_FRAME32k - L_FILT, st->buf_speech_enc + st->L_frame - L_FILT, L_FILT ); } - if ( st->extl != -1 && st->extl != IGF_BWE && st->igf == 1 ) + IF( st->tcxonly == 0 ) { - st->igf = 0; + Copy( wsp_fx, st->wspeech_enc, L_FRAME + L_LOOK_12k8 ); } } + IF( flag_16k_smc ) + { + Copy( st->buf_speech_enc + L_FRAME16k, new_inp_resamp16k_fx, L_FRAME16k ); + } /*-----------------------------------------------------------------* - * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) + * Updates *-----------------------------------------------------------------*/ - if ( loc_harm == 1 && cor_map_sum > 50 && st->clas == VOICED_CLAS && st->coder_type == GENERIC ) - { - st->last_harm_flag_acelp++; + /* update old weighted speech buffer - for OL pitch analysis */ + Copy( &old_wsp_fx[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); + st->exp_old_wsp = exp_wsp; + move16(); - if ( st->last_harm_flag_acelp > 10 ) - { - st->last_harm_flag_acelp = 10; - } - } - else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // No need to do fixed to float for signal_in_fx + st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); + st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); + st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); + st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { - st->last_harm_flag_acelp = 0; + *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); } - /*-----------------------------------------------------------------* - * Update audio frames counter (used for UV decision) - *-----------------------------------------------------------------*/ + fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( new_inp_resamp16k_fx, new_inp_resamp16k, Q_old_inp_16k, L_FRAME16k ); + fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); + fixedToFloat_arr( st->old_wsp_fx, st->old_wsp, 15 - st->exp_old_wsp, L_WSP_MEM ); + + fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); + fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); + fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - if ( st->coder_type == AUDIO ) + if ( st->hBWE_FD != NULL ) { - st->audio_frame_cnt += AUDIO_COUNTER_STEP; + fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); } - else if ( st->coder_type != INACTIVE ) + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) { - st->audio_frame_cnt--; + fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); } - - if ( st->audio_frame_cnt > AUDIO_COUNTER_MAX ) +#endif + /* set the pointer of the current frame for the ACELP core */ + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->audio_frame_cnt = AUDIO_COUNTER_MAX; + *inp = inp_12k8; } - - if ( st->audio_frame_cnt < 0 ) + ELSE { - st->audio_frame_cnt = 0; - } - - /*-----------------------------------------------------------------* - * Set formant sharpening flag - *-----------------------------------------------------------------*/ - - st->sharpFlag = 0; - - if ( st->coder_type == GENERIC || st->coder_type == VOICED || st->coder_type == TRANSITION ) - { - if ( element_brate >= FRMT_SHP_MIN_BRATE_IVAS && st->lp_noise > FORMANT_SHARPENING_NOISE_THRESHOLD ) - { - st->sharpFlag = 0; - } - else - { - st->sharpFlag = 1; - } - } - - /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ - if ( st->rf_mode && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) - { - st->sharpFlag = 1; - } - - /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */ - if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) - { - st->sharpFlag = 0; - if ( st->coder_type == GENERIC || st->coder_type == VOICED ) - { - st->sharpFlag = 1; - } - } - - /*-----------------------------------------------------------------* - * Set voicing flag for HQ FEC - *-----------------------------------------------------------------*/ - - if ( st->sp_aud_decision1 == 0 && ( st->coder_type == VOICED || st->coder_type == GENERIC ) ) - { - *Voicing_flag = 1; - } - else - { - *Voicing_flag = 0; - } -#endif - - /*-----------------------------------------------------------------* - * Compute core-coder buffers at internal sampling rate - *-----------------------------------------------------------------*/ - - sr_core_tmp = ( st->tcxonly == 0 ) ? INT_FS_16k : max( INT_FS_16k, st->sr_core ); /* indicates the ACELP sampling rate */ - - L_look = NS2SA( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ - - inp_16k = old_inp_16k + L_INP_MEM - L_look; - - if ( !flag_16k_smc ) - { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#endif - error = ivas_compute_core_buffers( st, &inp_16k, old_inp_16k, new_inp_resamp16k, input_frame, last_element_mode, sr_core_tmp, ener, -#ifndef IVAS_FLOAT_FIXED - A, Aw, -#else - A_fx, Aw_fx, -#endif - epsP, -#ifndef IVAS_FLOAT_FIXED - lsp_new, lsp_mid -#else - lsp_new_fx, lsp_mid_fx -#endif - ); - if ( error != IVAS_ERR_OK ) - { - return error; - } - } - - if ( !( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) ) - { - /* update signal buffers */ - mvr2r( new_inp_12k8, st->buf_speech_enc_pe_flt + st->L_frame, L_FRAME ); - mvr2r( st->buf_speech_enc_flt + L_FRAME32k, st->buf_speech_enc_flt + st->L_frame, L_FRAME ); - - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - STEREO_DFT_OVL_12k8, st->buf_speech_enc_flt + st->L_frame - STEREO_DFT_OVL_12k8, STEREO_DFT_OVL_12k8 ); - } - else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - lMemRecalc_12k8 - L_FILT, st->buf_speech_enc_flt + st->L_frame - lMemRecalc_12k8 - L_FILT, lMemRecalc_12k8 + L_FILT ); - } - else if ( element_mode == IVAS_SCE ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME32k - L_FILT, st->buf_speech_enc_flt + st->L_frame - L_FILT, L_FILT ); - } - - if ( st->tcxonly == 0 ) - { - mvr2r( wsp, st->wspeech_enc_flt, L_FRAME + L_LOOK_12k8 ); - } - } - - if ( flag_16k_smc ) - { - mvr2r( st->buf_speech_enc_flt + L_FRAME16k, new_inp_resamp16k, L_FRAME16k ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old weighted speech buffer - for OL pitch analysis */ - mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM ); - - - /* set the pointer of the current frame for the ACELP core */ - if ( st->L_frame == L_FRAME ) - { - *inp = inp_12k8; - } - else - { - *inp = inp_16k; + *inp = inp_16k; } /* Update VAD hangover frame counter in active frames */ -#ifdef IVAS_FLOAT_FIXED test(); test(); - IF( !( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->tcxonly == 0 ) + IF( !( EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) ) && st->tcxonly == 0 ) { test(); test(); @@ -1028,7 +698,7 @@ ivas_error pre_proc_ivas( { st->hTdCngEnc->burst_ho_cnt = add( st->hTdCngEnc->burst_ho_cnt, 1 ); move16(); - IF( GT_16( st->hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ) ) + if ( GT_16( st->hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE ) ) { st->hTdCngEnc->burst_ho_cnt = HO_HIST_SIZE; move16(); @@ -1040,23 +710,7 @@ ivas_error pre_proc_ivas( move16(); } } -#else - if ( !( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) && st->tcxonly == 0 ) - { - if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && vad_hover_flag ) - { - st->hTdCngEnc->burst_ho_cnt++; - if ( st->hTdCngEnc->burst_ho_cnt > HO_HIST_SIZE ) - { - st->hTdCngEnc->burst_ho_cnt = HO_HIST_SIZE; - } - } - else if ( st->hTdCngEnc != NULL && vad_flag_dtx ) - { - st->hTdCngEnc->burst_ho_cnt = 0; - } - } -#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); @@ -1075,165 +729,86 @@ ivas_error pre_proc_ivas( * * Compute core-coder buffers at internal sampling rate *--------------------------------------------------------------------*/ - -ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ -#ifndef IVAS_FLOAT_FIXED - float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ -#else - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ -#endif - float epsP[M + 1], /* i/o: LP prediction errors */ -#ifndef IVAS_FLOAT_FIXED - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ -#else - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ -#endif -) +ivas_error ivas_compute_core_buffers_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ + Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const Word16 input_frame, /* i : frame length */ + const Word16 last_element_mode, /* i : last element mode */ + const Word32 sr_core, /* i : core-coder sampling rate */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin */ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ + Word32 epsP_fx[M + 1], /* i/o: LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ + Word16 Q_old_inp_16k, + Word16 Q_r[2] ) { - float *inp_16k, *new_inp_16k; -#ifndef IVAS_FLOAT_FIXED - float tmp; - float mem_decim16k_dummy[2 * L_FILT_MAX]; -#endif - /*const*/ float *signal_in; - int16_t delay, element_mode; -#ifdef IVAS_FLOAT_FIXED + Word16 *inp_16k_fx, *new_inp_16k_fx; + Word16 delay, element_mode; Word16 temp1F_icatdmResampBuf_fx[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ Word16 mem_decim16k_dummy_fx[2 * L_FILT_MAX]; - Word32 *signal_in_32fx; Word16 *signal_in_fx; -#else - float temp1F_icatdmResampBuf[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ -#endif - float new_inp_resamp16k[L_FRAME16k]; - int16_t lMemRecalc, lMemRecalc_16k, L_frame_tmp, L_look; - int32_t input_Fs; + Word16 lMemRecalc, lMemRecalc_16k, L_frame_tmp, L_look; + Word32 input_Fs; - signal_in = st->input; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 new_inp_resamp16k_fx[L_FRAME16k], tmp_fx; Word16 Q_tmp, mem_decim16k_size, size_modified; - Word16 old_inp_16k_fx[L_INP]; - // Word16 Q_old_inp_16k = 0; - Word16 Q_old_inp_16k = -1; - Word16 *inp_16k_fx, *new_inp_16k_fx; - Word32 epsP_fx[M + 1]; - Word16 epsP_h[M + 1] = { 0 }; - Word16 epsP_l[M + 1] = { 0 }; - Word16 Q_r[2] = { 0 }; - Word32 ener_fx = 0; - 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]; + Word16 epsP_h[M + 1]; + Word16 epsP_l[M + 1]; #ifdef MSAN_FIX set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); #endif - signal_in_32fx = st->input32_fx; + set16_fx( epsP_h, 0, M + 1 ); + set16_fx( epsP_l, 0, M + 1 ); signal_in_fx = st->input_fx; - /* - !!!! ALL BUFFERS CONSIDERED IN Q(-1) for now !!!! - */ - // st->mem_preemph_enc = float_to_fix16( st->mem_preemph_enc_flt, Q_old_inp_16k ); - // st->mem_preemph16k_fx = float_to_fix16( st->mem_preemph16k, Q_old_inp_16k ); - // st->mem_preemph16k_DFT_fx = float_to_fix16( st->mem_preemph16k_DFT, Q_old_inp_16k ); - // st->mem_wsp_enc = float_to_fix16( st->mem_wsp_enc_flt, Q_old_inp_16k ); - - st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); - st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); - - floatToFixed_arrL( signal_in, signal_in_32fx, Q11, 960 ); - - floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); - floatToFixed_arr16( signal_in, signal_in_fx, Q_old_inp_16k, 960 ); -#ifndef MSAN_FIX - floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); -#endif - - f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); - floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); - floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); - floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - // wspeech_enc - - if ( st->hBWE_FD != NULL ) - { - floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); - st->Q_old_wtda = -1; // This reset needs to be looked into - } -#endif -#endif - input_Fs = st->input_Fs; + move32(); element_mode = st->element_mode; + move16(); lMemRecalc_16k = 0; + move16(); lMemRecalc = 0; + move16(); IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { lMemRecalc_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_NS ); + move16(); lMemRecalc = NS2SA( input_Fs, L_MEM_RECALC_NS ); + move16(); } /*---------------------------------------------------------------* * Preprocessing at other sampling frequency rate (16/25.6/32kHz) *----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) + { - L_frame_tmp = ( st->tcxonly == 0 ) ? L_FRAME16k : max( L_FRAME16k, st->L_frame ); + L_frame_tmp = L_FRAME16k; + move16(); + } + ELSE + { + L_frame_tmp = s_max( L_FRAME16k, st->L_frame ); + } L_look = NS2SA( sr_core, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + move16(); new_inp_16k_fx = old_inp_16k_fx + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ -#endif - inp_16k_fx = new_inp_16k_fx - L_look; /* pointer to the current frame of input signal in 16kHz core */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ -#endif + inp_16k_fx = new_inp_16k_fx - L_look; /* pointer to the current frame of input signal in 16kHz core */ /* shift the pointer back to take care of resampler memory update */ test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_SCE ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - new_inp_16k -= NS2SA( sr_core, DELAY_FIR_RESAMPL_NS ); -#endif new_inp_16k_fx -= NS2SA( sr_core, DELAY_FIR_RESAMPL_NS ); } -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - STEREO_DFT_OVL_16k ); - } - else if ( element_mode == IVAS_CPE_TD ) - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - L_MEM_RECALC_16K - L_FILT16k ); - } - else - { - mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM - L_FILT16k ); - } -#else IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - STEREO_DFT_OVL_16k ); @@ -1246,353 +821,11 @@ ivas_error ivas_compute_core_buffers( { Copy( st->old_inp_16k_fx, old_inp_16k_fx, L_INP_MEM - L_FILT16k ); } -#endif /*---------------------------------------------------------------* * Change the sampling frequency to 16/25.6/32 kHz *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - if ( element_mode == IVAS_SCE ) - { - if ( input_Fs == sr_core ) - { - /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ - delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); - mvr2r( st->mem_decim16k + delay, new_inp_16k, delay ); - mvr2r( signal_in, new_inp_16k + delay, input_frame ); - mvr2r( signal_in + input_frame - 2 * delay, st->mem_decim16k, 2 * delay ); - } - else if ( input_Fs == 32000 || input_Fs == 48000 ) - { - modify_Fs( signal_in, input_frame, input_Fs, new_inp_16k, sr_core, st->mem_decim16k, 0 ); - - mvr2r( st->mem_decim16k, mem_decim16k_dummy, 2 * L_FILT_MAX ); - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy, 0 ); - } - } - else if ( element_mode == IVAS_CPE_TD ) - { - if ( input_Fs == sr_core ) - { - /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ - delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); - mvr2r( st->mem_decim16k + delay, new_inp_16k - lMemRecalc - delay + L_FILT16k, delay ); - mvr2r( signal_in - lMemRecalc, new_inp_16k - lMemRecalc + L_FILT16k, input_frame + lMemRecalc ); - mvr2r( signal_in + input_frame - lMemRecalc - 2 * delay, st->mem_decim16k, 2 * delay ); - } - else if ( input_Fs == 32000 || input_Fs == 48000 ) - { - /* reconstruct past segment of input signal when switching from MDCT stereo */ - if ( last_element_mode == IVAS_CPE_MDCT /*|| st->idchan == 1*/ ) - { - int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - int16_t length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - - mvr2r( signal_in - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k, 0 ); - } - - modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_16k - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k, 0 ); - mvr2r( st->mem_decim16k, mem_decim16k_dummy, 2 * L_FILT_MAX ); - - if ( lMemRecalc > 0 ) - { - modify_Fs( signal_in - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy, 0 ); - } - - set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); - modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k + NS2SA( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy, 0 ); - } - } - else if ( st->idchan == 0 ) - { - /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ - mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); - } - - /*------------------------------------------------* - * Update BWE memories * - *------------------------------------------------*/ - - if ( sr_core == INT_FS_16k && element_mode != IVAS_CPE_MDCT ) - { - delay = NS2SA( INT_FS_16k, DELAY_FD_BWE_ENC_12k8_NS ); - - if ( element_mode == IVAS_CPE_DFT ) - { - /* save input resampled at 16kHz, non-preemphasised.*/ - mvr2r( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB ) - { - mvr2r( new_inp_16k - delay, st->hBWE_FD->old_input_wb, delay ); - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->hBWE_FD->old_wtda_swb + L_FRAME16k - STEREO_DFT_OVL_16k + delay, STEREO_DFT_OVL_16k - delay ); - } - } - else if ( element_mode == IVAS_CPE_TD ) - { - /* save input resampled at 16kHz, non-preemphasised */ - mvr2r( new_inp_16k + L_FILT16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB && st->hBWE_FD != NULL ) - { - mvr2r( new_inp_16k + L_FILT16k - delay, st->hBWE_FD->old_input_wb, delay ); - mvr2r( new_inp_16k - L_MEM_RECALC_16K, st->hBWE_FD->old_wtda_swb + L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k + delay, L_MEM_RECALC_16K + L_FILT16k - delay ); - } - } - else if ( element_mode == IVAS_SCE ) - { - /* save input resampled at 16kHz, non-preemphasised */ - mvr2r( new_inp_16k + L_FILT16k, new_inp_resamp16k, L_FRAME16k ); - - if ( st->bwidth == WB ) - { - mvr2r( new_inp_16k, st->hBWE_FD->old_input_wb + delay - L_FILT16k, L_FILT16k ); - /* all buffer st->hBWE_FD->old_wtda_swb is correct and does not need to be updated */ - } - } - } - else if ( sr_core > INT_FS_16k ) - { - /* reset the buffer, the signal is needed for WB BWEs */ - set_f( new_inp_resamp16k, 0.0f, L_FRAME16k ); - } - - /*------------------------------------------------------------------* - * Perform fixed preemphasis (16kHz signal) through 1 - g*z^-1 - *-----------------------------------------------------------------*/ - - if ( st->tcxonly == 0 && !( ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) || element_mode == IVAS_CPE_MDCT ) ) - { - st->mem_preemph_enc_flt = new_inp_16k[L_frame_tmp - 1]; - } - -#ifdef IVAS_FLOAT_FIXED - Word16 exp_new_inp_16k_fx = 0; - move16(); -#endif - if ( input_Fs > 8000 && sr_core == INT_FS_16k && element_mode != IVAS_CPE_MDCT ) - { - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ - - st->mem_preemph16k = st->mem_preemph16k_DFT; - st->mem_preemph16k_DFT = old_inp_16k[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - - if ( st->L_frame == L_FRAME16k ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->buf_speech_enc_flt + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } -#ifdef IVAS_FLOAT_FIXED - f2me_buf_16( new_inp_16k - STEREO_DFT_OVL_16k, new_inp_16k_fx - STEREO_DFT_OVL_16k, &exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - fixedToFloat_arr( new_inp_16k_fx - STEREO_DFT_OVL_16k, new_inp_16k - STEREO_DFT_OVL_16k, 15 - exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); -#else - preemph( new_inp_16k - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif - -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - move16(); - f2me_buf_16( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, &exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, STEREO_DFT_OVL_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, STEREO_DFT_OVL_16k, &tmp ); -#endif - } - else if ( st->element_mode == IVAS_CPE_TD ) - { - if ( last_element_mode == IVAS_CPE_DFT ) - { -#ifdef IVAS_FLOAT_FIXED - Word16 exp_inp_16k_mem_stereo_sw = 0; - move16(); - f2me_buf_16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, &exp_inp_16k_mem_stereo_sw, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, 15 - exp_inp_16k_mem_stereo_sw ); - - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; - move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - PREEMPH_FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); - - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_inp_16k_mem_stereo_sw ); - fixedToFloat_arr( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), 15 - exp_inp_16k_mem_stereo_sw, L_MEM_RECALC_16K + STEREO_DFT_OVL_16k + L_MEM_RECALC_16K + L_FILT16k ); -#else - st->mem_preemph16k = st->mem_preemph16k_DFT; - mvr2r( st->inp_16k_mem_stereo_sw, new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - preemph( new_inp_16k - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k_FLT, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k ); -#endif - } - - st->mem_preemph16k_DFT = old_inp_16k[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - - /* preemphasise past segment of input signal when switching from MDCT stereo */ - if ( last_element_mode == IVAS_CPE_MDCT ) - { - int16_t length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - move16(); - f2me_buf_16( new_inp_16k - lMemRecalc_16k - length_16k, new_inp_16k_fx - lMemRecalc_16k - length_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + length_16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); - - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k - length_16k, new_inp_16k - lMemRecalc_16k - length_16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + length_16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k - length_16k, PREEMPH_FAC_FLT, length_16k, &st->mem_preemph16k ); -#endif - } - - if ( st->L_frame == L_FRAME16k ) - { - mvr2r( new_inp_16k - lMemRecalc_16k, st->buf_speech_enc_flt + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k ); - } -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k - lMemRecalc_16k, new_inp_16k_fx - lMemRecalc_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k, new_inp_16k - lMemRecalc_16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k - lMemRecalc_16k, new_inp_16k_fx - lMemRecalc_16k, &exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, new_inp_16k - lMemRecalc_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, lMemRecalc_16k + L_FRAME16k ); -#else - preemph( new_inp_16k - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, lMemRecalc_16k + L_FILT16k, &tmp ); -#endif - } - else if ( element_mode == IVAS_SCE ) - { -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k, new_inp_16k_fx, &exp_new_inp_16k_fx, L_FRAME16k ); - st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - st->mem_preemph16k = fixedToFloat( st->mem_preemph16k_fx, 15 - exp_new_inp_16k_fx ); - fixedToFloat_arr( new_inp_16k_fx, new_inp_16k, 15 - exp_new_inp_16k_fx, L_FRAME16k ); -#else - preemph( new_inp_16k, PREEMPH_FAC_16k_FLT, L_FRAME16k, &( st->mem_preemph16k ) ); - tmp = st->mem_preemph16k; -#endif - -#ifdef IVAS_FLOAT_FIXED - exp_new_inp_16k_fx = 0; - f2me_buf_16( new_inp_16k + L_FRAME16k, new_inp_16k_fx + L_FRAME16k, &exp_new_inp_16k_fx, L_FRAME16k + L_FILT16k ); - Word16 tmp_fx = (Word16) floatToFixed( st->mem_preemph16k, 15 - exp_new_inp_16k_fx ); - PREEMPH_FX( new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); - fixedToFloat_arr( new_inp_16k_fx + L_FRAME16k, new_inp_16k + L_FRAME16k, 15 - exp_new_inp_16k_fx, L_FRAME16k + L_FILT16k ); -#else - preemph( new_inp_16k + L_FRAME16k, PREEMPH_FAC_16k_FLT, L_FILT16k, &tmp ); -#endif - } - else if ( input_Fs > 8000 ) /* keep memory up-to-date in case of bitrate switching */ - { - if ( element_mode == IVAS_CPE_DFT ) - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; - } - else if ( element_mode == IVAS_CPE_TD ) - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - lMemRecalc_16k - 1]; - } - else if ( element_mode == IVAS_CPE_MDCT ) - { - st->mem_preemph16k = 0; - } - else /* SCE */ - { - st->mem_preemph16k = new_inp_16k[L_frame_tmp - 1]; - } - st->mem_preemph16k_DFT = st->mem_preemph16k; - } - } - - /*-----------------------------------------------------------------* - * LP analysis at 16kHz if ACELP@16k core was selected - * update buffers - *-----------------------------------------------------------------*/ - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - /* update signal buffers */ - if ( element_mode == IVAS_CPE_DFT ) - { - mvr2r( new_inp_16k - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe_flt + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } - else if ( element_mode == IVAS_CPE_TD ) - { - mvr2r( new_inp_16k - lMemRecalc_16k, st->buf_speech_enc_pe_flt + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k ); - } - else - { - mvr2r( new_inp_resamp16k, st->buf_speech_enc_flt + L_FRAME16k, L_FRAME16k ); - mvr2r( new_inp_16k, st->buf_speech_enc_pe_flt + L_FRAME16k, L_FRAME16k ); - } - - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ - - if ( st->last_L_frame == L_FRAME ) - { - /* this is just an approximation, but it is sufficient */ - mvr2r( st->lsp_old1, st->lspold_enc, M ); - } - - analy_lp( inp_16k, L_FRAME16k, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lspold_enc, st->pitch, st->voicing, INT_FS_16k, 0 ); - /*--------------------------------------------------------------* - * Compute Weighted Input - *---------------------------------------------------------------*/ - - find_wsp( L_FRAME16k, L_SUBFR, NB_SUBFR16k, A, Aw, st->speech_enc_pe_flt, PREEMPH_FAC_16k_FLT, st->wspeech_enc_flt, &st->mem_wsp_enc_flt, st->gamma_flt, L_LOOK_16k ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old input signal @16kHz buffer */ - if ( ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) || element_mode == IVAS_CPE_MDCT ) - { - set_f( st->old_inp_16k, 0, L_INP_MEM ); - } - else if ( input_Fs > 8000 && sr_core == INT_FS_16k ) - { - mvr2r( &old_inp_16k[L_frame_tmp], st->old_inp_16k, L_INP_MEM ); - } - else if ( input_Fs > 8000 ) - { - lerp_flt( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 ); - } - - if ( inp16k_out != NULL ) - { - *inp16k_out = inp_16k; - } - - if ( new_inp_resamp16k_out != NULL ) - { - mvr2r( new_inp_resamp16k, new_inp_resamp16k_out, L_FRAME16k ); - } -#else IF( EQ_16( element_mode, IVAS_SCE ) ) { test(); @@ -1600,6 +833,7 @@ ivas_error ivas_compute_core_buffers( { /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); + move16(); Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx, delay ); Copy( signal_in_fx, new_inp_16k_fx + delay, input_frame ); Copy( signal_in_fx + input_frame - shl( delay, 1 ), st->mem_decim16k_fx, shl( delay, 1 ) ); @@ -1622,6 +856,7 @@ ivas_error ivas_compute_core_buffers( { /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ); + move16(); Copy( st->mem_decim16k_fx + delay, new_inp_16k_fx - sub( lMemRecalc, add( delay, L_FILT16k ) ), delay ); Copy( signal_in_fx - lMemRecalc, new_inp_16k_fx - add( lMemRecalc, L_FILT16k ), add( input_frame, lMemRecalc ) ); Copy( signal_in_fx + sub( sub( input_frame, lMemRecalc ), shl( delay, 1 ) ), st->mem_decim16k_fx, shl( delay, 1 ) ); @@ -1632,7 +867,9 @@ ivas_error ivas_compute_core_buffers( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) /*|| st->idchan == 1*/ ) { Word16 length_inp = NS2SA_FX2( input_Fs, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); Word16 length_16k = NS2SA_FX2( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); @@ -1764,6 +1001,7 @@ ivas_error ivas_compute_core_buffers( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); + move16(); PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); } @@ -1844,7 +1082,7 @@ ivas_error ivas_compute_core_buffers( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, &ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); + analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input @@ -1875,64 +1113,24 @@ ivas_error ivas_compute_core_buffers( Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); } - IF( inp16k_out != NULL ) + IF( inp16k_out_fx != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - *inp16k_out = inp_16k; -#endif *inp16k_out_fx = inp_16k_fx; } - IF( new_inp_resamp16k_out != NULL ) + IF( new_inp_resamp16k_out_fx != NULL ) { Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k ); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // No need to do fixed to float for signal_in_fx - st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); - st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); - st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); - st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) - { - *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); - } - - fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); - fixedToFloat_arr( signal_in_fx, signal_in, Q_old_inp_16k, 960 ); - fixedToFloat_arr( new_inp_resamp16k_fx, new_inp_resamp16k, Q_old_inp_16k, L_FRAME16k ); - - if ( new_inp_resamp16k_out != NULL ) - { - fixedToFloat_arr( new_inp_resamp16k_out_fx, new_inp_resamp16k_out, Q_old_inp_16k, L_FRAME16k ); - } - - fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); - fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); - fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel - fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc - - if ( st->hBWE_FD != NULL ) - { - fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - } - - if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + test(); + IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { - for ( Word16 i = 0; i < M + 1; i++ ) + FOR( Word16 i = 0; i < M + 1; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); move32(); } - - fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); } -#endif -#endif return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 4bd981654bb6eff8170e31ad5f61ee09dedd3458..c832021089c59230ab50f23ae893957bc4edc437 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1388,11 +1388,16 @@ ivas_error pre_proc_front_ivas_fx( { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ - +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, q_input, new_inp_out_size ); +#endif Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); +#endif } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -1405,20 +1410,31 @@ ivas_error pre_proc_front_ivas_fx( new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - add( lMemRecalc, length_inp ), length_inp, input_Fs, new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_12k8 - add( lMemRecalc_12k8, length_12k8 ), q_input, new_inp_out_size ); +#endif } new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ - +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, q_input, new_inp_out_size ); +#endif IF( lMemRecalc > 0 ) { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_12k8 + sub( L_FRAME, lMemRecalc_12k8 ), q_input, new_inp_out_size ); +#endif } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); +#endif } ELSE /* DFT stereo */ { @@ -1822,18 +1838,6 @@ ivas_error pre_proc_front_ivas_fx( { #ifdef IVAS_FLOAT_FIXED resetFdCngEnc_fx( st ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - Word16 totalNoiseIncrease_fx = st->hNoiseEst->totalNoise_fx - st->last_totalNoise_fx; - IF( - ( totalNoiseIncrease_fx > 5 * 256 && st->totalNoise_increase_len == TOTALNOISE_HIST_SIZE && st->ini_frame > 150 ) || - ( st->input_bwidth > st->last_input_bwidth ) || - ( st->last_core == AMR_WB_CORE ) ) - { - st->hFdCngEnc->hFdCngCom->init_old_flt = fix16_to_float( st->hFdCngEnc->hFdCngCom->init_old, Q15 ); - move16(); - } -#endif #else resetFdCngEnc( st ); #endif @@ -1888,11 +1892,6 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); st->hFdCngEnc->msNoiseEst_fx_exp = sub( st->hFdCngEnc->msNoiseEst_old_fx_exp, msNoiseEst_Q ); move16(); -#ifdef MSAN_FIX - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); -#else - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); -#endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } @@ -1917,6 +1916,7 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); #else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); +#endif #endif Word16 normmsPeriodog_fx = Q31, zero_flag = 0; move16(); @@ -1925,7 +1925,6 @@ ivas_error pre_proc_front_ivas_fx( IF( zero_flag ) { normmsPeriodog_fx = getScaleFactor32( st->hFdCngEnc->msPeriodog_fx, NPART ); - move16(); } st->hFdCngEnc->msPeriodog_fx_exp_cldfb = sub( 31, normmsPeriodog_fx ); st->hFdCngEnc->msPeriodog_fx_exp_fft = sub( 31, normmsPeriodog_fx ); @@ -1944,16 +1943,16 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig32( st->hFdCngEnc->msNoiseEst_old_fx, NPART, msNoiseEst_Q ); st->hFdCngEnc->msNoiseEst_fx_exp = st->hFdCngEnc->msNoiseEst_old_fx_exp - msNoiseEst_Q; move16(); -#ifdef MSAN_FIX - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); -#else - floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); -#endif - Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; - st->hFdCngEnc->hFdCngCom->init_old = (Word16) ( st->hFdCngEnc->hFdCngCom->init_old_flt * ( 1 << 9 ) ); + zero_flag = get_zero_flag( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + Word16 normmsperiodog = 31; + IF( zero_flag ) + { + normmsperiodog = getScaleFactor32( st->hFdCngEnc->hFdCngCom->periodog, PERIODOGLEN ); + } + st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( 31, normmsperiodog ); st->hFdCngEnc->hFdCngCom->scalingFactor = (Word16) ( st->hFdCngEnc->hFdCngCom->scalingFactor * ( 1 << 30 ) ); -#endif + move16(); + move16(); perform_noise_estimation_enc_ivas_fx( band_energies_fx, band_energies_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); } @@ -2229,11 +2228,6 @@ ivas_error pre_proc_front_ivas_fx( wsp[i] = fixedToFloat( wsp_fx1[i], q_inp_12k8 ); } st->mem_wsp = fixedToFloat( st->mem_wsp_fx, q_inp_12k8 ); - - IF( EQ_16( st->vad_flag, 0 ) ) - { - st->old_corr = (float) ( st->old_corr_fx ); // no Q-factor used here since it's initialised to 0. - } #endif #else @@ -2256,7 +2250,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q_factor_arr( st->old_wsp, L_WSP_MEM ), L_WSP_MEM ); Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; - st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); @@ -2272,7 +2265,6 @@ ivas_error pre_proc_front_ivas_fx( &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); corr_shift = fixedToFloat( corr_shift_fx, Q15 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q_wsp, 115 ); @@ -2801,22 +2793,37 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_old_inp_16k = -1; + floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); + + st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); + st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); + st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); + st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q_old_inp_16k ); + + floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, 880 ); + floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); + floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); + floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + floatToFixed_arr16( st->buf_speech_enc_flt, st->buf_speech_enc, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + floatToFixed_arr16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + floatToFixed_arr16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + // wspeech_enc + + if ( st->hBWE_FD != NULL ) + { + floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); + st->Q_old_wtda = -1; // This reset needs to be looked into + } +#endif #endif /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, -#ifndef IVAS_FLOAT_FIXED - A, Aw, -#else - A_fx, Aw_fx, -#endif - epsP, -#ifndef IVAS_FLOAT_FIXED - lsp_new, lsp_mid -#else - lsp_new_fx, lsp_mid_fx -#endif - ); + error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, &ener_fx, + A_fx, Aw_fx, + epsP_fx, + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r ); if ( error != IVAS_ERR_OK ) { return error; @@ -2826,6 +2833,37 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // No need to do fixed to float for signal_in_fx + st->mem_preemph_enc_flt = fixedToFloat_16( st->mem_preemph_enc, Q_old_inp_16k ); + st->mem_preemph16k = fixedToFloat_16( st->mem_preemph16k_fx, Q_old_inp_16k ); + st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); + st->mem_wsp_enc_flt = fixedToFloat_16( st->mem_wsp_enc, Q_old_inp_16k ); + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + { + *ener = fixedToFloat( ener_fx, Q_r[0] + 1 ); + } + + fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); + fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); + fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); + fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); + fixedToFloat_arr( st->inp_16k_mem_stereo_sw_fx, st->inp_16k_mem_stereo_sw, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + fixedToFloat_arr( st->buf_speech_enc_pe, st->buf_speech_enc_pe_flt, Q_old_inp_16k, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); // Should take care of st->speech_enc_pe as wel + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, Q_old_inp_16k, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); // Should take care of st->wspeech_enc + + if ( st->hBWE_FD != NULL ) + { + fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); + } + + if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) + { + fixedToFloat_arrL( epsP_fx, epsP, Q_r[0] + 1, M + 1 ); + } +#endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_speech_enc; @@ -2970,22 +3008,17 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); floatToFixed_arrL( st->hSpMusClas->tod_lt_Bin_E, st->hSpMusClas->tod_lt_Bin_E_fx, Q_new + Q_SCALE - 2, TOD_NSPEC ); floatToFixed_arr( S_map, S_map_fx, Q7, L_FFT / 2 ); - floatToFixed_arr( st->hSpMusClas->gsc_lt_diff_etot, st->hSpMusClas->gsc_lt_diff_etot_fx, Q8, MAX_LT ); - st->old_corr_fx = float_to_fix16( st->old_corr, Q15 ); floatToFixed_arrL( st->hSpMusClas->finc_prev, st->hSpMusClas->finc_prev_fx, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc_fx = floatToFixed( st->hSpMusClas->lt_finc, 2 * Q_new ); - st->hSpMusClas->mold_corr_fx = float_to_fix16( st->hSpMusClas->mold_corr, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ ivas_smc_mode_selection_fx( st, element_brate, smc_dec, relE_fx, Etot16_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->hSpMusClas->gsc_lt_diff_etot_fx, st->hSpMusClas->gsc_lt_diff_etot, Q8, MAX_LT ); fixedToFloat_arrL( st->hSpMusClas->finc_prev_fx, st->hSpMusClas->finc_prev, 2 * Q_new, ATT_NSEG ); st->hSpMusClas->lt_finc = fixedToFloat( st->hSpMusClas->lt_finc_fx, 2 * Q_new ); fixedToFloat_arrL( st->hSpMusClas->tod_lt_Bin_E_fx, st->hSpMusClas->tod_lt_Bin_E, Q_new + Q_SCALE - 2, TOD_NSPEC ); - st->hSpMusClas->mold_corr = fix16_to_float( st->hSpMusClas->mold_corr_fx, Q15 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS #else diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b31530d9f7f1573abf45893cd40cfbaad9603791..4d18891c48eeee1745739735ea06731fc570a23d 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -284,10 +284,6 @@ ivas_error ivas_cpe_enc_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( sts[0]->hFdCngEnc != NULL ) - { - sts[0]->hFdCngEnc->hFdCngCom->init_old_flt = ( sts[0]->hFdCngEnc->hFdCngCom->init_old == 32767 ) ? FLT_MAX : sts[0]->hFdCngEnc->hFdCngCom->init_old_flt; - } if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) { Word16 Qband = -1; @@ -692,15 +688,10 @@ ivas_error ivas_cpe_enc_fx( floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); - sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); - IF( hCPE->hStereoTD->tdm_last_SM_flag ) { floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); floatToFixed_arr16( sts[1]->input, sts[1]->input_fx, 0, input_frame ); - sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); - sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); } #endif /* Determine the energy ratio between the 2 channels */ @@ -1081,7 +1072,6 @@ ivas_error ivas_cpe_enc_fx( floatToFixed_arr( voicing_fr[1], voicing_fr_fx[1], Q15, NB_SUBFR ); floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, Q15, 3 ); floatToFixed_arr( hCPE->hCoreCoder[1]->voicing, hCPE->hCoreCoder[1]->voicing_fx, Q15, 3 ); - hCPE->hCoreCoder[0]->old_corr_fx = float_to_fix16( hCPE->hCoreCoder[0]->old_corr, Q15 ); #endif tdm_ol_pitch_comparison_fx( hCPE, pitch_fr_fx, voicing_fr_fx ); @@ -1093,7 +1083,6 @@ ivas_error ivas_cpe_enc_fx( fixedToFloat_arr( voicing_fr_fx[1], voicing_fr[1], Q15, NB_SUBFR ); fixedToFloat_arr( hCPE->hCoreCoder[0]->voicing_fx, hCPE->hCoreCoder[0]->voicing, Q15, 3 ); fixedToFloat_arr( hCPE->hCoreCoder[1]->voicing_fx, hCPE->hCoreCoder[1]->voicing, Q15, 3 ); - hCPE->hCoreCoder[1]->old_corr = fix16_to_float( hCPE->hCoreCoder[1]->old_corr_fx, Q15 ); #endif #else tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 7bf6300f9037ed32aafa94df32abf5623a86ab93..e1b06984bfefec9804d3f1b5b27b1ee67bd93e87 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -991,9 +991,6 @@ ivas_error front_vad_spar_fx( floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q8, 3 ); -#ifdef MSAN_FIX - st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); -#endif corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); @@ -1005,7 +1002,6 @@ ivas_error front_vad_spar_fx( fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); fixedToFloat_arr( st->old_wsp2_fx, st->old_wsp2, Q8, 115 ); fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); - st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); #endif /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7d841a9a07899ef78d20258a233491cb5a956ceb..92c5cebc4b2bf9c2d02df96626bc0560f4cf72ab 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -8545,7 +8545,7 @@ static void ivas_encode_masaism_metadata_fx( FOR( obj = 0; obj < nchan_ism; obj++ ) { L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 - L_tmp_e = sub( 30, hOmasaData->energy_ism_fx_e[sf][band] ); + L_tmp_e = add( 1, hOmasaData->energy_ism_fx_e[sf][band] ); energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); move32(); } @@ -8573,7 +8573,7 @@ static void ivas_encode_masaism_metadata_fx( } ELSE { - hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = MAX_32; + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = ONE_IN_Q30; // q30 move32(); } } diff --git a/lib_enc/pitch_ol.c b/lib_enc/pitch_ol.c index 15051574e382285857ae7474526b02e0564beeda..bb2415d0a7c42ae1e4cd1484f9c0da80e4160f53 100644 --- a/lib_enc/pitch_ol.c +++ b/lib_enc/pitch_ol.c @@ -79,6 +79,7 @@ static int16_t pitch_coherence( const int16_t pitch0, const int16_t pitch1, cons static void lp_decim2( const float x[], float y[], const int16_t l, float *mem ); +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * pitch_ol_init * @@ -86,27 +87,20 @@ static void lp_decim2( const float x[], float y[], const int16_t l, float *mem ) *-----------------------------------------------------------------*/ void pitch_ol_init( -#ifndef IVAS_FLOAT_FIXED - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#else - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ -#endif + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ int16_t *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ ) { -#ifndef IVAS_FLOAT_FIXED *old_thres = 0.0f; -#else - *old_thres = 0; -#endif *old_pitch = 0; *delta_pit = 0; *old_corr = 0.0f; return; } +#endif /*-----------------------------------------------------------------* * pitch_ol() diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 27c9e404e44919290479a6bad6323b65254b44f0..a48d3bbd0d6927a286f82821e811e2f736aa89f8 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2852,13 +2852,6 @@ void corr_xh_fx( const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ ); -void corr_xh_ivas_fx( - const Word16 *x, /* i : target signal Q_new - 1 */ - Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ - const Word16 *h, /* i : impulse response (of weighted synthesis filter) e(norm_s(h1[0])+1) */ - const Word16 L_subfr /* i : length of the subframe */ -); - void corr_hh_ivas_fx( const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */ Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */ @@ -2866,7 +2859,7 @@ void corr_hh_ivas_fx( const Word16 L_subfr /* i : length of the subframe */ ); -void corr_xh_ivas_fx2( +void corr_xh_ivas_fx( const Word16 x[], /* i : target signal */ const Word16 Qx, Word16 dn[], /* o : correlation between x[] and h[] */ diff --git a/lib_enc/q_gain2p.c b/lib_enc/q_gain2p.c index 40545d27121c404016f38925290fe7c99656626c..8c18d3ab19253988a6fef7c75fdf00f273eae295 100644 --- a/lib_enc/q_gain2p.c +++ b/lib_enc/q_gain2p.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------------*/ @@ -385,3 +386,4 @@ int16_t gain_enc_gacelp_uv( return index; } +#endif diff --git a/lib_enc/rst_enc.c b/lib_enc/rst_enc.c index 66ea72cc9f4536dcd63b40d0c58ba49497612a3d..2281cefa7d4dff0971d642441839ff5fb49fd133 100644 --- a/lib_enc/rst_enc.c +++ b/lib_enc/rst_enc.c @@ -56,19 +56,21 @@ void CNG_reset_enc( float *voice_factors, /* o : voicing factors */ int16_t VBR_cng_reset_flag ) { - init_gp_clip( st->clip_var ); #ifndef IVAS_FLOAT_FIXED + init_gp_clip( st->clip_var ); mvr2r( UVWB_Ave, st->mem_AR, M ); set_f( st->mem_MA, 0, M ); #else + init_gp_clip_fx( st->clip_var_fx ); Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); set16_fx( st->mem_MA_fx, 0, M ); #endif st->hLPDmem->mem_w0_flt = 0.0f; - st->hLPDmem->tilt_code_flt = 0.0f; #ifndef IVAS_FLOAT_FIXED + st->hLPDmem->tilt_code_flt = 0.0f; st->hLPDmem->gc_threshold_flt = 0.0f; #else + st->hLPDmem->tilt_code = 0; st->hLPDmem->gc_threshold = 0; #endif @@ -76,7 +78,20 @@ void CNG_reset_enc( { set_f( st->hLPDmem->mem_syn_flt, 0, M ); } +#ifndef IVAS_FLOAT_FIXED set_f( st->hLPDmem->dispMem_flt, 0, 8 ); +#else + st->hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st->hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( Word16 i = 2; i < 8; i++ ) + { + st->hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } +#endif /* last good received frame for FEC in ACELP */ st->clas = UNVOICED_CLAS; diff --git a/lib_enc/speech_music_classif.c b/lib_enc/speech_music_classif.c index b8c8f64a07bd1e34850ae3a856b701615cf1244e..1e937bf736b402fc3255fe2a2eee2d94b7f40a8e 100644 --- a/lib_enc/speech_music_classif.c +++ b/lib_enc/speech_music_classif.c @@ -164,16 +164,14 @@ void speech_music_clas_init( hSpMusClas->gsc_thres[1] = TH_1_MIN; hSpMusClas->gsc_thres[2] = TH_2_MIN; hSpMusClas->gsc_thres[3] = TH_3_MIN; -#endif set_f( hSpMusClas->gsc_lt_diff_etot, 0.0f, MAX_LT ); -#ifndef IVAS_FLOAT_FIXED hSpMusClas->gsc_mem_etot = 0.0f; #endif hSpMusClas->gsc_last_music_flag = 0; hSpMusClas->gsc_nb_thr_1 = 0; hSpMusClas->gsc_nb_thr_3 = 0; - hSpMusClas->mold_corr = 0.9f; #ifndef IVAS_FLOAT_FIXED + hSpMusClas->mold_corr = 0.9f; hSpMusClas->mean_avr_dyn = 0.5f; hSpMusClas->last_sw_dyn = 10.0f; #endif @@ -262,7 +260,9 @@ void speech_music_clas_init( #endif set_s( hSpMusClas->lt_corr_pitch, 0, 3 ); hSpMusClas->lt_hangover = 0; +#ifndef IVAS_FLOAT_FIXED hSpMusClas->lowrate_pitchGain_flt = 0; +#endif hSpMusClas->lt_music_hangover = 0; #ifndef IVAS_FLOAT_FIXED diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 51cbc7a7e6a0b73b2fdab7959fa6359779ea1f59..605fbbdbed231efcf3fe120e60eb26b1755842b5 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -525,6 +525,12 @@ typedef struct fd_cng_enc_structure float msPsdSecondMoment[NPART]; float msNoiseFloor[NPART]; /* Estimated noise floor */ float msNoiseEst[NPART]; /* Estimated noise level */ + float msNoiseEst_old[NPART]; + float energy_ho[NPART]; + float msLogPeriodog[NPART]; /* Periodogram */ + float msLogNoiseEst[NPART]; /* Estimated noise level */ + float msPeriodogBuf[MSBUFLEN * NPART]; + float mem_coherence[4]; #endif Word32 msPeriodog_fx[NPART]; /* Periodogram */ Word16 msPeriodog_fx_exp; /* Common exponent for fft and cldfb energies */ @@ -544,24 +550,14 @@ typedef struct fd_cng_enc_structure Word16 msPsdFirstMoment_fx[NPART]; Word32 msPsdSecondMoment_fx[NPART]; Word16 msNoiseFloor_fx[NPART]; /* Estimated noise floor */ -#ifndef IVAS_FLOAT_FIXED - float msNoiseEst_old[NPART]; - float energy_ho[NPART]; - float msLogPeriodog[NPART]; /* Periodogram */ - float msLogNoiseEst[NPART]; /* Estimated noise level */ -#endif - Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ + Word32 msNoiseEst_fx[NPART]; /* Estimated noise level */ Word16 msNoiseEst_fx_exp; Word32 energy_ho_fx[NPART]; Word16 energy_ho_fx_exp; Word32 msNoiseEst_old_fx[NPART]; Word16 msNoiseEst_old_fx_exp; -#ifndef IVAS_FLOAT_FIXED - float msPeriodogBuf[MSBUFLEN * NPART]; -#endif Word16 msPeriodogBuf_fx[MSBUFLEN * NPART]; Word16 msPeriodogBufPtr; - Word16 stopFFTbinDec; Word16 startBandDec; Word16 stopBandDec; @@ -569,15 +565,9 @@ typedef struct fd_cng_enc_structure Word16 midbandDec[NPART]; Word16 nFFTpartDec; Word16 partDec[NPART]; - - Word16 msLogPeriodog_fx[NPART]; Word16 msLogNoiseEst_fx[NPART]; -#ifndef IVAS_FLOAT_FIXED - float mem_coherence[4]; -#else Word32 mem_coherence_fx[4]; -#endif Word16 mem_coherence_exp[4]; } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; @@ -597,7 +587,7 @@ typedef struct dtx_enc_structure #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ #else - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ + Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps Q15 */ #endif Word16 VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ Word16 VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ @@ -606,15 +596,15 @@ typedef struct dtx_enc_structure float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ float frame_ener; #else - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ - Word32 frame_ener_fx; /* Q(-7) */ + Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ + Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ + Word32 frame_ener_fx; /* Q(-7) */ #endif Word16 cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ #ifndef IVAS_FLOAT_FIXED float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ #else - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ + Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ #endif Word16 last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ Word16 var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ @@ -818,7 +808,7 @@ typedef struct sp_mus_clas_structure #ifndef IVAS_FLOAT_FIXED float FV_st[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector */ #else - Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ + Word32 FV_st_fx[N_SMC_FEATURES]; /* Speech/music classifier - short-term mean of the feature vector Q20 */ #endif float past_PS[HIGHEST_FBIN - LOWEST_FBIN]; Word32 past_PS_fx[HIGHEST_FBIN - LOWEST_FBIN]; @@ -828,8 +818,8 @@ typedef struct sp_mus_clas_structure float past_epsP; float past_epsP2; #else - Word16 past_ps_diff_fx; /* Q10 */ - Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ + Word16 past_ps_diff_fx; /* Q10 */ + Word32 prev_FV_fx[N_SMC_FEATURES]; /* Q20 */ Word16 past_epsP_fx; Word16 past_epsP2_fx; /* Q10 */ #endif @@ -866,6 +856,8 @@ typedef struct sp_mus_clas_structure float last_non_sta; float past_log_enr[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ float gsc_thres[4]; /* Speech/music classifier - classification threshold */ + float gsc_lt_diff_etot[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ + float gsc_mem_etot; /* Speech/music classifier - total energy memory */ #else Word32 dlp_mean_LT_fx; /* Q19 */ Word32 dlp_var_LT_fx; /* Q19 */ @@ -874,26 +866,21 @@ typedef struct sp_mus_clas_structure Word16 last_non_sta_fx; /* Q8 */ Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX Q8 */ Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold Q11 */ -#endif - float gsc_lt_diff_etot[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ - Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation Q8 */ -#ifndef IVAS_FLOAT_FIXED - float gsc_mem_etot; /* Speech/music classifier - total energy memory */ -#else + Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation Q8 */ Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory Q8 */ #endif int16_t gsc_last_music_flag; /* Speech/music classifier - last music flag */ int16_t gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ int16_t gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ - float mold_corr; - Word16 mold_corr_fx; /* Q15 */ #ifndef IVAS_FLOAT_FIXED + float mold_corr; float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ float last_sw_dyn; /* Speech/music classifier - last dynamic */ float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ #else + Word16 mold_corr_fx; /* Q15 */ Word16 mean_avr_dyn_fx; /* Speech/music classifier - long term average dynamic Q7 */ Word16 last_sw_dyn_fx; /* Speech/music classifier - last dynamic Q7 */ Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values Q9 */ @@ -1012,8 +999,8 @@ typedef struct sp_mus_clas_structure float LT_sparse; #else Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ - Word16 LT_sparse_fx; /* Q8 */ + Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ + Word16 LT_sparse_fx; /* Q8 */ #endif int16_t gsc_cnt; @@ -1025,20 +1012,20 @@ typedef struct sp_mus_clas_structure float lt_corr_flt; float lt_tonality_flt; #else - Word16 lt_voicing; /* Q15 */ - Word16 lt_corr; /* Q15 */ - Word32 lt_tonality; /* Q15 */ + Word16 lt_voicing; /* Q15 */ + Word16 lt_corr; /* Q15 */ + Word32 lt_tonality; /* Q15 */ #endif int16_t lt_corr_pitch[3]; int16_t lt_hangover; - float lowrate_pitchGain_flt; - Word16 lowrate_pitchGain; /* Q14 */ #ifndef IVAS_FLOAT_FIXED + float lowrate_pitchGain_flt; float tdm_lt_Etot; float var_cor_t[VAR_COR_LEN]; #else - Word16 tdm_lt_Etot_fx; /* Q8 */ - Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ + Word16 lowrate_pitchGain; /* Q14 */ + Word16 tdm_lt_Etot_fx; /* Q8 */ + Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif int16_t high_stable_cor; @@ -1047,9 +1034,9 @@ typedef struct sp_mus_clas_structure float lpm; float lpn; #else - Word16 lps_fx; /* Q7 */ - Word16 lpm_fx; /* Q7 */ - Word16 lpn_fx; /* Q7 */ + Word16 lps_fx; /* Q7 */ + Word16 lpm_fx; /* Q7 */ + Word16 lpn_fx; /* Q7 */ #endif @@ -1090,16 +1077,15 @@ typedef struct lpd_state_structure Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ Word16 mem_syn3[M]; - float tilt_code_flt; - Word16 tilt_code; /* Q15 */ #ifndef IVAS_FLOAT_FIXED + float tilt_code_flt; float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ + float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ #else - Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ + Word16 tilt_code; /* Q15 */ + Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ + struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ #endif - float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ } LPD_state, *LPD_state_HANDLE; @@ -1107,19 +1093,20 @@ typedef struct lpd_state_structure /* Structure for storing correlations between ACELP codebook components and target */ typedef struct acelp_cbkcorr_structure { +#ifndef IVAS_FLOAT_FIXED float xx_flt; /* energy of target x */ float y1y1_flt; /* energy of adaptive cbk contribution y1 */ float y2y2_flt; /* energy of fixed cbk contribution y2 */ float xy1_flt; /* correlation of x and y1 */ float xy2_flt; /* correlation of x and y2 */ float y1y2_flt; /* correlation of y1 and y2 */ - - Word16 xx; /* energy of target x */ - Word16 y1y1; /* energy of adaptive cbk contribution y1 */ - Word16 y2y2; /* energy of fixed cbk contribution y2 */ - Word16 xy1; /* correlation of x and y1 */ - Word16 xy2; /* correlation of x and y2 */ - Word16 y1y2; /* correlation of y1 and y2 */ +#else + Word16 xx; /* energy of target x */ + Word16 y1y1; /* energy of adaptive cbk contribution y1 */ + Word16 y2y2; /* energy of fixed cbk contribution y2 */ + Word16 xy1; /* correlation of x and y1 */ + Word16 xy2; /* correlation of x and y2 */ + Word16 y1y2; /* correlation of y1 and y2 */ Word16 xx_e; /* energy of target x */ Word16 y1y1_e; /* energy of adaptive cbk contribution y1 */ @@ -1127,6 +1114,7 @@ typedef struct acelp_cbkcorr_structure Word16 xy1_e; /* correlation of x and y1 */ Word16 xy2_e; /* correlation of x and y2 */ Word16 y1y2_e; /* correlation of y1 and y2 */ +#endif } ACELP_CbkCorr; @@ -1139,12 +1127,15 @@ typedef struct gsc_enc_structure int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ int16_t mem_last_pit_band; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ +#ifndef IVAS_FLOAT_FIXED float mem_w0_tmp; float mem_syn_tmp[M]; float mid_dyn; /* AC mode (GSC) - signal dynamic */ +#else Word16 mem_w0_tmp_fx; Word16 mem_syn_tmp_fx[M]; - Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ + Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic Q7 */ +#endif int16_t noise_lev; /* AC mode (GSC) - noise level */ int16_t past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ @@ -1153,12 +1144,17 @@ typedef struct gsc_enc_structure float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous exciation */ Word16 Q_last_exc_dct_in; - float last_ener; /* AC mode (GSC) - previous energy */ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ +#ifndef IVAS_FLOAT_FIXED + float last_ener; /* AC mode (GSC) - previous energy */ +#else + Word16 last_ener_fx; /* AC mode (GSC) - previous energy Q0 */ +#endif int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ +#ifndef IVAS_FLOAT_FIXED float lt_gpitch; - - Word16 lt_gpitch_fx; /*Q15 */ +#else + Word16 lt_gpitch_fx; /* Q15 */ +#endif } GSC_ENC_DATA, *GSC_ENC_HANDLE; @@ -1286,10 +1282,13 @@ typedef struct sc_vbr_enc_structure int16_t last_ppp_mode; int16_t last_last_ppp_mode; int16_t ppp_mode; +#ifndef IVAS_FLOAT_FIXED float prev_ppp_gain_pit; float prev_tilt_code; - Word16 prev_ppp_gain_pit_fx; /* Q14 */ - Word16 prev_tilt_code_fx; /* Q15 */ +#else + Word16 prev_ppp_gain_pit_fx; /* Q14 */ + Word16 prev_tilt_code_fx; /* Q15 */ +#endif /* voiced encoder variables */ int16_t firstTime_voicedenc; @@ -2045,11 +2044,12 @@ typedef struct enc_core_structure float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ - float clip_var[6]; /* pitch gain clipping memory */ #ifndef IVAS_FLOAT_FIXED - float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + float clip_var[6]; /* pitch gain clipping memory */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ #else + Word16 clip_var_fx[6]; /* pitch gain clipping memory */ Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ #endif @@ -2071,11 +2071,10 @@ typedef struct enc_core_structure Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 clip_var_fx[6]; - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_deemph_fx; /* deemphasis filter memory */ + Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ int16_t GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; @@ -2115,13 +2114,13 @@ typedef struct enc_core_structure int16_t last_coder_type; /* previous coding type */ #ifndef IVAS_FLOAT_FIXED float old_thres; /* normalized correlation weighting in open-loop pitch */ + float old_corr; /* normalized correlation in previous frame (mean value) */ #else Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ + Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ #endif - float old_corr; /* normalized correlation in previous frame (mean value) */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ - int16_t old_pitch; /* previous pitch for open-loop pitch search */ - int16_t delta_pit; /* open-loop pitch extrapolation correction */ + int16_t old_pitch; /* previous pitch for open-loop pitch search */ + int16_t delta_pit; /* open-loop pitch extrapolation correction */ #ifndef IVAS_FLOAT_FIXED float ee_old; /* previous frame low/high frequency energy ratio */ #else diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index e4e4cb32db7199ac49fec86d26c6fec5edb4faa2..3c673d1382ef1d016a6484914ef72495eb730e3b 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -324,7 +324,6 @@ void swb_bwe_enc_ivas_fx( move32(); #endif Word16 fb_band_begin; - Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -437,11 +436,6 @@ void swb_bwe_enc_ivas_fx( &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); - /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ - sf = L_norm_arr( L_old_input_fx, inner_frame ); - scale_sig32( L_old_input_fx, inner_frame, sf ); - new_input_fx_exp = add( new_input_fx_exp, sf ); // It is Q, not exp - /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); @@ -3188,7 +3182,6 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 inner_frame; Word16 q_shift; Word16 yos_fx_16[L_FRAME_MAX]; - Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3599,12 +3592,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - sf = getScaleFactor32( yos_fx, inner_frame ); - Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, sf ); - mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, sf ), Q16 ), Q_shb, st_fx ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, 0 ); + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( Q_synth, Q16 ), Q_shb, st_fx ); push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, sf ), Q16 ) ); + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( Q_synth_lf, Q16 ) ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { diff --git a/lib_enc/tcq_core_enc.c b/lib_enc/tcq_core_enc.c index c5a5c21e994f1f8333cb7123d5d870d9502fdb36..9ce8750d8db74e4ae9d20468a1a83f25719ce832 100644 --- a/lib_enc/tcq_core_enc.c +++ b/lib_enc/tcq_core_enc.c @@ -49,6 +49,7 @@ * Main Generic Audio Encoder Routine for LR-MDCT *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error tcq_core_LR_enc( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int32_t inp_vector[], @@ -468,3 +469,4 @@ ivas_error tcq_core_LR_enc( return error; } +#endif diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index a703085a88b2f63b5c4ce80754a27d309f6201b3..16499fcfd0608de3e306467a9917dcd972a1089b 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -695,7 +695,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) ); FOR( i = 0; i < n; i++ ) { - tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i], shift ) ); + tmpbuf[i] = round_fx_sat( L_shl( pSpectrum[iStartLine + i], shift ) ); // using round_fx_sat to address corner case move16(); } diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index cd6e48fe239b1abd60ea5c0681c12eff2211ea75..190ce580f67bfd689a1fa02e639d945a57c46fa8 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" #include "prot_fx.h" +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ @@ -970,7 +971,6 @@ static void gain_trans_enc( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * tc_classif_enc() * diff --git a/lib_enc/voiced_enc.c b/lib_enc/voiced_enc.c index 3a0382268c78c65fc641b75eb0c9a749b03efbc9..ab1a9f8b80c3bc8df4b9882bfcd00aa4a0b1e038 100644 --- a/lib_enc/voiced_enc.c +++ b/lib_enc/voiced_enc.c @@ -1130,7 +1130,6 @@ static void SynthesisFilter( return; } -#endif /*---------------------------------------------------------------------* @@ -1160,27 +1159,15 @@ void sc_vbr_enc_init( hSC_VBR->set_ppp_generic = 0; hSC_VBR->Q_to_F = 0; - hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ -#ifndef IVAS_FLOAT_FIXED + hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ hSC_VBR->sum_of_rates = 0.0f; /* sum of the rates of past 600 active frames*/ hSC_VBR->global_avr_rate = 0.0f; /* global rate upto current time. recorded a (rate in kbps) *6000*/ -#else - hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ - move32(); - hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - move32(); -#endif - hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ + hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ hSC_VBR->rate_control = 0; -#ifndef IVAS_FLOAT_FIXED hSC_VBR->SNR_THLD = 67.0f; -#else - hSC_VBR->SNR_THLD_fx = SNR_THLD_FX_Q8; -#endif hSC_VBR->mode_QQF = 1; -#ifndef IVAS_FLOAT_FIXED set_f( hSC_VBR->shape1_filt_mem, 0, 20 ); set_f( hSC_VBR->shape2_filt_mem, 0, 20 ); set_f( hSC_VBR->shape3_filt_mem, 0, 20 ); @@ -1188,15 +1175,6 @@ void sc_vbr_enc_init( set_f( hSC_VBR->txlpf1_filt2_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt1_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt2_mem, 0, 20 ); -#else - set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 20 ); - set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 20 ); -#endif hSC_VBR->last_7k2_coder_type = GENERIC; hSC_VBR->vbr_generic_ho = 0; @@ -1204,3 +1182,4 @@ void sc_vbr_enc_init( return; } +#endif