diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 8e0d593a03940f6e01edb52fd2a07366dc5e59be..3329d33d1364ebda635a1f9ae8715f2f5198a82f 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -286,8 +286,6 @@ - - @@ -401,11 +399,7 @@ - - - - diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index 97eb07edc45edfeb2dd3beddc2bb1e55f5104e4c..b13f120be36ca98b0b9a3c67b1a3e373c407168a 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -199,12 +199,6 @@ enc_all_c - - enc_all_c - - - enc_all_c - enc_all_c @@ -295,18 +289,6 @@ enc_all_c - - enc_all_c - - - enc_all_c - - - enc_all_c - - - enc_all_c - enc_all_c diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 48be311001eed26b4e5c41e5f6bf8157fdc6e029..2e475c41bf95d3ffb309813bad6faa10b521edff 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3680,58 +3680,64 @@ gp_clips_fx.c /========================================================================================================*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ ); Word16 gp_clip_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) Q15*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 coder_type, /* i : type of coder Q0*/ + const Word16 xn[], /* i : target vector Q_new*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ const Word16 Q_new /* i : scaling factor */ ); void gp_clip_test_isf_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 isf[], /* i : isf values (in frequency domain) Q2.56*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm Q15*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ); void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ ); -Word16 Mode2_gp_clip( - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ +Word16 Mode2_gp_clip_fx( + const Word16 *voicing, /* i : normalized correlations from OL pitch Q15 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + const Word16 coder_type, /* i : type of coder Q0 */ + const Word16 xn[], /* i : target vector Q_xn */ Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 L_subfr, - const Word16 Q_xn /* i : xn data format */ + /* mem[0]: Q0 */ + /* mem[1]: 1Q14 */ + /* mem[2]: 8Q7 */ + /* mem[3]: Q0 (integer) */ + /* mem[4]: Q14 */ + /* mem[5]: Q14 */ + const Word16 L_subfr, /* Q0 */ + const Word16 Q_xn /* i : scaling factor of vector xn[] */ ); void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 m /* i : dimension of lsf Q0*/ ); void gp_clip_test_lsf_ivas_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 lsf[], /* i : LSF vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 lsf[], /* i : LSF vector 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ); /*========================================================================================================/ diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 8950b423b466c23b51c4f02d4d0909a43fc4e73b..bea89f5116e8d52f17b82f8a096f21f546042360 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -232,7 +232,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = Mode2_gp_clip( st->voicing_fx, i_subfr, st->coder_type, xn, st->clip_var_fx, L_SUBFR, Q_xn ); + clip_gain = Mode2_gp_clip_fx( st->voicing_fx, i_subfr, st->coder_type, xn, st->clip_var_fx, L_SUBFR, Q_xn ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index ae70dc6b33a5f4761cc65573c624c993b2f5394b..fa91460173d533b2f9c9c4c8a8fce0287500c69f 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -295,7 +295,7 @@ void coder_acelp_rf_fx( } ELSE { - clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); + clip_gain = Mode2_gp_clip_fx( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index ea88f28b5eff44a563723987895777f3666759dd..bbe16cea2c377fddd0209da2821cb6dfea5e2dc9 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -123,7 +123,7 @@ void encod_unvoiced_fx( * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - Mode2_gp_clip( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); + Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); *pt_pitch_fx = L_SUBFR; move16(); /*----------------------------------------------------------------------* @@ -358,7 +358,7 @@ void encod_unvoiced_ivas_fx( * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - Mode2_gp_clip( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); + Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); *pt_pitch_fx = L_SUBFR << 6; move16(); /*----------------------------------------------------------------------* diff --git a/lib_enc/gaus_enc.c b/lib_enc/gaus_enc.c deleted file mode 100644 index d441f6ead49ddcb3a6a1ffab0962633db8157cd0..0000000000000000000000000000000000000000 --- a/lib_enc/gaus_enc.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 03683dceacecf1333166d2c5a289887391dcbdc9..1f91a5d95c4936688f898ecefaf3d362d5259b08 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -41,22 +41,22 @@ static void gauss2v_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word *-------------------------------------------------------------------*/ Word16 gaus_encode_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 *h1, /* i : weighted filter input response Q14*/ + const Word16 *xn, /* i : target vector Q12*/ + Word16 *exc, /* o : pointer to excitation signal frame Q_new*/ + Word16 *mem_w0, /* o : weighting filter denominator memory Q_new*/ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word32 *gain_code, /* o : Code gain. Q16*/ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9*/ + Word16 *gain_inov, /* o : innovation gain Q12*/ + Word16 *voice_fac, /* o : voicing factor Q15*/ + Word16 *gain_pit, /* o : adaptive excitation gain Q14*/ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ ) { Word16 nb_bits, idx; @@ -66,6 +66,7 @@ Word16 gaus_encode_fx( Word16 exp, tmp, tmp_idx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* @@ -76,7 +77,7 @@ Word16 gaus_encode_fx( corr_xh_fx( xn, dn, h1 ); tmp_idx = shr( i_subfr, 6 ); - nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; /* Q0 */ move16(); gauss2v_fx( st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr( nb_bits, 1 ) ); @@ -92,10 +93,10 @@ Word16 gaus_encode_fx( Ltmp = Isqrt_lc( Ltmp, &exp_code ); *gain_inov = extract_h( L_shl( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ - nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; + nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; /* Q0 */ move16(); /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ - idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); + idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); /* Q0 */ push_indice_fx( st_fx->hBstr, IND_GAIN, idx, nb_bits ); /*----------------------------------------------------------------* @@ -108,20 +109,21 @@ Word16 gaus_encode_fx( #endif /* BASOP_NOGLOB */ FOR( i = 0; i < L_SUBFR; i++ ) { - exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); + exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); /* Q_new */ } /*----------------------------------------------------------------* * Updates: last value of new target is stored in mem_w0 *----------------------------------------------------------------*/ - Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); /* Q_new + 10 */ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /* Q_new + 15 + shift */ Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); /* Q_new + 15 + shift */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - *mem_w0 = round_fx_sat( Ltmp ); + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 16 */ + *mem_w0 = round_fx_sat( Ltmp ); /* Q_new */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); *mem_w0 = round_fx( Ltmp ); @@ -130,14 +132,14 @@ Word16 gaus_encode_fx( *gain_pit = 0; *tilt_code = 0; - move16(); /* purely unvoiced */ - *voice_fac = -32768; - move16(); /* purely unvoiced */ + move16(); /* purely unvoiced */ + *voice_fac = -32768; /* -1 in Q31 */ + move16(); /* purely unvoiced */ exp = sub( norm_s( *gain_inov ), 1 ); exp = s_max( exp, 0 ); tmp = div_s( shr( 8192, exp ), *gain_inov ); - *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); /* Q16 */ move16(); return ( L_SUBFR << 6 ); @@ -145,31 +147,33 @@ Word16 gaus_encode_fx( Word16 gaus_encode_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 *h1, /* i : weighted filter input response Q14*/ + const Word16 *xn, /* i : target vector Q12*/ + Word16 *exc, /* o : pointer to excitation signal frame Q_new*/ + Word16 *mem_w0, /* o : weighting filter denominator memory Q_new*/ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word32 *gain_code, /* o : Code gain. Q16*/ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9*/ + Word16 *gain_inov, /* o : innovation gain Q12*/ + Word16 *voice_fac, /* o : voicing factor Q15*/ + Word16 *gain_pit, /* o : adaptive excitation gain Q14*/ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ ) { Word16 nb_bits, idx; Word16 i = 0; + move16(); Word32 Ltmp; Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ Word16 exp, tmp, tmp_idx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* @@ -180,7 +184,7 @@ Word16 gaus_encode_ivas_fx( corr_xh_fx( xn, dn, h1 ); tmp_idx = shr( i_subfr, 6 ); - nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; + nb_bits = st_fx->acelp_cfg.fixed_cdk_index[tmp_idx]; /* Q0 */ move16(); gauss2v_ivas_fx( st_fx->hBstr, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr( nb_bits, 1 ) ); @@ -196,10 +200,10 @@ Word16 gaus_encode_ivas_fx( Ltmp = Isqrt_lc( Ltmp, &exp_code ); *gain_inov = extract_h( L_shl( Ltmp, sub( exp_code, 3 ) ) ); /* g_code_inov in Q12 */ - nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; + nb_bits = st_fx->acelp_cfg.gains_mode[tmp_idx]; /* Q0 */ move16(); /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ - idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); + idx = gain_enc_gaus_fx( gain_code, nb_bits, -7680, 28160, 19065 ); /* Q0 */ push_indice( st_fx->hBstr, IND_GAIN, idx, nb_bits ); /*----------------------------------------------------------------* @@ -212,20 +216,21 @@ Word16 gaus_encode_ivas_fx( #endif /* BASOP_NOGLOB */ FOR( i = 0; i < L_SUBFR; i++ ) { - exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); + exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); /* Q_new */ } /*----------------------------------------------------------------* * Updates: last value of new target is stored in mem_w0 *----------------------------------------------------------------*/ - Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_mult( gcode, y2[L_SUBFR - 1] ); /* Q_new + 10 */ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /* Q_new + 15 + shift */ Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); /* Q_new + 15 + shift */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - *mem_w0 = round_fx_sat( Ltmp ); + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 16 */ + *mem_w0 = round_fx_sat( Ltmp ); /* Q_new */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); *mem_w0 = round_fx( Ltmp ); @@ -234,14 +239,14 @@ Word16 gaus_encode_ivas_fx( *gain_pit = 0; *tilt_code = 0; - move16(); /* purely unvoiced */ - *voice_fac = -32768; - move16(); /* purely unvoiced */ + move16(); /* purely unvoiced */ + *voice_fac = -32768; /* -1 in Q15 */ + move16(); /* purely unvoiced */ exp = sub( norm_s( *gain_inov ), 1 ); exp = s_max( exp, 0 ); tmp = div_s( shr( 8192, exp ), *gain_inov ); - *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, exp ) ); /* Q16 */ move16(); return ( L_SUBFR << 6 ); @@ -265,7 +270,7 @@ void gauss2v_fx( const Word16 lg, /* i : subframe size Q0 */ const Word16 shift, /* i : Scaling factor Q0 */ const Word16 Q_new, /* i : Scaling factor Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ + const Word16 nb_bits /* i : nb ob bits per track (max 6) Q0 */ ) { Word16 i, j, ind1, ind2; @@ -308,6 +313,7 @@ void gauss2v_fx( Word16 shiftP3; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* @@ -315,15 +321,15 @@ void gauss2v_fx( *----------------------------------------------------------------*/ /* Compute spectral tilt of target */ - Lc0 = L_mult( xn[1], xn[1] ); - Lc1 = L_mult( xn[1], xn[0] ); + Lc0 = L_mult( xn[1], xn[1] ); /* Q25 */ + Lc1 = L_mult( xn[1], xn[0] ); /* Q25 */ FOR( i = 2; i < L_SUBFR; i++ ) { /* fc0 += xn[i]*xn[i] */ /* fc1 += xn[i]*xn[i-1] */ #ifdef BASOP_NOGLOB - Lc0 = L_mac_sat( Lc0, xn[i], xn[i] ); - Lc1 = L_mac_sat( Lc1, xn[i], xn[i - 1] ); + Lc0 = L_mac_sat( Lc0, xn[i], xn[i] ); /* Q25 */ + Lc1 = L_mac_sat( Lc1, xn[i], xn[i - 1] ); /* Q25 */ #else Lc0 = L_mac( Lc0, xn[i], xn[i] ); Lc1 = L_mac( Lc1, xn[i], xn[i - 1] ); @@ -336,22 +342,22 @@ void gauss2v_fx( Num = abs_s( Num ); Lc0 = L_max( Lc0, 1 ); exp_den = norm_l( Lc0 ); - Den = extract_h( L_shl( Lc0, exp_den ) ); + Den = extract_h( L_shl( Lc0, exp_den ) ); /* Q9 + exp_den */ gxx = shr( div_s( Num, Den ), sub( exp_num, sub( exp_den, 2 ) ) ); /* Q13 */ gxx = i_mult2( gxx, m_sign ); /* Apply sign */ - set16_fx( hg, 0, 190 ); /* Compute spectral tilt of filtered codebook */ - Copy( h, hg, L_SUBFR ); - conv_fx( gaus_dico_fx, hg, Gaus_dico2, 190 ); + set16_fx( hg, 0, 190 ); /* Compute spectral tilt of filtered codebook */ + Copy( h, hg, L_SUBFR ); // Q15 + conv_fx( gaus_dico_fx, hg, Gaus_dico2, 190 ); // Q12 - Lc0 = L_mult( Gaus_dico2[1], Gaus_dico2[1] ); - Lc1 = L_mult( Gaus_dico2[1], Gaus_dico2[0] ); + Lc0 = L_mult( Gaus_dico2[1], Gaus_dico2[1] ); /* Q25 */ + Lc1 = L_mult( Gaus_dico2[1], Gaus_dico2[0] ); /* Q25 */ FOR( i = 2; i < 190; i++ ) { /* fc0 += fgaus_dico2[i]*fgaus_dico2[i] */ /* fc1 += fgaus_dico2[i]*fgaus_dico2[i-1] */ - Lc0 = L_mac( Lc0, Gaus_dico2[i], Gaus_dico2[i] ); - Lc1 = L_mac( Lc1, Gaus_dico2[i], Gaus_dico2[i - 1] ); + Lc0 = L_mac( Lc0, Gaus_dico2[i], Gaus_dico2[i] ); /* Q25 */ + Lc1 = L_mac( Lc1, Gaus_dico2[i], Gaus_dico2[i - 1] ); /* Q25 */ } /* fgcc = fc1/fc0 */ @@ -372,8 +378,8 @@ void gauss2v_fx( Lden = L_mac( L_mult( gxx, 8192 ), gcc, 16384 ); /* Q30 */ exp_num = sub( norm_l( Lnum ), 1 ); - Num = extract_h( L_shl( Lnum, exp_num ) ); - m_sign = s_or( shr( Num, 16 ), 1 ); /* Remove sign */ + Num = extract_h( L_shl( Lnum, exp_num ) ); /* Q14 + exp_den */ + m_sign = s_or( shr( Num, 16 ), 1 ); /* Remove sign */ Num = abs_s( Num ); Lden = L_max( Lden, 1 ); @@ -385,7 +391,7 @@ void gauss2v_fx( #else /* BASOP_NOGLOB */ delta = shr( div_s( Num, Den ), sub( exp_num, exp_den ) ); /* Q15 */ #endif - delta = i_mult2( delta, m_sign ); /* Apply sign */ + delta = i_mult2( delta, m_sign ); /* Apply sign Q0*/ /* index_delta = (short)(FAC_DELTA * fdelta) */ index_delta = shr( delta, SFAC_DELTA ); @@ -403,7 +409,8 @@ void gauss2v_fx( move16(); /* Q15 */ /* fgaus_dico2[0] = gaus_dico[0] */ - Gaus_dico2[0] = gaus_dico_fx[0]; + Gaus_dico2[0] = gaus_dico_fx[0]; /* Q12 */ + move16(); FOR( i = 1; i < 190; i++ ) { /* fgaus_dico2[i] = (gaus_dico[i] - fdelta*gaus_dico[i-1]) / (1 + fdelta*fdelta) */ @@ -416,7 +423,7 @@ void gauss2v_fx( FOR( i = 0; i < 190; i++ ) { /* fgaus_dico2[i] = gaus_dico[i] */ - Gaus_dico2[i] = gaus_dico_fx[i]; + Gaus_dico2[i] = gaus_dico_fx[i]; /* Q12 */ move16(); } } @@ -661,7 +668,7 @@ void gauss2v_fx( i = (Word16) ( ( pos[ind1] - Gaus_dico2 ) / step ); /* Division by step can be replaced by shift. Pointer arithmetic */ j = (Word16) ( ( pos[ind2] - Gaus_dico2 ) / step ); /* Division by step can be replaced by shift. Pointer arithmetic */ - idx = cod_2pos_fx( i, j, sign1, sign2, nvec ); + idx = cod_2pos_fx( i, j, sign1, sign2, nvec ); /* Q0 */ move16(); push_indice_fx( hBstr, IND_GAUS_CDBK_INDEX, idx, 2 * nb_bits + 1 ); @@ -734,7 +741,7 @@ void gauss2v_fx( /* Gain must be output in a 32-bit variable as a Q16 */ /* Compensate for Q_new */ #ifdef BASOP_NOGLOB - *gain = L_shl_o( Portion, sub( 13, Q_new ), &Overflow ); + *gain = L_shl_o( Portion, sub( 13, Q_new ), &Overflow ); /* Q16 */ #else *gain = L_shl( Portion, sub( 13, Q_new ) ); #endif @@ -1238,12 +1245,12 @@ void gauss2v_ivas_fx( /*---------------------------------------------------------------------* * Put selected codevector positions and signs into quantization index *---------------------------------------------------------------------*/ -static Word16 cod_2pos_fx( /* o : codebook quantization index */ - const Word16 ind1, /* i : index of 1st gaussian vector */ - const Word16 ind2, /* i : index of 2nd gaussian vector */ - const Word16 sign1, /* i : sign of 1st gaussian vector */ - const Word16 sign2, /* i : sign of 2nd gaussian vector */ - const Word16 n /* i : nb. of codebook vectors */ +static Word16 cod_2pos_fx( /* o : codebook quantization index */ + const Word16 ind1, /* i : index of 1st gaussian vector Q0*/ + const Word16 ind2, /* i : index of 2nd gaussian vector Q0*/ + const Word16 sign1, /* i : sign of 1st gaussian vector Qx*/ + const Word16 sign2, /* i : sign of 2nd gaussian vector Qx*/ + const Word16 n /* i : nb. of codebook vectors Q0*/ ) { Word16 i1, i2, index, s1, s2; @@ -1267,16 +1274,16 @@ static Word16 cod_2pos_fx( /* o : codebook quantization in { IF( LE_16( ind1, ind2 ) ) { - i1 = ind1; + i1 = ind1; /* Q0 */ move16(); - i2 = ind2; + i2 = ind2; /* Q0 */ move16(); } ELSE { - i1 = ind2; + i1 = ind2; /* Q0 */ move16(); - i2 = ind1; + i2 = ind1; /* Q0 */ move16(); } } @@ -1284,16 +1291,16 @@ static Word16 cod_2pos_fx( /* o : codebook quantization in { IF( GT_16( ind1, ind2 ) ) { - i1 = ind1; + i1 = ind1; /* Q0 */ move16(); - i2 = ind2; + i2 = ind2; /* Q0 */ move16(); } ELSE { - i1 = ind2; + i1 = ind2; /* Q0 */ move16(); - i2 = ind1; + i2 = ind1; /* Q0 */ move16(); s1 = s2; move16(); diff --git a/lib_enc/gp_clip.c b/lib_enc/gp_clip.c deleted file mode 100644 index 7dd2c1f21169fdc182f70f2f4e86aa4bb3106165..0000000000000000000000000000000000000000 --- a/lib_enc/gp_clip.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "prot.h" -#include "cnst.h" -#include "wmc_auto.h" diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index bf532a085cf9fc3164f867f3c3e3db1a1de82d13..4ca86a09cbd191637cf4340ec52a0a8bb5dd75d2 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -68,7 +68,7 @@ * Pitch Gain clipping initializations *-------------------------------------------------------------------*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ ) { mem[0] = DIST_ISF_MAX; @@ -98,13 +98,13 @@ void init_gp_clip_fx( *-------------------------------------------------------------------*/ Word16 gp_clip_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 *voicing, /* i : normalized correlations (from OL pitch) Q15*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 coder_type, /* i : type of coder Q0*/ + const Word16 xn[], /* i : target vector Q_new*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ const Word16 Q_new /* i : scaling factor */ ) { @@ -116,16 +116,16 @@ Word16 gp_clip_fx( Word16 thres; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif clip = 0; move16(); test(); test(); - IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || element_mode > EVS_MONO ) { - thres = add( 14746, mult( 1638, extract_l( L_mult( mem[0], (Word16) ( 16384 / DIST_ISF_MAX_IO ) ) ) ) ); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ - test(); + thres = add( 14746 /* 0.9 in Q14 */, mult( 1638 /* 0.1 in Q14 */, extract_l( L_mult( mem[0], (Word16) ( 16384 / DIST_ISF_MAX_IO ) ) ) ) ); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ if ( GT_16( mem[1], thres ) ) { clip = 1; @@ -160,7 +160,7 @@ Word16 gp_clip_fx( e_ener = norm_l( ener ); f_ener = Log2_norm_lc( L_shl( ener, e_ener ) ); e_ener = sub( 30, e_ener ); - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { e_ener = sub( e_ener, Q_new * 2 + 1 ); } @@ -168,20 +168,20 @@ Word16 gp_clip_fx( { e_ener = sub( e_ener, Q_new ); } - ener = Mpy_32_16( e_ener, f_ener, LG10 ); - wener = round_fx( L_shl( ener, 10 ) ); + ener = Mpy_32_16( e_ener, f_ener, LG10 ); /* Q14 */ + wener = round_fx( L_shl( ener, 10 ) ); /* Q8 */ test(); - if ( LT_16( wener, sub( mem[2], 1536 ) ) && GT_16( mem[1], 16384 ) ) + if ( LT_16( wener, sub( mem[2], 1536 /* 6.0f in Q8 */ ) ) && GT_16( mem[1], 16384 /* 1 in Q14 */ ) ) { clip = 1; move16(); } - mem[2] = wener; + mem[2] = wener; /* Q8 */ move16(); - L_tmp = L_mult( ALPHA1, mem[4] ); + L_tmp = L_mult( ALPHA1, mem[4] ); /* Q30 */ test(); test(); @@ -189,19 +189,19 @@ Word16 gp_clip_fx( { /* mem[4] = (1-ALPHA1) + ALPHA1 * mem[4], if branch taken */ /* mem[4] = ALPHA1 * mem[4], otherwise */ - L_tmp = L_add( L_tmp, 32768L * ( 32768 - ALPHA1 ) ); + L_tmp = L_add( L_tmp, 32768L * ( 32768 - ALPHA1 ) ); /* Q30 */ } - mem[4] = round_fx( L_tmp ); + mem[4] = round_fx( L_tmp ); /* Q14 */ L_tmp = L_mult( ALPHA4, mem[5] ); - if ( i_subfr == 0 ) + IF( i_subfr == 0 ) { /* mem[5] = (1-ALPHA4) * voicing[0] + ALPHA4 * mem[5] */ mem[5] = mac_r( L_tmp, ( 32768 - ALPHA4 ) / 2, voicing[0] ); move16(); /* /2 to put voicing from Q15 to Q14 */ } - if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) + IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { /* mem[5] = (1-ALPHA4) * voicing[1] + ALPHA4 * mem[5] */ mem[5] = mac_r( L_tmp, ( 32768 - ALPHA4 ) / 2, voicing[1] ); @@ -219,7 +219,7 @@ Word16 gp_clip_fx( } ELSE { - mem[3] = add( mem[3], 1 ); + mem[3] = add( mem[3], 1 ); /* Q0 */ move16(); } @@ -233,16 +233,16 @@ Word16 gp_clip_fx( *-------------------------------------------------------------------*/ void gp_clip_test_isf_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 isf[], /* i : isf values (in frequency domain) Q2.56*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm Q15*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ) { Word16 i, dist, dist_min, m; - dist_min = sub( isf[1], isf[0] ); + dist_min = sub( isf[1], isf[0] ); /* Q2.56 */ m = M; move16(); @@ -255,15 +255,15 @@ void gp_clip_test_isf_fx( move16(); /* ptr init*/ FOR( i = 2; i < m; i++ ) { - dist = sub( isf[i], isf[i - 1] ); - dist_min = s_min( dist, dist_min ); + dist = sub( isf[i], isf[i - 1] ); /* Q2.56 */ + dist_min = s_min( dist, dist_min ); /* Q2.56 */ } - dist = extract_h( L_mac( L_mult( 26214, mem[0] ), 6554, dist_min ) ); + dist = extract_h( L_mac( L_mult( 26214 /* 0.8f in Q15 */, mem[0] ), 6554 /* 0.2f in Q15 */, dist_min ) ); /* Q15 */ test(); test(); - IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || element_mode > EVS_MONO ) { dist = s_min( dist, DIST_ISF_MAX_IO ); } @@ -271,7 +271,7 @@ void gp_clip_test_isf_fx( { dist = s_min( dist, DIST_ISF_MAX ); } - mem[0] = dist; + mem[0] = dist; /* Q15 */ move16(); return; @@ -284,10 +284,10 @@ void gp_clip_test_isf_fx( *-------------------------------------------------------------------*/ void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ ) { Word16 gain; @@ -295,19 +295,19 @@ void gp_clip_test_gain_pit_fx( test(); test(); - IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || GT_16( element_mode, EVS_MONO ) ) + IF( EQ_32( core_brate, ACELP_6k60 ) || EQ_32( core_brate, ACELP_8k85 ) || element_mode > EVS_MONO ) { - L_tmp = L_mult( 32113, mem[1] ); /* long term LTP gain average (>250ms) */ - L_tmp = L_mac( L_tmp, 655, gain_pit ); + L_tmp = L_mult( 32113 /* 0.98 in Q15 */, mem[1] ); /* long term LTP gain average (>250ms) */ + L_tmp = L_mac( L_tmp, 655 /* 0.02 in Q15 */, gain_pit ); } ELSE { - L_tmp = L_mult( 29491, mem[1] ); - L_tmp = L_mac( L_tmp, 3277, gain_pit ); + L_tmp = L_mult( 29491 /* 0.9 in Q15 */, mem[1] ); + L_tmp = L_mac( L_tmp, 3277 /* 0.1 in Q15 */, gain_pit ); } gain = extract_h( L_tmp ); gain = s_max( gain, GAIN_PIT_MIN ); - mem[1] = gain; + mem[1] = gain; /* Q14 */ move16(); return; @@ -323,10 +323,10 @@ void gp_clip_test_gain_pit_fx( * prediction (lp_gp > 0.9) * - target energy drops by 6 dB AND a good pitch prediction (lp_gp>1.0) *-------------------------------------------------------------------*/ -Word16 Mode2_gp_clip( +Word16 Mode2_gp_clip_fx( const Word16 *voicing, /* i : normalized correlations from OL pitch Q15 */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ + const Word16 i_subfr, /* i : subframe index Q0 */ + const Word16 coder_type, /* i : type of coder Q0 */ const Word16 xn[], /* i : target vector Q_xn */ Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ /* mem[0]: Q0 */ @@ -335,8 +335,8 @@ Word16 Mode2_gp_clip( /* mem[3]: Q0 (integer) */ /* mem[4]: Q14 */ /* mem[5]: Q14 */ - const Word16 L_subfr, - const Word16 Q_xn /* i : scaling factor of vector xn[] */ + const Word16 L_subfr, /* Q0 */ + const Word16 Q_xn /* i : scaling factor of vector xn[] */ ) { Word16 clip, tmp, exp_xn; @@ -344,6 +344,7 @@ Word16 Mode2_gp_clip( Word32 wener, Ltmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); clip = 0; @@ -393,20 +394,20 @@ Word16 Mode2_gp_clip( if ( s_or( (Word16) EQ_16( coder_type, GENERIC ), (Word16) EQ_16( coder_type, TRANSITION ) ) ) { - Ltmp = L_add( Ltmp, ALPHA1_M1 ); + Ltmp = L_add( Ltmp, ALPHA1_M1 ); /* Q30 */ } - mem[4] = round_fx( Ltmp ); + mem[4] = round_fx( Ltmp ); /* Q14 */ Ltmp = Mpy_32_16_1( ALPHA4, mem[5] ); /* mem[5] in Q14 format, Ltmp in Q14 */ IF( i_subfr == 0 ) { - move16(); /* voicing: Q15 */ - mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[0] ), Ltmp ) ); + move16(); /* voicing: Q15 */ + mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[0] ), Ltmp ) ); /* Q14 */ } ELSE IF( EQ_16( i_subfr, shl( L_subfr, 1 ) ) ) { move16(); - mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[1] ), Ltmp ) ); + mem[5] = round_fx( L_add( Mpy_32_16_1( ALPHA4_M1, voicing[1] ), Ltmp ) ); /* Q14 */ } IF( GT_16( mem[3], WINDOW_SIZE ) ) @@ -421,7 +422,7 @@ Word16 Mode2_gp_clip( ELSE { move16(); - mem[3] = add( mem[3], 1 ); + mem[3] = add( mem[3], 1 ); /* Q0 */ } @@ -434,10 +435,10 @@ Word16 Mode2_gp_clip( * check the minimum distance of LSFs for pitch gain clipping flag *-------------------------------------------------------------------*/ void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 m /* i : dimension of lsf Q0*/ ) { Word16 i; @@ -445,22 +446,22 @@ void gp_clip_test_lsf_fx( dist_max = DIST_ISF_MAX; move16(); - if ( GT_16( element_mode, EVS_MONO ) ) + if ( element_mode > EVS_MONO ) { dist_max = DIST_ISF_MAX_IO; move16(); } - dist_min = sub( lsf[1], lsf[0] ); + dist_min = sub( lsf[1], lsf[0] ); /* 14Q1*1.28 */ FOR( i = 2; i < m - 1; i++ ) { - dist = sub( lsf[i], lsf[i - 1] ); + dist = sub( lsf[i], lsf[i - 1] ); /* 14Q1*1.28 */ dist_min = s_min( dist, dist_min ); } /*dist = 0.8f*mem[0] + 0.2f*dist_min;*/ - dist = s_min( dist_max, mac_r( L_mult( 26214 /*0.8f Q15*/, mem[0] ), 6554 /*0.2f Q15*/, dist_min ) ); + dist = s_min( dist_max, mac_r( L_mult( 26214 /*0.8f Q15*/, mem[0] ), 6554 /*0.2f Q15*/, dist_min ) ); /* x2.56 */ - mem[0] = dist; + mem[0] = dist; /* x2.56 */ move16(); @@ -468,18 +469,18 @@ void gp_clip_test_lsf_fx( } void gp_clip_test_lsf_ivas_fx( - const Word16 element_mode, /* i : element mode */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 lsf[], /* i : LSF vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 lsf[], /* i : LSF vector 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ) { Word16 i; Word16 m; Word16 dist, dist_min; - dist_min = sub( lsf[1], lsf[0] ); + dist_min = sub( lsf[1], lsf[0] ); /* 14Q1*1.28 */ IF( Opt_AMR_WB ) { @@ -494,12 +495,12 @@ void gp_clip_test_lsf_ivas_fx( FOR( i = 2; i < m; i++ ) { - dist = sub( lsf[i], lsf[i - 1] ); + dist = sub( lsf[i], lsf[i - 1] ); /* 14Q1*1.28 */ dist_min = s_min( dist, dist_min ); } // dist = 0.8f * mem[0] + 0.2f * dist_min; - dist = mac_r( L_mult( 26214 /*0.8f Q15*/, mem[0] ), 6554 /*0.2f Q15*/, dist_min ); + dist = mac_r( L_mult( 26214 /*0.8f Q15*/, mem[0] ), 6554 /*0.2f Q15*/, dist_min ); /* 2.56x */ test(); test(); @@ -517,7 +518,7 @@ void gp_clip_test_lsf_ivas_fx( move16(); } - mem[0] = dist; + mem[0] = dist; /* 2.56x */ move16(); return; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 355b575a619e77c0aaf1428df2430c0bdcc1bfdd..057424445a512e3fcb8b0da59a791b95cc4ac7ae 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -209,16 +209,27 @@ ivas_error ivas_cpe_enc_fx( Copy32( data_fx_ch0, sts[0]->input32_fx, input_frame ); // Q(q_data_fx) sts[0]->q_inp32 = q_data_fx; move16(); - Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 - sts[0]->q_inp = 0; + Word16 norm = L_norm_arr( sts[0]->input32_fx, input_frame ); + scale_sig32( sts[0]->input32_fx, input_frame, norm ); + sts[0]->q_inp32 = add( sts[0]->q_inp32, norm ); + move16(); + + Copy_Scale_sig32_16( sts[0]->input32_fx, sts[0]->input_fx, input_frame, 0 ); + sts[0]->q_inp = sub( sts[0]->q_inp32, Q16 ); move16(); IF( data_fx_ch1 != NULL ) /*this may happen for cases with odd number of channels*/ { Copy32( data_fx_ch1, sts[1]->input32_fx, input_frame ); // Q(q_data_fx) sts[1]->q_inp32 = q_data_fx; move16(); - Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, sub( Q16, q_data_fx ) ); // Q(q_data_fx) -> Q0 - sts[1]->q_inp = 0; + + norm = L_norm_arr( sts[1]->input32_fx, input_frame ); + scale_sig32( sts[1]->input32_fx, input_frame, norm ); + sts[1]->q_inp32 = add( sts[1]->q_inp32, norm ); + move16(); + + Copy_Scale_sig32_16( sts[1]->input32_fx, sts[1]->input_fx, input_frame, 0 ); + sts[1]->q_inp = sub( sts[1]->q_inp32, Q16 ); move16(); } diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 17d98b765dbfc033e0c24669ab8fa213a0213032..6020d83516321a44fe1a58e145ac74e88aee9971 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -67,7 +67,7 @@ static void unclr_calc_corr_features_fx( #define XH_BIAS_FX_Q15 13107 #define XL_WIDTH_FX_Q15 3932 #define XH_WIDTH_FX_Q15 4915 -#define SMOOTH_DIST_FACTOR_FX_Q15 14418 +#define SMOOTH_DIST_FACTOR_FX_Q15 13107 #define A_BIAS_FX_Q15 3277 #define B_BIAS_FX_Q15 -16384 #define A_WIDTH_FX_Q31 32212264 @@ -840,23 +840,13 @@ static void corrStatsEst_fx( scale_sig32( corrEst_fx, 2 * L_NCSHIFT_DS + 1, temp ); /* Q31-corrEst_exp */ corrEst_exp = sub( corrEst_exp, temp ); - IF( GT_16( corrEst_exp, hStereoTCA->corrEstPrev_exp ) ) - { - scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); /* Q31-hStereoTCA->corrEstPrev_exp */ - scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, sub( hStereoTCA->corrEstPrev_exp, corrEst_exp ) ); /* Q31-hStereoTCA->corrEstPrev_exp */ - Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); /* Q31-corrEst_exp */ - hStereoTCA->corrEstPrev_exp = corrEst_exp; - move16(); - } - ELSE - { - Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); /* Q31-corrEst_exp */ - scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, sub( corrEst_exp, hStereoTCA->corrEstPrev_exp ) ); /* Q31-corrEst_exp */ - } - scale_sig32( hStereoTCA->corrEstPrev_fx[0], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ - scale_sig32( hStereoTCA->corrEstPrev_fx[1], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ - scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, -1 ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ - hStereoTCA->corrEstPrev_exp = add( hStereoTCA->corrEstPrev_exp, 1 ); + Copy32( corrEst_fx, hStereoTCA->corrEstPrev_fx[2], tempLen ); /* Q31-corrEst_exp */ + hStereoTCA->corrEstPrev_exp = corrEst_exp; + move16(); + Word16 gb = find_guarded_bits_fx( 2 * L_NCSHIFT_DS + 1 ); + + scale_sig32( hStereoTCA->corrEstPrev_fx[2], 2 * L_NCSHIFT_DS + 1, -gb ); /* Q31-hStereoTCA->corrEstPrev_exp-1 */ + hStereoTCA->corrEstPrev_exp = add( hStereoTCA->corrEstPrev_exp, gb ); move16(); Word32 buf1_fx_temp[L_FRAME_DS]; Word32 buf2_fx_temp[L_FRAME_DS]; @@ -1032,7 +1022,8 @@ static void corrStatsEst_fx( loc_weight_win_fx[i] = win_bias_fx; // Q15 move16(); } - + reg_prv_corr_fx = L_shr( reg_prv_corr_fx, 1 ); + reg_prv_corr_exp = add( reg_prv_corr_exp, 1 ); Word16 x = TRUNC_FX( reg_prv_corr_fx, reg_prv_corr_exp ); /* Q0 */ move16(); for ( i = 0, j = ( L_NCSHIFT_DS - x ); i < 2 * L_NCSHIFT_DS + 1; i++, j++ ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 357d3120ce631230143eae8d002dbfb158bf27a0..e9a09befcf34d98681ed09bdb645bb02ff8ead93 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1493,34 +1493,34 @@ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, void lpc_quantization_fx( Encoder_State *st, - const Word16 lsp[], - const Word16 lspmid[], - Word16 lsp_q[], - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], - Word16 lspq_ind[], - Word16 clip_var[], - const Word16 coder_type, - const Word16 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 *bits_param_lpc, - Word16 *no_param_lpc, + const Word16 lsp[], /* Q15 */ + const Word16 lspmid[], /* Q15 */ + Word16 lsp_q[], /* Q15 */ + Word16 lsf_q[], /* 14Q1*1.28 */ + Word16 lspmid_q[], /* Q15 */ + Word16 lspq_ind[], /* Q15 */ + Word16 clip_var[], /* [2.56x,Q14,Q8,Q0,Q14,Q14] */ + const Word16 coder_type, /* Q0 */ + const Word16 acelp_midLpc, /* Q0 */ + Word16 param_lpc[], /* Q0 */ + Word16 nbits_lpc[], /* Q0 */ + Word16 *bits_param_lpc, /* Q0 */ + Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ); void lpc_quantization_ivas_fx( Encoder_State *st, - const Word16 lsp[], /* Q15 */ - const Word16 lspmid[], /* Q15 */ - Word16 lsp_q[], /* Q15 */ - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], /* Q15 */ - const Word16 coder_type, - const Word16 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 *bits_param_lpc, - Word16 *no_param_lpc, + const Word16 lsp[], /* Q15 */ + const Word16 lspmid[], /* Q15 */ + Word16 lsp_q[], /* Q15 */ + Word16 lsf_q[], /* 14Q1*1.28 */ + Word16 lspmid_q[], /* Q15 */ + const Word16 coder_type, /* Q0 */ + const Word16 acelp_midLpc, /* Q0 */ + Word16 param_lpc[], /* Q0 */ + Word16 nbits_lpc[], /* Q0 */ + Word16 *bits_param_lpc, /* Q0 */ + Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ); void Mode2_pit_encode_fx( @@ -2816,18 +2816,18 @@ Word16 enc_lsf_tcxlpc_ivas_fx( Word16 encode_lpc_avq_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc */ - const Word16 *param_lpc, /* i : lpc parameters */ - const Word16 core, /* i : core */ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ + const Word16 numlpc, /* i : Number of sets of lpc Q0*/ + const Word16 *param_lpc, /* i : lpc parameters Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ ); Word16 encode_lpc_avq_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc */ - const Word16 *param_lpc, /* i : lpc parameters */ - const Word16 core, /* i : core */ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ + const Word16 numlpc, /* i : Number of sets of lpc Q0*/ + const Word16 *param_lpc, /* i : lpc parameters Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ ); Word16 lsf_bctcvq_encprm_fx( @@ -2964,11 +2964,11 @@ void qlpc_avq_fx( const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ Word16 *lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ Word16 *lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ - Word16 *index, /* o : Quantization indices */ - Word16 *nb_indices, /* o : Number of quantization indices */ - Word16 *nbbits, /* o : Number of quantization bits */ - const Word16 core, /* i : TCX10 or TCX20 */ - const Word32 sr_core /* i : internal sampling rate */ + Word16 *index, /* o : Quantization indices Q0 */ + Word16 *nb_indices, /* o : Number of quantization indices Q0 */ + Word16 *nbbits, /* o : Number of quantization bits Q0 */ + const Word16 core, /* i : TCX10 or TCX20 Q0 */ + const Word32 sr_core /* i : internal sampling rate Q0 */ ); /* ivas_tcx_core_enc.c */ @@ -3539,10 +3539,10 @@ void encod_amr_wb_fx( Word16 Q_new ); void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 x[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) Q0*/ + UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) Q0*/ + Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index Q0*/ ); void TBEreset_enc_fx( @@ -3885,42 +3885,42 @@ void gain_enc_tc_ivas_fx( Word16 gaus_encode_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter i response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 *h1, /* i : weighted filter input response Q14*/ + const Word16 *xn, /* i : target vector Q12*/ + Word16 *exc, /* o : pointer to excitation signal frame Q_new*/ + Word16 *mem_w0, /* o : weighting filter denominator memory Q_new*/ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word32 *gain_code, /* o : Code gain. Q16*/ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9*/ + Word16 *gain_inov, /* o : innovation gain Q12*/ + Word16 *voice_fac, /* o : voicing factor Q15*/ + Word16 *gain_pit, /* o : adaptive excitation gain Q14*/ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ ); Word16 gaus_encode_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 *h1, /* i : weighted filter input response Q14*/ + const Word16 *xn, /* i : target vector Q12*/ + Word16 *exc, /* o : pointer to excitation signal frame Q_new*/ + Word16 *mem_w0, /* o : weighting filter denominator memory Q_new*/ + Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15*/ + Word16 *code, /* o : algebraic excitation Q9*/ + Word32 *gain_code, /* o : Code gain. Q16*/ + Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9*/ + Word16 *gain_inov, /* o : innovation gain Q12*/ + Word16 *voice_fac, /* o : voicing factor Q15*/ + Word16 *gain_pit, /* o : adaptive excitation gain Q14*/ + const Word16 Q_new, /* i : scaling factor */ + const Word16 shift, /* i : scaling factor */ + Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ ); void pre_proc_fx( @@ -4445,14 +4445,14 @@ Word32 mslvq_cng_ivas_fx( ); void Unified_weighting_fx( - const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband Q0*/ + const Word16 unvoiced, /* i : flag for Unvoiced frame Q0*/ + const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ + const Word16 order /* i : LP order Q0*/ ); Word32 qlsf_ARSN_tcvq_Enc_16k_fx( @@ -4581,7 +4581,7 @@ void pvq_encode_ivas_fx( ); void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget Q0*/ ); void rc_enc_finish_fx( @@ -4594,43 +4594,43 @@ void rc_enc_finish_ivas_fx( ); void rc_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ); void rc_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ); void rc_enc_uniform_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ); void rc_enc_uniform_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ); void rc_enc_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ); void rc_enc_bits_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ); void re8_compute_base_index_fx( const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index b3b126876ce5b858466290261984f152bbd4325e..13e0a3cf7e196cb86b31882c04a719a52bd8d1f0 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -23,11 +23,11 @@ void qlpc_avq_fx( const Word16 *lsfmid, /* i : Input LSF vectors (14Q1*1.28) */ Word16 *lsf_q, /* o : Quantized LFS vectors (14Q1*1.28) */ Word16 *lsfmid_q, /* o : Quantized LFS vectors (14Q1*1.28) */ - Word16 *index, /* o : Quantization indices */ - Word16 *nb_indices, /* o : Number of quantization indices */ - Word16 *nbbits, /* o : Number of quantization bits */ - const Word16 core, /* i : TCX10 or TCX20 */ - const Word32 sr_core /* i : internal sampling rate */ + Word16 *index, /* o : Quantization indices Q0 */ + Word16 *nb_indices, /* o : Number of quantization indices Q0 */ + Word16 *nbbits, /* o : Number of quantization bits Q0 */ + const Word16 core, /* i : TCX10 or TCX20 Q0 */ + const Word32 sr_core /* i : internal sampling rate Q0 */ ) { Word16 i; @@ -37,25 +37,25 @@ void qlpc_avq_fx( /* Init */ - tmp_index = &index[0]; + tmp_index = &index[0]; // Q0 *nb_indices = 0; move16(); - tmp_index[0] = vlpc_1st_cod_fx( lsf, lsf_q, dummy, 0 ); + tmp_index[0] = vlpc_1st_cod_fx( lsf, lsf_q, dummy, 0 ); // Q0 - nbt = vlpc_2st_cod_fx( lsf, lsf_q, &tmp_index[1], 0, sr_core ); + nbt = vlpc_2st_cod_fx( lsf, lsf_q, &tmp_index[1], 0, sr_core ); // Q0 /*nit = 1 + 2 + index[1] + index[2]; nit < NPRM_LPC_NEW(=50) */ - nit = add( add( 3, index[1] ), index[2] ); + nit = add( add( 3, index[1] ), index[2] ); // Q0 assert( nit < NPRM_LPC_NEW ); /*tmp_index += nit;*/ tmp_index = tmp_index + nit; /**nb_indices += nit;*/ - *nb_indices = add( *nb_indices, nit ); + *nb_indices = add( *nb_indices, nit ); // Q0 move16(); /*nbbits[0] = 8 + nbt;*/ - nbbits[0] = add( 8, nbt ); + nbbits[0] = add( 8, nbt ); // Q0 move16(); *tmp_index = 0; @@ -70,51 +70,51 @@ void qlpc_avq_fx( /* Quantize intermediate LPC (512 framing) */ tmp_index++; /**nb_indices +=1;*/ - *nb_indices = add( *nb_indices, 1 ); + *nb_indices = add( *nb_indices, 1 ); // Q0 move16(); /* LPC2: Abs? */ - tmp_index[0] = vlpc_1st_cod_fx( lsfmid, lsfmid_q, dummy, 0 ); + tmp_index[0] = vlpc_1st_cod_fx( lsfmid, lsfmid_q, dummy, 0 ); // Q0 - nbits = vlpc_2st_cod_fx( lsfmid, lsfmid_q, &tmp_index[1], 0, sr_core ); + nbits = vlpc_2st_cod_fx( lsfmid, lsfmid_q, &tmp_index[1], 0, sr_core ); // Q0 /*nbt = 8 + nbits;*/ nbt = add( 8, nbits ); /*nit = 1 + 2 + tmp_index[1] + tmp_index[2];*/ - nit = add( add( 3, tmp_index[1] ), tmp_index[2] ); + nit = add( add( 3, tmp_index[1] ), tmp_index[2] ); // Q0 /* LPC2: RelR? */ FOR( i = 0; i < M; i++ ) { - lsfmid_q0[i] = lsf_q[i]; + lsfmid_q0[i] = lsf_q[i]; /* 14Q1*1.28 */ move16(); } - nbits = vlpc_2st_cod_fx( lsfmid, lsfmid_q0, indxt, 3, sr_core ); + nbits = vlpc_2st_cod_fx( lsfmid, lsfmid_q0, indxt, 3, sr_core ); // Q0 IF( LT_16( nbits, nbt ) ) { - nbt = nbits; + nbt = nbits; // Q0 move16(); /*nit = 2 + indxt[0] + indxt[1];*/ - nit = add( add( 2, indxt[0] ), indxt[1] ); + nit = add( add( 2, indxt[0] ), indxt[1] ); // Q0 tmp_index[-1] = 1; move16(); FOR( i = 0; i < M; i++ ) { - lsfmid_q[i] = lsfmid_q0[i]; + lsfmid_q[i] = lsfmid_q0[i]; /* 14Q1*1.28 */ move16(); } FOR( i = 0; i < nit; i++ ) { - tmp_index[i] = indxt[i]; + tmp_index[i] = indxt[i]; // Q0 move16(); } } tmp_index += nit; /**nb_indices += nit;*/ - *nb_indices = add( *nb_indices, nit ); + *nb_indices = add( *nb_indices, nit ); // Q0 move16(); /*nbbits[1] = 1 + nbt;*/ nbbits[1] = add( 1, nbt ); @@ -129,7 +129,9 @@ void qlpc_avq_fx( * *--------------------------------------------------------------------*/ -static Word16 unary_code( Word16 ind, BSTR_ENC_HANDLE hBstr ) +static Word16 unary_code( + Word16 ind, /* Q0 */ + BSTR_ENC_HANDLE hBstr ) { Word16 nb_bits; @@ -142,7 +144,7 @@ static Word16 unary_code( Word16 ind, BSTR_ENC_HANDLE hBstr ) FOR( ; ind > 0; ind-- ) { push_next_indice_fx( hBstr, 1, 1 ); - nb_bits = add( nb_bits, 1 ); + nb_bits = add( nb_bits, 1 ); // Q0 } /* Stop bit */ @@ -150,7 +152,9 @@ static Word16 unary_code( Word16 ind, BSTR_ENC_HANDLE hBstr ) return ( nb_bits ); } -static Word16 unary_code_ivas_fx( Word16 ind, BSTR_ENC_HANDLE hBstr ) +static Word16 unary_code_ivas_fx( + Word16 ind, /* Q0 */ + BSTR_ENC_HANDLE hBstr ) { Word16 nb_bits; @@ -158,18 +162,18 @@ static Word16 unary_code_ivas_fx( Word16 ind, BSTR_ENC_HANDLE hBstr ) nb_bits = 1; /* Index bits */ - ind = sub( ind, 1 ); + ind = sub( ind, 1 ); // Q0 WHILE( ind >= 16 ) { push_next_indice( hBstr, 0xffffU, 16 ); - nb_bits = add( nb_bits, 16 ); + nb_bits = add( nb_bits, 16 ); // Q0 ind = sub( ind, 16 ); } IF( ind > 0 ) { push_next_indice( hBstr, ( 1U << ind ) - 1, ind ); - nb_bits = add( nb_bits, ind ); + nb_bits = add( nb_bits, ind ); // Q0 } /* Stop bit */ @@ -182,7 +186,10 @@ static Word16 unary_code_ivas_fx( Word16 ind, BSTR_ENC_HANDLE hBstr ) * * *--------------------------------------------------------------------*/ -static Word16 unpack4bits( Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr ) +static Word16 unpack4bits( + Word16 nbits, /* Q0 */ + const Word16 *prm, /* Q0 */ + BSTR_ENC_HANDLE hBstr ) { Word16 i; @@ -208,7 +215,10 @@ static Word16 unpack4bits( Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBst return ( i ); } -static Word16 unpack4bits_ivas_fx( Word16 nbits, const Word16 *prm, BSTR_ENC_HANDLE hBstr ) +static Word16 unpack4bits_ivas_fx( + Word16 nbits, /* Q0 */ + const Word16 *prm, /* Q0 */ + BSTR_ENC_HANDLE hBstr ) { Word16 i; @@ -242,10 +252,10 @@ static Word16 unpack4bits_ivas_fx( Word16 nbits, const Word16 *prm, BSTR_ENC_HAN Word16 encode_lpc_avq_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc */ - const Word16 *param_lpc, /* i : lpc parameters */ - const Word16 core, /* i : core */ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ + const Word16 numlpc, /* i : Number of sets of lpc Q0*/ + const Word16 *param_lpc, /* i : lpc parameters Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ ) { Word16 k, j; @@ -281,13 +291,13 @@ Word16 encode_lpc_avq_fx( if ( k != 0 ) { move16(); - q_type = param_lpc[j]; + q_type = param_lpc[j]; // Q0 j = add( j, 1 ); } test(); if ( EQ_16( element_mode, IVAS_CPE_MDCT ) && k == 0 ) { - stereo_mode = param_lpc[j]; + stereo_mode = param_lpc[j]; // Q0 move16(); j = add( j, 1 ); } @@ -298,17 +308,19 @@ Word16 encode_lpc_avq_fx( if ( q_type == 0 ) { move16(); - st1 = param_lpc[j++]; + st1 = param_lpc[j++]; // Q0 } move16(); move16(); - qn1 = param_lpc[j++]; - qn2 = param_lpc[j++]; + qn1 = param_lpc[j++]; // Q0 + qn2 = param_lpc[j++]; // Q0 IF( EQ_16( qn1, SNS_LOW_BR_MODE ) ) { nb_ind = add( qn1, qn2 ); } + test(); + test(); IF( k == 0 || ( EQ_16( k, 1 ) && NE_16( core, TCX_20_CORE ) ) ) { /* Encode quantizer type */ @@ -317,12 +329,13 @@ Word16 encode_lpc_avq_fx( IF( k != 0 ) { nb = 1; + move16(); push_next_indice_fx( hBstr, q_type, nb ); } - nb_bits = add( nb_bits, nb ); + nb_bits = add( nb_bits, nb ); // Q0 /* Encode quantizer data */ -#if 1 // IVAS_CODE + test(); test(); test(); test(); @@ -330,7 +343,7 @@ Word16 encode_lpc_avq_fx( { /* Absolute quantizer with 1st stage stochastic codebook */ push_next_indice_fx( hBstr, st1, bits_for_abs_quant ); - nb_bits = add( nb_bits, bits_for_abs_quant ); + nb_bits = add( nb_bits, bits_for_abs_quant ); // Q0 } test(); @@ -338,21 +351,16 @@ Word16 encode_lpc_avq_fx( IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && EQ_16( stereo_mode, 3 ) && st1 < 0 ) { push_next_indice_fx( hBstr, add( st1, 2 ), 1 ); - nb_bits = add( nb_bits, 1 ); - } -#else - IF( q_type == 0 ) - { - /* Absolute quantizer with 1st stage stochastic codebook */ - push_next_indice_fx( hBstr, st1, 8 ); - nb_bits = add( nb_bits, 8 ); + nb_bits = add( nb_bits, 1 ); // Q0 } -#endif + + test(); + test(); IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( NE_16( st1, -2 ) && NE_16( qn1, SNS_LOW_BR_MODE ) ) ) { /* 2 bits to specify Q2,Q3,Q4,ext */ - nb_bits = add( nb_bits, 4 ); + nb_bits = add( nb_bits, 4 ); // Q0 i = sub( qn1, 2 ); if ( s_or( i < 0, (Word16) GT_16( i, 3 ) ) ) @@ -399,18 +407,18 @@ Word16 encode_lpc_avq_fx( { unary_code( nb, hBstr ); } - nb_bits = add( nb_bits, nb ); + nb_bits = add( nb_bits, nb ); // Q0 move16(); nb = qn2; IF( GT_16( nb, 6 ) ) { - nb = sub( nb, 3 ); + nb = sub( nb, 3 ); // Q0 } ELSE IF( GT_16( nb, 4 ) ) { - nb = sub( nb, 4 ); + nb = sub( nb, 4 ); // Q0 } ELSE IF( nb == 0 ) { @@ -427,17 +435,17 @@ Word16 encode_lpc_avq_fx( { unary_code( nb, hBstr ); } - nb_bits = add( nb_bits, nb ); + nb_bits = add( nb_bits, nb ); // Q0 avqBits = shl( qn1, 2 ); unpack4bits( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn1 ); - nb_bits = add( nb_bits, avqBits ); + nb_bits = add( nb_bits, avqBits ); // Q0 avqBits = shl( qn2, 2 ); unpack4bits( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn2 ); - nb_bits = add( nb_bits, avqBits ); + nb_bits = add( nb_bits, avqBits ); // Q0 } } ELSE @@ -451,10 +459,10 @@ Word16 encode_lpc_avq_fx( Word16 encode_lpc_avq_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc */ - const Word16 *param_lpc, /* i : lpc parameters */ - const Word16 core, /* i : core */ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding */ + const Word16 numlpc, /* i : Number of sets of lpc Q0*/ + const Word16 *param_lpc, /* i : lpc parameters Q0*/ + const Word16 core, /* i : core Q0*/ + const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ ) { Word16 k, j; @@ -490,13 +498,13 @@ Word16 encode_lpc_avq_ivas_fx( IF( k != 0 ) { move16(); - q_type = param_lpc[j]; + q_type = param_lpc[j]; // Q0 j = add( j, 1 ); } test(); IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && k == 0 ) { - stereo_mode = param_lpc[j]; + stereo_mode = param_lpc[j]; // Q0 move16(); j = add( j, 1 ); } @@ -507,18 +515,18 @@ Word16 encode_lpc_avq_ivas_fx( IF( q_type == 0 ) { move16(); - st1 = param_lpc[j]; + st1 = param_lpc[j]; // Q0 j = add( j, 1 ); } move16(); move16(); - qn1 = param_lpc[j]; + qn1 = param_lpc[j]; // Q0 j = add( j, 1 ); - qn2 = param_lpc[j]; + qn2 = param_lpc[j]; // Q0 j = add( j, 1 ); IF( NE_16( qn1, SNS_LOW_BR_MODE ) ) { - nb_ind = add( nb_ind, add( qn1, qn2 ) ); + nb_ind = add( nb_ind, add( qn1, qn2 ) ); // Q0 } test(); @@ -534,7 +542,7 @@ Word16 encode_lpc_avq_ivas_fx( move16(); push_next_indice( hBstr, q_type, nb ); } - nb_bits = add( nb_bits, nb ); + nb_bits = add( nb_bits, nb ); // Q0 /* Encode quantizer data */ test(); @@ -545,7 +553,7 @@ Word16 encode_lpc_avq_ivas_fx( { /* Absolute quantizer with 1st stage stochastic codebook */ push_next_indice( hBstr, st1, bits_for_abs_quant ); - nb_bits = add( nb_bits, bits_for_abs_quant ); + nb_bits = add( nb_bits, bits_for_abs_quant ); // Q0 } test(); @@ -553,7 +561,7 @@ Word16 encode_lpc_avq_ivas_fx( IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && EQ_16( stereo_mode, 3 ) && st1 < 0 ) { push_next_indice( hBstr, add( st1, 2 ), 1 ); - nb_bits = add( nb_bits, 1 ); + nb_bits = add( nb_bits, 1 ); // Q0 } test(); @@ -642,12 +650,12 @@ Word16 encode_lpc_avq_ivas_fx( avqBits = shl( qn1, 2 ); unpack4bits_ivas_fx( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn1 ); - nb_bits = add( nb_bits, avqBits ); + nb_bits = add( nb_bits, avqBits ); // Q0 avqBits = shl( qn2, 2 ); unpack4bits_ivas_fx( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn2 ); - nb_bits = add( nb_bits, avqBits ); + nb_bits = add( nb_bits, avqBits ); // Q0 } } ELSE diff --git a/lib_enc/qlpc_stoch.c b/lib_enc/qlpc_stoch.c deleted file mode 100644 index bb488002d71e75a2e34c66942bb1e8f1fc8762ca..0000000000000000000000000000000000000000 --- a/lib_enc/qlpc_stoch.c +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "rom_enc.h" -#include "basop_proto_func.h" -#include "wmc_auto.h" diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index 1750528b3d433010d0e4905c32413f978b7f1149..5a98fb328b8735f6f86be5ebb7e1bfa888f874c9 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -30,19 +30,19 @@ *--------------------------------------------------------------------*/ void lpc_quantization_fx( Encoder_State *st, - const Word16 lsp[], - const Word16 lspmid[], - Word16 lsp_q[], - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], - Word16 lspq_ind[], - Word16 clip_var[], - const Word16 coder_type, - const Word16 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 *bits_param_lpc, - Word16 *no_param_lpc, + const Word16 lsp[], /* Q15 */ + const Word16 lspmid[], /* Q15 */ + Word16 lsp_q[], /* Q15 */ + Word16 lsf_q[], /* 14Q1*1.28 */ + Word16 lspmid_q[], /* Q15 */ + Word16 lspq_ind[], /* Q15 */ + Word16 clip_var[], /* [2.56x,Q14,Q8,Q0,Q14,Q14] */ + const Word16 coder_type, /* Q0 */ + const Word16 acelp_midLpc, /* Q0 */ + Word16 param_lpc[], /* Q0 */ + Word16 nbits_lpc[], /* Q0 */ + Word16 *bits_param_lpc, /* Q0 */ + Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ) { Word16 nb_indices; @@ -114,7 +114,9 @@ void lpc_quantization_fx( IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) ) { force_sf = 1; + move16(); st->next_force_safety_net = 0; + move16(); } test(); @@ -123,14 +125,16 @@ void lpc_quantization_fx( lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); - nb_indices = *no_param_lpc; + nb_indices = *no_param_lpc; // Q0 + move16(); } ELSE { lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); - nb_indices = *no_param_lpc; + nb_indices = *no_param_lpc; // Q0 + move16(); } @@ -147,6 +151,7 @@ void lpc_quantization_fx( ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) ) { st->next_force_safety_net = 1; + move16(); } lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core ); @@ -168,7 +173,7 @@ void lpc_quantization_fx( move16(); FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0 move16(); } @@ -183,7 +188,7 @@ void lpc_quantization_fx( lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type ); - param_lpc[nb_indices++] = lsfmid_idx; + param_lpc[nb_indices++] = lsfmid_idx; // Q0 move16(); midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 ); @@ -203,17 +208,17 @@ void lpc_quantization_fx( void lpc_quantization_ivas_fx( Encoder_State *st, - const Word16 lsp[], /* Q15 */ - const Word16 lspmid[], /* Q15 */ - Word16 lsp_q[], /* Q15 */ - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], /* Q15 */ - const Word16 coder_type, - const Word16 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 *bits_param_lpc, - Word16 *no_param_lpc, + const Word16 lsp[], /* Q15 */ + const Word16 lspmid[], /* Q15 */ + Word16 lsp_q[], /* Q15 */ + Word16 lsf_q[], /* 14Q1*1.28 */ + Word16 lspmid_q[], /* Q15 */ + const Word16 coder_type, /* Q0 */ + const Word16 acelp_midLpc, /* Q0 */ + Word16 param_lpc[], /* Q0 */ + Word16 nbits_lpc[], /* Q0 */ + Word16 *bits_param_lpc, /* Q0 */ + Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ) { Word16 nb_indices; @@ -262,7 +267,7 @@ void lpc_quantization_ivas_fx( /*Force safety net when possible in case of transitions*/ test(); test(); - IF( st->tc_cnt >= 1 || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) ) + IF( GE_32( st->tc_cnt, 1 ) || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) ) { force_sf = 1; move16(); @@ -285,7 +290,7 @@ void lpc_quantization_ivas_fx( lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); - nb_indices = *no_param_lpc; + nb_indices = *no_param_lpc; // Q0 move16(); } ELSE @@ -293,7 +298,7 @@ void lpc_quantization_ivas_fx( lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); - nb_indices = *no_param_lpc; + nb_indices = *no_param_lpc; // Q0 move16(); } @@ -328,7 +333,7 @@ void lpc_quantization_ivas_fx( move16(); FOR( i = nb_indices - 1; i >= 0; i-- ) { - st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); + st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0 move16(); } @@ -343,7 +348,7 @@ void lpc_quantization_ivas_fx( lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type ); - param_lpc[nb_indices] = lsfmid_idx; + param_lpc[nb_indices] = lsfmid_idx; // Q0 move16(); nb_indices = add( nb_indices, 1 ); midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 ); @@ -355,7 +360,7 @@ void lpc_quantization_ivas_fx( { param_lpc[nb_indices] = 0; move16(); - nb_indices = add( nb_indices, 1 ); + nb_indices = add( nb_indices, 1 ); // Q0 } } @@ -371,14 +376,14 @@ void lpc_quantization_ivas_fx( *-------------------------------------------------------------------*/ void Unified_weighting_fx( - const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband Q0*/ + const Word16 unvoiced, /* i : flag for Unvoiced frame Q0*/ + const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ + const Word16 order /* i : LP order Q0*/ ) { Word16 i; @@ -396,47 +401,48 @@ void Unified_weighting_fx( const Word32 *Freq_w_Table_fx, *Bin_Ener_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*Config. weighting*/ IF( narrowBand ) { - ptr_lsf_fit_model = lsf_unified_fit_model_nb; - nf_fx = 16384; - move16(); /* x2.56 */ + ptr_lsf_fit_model = lsf_unified_fit_model_nb; // Q0 + nf_fx = 16384; /* 6400 in x2.56 */ + move16(); last_bin = 127; move16(); - Bin_Ener_fx = Bin_Ener_128_fx; + Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */ } ELSE IF( EQ_32( sr_core, INT_FS_12k8 ) ) { ptr_lsf_fit_model = lsf_unified_fit_model_wb; - nf_fx = 16384; - move16(); /* x2.56 */ + nf_fx = 16384; /* 6400 in x2.56 */ + move16(); last_bin = 127; move16(); - Bin_Ener_fx = Bin_Ener_128_fx; + Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */ } ELSE { ptr_lsf_fit_model = lsf_unified_fit_model_wbhb; - nf_fx = 20480; - move16(); /* x2.56 */ + nf_fx = 20480; /* 8000 in x2.56 */ + move16(); /* Fill the missing part (128~159) of the bin energy */ last_bin = 159; move16(); - Copy32( Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT / 2 ); + Copy32( Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT / 2 ); /* Q_ener */ /* Find average bin energy (32 Energy) */ L_tmp = L_deposit_l( 0 ); FOR( i = 95; i < 127; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); + L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); /* Q_ener */ #else L_tmp = L_add( L_tmp, Bin_Ener_160_fx[i] ); #endif @@ -445,18 +451,18 @@ void Unified_weighting_fx( L_tmp = L_shr( L_tmp, 5 ); FOR( i = 127; i < 160; i++ ) { - Bin_Ener_160_fx[i] = L_tmp; + Bin_Ener_160_fx[i] = L_tmp; /* Q_ener */ move32(); } - Bin_Ener_fx = Bin_Ener_160_fx; + Bin_Ener_fx = Bin_Ener_160_fx; /* Q_ener */ } /* 1) FFT weights*/ - Freq_w_Table_fx = Freq_Weight_Com_fx; + Freq_w_Table_fx = Freq_Weight_Com_fx; /* Q31 */ if ( unvoiced ) { - Freq_w_Table_fx = Freq_Weight_UV_fx; + Freq_w_Table_fx = Freq_Weight_UV_fx; /* Q31 */ } /* Use Envelope */ @@ -506,7 +512,7 @@ void Unified_weighting_fx( if ( LT_16( w_fft_fx[i], min_fx ) ) { - min_fx = w_fft_fx[i]; + min_fx = w_fft_fx[i]; // Q8 move16(); } } @@ -541,21 +547,21 @@ void Unified_weighting_fx( FOR( i = 0; i < order; i++ ) { /* 2) IHM weights*/ - tmp1_fx = lsf_fx[i]; + tmp1_fx = lsf_fx[i]; /* x2.56 */ move16(); if ( i > 0 ) { - tmp1_fx = sub( tmp1_fx, lsf_fx[i - 1] ); + tmp1_fx = sub( tmp1_fx, lsf_fx[i - 1] ); /* x2.56 */ } tmp2_fx = nf_fx; move16(); - if ( NE_16( i, order - 1 ) ) + if ( NE_16( i, sub( order, 1 ) ) ) { - tmp2_fx = lsf_fx[i + 1]; + tmp2_fx = lsf_fx[i + 1]; /* x2.56 */ move16(); } - tmp2_fx = sub( tmp2_fx, lsf_fx[i] ); + tmp2_fx = sub( tmp2_fx, lsf_fx[i] ); /* x2.56 */ s1 = 15; move16(); @@ -564,15 +570,17 @@ void Unified_weighting_fx( if ( tmp1_fx == 0 ) { tmp1_fx = 8; + move16(); } tmp1_fx = Inv16( tmp1_fx, &s1 ); if ( tmp2_fx == 0 ) { tmp2_fx = 8; + move16(); } tmp2_fx = Inv16( tmp2_fx, &s2 ); s1 = BASOP_Util_Add_MantExp( tmp1_fx, s1, tmp2_fx, s2, &tmp1_fx ); /* x * 2.56 / pow(2.0, 15 + |s1|) */ - tmp_fx = mult_r( nf_fx, 10430 ); + tmp_fx = mult_r( nf_fx, 10430 /* 0.31 in Q15*/ ); s2 = norm_s( tmp_fx ); tmp_fx = shl( tmp_fx, s2 ); s1 = sub( s1, s2 ); @@ -589,7 +597,7 @@ void Unified_weighting_fx( IF( LT_32( L_shl( L_tmp, 5 ), InvIntTable[i + 1] ) ) { - w_fx[i] = shr( InvIntTable[i + 1], 7 ); + w_fx[i] = shr( InvIntTable[i + 1], 7 ); // Q8 move16(); } ELSE @@ -601,7 +609,8 @@ void Unified_weighting_fx( } ELSE { - w_fx[i] = extract_l( L_shr( L_tmp, 2 ) ); + w_fx[i] = extract_l( L_shr( L_tmp, 2 ) ); // Q8 + move16(); } } } diff --git a/lib_enc/range_enc.c b/lib_enc/range_enc.c deleted file mode 100644 index fd4f3cb7c53af6bc1a4a149c6db6799b8f39655e..0000000000000000000000000000000000000000 --- a/lib_enc/range_enc.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index da325b2bd232a5fa22087054352ad2c5f3e941cb..15e3f398348f70803c7e76c89e3055515cb2ee1c 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -26,7 +26,7 @@ static void rc_enc_write_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bit void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget Q0*/ ) { hPVQ->rc_low = L_deposit_l( 0 ); @@ -40,7 +40,7 @@ void rc_enc_init_fx( move16(); hPVQ->rc_num_bits = 0; move16(); - hPVQ->rc_tot_bits = tot_bits; + hPVQ->rc_tot_bits = tot_bits; // Q0 move16(); hPVQ->rc_offset = 0; move16(); @@ -54,37 +54,37 @@ void rc_enc_init_fx( * Encode symbol with range coder *-------------------------------------------------------------------*/ void rc_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ) { UWord32 r, tmp, inv_tot, lsb; Word16 exp; UWord16 carry; - inv_tot = UL_inverse( tot, &exp ); + inv_tot = UL_inverse( tot, &exp ); // Q0 Mpy_32_32_uu( hPVQ->rc_range, inv_tot, &tmp, &lsb ); /*0+exp-32 */ r = UL_lshr( tmp, sub( exp, 32 ) ); /* exp-32-exp3+32 = 0 */ tmp = UL_Mpy_32_32( r, cum_freq ); - hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); + hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); // Q0 move32(); if ( carry != 0 ) { - hPVQ->rc_carry = carry; + hPVQ->rc_carry = carry; // Q0 move16(); } - hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); + hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); // Q0 move32(); WHILE( LT_64( hPVQ->rc_range, 1 << 24 ) ) { - hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); + hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); // Q0 move32(); - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); // Q0 move16(); rc_enc_shift_ivas_fx( hBstr, hPVQ ); } @@ -92,36 +92,36 @@ void rc_encode_ivas_fx( return; } void rc_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ) { UWord32 r, tmp, inv_tot, lsb; Word16 exp; UWord16 carry; - inv_tot = UL_inverse( tot, &exp ); + inv_tot = UL_inverse( tot, &exp ); // Q0 Mpy_32_32_uu( hPVQ->rc_range, inv_tot, &tmp, &lsb ); /*0+exp-32 */ r = UL_lshr( tmp, sub( exp, 32 ) ); /* exp-32-exp3+32 = 0 */ tmp = UL_Mpy_32_32( r, cum_freq ); - hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); + hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); // Q0 if ( carry != 0 ) { - hPVQ->rc_carry = carry; + hPVQ->rc_carry = carry; // Q0 move16(); } - hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); + hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); // Q0 WHILE( hPVQ->rc_range < 1 << 24 ) { - L_sub( 0, 0 ); /* Comparison in while */ - hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); + L_sub( 0, 0 ); /* Comparison in while */ + hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); // Q0 + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); // Q0 rc_enc_shift_fx( hBstr, hPVQ ); } @@ -146,8 +146,8 @@ void rc_enc_finish_ivas_fx( bits = add( norm_ul( hPVQ->rc_range ), 1 ); mask = UL_lshr( 0xffffffff, bits ); - val = UL_addNs( hPVQ->rc_low, mask, &over1 ); - high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); + val = UL_addNs( hPVQ->rc_low, mask, &over1 ); // Q0 + high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); // Q0 val = L_and( val, ~mask ); L_xor( 0, 0 ); /* For bit not */ @@ -157,10 +157,10 @@ void rc_enc_finish_ivas_fx( L_sub( 0, 0 ); /* For comparision in if */ IF( UL_addNsD( val, mask ) >= high ) { - bits = add( bits, 1 ); - mask = UL_lshr( mask, 1 ); - val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); - L_xor( 0, 0 ); /* For bit not */ + bits = add( bits, 1 ); // Q0 + mask = UL_lshr( mask, 1 ); // Q0 + val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); // Q0 + L_xor( 0, 0 ); /* For bit not */ } if ( LT_32( val, hPVQ->rc_low ) ) @@ -175,10 +175,10 @@ void rc_enc_finish_ivas_fx( IF( GT_16( bits, sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ) ) ) { - bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); + bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); // Q0 } - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0 move16(); FOR( ; bits > 0; bits -= 8 ) { @@ -201,7 +201,7 @@ void rc_enc_finish_ivas_fx( rc_enc_write_ivas_fx( hBstr, lshr( add( hPVQ->rc_cache, hPVQ->rc_carry ), sub( 8, bits ) ), bits ); } - bits = hPVQ->rc_num_bits; + bits = hPVQ->rc_num_bits; // Q0 move16(); WHILE( LT_16( bits, sub( hPVQ->rc_tot_bits, 16 ) ) ) { @@ -209,7 +209,7 @@ void rc_enc_finish_ivas_fx( bits = add( bits, 16 ); } - bits = sub( hPVQ->rc_tot_bits, bits ); + bits = sub( hPVQ->rc_tot_bits, bits ); // Q0 IF( bits > 0 ) { rc_enc_write_ivas_fx( hBstr, 0, bits ); @@ -227,11 +227,11 @@ void rc_enc_finish_fx( Word16 bits; UWord16 over1, over2; - bits = add( norm_ul( hPVQ->rc_range ), 1 ); + bits = add( norm_ul( hPVQ->rc_range ), 1 ); // Q0 mask = UL_lshr( 0xffffffff, bits ); - val = UL_addNs( hPVQ->rc_low, mask, &over1 ); - high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); + val = UL_addNs( hPVQ->rc_low, mask, &over1 ); // Q0 + high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); // Q0 val = L_and( val, ~mask ); L_xor( 0, 0 ); /* For bit not */ @@ -241,10 +241,10 @@ void rc_enc_finish_fx( L_sub( 0, 0 ); /* For comparision in if */ IF( UL_addNsD( val, mask ) >= high ) { - bits = add( bits, 1 ); - mask = UL_lshr( mask, 1 ); - val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); - L_xor( 0, 0 ); /* For bit not */ + bits = add( bits, 1 ); // Q0 + mask = UL_lshr( mask, 1 ); // Q0 + val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); // Q0 + L_xor( 0, 0 ); /* For bit not */ } if ( val < hPVQ->rc_low ) @@ -259,10 +259,10 @@ void rc_enc_finish_fx( IF( GT_16( bits, sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ) ) ) { - bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); + bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); // Q0 } - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0 FOR( ; bits > 0; bits -= 8 ) { rc_enc_shift_fx( hBstr, hPVQ ); @@ -284,7 +284,7 @@ void rc_enc_finish_fx( rc_enc_write_fx( hBstr, lshr( add( hPVQ->rc_cache, hPVQ->rc_carry ), sub( 8, bits ) ), bits ); } - bits = hPVQ->rc_num_bits; + bits = hPVQ->rc_num_bits; // Q0 move16(); WHILE( LT_16( bits, sub( hPVQ->rc_tot_bits, 16 ) ) ) { @@ -323,7 +323,7 @@ static void rc_enc_shift_ivas_fx( WHILE( hPVQ->rc_carry_count > 0 ) { rc_enc_write_ivas_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), 255 ), 8 ); - hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); + hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); // Q0 move16(); } @@ -333,7 +333,7 @@ static void rc_enc_shift_ivas_fx( } ELSE { - hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); + hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); // Q0 move16(); } hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 ); @@ -357,7 +357,7 @@ static void rc_enc_shift_fx( WHILE( hPVQ->rc_carry_count > 0 ) { rc_enc_write_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), 255 ), 8 ); - hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); + hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); // Q0 } hPVQ->rc_cache = u_extract_l( UL_lshr( hPVQ->rc_low, 24 ) ); @@ -366,9 +366,9 @@ static void rc_enc_shift_fx( } ELSE { - hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); + hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); // Q0 } - hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 ); + hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 ); // Q0 return; } @@ -379,29 +379,29 @@ static void rc_enc_shift_fx( * *-------------------------------------------------------------------*/ void rc_enc_bits_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ) { IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) ) { - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0 move16(); IF( GT_16( bits, 16 ) ) { push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_lshr( value, 16 ) ), sub( bits, 16 ) ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 move16(); push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_and( value, 0x0000ffff ) ), 16 ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 move16(); } ELSE { push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( value ), bits ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 move16(); } } @@ -412,27 +412,27 @@ void rc_enc_bits_ivas_fx( return; } void rc_enc_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ) { IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) ) { - hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0 IF( GT_16( bits, 16 ) ) { push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_lshr( value, 16 ) ), sub( bits, 16 ) ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_and( value, 0x0000ffff ) ), 16 ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 } ELSE { push_indice_fx( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( value ), bits ); - hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); + hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0 } } ELSE @@ -448,10 +448,10 @@ void rc_enc_bits_fx( * Encode with uniform distribution *-------------------------------------------------------------------*/ void rc_enc_uniform_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ) { Word16 n; @@ -472,15 +472,15 @@ void rc_enc_uniform_ivas_fx( return; } void rc_enc_uniform_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ) { Word16 n; - n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); + n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); // Q0 IF( LE_16( n, 8 ) ) { @@ -488,7 +488,7 @@ void rc_enc_uniform_fx( } ELSE { - n = sub( n, 8 ); + n = sub( n, 8 ); // Q0 rc_encode_fx( hBstr, hPVQ, UL_lshr( value, n ), 1, UL_addNsD( UL_lshr( tot, n ), 1 ) ); rc_enc_bits_fx( hBstr, hPVQ, UL_and( value, UL_subNsD( UL_lshl( 1, n ), 1 ) ), n ); } @@ -502,9 +502,9 @@ void rc_enc_uniform_fx( * Write a byte to bitstream *-------------------------------------------------------------------*/ static void rc_enc_write_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 byte, /* i : Byte to write */ - Word16 bits /* i : Number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 byte, /* i : Byte to write Q0*/ + Word16 bits /* i : Number of bits Q0*/ ) { push_indice( hBstr, IND_RC_START, byte, bits ); @@ -512,9 +512,9 @@ static void rc_enc_write_ivas_fx( return; } static void rc_enc_write_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 byte, /* i : Byte to write */ - Word16 bits /* i : Number of bits */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 byte, /* i : Byte to write Q0*/ + Word16 bits /* i : Number of bits Q0*/ ) { push_indice_fx( hBstr, IND_RC_START, byte, bits ); diff --git a/lib_enc/re8_cod.c b/lib_enc/re8_cod.c deleted file mode 100644 index e748899a9667996f0776eb65127752b66796a660..0000000000000000000000000000000000000000 --- a/lib_enc/re8_cod.c +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/re8_cod_fx.c b/lib_enc/re8_cod_fx.c index e035baf57ccfbd988bbb2596722035453751371f..d43dbbf57aa184d18022f519071e0e3df1c0a9b8 100644 --- a/lib_enc/re8_cod_fx.c +++ b/lib_enc/re8_cod_fx.c @@ -4,7 +4,6 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" -//#include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -17,10 +16,10 @@ *--------------------------------------------------------------------------*/ void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ + Word16 x[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) Q0*/ + UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) Q0*/ + Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index Q0*/ ) { Word16 ka_fx, c_fx[8]; diff --git a/lib_enc/reordernorm.c b/lib_enc/reordernorm.c deleted file mode 100644 index 4922b9e4cac63a8b7e0bad323eeb65ac2b6706ba..0000000000000000000000000000000000000000 --- a/lib_enc/reordernorm.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot.h" -#include "cnst.h" -#include "rom_com.h" -#include "wmc_auto.h" diff --git a/lib_enc/reordernorm_fx.c b/lib_enc/reordernorm_fx.c index 40f12ffb8bec38ed8ecbc01a358e73bd0db34972..176b54f8e586150bc57f8f4e6f404d3c9724d994 100644 --- a/lib_enc/reordernorm_fx.c +++ b/lib_enc/reordernorm_fx.c @@ -7,7 +7,6 @@ #include "cnst.h" /* Common constants */ #include "rom_com_fx.h" #include "rom_com.h" -//#include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -32,25 +31,25 @@ void reordernorm_fx( SWITCH( nb_sfm ) { case NB_SFM: - order = norm_order_48; + order = norm_order_48; // Q0 BREAK; case SFM_N_SWB: - order = norm_order_32; + order = norm_order_32; // Q0 BREAK; case SFM_N_WB: - order = norm_order_16; + order = norm_order_16; // Q0 BREAK; default: - order = norm_order_48; + order = norm_order_48; // Q0 BREAK; } FOR( i = 0; i < nb_sfm; i++ ) { - idxbuf[i] = ynrm[order[i]]; + idxbuf[i] = ynrm[order[i]]; // Q0 move16(); move16(); - normbuf[i] = normqlg2[order[i]]; + normbuf[i] = normqlg2[order[i]]; // Q0 move16(); move16(); } diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index a68053993c7c4d84af5b75561598ce870001955c..317789ee228dd7655aa31461b38fcfebf0d3b7c1 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -575,6 +575,12 @@ void RunTransientDetection_ivas_fx( } ELSE { + Word16 norm = norm_arr( input_fx, length ); + IF( norm == 0 ) + { + Scale_sig( input_fx, length, -1 ); + q_input = sub( q_input, 1 ); + } pSubblockEnergies->firState1 = shl( pSubblockEnergies->firState1, sub( q_input, pSubblockEnergies->q_firState ) ); // q_input move16(); pSubblockEnergies->firState2 = shl( pSubblockEnergies->firState2, sub( q_input, pSubblockEnergies->q_firState ) ); // q_input