From ee1e477ea762cdd35243195dd1659b17a0b47866 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 6 Mar 2024 13:46:05 +0530 Subject: [PATCH] Few fixed point converted functions included in call-stack [x] stereo_dft_sg_recovery_fx,rc_uni_dec_init_fx,rc_uni_dec_read_symbol_fastS_fx added in call-stack. [x] Added fix for overflow occuring in rc_uni_dec_read_symbol_fastS_fx [x] Added fix for overflow observed in stereo_dft_sg_recovery_fx --- lib_com/ivas_prot.h | 5 +++ lib_dec/ivas_jbm_dec.c | 33 ++++++++++++++++++++ lib_dec/ivas_mc_param_dec.c | 9 ++++++ lib_dec/ivas_range_uni_dec.c | 2 +- lib_dec/ivas_stereo_dft_dec.c | 10 ++++++ lib_dec/ivas_stereo_dft_plc_fx.c | 3 +- lib_dec/ivas_stereo_eclvq_dec.c | 6 ++-- lib_rend/ivas_dirac_dec_binaural_functions.c | 29 +++++++++++++++++ lib_rend/ivas_prot_rend.h | 7 +++++ 9 files changed, 99 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6d9163fb5..021e9762b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1551,6 +1551,11 @@ float stereo_dft_dmx_swb_nrg( const int16_t frame_length /* i : frame lanegth */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 stereo_dft_sg_recovery_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ +); +#endif int16_t stereo_dft_sg_recovery( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ ); diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 1a9ced035..b574152f3 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -507,7 +507,40 @@ ivas_error ivas_jbm_dec_tc( else if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) { /* loudness correction */ +#ifdef IVAS_FLOAT_FIXED + Word32 *p_output_fx[12]; + for ( int lp = 0; lp < st_ivas->nchan_transport; lp++ ) + { + if ( p_output[lp] != NULL ) + { + p_output_fx[lp] = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); + } + } + Word16 Q_p_output = 31; + for ( int i = 0; i< st_ivas->nchan_transport; i++ ) + { + Q_p_output = s_min( Q_p_output, Q_factor_arrL( p_output[i], output_frame) ); + } + for ( int i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( p_output[i], p_output_fx[i], Q_p_output, output_frame); + } + ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, st_ivas->nchan_transport, output_frame );/*returns Q-1*/ + Q_p_output = Q_p_output - 1; + for ( int i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q_p_output, output_frame); + } + for ( int lp = 0; lp < st_ivas->nchan_transport; lp++ ) + { + if ( p_output_fx[lp] != NULL ) + { + free( p_output_fx[lp] ); + } + } +#else ivas_dirac_dec_binaural_sba_gain( p_output, st_ivas->nchan_transport, output_frame ); +#endif // IVAS_FLOAT_FIXED } } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e4621731c..88e018d42 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -2299,13 +2299,22 @@ static int16_t ivas_param_mc_range_decoder_LC( /* Start Decoding */ /* Initialize range decoder */ cur_bit_pos = 0; +#ifdef IVAS_FLOAT_FIXED + rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ +#else rc_uni_dec_init( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ +#endif // IVAS_FLOAT_FIXED /* Main Loop through the indices */ for ( k = 0; k < sz_seq; k++ ) { +#ifdef IVAS_FLOAT_FIXED + r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ + /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ +#else r = rc_uni_dec_read_symbol_fastS( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ +#endif // IVAS_FLOAT_FIXED /* Update bitstream pointer */ cur_bit_pos = rc_uni_dec_virtual_finish( &rc_st_dec ); diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index cf5c1867b..1e426869a 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -256,7 +256,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( { sym_middle = shr(add( sym_begin , sym_end ) , 1); /* completely equvalent with low >= range * ((1 << tot_shift) - table[sym_middle]) */ - IF ( range * sub( shl( 1 , tot_shift ) , cum_freq_table[sym_middle] ) >= reversed_low ) + IF ( range * L_sub( L_shl( 1 , tot_shift ) , cum_freq_table[sym_middle] ) >= reversed_low ) { sym_begin = sym_middle; } diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 195ab3ace..f102baacd 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -3044,7 +3044,13 @@ void stereo_dft_dec_read_BS( if ( ivas_total_brate > IVAS_SID_5k2 ) { +#ifdef IVAS_FLOAT_FIXED + floatToFixed_arrL( hStereoDft->side_gain, hStereoDft->side_gain_fx, 31, 39 ); + hStereoDft->recovery_flg = stereo_dft_sg_recovery_fx( hStereoDft ); + hStereoDft->sg_mean = fixedToFloat( hStereoDft->sg_mean_fx, 31 ); +#else hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); +#endif // IVAS_FLOAT_FIXED if ( hStereoDft->recovery_flg ) { @@ -3075,7 +3081,11 @@ void stereo_dft_dec_read_BS( ECSQ_init_instance( &ecsq_inst, 0 /*dummy index*/, &range_uni_dec_state ); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED + rc_uni_dec_init_fx( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); +#else rc_uni_dec_init( &range_uni_dec_state, bit_stream_side + *nb_bits, max_bits - *nb_bits ); +#endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED Word32 res_global_gain_fx; diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 9d3ba36d8..17b50c5f3 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -986,10 +986,11 @@ Word16 stereo_dft_sg_recovery_fx( sg_m = EPSILON_FIX; FOR ( b = 0; b < hStereoDft->nbands; b++ ) { - sg_m = L_add(sg_m , pSideGain[b]); + sg_m = L_add_sat(sg_m , L_shr(pSideGain[b],5)); } sg_m /= hStereoDft->nbands; + sg_m = L_shl_sat( sg_m, 5 ); IF ( LT_32(sg_m , (Word32)0x4CCCCCCD) && GT_32(sg_m , (Word32)(0xB3333333) )) { hStereoDft->sg_mean_fx = 0; diff --git a/lib_dec/ivas_stereo_eclvq_dec.c b/lib_dec/ivas_stereo_eclvq_dec.c index 5b969ac32..0e3cdc467 100644 --- a/lib_dec/ivas_stereo_eclvq_dec.c +++ b/lib_dec/ivas_stereo_eclvq_dec.c @@ -152,7 +152,7 @@ static Word16 arith_decode_prob_escape( { Word16 symbol; - symbol = rc_uni_dec_read_symbol_fastS( rc_st_dec, cum_freq_table, sym_freq_table, table_size, ECSQ_PROB_BITS ); + symbol = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_table, sym_freq_table, table_size, ECSQ_PROB_BITS ); IF( EQ_16( symbol, sub( table_size, 1 ) ) ) /* escape symbol */ { @@ -300,7 +300,7 @@ void ECSQ_decode( seg_start = shl( segment, 3 ); seg_stop = sub( s_min( add( seg_start, ECSQ_SEGMENT_SIZE ), N ), 1 ); - param_zb = rc_uni_dec_read_symbol_fastS( rc_st_dec, cum_freq_ECSQ_tab_param[ecsq_inst->config_index], sym_freq_ECSQ_tab_param[ecsq_inst->config_index], ECSQ_PARAM_COUNT, ECSQ_PROB_BITS ); + param_zb = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, cum_freq_ECSQ_tab_param[ecsq_inst->config_index], sym_freq_ECSQ_tab_param[ecsq_inst->config_index], ECSQ_PARAM_COUNT, ECSQ_PROB_BITS ); shift = s_max( 0, sub( param_zb, 3 ) ); /* first nonzero shift of 1 is used for param 3 */ IF( NE_16( param_zb, 0 ) ) /* not the ECSQ_ALL_ZERO_PARAM param */ @@ -323,7 +323,7 @@ void ECSQ_decode( } ELSE /* (sym == 0) && (shift <= 4) */ { - lsbs = rc_uni_dec_read_symbol_fastS( rc_st_dec, tab_abs_lsbs_cum_freq, tab_abs_lsbs_sym_freq, shl( 1, shift ), ECSQ_PROB_BITS ); + lsbs = rc_uni_dec_read_symbol_fastS_fx( rc_st_dec, tab_abs_lsbs_cum_freq, tab_abs_lsbs_sym_freq, shl( 1, shift ), ECSQ_PROB_BITS ); } sym = s_or( shl( sym, shift ), lsbs ); } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 36bfa9bc3..dd558b22c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -539,6 +539,35 @@ void ivas_dirac_dec_binaural_render( * * loudness correction for parametric binaural renderer *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_binaural_sba_gain_fx( + Word32 *output[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame /* i : output frame length */ +) +{ + Word16 n; + Word16 gain;/*Q-14*/ + + IF ( EQ_16(nchan_remapped , 1) ) + { + gain = 23681; + move16(); + } + ELSE + { + gain = 22376; + move16(); + } + + FOR ( n = 0; n < nchan_remapped; n++ ) + { + v_multc_fixed_16( output[n], gain, output[n], output_frame ); + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_dirac_dec_binaural_sba_gain( float *output[], /* i/o: synthesized core-coder transport channels/DirAC output */ diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index a68896ef8..12ebdcf25 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -307,6 +307,13 @@ ivas_error ivas_sba_get_hoa_dec_matrix( const Word16 ambisonics_order /* i : Ambisonics order */ ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_binaural_sba_gain_fx( + Word32 *output[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame /* i : output frame length */ +); +#endif void ivas_dirac_dec_binaural_sba_gain( float *output[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ -- GitLab