From 057d940ac6c41e4cdb784743332f1431ee2771be Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 30 Jan 2025 20:18:46 +0530 Subject: [PATCH] Partial fix for Encoder saturating when copying vectors and q-doc, basops and instrumentation --- lib_com/ivas_prot.h | 57 ------------ lib_com/ivas_prot_fx.h | 43 ++++++--- lib_com/prot_fx.h | 5 ++ lib_com/tools_fx.c | 18 ++++ lib_enc/ACcontextMapping_enc_fx.c | 19 ++-- lib_enc/ivas_corecoder_enc_reconfig.c | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_init_enc.c | 7 +- lib_enc/ivas_mc_param_enc.c | 8 +- lib_enc/ivas_range_uni_enc.c | 39 +++++---- lib_enc/ivas_sba_enc.c | 7 +- lib_enc/ivas_sce_enc.c | 24 +++-- lib_enc/ivas_sns_enc.c | 7 +- lib_enc/ivas_spar_encoder.c | 57 +++++++----- lib_enc/ivas_spar_md_enc.c | 34 ++++---- lib_enc/ivas_stereo_adapt_GR_enc.c | 65 +++++++------- lib_enc/ivas_stereo_classifier.c | 56 +++++++----- lib_enc/ivas_stereo_cng_enc.c | 2 +- lib_enc/ivas_stereo_dft_enc.c | 16 ++-- lib_enc/ivas_stereo_eclvq_enc.c | 8 +- lib_enc/speech_music_classif_fx.c | 51 +++++++---- lib_enc/stat_enc.h | 5 +- lib_enc/swb_tbe_enc_fx.c | 121 +++++++++++++------------- 24 files changed, 346 insertions(+), 309 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b9f3688ab..5ea7b0765 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -83,12 +83,6 @@ ivas_error create_sce_enc( const int32_t element_brate /* i : element bitrate */ ); -ivas_error create_evs_sce_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t sce_id, /* i : SCE # identifier */ - const int32_t element_brate /* i : element bitrate */ -); - ivas_error create_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ @@ -99,15 +93,6 @@ ivas_error create_mct_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -ivas_error ivas_sba_enc_reconfigure( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); - -void destroy_sce_enc( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - Flag is_evs /* i : Flag to indicate EVS encoder */ -); - void destroy_cpe_enc( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); @@ -1215,41 +1200,6 @@ void add_HB_to_mono_dmx( * Range Coder prototypes *----------------------------------------------------------------------------------*/ -void rc_uni_enc_init( - RangeUniEncState *rc_st_enc /* i/o: RC state handle */ -); - -void rc_uni_enc_encode_fast( - RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ - const uint16_t cum_freq, /* i : Cumulative frequency up to symbol */ - const uint16_t sym_freq, /* i : Symbol frequency */ - const uint16_t tot_shift /* i : Total frequency as a power of 2 */ -); - -void rc_uni_enc_encode_symbol_fastS( - RangeUniEncState *rc_st_enc, /* i/o: Encoder state */ - const uint16_t symbol, /* i : Symbol to encode */ - const uint16_t cum_freq[], /* i : Cumulative frequency up to symbol */ - const uint16_t sym_freq[], /* i : Symbol frequency */ - const uint16_t tot_shift /* i : Total frequency as a power of 2 */ -); - -void rc_uni_enc_encode_bits( - RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ - const uint16_t value, /* i : Value to encode */ - const int16_t bits /* i : Number of bits */ -); - -/*! r: Total number of bits produced */ -int16_t rc_uni_enc_virtual_finish( - RangeUniEncState *rc_st_enc /* i : RC state handle */ -); - -/*! r: Total number of bits produced */ -int16_t rc_uni_enc_finish( - RangeUniEncState *rc_st_enc /* i/o: RC state handle */ -); - void rc_uni_dec_init( RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ uint16_t *bit_buffer, /* i : Bit buffer */ @@ -1403,13 +1353,6 @@ void stereo_icBWE_decproc( * Stereo classifiers prototypes *----------------------------------------------------------------------------------*/ -/*! r: element mode */ -int16_t select_stereo_mode( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ -); - - void stereo_classifier_features( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const int16_t idchan, /* i : channel ID */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f44454c87..5ce037b9a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -53,6 +53,17 @@ void ivas_masa_dec_close_fx( MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); +ivas_error create_evs_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + +void destroy_sce_enc_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + Flag is_evs /* i : Flag to indicate EVS encoder */ +); + void generate_gridEq_fx( SPHERICAL_GRID_DATA *data /* o : data structure for grid */ ); @@ -2801,18 +2812,18 @@ Word16 mdct_classifier_ivas_fx( * Range Coder prototypes *----------------------------------------------------------------------------------*/ -void rc_uni_enc_init( +void rc_uni_enc_init_fx( RangeUniEncState *rc_st_enc /* i/o: RC state handle */ ); -void rc_uni_enc_encode_fast( +void rc_uni_enc_encode_fast_fx( RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ const UWord16 cum_freq, /* i : Cumulative frequency up to symbol */ const UWord16 sym_freq, /* i : Symbol frequency */ const UWord16 tot_shift /* i : Total frequency as a power of 2 */ ); -void rc_uni_enc_encode_symbol_fastS( +void rc_uni_enc_encode_symbol_fastS_fx( RangeUniEncState *rc_st_enc, /* i/o: Encoder state */ const UWord16 symbol, /* i : Symbol to encode */ const UWord16 cum_freq[], /* i : Cumulative frequency up to symbol */ @@ -2821,16 +2832,16 @@ void rc_uni_enc_encode_symbol_fastS( ); /*! r: Total number of bits produced */ -Word16 rc_uni_enc_finish( +Word16 rc_uni_enc_finish_fx( RangeUniEncState *rc_st_enc /* i/o: RC state handle */ ); /*! r: Total number of bits produced */ -Word16 rc_uni_enc_virtual_finish( +Word16 rc_uni_enc_virtual_finish_fx( RangeUniEncState *rc_st_enc /* i : RC state handle */ ); -void rc_uni_enc_encode_bits( +void rc_uni_enc_encode_bits_fx( RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ const UWord16 value, /* i : Value to encode */ const Word16 bits /* i : Number of bits */ @@ -3097,6 +3108,12 @@ void ivas_smc_mode_selection_fx( const Word16 flag_spitch /* i : flag to indicate very short stable pitch*/ ); +/*! r: element mode */ +Word16 select_stereo_mode_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ +); + void stereo_classifier_features_ivas_fx( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 idchan, /* i : channel ID */ @@ -4278,7 +4295,7 @@ void stereo_dft_dec_read_BS_fx( const Word16 ivas_format /* i : ivas format Q0*/ ); -Word16 write_bitstream_adapt_GR( +Word16 write_bitstream_adapt_GR_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : values to be written in bitstream */ @@ -4304,7 +4321,7 @@ Word16 adapt_GR_ief_fx( const Word16 try_diff /* i : diff coding allowed 1/0 */ ); -Word16 adapt_GR_rpg1_ief( +Word16 adapt_GR_rpg1_ief_fx( const Word16 *in, /* i : res pred gains input vector */ Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ const Word16 *prev, /* i : previous frame data */ @@ -4318,14 +4335,14 @@ Word16 adapt_GR_rpg1_ief( const Word16 try_diff /* i : diff coding allowed 1/0 */ ); -Word16 write_GR1( +Word16 write_GR1_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : data to be encoded */ const Word16 len /* i : input data length */ ); -Word16 write_bitstream_GR( +Word16 write_bitstream_GR_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : input vector */ @@ -4757,7 +4774,7 @@ void stereo_mdct2dft_update_fx( Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ ); -Word16 write_GR0( +Word16 write_GR0_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : data to be encoded */ @@ -4856,6 +4873,10 @@ ivas_error ivas_cldfb_dec_reconfig_fx( const Word16 numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */ ); +ivas_error ivas_sba_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + Word16 ivas_sba_get_order_fx( const Word16 nb_channels, /* i : Number of ambisonic channels */ const Word16 sba_planar /* i : SBA planar flag */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 53e6adb14..3c2b1395c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -218,6 +218,11 @@ Word32 sum2_fx( /* o : sum of all squared vector elements const Word16 lvec /* i : length of i vector */ ); +Word64 sum2_fx_no_sat( /* o : sum of all squared vector elements Q(2x)*/ + const Word16 *vec, /* i : i vector Qx*/ + const Word16 lvec /* i : length of i vector */ +); + Word16 sign_fx( const Word32 x /* i : input value of x */ ); diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index a8e1b0da0..704b44b84 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -401,6 +401,24 @@ Word32 sum2_fx( /* o : sum of all squared vector elements return L_tmp; } +Word64 sum2_fx_no_sat( /* o : sum of all squared vector elements Q(2*Qx)*/ + const Word16 *vec, /* i : input vector Qx*/ + const Word16 lvec /* i : length of input vector */ +) +{ + Word16 i; + Word64 sum; + + sum = 0; + move64(); + FOR( i = 0; i < lvec; i++ ) + { + sum = W_mac0_16_16( sum, vec[i], vec[i] ); // 2*Qx + } + + return sum; +} + Word32 sum_32_fx( const Word32 *vec, /* i : input vector */ const Word16 lvec, /* i : length of input vector */ diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index bae267901..08baa4f3d 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -841,7 +841,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( /*Start Encoding*/ /* Initialize range encoder */ - rc_uni_enc_init( &rc_st_enc ); + rc_uni_enc_init_fx( &rc_st_enc ); /*Main Loop through the 2-tuples*/ b1_i = -1; @@ -909,7 +909,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( { pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */ move16(); - rc_uni_enc_encode_symbol_fastS( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ + rc_uni_enc_encode_symbol_fastS_fx( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ *lsbs_bits-- = s_and( a1, 1 ); *lsbs_bits-- = s_and( b1, 1 ); @@ -927,7 +927,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */ move16(); - rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ + rc_uni_enc_encode_symbol_fastS_fx( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ @@ -1009,7 +1009,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( /*Start Encoding*/ /* Initialize range encoder */ - rc_uni_enc_init( &rc_st_enc ); + rc_uni_enc_init_fx( &rc_st_enc ); /*Main Loop through the 2-tuples*/ FOR( k = 0; k < lastnz; k += 2 ) @@ -1064,7 +1064,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( { pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; move16(); - rc_uni_enc_encode_symbol_fastS( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ + rc_uni_enc_encode_symbol_fastS_fx( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */ *lsbs_bits-- = s_and( a1, 1 ); *lsbs_bits-- = s_and( b1, 1 ); @@ -1082,8 +1082,9 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( } move16(); - pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */ - rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ + + pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */ + rc_uni_enc_encode_symbol_fastS_fx( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */ /*Confirm that there is no overflow, i.e. bit-budget has not exceeded */ @@ -1105,8 +1106,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( } /* Finish range encoder */ - rc_tot_bits = rc_uni_enc_finish( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ - bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ + rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ + bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ /* Cross-check that there is no overflow */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 4e087ab8d..847cdd0f6 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -339,7 +339,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( q_input_buff[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32; move16(); } - destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); + destroy_sce_enc_fx( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); st_ivas->hSCE[sce_id] = NULL; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c06346e82..5f04dc87f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -262,7 +262,7 @@ ivas_error ivas_cpe_enc_fx( test(); IF( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); /* Q0 */ + hCPE->element_mode = select_stereo_mode_fx( hCPE, ivas_format ); } stereo_mode_combined_format_enc_fx( st_ivas, hCPE ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 95cafd8ff..a7fb71461 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -135,7 +135,7 @@ ivas_error ivas_enc_fx( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_enc_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index d6a3597bd..7a499ce67 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -36,6 +36,7 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "ivas_stat_enc.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -608,7 +609,7 @@ ivas_error ivas_init_encoder( } ELSE { - IF( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_evs_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -1209,7 +1210,7 @@ ivas_error ivas_init_encoder_fx( test(); IF( st_ivas->hEncoderConfig->element_mode_init == EVS_MONO ) { - IF( ( error = create_evs_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_evs_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -2010,7 +2011,7 @@ void ivas_destroy_enc_fx( { if ( st_ivas->hSCE[i] != NULL ) { - destroy_sce_enc( st_ivas->hSCE[i], EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ); + destroy_sce_enc_fx( st_ivas->hSCE[i], EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ); st_ivas->hSCE[i] = NULL; } } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 63b5862ca..0577df340 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -1979,14 +1979,14 @@ static void ivas_param_mc_range_encoder_fx( UWord16 *bits; /* Initialize range encoder */ - rc_uni_enc_init( &rc_st_enc ); + rc_uni_enc_init_fx( &rc_st_enc ); /* Main loop over the length of the sequence */ FOR( i = 0; i < num_symbols; ++i ) { - rc_uni_enc_encode_symbol_fastS( &rc_st_enc, (UWord16) seq_in[i], cum_freq, sym_freq, tot_shift ); + rc_uni_enc_encode_symbol_fastS_fx( &rc_st_enc, (UWord16) seq_in[i], cum_freq, sym_freq, tot_shift ); - IF( GT_16( rc_uni_enc_virtual_finish( &rc_st_enc ), max_nb_bits ) ) + IF( GT_16( rc_uni_enc_virtual_finish_fx( &rc_st_enc ), max_nb_bits ) ) { /* we alread have exceeded the maximum number of bits allowed, i.e. the uniform fallback */ *bit_pos = MAX_BITS_PER_FRAME; @@ -1995,7 +1995,7 @@ static void ivas_param_mc_range_encoder_fx( } /* Finish range encoder */ - rc_tot_bits = rc_uni_enc_finish( &rc_st_enc ); /* No. of bits consumed by range coder */ + rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder */ /* Push range coded bits from byte_buffer to bitstream */ diff --git a/lib_enc/ivas_range_uni_enc.c b/lib_enc/ivas_range_uni_enc.c index 5bb5118a1..a93f470f5 100644 --- a/lib_enc/ivas_range_uni_enc.c +++ b/lib_enc/ivas_range_uni_enc.c @@ -32,6 +32,7 @@ #include #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_stat_enc.h" #include "cnst.h" @@ -55,15 +56,15 @@ * Local function prototypes *-------------------------------------------------------------------*/ -static void rc_uni_enc_shift( RangeUniEncState *rc_st_enc ); +static void rc_uni_enc_shift_fx( RangeUniEncState *rc_st_enc ); /*-------------------------------------------------------------------* - * rc_uni_enc_init() + * rc_uni_enc_init_fx() * * Initalize the range encoder *-------------------------------------------------------------------*/ -void rc_uni_enc_init( +void rc_uni_enc_init_fx( RangeUniEncState *rc_st_enc /* i/o: RC state handle */ ) { @@ -91,7 +92,7 @@ void rc_uni_enc_init( * * Encode given cumulative frequency and frequency when total frequency is a power of 2 *-------------------------------------------------------------------*/ -void rc_uni_enc_encode_fast( +void rc_uni_enc_encode_fast_fx( RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ const UWord16 cum_freq, /* i : Cumulative frequency up to symbol */ const UWord16 sym_freq, /* i : Symbol frequency */ @@ -119,12 +120,12 @@ void rc_uni_enc_encode_fast( { rc_st_enc->rc_range = UL_lshl( rc_st_enc->rc_range, 8 ); move32(); - rc_uni_enc_shift( rc_st_enc ); + rc_uni_enc_shift_fx( rc_st_enc ); IF( LT_64( rc_st_enc->rc_range, 0x01000000 ) ) { rc_st_enc->rc_range = UL_lshl( rc_st_enc->rc_range, 8 ); move32(); - rc_uni_enc_shift( rc_st_enc ); + rc_uni_enc_shift_fx( rc_st_enc ); } } @@ -133,11 +134,11 @@ void rc_uni_enc_encode_fast( /*-------------------------------------------------------------------* - * rc_uni_enc_encode_symbol_fastS() + * rc_uni_enc_encode_symbol_fastS_fx() * * Encode an alphabet symbol when total frequency is a power of 2 *-------------------------------------------------------------------*/ -void rc_uni_enc_encode_symbol_fastS( +void rc_uni_enc_encode_symbol_fastS_fx( RangeUniEncState *rc_st_enc, /* i/o: Encoder state */ const UWord16 symbol, /* i : Symbol to encode */ const UWord16 cum_freq[], /* i : Cumulative frequency up to symbol */ @@ -145,18 +146,18 @@ void rc_uni_enc_encode_symbol_fastS( const UWord16 tot_shift /* i : Total frequency as a power of 2 */ ) { - rc_uni_enc_encode_fast( rc_st_enc, cum_freq[symbol], sym_freq[symbol], tot_shift ); + rc_uni_enc_encode_fast_fx( rc_st_enc, cum_freq[symbol], sym_freq[symbol], tot_shift ); return; } /*-------------------------------------------------------------------* - * rc_uni_enc_finish() + * rc_uni_enc_finish_fx() * * Finalize the range encoder *-------------------------------------------------------------------*/ /*! r: Total number of bits produced */ -Word16 rc_uni_enc_finish( +Word16 rc_uni_enc_finish_fx( RangeUniEncState *rc_st_enc /* i/o: RC state handle */ ) { @@ -186,7 +187,7 @@ Word16 rc_uni_enc_finish( WHILE( bits > 0 ) { - rc_uni_enc_shift( rc_st_enc ); + rc_uni_enc_shift_fx( rc_st_enc ); bits = sub( bits, 8 ); } @@ -245,7 +246,7 @@ Word16 rc_uni_enc_finish( * Get the total number of bits that would be produced by finalization *-------------------------------------------------------------------*/ /*! r: Total number of bits produced */ -Word16 rc_uni_enc_virtual_finish( +Word16 rc_uni_enc_virtual_finish_fx( RangeUniEncState *rc_st_enc /* i : RC state handle */ ) { @@ -278,11 +279,11 @@ Word16 rc_uni_enc_virtual_finish( /*-------------------------------------------------------------------* - * rc_uni_enc_shift() + * rc_uni_enc_shift_fx() * * Shift a byte out to bitstream (internal function) *-------------------------------------------------------------------*/ -static void rc_uni_enc_shift( +static void rc_uni_enc_shift_fx( RangeUniEncState *rc_st_enc /* i/o: RC state handle */ ) { @@ -326,11 +327,11 @@ static void rc_uni_enc_shift( /*-------------------------------------------------------------------* - * rc_uni_enc_encode_bits() + * rc_uni_enc_encode_bits_fx() * * Encode up to 16 bits with uniform probability *-------------------------------------------------------------------*/ -void rc_uni_enc_encode_bits( +void rc_uni_enc_encode_bits_fx( RangeUniEncState *rc_st_enc, /* i/o: RC state handle */ const UWord16 value, /* i : Value to encode */ const Word16 bits /* i : Number of bits */ @@ -355,12 +356,12 @@ void rc_uni_enc_encode_bits( { rc_st_enc->rc_range = UL_lshl( rc_st_enc->rc_range, 8 ); move32(); - rc_uni_enc_shift( rc_st_enc ); + rc_uni_enc_shift_fx( rc_st_enc ); IF( LT_64( rc_st_enc->rc_range, 0x01000000 ) ) { rc_st_enc->rc_range = UL_lshl( rc_st_enc->rc_range, 8 ); move32(); - rc_uni_enc_shift( rc_st_enc ); + rc_uni_enc_shift_fx( rc_st_enc ); } } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 0fe07179a..ef76d67c9 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -38,6 +38,7 @@ #include "ivas_cnst.h" #include "rom_com.h" #include "prot.h" +#include "ivas_prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -86,12 +87,12 @@ void ivas_sba_getTCs_fx( } /*-------------------------------------------------------------------* - * ivas_sba_enc_reconfigure() + * ivas_sba_enc_reconfigure_fx() * * Reconfigure IVAS SBA encoder *-------------------------------------------------------------------*/ -/* To be renamed as ivas_sba_enc_reconfigure_fx later */ -ivas_error ivas_sba_enc_reconfigure( + +ivas_error ivas_sba_enc_reconfigure_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index d7aeddbc8..dd9cb61a0 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -177,8 +177,6 @@ ivas_error ivas_sce_enc_fx( IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input ); - move16(); - move16(); } currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q7 @@ -266,7 +264,7 @@ ivas_error ivas_sce_enc_fx( ); e_old_wsp[0] = sub( Q15, q_old_wsp ); move16(); - IF( error != IVAS_ERR_OK ) + IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } @@ -319,7 +317,7 @@ ivas_error ivas_sce_enc_fx( /* IGF reconfiguration */ test(); - IF( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth ) + IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_16( st->last_bwidth, st->bwidth ) ) { Word16 igf; igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode ); @@ -332,7 +330,7 @@ ivas_error ivas_sce_enc_fx( /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ test(); test(); - IF( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) + IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) { st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); } @@ -353,10 +351,10 @@ ivas_error ivas_sce_enc_fx( * Encoder *----------------------------------------------------------------*/ - Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); + Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); // Q(15-16) e_old_wsp[0] = 16; move16(); - IF( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ), IVAS_ERR_OK ) ) { return error; } @@ -434,7 +432,7 @@ ivas_error create_sce_enc_fx( test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - IF( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -469,7 +467,7 @@ ivas_error create_sce_enc_fx( move32(); move32(); - IF( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -481,12 +479,12 @@ ivas_error create_sce_enc_fx( } /*------------------------------------------------------------------------- - * create_evs_sce_enc() + * create_evs_sce_enc_fx() * * Create, allocate and initialize EVS encoder SCE handle *-------------------------------------------------------------------------*/ -ivas_error create_evs_sce_enc( +ivas_error create_evs_sce_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ const Word32 element_brate /* i : element bitrate */ @@ -618,12 +616,12 @@ ivas_error create_evs_sce_enc( } /*------------------------------------------------------------------------- - * destroy_sce_enc() + * destroy_sce_enc_fx() * * Destroy and deallocate IVAS encoder SCE handle *-------------------------------------------------------------------------*/ -void destroy_sce_enc( +void destroy_sce_enc_fx( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ Flag is_evs /* i : Flag to indicate EVS encoder*/ ) diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index d36fcaaa5..5566c1547 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -235,6 +235,7 @@ static Word16 sns_2st_cod_fx( FOR( i = 0; i < 2; i++ ) { nq = indx[i]; + move16(); nbits = add( nbits, ( add( 2, ( shl( nq, 2 ) ) ) ) ); /* 2 bits to specify Q2,Q3,Q4,ext */ IF( GT_16( nq, 6 ) ) @@ -393,7 +394,7 @@ void sns_avq_cod_stereo_fx( side_fx[i] = BASOP_Util_Add_Mant32Exp( snsl_fx[i], exp_snl, L_negate( snsr_fx[i] ), exp_snr, &exp_side_buffer[i] ); move32(); Word32 tmp = Mpy_32_32( side_fx[i], side_fx[i] ); // exp_side[i] * 2 - ener_side_fx = BASOP_Util_Add_Mant32Exp( ener_side_fx, exp_ener_side, tmp, exp_side_buffer[i] * 2, &exp_ener_side ); + ener_side_fx = BASOP_Util_Add_Mant32Exp( ener_side_fx, exp_ener_side, tmp, shl( exp_side_buffer[i], 1 ), &exp_ener_side ); } FOR( i = 0; i < M; i++ ) { @@ -697,7 +698,7 @@ Word16 quantize_sns_fx( } Word16 shift = find_guarded_bits_fx( M ); sns_e_tmp[ch][k] = sub( 31, sub( 20, shift ) ); - + move16(); idxIndices = add( idxIndices, nStages ); FOR( i = 0; i < nStages; ++i ) @@ -721,7 +722,7 @@ Word16 quantize_sns_fx( #ifdef MSAN_FIX FOR( k = 0; k < nSubframes; k++ ) { - scale_sig32( snsQ_out_fx[ch][k], M, sub( sns_e_tmp[ch][k], sns_e ) ); + scale_sig32( snsQ_out_fx[ch][k], M, sub( sns_e_tmp[ch][k], sns_e ) ); // Q(31-sns_e_tmp[ch][k]) } #else scale_sig32( snsQ_out_fx[ch][0], M, sub( sns_e_tmp[ch][0], *sns_e ) ); diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 632b92126..e1b3905c2 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -130,14 +130,14 @@ ivas_error ivas_spar_enc_open_fx( /* set FB config. */ active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; move16(); - IF( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in ) ), IVAS_ERR_OK ) ) { return error; } fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ - IF( ( error = ivas_FB_mixer_open_fx( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_FB_mixer_open_fx( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -150,7 +150,7 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { /* Transient Detector handle */ - IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -165,7 +165,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hAgcEnc = NULL; IF( hSpar->AGC_Enable ) { - IF( ( error = ivas_spar_agc_enc_open_fx( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_agc_enc_open_fx( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ), IVAS_ERR_OK ) ) { return error; } @@ -214,7 +214,7 @@ ivas_error ivas_spar_enc_open_fx( move16(); IF( hEncoderConfig->Opt_DTX_ON ) { - IF( ( error = front_vad_create_fx( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = front_vad_create_fx( &( hSpar->hFrontVad ), hEncoderConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -230,7 +230,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); move32(); - IF( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -343,10 +343,20 @@ ivas_error ivas_spar_enc_fx( error = IVAS_ERR_OK; move32(); hEncoderConfig = st_ivas->hEncoderConfig; - st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( st_ivas->nSCE > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } + + test(); + test(); /* Write SBA signaling bits */ - if ( hEncoderConfig->ivas_format == SBA_FORMAT || ( hEncoderConfig->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) + IF( EQ_32( hEncoderConfig->ivas_format, SBA_FORMAT ) || ( EQ_32( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) { /* Write SBA planar flag */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); @@ -354,9 +364,9 @@ ivas_error ivas_spar_enc_fx( /* Write SBA order */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); } - else /* ism_mode == ISM_MODE_NONE */ + ELSE /* ism_mode == ISM_MODE_NONE */ { - if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) { /* Write SBA planar flag */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); @@ -364,20 +374,20 @@ ivas_error ivas_spar_enc_fx( /* hack to indicate OSBA bitstream at VLBR */ push_indice( st0->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); } - else + ELSE { /* Write SBA order */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); } } - if ( hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { /* write the number of objects in ISM_SBA format*/ push_indice( hMetaData, IND_ISM_NUM_OBJECTS, hEncoderConfig->nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); } /* front VAD */ - IF( ( error = front_vad_spar_fx( st_ivas->hSpar, data_fx[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = front_vad_spar_fx( st_ivas->hSpar, data_fx[0], hEncoderConfig, input_frame ) ), IVAS_ERR_OK ) ) { return error; } @@ -394,11 +404,14 @@ ivas_error ivas_spar_enc_fx( } *nb_bits_metadata = hMetaData->nb_bits_tot; + move16(); + test(); /* Force IVAS front pre-proc decision for higher bitrates */ - if ( hEncoderConfig->ivas_total_brate > SBA_DTX_BITRATE_THRESHOLD || hEncoderConfig->Opt_DTX_ON == 0 ) + if ( GT_32( hEncoderConfig->ivas_total_brate, SBA_DTX_BITRATE_THRESHOLD ) || hEncoderConfig->Opt_DTX_ON == 0 ) { st_ivas->hSpar->front_vad_flag = 0; + move16(); } return error; @@ -418,8 +431,8 @@ static ivas_error ivas_spar_cov_md_process_fx( BSTR_ENC_HANDLE hMetaData, const Word16 nchan_inp, const Word16 sba_order, - Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], - Word32 *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH], + Word32 *ppIn_FR_real_fx[IVAS_SPAR_MAX_CH], // q_ppIn_FR + Word32 *ppIn_FR_imag_fx[IVAS_SPAR_MAX_CH], // q_ppIn_FR const Word16 transient_det[2], const Word16 dtx_vad, const Word16 nchan_transport, @@ -659,7 +672,7 @@ static ivas_error ivas_spar_enc_process_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 front_vad_flag, /* i : front-VAD decision */ - Word32 *data_fx[], /* i/o: input/transport audio channels */ + Word32 *data_fx[], /* i/o: input/transport audio channels Q(q_data) */ const Word16 q_data ) { Word32 pcm_tmp_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; @@ -762,7 +775,7 @@ static ivas_error ivas_spar_enc_process_fx( FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { /* changing q format to q_data*/ - scale_sig32( p_pcm_tmp_fx[i], shl( input_frame, 1 ), sub( q_data, q_p_pcm_tmp_fx[i] ) ); + scale_sig32( p_pcm_tmp_fx[i], shl( input_frame, 1 ), sub( q_data, q_p_pcm_tmp_fx[i] ) ); // q_data } /* prepare Parameter MDFT analysis */ @@ -843,8 +856,8 @@ static ivas_error ivas_spar_enc_process_fx( FR_q = s_min( re_q, im_q ); FOR( i = 0; i < nchan_fb_in; i++ ) { - scale_sig32( ppIn_FR_real_fx[i], input_frame, FR_q ); - scale_sig32( ppIn_FR_imag_fx[i], input_frame, FR_q ); + scale_sig32( ppIn_FR_real_fx[i], input_frame, FR_q ); // Q(FR_q+pp_fr_q) + scale_sig32( ppIn_FR_imag_fx[i], input_frame, FR_q ); // Q(FR_q+pp_fr_q) } pp_fr_q = add( FR_q, pp_fr_q ); @@ -905,7 +918,7 @@ static ivas_error ivas_spar_enc_process_fx( FOR( Word32 ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) { /* changing q format to q_data*/ - scale_sig32( p_pcm_tmp_fx[ch], input_frame, sub( q_data, q_p_pcm_tmp_fx[ch] ) ); + scale_sig32( p_pcm_tmp_fx[ch], input_frame, sub( q_data, q_p_pcm_tmp_fx[ch] ) ); // q_data q_p_pcm_tmp_fx[ch] = q_data; move16(); } @@ -995,7 +1008,7 @@ static ivas_error ivas_spar_enc_process_fx( FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { - scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_pcm_fx[i] ) ); + scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_pcm_fx[i] ) ); // q_data q_pcm_fx[i] = q_data; move16(); } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index ca209c66b..1d367dd52 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -48,7 +48,7 @@ * PreProcessor *------------------------------------------------------------------------------------------*/ /*Q28*/ -static const Word32 pr_boost_range_fx[2] = { 26843546, 107374182 }; +static const Word32 pr_boost_range_fx[2] = { 26843546 /*.1f in Q28*/, 107374182 /*.4f in Q28*/ }; typedef enum ivas_strats_t { @@ -141,8 +141,8 @@ ivas_error ivas_spar_md_enc_open_fx( } } hMdEnc->q_mixer_mat_fx = 0; - - IF( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -455,17 +455,17 @@ static void write_metadata_buffer_fx( *-----------------------------------------------------------------------------------------*/ ivas_error ivas_spar_md_enc_process_fx( - ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q(cov_real_q)*/ Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q(cov_dtx_real_q)*/ Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, const Word16 sba_order, /* i : Ambisonic (SBA) order */ - Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix Q(q_prior_mixer) */ Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ @@ -479,6 +479,7 @@ ivas_error ivas_spar_md_enc_process_fx( Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; Word16 active_w, nchan_transport, dmx_switch, strat; Word16 nB, bands_bw, packed_ok = 0; + move16(); ivas_strats_t cs[MAX_CODING_STRATS]; Word16 code_strat; Word16 bit_pos_start, next_ind_start; @@ -711,7 +712,7 @@ ivas_error ivas_spar_md_enc_process_fx( PR_step_e = sub( PR_step_e, Q12 ); Word16 PR_sign; - PR_sign = sub( (Word16) ( GT_32( PR_uq, 0 ) ), (Word16) ( LT_32( PR_uq, 0 ) ) ); + PR_sign = sub( extract_l( GT_32( PR_uq, 0 ) ), extract_l( LT_32( PR_uq, 0 ) ) ); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = PR_sign; move16(); @@ -989,7 +990,7 @@ ivas_error ivas_spar_md_enc_process_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_band_mixer_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // Q(cov_real_q) Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 num_ch, Word16 *num_bands, @@ -1141,7 +1142,7 @@ static void ivas_write_spar_md_bitstream_fx( push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); FOR( i = 0; i < nB; i++ ) { - do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 1 ) ); + do_diff[i] = extract_l( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 1 ) ); move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); @@ -1150,7 +1151,7 @@ static void ivas_write_spar_md_bitstream_fx( push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); FOR( i = 0; i < nB; i++ ) { - do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 2 ) ); + do_diff[i] = extract_l( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 2 ) ); move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); @@ -1159,7 +1160,7 @@ static void ivas_write_spar_md_bitstream_fx( push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); FOR( i = 0; i < nB; i++ ) { - do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 3 ) ); + do_diff[i] = extract_l( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 3 ) ); move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); @@ -1327,6 +1328,7 @@ static Word16 ivas_get_arith_coded_bs_fx( { pred_cell_dims[i].dim1 = sub( add( ndm, ndec ), 1 ); move16(); + test(); IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) @@ -1752,7 +1754,7 @@ static void ivas_write_parameter_bitstream_dtx_fx( zero_pad_bits = sub( zero_pad_bits, 1 ); } - WHILE( GT_16( zero_pad_bits, 0 ) ) + WHILE( zero_pad_bits > 0 ) { j = s_min( zero_pad_bits, 16 ); push_next_indice( hMetaData, 0, j ); @@ -1803,7 +1805,7 @@ static void ivas_quant_c_per_band_fx( { C_re[k] = pband_coeffs->C_re_fx[i][j]; move32(); - k = add( k, 1 ); + k++; } } ivas_quantise_real_values_enc_fx_varq( C_re, pQs->C.q_levels[0], pQs->C.min_fx, pQs->C.max_fx, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ), q_C ); @@ -1815,7 +1817,7 @@ static void ivas_quant_c_per_band_fx( { pband_coeffs->C_quant_re_fx[i][j] = C_re[k]; move32(); - k = add( k, 1 ); + k++; } } diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index e5cd1da07..a47029be4 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -44,16 +44,16 @@ * Local function prototypes *---------------------------------------------------------------------*/ -static int16_t adapt_GR_sg( const int16_t *in, const int16_t len, const int16_t no_symb, int16_t *nbits, int16_t *in_enc, const int16_t *map0, const int16_t no_GR_ord ); +static Word16 adapt_GR_sg_fx( const Word16 *in, const Word16 len, const Word16 no_symb, Word16 *nbits, Word16 *in_enc, const Word16 *map0, const Word16 no_GR_ord ); /*---------------------------------------------------------------------* - * calculate_diff() + * calculate_diff_fx() * * calculate difference wrt previous frame and maps it to positive integer *---------------------------------------------------------------------*/ -static void calculate_diff( +static void calculate_diff_fx( const Word16 *in, /* i : current frame values */ const Word16 *prev, /* i : previous frmae values */ Word16 *in_diff, /* o : difference values */ @@ -90,14 +90,14 @@ static void calculate_diff( /*---------------------------------------------------------------------* - * calculate_bit_diff() + * calculate_bit_diff_fx() * * estimates the GR number of bits for encoding differential values * selects between GR order 0 or 1 *---------------------------------------------------------------------*/ /*! r: number of bits */ -static Word16 calculate_bit_diff( +static Word16 calculate_bit_diff_fx( Word16 *in_diff, /* i : values to be encoded */ Word16 len, /* i : number of params */ Word16 *flag_diff /* o : selected GR order */ @@ -153,7 +153,7 @@ Word16 adapt_GR_ief_fx( const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ Word16 *nbits_diff, /* o : number bits in diff encoding */ const Word16 side_gain_counter, /* i : number of frames since last abs coding */ - Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff Q(q_side_gain_bitdiff_lp) */ Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ const Word16 try_diff /* i : diff coding allowed 1/0 */ ) @@ -163,12 +163,12 @@ Word16 adapt_GR_ief_fx( Word32 L_tmp, L_tmp1; Word16 exp_diff; - flag = adapt_GR_sg( in, len, no_symb, nbits, in_enc, map0, no_GR_ord ); + flag = adapt_GR_sg_fx( in, len, no_symb, nbits, in_enc, map0, no_GR_ord ); IF( try_diff ) /* inter-frame prediction allowed */ { - calculate_diff( in, prev, in_diff, len ); - nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + calculate_diff_fx( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff_fx( in_diff, len, &flag_diff ); *nbits_diff = nb_diff; move16(); @@ -202,13 +202,13 @@ Word16 adapt_GR_ief_fx( /*---------------------------------------------------------------------* - * adapt_GR_rpg1_ief() + * adapt_GR_rpg1_ief_fx() * * use adaptive GR for RPG's considering also the differential case *---------------------------------------------------------------------*/ /*! r: used GR order */ -Word16 adapt_GR_rpg1_ief( +Word16 adapt_GR_rpg1_ief_fx( const Word16 *in, /* i : res pred gains input vector */ Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ const Word16 *prev, /* i : previous frame data */ @@ -254,13 +254,13 @@ Word16 adapt_GR_rpg1_ief( } ELSE { - GR_ord = adapt_GR_sg( in, len, no_symb, nbits, in_enc, maps, no_GR_ord ); + GR_ord = adapt_GR_sg_fx( in, len, no_symb, nbits, in_enc, maps, no_GR_ord ); } IF( try_diff ) { - calculate_diff( in, prev, in_diff, len ); - nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + calculate_diff_fx( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff_fx( in_diff, len, &flag_diff ); *nbits_diff = nb_diff; move16(); @@ -283,13 +283,13 @@ Word16 adapt_GR_rpg1_ief( /*---------------------------------------------------------------------* - * adapt_GR_sg() + * adapt_GR_sg_fx() * * adaptive GR coding *---------------------------------------------------------------------*/ /*! r: GR order */ -static Word16 adapt_GR_sg( +static Word16 adapt_GR_sg_fx( const Word16 *in, /* i : data to be encoded */ const Word16 len, /* i : number of params to be encoded */ const Word16 no_symb, /* i : max number of symbols */ @@ -411,13 +411,13 @@ static Word16 adapt_GR_sg( /*---------------------------------------------------------------------* - * write_GR0() + * write_GR0_fx() * * write data with GR order 0 *---------------------------------------------------------------------*/ /*! r: number of bits written */ -Word16 write_GR0( +Word16 write_GR0_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : data to be encoded */ @@ -452,13 +452,13 @@ Word16 write_GR0( /*---------------------------------------------------------------------* - * write_GR1() + * write_GR1_fx() * * write data with GR order 1 *---------------------------------------------------------------------*/ /*! r: number of bits written */ -Word16 write_GR1( +Word16 write_GR1_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : data to be encoded */ @@ -496,13 +496,13 @@ Word16 write_GR1( /*---------------------------------------------------------------------* - * write_GR2() + * write_GR2_fx() * * write data with GR order 2 *---------------------------------------------------------------------*/ /*! r: number of bits written */ -static Word16 write_GR2( +static Word16 write_GR2_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : data to be encoded */ @@ -543,13 +543,13 @@ static Word16 write_GR2( /*---------------------------------------------------------------------* - * write_bitstream_GR() + * write_bitstream_GR_fx() * * generic GR encoder for GR order 0 or 1 *---------------------------------------------------------------------*/ /*! r: number of bits written */ -Word16 write_bitstream_GR( +Word16 write_bitstream_GR_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : input vector */ @@ -566,11 +566,11 @@ Word16 write_bitstream_GR( IF( GR_ord == 0 ) { - nb = add( nb, write_GR0( hBstr, ind, in, len ) ); + nb = add( nb, write_GR0_fx( hBstr, ind, in, len ) ); } ELSE { - nb = add( nb, write_GR1( hBstr, ind, in, len ) ); + nb = add( nb, write_GR1_fx( hBstr, ind, in, len ) ); } return nb; @@ -578,13 +578,13 @@ Word16 write_bitstream_GR( /*---------------------------------------------------------------------* - * write_bitstream_adapt_GR() + * write_bitstream_adapt_GR_fx() * * write encoded data using adaptive GR *---------------------------------------------------------------------*/ /*! r: number of bits written */ -Word16 write_bitstream_adapt_GR( +Word16 write_bitstream_adapt_GR_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const Word16 ind, /* i : bitstream index */ const Word16 *in, /* i : values to be written in bitstream */ @@ -596,8 +596,9 @@ Word16 write_bitstream_adapt_GR( Word16 nb; nb = 0; + move16(); /* first component first */ - nb = add( nb, write_GR1( hBstr, ind, in, 1 ) ); + nb = add( nb, write_GR1_fx( hBstr, ind, in, 1 ) ); /* write the GR order */ IF( EQ_16( no_GR_ord, 2 ) ) @@ -622,17 +623,17 @@ Word16 write_bitstream_adapt_GR( IF( GR_ord == 0 ) { - nb = add( nb, write_GR0( hBstr, ind, &in[1], sub( len, 1 ) ) ); + nb = add( nb, write_GR0_fx( hBstr, ind, &in[1], sub( len, 1 ) ) ); } ELSE { IF( EQ_16( GR_ord, 1 ) ) { - nb = add( nb, write_GR1( hBstr, ind, &in[1], sub( len, 1 ) ) ); + nb = add( nb, write_GR1_fx( hBstr, ind, &in[1], sub( len, 1 ) ) ); } ELSE { - nb = add( nb, write_GR2( hBstr, ind, &in[1], sub( len, 1 ) ) ); + nb = add( nb, write_GR2_fx( hBstr, ind, &in[1], sub( len, 1 ) ) ); } } diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 83386836e..c84fd73f1 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -86,18 +86,18 @@ * Local function prototypes *-------------------------------------------------------------------*/ static void rc_filter_fx( const Word32 x, Word32 *y, const Word16 order, const Word32 tau ); -static void edge_detect( const Word32 *inp, const Word16 len, const Word32 inp_min, const Word32 inp_max, Word16 *edge_str, Word16 *edge_type ); +static void edge_detect_fx( const Word32 *inp, const Word16 len, const Word32 inp_min, const Word32 inp_max, Word16 *edge_str, Word16 *edge_type ); static Word32 redge_detect_fx( const Word32 *inp, const Word16 len, const Word32 inp_min, const Word32 inp_max, Word16 *edge_min_e ); /*-------------------------------------------------------------------* - * Function select_stereo_mode() + * Function select_stereo_mode_fx() * * Select stereo technology based on output of stereo classifiers *-------------------------------------------------------------------*/ /*! r: element mode */ -Word16 select_stereo_mode( +Word16 select_stereo_mode_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format /* i : IVAS format */ ) @@ -130,11 +130,12 @@ Word16 select_stereo_mode( test(); test(); + test(); #ifdef DEBUGGING IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) ) #else - IF( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && - LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) ) + if ( GE_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) || ( ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && + LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) ) ) #endif { stereo_switching_flag = 0; @@ -161,6 +162,7 @@ Word16 select_stereo_mode( test(); test(); test(); + test(); IF( EQ_16( stereo_switching_flag, 1 ) && GT_32( hCPE->element_brate, IVAS_13k2 ) && LT_16( hCPE->hCoreCoder[0]->hSpMusClas->past_dlp_fx[0], ONE_IN_Q9 ) && LT_32( hCPE->hCoreCoder[0]->hSpMusClas->wdlp_xtalk_fx, -335544 /* -0.01 in Q25 */ ) && EQ_16( hCPE->hCoreCoder[0]->vad_flag, 1 ) && ( hCPE->hStereoMdct->sw_uncorr || hStereoClassif->xtalk_decision ) ) { hStereoClassif->lrtd_mode = 1; @@ -183,7 +185,7 @@ Word16 select_stereo_mode( { test(); test(); - IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) + if ( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && LT_32( hCPE->element_brate, MASA_STEREO_MIN_BITRATE ) ) { element_mode = IVAS_CPE_DFT; move16(); @@ -229,7 +231,7 @@ Word16 select_stereo_mode( test(); IF( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 && GT_16( hCPE->hStereoTD->tdm_FD2LRTD_SW_cnt, 15 ) && GT_16( hCPE->hStereoTD->tdm_last_LRTD_frame_cnt, 3 ) && LT_16( hCPE->hCoreCoder[0]->clas, VOICED_CLAS ) && ( GE_32( hCPE->element_brate, IVAS_16k4 ) || LT_32( hStereoClassif->xtalk_wscore_fx, 21474836 /*0.01f in Q31*/ ) ) ) { - IF( EQ_16( stereo_switching_flag, 1 ) ) + if ( EQ_16( stereo_switching_flag, 1 ) ) { element_mode = IVAS_CPE_DFT; move16(); @@ -450,9 +452,9 @@ void stereo_classifier_features_ivas_fx( Word32 epsP_fx[], /* i : LP analysis residual energies for each iteration*/ Word16 pitch[], /* i : open-loop pitch values for quantiz. Q0 */ Word16 voicing_fx[], /* i : OL maximum normalized correlation Q15 */ - Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter */ - Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. */ - Word16 sp_div_fx, /* i : spectral diversity feature */ + Word32 cor_map_sum_fx, /* i : speech/music clasif. parameter Q(31-cor_map_sum_e) */ + Word32 non_staX_fx, /* i : unbound non-stationarity for sp/mu clas. Q(31-non_staX_e) */ + Word16 sp_div_fx, /* i : spectral diversity feature Q(15-sp_div_e) */ const Word16 clas, /* i : signal class */ Word16 epsP_e, /*exponent for epsP_fx */ Word16 cor_map_sum_e, /*exponent for cor_map_sum_fx */ @@ -598,7 +600,7 @@ void stereo_classifier_features_ivas_fx( IF( LT_32( L_shr( hStereoClassif->Etot_up_fx, 1 ), L_add( L_shr( hStereoClassif->Etot_dn_fx, 1 ), L_shl( 20, sub( 30, hStereoClassif->e_Etot_buf_fx ) ) ) ) ) /*right shifted by 1 to avoid avoid overflow in addition*/ { hStereoClassif->Etot_dn_fx = L_shr( hStereoClassif->Etot_dn_fx, 1 ); - scale_sig32( hStereoClassif->Etot_buf_fx, 3, -1 ); + scale_sig32( hStereoClassif->Etot_buf_fx, 3, -1 ); // Q(31-(e_Etot_buf_fx+1)) hStereoClassif->e_Etot_buf_fx = add( hStereoClassif->e_Etot_buf_fx, 1 ); hStereoClassif->Etot_up_fx = L_add( hStereoClassif->Etot_dn_fx, L_shl( 20, sub( 31, hStereoClassif->e_Etot_buf_fx ) ) ); move32(); @@ -626,6 +628,7 @@ void stereo_classifier_features_ivas_fx( move32(); /* estimate VAD flag based on relative energy */ + IF( LT_32( hStereoClassif->relE_0_1_LT_fx, 214748365 /* 0.1f in Q31 */ ) ) { hStereoClassif->vad_relE = 0; @@ -646,7 +649,6 @@ void stereo_classifier_features_ivas_fx( Copy( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); hStereoClassif->lepsP_ch1_fx = L_shr( L_sub( BASOP_Util_Loge( L_add( epsP_fx[13], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ), BASOP_Util_Loge( L_add( epsP_fx[0], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ) ), 10 ); /*q15*/ move32(); - move16(); hStereoClassif->xtalk_fv_fx[E_lsf_1] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[0] ); /*q15*/ hStereoClassif->xtalk_fv_fx[E_lsf_4] = Mpy_32_16_1( 419430400 /* 1/2.56f in Q30 */, lsf_new_fx[3] ); /*q15*/ @@ -750,7 +752,6 @@ void stereo_classifier_features_ivas_fx( move32(); move32(); move32(); - move32(); move16(); move16(); move16(); @@ -1201,7 +1202,7 @@ void xtalk_classifier_td_fx( /* test rising edge (use 0 as edge_type because of newer->older buffer samples ordering) */ edge_type = 0; move16(); - edge_detect( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN, -53687091 /*-0.2f Q28*/, ONE_IN_Q28, &edge, &edge_type ); + edge_detect_fx( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN, -53687091 /*-0.2f Q28*/, ONE_IN_Q28, &edge, &edge_type ); test(); IF( edge_type == 0 && LT_16( edge, 9830 /*0.3f Q15*/ ) ) @@ -1236,6 +1237,8 @@ void xtalk_classifier_td_fx( /* binary decision w. hysteresis (switch the decision only when coder_type is GC, UC or IC) */ test(); test(); + test(); + test(); if ( ( hStereoClassif->unclr_decision == 0 && hStereoClassif->xtalk_decision == 0 && GT_32( hStereoClassif->xtalk_wscore_fx, 64424509 /*0.03f Q31*/ ) ) /*|| (hStereoClassif->xtalk_decision == 1 && hStereoClassif->xtalk_wscore < 0.00f)*/ && ( hStereoClassif->unclr_sw_enable_cnt[0] > 0 || hStereoClassif->unclr_sw_enable_cnt[1] > 0 ) ) { /* let's switch the binary decision */ @@ -1270,7 +1273,14 @@ void xtalk_classifier_dft_fx( Word64 W_tmp; hStereoClassif = hCPE->hStereoClassif; - hItd = ( hCPE->hStereoDft != NULL ) ? hCPE->hStereoDft->hItd : hCPE->hStereoMdct->hItd; + IF( hCPE->hStereoDft != NULL ) + { + hItd = hCPE->hStereoDft->hItd; + } + ELSE + { + hItd = hCPE->hStereoMdct->hItd; + } m1 = 0; move32(); @@ -1296,7 +1306,7 @@ void xtalk_classifier_dft_fx( m2 = L_abs( gcc_phat[0] ); itd2 = -XTALK_PHAT_LEN; move16(); - FOR( i = 1; i < sub( XTALK_PHAT_LEN, thr ); i++ ) + FOR( i = 1; i < ( XTALK_PHAT_LEN - thr ); i++ ) { IF( GT_32( L_abs( gcc_phat[i] ), m2 ) ) { @@ -1310,7 +1320,7 @@ void xtalk_classifier_dft_fx( m1 = L_abs( gcc_phat[itd + XTALK_PHAT_LEN] ); m2 = L_abs( gcc_phat[XTALK_PHAT_LEN + thr + 1] ); itd2 = add( thr, 1 ); - FOR( i = add( XTALK_PHAT_LEN + 2, thr ); i < 2 * XTALK_PHAT_LEN + 1; i++ ) + FOR( i = ( XTALK_PHAT_LEN + 2 + thr ); i < 2 * XTALK_PHAT_LEN + 1; i++ ) { IF( GT_32( L_abs( gcc_phat[i] ), m2 ) ) { @@ -1398,7 +1408,7 @@ void xtalk_classifier_dft_fx( /* rising edge detector on raw score -> yields 1 if strong rising edge is detected in the given buffer */ Copy32( &hStereoClassif->xtalk_score_buf_fx[0], &hStereoClassif->xtalk_score_buf_fx[1], XTALK_SCORE_BUF_LEN - 1 ); hStereoClassif->xtalk_score_buf_fx[0] = score; - + move32(); minimum_l( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN, &scr_min ); maximum_l( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN, &scr_max ); @@ -1502,14 +1512,14 @@ static void rc_filter_fx( } /*-------------------------------------------------------------------* - * Function edge_detect() + * Function edge_detect_fx() * * Rising/falling edge detection algorithm * Analyzes the input buffer and outputs strength and type of the detected edge (rising or falling) * Set edge_type to 0/1/2 when calling this function to specify the edge type you want to detect. The returned value will be modified * according to the edge type detected (-1 indicates that no edge has been detected) *-------------------------------------------------------------------*/ -static void edge_detect( +static void edge_detect_fx( const Word32 *inp, /* i : input buffer Q31*/ const Word16 len, /* i : length of the input buffer Q0*/ const Word32 inp_min, /* i : minimum value for edge detection Q28*/ @@ -1654,10 +1664,10 @@ static void edge_detect( /*! r: rising edge strength normalized to 0-1 */ static Word32 redge_detect_fx( - const Word32 *inp, /* i : input buffer (ordered from newest to oldest values)*/ + const Word32 *inp, /* i : input buffer (ordered from newest to oldest values) Q31*/ const Word16 len, /* i : length of the input buffer */ - const Word32 inp_min, /* i : minimum value for edge detection */ - const Word32 inp_max, /* i : maximum value for edge detection */ + const Word32 inp_min, /* i : minimum value for edge detection Q31 */ + const Word32 inp_max, /* i : maximum value for edge detection Q31 */ Word16 *edge_min_e ) { Word16 i, j; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 059eb5b8e..92add6cdd 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -411,7 +411,7 @@ void stereo_dft_enc_sid_coh_fx( /* Write residual index to bitstream */ IF( LE_16( add( add( res_index, 1 ), *nb_bits ), nr_of_sid_stereo_bits ) ) /* If the bit limit is reached, res_index = 0 is assumed for remaining indices */ { - *nb_bits = add( *nb_bits, write_GR0( hBstr, IND_STEREO_DFT_SID_COH, &res_index, 1 ) ); + *nb_bits = add( *nb_bits, write_GR0_fx( hBstr, IND_STEREO_DFT_SID_COH, &res_index, 1 ) ); move16(); } diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 10bfbacd8..90e9752f4 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -2795,7 +2795,7 @@ void stereo_dft_enc_res_fx( push_wmops( "residual_encode" ); /* residual encoding */ ECSQ_init_instance_fx( &ecsq_inst, 0 /*dummy index*/, &range_uni_enc_state ); - rc_uni_enc_init( &range_uni_enc_state ); + rc_uni_enc_init_fx( &range_uni_enc_state ); ecsq_inst.bit_count_estimate = 0; move32(); @@ -2806,7 +2806,7 @@ void stereo_dft_enc_res_fx( ECSQ_encode_target_SNR_fx( &ecsq_inst, MDCT_RES, MDCT_RES_e, hStereoDft->res_cod_line_max, max_snr, max_bits - ( *nb_bits ) - STEREO_DFT_RES_GLOBAL_GAIN_BITS - 2 - 8, NULL, &global_gain_index ); IF( NE_16( global_gain_index, ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO ) ) { - total_bit_count = rc_uni_enc_finish( &range_uni_enc_state ); + total_bit_count = rc_uni_enc_finish_fx( &range_uni_enc_state ); IF( LE_16( total_bit_count, sub( sub( max_bits, *nb_bits ), STEREO_DFT_RES_GLOBAL_GAIN_BITS ) ) ) { @@ -3058,11 +3058,11 @@ void stereo_dft_enc_write_BS_fx( IF( hStereoDft->side_gain_flag_1 == 0 ) { - nb = add( nb, write_bitstream_adapt_GR( hBstr, IND_STEREO_DFT_SIDEGAINS, encoded_ind_GR, hStereoDft->nbands, hStereoDft->side_gain_flag_2, no_GR_ord ) ); + nb = add( nb, write_bitstream_adapt_GR_fx( hBstr, IND_STEREO_DFT_SIDEGAINS, encoded_ind_GR, hStereoDft->nbands, hStereoDft->side_gain_flag_2, no_GR_ord ) ); } ELSE{ IF( EQ_16( hStereoDft->side_gain_flag_1, 2 ) ){ - nb = add( nb, write_bitstream_GR( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_ECDiff, hStereoDft->nbands, hStereoDft->side_gain_flag_2 - no_GR_ord ) ); + nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_SIDEGAINS, hStereoDft->side_gain_index_ECDiff, hStereoDft->nbands, hStereoDft->side_gain_flag_2 - no_GR_ord ) ); } ELSE { @@ -3231,18 +3231,18 @@ IF( hStereoDft->res_pred_mode[k_offset] ) { IF( EQ_16( encoded_ind_pred_GR[0], dft_maps_rpg[8 * NO_SYMB_GR_PRED_G] ) ) { - nb = add( nb, write_GR1( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, 1 ) ); + nb = add( nb, write_GR1_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, 1 ) ); } ELSE { - nb = add( nb, write_bitstream_adapt_GR( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2, 2 ) ); + nb = add( nb, write_bitstream_adapt_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, encoded_ind_pred_GR, nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2, 2 ) ); } } ELSE { IF( EQ_16( hStereoDft->res_pred_flag_1, 2 ) ) { - nb = add( nb, write_bitstream_GR( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2 - no_GR_ord ) ); + nb = add( nb, write_bitstream_GR_fx( hBstr, IND_STEREO_DFT_PRED_GAIN_COD, &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, hStereoDft->res_pred_flag_2 - no_GR_ord ) ); } ELSE { @@ -4196,7 +4196,7 @@ static void res_pred_gain_mode_decision_fx( no_GR_ord = 2; move16(); - hStereoDft->res_pred_flag_2 = adapt_GR_rpg1_ief( &hStereoDft->res_pred_index_EC[hStereoDft->res_pred_band_min], &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], &hStereoDft->res_pred_index_ECprevious[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, NO_SYMB_GR_PRED_G, &n_bits, encoded_ind_pred_GR, dft_maps_rpg, &nb_diff, no_GR_ord, try_diff ); + hStereoDft->res_pred_flag_2 = adapt_GR_rpg1_ief_fx( &hStereoDft->res_pred_index_EC[hStereoDft->res_pred_band_min], &hStereoDft->res_pred_index_ECDiff[hStereoDft->res_pred_band_min], &hStereoDft->res_pred_index_ECprevious[hStereoDft->res_pred_band_min], nbands - hStereoDft->res_pred_band_min, NO_SYMB_GR_PRED_G, &n_bits, encoded_ind_pred_GR, dft_maps_rpg, &nb_diff, no_GR_ord, try_diff ); move16(); FOR( i = 0; i < nbands; i++ ) diff --git a/lib_enc/ivas_stereo_eclvq_enc.c b/lib_enc/ivas_stereo_eclvq_enc.c index ac716bf3a..118baaa69 100644 --- a/lib_enc/ivas_stereo_eclvq_enc.c +++ b/lib_enc/ivas_stereo_eclvq_enc.c @@ -197,7 +197,7 @@ static void arith_encode_bit_fx( IF( ecsq_inst->encoding_active ) { /* call to the actual AC */ - rc_uni_enc_encode_bits( rc_st_enc, bit, 1 ); + rc_uni_enc_encode_bits_fx( rc_st_enc, bit, 1 ); } return; @@ -221,7 +221,7 @@ static void arith_encode_bits_fx( IF( ecsq_inst->encoding_active ) { - rc_uni_enc_encode_bits( rc_st_enc, n, size ); + rc_uni_enc_encode_bits_fx( rc_st_enc, n, size ); } return; @@ -282,7 +282,7 @@ static void arith_encode_bit_prob_fx( IF( ecsq_inst->encoding_active ) { /* call to the actual AC */ - rc_uni_enc_encode_fast( rc_st_enc, u_extract_l( L_mult0( bit, count0 ) ), count, 14 ); + rc_uni_enc_encode_fast_fx( rc_st_enc, u_extract_l( L_mult0( bit, count0 ) ), count, 14 ); } return; @@ -314,7 +314,7 @@ static void arith_encode_prob_fx( IF( ecsq_inst->encoding_active ) { /* call to the actual AC */ - rc_uni_enc_encode_fast( rc_st_enc, u_extract_l( UL_subNsD( ECSQ_PROB_TOTAL, table[symbol] ) ), count, 14 ); + rc_uni_enc_encode_fast_fx( rc_st_enc, u_extract_l( UL_subNsD( ECSQ_PROB_TOTAL, table[symbol] ) ), count, 14 ); } return; diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 41e1cfeba..32b521ef4 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -392,6 +392,8 @@ void speech_music_clas_init_ivas_fx( move16(); set32_fx( hSpMusClas->finc_prev_fx, 0, ATT_NSEG ); + hSpMusClas->q_finc_prev = Q31; + move16(); hSpMusClas->lt_finc_fx = 0; move32(); hSpMusClas->Q_lt_finc = Q31; @@ -2684,8 +2686,10 @@ static Word16 attack_det_ivas_fx( /* o : attack flag const Word32 total_brate, /* i : total bitrate */ const Word16 element_mode, /* i : IVAS element mode */ const Word16 clas, /* i : signal class */ - Word32 finc_prev[], /* i/o: previous finc, (2 * Qx) */ - Word32 *lt_finc, /* i/o: long-term mean finc, (2 * Qx) */ + Word32 finc_prev[], /* i/o: previous finc, (q_finc_prev) */ + Word16 *q_finc_prev, /* i/o: Q of previous finc */ + Word32 *lt_finc, /* i/o: long-term mean finc, (q_lt_finc) */ + Word16 *q_lt_finc, /* i/o: Q of lt_finc */ Word16 *last_strong_attack /* i/o: last strong attack flag */ ) { @@ -2693,8 +2697,8 @@ static Word16 attack_det_ivas_fx( /* o : attack flag Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG], mean_finc; Word16 att_3lsub_pos; Word16 attack1; - Word64 W_tmp = 0; - move64(); + Word64 W_tmp; + Word16 q_diff; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; @@ -2727,6 +2731,9 @@ static Word16 attack_det_ivas_fx( /* o : attack flag attack1 = attack; move16(); + *q_finc_prev = shl( Qx, 1 ); // Q of finc + move16(); + q_diff = sub( *q_finc_prev, *q_lt_finc ); test(); IF( EQ_16( localVAD, 1 ) && EQ_16( coder_type, GENERIC ) ) { @@ -2817,7 +2824,7 @@ static Word16 attack_det_ivas_fx( /* o : attack flag move16(); } test(); - if ( GT_32( *lt_finc, Mpy_32_32( etmp2, 107374182 /* 1.f/20 in Q31 */ ) ) || *last_strong_attack ) + if ( GT_32( L_shl_sat( *lt_finc, q_diff ), Mpy_32_32( etmp2, 107374182 /* 1.f/20 in Q31 */ ) ) || *last_strong_attack ) { attack = 0; move16(); @@ -2849,15 +2856,29 @@ static Word16 attack_det_ivas_fx( /* o : attack flag Copy32( finc, finc_prev, ATT_NSEG ); /* Calculating mean of finc */ - FOR( i = 0; i < ATT_NSEG; i++ ) + W_tmp = W_mult_32_16( finc[0], 1 ); // q_finc_prev+1 + FOR( i = 1; i < ATT_NSEG; i++ ) { - W_tmp = W_add( W_tmp, (Word64) finc[i] ); + W_tmp = W_mac_32_16( W_tmp, finc[i], 1 ); // q_finc_prev+1 } - mean_finc = W_extract_l( W_shr( W_tmp, 5 ) ); + /* mean = W_tmp / 32 and change the Q from q_finc_prev+1 to q_finc_prev + Mean value doesn't saturate, W_shl_sat_l is used only considering complexity */ + mean_finc = W_shl_sat_l( W_tmp, -Q6 ); // q_finc_prev+1 -> q_finc_prev //*lt_finc = 0.95f * *lt_finc + 0.05f * mean( finc, ATT_NSEG ); - *lt_finc = L_add( Mpy_32_32( *lt_finc, 2040109466 /* 0.95 in Q31 */ ), Mpy_32_32( mean_finc, 107374182 /* 0.05f in Q31 */ ) ); - move32(); + IF( q_diff > 0 ) /* q_finc_prev > q_lt_finc */ + { + mean_finc = L_shr( mean_finc, q_diff ); // q_lt_finc + *lt_finc = Madd_32_32( Mpy_32_32( *lt_finc, 2040109466 /* 0.95 in Q31 */ ), mean_finc, 107374182 /* 0.05f in Q31 */ ); // q_lt_finc + move32(); + } + ELSE + { + *lt_finc = Madd_32_32( Mpy_32_32( L_shl( *lt_finc, q_diff ), 2040109466 /* 0.95 in Q31 */ ), mean_finc, 107374182 /* 0.05f in Q31 */ ); // q_finc_prev + move32(); + *q_lt_finc = *q_finc_prev; + move16(); + } return attack; } @@ -2999,14 +3020,14 @@ void ivas_smc_mode_selection_fx( var_cor_calc_ivas_fx( st->old_corr_fx, &hSpMusClas->mold_corr_fx, hSpMusClas->var_cor_t_fx, &hSpMusClas->high_stable_cor ); /* attack detection */ - IF( NE_16( shl( Q_new, 1 ), hSpMusClas->Q_lt_finc ) ) + IF( NE_16( shl( Q_new, 1 ), hSpMusClas->q_finc_prev ) ) { - Scale_sig32( &hSpMusClas->lt_finc_fx, 1, sub( shl( Q_new, 1 ), hSpMusClas->Q_lt_finc ) ); - Scale_sig32( hSpMusClas->finc_prev_fx, ATT_NSEG, sub( shl( Q_new, 1 ), hSpMusClas->Q_lt_finc ) ); - hSpMusClas->Q_lt_finc = shl( Q_new, 1 ); + Scale_sig32( hSpMusClas->finc_prev_fx, ATT_NSEG, sub( shl( Q_new, 1 ), hSpMusClas->q_finc_prev ) ); + hSpMusClas->q_finc_prev = shl( Q_new, 1 ); move16(); } - attack = attack_det_ivas_fx( inp, Q_new, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev_fx, &hSpMusClas->lt_finc_fx, &hSpMusClas->last_strong_attack ); + attack = attack_det_ivas_fx( inp, Q_new, st->clas, st->localVAD, st->coder_type, 0, st->element_mode, st->clas, hSpMusClas->finc_prev_fx, + &hSpMusClas->q_finc_prev, &hSpMusClas->lt_finc_fx, &hSpMusClas->Q_lt_finc, &hSpMusClas->last_strong_attack ); /* tonal detector */ ton = tonal_det_fx( S_map, st->vad_flag, hSpMusClas->tod_S_map_lt_fx, &hSpMusClas->tod_thr_lt_fx, &hSpMusClas->tod_weight_fx, &hSpMusClas->tod_S_mass_prev_fx, &hSpMusClas->tod_S_mass_lt_fx ); // Q22 diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 6c4020e27..ca8830a4c 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -641,8 +641,9 @@ typedef struct sp_mus_clas_structure Word16 UV_cnt1; Word16 LT_UV_cnt1_fx; /* Q6 */ - Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (Q_new * 2) */ - Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, Q_lt_finc (Q_new * 2) */ + Word32 finc_prev_fx[ATT_NSEG]; /* strong attack detection - previous finc, (q_finc_prev) */ + Word16 q_finc_prev; + Word32 lt_finc_fx; /* strong attack detection - long-term finc energy, Q_lt_finc */ Word16 Q_lt_finc; Word16 last_strong_attack; /* strong attack detection - last strong attack flag */ Word32 tod_lt_Bin_E_fx[TOD_NSPEC]; /* tonal detector - long-term energy spectrum, Q_tod_lt_Bin_E */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 06f8a5e92..a2965d5dc 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -7416,15 +7416,13 @@ void fb_tbe_enc_ivas_fx( Word16 input_fhb_new[L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; Word16 input_fhb[L_FRAME48k]; Word16 Sample_Delay_HP; - Word32 fb_exc_energy, temp2; - Word32 L_tmp; - Word16 tmp, tmp1, tmp2, exp, exp2, exp_norm; + Word64 fb_exc_energy; + Word16 tmp, tmp2, exp, exp2; Word16 s_max_value, exp_temp, i; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move16(); -#endif + Word16 q_diff, q_input_fhb; + Word64 temp1, temp2; + s_max_value = 0; move16(); FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) @@ -7474,71 +7472,72 @@ void fb_tbe_enc_ivas_fx( move16(); set16_fx( tmp_vec, 0, L_FRAME16k ); } - Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); + + q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q + Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp + IF( q_diff > 0 ) + { + scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q + q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + move16(); + } + ELSE + { + scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp + q_input_fhb = exp_temp; + move16(); + } + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); hBWE_TD->old_input_fhb_fx_Q = exp_temp; move16(); - Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); - Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q(2*Q_input_fhb-8) */ - temp2 = L_add_o( temp2, L_shl_o( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 8 ), hBWE_TD->prev_fb_energy_fx_Q ), &Overflow ), &Overflow ); /* Q(2*(exp_temp)-8) */ - hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q(2*(Q_input_fhb)-8) */ + + temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ + temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( q_input_fhb, hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb + + temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb + exp = W_norm( temp1 ); + temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp + hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 move32(); - hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 8 ); + hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); move16(); - fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc-8) */ - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - L_tmp = L_max( 1, temp2 ); /*Q(2*(exp_temp)-8)*/ - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* (L_tmp in Q(2*(exp_temp)-8))*/ + fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc - exp2 = norm_l( fb_exc_energy ); - tmp2 = extract_h( L_shl( fb_exc_energy, exp2 ) ); - tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ - exp2 = sub( sub( 31, tmp1 ), exp2 ); /* (L_tmp in Q(2*(exp_temp)-8))*/ + /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ + exp = sub( W_norm( temp2 ), 1 ); + tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 + exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) - exp = sub( exp2, exp ); /* Denormalize and substract */ - IF( GT_16( tmp2, tmp ) ) - { - tmp2 = shr( tmp2, 1 ); - exp = add( exp, 1 ); - } - IF( 0 != tmp ) - { - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ - L_tmp = L_max( L_shr_o( L_tmp, sub( 31, exp ), &Overflow ), 0x1 ); /* Q0 */ - } - ELSE - { - L_tmp = 0; - move32(); - } + exp2 = W_norm( fb_exc_energy ); + tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 + exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) - /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - idxGain = max( 0, min(15,idxGain) ); */ ratio = 0; + idxGain = 0; + move16(); move16(); - IF( GE_32( L_tmp, 32768 ) ) - { - idxGain = 15; - move16(); - } - ELSE - { - ratio = extract_l( L_tmp ); - exp_norm = norm_s( ratio ); - idxGain = sub( 14, exp_norm ); - idxGain = s_max( 0, idxGain ); - } - test(); test(); - IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) - { - idxGain = add( idxGain, 1 ); + IF( tmp != 0 && tmp2 != 0 ) + { + ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 + exp = sub( exp, exp2 ); + /* ratio = (float) sqrt( temp2 / fb_exc_energy ); + idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + + => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) + = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) + = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) + increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt + */ + exp = add( exp, 1 ); + ratio = Sqrt16( ratio, &exp ); + /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ + idxGain = sub( exp, 1 ); // 14 - (15-exp) + + /* idxGain = max( 0, min( 15, idxGain ) ); */ + idxGain = s_max( 0, s_min( 15, idxGain ) ); } /* ratio = (float)(1 << idxGain);*/ -- GitLab