From 76142da0269cc7a87a04285afb132bc83ac6f8b8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 14:07:12 +0530 Subject: [PATCH] SBA path functions conversion, ASAN and MSAN fixes, cleanup [x] spar process functions/ sub-functions conversion and integration [x] Cleanup of ivas_dirac_param_est_enc function [x] Few ASAN and MSAN fixes [x] Q-info updates for lib_dec and lib_rend files --- lib_com/ivas_fb_mixer.c | 220 ++++++- lib_com/ivas_prot.h | 35 +- lib_com/ivas_prot_fx.h | 20 +- lib_com/ivas_rom_com_fx.c | 106 ++-- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_stat_com.h | 1 + lib_com/prot.h | 24 +- lib_com/prot_fx.h | 311 +++++----- lib_com/rom_com.c | 26 +- lib_com/rom_com_fx.c | 53 ++ lib_dec/er_scale_syn_fx.c | 16 +- lib_dec/er_sync_exc_fx.c | 140 ++--- lib_dec/er_util_fx.c | 102 ++-- lib_dec/hf_synth_fx.c | 591 +++++++++--------- lib_dec/hq_classifier_dec_fx.c | 32 +- lib_dec/hq_conf_fec_fx.c | 24 +- lib_dec/hq_core_dec_fx.c | 236 +++---- lib_dec/hq_env_dec_fx.c | 110 ++-- lib_dec/hq_hr_dec_fx.c | 112 ++-- lib_dec/swb_bwe_dec.c | 67 +- lib_dec/swb_bwe_dec_fx.c | 139 ++--- lib_dec/swb_bwe_dec_hr_fx.c | 105 ++-- lib_dec/swb_bwe_dec_lr_fx.c | 125 ++-- lib_dec/swb_tbe_dec.c | 153 +++-- lib_dec/swb_tbe_dec_fx.c | 153 +++-- lib_dec/syn_outp.c | 3 +- lib_dec/syn_outp_fx.c | 18 +- lib_dec/tcq_core_dec_fx.c | 47 +- lib_dec/tcx_utils_dec_fx.c | 87 ++- lib_dec/tns_base_dec_fx.c | 24 +- lib_enc/ivas_core_enc.c | 19 +- lib_enc/ivas_core_pre_proc_front.c | 3 + lib_enc/ivas_dirac_enc.c | 949 ++++++++++++----------------- lib_enc/ivas_mdct_core_enc.c | 5 + lib_enc/ivas_spar_encoder.c | 119 +++- lib_enc/ivas_spar_md_enc.c | 69 +++ lib_enc/ivas_stat_enc.h | 7 +- lib_enc/swb_pre_proc.c | 2 +- 38 files changed, 2270 insertions(+), 1987 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 9d54f3f0a..5da92e987 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,7 +48,7 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ - +static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED @@ -426,6 +426,21 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + + Word32 *pTemp_mem_fx; + if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); + } + for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + { + hFbMixer->prior_mixer_fx[i][j] = pTemp_mem_fx; + pTemp_mem_fx += IVAS_MAX_NUM_BANDS; + set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } } if ( !spar_reconfig_flag ) @@ -506,6 +521,12 @@ ivas_error ivas_FB_mixer_open( { return error; } + Word16 index[IVAS_MAX_NUM_FB_BANDS]; + set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); + if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + { + return error; + } } *hFbMixer_out = hFbMixer; @@ -1400,7 +1421,162 @@ void ivas_fb_mixer_cross_fading_fx( * * Filter bank process *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +{ + *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); +} +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +) +{ + ivas_filterbank_t *pFb = hFbMixer->pFb; + Word16 num_bands = pFb->filterbank_num_bands; + move16(); + Word16 i, j, k, ch, hist; + + const Word32 *pFilterbank_bin_to_band_re_fx; + const Word32 *pFilterbank_bin_to_band_im_fx; + Word32 *pMdft_out_fx[2]; + Word32 *pOut_fr_re_fx, *pOut_fr_im_fx; + Word16 q_pOut_fr_fx = 31; + move16(); + Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k]; + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; + + pOut_fr_re_fx = Out_fr_re_fx; + pOut_fr_im_fx = Out_fr_im_fx; + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; + + FOR( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ + FOR( hist = 0; hist < 2; hist++ ) + { + set_zero_fx( pOut_fr_re_fx, frame_len ); + set_zero_fx( pOut_fr_im_fx, frame_len ); + q_pOut_fr_fx = 31; + move16(); + FOR( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + { + IF( in_out_mixer_map[ch][j] != 0 ) + { + + Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; + Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + + set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); + set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); + + Word16 total_guard = find_guarded_bits_fx( num_bands ); + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; + move16(); + Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; + move16(); + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + move32(); + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + + FOR( k = start_offset; k < num_bins + start_offset; k++ ) + { + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + move32(); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + move32(); + /*filterbank_mixer_bins_im_fx q 30 */ + /*mixer_const_fx q q_ppOut_pcm_fx */ + pFilterbank_bin_to_band_re_fx++; + pFilterbank_bin_to_band_im_fx++; + } + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + move32(); + } + Word16 res_q = 0; + move16(); + FOR( k = 0; k < frame_len; k++ ) + { + Word32 temp_out_re_fx, temp_out_im_fx; + + Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); + Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_re = pFb_inFR_re_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + move32(); + } + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_im = pFb_inFR_im_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ + move32(); + } + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, + inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); + move16(); + Word16 q_check = s_min( q_pOut_fr_fx, res_q ); + move16(); + IF( NE_16( q_check, q_pOut_fr_fx ) ) + { + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + } + IF( q_check != res_q ) + { + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + } + res_q = q_check; + move16(); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + move32(); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + move32(); + } + q_pOut_fr_fx = res_q; + move16(); + } + } + ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); + } + + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); + q_ppOut_pcm_fx[ch] = q_pOut_fr_fx; + move16(); + } + + return; +} + +#else void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -1415,13 +1591,27 @@ void ivas_fb_mixer_process( const float *pFilterbank_bin_to_band_re; const float *pFilterbank_bin_to_band_im; float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 *pMdft_out_fx[2]; + Word32 **ppOut_pcm_fx = (Word32 **) malloc( hFbMixer->fb_cfg->num_out_chans * sizeof( Word32 * ) ); + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + ppOut_pcm_fx[ch] = (Word32 *) malloc( frame_len * sizeof( Word32 ) ); + } +#endif float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k]; float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2]; - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; +#endif pOut_fr_re = Out_fr_re; pOut_fr_im = Out_fr_im; pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; +#endif for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) { @@ -1476,14 +1666,32 @@ void ivas_fb_mixer_process( ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len ); } - +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q1 = Q_factor_arrL( pMdft_out[0], frame_len * 2 ); + Word16 q2 = Q_factor_arrL( pMdft_out[1], frame_len * 2 ); + Word16 q = s_min( q1, q2 ); + floatToFixed_arrL( pMdft_out[0], pMdft_out_fx[0], q, frame_len * 2 ); + floatToFixed_arrL( pMdft_out[1], pMdft_out_fx[1], q, frame_len * 2 ); +#endif + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( ppOut_pcm_fx[ch], ppOut_pcm[ch], q, frame_len ); +#endif +#endif } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + free( ppOut_pcm_fx[ch] ); + } + free( ppOut_pcm_fx ); +#endif return; } - - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_get_in_out_mapping() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index db7ec4ee2..5e1214c42 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4706,6 +4706,23 @@ int16_t ivas_chan_project_elevation_index( ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag +); +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4720,6 +4737,7 @@ void ivas_dirac_param_est_enc( int16_t *mono_frame_count, int16_t *dirac_mono_flag ); +#endif void ivas_sba_config( @@ -8409,14 +8427,25 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); +#ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ const int16_t frame_len, /* i : frame length in samples */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); - +#else +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float ***mixer_mat, /* i : mixer matrix */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); +#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 07f548f32..121570bc3 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1911,16 +1911,16 @@ void ivas_GenShapedWBExcitation_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ); +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..200c376cb 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,46 +1634,76 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[90] = { - 0, 1509949440, 754974720, 503316480, 377487360, 301989888, - 251658240, 215707056, 188743680, 167772160, 150994944, - 137268128, 125829120, 116149960, 107853528, 100663296, - 94371840, 88820552, 83886080, 79471024, 75497472, - 71902352, 68634064, 65649976, 62914560, 60397976, - 58074980, 55924052, 53926764, 52067224, 50331648, - 48708048, 47185920, 45756044, 44410276, 43141412, - 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, - 32824988, 32126584, 31457280, 30815294, 30198988, - 29606852, 29037490, 28489612, 27962026, 27453626, - 26963382, 26490342, 26033612, 25592364, 25165824, - 24753270, 24354024, 23967452, 23592960, 23229992, - 22878022, 22536558, 22205138, 21883326, 21570706, - 21266894, 20971520, 20684238, 20404722, 20132660, - 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, - 17557552, 17355740, 17158516, 16965724 +const Word32 delta_phi_val[257] = { + 0, + 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, + 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, + 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, + 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, + 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, + 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, + 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, + 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, + 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, + 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, + 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, + 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, + 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, + 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, + 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, + 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, + 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, + 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, + 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, + 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, + 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, + 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, + 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, + 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, + 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, + 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, + 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, + 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, + 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, + 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 }; -const Word32 inv_delta_phi_val[90] = { - 0, 5965232, 11930464, 17895697, 23860929, 29826161, - 35791394, 41756626, 47721858, 53687091, 59652323, - 65617555, 71582788, 77548020, 83513252, 89478485, - 95443717, 101408950, 107374182, 113339414, 119304647, - 125269879, 131235111, 137200344, 143165576, 149130808, - 155096041, 161061273, 167026505, 172991738, 178956970, - 184922203, 190887435, 196852667, 202817900, 208783132, - 214748364, 220713597, 226678829, 232644061, 238609294, - 244574526, 250539758, 256504991, 262470223, 268435456, - 274400688, 280365920, 286331153, 292296385, 298261617, - 304226850, 310192082, 316157314, 322122547, 328087779, - 334053011, 340018244, 345983476, 351948708, 357913941, - 363879173, 369844406, 375809638, 381774870, 387740103, - 393705335, 399670567, 405635800, 411601032, 417566264, - 423531497, 429496729, 435461961, 441427194, 447392426, - 453357659, 459322891, 465288123, 471253356, 477218588, - 483183820, 489149053, 495114285, 501079517, 507044750, - 513009982, 518975214, 524940447, 530905679 +const Word32 inv_delta_phi_val[257] = { + 0, + 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, + 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, + 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, + 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, + 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, + 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, + 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, + 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, + 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, + 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, + 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, + 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, + 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, + 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, + 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, + 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, + 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, + 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, + 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, + 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, + 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, + 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, + 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, + 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, + 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, + 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, + 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, + 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, + 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, + 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, + 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, + 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..6d4f50fa8 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[90]; -extern const Word32 inv_delta_phi_val[90]; +extern const Word32 delta_phi_val[257]; +extern const Word32 inv_delta_phi_val[257]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5fdcf2bc1..a4d1065f4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -871,6 +871,7 @@ typedef struct ivas_fb_mixer_state_structure Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_prior_mixer_fx; #endif /* store sin part in const table (no need to store 1s and 0s, no need to do windowing for 1's and 0's as well) */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d0fc8d2ff..d286851e0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -240,11 +240,13 @@ void mvl2l( const int16_t n /* i : vector size */ ); +#ifndef IVAS_FLOAT_FIXED void AGC_dec( float x[], /* i/o: input/output vector */ float mem[], /* i/o: mem[2] should be init to [0,0] */ const int16_t n /* i : vector size */ ); +#endif /*! r: index of the maximum value in the input vector */ int16_t maximum( @@ -2792,13 +2794,13 @@ void GenTransition( void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t element_mode, /* i : element mode */ - const int16_t L_frame, /* i : ACELP frame length */ - const int16_t rf_flag, /* i : RF flag */ - const int32_t total_brate, /* i : total bitrate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ); void GenTransition_WB( @@ -2808,9 +2810,9 @@ void GenTransition_WB( ); void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const int32_t output_Fs /* i : output sampling rate */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -4923,11 +4925,13 @@ void dec_acelp_4t64( const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#ifndef IVAS_FLOAT_FIXED uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#endif void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1a1b8a81a..da45e5743 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6372,20 +6372,20 @@ void hf_synth_reset_fx( ); void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ); void hf_synth_amr_wb_init_fx( @@ -6400,21 +6400,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ); // dec_post_fx @@ -6518,19 +6518,20 @@ void init_tcx_cfg_fx( // syn_outp_fx.c void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n ); + const Word16 x[], /* i: 16kHz synthesis Qx */ + const Word16 Qx, /* i: scale factor of x */ + Word16 y[], /* o: output vector Q0 */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ + const Word16 n /* i: vector size */ +); // bass_psfilter_fx.c void bass_psfilter_init_fx( @@ -7514,21 +7515,21 @@ void destroy_cldfb_decoder_fx( // swb_bwe_dec_fx.c Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ); - + Word16 *WB_fenv /*Q15*/ +); Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ); @@ -7542,19 +7543,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class const Word16 hqswb_clas /* i : HQ BWE class */ ); -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ); + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); void fd_bwe_dec_init( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7573,11 +7574,11 @@ void hq_core_enc_ivas_fx( // hq_core_dec_fx.c void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ); void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ @@ -7623,24 +7624,24 @@ void hq_lr_dec_fx( ); // gq_env_dec_fx.c -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ); void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ); #ifdef IVAS_FLOAT_FIXED @@ -7690,20 +7691,21 @@ void hdecnrm_tran_fx( // tcq_core_dec_fx.c void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ); + Word16 *inp_vector_fx, /*x5 */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +); // FEC_HQ_core_fx.c void HQ_FEC_processing_fx( @@ -7745,11 +7747,11 @@ void time_domain_FEC_HQ_fx( // hq_hr_dec_fx.c void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7761,7 +7763,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); // hq_classifier_dec_fx.c @@ -7804,12 +7806,12 @@ Word16 hvq_pvq_bitalloc_fx( // hq_conf_fec_fx.c void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ); // core_switching_dec_fx.c @@ -8255,14 +8257,14 @@ void tcxltp_dec_init_fx( const Word32 sr_core ); /* Q0 */ // swb_bwe_dec_hr_fx.c -Word16 swb_bwe_dec_hr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ); void hr_bwe_dec_init( @@ -8517,26 +8519,26 @@ ivas_error decod_ppp_fx( // swb_bwe_dec_lr_fx.c void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ); #ifdef IVAS_FLOAT_FIXED @@ -9291,39 +9293,40 @@ void tcx_arith_decode_envelope_fx( // tcx_utils_dec_fx.c void tcx_decoder_memory_update( - Word16 *xn_buf, /* i: mdct output buffer */ - Word16 *synthout, /* i/o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ); Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ); Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, + Word16 *prm, /*i*/ Word16 resQBits ); Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ +); // er_dec_acelp_fx.c void con_acelp_fx( @@ -10461,24 +10464,24 @@ void v_sub32_fx( ); void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( - Decoder_State *st, /* i/o: decoder state structure */ - Word32 output[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); ivas_error acelp_core_dec_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 450c166cb..9047d8338 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -26312,23 +26312,7 @@ const float lsf_q_cb_3b[8] = 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f }; -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; @@ -26344,16 +26328,8 @@ const float lsf_grid[4][5] = { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } }; -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; -const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; const float allpass_poles_3_ov_2_flt[9] = { diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index a1465dc53..39b94b308 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -6631,3 +6631,56 @@ const Word16 LP_assym_window_16k_fx[L_LP_16k] = { 0x0a40, 0x0a3d, }; + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +/*Q15*/ +const Word16 lsf_q_cb_4b_fx[16] = { + 589, 773, 914, 1043, + 1173, 1302, 1430, 1558, + 1698, 1843, 1973, 2103, + 2258, 2470, 2787, 3282 + +}; + +/*Q15*/ +const Word16 lsf_q_cb_3b_fx[8] = { + 679, 976, 1245, 1491, + 1739, 2011, 2365, 2953 +}; + +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; + +/*Q15*/ +const Word16 lsf_grid_fx[4][5] = { + { + 5242, + 10229, + 15516, + 21804, + 27540, + }, + { + 5117, + 10059, + 14949, + 20478, + 25493, + }, + { + 4648, + 8732, + 13022, + 18247, + 24474, + }, + { + 5052, + 8925, + 12903, + 19427, + 28382, + } +}; + +/*Q15*/ +const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 2e5746ccf..509fd071b 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -57,8 +57,8 @@ Word16 Damping_fact_fx( /* o : damping factor IF( EQ_16( nbLostCmpt, 1 ) ) { /* If stable, do not decrease the energy, pitch gain = 0 */ - /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); + /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ + alpha = add( mult_r( stab_fac, sub( 16384, _ALPHA_U_FX ) ), _ALPHA_U_FX ); /*Q14*/ } ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { @@ -67,7 +67,7 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = mult_r( _ALPHA_U_FX, 16384 ); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 Q14*/ } } ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) @@ -80,12 +80,12 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { - alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ + alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames Q14*/ } IF( GE_16( last_good, VOICED_CLAS ) ) { - lp_tmp = *lp_gainp; + lp_tmp = *lp_gainp; /*Q29*/ move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ @@ -96,7 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; move16(); - gain32 = Sqrt32( lp_tmp, &s_gainp ); + gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/ #ifdef BASOP_NOGLOB gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ @@ -110,7 +110,7 @@ Word16 Damping_fact_fx( /* o : damping factor ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { /*0.6 + 0.35*stab_fac*/ - alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); + alpha = mult_r( mac_r( 1288490240l /*0.6f Q31*/, 11469 /*0.35f Q15*/, stab_fac ), round_fx( L_shl( lp_tmp, 1 ) ) ); /*Q14*/ } ELSE { @@ -118,7 +118,7 @@ Word16 Damping_fact_fx( /* o : damping factor lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } - *lp_gainp = lp_tmp; /*store*/ + *lp_gainp = lp_tmp; /*store Q29*/ move32(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 268476821..ac04d048c 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -36,9 +36,9 @@ static Word16 GetMinimumPosition_fx( move16(); #endif - filterLength = s_min( filterLength, length ); - center = shr( filterLength, 1 ); - iMinEnergyPos = center; + filterLength = s_min( filterLength, length ); /*Q0*/ + center = shr( filterLength, 1 ); /*Q0*/ + iMinEnergyPos = center; /*Q0*/ move16(); IF( filterLength > 0 ) @@ -47,22 +47,22 @@ static Word16 GetMinimumPosition_fx( energy = L_deposit_l( 0 ); energy_old = L_deposit_l( 0 ); - cnt = sub( length, filterLength ); + cnt = sub( length, filterLength ); /*Q0*/ tmp_e = 0; move16(); FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr( x[i], tmp_e ); + tmp16 = shr( x[i], tmp_e ); /*Qx*/ #ifdef BASOP_NOGLOB - energy = L_msu_sat( energy_old, tmp16, tmp16 ); + energy = L_msu_sat( energy_old, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ + tmp16 = shr( x[( i + filterLength )], tmp_e ); /*Qx*/ + BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB - energy = L_mac_sat( energy, tmp16, tmp16 ); + energy = L_mac_sat( energy, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_mac( energy, tmp16, tmp16 ); #endif @@ -71,7 +71,7 @@ static Word16 GetMinimumPosition_fx( /*if (energy == MAXVAL_WORD32)*/ BASOP_SATURATE_WARNING_OFF_EVS /*saturates if energy < 0*/ #ifdef BASOP_NOGLOB - tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); + tmptest = L_sub_o( energy, MAXVAL_WORD32, &Overflow ); /*Q31*/ #else tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif @@ -80,15 +80,15 @@ static Word16 GetMinimumPosition_fx( { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); - tmp16 = shr( x[i], tmp_e ); - energy = L_msu( energy, tmp16, tmp16 ); - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - energy = L_mac( energy, tmp16, tmp16 ); + tmp16 = shr( x[i], tmp_e ); /*Qx-1*/ + energy = L_msu( energy, tmp16, tmp16 ); /*2Qx-1*/ + tmp16 = shr( x[( i - filterLength )], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); /*2Qx-1*/ } IF( energy < 0 ) { - iMinEnergyPos = add( i, center ); + iMinEnergyPos = add( i, center ); /*Q0*/ tmp_e = 0; move16(); energy = 0; @@ -98,7 +98,7 @@ static Word16 GetMinimumPosition_fx( } } - return iMinEnergyPos; + return iMinEnergyPos; /*Q0*/ } /*! @@ -108,7 +108,7 @@ static Word16 GetMinimumPosition_fx( */ static Word16 FindMaxPeak_fx( - Word16 /*float*/ const *x, /* 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } /* Add some samples */ - ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); /*Qx*/ FOR( j = 0; j < points_by_pos[i]; j++ ) { - *pt_dest++ = ftmp; + *pt_dest++ = ftmp; /*Qx*/ move16(); - ftmp = negate( ftmp ); + ftmp = negate( ftmp ); /*Qx*/ } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } } @@ -192,30 +192,30 @@ static void RemoveSamples_fx( Word16 /*int*/ last_min_pos, i, j; - pt_dest = new_exc + L_frame; - last_min_pos = sub( L_frame, n_samples_to_add ); + pt_dest = new_exc + L_frame; /*Qx*/ + last_min_pos = sub( L_frame, n_samples_to_add ); /*Q0*/ FOR( i = sub( nb_min, 1 ); i >= 0; i-- ) { /* Compute len to copy */ /* Copy section, removing some samples */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = last_min_pos; j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } } @@ -258,7 +258,7 @@ void PulseResynchronization_fx( test(); IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy( src_exc, dst_exc, nFrameLength ); + Copy( src_exc, dst_exc, nFrameLength ); /*Q15*/ } return; } @@ -282,7 +282,7 @@ void PulseResynchronization_fx( tmp16 = shl( tmp16, tmp_e ); /*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ tmp_e = sub( 15, tmp_e ); tmp16 = Inv16( tmp16, &tmp_e ); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub( pitchEnd, pitchStart ); + tmp32 = L_sub( pitchEnd, pitchStart ); /*Q16*/ tmp2_e = norm_l( tmp32 ); tmp32 = L_shl( tmp32, tmp2_e ); /*Q16,-tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ @@ -290,7 +290,7 @@ void PulseResynchronization_fx( tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ tmp2_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp2_e ); + tmp16 = shl( tmp16, tmp2_e ); /*Q0+tmp2_e*/ tmp32 = Mpy_32_16_1( tmp32, tmp16 ); /*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ tmp_e = sub( sub( tmp_e, tmp2_e ), 1 ); /* sum up all the scalings for tmp32 */ @@ -298,7 +298,7 @@ void PulseResynchronization_fx( /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ tmp2_e = norm_l( pitchStart ); - tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = L_shl( pitchStart, tmp2_e ); /*Q16+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q16,-tmp2_e*/, freqStart /*Q15,freqStart_e*/ ); /*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ tmp16 = norm_l( tmp32_a ); tmp32_a = L_shl( tmp32_a, tmp16 ); @@ -314,7 +314,7 @@ void PulseResynchronization_fx( tmp32_a = L_add( L_shl( 1, sub( 31, tmp3_e ) ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ #endif tmp2_e = norm_s( nFrameLength ); - tmp16_a = shl( nFrameLength, tmp2_e ); + tmp16_a = shl( nFrameLength, tmp2_e ); /*Q0+tmp2_e*/ tmp32_a = Mpy_32_16_1( tmp32_a /*Q31,tmp3_e*/, tmp16_a /*Q0,-tmp2_e*/ ); /*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ tmp2_e = add( sub( tmp3_e, tmp2_e ), 15 ); samplesDelta = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, L_negate( tmp32_a ), tmp2_e, &samplesDelta_e ); /*Q31,samplesDelta_e*/ @@ -346,7 +346,7 @@ void PulseResynchronization_fx( tmp32 = L_shl( tmp32, tmp2_e ); tmp_e = sub( tmp_e, tmp2_e ); /*tmp32 = Q31,tmp_e*/ tmp2_e = norm_l( absPitchDiff ); - tmp32_b = L_shl( absPitchDiff, tmp2_e ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); /*Q16+tmp2_e*/ tmp_e = sub( tmp_e, tmp2_e ); tmp32 = Mpy_32_16_1( tmp32_b, round_fx( tmp32 ) ); /*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ tmp32_a = Mpy_32_16_1( L_abs( samplesDelta ) /*Q31,samplesDelta_e*/, roundedPitchStart /*Q0*/ ); /*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ @@ -412,33 +412,33 @@ void PulseResynchronization_fx( /* Make sure that the number of samples increases */ IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { - iDeltaSamples[i] = roundedCycleDelta; + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i - 1] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i - 1] = roundedCycleDelta; /*Q0*/ move16(); } ELSE { - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[( k + 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( k, 1 )] ); /*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[( k + 1 )] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ /*iMinPos1 = T0+GetMinimumPosition_fx(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ BASOP_Util_Divide_MantExp( add( nSubframes, 1 ), 15, nSubframes, 15, &tmp16, &tmp_e ); tmp32 = L_mult( nFrameLength /*Q0*/, tmp16 /*Q15,tmp_e*/ ); /*Q16,tmp_e*/ - tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); - tmp16 = sub( tmp16, T0 ); + tmp16 = round_fx( L_shl( tmp32, tmp_e ) ); /*Q0*/ + tmp16 = sub( tmp16, T0 ); /*Q0*/ tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( @@ -455,26 +455,26 @@ void PulseResynchronization_fx( IF( GT_16( iMinPos1, add( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ) ) { - iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); + iMinPos[0] = sub( iMinPos1, sub( roundedPitchStart, shr( iDeltaSamples[0], 1 ) ) ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); + iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); + iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( k, 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[( k + 1 )], shr( iDeltaSamples[( k + 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); + iMinPos[( k + 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[( k + 1 )], 1 ) ) ); /*Q0*/ move16(); } ELSE @@ -482,18 +482,18 @@ void PulseResynchronization_fx( /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); - iMinPos[add( k, 1 )] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[( k + 1 )], 1 ) ); + iMinPos[( k + 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + iDeltaSamples[( k + 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[( k + 1 )] ) ); /*Q0*/ move16(); } @@ -505,43 +505,43 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy before the first pulse */ IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub( iMinPos1, roundedPitchStart ); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = iMinPos1; + iMinPos[i] = iMinPos1; /*Q0*/ move16(); - iMinPos1 = add( iMinPos1, roundedPitchStart ); + iMinPos1 = add( iMinPos1, roundedPitchStart ); /*Q0*/ } /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = iMinPos1; + iMinPos[( k + 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[add( k, 1 )] = tmp16; + iMinPos[( k + 1 )] = tmp16; /*Q0*/ move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); + iDeltaSamples[( k + 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[( k + 1 )] ); /*Q0*/ move16(); } /* Add samples at the given positions */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index cc6a53cd2..c2c766d9e 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -61,7 +61,7 @@ void minimumStatistics_fx( #endif { BASOP_SATURATE_WARNING_ON_EVS - currentFrameLevel = PLC_MIN_CNG_LEV; + currentFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); currentFrameLevel_e = 0; move16(); @@ -73,13 +73,13 @@ void minimumStatistics_fx( IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( noiseEstimate_e, *lastFrameLevel_e ) ); } ELSE { /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ @@ -90,7 +90,7 @@ void minimumStatistics_fx( move16(); } - *lastFrameLevel = currentFrameLevel; + *lastFrameLevel = currentFrameLevel; /*Qx*/ move16(); *lastFrameLevel_e = currentFrameLevel_e; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( move16(); if ( tmp == 0 ) { - tmp = PLC_MIN_STAT_BUFF_SIZE; + tmp = PLC_MIN_STAT_BUFF_SIZE; /*Q0*/ move16(); } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ @@ -128,7 +128,7 @@ void minimumStatistics_fx( assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ - p = *noiseLevelIndex; + p = *noiseLevelIndex; /*Q0*/ move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); IF( tmp >= 0 ) @@ -137,7 +137,7 @@ void minimumStatistics_fx( /*rescale noiseLevelMemory*/ setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); - p = *currLevelIndex; + p = *currLevelIndex; /*Q0*/ move16(); } ELSE @@ -147,7 +147,7 @@ void minimumStatistics_fx( /* current min is not a new min, so check if min must be re-searched */ IF( NE_16( p, *currLevelIndex ) ) { - f = noiseLevelMemory[p]; /* min is still in memory, so return it */ + f = noiseLevelMemory[p]; /* min is still in memory, so return it Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -164,7 +164,7 @@ void minimumStatistics_fx( move16(); } } - f = noiseLevelMemory[p]; + f = noiseLevelMemory[p]; /*Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -172,10 +172,10 @@ void minimumStatistics_fx( } /* update local-minimum-value index and current circular-buffer index */ - *noiseLevelIndex = p; + *noiseLevelIndex = p; /*Q0*/ move16(); p = add( *currLevelIndex, 1 ); - *currLevelIndex = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); /*Q0*/ move16(); if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { @@ -183,7 +183,7 @@ void minimumStatistics_fx( move16(); } - *noiseEstimate = f; + *noiseEstimate = f; /*Qx*/ move16(); } @@ -226,15 +226,15 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub( 15, norm_s( lenLpcExc ) ); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); /*Q0*/ Q_h1 = s_max( sub( Q_h1, Hr16 ), 0 ); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); + tmp16 = shr( 32768 / 2, sub( Hr16, 1 ) ); /*Q15*/ /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r( h1Init[0], tmp16 ); + h1Init[0] = mult_r( h1Init[0], tmp16 ); /*Q15*/ move16(); FOR( loop = 0; loop < numLoops; loop++ ) @@ -242,7 +242,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ set16_fx( h1, 0, lenLpcExc ); set16_fx( mem, 0, lpcorder ); - Copy( h1Init, h1, 1 ); + Copy( h1Init, h1, 1 ); /*Q15*/ /*h1 will be scaled down, Q_h1 */ E_UTIL_synthesis( Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder ); deemph_fx( h1, preemph_fac, lenLpcExc, &tmp ); @@ -250,10 +250,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); /*Q31 - s16*/ s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31 - s16*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ @@ -262,14 +262,14 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s( 1, numLoops ); + tmp16 = div_s( 1, numLoops ); /*Q15*/ } levelSynDeemph = L_add( levelSynDeemph, L_shl( Mpy_32_16_1( levelSynDeemphSub, tmp16 ), sub( s16, 10 ) ) ); /*10Q21*/ } s16 = norm_l( levelSynDeemph ); - levelSynDeemph = L_shl( levelSynDeemph, s16 ); - *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + levelSynDeemph = L_shl( levelSynDeemph, s16 ); /*Q31*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ move16(); #ifdef BASOP_NOGLOB @@ -281,10 +281,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* BASOP version: up to date with rev 7422 */ void genPlcFiltBWAdap_fx( - const Word32 sr_core, /* i : core sampling rate */ - Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc */ - const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass */ - const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt */ + const Word32 sr_core, /* i : core sampling rate Q0*/ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc Q15*/ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass Q0*/ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt Q15*/ ) { Word16 a, b, exp; @@ -305,17 +305,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 13107 /*0.4000f Q15*/, alpha ); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -332,17 +332,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 9218 /*0.2813f Q15*/, alpha ); + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -355,11 +355,11 @@ void genPlcFiltBWAdap_fx( *-----------------------------------------------------------------*/ /*VERSIONINFO: This port is up to date with trunk rev. 32434*/ void highPassFiltering_fx( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ + const Word16 last_good, /* i: short last classification type Q0*/ + const Word16 L_buffer, /* i: int buffer length Q0*/ Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer ) /* i: high pass filter length */ + const Word16 l_fir_fer ) /* i: high pass filter length Q0*/ { Word16 i; /*int*/ @@ -368,7 +368,7 @@ void highPassFiltering_fx( { FOR( i = 0; i < L_buffer; i++ ) { - exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); + exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); /*Qx*/ move16(); } } @@ -391,9 +391,9 @@ Word16 GetPLCModeDecision_ivas_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -430,7 +430,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); if ( GT_16( st->nbLostCmpt, 1 ) ) { - core = st->last_core_bfi; + core = st->last_core_bfi; /*Q0*/ move16(); } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_ivas_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) @@ -503,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( } } } - return core; + return core; /*Q0*/ } #endif @@ -523,9 +523,9 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -594,7 +594,7 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - pitch = L_add( st->old_fpitch, 0 ); + pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } IF( st->element_mode == EVS_MONO ) { diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 21989d052..9af04d1f2 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -90,20 +90,20 @@ void hf_synth_reset_fx( *---------------------------------------------------------------------*/ void hf_synth_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc */ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2 */ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { const Word16 *p_Aq; @@ -112,13 +112,13 @@ void hf_synth_fx( output_subfr = output_frame / NB_SUBFR; move16(); - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); - p_Aq += ( M + 1 ); + p_Aq += ( M + 1 ); /* Q12 */ } return; @@ -176,19 +176,19 @@ void hf_synth_ivas_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn*/ Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { Word16 i; @@ -219,22 +219,22 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */ exp2 = sub( exp2, add( Q_exc, Q_exc ) ); /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); - tmp = round_fx( L_tmp ); + tmp = round_fx( L_tmp ); /* Q15 */ /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); - tmp = shl( tmp, scale ); + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ exp1 = sub( exp1, scale ); - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp1 ); scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ @@ -256,11 +256,11 @@ static void hf_synthesis_fx( /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 1; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif @@ -269,11 +269,11 @@ static void hf_synthesis_fx( ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - L_tmp = L_mac( 1L, synth[1], synth[0] ); + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ FOR( i = 2; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif @@ -287,7 +287,7 @@ static void hf_synthesis_fx( tmp = s_max( 0, tmp ); if ( tmp > 0 ) { - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -296,7 +296,7 @@ static void hf_synthesis_fx( /* tmp = 1.0 - fac */ #ifdef BASOP_NOGLOB - tmp = add_o( 1, sub( 32767, tmp ), &Overflow ); + tmp = add_o( 1, sub( 32767 /* 1 in Q15 */, tmp ), &Overflow ); #else tmp = add( 1, sub( 32767, tmp ) ); #endif @@ -306,7 +306,7 @@ static void hf_synthesis_fx( /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o( tmp, tmp, &Overflow ); + tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */ #else tmp = add( tmp, tmp ); #endif @@ -347,10 +347,10 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); /* Q_syn+exp1 */ + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); /* Q_syn+exp1 */ + Copy( delay_syn_hf, HF_syn, delay ); /* Q_syn */ + Copy( temp_buffer, delay_syn_hf, delay ); /* Q_syn */ /* interpolate the HF synthesis */ IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ @@ -360,12 +360,12 @@ static void hf_synthesis_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } @@ -374,17 +374,17 @@ static void hf_synthesis_fx( { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); @@ -630,11 +630,11 @@ static void hf_synthesis_ivas_fx( * (gain=4.0) *-------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -647,8 +647,8 @@ static void filt_6k_7k_scale_fx( FOR( i = 0; i < lg; i++ ) { - x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); - move16(); /* gain of filter = 4 */ + x[i + L_FIR - 1] = shr( mult( signal[i], fact ), 2 ); /* Qx - 2 */ + move16(); /* gain of filter = 4 */ } FOR( i = 0; i < lg; i++ ) { @@ -659,20 +659,20 @@ static void filt_6k_7k_scale_fx( FOR( j = 0; j < 31; j++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); + L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); /* Q16 */ #else L_tmp = L_mac( L_tmp, x[i + j], fir_6k_7k_fx[j] ); #endif } #ifdef BASOP_NOGLOB - signal[i] = round_fx_o( L_tmp, &Overflow ); + signal[i] = round_fx_o( L_tmp, &Overflow ); /* Q0 */ move16(); #else signal[i] = round_fx( L_tmp ); #endif } - Copy( x + lg, mem, L_FIR - 1 ); + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ } /*-------------------------------------------------------------------* @@ -694,7 +694,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -702,7 +702,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -710,7 +710,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ ; return; } @@ -746,7 +746,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -754,7 +754,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -762,7 +762,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ return; } @@ -776,21 +776,21 @@ void hf_synth_amr_wb_reset_fx( void hf_synth_amr_wb_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : Q_syn2-1 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + const Word16 *hf_gain, /* i : decoded HF gain Q0*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 Q_exc, /* i : exc scaling */ + const Word16 Q_out /* i : Q_syn2-1 */ ) { Word16 core_type = 1; @@ -824,11 +824,12 @@ void hf_synth_amr_wb_fx( Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; Word16 gamma; + move16(); - Scale_sig( synth, L_FRAME, -3 ); + Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */ - pt1 = synth + 1; - pt2 = synth; + pt1 = synth + 1; /* Q_syn - 3 */ + pt2 = synth; /* Q_syn - 3 */ pt3 = til; pt4 = til0; FOR( i = 0; i < NB_SUBFR; i++ ) @@ -836,9 +837,9 @@ void hf_synth_amr_wb_fx( enr1 = Dot_product( pt2, pt2, L_SUBFR ); /*2*(Q_syn-3)+1 */ enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */ - tmp1 = extract_h( enr1 ); + tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */ tmp1 = s_max( 1, tmp1 ); - tmp2 = extract_h( enr2 ); + tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */ exp = norm_s( tmp1 ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ @@ -852,7 +853,7 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr( output_frame, 2 ); + output_subfr = shr( output_frame, 2 ); /* Q0 */ if ( NE_16( *amr_io_class, 7 ) ) { @@ -863,8 +864,8 @@ void hf_synth_amr_wb_fx( /* modify LF parameters for excitation weighting or sub-frame gains calculating */ pitch_var_cur = 0; move16(); - pt6 = pitch_buf; - pt7 = pitch_buf + 1; + pt6 = pitch_buf; /* Q5 */ + pt7 = pitch_buf + 1; /* Q5 */ FOR( i = 0; i < 3; i++ ) { tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ @@ -874,41 +875,41 @@ void hf_synth_amr_wb_fx( IF( GT_16( hAmrwb_IO->frame_count_fx, FRAME_COUNT_HF_SYNTH ) && *amr_io_class == UNVOICED_CLAS ) { hAmrwb_IO->frame_count_fx = 0; - hAmrwb_IO->ne_min_fx = -7680; + hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */ move16(); move16(); /*Q8; */ } ELSE { - hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */ move16(); - hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */ move16(); - hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */ move16(); } pt6 = voice_factors; - L_tmp = L_mult( *pt6++, 4096 ); + L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac( L_tmp, *pt6++, 4096 ); + L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ } - voice_fac = round_fx( L_tmp ); + voice_fac = round_fx( L_tmp ); /* Q14 */ /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - fmerit_w = s_min( fmerit, 5734 ); - fmerit_w = s_max( fmerit_w, 2458 ); + fmerit_w = s_min( fmerit, 5734 /* 0.35 IN Q14 */ ); /* Q14 */ + fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */ if ( EQ_16( core_type, 1 ) ) { - fmerit_w = shr( fmerit_w, 1 ); /*Q14; */ + fmerit_w = shr( fmerit_w, 1 ); /* Q14 */ } #ifdef BASOP_NOGLOB - L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); + L_tmp = L_mult( fmerit_w, add_sat( 16384, voice_fac ) ); /* Q14 */ #else L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif @@ -920,17 +921,17 @@ void hf_synth_amr_wb_fx( move16(); - tmp1 = fmerit; + tmp1 = fmerit; /* Q14 */ move16(); - if ( LT_16( fmerit, 8192 ) ) + if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) ) { - tmp1 = 16384; + tmp1 = 16384; /* 1.0f in Q14 */ move16(); } fmerit_m = negate( add( -32768, tmp1 ) ); hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ move16(); - fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */ move16(); pt1 = til; @@ -940,15 +941,15 @@ void hf_synth_amr_wb_fx( tmp = s_and( tmp, *pt1 ); if ( tmp < 0 ) { - *pt1 = 1638; + *pt1 = 1638; /* 0.2 in Q13 */ move16(); } - tmp1 = sub( 8192, *pt1 ); - *pt1 = s_max( 6554, tmp1 ); + tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 ); /* Q13 */ + *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */ move16(); - tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ - tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ *pt1 = add( *pt1, tmp1 ); move16(); /*Q13 */ @@ -979,19 +980,19 @@ void hf_synth_amr_wb_fx( q_tmp = Exp16Array( L_FRAME, exc ); qdct = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */ qdct = add( qdct, Q_exc ); edct_fx( exc32, dct_exc32, L_FRAME, &qdct ); q_tmp = Exp32Array( L_FRAME, dct_exc32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */ qdct = add( qdct, q_tmp ); set16_fx( dct_hb, 0, L_FRAME16k ); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; + pt1 = &dct_hb[200]; /* qdct */ + pt2 = &dct_exc[200]; /* qdct */ FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; @@ -1014,10 +1015,10 @@ void hf_synth_amr_wb_fx( } hb_ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k ); - L_tmp = L_shl( L_mult( start_band, 205 ), 14 ); /*Q30 */ - tmp = round_fx( L_tmp ); /*Q14 */ - tmp = sub( 18022, tmp ); /*Q14 */ - fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ + L_tmp = L_shl( L_mult( start_band, 205 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022 /* 1.1f in Q14 */, tmp ); /*Q14 */ + fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ @@ -1027,15 +1028,15 @@ void hf_synth_amr_wb_fx( alpha = div_s( shl( 1, sub( 14, q2 ) ), tmp ); /*Q(29-q2-8); */ alpha = shl( alpha, sub( q2, 7 ) ); /*Q14 */ - beta = sub( 16384, fmerit_w ); /*Q14 */ + beta = sub( 16384 /* 1.0f in Q14 */, fmerit_w ); /*Q14 */ - L_tmp = L_mult( alpha, 31130 ); /*Q30 */ - gamma = round_fx( L_tmp ); /*Q14 */ - gamma = sub( 17203, gamma ); /*Q14 */ - gamma = s_min( 16384, gamma ); - gamma = s_max( 4915, gamma ); + L_tmp = L_mult( alpha, 31130 /* 0.95f in Q15 */ ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203 /* 1.05f in Q14 */, gamma ); /*Q14 */ + gamma = s_min( 16384 /* 1.0f in Q14 */, gamma ); /* Q14 */ + gamma = s_max( 4915 /* 0.3f in Q14 */, gamma ); /* Q14 */ - IF( LT_16( beta, 16384 ) ) + IF( LT_16( beta, 16384 /* 1 in Q14 */ ) ) { L_tmp = 1; /*variable for tonal energy*/ move32(); @@ -1045,7 +1046,7 @@ void hf_synth_amr_wb_fx( pt3 = &dct_hb[240]; FOR( i = 0; i < 8; i++ ) { - fn = add( i, 8 ); + fn = add( i, 8 ); /* Q0 */ tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); @@ -1060,11 +1061,11 @@ void hf_synth_amr_wb_fx( } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ move16(); - *pt2 = sub( *pt3, *pt1 ); + *pt2 = sub( *pt3, *pt1 ); /* qdct */ move16(); IF( *pt2 > 0 ) { - L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ } pt1++; pt2++; @@ -1072,8 +1073,8 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub( i, 7 ); - fn = add( fb, 15 ); + fb = sub( i, 7 ); /* Q0 */ + fn = add( fb, 15 ); /* Q0 */ tmp = 0; move16(); pt4 = &dct_hb[fb + 240]; @@ -1092,7 +1093,7 @@ void hf_synth_amr_wb_fx( IF( *pt2 > 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); + L_tmp = L_mac0_sat( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); /*2*qdct-2 */ #else L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif @@ -1103,11 +1104,11 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k; i++ ) { - fb = sub( i, 7 ); + fb = sub( i, 7 ); /* Q0 */ tmp = 0; move16(); - fn = sub( L_SUBFR16k, fb ); - tmp1 = div_s( 1, fn ); /*Q15 */ + fn = sub( L_SUBFR16k, fb ); /* Q0 */ + tmp1 = div_s( 1, fn ); /*Q15 */ pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < L_SUBFR16k; j++ ) { @@ -1172,11 +1173,11 @@ void hf_synth_amr_wb_fx( pt4++; } - ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); - scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ - L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ - scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ + ener = dot_prod_satcontr( &dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k ); /* q2 */ + scale = div_s( shl( 1, 14 ), hb_ener ); /*Q(29-q1) */ + L_tmp = L_mult( ener, scale ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ + scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_mult( scale, gamma ), 4 ) ); /*Q15 */ #else @@ -1191,23 +1192,23 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_6k60 ) ) { - filt_weight_coeff = 60; + filt_weight_coeff = 60; /* Q0 */ move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { - filt_weight_coeff = 40; + filt_weight_coeff = 40; /* Q0 */ move16(); - rev_filt_weight_coeff = 840; + rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } ELSE { - filt_weight_coeff = 20; + filt_weight_coeff = 20; /* Q0 */ move16(); - rev_filt_weight_coeff = 1725; + rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } @@ -1223,7 +1224,7 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_23k85 ) ) { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { @@ -1252,21 +1253,21 @@ void hf_synth_amr_wb_fx( { tmp = *pt6++; move16(); - *pt1++ = HP_gain_fx[tmp]; + *pt1++ = HP_gain_fx[tmp]; /* Q15 */ move16(); } } ELSE { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { *pt1 = mult_r( *pt1, scale ); /*qdct */ IF( GT_16( i, 255 ) ) { - *pt1 = mult_r( 19505, *pt1 ); + *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 ); move16(); } @@ -1281,25 +1282,25 @@ void hf_synth_amr_wb_fx( pt1 = dct_hb + 200; pt6 = filt_hp_fx; - pt7 = deem_tab_fx; + pt7 = deem_tab_fx; /* Q15 */ FOR( i = 200; i < 256; i++ ) { *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ *pt1 = mult_r( *pt7++, *pt1 ); - move16(); + move16(); /* qdct */ pt1++; } } q_tmp = Exp16Array( L_FRAME16k, dct_hb ); qhf = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */ qhf = add( qhf, qdct ); edct_fx( dct_hb32, exc16k32, L_FRAME16k, &qhf ); q_tmp = Exp32Array( L_FRAME16k, exc16k32 ); q_tmp = sub( q_tmp, 16 ); - Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */ qhf = add( qhf, q_tmp ); ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); @@ -1383,19 +1384,19 @@ void hf_synth_amr_wb_fx( return; } static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ + const Word32 core_brate, /* i : core bitrate : Q0*/ + const Word16 output_subfr, /* i : output sub-frame length : Q0*/ + const Word16 Ap[], /* i : quantized Aq : Q12*/ + Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ + Word16 synth_out[], /* i/o: synthesis signal at output Fs : Q_out*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + Word16 p_r, /* i : sub-frame gain : Q12*/ + Word16 HF_corr_gain, /* i : HF gain index : Q14*/ + Word16 til, /* Q14 */ + Word16 voice_factors, /* Q14 */ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -1412,7 +1413,7 @@ static void hf_synthesis_amr_wb_fx( ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); tmp = dot_prod_satcontr( exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k ); - L_tmp = L_mult( ener, 6554 ); /*Q(q1+16) */ + L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*Q(q1+16) */ q3 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q3 ); /*Q(q1+q3+16) */ ener = extract_h( L_tmp ); /*Q(q1+q3); */ @@ -1463,14 +1464,14 @@ static void hf_synthesis_amr_wb_fx( scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif flag = negate( s_and( til, -0x8000 ) ); - if ( GT_16( scale, 4096 ) ) + if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) ) { flag = 1; move16(); } IF( flag ) { - Copy( exc2385, exc16k, L_SUBFR16k ); + Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */ } ELSE { @@ -1478,10 +1479,10 @@ static void hf_synthesis_amr_wb_fx( pt2 = exc2385; FOR( i = 0; i < L_SUBFR16k; i++ ) { - tmp = sub( 16348, shl( til, 1 ) ); /*Q14 */ - L_tmp = L_mult( tmp, sub( 26214, shr( voice_factors, 1 ) ) ); /*Q29*/ - tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ - tmp = s_min( tmp, 4096 ); + tmp = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 /* 1 in Q12 */ ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; move16(); @@ -1517,31 +1518,31 @@ static void hf_synthesis_amr_wb_fx( s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), sub( Find_Max_Norm16( mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */ interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp ); - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ { Word16 s; s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + s */ Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Qout */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */ } Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); @@ -1550,15 +1551,15 @@ static void hf_synthesis_amr_wb_fx( } static Word16 EnhanceClass_fx( - const Word16 qq_fx, - const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ + const Word16 qq_fx, /* Qx */ + const Word16 pp_fx, /* Qx */ + const Word16 tilt0_fx, /* i : spectrum tilt Q13*/ + const Word16 tilt_fx, /* i : spectrum tilt Q13*/ + const Word16 voice_factor_fx, /* i : voice factor Q15*/ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter Q15*/ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter Q15*/ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter Q15*/ + Word16 *unvoicing_flag /* i/o: unvoiced flag Q0*/ ) { Word16 unvoicing_tmp_fx; @@ -1571,41 +1572,41 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ + *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */ move16(); - tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ + tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */ - L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ + L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */ L_tmp = Mult_32_16( L_tmp, tmp ); /*Q13 */ tmp = extract_l( L_tmp ); /*Q13 */ tmp1 = mult_r( tilt_fx, 21845 ); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min( tmp1, 8192 ); + tmp1 = s_min( tmp1, 8192 /* 1.0f in Q13 */ ); L_tmp = L_mult( tmp, tmp1 ); /*Q13+Q13+1 */ unvoicing_tmp_fx = extract_l( L_shr( L_tmp, 12 ) ); /*Q15 */ /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ + *unvoicing_fx = round_fx( L_mac( L_mult( 16384 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */ move16(); IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ + *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } #ifdef BASOP_NOGLOB - if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 ) ) + if ( GT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 3277 /* 0.1 in Q15 */ ) ) #else if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif @@ -1615,7 +1616,7 @@ static Word16 EnhanceClass_fx( } #ifdef BASOP_NOGLOB - if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 ) ) + if ( LT_16( sub_o( *unvoicing_fx, *unvoicing_sm_fx, &Overflow ), 1638 /* 0.05 in Q15 */ ) ) #else if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif @@ -1629,13 +1630,13 @@ static Word16 EnhanceClass_fx( static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor /* i : voice factor, Q15 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + Word16 Ap[], /* o : extended LPC coefficents, Q12*/ + Word16 *sub_gain, /* o : sub-frame gain, Q12*/ + Word16 tilt0, /* i : spectrum tilt, Q14*/ + Word16 tilt, /* i : spectrum tilt, Q13*/ + Word16 voice_factor /* i : voice factor, Q15*/ ) { @@ -1654,7 +1655,7 @@ static void envelope_fx( /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); - Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */ /* LPC envelope weighting */ IF( EQ_32( core_brate, ACELP_6k60 ) ) @@ -1670,17 +1671,17 @@ static void envelope_fx( shift = sub( norm_s( Ap[0] ), 2 ); IF( shift != 0 ) { - Scale_sig( Ap, M + 1, shift ); + Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */ } /* LPC envelope level estimate */ L_tmp = 0; move32(); - pt1 = Ap; - pt2 = exp_tab_p_fx; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1688,11 +1689,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = Ap; - pt2 = exp_tab_p_fx + 33; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1710,12 +1711,12 @@ static void envelope_fx( py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3++ ); /* Q27 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif @@ -1725,12 +1726,12 @@ static void envelope_fx( rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx + 33; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); + L_tmp = L_mac_sat( L_tmp, *pt2++, *pt3-- ); /* Q14 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif @@ -1765,21 +1766,21 @@ static void envelope_fx( rr = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q2, 1 ) ) ) ) ); /*Q10*/ #endif Copy( Aq, As, 3 ); - IF( EQ_16( shr( As[2], 1 ), -2048 ) ) + IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); if ( As[1] < 0 ) { - k1 = -k1; + k1 = -k1; /* Q12 */ move16(); } } ELSE { - k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ + k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); q2 = norm_s( k1 ); @@ -1801,28 +1802,28 @@ static void envelope_fx( #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16( k2, 2458 ) ) + if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) ) { - k2 = 2458; + k2 = 2458; /* 0.6f in Q12 */ move16(); } - if ( LT_16( k2, -2458 ) ) + if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); } - if ( GT_16( k1, 4055 ) ) + if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) ) { - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); } - if ( LT_16( k1, -4055 ) ) + if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) ) { - k1 = -4055; + k1 = -4055; /* -0.99f in Q12 */ move16(); } } - As[1] = add( 4096, k2 ); + As[1] = add( 4096 /* 1 in Q12 */, k2 ); move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ @@ -1831,11 +1832,11 @@ static void envelope_fx( move16(); /*Q12 */ L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1843,11 +1844,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx + 33; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1865,11 +1866,11 @@ static void envelope_fx( qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult( qx, qx ); - L_tmp = L_mac( L_tmp, qy, qy ); + L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ + L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); + Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, &hAmrwb_IO->voice_fac_amr_wb_hf, &hAmrwb_IO->unvoicing_fx, &hAmrwb_IO->unvoicing_sm_fx, &hAmrwb_IO->unvoicing_flag_fx ); /* Q0 */ alpha = 0; move16(); IF( Unvoicing_flag ) @@ -1886,31 +1887,31 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); - L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ - rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_max( L_tmp, 268435456 ); + L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else qq = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ #endif - rr = s_min( rr, qq ); - rr = s_max( rr, pp ); + rr = s_min( rr, qq ); /* Q10 */ + rr = s_max( rr, pp ); /* Q10 */ } ELSE { test(); - IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) + IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) ) { L_tmp = L_mult( rr, rr ); /*Q21*/ tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ - L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + L_tmp = L_sub( 2097152 /* 1 in Q21 */, L_tmp ); /*Q21*/ alpha = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ L_tmp = L_mult( alpha, ( hAmrwb_IO->prev_r_fx ) ); /*Q25*/ L_tmp = L_mac( L_tmp, tmp, rr ); /*Q25*/ @@ -1924,9 +1925,9 @@ static void envelope_fx( hAmrwb_IO->prev_r_fx = rr; move16(); - L_tmp = L_mult( tilt, sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1935,8 +1936,8 @@ static void envelope_fx( tmp = s_min( tmp, qq ); rr = s_min( tmp, rr ); - L_tmp = L_mult( abs_s( sub( tilt, 8192 ) ), sub( 26214, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_add( L_tmp, 268435456 ); + L_tmp = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1949,7 +1950,7 @@ static void envelope_fx( L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ #ifdef BASOP_NOGLOB - *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ + *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ @@ -1963,15 +1964,15 @@ static void envelope_fx( * adaptively select the start band of bandwidth extension *---------------------------------------------------------------------*/ -void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 core_rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ - Word16 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ +static void AdaptiveStartBand_fx( + Word16 *start_band, /* o : start point of copied band Q0*/ + const Word32 core_rate, /* i : core bitrate Q0*/ + const Word16 *lsf_fx, /* i : lsf frequency Q2*/ + const Word16 voicing_fac_fx, /* i : voicing factors Q14*/ + const Word16 clas, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *voicing_flag, /* Q0 */ + Word16 *start_band_old, /* Q0 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1985,19 +1986,19 @@ void AdaptiveStartBand_fx( move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; + voicing_flag_old = *voicing_flag; /* Q0 */ move16(); test(); test(); test(); - if ( GT_16( voicing_fac_fx, 6554 ) || ( GT_16( voicing_fac_fx, 4915 ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) + if ( GT_16( voicing_fac_fx, 6554 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { - *voicing_flag = 1; + *voicing_flag = 1; /* Q0 */ move16(); } test(); - if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) + if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -2016,14 +2017,14 @@ void AdaptiveStartBand_fx( *pt1++ = sub( *pt2++, *pt3++ ); move16(); /*Q2 */ } - tmp1 = extract_l( Mult_32_16( core_rate, 27046 ) ); /*Q14 */ - L_tmp = L_shr( L_mult0( tmp1, 22370 ), 15 ); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l( L_tmp ); /*Q26 */ - W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ + tmp1 = extract_l( Mult_32_16( core_rate, 27046 /* 0.00005 in Q29 */ ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ IF( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r( W_fx, 24576 ); /*Q25 */ + W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */ } pos = 2; @@ -2050,8 +2051,8 @@ void AdaptiveStartBand_fx( } /*do the procedure for i==2*/ - L_tmp = L_max( L_msu( 171798692, lsf_fx[2], W_fx ), 171799 ); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ + Crit_fx = Mult_32_16( L_tmp, lsf_diff_fx[2] ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ OptCrit_fx = L_add( Crit_fx, 0 ); pos = 2; @@ -2062,37 +2063,37 @@ void AdaptiveStartBand_fx( pt1 = &lsf_diff_fx[3]; FOR( i = 3; i < M2; i++ ) { - L_tmp = L_max( L_msu( 171798692, *pt2++, W_fx ), 171799 ); /* Q2.56+25+1 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ IF( LE_32( Crit_fx, OptCrit_fx ) ) { OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */ - pos = i; + pos = i; /* Q0 */ move16(); } } - tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); - *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */ + *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); /* Q0 */ move16(); - L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ + L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */ test(); test(); test(); test(); IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || - ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); test(); test(); if ( LT_16( abs_s( sub( ( *start_band ), ( *start_band_old ) ) ), 20 ) && EQ_16( *voicing_flag, 1 ) && EQ_16( voicing_flag_old, 1 ) ) { - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } } @@ -2101,29 +2102,29 @@ void AdaptiveStartBand_fx( test(); if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); } - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } IF( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min( *start_band, 120 ); + *start_band = s_min( *start_band, 120 ); /* Q0 */ move16(); } flag = sub( s_and( *start_band, 0x0001 ), 1 ); IF( flag == 0 ) { - *start_band = sub( *start_band, 1 ); + *start_band = sub( *start_band, 1 ); /* Q0 */ move16(); } } - *start_band_old = *start_band; + *start_band_old = *start_band; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index ace2e535c..e67d5f663 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -26,11 +26,11 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } test(); @@ -38,21 +38,21 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -62,7 +62,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -71,12 +71,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } @@ -97,11 +97,11 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } #ifndef SOLVED_COMP_ENC_DEC @@ -116,21 +116,21 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) #endif { - *hqswb_clas = get_next_indice( st_fx, 2 ); + *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -140,7 +140,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -149,7 +149,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #ifndef SOLVED_COMP_ENC_DEC @@ -158,7 +158,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dfc19c542..adcd83076 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -16,22 +16,22 @@ * Initialization of HQ bands and subframes *--------------------------------------------------------------------------*/ void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - const Word16 **sfmsize, /* o : Subband bandwidths */ - const Word16 **sfm_start, /* o : Subband start coefficients */ - const Word16 **sfm_end /* o : Subband end coefficients */ + Word16 *nb_sfm, /* o : Number of sub bands Q0*/ + Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0*/ + Word16 *num_bands_p, /* o : FEC sub bands Q0*/ + const Word16 **sfmsize, /* o : Subband bandwidths Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ) { - *num_Sb = MAX_SB_NB; + *num_Sb = MAX_SB_NB; /* Q0 */ move16(); - *nb_sfm = SFM_N_NB; + *nb_sfm = SFM_N_NB; /* Q0 */ move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; + Copy( Num_bands_NB, num_bands_p, *num_Sb ); /* Q0 */ + *sfmsize = band_len_wb; /* Q0 */ + *sfm_start = band_start_wb; /* Q0 */ + *sfm_end = band_end_wb; /* Q0 */ move16(); move16(); move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9ff889997..de8d19e32 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -19,11 +19,11 @@ void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -62,15 +62,17 @@ void hq_core_dec_fx( move16(); sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; + move16(); + move16(); - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding @@ -114,18 +116,18 @@ void hq_core_dec_fx( } #endif /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -133,7 +135,7 @@ void hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -145,10 +147,10 @@ void hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC - L_spec = inner_frame; + L_spec = inner_frame; /* Q0 */ #endif move16(); @@ -174,7 +176,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -189,22 +191,22 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -222,7 +224,7 @@ void hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -251,8 +253,8 @@ void hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -280,7 +282,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15 */ } ELSE { @@ -291,11 +293,11 @@ void hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -304,7 +306,7 @@ void hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -315,11 +317,11 @@ void hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -421,7 +423,7 @@ void hq_core_dec_fx( test(); IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -499,7 +501,7 @@ void hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q14 + Q_synth */ move16(); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); @@ -526,7 +528,7 @@ void hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -548,9 +550,9 @@ void hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,11 +560,11 @@ void hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -572,9 +574,9 @@ void hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE @@ -590,12 +592,12 @@ void hq_core_dec_fx( void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ - Word16 output[], + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ + Word16 output[], /* Q_ouput */ Word16 *Q_output ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -656,14 +658,14 @@ void ivas_hq_core_dec_fx( hTcxDec = st_fx->hTcxDec; - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); test(); test(); @@ -678,7 +680,7 @@ void ivas_hq_core_dec_fx( num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ /* Set default spectrum length */ - L_spec = l_spec_tbl[st_fx->bwidth]; + L_spec = l_spec_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( !st_fx->bfi ) { @@ -686,7 +688,7 @@ void ivas_hq_core_dec_fx( { IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - L_spec = l_spec_ext_tbl[st_fx->bwidth]; + L_spec = l_spec_ext_tbl[st_fx->bwidth]; /* Q0 */ move16(); } ELSE @@ -706,18 +708,18 @@ void ivas_hq_core_dec_fx( acelp_plc_mdct_transition_fx( st_fx ); } /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -725,7 +727,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -737,7 +739,7 @@ void ivas_hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( EQ_16( st_fx->bfi, 0 ) ) @@ -746,7 +748,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; /* Q0 */ move16(); } } @@ -762,7 +764,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -777,22 +779,22 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* q_previoussynth */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* q_delay_buff */ flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ move16(); set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } @@ -811,7 +813,7 @@ void ivas_hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -843,8 +845,8 @@ void ivas_hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -872,7 +874,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15*/ } ELSE { @@ -883,11 +885,11 @@ void ivas_hq_core_dec_fx( { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { - tmp_loop = mult( inner_frame, 8192 ); - FOR( j = mult( inner_frame_tbl[sub( st_fx->bwidth, 1 )], 8192 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); /* Q0 */ + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -896,7 +898,7 @@ void ivas_hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -907,11 +909,11 @@ void ivas_hq_core_dec_fx( /* WB/SWB bandwidth switching */ IF( is_transient ) { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); + Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ } ELSE { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); + Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ } @@ -926,34 +928,34 @@ void ivas_hq_core_dec_fx( { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st_fx->hTcxCfg; - L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frameTCX_glob = hTcxDec->L_frameTCX; /* Q0 */ move16(); - L_frame_glob = st_fx->L_frame; + L_frame_glob = st_fx->L_frame; /* Q0 */ move16(); - L_spec = hTcxDec->L_frameTCX; + L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ // fscaleFB = sr2fscale( st_fx->output_Fs ); // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; - mdctWindowLength = getMdctWindowLength( st_fx->fscale ); + mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); - mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); + mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ IF( core_switching_flag ) { - tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; /* Q0 */ move16(); } ELSE { - tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame Q0*/ move16(); } @@ -961,11 +963,11 @@ void ivas_hq_core_dec_fx( init_tcx_info_fx( st_fx, L_frame_glob, L_frameTCX_glob, 0, st_fx->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = tcx_cfg->tcx_mdct_window_length; /* Q0 */ move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); - index = tcx_cfg->tcx_last_overlap_mode; + index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); #ifndef MSAN_FIX @@ -978,9 +980,9 @@ void ivas_hq_core_dec_fx( left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, 0, st_fx->bfi, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, st_fx, 0, acelp_zir ); // values till L_frame same - Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); + Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); + Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); /* q_wtda + 1 */ /* FB synthesis */ temp = BASOP_Util_Divide3232_Scale( L_mult0( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob, &temp_e ); @@ -988,14 +990,14 @@ void ivas_hq_core_dec_fx( IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio_16, tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, 0, st_fx->bfi, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, st_fx, temp, acelp_zir ); - Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); + Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); + Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); /* q_wtda */ - Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); + Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core */ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -1036,9 +1038,9 @@ void ivas_hq_core_dec_fx( tmp = Sqrt16( tmp, &tmp_e ); ener_match = shr( tmp, sub( 2, tmp_e ) ); // Q13 - v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q + v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q10 - Scale_sig32( t_audio_q, inner_frame, Q2 ); + Scale_sig32( t_audio_q, inner_frame, Q2 ); // Q10 + Q2 Q_audio = Q_G_audio; move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); @@ -1052,7 +1054,7 @@ void ivas_hq_core_dec_fx( test(); IF( EQ_16( st_fx->bfi, 0 ) && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 31 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -1129,7 +1131,7 @@ void ivas_hq_core_dec_fx( IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { #ifdef BASOP_NOGLOB - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); + st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q15 */ #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif @@ -1155,7 +1157,7 @@ void ivas_hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -1177,9 +1179,9 @@ void ivas_hq_core_dec_fx( IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -1187,10 +1189,10 @@ void ivas_hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -1200,16 +1202,16 @@ void ivas_hq_core_dec_fx( { set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ IF( st_fx->element_mode > EVS_MONO ) { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, -( *Q_output ) ); - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); + Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ + Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } return; } @@ -1238,7 +1240,7 @@ void HQ_core_dec_init_fx( move16(); move16(); - hHQ_core->last_hq_core_type = -1; + hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); set16_fx( hHQ_core->old_is_transient, 0, 3 ); @@ -1251,7 +1253,7 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f in Q13*/ hHQ_core->hq_generic_seed = RANDOM_INITSEED; set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); hHQ_core->prev_hqswb_clas = HQ_NORMAL; @@ -1281,7 +1283,7 @@ void HQ_core_dec_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*0.5 in Q15*/ move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); @@ -1309,9 +1311,9 @@ void HQ_core_dec_init_fx( set16_fx( hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); hHQ_core->envstabplc_hocnt = 0; move16(); - set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->mag_chg_1st_fx, 32767 /* 1.0f in Q15 */, LGW_MAX ); set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; /* Q15 */ hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; hHQ_core->oldHqVoicing = 0; @@ -1343,7 +1345,7 @@ void HQ_nbfec_init_fx( { Word16 i, j; - hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->prev_last_core = -1; /* Q0 */ hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 81385aaaa..677221f31 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -14,15 +14,15 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ + const Word16 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ) { Word16 hcode_l; @@ -34,14 +34,14 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); /* Q0 */ move16(); } ELSE { - LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); /* Q0 */ move16(); } @@ -53,10 +53,10 @@ Word16 decode_envelope_indices_fx( /* o : Number of b IF( EQ_16( LCmode, 1 ) ) { hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add( start_norm, num_sfm ); + j = add( start_norm, num_sfm ); /* Q0 */ FOR( i = start_norm + 1; i < j; i++ ) { - hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); + hcode_l = add( hcode_l, huffsizn_tran[difidx[i]] ); /* Q0 */ } } ELSE @@ -74,68 +74,68 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } ELSE IF( EQ_16( LCmode, 1 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { j = *pDifidx++; move16(); - hcode_l = add( hcode_l, resize_huffsizn[j] ); + hcode_l = add( hcode_l, resize_huffsizn[j] ); /* Q0 */ } - pDifidx1 = &difidx[startNormPlus1]; + pDifidx1 = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus2 = sub( num_sfm, 2 ); + numSfmMinus2 = sub( num_sfm, 2 ); /* Q0 */ FOR( i = 0; i < numSfmMinus2; i++ ) { - pDifidx = pDifidx1++; + pDifidx = pDifidx1++; /* Q0 */ move16(); IF( GT_16( *pDifidx, 17 ) ) { - offset = sub( *pDifidx, 17 ); - offset = s_min( offset, 3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 17 ); /* Q0 */ + offset = s_min( offset, 3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } ELSE IF( LT_16( *pDifidx, 13 ) ) { - offset = sub( *pDifidx, 13 ); - offset = s_max( offset, -3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 13 ); /* Q0 */ + offset = s_max( offset, -3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } } } ELSE IF( EQ_16( LCmode, 2 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - j = *pDifidx++; + j = *pDifidx++; /* Q0 */ move16(); - hcode_l = add( hcode_l, huffsizn[j] ); + hcode_l = add( hcode_l, huffsizn[j] ); /* Q0 */ } } ELSE { - startNormPlus1 = add( start_norm, 1 ); - numSfmMinus1 = sub( num_sfm, 1 ); - pDifidx = &difidx[startNormPlus1]; + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ + pDifidx = &difidx[startNormPlus1]; /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); /* Q0 */ move16(); } - hcode_l = numnrmibits; + hcode_l = numnrmibits; /* Q0 */ move16(); } } @@ -152,12 +152,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b *------------------------------------------------------------------------*/ void dequantize_norms_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 start_norm, /* i : First SDE encoded norm Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ) { Word16 i, j; @@ -165,28 +165,28 @@ void dequantize_norms_fx( Word16 *pYnrm, *pNormqlg2; /* First sub-frame */ - i = ynrm[start_norm]; + i = ynrm[start_norm]; /* Q0 */ move16(); - normqlg2[start_norm] = dicnlg2[i]; + normqlg2[start_norm] = dicnlg2[i]; /* Q0 */ move16(); /* Other sub-frames */ IF( is_transient ) { /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; + idxbuf[0] = ynrm[0]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); + idxbuf[i] = sub( add( ynrm[i], idxbuf[i - 1] ), 15 ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { - idxbuf[i] = 39; + idxbuf[i] = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } } @@ -195,26 +195,26 @@ void dequantize_norms_fx( } ELSE { - pYnrm = &ynrm[start_norm]; + pYnrm = &ynrm[start_norm]; /* Q0 */ move16(); - pNormqlg2 = &normqlg2[start_norm + 1]; + pNormqlg2 = &normqlg2[start_norm + 1]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = sub( *pYnrm++, 15 ); + j = sub( *pYnrm++, 15 ); /* Q0 */ move16(); - *pYnrm = add( *pYnrm, j ); + *pYnrm = add( *pYnrm, j ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { - *pYnrm = 39; + *pYnrm = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - *pNormqlg2++ = dicnlg2[*pYnrm]; + *pNormqlg2++ = dicnlg2[*pYnrm]; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 93b94a5c8..556006121 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -18,10 +18,10 @@ #ifdef IVAS_FLOAT_FIXED void ivas_hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -41,7 +41,7 @@ void ivas_hq_pred_hb_bws_fx( { L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -71,11 +71,11 @@ void ivas_hq_pred_hb_bws_fx( } void hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -99,7 +99,7 @@ void hq_pred_hb_bws_fx( L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ #endif } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ move16(); @@ -153,7 +153,7 @@ void ivas_hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -211,8 +211,8 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters @@ -231,15 +231,15 @@ void ivas_hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice_fx( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); @@ -249,7 +249,7 @@ void ivas_hq_hr_dec_fx( hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -257,8 +257,8 @@ void ivas_hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) NE_16( st_fx->element_mode, EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -267,7 +267,7 @@ void ivas_hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q15 */ } ELSE { @@ -286,16 +286,16 @@ void ivas_hq_hr_dec_fx( { IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); /*------------------------------------------------------------------* @@ -309,20 +309,20 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -330,8 +330,8 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -350,10 +350,10 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -407,7 +407,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; @@ -422,7 +422,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -500,25 +500,25 @@ void hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); + nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -526,8 +526,8 @@ void hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); + csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -536,7 +536,7 @@ void hq_hr_dec_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q0 */ } ELSE { @@ -556,16 +556,16 @@ void hq_hr_dec_fx( test(); IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ move16(); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ /*------------------------------------------------------------------* * Bit allocation @@ -578,20 +578,20 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) { - tmp = i_mult( st_fx->bws_cnt1, 1638 ); + tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); /* Q15 */ move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( n_band = 0; n_band < 4; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); + SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ move16(); } } @@ -599,8 +599,8 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub( sum, b_delta_env ); + b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -619,10 +619,10 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) { - subband_search_offset = subband_search_offsets_13p2kbps_Har; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -676,7 +676,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index a1f18d2da..34bb10fc8 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -218,9 +218,9 @@ static int16_t para_pred_bws( #endif #ifdef IVAS_FLOAT_FIXED static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -242,7 +242,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -251,9 +251,9 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -275,7 +275,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -287,11 +287,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -303,7 +303,7 @@ static Word16 para_pred_bws_fx( IF( LT_16( exp, 16 ) ) { tmp_den = extract_l( L_shr( mean_fx[i], sub( 16, exp ) ) ); /*Qsyn - 16 + exp */ - tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*//Qsyn - 16 + exp */ + tmp_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */ } ELSE { @@ -315,16 +315,16 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); /*Q_syn + Q15 - 15*/ move32(); } min_fx = L_min( min_fx, mean_fx[i] ); peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -410,21 +410,21 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { test(); - IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) ); move16(); } ELSE { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767 /*1.0f in Q15*/, st_fx->attenu_fx ) ) ); move16(); } } - IF( LT_16( st_fx->attenu_fx, 29491 ) ) + IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) ) { - st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ ); move16(); } } @@ -439,7 +439,7 @@ static Word16 para_pred_bws_fx( { FOR( i = 0; i < SWB_FENV; i++ ) { - if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -449,10 +449,10 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -1031,12 +1031,12 @@ void swb_bwe_dec_flt( #ifdef IVAS_FLOAT_FIXED Word16 swb_bwe_dec_fx32( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 output_fx[], /* i : synthesis @internal Fs Q11 */ - Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis Q11 */ - Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - Word16 output_frame /* i : frame length */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ + Word32 *synth_fx, /* i : ACELP core synthesis/final synthesis : Q11 */ + Word32 *hb_synth_fx, /* o : SHB synthesis/final synthesis : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { Word16 L; @@ -1285,7 +1285,7 @@ Word16 swb_bwe_dec_fx32( { FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15 move32(); } @@ -1351,7 +1351,7 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < output_frame; i++ ) { - hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb move32(); } @@ -1400,7 +1400,7 @@ void fd_bwe_dec_init_fx( ) { set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->prev_Energy_fx = 0; @@ -1420,7 +1420,6 @@ void fd_bwe_dec_init_fx( move16(); hBWE_FD->prev_Energy_wb_fx = 0; move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 765458a90..6e9fd80dc 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -21,9 +21,9 @@ * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ static Word16 para_pred_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -45,7 +45,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -54,13 +54,13 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ /*IF (sub(mag_fx, peak_fx) > 0) */ /*{ */ /* peak_fx = mag_fx; */ /*} */ - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -82,7 +82,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -94,11 +94,11 @@ static Word16 para_pred_bws_fx( avrg2_fx = L_deposit_l( 0 ); FOR( i = 1; i < 4; i++ ) { - avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); - avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); + avrg1_fx = L_add( avrg1_fx, mean_fx[i] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - avrg1_fx = Mult_32_16( avrg1_fx, 10923 ); - avrg2_fx = Mult_32_16( avrg2_fx, 10923 ); /* 1/3 -> Q15 -> 10923 */ + avrg1_fx = Mult_32_16( avrg1_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -122,11 +122,11 @@ static Word16 para_pred_bws_fx( tmp = i_mult( tmp_num, tmp_den ); /*Q15 */ - mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); + mean_fx[i] = Mult_32_16( mean_fx[i], tmp ); // Q_syn + Q15 - 15 move32(); } min_fx = L_min( min_fx, mean_fx[i] ); - peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/ /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -137,9 +137,9 @@ static Word16 para_pred_bws_fx( /*} */ } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -147,7 +147,7 @@ static Word16 para_pred_bws_fx( ELSE { tmp = extract_l( L_shr( L_mult0( st_fx->tilt_wb_fx, 17476 ), 14 ) ); /*Q15 */ - min_fx = Mult_32_16( peak_32_fx, tmp ); + min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/ } } @@ -272,7 +272,7 @@ static Word16 para_pred_bws_fx( SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -309,7 +309,8 @@ static Word16 para_pred_bws_fx( *-------------------------------------------------------------------*/ Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ) + Word16 *WB_fenv /* o : Q15 */ +) { Word16 mode; Word16 index, index2; @@ -320,25 +321,25 @@ Word16 WB_BWE_gain_deq_fx( mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); - L_tmp = L_shr( F_2_5_fx[index2], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[0] = shl( tmp, add( exp, 3 ) ); + WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); - L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[1] = shl( tmp, add( exp, 3 ) ); + WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); return ( mode ); @@ -349,16 +350,16 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ) +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -449,7 +450,7 @@ Word16 ivas_wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -536,15 +537,15 @@ Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ) { @@ -706,12 +707,12 @@ Word16 wb_bwe_dec_fx( * Decoding of SWB parameters *-------------------------------------------------------------------*/ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -759,7 +760,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) { /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[add( tmp, n_band )]; /*Q8 */ + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */ move16(); } @@ -848,8 +849,8 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); } - Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) @@ -867,13 +868,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif @@ -896,7 +897,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[n_band * 2 + 1] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif @@ -929,11 +930,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - Copy( &EnvCdbkFB_fx[i_mult2( indice[5], DIM_FB )], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ + Copy( &EnvCdbkFB_fx[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( SWB_fenv[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); + tmp = add( SWB_fenv[n_band + nenv], Mean_env_fb_fx[n_band] ); L_tmp = L_mult( tmp, 21771 ); /* 0.166096 in Q17 -> Q25 */ L_tmp = L_shr( L_tmp, 9 ); /* From Q25 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ @@ -942,7 +943,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 13 ); - SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); + SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -958,19 +959,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #ifdef ADD_IVAS_BWE - const Word16 output[], /* i : suntehsis @ internal Fs */ + const Word16 output[], /* i : suntehsis @ internal Fs */ #endif - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #ifdef ADD_IVAS_BWE - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ #endif - const Word16 output_frame /* i : frame length */ - , - Word16 *Qpost ) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -1280,7 +1281,7 @@ void fd_bwe_dec_init( { hBWE_FD->old_wtda_wb_fx_exp = 0; move16(); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 51880fe61..8b238e46c 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -26,6 +26,7 @@ two functions would be less efficient (Performance Wise) since the function here doesn't use 'Log2_norm_lc' at all versus gain_dequant_fx() which does. */ +#ifdef IVAS_FLOAT_FIXED static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ const Word16 min, /* i: value of lower limit (Q13) */ @@ -40,9 +41,9 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) L_mini = 0; /* no complexity counted, just to remove warning */ L_fact = 0; /* no complexity counted, just to remove warning */ - move32(); move32(); + IF( EQ_16( min, G_AVQ_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ @@ -83,7 +84,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) /* c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /* gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min );*/ - L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); + L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); // Q12 + Qx exp1 = norm_s( index ); index = shl( index, exp1 ); /* inv_tbl has variable Q, with Q0 being at [2]*/ @@ -100,7 +101,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) exp1 = sub( 30 - 16 - 15, p2_int ); exp1 = add( exp1, extract_l( L_mini ) ); - gain = round_fx( L_temp ); + gain = round_fx( L_temp ); // exp1 L_temp = L_mult( gain, extract_h( L_mini ) ); exp2 = norm_l( L_temp ); @@ -109,7 +110,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) gain = round_fx( L_temp ); exp1 = add( exp1, exp2 ); - *exp = exp1; + *exp = exp1; // gain_e move16(); return gain; @@ -122,7 +123,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis Q(15 - hb_synth_fx_exp) */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -251,14 +252,14 @@ static Word16 TD_Postprocess( /* o : gain in Q15 * HR SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ +Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -413,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[add( pos, i )] = L_temp; + t_audio32[pos + i] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -590,17 +591,17 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( ind1, 1 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 2 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16 ) ); // Q9 } IF( EQ_16( ind1, 3 ) ) { - en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); + en_noncoded = round_fx( L_mult0( en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16 ) ); // Q9 } } @@ -621,7 +622,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -656,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } @@ -678,8 +679,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); - ptr16 = &t_audio[add( temp2, j )]; - ptr32 = &t_audio32[add( temp2, j )]; + ptr16 = &t_audio[temp2 + j]; + ptr32 = &t_audio32[temp2 + j]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) { @@ -763,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); + t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); move16(); } } @@ -787,18 +788,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); - en_band[0] = swb_hr_env_code1_fx[temp]; + en_band[0] = swb_hr_env_code1_fx[temp]; // Q9 move16(); - en_band[1] = swb_hr_env_code1_fx[temp + 1]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; // Q9 move16(); temp = shl( ind2, 1 ); - en_band[2] = swb_hr_env_code2_fx[temp]; + en_band[2] = swb_hr_env_code2_fx[temp]; // Q9 move16(); - en_band[3] = swb_hr_env_code2_fx[temp + 1]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; // Q9 move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ - env = mac_r( L_mac( L_mac( L_mult( en_band[0], 8192 ), en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); + env = mac_r( L_mac( L_mac( L_mult( en_band[0] /*Q9*/, 8192 /*0.25 in Q15*/ ) /*Q23*/, en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); // Q23 /*---------------------------------------------------------------------* * choose sub-bands to be dequantized @@ -846,19 +847,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB if ( EQ_16( ind1, 1 ) ) { /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); + en_noncoded = mult_r( min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 / 2 ); // Q9 } IF( EQ_16( ind1, 2 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); + en_noncoded = round_fx( L_shl( L_mult( BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env ), 1 ) ); // Q9 } if ( EQ_16( ind1, 3 ) ) { /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); + en_noncoded = mult_r( BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env ); // Q9 } } @@ -954,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + t_audio_tmp[temp + j] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -978,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[temp + j] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -1043,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = j - 1; + j = sub( j, 1 ); } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1271,7 +1272,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Apply global gain */ if ( LE_16( nBits_total, NBITS_THRESH_BWE_HR ) ) { - gain_fx = mult_r( 27853, gain_fx ); /* 0.85 */ + gain_fx = mult_r( 27853, gain_fx ); /* 0.85 in exp_0 */ + // gain_e } ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; @@ -1336,12 +1338,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } ELSE { - st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); + st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ) /*gain_e + (31 - Q23)*/, 7 ) ); /*gain_e + 15*/ move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; + st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } @@ -1512,7 +1514,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } } - hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; // exp_temp4 move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); @@ -1558,7 +1560,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1567,32 +1568,14 @@ void hr_bwe_dec_init( set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; /*0.75f in Q14*/ move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); /*1.0f in Q30*/ move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ return; } -#else -void hr_bwe_dec_init( - HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ -) -{ - set16_fx( hBWE_FD_HR->t_audio_prev_fx, 0, 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( hBWE_FD_HR->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - hBWE_FD_HR->old_is_transient_hr_bwe_fx = 0; - move16(); - hBWE_FD_HR->bwe_highrate_seed_fx = 12345; - move16(); - - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); - hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - return; -} #endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index f2aa60a59..b9bb17621 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,12 +15,12 @@ *-------------------------------------------------------------------*/ static void DecodeSWBGenericParameters_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 nBands_search_fx, /* i : number of subbnads for SSearch */ - const Word16 BANDS_fx, /* i : total number of subbands per frame */ - const Word16 *p2a_flags_fx, /* i : HF tonal flag */ - const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *lagIndices_fx, /* o : lowband index for each subband :Q0 */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch :Q0 */ + const Word16 BANDS_fx, /* i : total number of subbands per frame :Q0 */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag :Q0 */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC :Q0 */ ) { Word16 sb; @@ -35,16 +35,15 @@ static void DecodeSWBGenericParameters_fx( } ELSE { - IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); - move16(); } ELSE { lagIndices_fx[sb] = 0; - move16(); } + move16(); } } @@ -61,32 +60,32 @@ static void DecodeSWBGenericParameters_fx( *-------------------------------------------------------------------*/ static void DecodeSWBSubbands_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value of spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : subband offsets */ - Word16 *lagIndices_fx, /* i : lowband index for each subband */ - Word16 *lagGains_fx, /* i : first gain for each subband */ - Word16 *QlagGains, /* i : Q value of lagGains */ - Word16 BANDS_fx, /* i : number subbands per frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - const Word16 har_bands_fx, /* i : number of LF harmonic bands */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband band widths */ - const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + HQ_DEC_HANDLE hHQ_core, /* i/o: HQ decoder handle */ + Word32 *L_spectra, /* i/o: MDCT domain spectrum : QsL */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length : Q0 */ + const Word16 fLenHigh_fx, /* i : highband length : Q0 */ + const Word16 nBands_fx, /* i : number of subbands : Q0 */ + const Word16 *sbWidth_fx, /* i : subband lengths : Q0 */ + const Word16 *subband_offsets_fx, /* i : subband offsets : Q0 */ + Word16 *lagIndices_fx, /* i : lowband index for each subband : Q0 */ + Word16 *lagGains_fx, /* i : first gain for each subband QlagGains*/ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame : Q0 */ + Word16 *band_start_fx, /* i : band start of each SB : Q0 */ + Word16 *band_end_fx, /* i : band end of each SB : Q0 */ + Word32 *L_band_energy, /* i : band energy of each SB : Q0 */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands : Q0 */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband band widths : Q0 */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled : QsL */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI : Q0 */ ) { Word16 i, k; @@ -179,7 +178,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -192,7 +191,7 @@ static void DecodeSWBSubbands_fx( convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -200,12 +199,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[sub( BANDS_fx, NB_SWB_SUBBANDS )], Qbe, + &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR( k = 0; k < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -214,7 +213,7 @@ static void DecodeSWBSubbands_fx( } ELSE { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 /*0.9f in Q15*/ ); /* lagGains[k]*0.9f; */ move16(); } } @@ -223,7 +222,7 @@ static void DecodeSWBSubbands_fx( { L_th_g[k] = 0; move32(); - IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ move32(); @@ -244,7 +243,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -252,7 +251,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_spectra_ni[i]; + L_spectra[i] = L_spectra_ni[i]; /* QsL */ move32(); } } @@ -268,26 +267,26 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ void swb_bwe_dec_lr_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal Indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ) { Word16 k; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c5c1bed29..3c788e784 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -466,10 +466,10 @@ void wb_tbe_dec( } #else static void calc_tilt_bwe_fx_loc( - const Word32 *sp_fx, /* i : input signal */ - Word32 *tilt_fx, /* o : signal tilt */ - Word16 *tilt_fx_q, /* o : signal tilt */ - const Word16 N /* i : signal length */ + const Word32 *sp_fx, /* i : input signal : Q11 */ + Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length : Q0 */ ) { Word16 i; @@ -479,14 +479,14 @@ static void calc_tilt_bwe_fx_loc( move64(); FOR( i = 0; i < N; i++ ) { - r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/ } - r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/ FOR( i = 2; i < N; i++ ) { - IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 ) { - r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/ } } Word16 headroom_left_r0 = W_norm( r0_fx ); @@ -494,7 +494,6 @@ static void calc_tilt_bwe_fx_loc( Word16 r0_q = 0, r1_q = 0; move16(); move16(); - // Word16 r0_bits_occ = 0, r1_bits_occ = 0; IF( LT_16( headroom_left_r0, 32 ) ) { r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); @@ -553,7 +552,8 @@ static void calc_tilt_bwe_fx_loc( *-------------------------------------------------------------------*/ static void rescale_genSHB_mem_dec( Decoder_State *st_fx, - Word16 sf ) + Word16 sf /*Q0*/ +) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -598,8 +598,8 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, - Word16 *GainShape_fx, - Word32 *GainFrame_fx ) + Word16 *GainShape_fx, /*Q15*/ + Word32 *GainFrame_fx /* Q18 */ ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -617,7 +617,7 @@ static void gradientGainShape( move16(); /* Q14 */ GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) ); move16(); /* Q14 */ } @@ -628,14 +628,14 @@ static void gradientGainShape( IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) ); move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } @@ -649,7 +649,7 @@ static void gradientGainShape( } ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } ELSE @@ -668,7 +668,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 /*0.8f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); @@ -681,7 +681,7 @@ static void gradientGainShape( { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 /*0.2f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ @@ -709,17 +709,17 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */ IF( GT_16( 8192, tmp ) ) { - GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/ + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } @@ -734,17 +734,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15 move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/ move16(); } ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) @@ -753,11 +753,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; + GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/ move16(); } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/ move16(); } ELSE @@ -768,17 +768,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/ move16(); } @@ -1012,15 +1012,15 @@ void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -1136,7 +1136,7 @@ void ivas_swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) ) { test(); test(); @@ -1155,21 +1155,20 @@ void ivas_swb_tbe_dec_fx( ) { is_fractive = 0; - move16(); } ELSE { is_fractive = 1; - move16(); } + move16(); } /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); - inc_fx = 1489; /*Q15*/ + inc_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); IF( EQ_16( is_fractive, 1 ) ) @@ -1180,9 +1179,9 @@ void ivas_swb_tbe_dec_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } test(); @@ -1194,13 +1193,13 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { - set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); + set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/ } ELSE { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/ { - hBWE_TD->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/ move16(); } set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); @@ -1220,7 +1219,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); f_fx = add( f_fx, inc_fx ); } @@ -1240,9 +1239,9 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); @@ -1267,7 +1266,7 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { - GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); + GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) ); } } ELSE @@ -1323,13 +1322,14 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); + /*Q18*/ } IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) ) { - GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); + GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18 } } } @@ -1360,7 +1360,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } @@ -1464,7 +1464,7 @@ void ivas_swb_tbe_dec_fx( Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -2140,9 +2140,9 @@ void ivas_swb_tbe_dec_fx( IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) ) { - GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/ + GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/ } ELSE { @@ -2154,11 +2154,11 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */ } ELSE { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */ } } } @@ -2446,7 +2446,7 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); + GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { @@ -2573,7 +2573,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); + shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2772,7 +2772,7 @@ void ivas_swb_tbe_dec_fx( if ( !st->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -2784,7 +2784,7 @@ void ivas_swb_tbe_dec_fx( move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -4565,12 +4565,12 @@ void GenTransition( #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 rf_flag, /* i : RF flag */ - const Word32 total_brate, /* i : total bitrate */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ) { Word16 i, length; @@ -4578,7 +4578,7 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); @@ -4599,13 +4599,12 @@ void GenTransition_fixed( IF( i % 2 == 0 ) { syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - move32(); } ELSE { syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - move32(); } + move32(); } } @@ -4697,7 +4696,7 @@ void GenTransition_WB( #ifdef IVAS_FLOAT_FIXED void GenTransition_WB_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ const Word32 output_Fs /* i : output sampling rate */ ) { @@ -4706,7 +4705,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 2e187546e..cb3ae52a8 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -633,11 +633,11 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /*==========================================================================*/ void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -716,7 +716,7 @@ void ivas_wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame /*Q18*/, 6553 /*0.2f in Q15*/ ) /*Q18+Q15 - 15*/ ); /*Q18*/ } } ELSE @@ -782,7 +782,7 @@ void ivas_wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 /*0.3f in Q15*/ ); /*Q18*/ } } } @@ -806,12 +806,12 @@ void ivas_wb_tbe_dec_fx( } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 /*0.85f in Q15*/ ); /*Q15*/ move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx /*Q18*/, hBWE_TD->GainAttn_fx /*Q15*/ ); /*Q15+Q18-15*/ } ELSE { @@ -835,7 +835,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } ELSE @@ -852,7 +852,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } @@ -1187,7 +1187,7 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - synth[i] = mult_r( error[i], 21299 ); + synth[i] = mult_r( error[i], 21299 /*0.65f in Q15*/ ); move16(); } @@ -1376,11 +1376,11 @@ void wb_tbe_dec_fx( move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ move16(); } } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) @@ -1397,7 +1397,7 @@ void wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ } } ELSE @@ -1463,7 +1463,7 @@ void wb_tbe_dec_fx( test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); + GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ } } } @@ -1478,11 +1478,11 @@ void wb_tbe_dec_fx( { IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -1971,18 +1971,18 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ move32(); IF( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } @@ -3742,7 +3742,7 @@ void swb_tbe_dec_fx( if ( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3754,7 +3754,7 @@ void swb_tbe_dec_fx( move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3970,7 +3970,7 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ ) { Word16 i; @@ -3979,7 +3979,7 @@ static void Dequant_lower_LSF_fx( move16(); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ move16(); } @@ -3993,9 +3993,10 @@ static void Dequant_lower_LSF_fx( *-------------------------------------------------------------------*/ static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -4007,42 +4008,42 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ move16(); } IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { - offset = lsf_map[0]; + offset = lsf_map[0]; /*Q15*/ move16(); scale = div_s( sub( MAX_LSF_FX, m ), m ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); } } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ move16(); scale = sub( MAX_LSF_FX, last_q_lsf ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ ) ) ); + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ move16(); } @@ -4051,40 +4052,41 @@ static void Map_higher_LSF_fx( static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, - /* i : Mirror point index */ Word16 *m /* i : Mirroring point */ ) + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) { - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ move16(); return; } Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } - suma = L_shl_sat( suma, guarded_bits ); + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return extract_h( suma ); + return extract_h( suma ); /*Qx + Qy - 16*/ } void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ @@ -4281,13 +4283,10 @@ void ivas_dequantizeSHBparams_fx_9_1( *Q_mixFactors = 0; move16(); } - //*Q_mixFactors = 0; set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ - - test(); test(); test(); @@ -4327,13 +4326,13 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); - predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; Idx_pred = 0; move16(); @@ -4364,9 +4363,9 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); move16(); } @@ -4541,15 +4540,15 @@ void ivas_dequantizeSHBparams_fx_9_1( static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ + const Word16 extl, /* i : extension layer */ + Word32 extl_brate, /* i : extensiuon layer bitrate */ + Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors /* o : Q15 */ + Word32 *Q_shb_ener_sf, /* o : Q15*/ + Word16 *Q_shb_res_gshape, /* o : Q14*/ + Word16 *Q_mixFactors /* o : Q15*/ ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; @@ -4841,10 +4840,10 @@ static void dequantizeSHBparams_fx_9_1( * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp ) { @@ -4903,11 +4902,11 @@ void fb_tbe_dec_fx( void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, - Word16 *fb_synth_ref, + Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, Word16 output_frame ) @@ -4978,7 +4977,7 @@ void fb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME48k; i++ ) { // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp move16(); } return; @@ -5099,12 +5098,12 @@ void tbe_read_bitstream_fx( * switching from TBE to IGF *---------------------------------------------------------------------*/ void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ + const Word16 *input, /* i : gain shape overlap buffer Q11 */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ + Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, @@ -5446,7 +5445,7 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t i; + Word16 i; /* init. SHB buffers */; InitSWBdecBuffer_fx( st_fx ); @@ -5469,7 +5468,7 @@ void td_bwe_dec_init_fx( hBWE_TD->tilt_mem_fx = 0; move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /*0.5f in Q15*/, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); @@ -5503,10 +5502,8 @@ void td_bwe_dec_init_fx( hBWE_TD->fb_tbe_demph_fx = 0; move16(); - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); diff --git a/lib_dec/syn_outp.c b/lib_dec/syn_outp.c index 65e36bc61..31cd8b109 100644 --- a/lib_dec/syn_outp.c +++ b/lib_dec/syn_outp.c @@ -47,7 +47,7 @@ * Output synthesis signal with compensation for saturation * returns number of clipped samples *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: number of clipped samples */ uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ @@ -133,3 +133,4 @@ void AGC_dec( return; } +#endif diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 7d51c4341..0d84c0c88 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -15,11 +15,11 @@ *-------------------------------------------------------------------*/ void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: fixed point synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length Q0 */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { Word16 i, tmp; @@ -66,7 +66,7 @@ void unscale_AGC( const Word16 x[], /* i: 16kHz synthesis Qx */ const Word16 Qx, /* i: scale factor of x */ Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ const Word16 n /* i: vector size */ ) { @@ -97,16 +97,16 @@ void unscale_AGC( move16(); IF( GT_16( max_val, tmp ) ) { - frame_fac = sub( 16384, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ + frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */ } /*----------------------------------------------------------------* * AGC *----------------------------------------------------------------*/ /* update AGC factor (slowly) */ - fac = mac_r( L_mult( 32440, mem[0] ), 328, frame_fac ); + fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ ); - L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13 L_tmp = L_msu0( L_tmp, fac, x[0] ); L_tmp = L_msu( L_tmp, fac, mem[1] ); L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 41c83c71e..0432f02a5 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -16,20 +16,21 @@ #ifdef IVAS_FLOAT_FIXED void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient ) + Word16 *inp_vector_fx, /*Qx */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; @@ -141,7 +142,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); /*Q16*/ move32(); IF( Rk_fx[j] < 0 ) { @@ -201,7 +202,7 @@ void tcq_core_LR_dec_fx( IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; - move32(); /*16 */ + move32(); /*2 in Q16 */ bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); @@ -244,7 +245,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -266,7 +267,7 @@ void tcq_core_LR_dec_fx( decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -282,7 +283,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -302,7 +303,7 @@ void tcq_core_LR_dec_fx( decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE @@ -311,7 +312,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -403,7 +404,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -436,7 +437,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e4b56eca9..1c7bee57b 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,11 +20,11 @@ * *--------------------------------------------------------------*/ void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; @@ -35,7 +35,7 @@ void tcx_decoder_memory_update( L_frame_glob = st->L_frame; move16(); - preemph = st->preemph_fac; + preemph = st->preemph_fac; // Q15 move16(); /* Output synth */ @@ -105,7 +105,7 @@ void tcx_decoder_memory_update( Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); } /* Update old_Aq */ - Copy( A, st->old_Aq_12_8_fx, M + 1 ); + Copy( A, st->old_Aq_12_8_fx /*Q12*/, M + 1 ); #ifdef FIX_778_STEREO_BRATE_SWITCHING } #endif @@ -116,27 +116,22 @@ void tcx_decoder_memory_update( /* Returns: number of bits used (including "bits") */ Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_e) */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; + Word16 i, j, num_zeros, zeros[L_FRAME_PLUS], fac_p, sign, s; Word32 L_tmp; - Word16 s; - /* Limit the number of residual bits */ target_bits = s_min( target_bits, NPRM_RESQ ); - /* Requantize the spectrum line-by-line */ /* fac_m = deadzone * 0.5f; */ num_zeros = 0; @@ -157,7 +152,7 @@ Word16 tcx_ari_res_invQ_spec( sign = negate( sign ); /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); // x_Q_e move32(); bits = add( bits, 1 ); } @@ -196,7 +191,6 @@ Word16 tcx_ari_res_invQ_spec( bits = add( bits, 1 ); } - return bits; } /*--------------------------------------------------------------- @@ -205,14 +199,13 @@ Word16 tcx_ari_res_invQ_spec( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) + Word16 *prm, /*i : Q0 */ + Word16 resQBits /*i : Q0 */ +) { - Word16 bits; - Word16 gain, tmp1, tmp2; - + Word16 bits, gain, tmp1, tmp2; gain = *gain_tcx; move16(); @@ -255,14 +248,14 @@ Word16 tcx_res_invQ_gain( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ ) { Word16 i; Word16 fac_m, fac_p; @@ -275,9 +268,9 @@ Word16 tcx_res_invQ_spec( /* Requantize the spectrum line-by-line */ fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); + fac_p = sub( 0x4000 /*0.5f Q15*/, fac_m ); // Q15 - lf_deemph_factor = 0x4000; + lf_deemph_factor = 0x4000; /*0.5f Q15*/ move16(); s = sub( x_e, 1 ); @@ -290,11 +283,11 @@ Word16 tcx_res_invQ_spec( test(); test(); - IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 /*0.5f in Q14*/ ) ) ) ) { if ( lf_deemph_factors != NULL ) { - lf_deemph_factor = lf_deemph_factors[i]; + lf_deemph_factor = lf_deemph_factors[i]; // Q14 move16(); } @@ -306,13 +299,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_sub( x[i], L_shr( tmp, s ) ); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } ELSE @@ -323,13 +316,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_add( x[i], L_shr( tmp, s ) ); + x[i] = L_add( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -354,11 +347,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p /*Q15*/ ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -367,7 +360,7 @@ Word16 tcx_res_invQ_spec( } ELSE { - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); // Q15 FOR( i = 0; i < L_frame; i++ ) { @@ -383,11 +376,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( c, lf_deemph_factors[i] ); + tmp = L_mult( c, lf_deemph_factors[i] ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 4f44dab85..4a68a49c2 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -35,9 +35,10 @@ Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; @@ -97,13 +98,13 @@ Word16 ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; - move16(); start_bit_pos = st->next_bit_pos; @@ -143,7 +144,6 @@ ReadTnsData_ivas_fx( move16(); *pnBits = sub( st->next_bit_pos, start_bit_pos ); - #ifdef IVAS_CODE return; #else @@ -159,8 +159,8 @@ ReadTnsData_ivas_fx( Word16 DecodeTnsData( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; @@ -215,8 +215,8 @@ Word16 DecodeTnsData( Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d601c6fa2..48e175a43 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -114,8 +114,8 @@ ivas_error ivas_core_enc( Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 *new_swb_speech_fx1; - Word16 new_swb_speech_buffer_fx1[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word16 *new_swb_speech_fx_16; + Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions @@ -140,6 +140,9 @@ ivas_error ivas_core_enc( Word16 i; #endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) { @@ -906,7 +909,7 @@ ivas_error ivas_core_enc( new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; #ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; - new_swb_speech_fx1 = new_swb_speech_buffer_fx1 + STEREO_DFT_OVL_MAX; + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; #endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) @@ -916,7 +919,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; + // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); @@ -963,7 +966,7 @@ ivas_error ivas_core_enc( } #endif #endif - swb_pre_proc_ivas_fx( st, new_swb_speech_16_fx, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -973,7 +976,7 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); - fixedToFloat_arr( new_swb_speech_16_fx, new_swb_speech, 0, L_FRAME48k ); + fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); @@ -1153,7 +1156,7 @@ ivas_error ivas_core_enc( for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) { - new_swb_speech_buffer_fx1[ii] = (Word16) new_swb_speech_buffer[ii]; + new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; } for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) { @@ -1161,7 +1164,7 @@ ivas_error ivas_core_enc( } #endif /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx1, shb_speech_fx, q_shb_speech_fx, q_val ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, q_shb_speech_fx, q_val ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_FD != NULL ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 3cdbd36a0..b84e82262 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2128,6 +2128,9 @@ ivas_error pre_proc_front_ivas_fx( } stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); + + free( old_inp_12k8_loc_fx ); + #endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 7891a753b..2a10d92d7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -138,6 +138,21 @@ ivas_error ivas_dirac_enc_open( } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } +#endif } hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); @@ -426,6 +441,10 @@ void ivas_dirac_enc_close( { free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; +#endif } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) @@ -456,6 +475,10 @@ void ivas_dirac_enc_close( free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; +#endif } free( hDirAC->buffer_energy ); @@ -505,7 +528,159 @@ ivas_error ivas_dirac_enc( ivas_error error; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- float to fixed ----------------------------------------------*/ + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + Word16 block_m_idx; + Word16 band_m_idx; + Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; + Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); + hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); + hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; + } + } + + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } +#endif + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- fixed to float ----------------------------------------------*/ + for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + if ( hodirac_flag ) + { + hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + } + } + } + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) + { + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + } + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + } + } + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); + me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); + } + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < N_bands; k++ ) + { + hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); + } + } +#endif + if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -1400,9 +1575,10 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const UWord8 useLowerRes, - float *data_f[], - float **pp_fr_real, - float **pp_fr_imag, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, const Word16 input_frame, const IVAS_FORMAT ivas_format, const Word16 hodirac_flag, @@ -1410,116 +1586,31 @@ void ivas_dirac_param_est_enc( Word16 *mono_frame_count, Word16 *dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - Word32 **pp_fr_real_fx; - Word32 **pp_fr_imag_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Assign memory */ - Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - } - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); - max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - /* Float to fixed */ - pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - for ( int i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - for ( int j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); - } - } -#endif - - Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED Word32 dir_v_fx[DIRAC_NUM_DIMS]; -#endif - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) - { - set_zero( Cldfb_RealBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - set_zero( Cldfb_ImagBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - } -#endif - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; -#ifdef IVAS_FLOAT_FIXED Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 intensity_real_q = 0; + Word16 intensity_real_q; Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 direction_vector_q = 0; + Word16 direction_vector_q; Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; - Word16 diffuseness_vector_q = 0; - move16(); - move16(); - move16(); -#endif - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q; Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word16 renormalization_factor_exp; Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; - float norm_tmp; + Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS]; + Word32 norm_tmp_fx; + Word16 norm_tmp_exp; Word16 mrange[2]; Word16 num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word16 reference_power_exp; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; @@ -1534,6 +1625,12 @@ void ivas_dirac_param_est_enc( /* Initialization */ cldfb_q = 0; move16(); + intensity_real_q = 0; + move16(); + direction_vector_q = 0; + move16(); + diffuseness_vector_q = 0; + move16(); l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) @@ -1553,7 +1650,11 @@ void ivas_dirac_param_est_enc( /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands ); set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands ); + reference_power_exp = 0; + move16(); set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); @@ -1563,168 +1664,45 @@ void ivas_dirac_param_est_enc( set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* assign memory */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] = data_f_fx[i]; p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; } -#if 1 - /* using void temporarily to avoid null */ - (void) p_Cldfb_RealBuffer_fx; - (void) p_Cldfb_ImagBuffer_fx; - (void) p_Cldfb_RealBuffer; - (void) p_Cldfb_ImagBuffer; - (void) pcm_in_fx; - (void) pcm_in; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Fixed to float */ - fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); -#endif - -#else - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; - float norm_tmp; - int16_t mrange[2]; - int16_t num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - - push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; - - /* Initialization */ - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - if ( useLowerRes ) - { - q_direction->cfg.nblocks = 1; - num_blocks = 1; - } - else - { - q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - renormalization_factor_diff[i] = 0; - hDirAC->diffuseness_m[i] = 0; - } - - set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { -#ifdef IVAS_FLOAT_FIXED mrange[0] = hDirAC->block_grouping[block_m_idx]; move16(); mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; move16(); set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + renormalization_factor_exp = 0; + move16(); set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + hDirAC->direction_vector_m_exp[block_m_idx] = 0; + move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); -#endif + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + IF( hDirAC->hFbMixer ) + { + ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); -#else - mrange[0] = hDirAC->block_grouping[block_m_idx]; - mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; - - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - renormalization_factor[band_m_idx] = EPSILON; - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; - } -#endif - - for ( ts = mrange[0]; ts < mrange[1]; ts++ ) - { - if ( hDirAC->hFbMixer ) - { -#ifdef IVAS_FLOAT_FIXED - ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); - - ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] += l_ts; } -#else - ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] += l_ts; - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } FOR( i = 0; i < nchan_fb_in; i++ ) { Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); @@ -1732,94 +1710,31 @@ void ivas_dirac_param_est_enc( } cldfb_q = pp_fr_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); - fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); - } -#endif -#else - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - computeReferencePower_enc( - hDirAC->band_grouping, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - reference_power[ts], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - ivas_format, - hodirac_flag ? 0 : 1, - FOA_CHANNELS, - mono_frame_count, - dirac_mono_flag ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_Cldfb = 31; - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Q_Cldfb = s_min( Q_Cldfb, Q_factor_L( Cldfb_RealBuffer[x][k] ) ); - } - } - Word16 guard = find_guarded_bits_fx( 16 ) / 2; // Guard bits to avoid the precision loss for the reference_power - Word16 e_reference; - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_RealBuffer[k], Cldfb_RealBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_ImagBuffer[k], Cldfb_ImagBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Cldfb_RealBuffer_fx[x][k] = L_shr( Cldfb_RealBuffer_fx[x][k], guard ); - Cldfb_ImagBuffer_fx[x][k] = L_shr( Cldfb_ImagBuffer_fx[x][k], guard ); - } } - Q_Cldfb = sub( Q_Cldfb, guard ); - Word16 hodirac_flag_temp = 1; + Word16 ref_power_w = 1; + move16(); IF( hodirac_flag ) { - hodirac_flag_temp = 0; + ref_power_w = 0; + move16(); } -#endif + computeReferencePower_enc_fx_dirac( hDirAC->band_grouping, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - sub( 31, Q_Cldfb ), + sub( 31, cldfb_q ), reference_power_fx[ts], - &e_reference, + &reference_power_exp, hDirAC->hConfig->enc_param_start_band, num_freq_bands, ivas_format, - hodirac_flag_temp, + ref_power_w, FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( reference_power_fx[ts], reference_power[ts], 31 - e_reference, DIRAC_NO_FB_BANDS_MAX ); -#endif -#endif -#ifdef IVAS_FLOAT_FIXED computeIntensityVector_enc_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -1828,29 +1743,10 @@ void ivas_dirac_param_est_enc( num_freq_bands, intensity_real_fx ); - // intensity_real_q = 2 * Q_Cldfb + 1 - 32; - intensity_real_q = sub( shl( Q_Cldfb, 1 ), 31 ); - move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( intensity_real_fx[i], intensity_real[i], intensity_real_q, num_freq_bands ); - } -#endif -#else - computeIntensityVector_enc( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - intensity_real ); -#endif + intensity_real_q = sub( shl( cldfb_q, 1 ), 31 ); // 2 * Q_Cldfb + 1 - 32; - if ( !hodirac_flag ) + IF( !hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], @@ -1864,153 +1760,71 @@ void ivas_dirac_param_est_enc( direction_vector_q = Q30; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( direction_vector_fx[i], direction_vector[i], direction_vector_q, num_freq_bands ); - } -#endif -#else - computeDirectionVectors( - intensity_real[0], - intensity_real[1], - intensity_real[2], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - direction_vector[0], - direction_vector[1], - direction_vector[2] ); -#endif } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ - Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; - Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - max_val = 0; - Word32 tmp32; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - float tmpf; - maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); - max_val = fmaxf( max_val, tmpf ); - } - Word16 intensity_real_exp; - f2me( max_val, &tmp32, &intensity_real_exp ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( int j = 0; j < num_freq_bands; j++ ) - { - intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); - } - } - f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); -#endif /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - assert( index <= MAX_NUM_INDEX_INTENSITY ); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); } - Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); + + Word16 buffer_intensity_real_single_q; + buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0]; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); - } - me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); -#endif -#else - /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ - index = hDirAC->index_buffer_intensity; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - /* only real part needed */ - mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } } - mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); -#endif - - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 buffer_intensity_real_q = 0; - float max_buffer_intensity_real_val = 0; - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { - for ( int k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - max_buffer_intensity_real_val = max( max_buffer_intensity_real_val, (float) fabs( hDirAC->buffer_intensity_real[j][i][k] ) ); + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + move32(); + hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; + move16(); } } } - Word32 tmp_var = 0; - Word16 buffer_intensity_real_buff_e = 0; - f2me( (float) fabs( max_buffer_intensity_real_val ), &tmp_var, &buffer_intensity_real_buff_e ); - buffer_intensity_real_q = sub( 31, buffer_intensity_real_buff_e ); - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + Word16 buffer_energy_single_q; + Word16 buffer_len; + buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff ); + minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); + FOR( i = 0; i < buffer_len; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) - { - floatToFixed_arrL( hDirAC->buffer_intensity_real[j][i], hDirAC->buffer_intensity_real_fx[j][i], buffer_intensity_real_q, num_freq_bands ); - } + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + move32(); + hDirAC->buffer_energy_q[i] = buffer_energy_single_q; + move16(); } - Word16 buffer_energy_e = 0; - Word16 buffer_energy_q = 0; - move16(); - move16(); - f2me_buf( hDirAC->buffer_energy, hDirAC->buffer_energy_fx, &buffer_energy_e, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - buffer_energy_q = sub( 31, buffer_energy_e ); -#endif - Word16 *buffer_energy_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - Word16 *buffer_intensity_real_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - set16_fx( buffer_energy_buff_q, buffer_energy_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - set16_fx( buffer_intensity_real_buff_q, buffer_intensity_real_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; - computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, buffer_intensity_real_buff_q, buffer_energy_buff_q, &diffuseness_vector_q ); + set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len ); + set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( diffuseness_vector_fx, diffuseness_vector, diffuseness_vector_q, num_freq_bands ); -#endif - free( buffer_energy_buff_q ); - buffer_energy_buff_q = NULL; - free( buffer_intensity_real_buff_q ); - buffer_intensity_real_buff_q = NULL; -#else - computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); -#endif + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q ); - if ( hodirac_flag ) + IF( hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( int j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } -#endif calculate_hodirac_sector_parameters_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -2026,189 +1840,188 @@ void ivas_dirac_param_est_enc( diff_secs_exp, ene_secs_fx, ene_secs_exp ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - azi_secs[i_sec * N_bands + i_band] = fix_to_float( azi_secs_fx[i_sec * N_bands + i_band], Q23 ); - ele_secs[i_sec * N_bands + i_band] = fix_to_float( ele_secs_fx[i_sec * N_bands + i_band], Q23 ); - ene_secs[i_sec * N_bands + i_band] = me2f( ene_secs_fx[i_sec * N_bands + i_band], ene_secs_exp[i_sec * N_bands + i_band] ); - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - diff_secs[i_sec * N_bands + i_band] = me2f( diff_secs_fx[i_sec * N_bands + i_band], diff_secs_exp[i_sec * N_bands + i_band] ); - } - } -#endif - -#else - calculate_hodirac_sector_parameters( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - 0.20f, - hDirAC->band_grouping, - hDirAC->hConfig->nbands, - hDirAC->hConfig->enc_param_start_band, - azi_secs, - ele_secs, - diff_secs, - ene_secs ); -#endif } - if ( hodirac_flag ) + const Word16 gbits = 4; // 4 guard bits + move16(); + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } } - else + ELSE { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); - - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; - renormalization_factor[band_m_idx] += norm_tmp; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + move32(); + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } + norm_tmp_exp = add( reference_power_exp, 1 ); + hDirAC->direction_vector_m_exp[block_m_idx] = add( norm_tmp_exp, add( sub( 31, direction_vector_q ), gbits ) ); + move32(); + renormalization_factor_exp = add( norm_tmp_exp, gbits ); } } - if ( !hodirac_flag ) + IF( !hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - renormalization_factor[band_m_idx] = EPSILON; - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) - { - renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); - } - renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + renormalization_factor_fx[band_m_idx] = EPSILON_FX; + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp + renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); + move32(); - if ( renormalization_factor[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + Word16 tmp_e; + Word32 tmp32; + + tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); } - else + ELSE { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30; + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move32(); } + hDirAC->direction_vector_m_exp[block_m_idx] = 1; + move16(); /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30 + move32(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_dir_e = 0; - f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); -#endif - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, - Q31 - q_dir_e, + Q30, &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); -#endif -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( - dir_v, - &q_direction->band_data[band_m_idx].azimuth[block_m_idx], - &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); -#endif } } /* Sectors */ - if ( hodirac_flag ) + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; - q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; - // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); - } - } - } + q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); + Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); -#ifdef IVAS_FLOAT_FIXED - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) - { - free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + Word16 tmp16 = extract_h( L_add( x, y ) ); + Word32 tmp32; + IF( tmp16 == 0 ) + { + tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + } + ELSE + { + tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + } + tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 + } + } } - free( hDirAC->direction_vector_m_fx[0] ); - free( hDirAC->direction_vector_m_fx[1] ); - free( hDirAC->direction_vector_m_fx[2] ); -#endif /* Diffuseness */ - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + Word16 tmp_e; + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 + move32(); } - else + ELSE { - hDirAC->diffuseness_m[band_m_idx] = 0.f; + hDirAC->diffuseness_m_fx[band_m_idx] = 0; + move32(); } + hDirAC->diffuseness_m_exp[band_m_idx] = 1; + move16(); /* set coherence to zero and convert diffuseness to energy ratio*/ - set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks ); - for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) { - if ( q_direction->coherence_band_data != NULL ) + IF( q_direction->coherence_band_data != NULL ) { q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + move16(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - free( data_f_fx[i] ); - free( pp_fr_real_fx[i] ); - free( pp_fr_imag_fx[i] ); - } - free( pp_fr_real_fx ); - free( pp_fr_imag_fx ); -#endif - pop_wmops(); return; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index aecf4c9a9..f8787ab7d 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -2128,9 +2128,14 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef MSAN_FIX + q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], st->hTcxEnc->L_frameTCX / ( n + 1 ) ); + floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, st->hTcxEnc->L_frameTCX / ( n + 1 ) ); +#else Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], l_frame ); floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, l_frame ); +#endif #endif bw_detect_fx( st, NULL, spect_fx[n], NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6777a8527..2ba611679 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -861,8 +861,15 @@ static ivas_error ivas_spar_cov_md_process( move32(); FOR( i = 1; i < nchan_inp; i++ ) { - Word32 tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); - tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + Word32 tmp = 0; + move32(); + tmp_e = 0; + move16(); + IF( cov_real_fx[0][0][b] != 0 ) + { + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + } Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); move32(); } @@ -1125,9 +1132,9 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - FOR( Word16 m = 0; m < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; m++ ) + FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) { - IF( data_f[m] != NULL && ( m <= nchan_fb_in + nchan_transport ) ) + IF( data_f[m] != NULL ) { q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); @@ -1325,9 +1332,73 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 mixer_q = 31; + Word16 prior_mixer_q = 31; + Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + + mixer_q = s_min( mixer_q, prior_mixer_q ); + // both should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + + hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; +#endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); + } + } + + // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + // should be same + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); + } + } +#endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { @@ -1337,7 +1408,7 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) { float new_w[L_FRAME48k]; - + Word32 new_w_fx[L_FRAME48k]; /* delayed W */ mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); @@ -1347,11 +1418,47 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } } else diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 13c9bdc0a..357e52230 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -299,6 +299,7 @@ ivas_error ivas_spar_md_enc_open_fx( * Deallocate SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) @@ -331,12 +332,80 @@ void ivas_spar_md_enc_close( } free( hMdEnc->mixer_mat ); } +#ifdef IVAS_FLOAT_FIXED + IF( hMdEnc->mixer_mat_fx != NULL ) + { + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_fx[i][j] ); + } + free( hMdEnc->mixer_mat_fx[i] ); + } + free( hMdEnc->mixer_mat_fx ); + } +#endif free( *hMdEnc_in ); *hMdEnc_in = NULL; return; } +#else +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +{ + int16_t num_channels, i, j; + ivas_spar_md_enc_state_t *hMdEnc; + + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + + hMdEnc = *hMdEnc_in; + num_channels = hMdEnc->num_umx_ch; + + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } + if ( hMdEnc->mixer_mat != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat[i][j] ); + } + free( hMdEnc->mixer_mat[i] ); + } + free( hMdEnc->mixer_mat ); + } + + if ( hMdEnc->mixer_mat_local != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_local[i][j] ); + } + free( hMdEnc->mixer_mat_local[i] ); + } + free( hMdEnc->mixer_mat_local ); + } + + free( *hMdEnc_in ); + *hMdEnc_in = NULL; + + return; +} +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 746d5712a..4c3eca4d9 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -942,8 +942,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; @@ -979,7 +981,9 @@ typedef struct ivas_dirac_enc_data_structure float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; #endif /* Frame count for detecting mono */ @@ -1061,7 +1065,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; Word32 ***mixer_mat_fx; Word16 q_mixer_mat_fx; - Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index de6cafa55..b8c891d3c 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -567,7 +567,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx, new_swb_speech, q_reImBuffer, L_FRAME48k ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } -- GitLab