diff --git a/lib_com/cnst.h b/lib_com/cnst.h index f2f1a64e68ae736c95d6ee90770ccb45ffb658db..a046d6efee07e5677ce3d78275e0b73e264b9485 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1104,12 +1104,17 @@ enum #define MAX_NO_VALS 4 #define WB_LIMIT_LSF 6350 #define CNG_LVQ_MODES 16 +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE +#define MAX_NO_MODES 169 +#define START_CNG MAX_NO_MODES - CNG_LVQ_MODES +#else #define MAX_NO_MODES_IVAS 169 #define MAX_NO_MODES 128 #define START_CNG_IVAS MAX_NO_MODES_IVAS - CNG_LVQ_MODES #define START_CNG 112 #define MAX_NO_MODES_p_IVAS 237 #define MAX_NO_MODES_p 145 +#endif #define NO_CODING_MODES 6 #define LVQ_COD_MODES 18 diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index f8ef32ed0ab9216fa2cc303d9d46408682227d18..da980b80205830b12ef53ab9e2f213e1c583ba1c 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -4395,12 +4395,12 @@ const Word32 azimuth_cb_fx[8] = { 0, -754974720, -377487360, 377487360, -188743680, 188743680, -566231040, 566231040 }; -// Q22 +/* Q22 */ const Word32 delta_theta_masa_fx[NO_SPHERICAL_GRIDS - 2] = { 188743680, 188743680, 150994944, 106954752, 83886080, 62914560, 45214596, 28101836, 20971520 }; -// Q31 +/* Q31 */ const Word32 delta_theta_masa_inv_fx[NO_SPHERICAL_GRIDS - 2] = { 47721859, 47721859, 59652324, 84215045, 107374182, 143165577, 199209986, 320519947, 429496730 }; diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index c69503350f8320bcd8cde9f92f1f44a16dd62e1c..6e3ec9bd86b0479ddc3665a94b69ab635399956d 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -30,19 +30,23 @@ *******************************************************************************************************/ +/*==================================================================================== + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 + ====================================================================================*/ + #include #include #include "options.h" /* Compilation switches */ -#include "basop_util.h" #include "rom_com.h" #include "ivas_cnst.h" #include "prot_fx.h" -#include "ivas_error.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ + #define NC_MAX 8 #define GUESS_TBL_SZ 256 @@ -1815,7 +1819,65 @@ void a2rc_fx( return; } +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + +/*----------------------------------------------------------------------------------* + * vq_dec_lvq() + * + * Multi-stage VQ decoder for LSF parameters, last stage LVQ + *----------------------------------------------------------------------------------*/ + +Word16 vq_dec_lvq_fx( + const Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 mode, /* i : mode_lvq, or mode_lvq_p */ + const Word16 no_bits /* i : no. bits for lattice */ +) +{ + Word16 x_lvq[M]; + Word16 i, stagesm1; + Word16 pt_fx; + Word16 ber_flag; + + /* clear vector */ + set16_fx( x, 0, N ); + + /*-----------------------------------------------* + * add contribution of each stage + *-----------------------------------------------*/ + + stagesm1 = sub( stages, 1 ); + IF( EQ_16( sf_flag, 1 ) ) + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_fx[CB_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + deindex_lvq_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits ); + } + ELSE + { + FOR( i = 0; i < stagesm1; i++ ) + { + pt_fx = i_mult2( indices[i], N ); + Vr_add( x, &Quantizers_p_fx[CB_p_lsf[mode] + i][pt_fx], x, N ); + } + + ber_flag = + deindex_lvq_fx( &indices[stagesm1], x_lvq, mode, sf_flag, no_bits ); + } + + Vr_add( x, x_lvq, x, N ); + return ber_flag; +} +#else Word16 vq_dec_lvq_fx( Word16 sf_flag, /* i : safety net flag */ Word16 x[], /* o : Decoded vector Q(x2.56)*/ @@ -1922,6 +1984,14 @@ Word16 vq_dec_lvq_ivas_fx( return ber_flag; } +#endif + + +/*----------------------------------------------------------------------------------* + * lsf_allocate() + * + * Calculate number of stages and levels for each stage based on the allowed bit allocation + *----------------------------------------------------------------------------------*/ ivas_error lsf_allocate_fx( const Word16 nBits, /* i : Number of bits to use for quantization */ @@ -2082,6 +2152,13 @@ ivas_error lsf_allocate_fx( return error; } + +/*----------------------------------------------------------------------------------* + * find_pred_mode() + * + * + *----------------------------------------------------------------------------------*/ + ivas_error find_pred_mode( Word16 *predmode, /* o : prediction mode */ const Word16 coder_type, /* i : coding type */ @@ -2171,12 +2248,14 @@ ivas_error find_pred_mode( return error; } + /*---------------------------------------------------------------------------* * reorder_isf * * To make sure that the isfs are properly ordered and to keep a certain * minimum distance between consecutive isfs. *--------------------------------------------------------------------------*/ + void reorder_isf_fx( Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ const Word16 min_dist, /* i : minimum required distance */ @@ -2223,33 +2302,36 @@ void reorder_isf_fx( isf_max = sub( isf[i], min_dist ); } } + + return; } + /*========================================================================*/ -/* FUNCTION : lsf_stab_fx() */ +/* FUNCTION : lsf_stab_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Check LSF stability (distance between old LSFs and */ -/* current LSFs) */ +/* PURPOSE : Check LSF stability (distance between old LSFs and */ +/* current LSFs) */ /*------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ -/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */ -/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */ +/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ +/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */ +/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) stab_fac_fx : LP filter stability Q15 */ +/* RETURN ARGUMENTS : */ +/* _ (Word16) stab_fac_fx : LP filter stability Q15 */ /*========================================================================*/ -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +/* o : LP filter stability Q15*/ +Word16 lsf_stab_fx( + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ) { Word16 i, m; @@ -2309,31 +2391,32 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ return tmp; } + /*========================================================================*/ -/* FUNCTION : lsf_stab_ivas_fx() */ +/* FUNCTION : lsf_stab_ivas_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Check LSF stability (distance between old LSFs and */ -/* current LSFs) */ +/* PURPOSE : Check LSF stability (distance between old LSFs and */ +/* current LSFs) */ /*------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ -/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */ -/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */ +/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ +/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */ +/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) stab_fac_fx : LP filter stability Q15 */ +/* RETURN ARGUMENTS : */ +/* _ (Word16) stab_fac_fx : LP filter stability Q15 */ /*========================================================================*/ -Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ +/* o : LP filter stability Q15*/ +Word16 lsf_stab_ivas_fx( + const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ + const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame /* i : frame length */ ) { Word16 i, m; @@ -2343,6 +2426,7 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability /*-------------------------------------------------------------------* * Check stability on lsf: distance between old lsf and current lsf *-------------------------------------------------------------------*/ + IF( Opt_AMR_WB ) { m = M - 1; @@ -2426,7 +2510,11 @@ void lsp2isp_fx( /* Update to latest stable ISP */ Copy( isp, stable_isp, M ); + + return; } + + /*-------------------------------------------------------------------* * isp2lsp() * @@ -2450,6 +2538,8 @@ void isp2lsp_fx( E_LPC_a_lsp_conversion( a, lsp, stable_lsp, m ); /* Update to latest stable LSP */ Copy( lsp, stable_lsp, M ); + + return; } /*-------------------------------------------------------------------* @@ -2481,6 +2571,8 @@ void lsf2isf_fx( return; } + + /*-------------------------------------------------------------------* * isf2lsf() * @@ -2505,8 +2597,11 @@ void isf2lsf_fx( /* LSP --> LSF */ /*lsp2lsf( tmp_lsp, lsf, m, int_fs );*/ E_LPC_lsp_lsf_conversion( tmp_lsp, lsf, M ); + return; } + + /*==========================================================================*/ /* FUNCTION : void lsp2lsf_fx () */ /*--------------------------------------------------------------------------*/ @@ -2555,26 +2650,30 @@ void lsp2lsf_fx( lsf[i] = extract_l( L_tmp ); move16(); } + + return; } + + /*===========================================================================*/ -/* FUNCTION : lsf2lsp_fx() */ +/* FUNCTION : lsf2lsp_fx() */ /*---------------------------------------------------------------------------*/ /* PURPOSE : Transformation of LSFs to LSPs */ /* LSP are line spectral pairs in cosine domain (-1 to 1). */ -/* LSF are line spectral frequencies (0 to fs/2). */ +/* LSF are line spectral frequencies (0 to fs/2). */ /*---------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16[]) lsf : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56) */ -/* _ (Word16) m : LPC order */ +/* _ (Word16[]) lsf : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ +/* _ (Word16) m : LPC order */ /*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) lsp : lsp[m] (range: -1<=val<1) Q15 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) lsp : lsp[m] (range: -1<=val<1) Q15 */ /*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*===========================================================================*/ + void lsf2lsp_fx( const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ @@ -2588,7 +2687,6 @@ void lsf2lsp_fx( Word16 const add_prec = 4; Word16 lsf_tmp; - /* 0.75 = (1<mem_w0; move16(); - *btilt_code_fx = hLPDmem->tilt_code; move16(); *gc_threshold_fx = hLPDmem->gc_threshold; @@ -2964,17 +3077,22 @@ void lsf_syn_mem_backup_fx( *next_force_sf_bck_fx = st_fx->next_force_safety_net; move16(); - return; } -void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qlsf[], /* i : quantized lsf coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ +/*--------------------------------------------------------------------------* + * lsf_update_memory() + * + * + *--------------------------------------------------------------------------*/ + +void lsf_update_memory_fx( + const Word16 narrowband, /* i : narrowband flag */ + const Word16 qlsf[], /* i : quantized lsf coefficients */ + Word16 old_mem_MA[], /* i : MA memory */ + Word16 mem_MA[], /* o : updated MA memory */ + Word16 lpcorder /* i : LPC order */ ) { Word16 i; diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 76a6395393560b5cd50ad4acb74f35deb72def1e..148a8eca5831314310d4fac4be19ce5e5d466cfc 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -1,41 +1,12 @@ -/****************************************************************************************************** - - (C) 2022-2026 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.452 Nov 04, 2021. Version 16.4.0 + ====================================================================================*/ #include #include "options.h" #include "cnst.h" #include "prot_fx.h" #include "ivas_cnst.h" -#include "stl.h" #include "rom_com.h" #include "ivas_prot_fx.h" #include "wmc_auto.h" @@ -45,21 +16,36 @@ * Local functions *-----------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static void make_offset_scale_fx( const Word32 tab_no_cv[], const Word8 *no_ld, const Word16 no_scl, UWord32 *offset_scale ); +#else static void make_offset_scale_fx( Word16 j, const Word32 tab_no_cv[], const Word16 no_ld[], Word16 no_scl, Word32 offset_scale[][MAX_NO_SCALES + 1] ); static void init_offset_fx( Word32 offset_scale1[][MAX_NO_SCALES + 1], Word32 offset_scale2[][MAX_NO_SCALES + 1], Word32 offset_scale1_p[][MAX_NO_SCALES + 1], Word32 offset_scale2_p[][MAX_NO_SCALES + 1], Word16 no_scales[][2], Word16 no_scales_p[][2] ); -static void decode_comb_fx( Word32 index, Word16 *cv, Word16 idx_lead ); -static void decode_sign_pc1_fx( Word16 *c, Word16 idx_sign, Word16 parity ); -static void put_value_fx( Word16 *cv, Word16 *p, Word16 val, Word16 dim, Word16 no_new_val ); -static void decode_leaders_fx( Word16 index, Word16 idx_lead, Word16 *cv ); -static void idx2c_fx( Word16 n, Word16 *p, Word16 k, Word16 val ); +#endif +static void decode_comb_fx( Word32 index, Word16 *cv, const Word16 idx_lead ); +static void decode_sign_pc1_fx( Word16 *c, Word16 idx_sign, const Word16 parity ); +static void put_value_fx( Word16 *cv, const Word16 *p, const Word16 val, const Word16 dim, const Word16 no_new_val ); +static void decode_leaders_fx( Word16 index, const Word16 idx_lead, Word16 *cv ); +static void idx2c_fx( Word16 n, Word16 *p, const Word16 k, Word16 val ); static void divide_64_32_fx( Word16 *xs, Word32 y, Word32 *result, Word32 *rem ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static Word16 decode_indexes_fx( Word16 *index, const Word16 no_bits, const Word16 *p_scales, Word16 *x_lvq, const Word16 mode_glb, Word16 *scales_mslvq, const Word16 prediction_flag ); +#else static Word16 decode_indexes_fx( Word16 *index, Word16 no_bits, const Word16 *p_scales, Word16 *p_no_scales, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *x_lvq, Word16 mode_glb, Word16 *scales ); static Word16 decode_indexes_ivas_fx( Word16 *index, const Word16 no_bits, const Word16 *p_scales, const Word16 prediction_flag, Word16 *x_lvq, const Word16 mode_glb, Word16 *scales_mslvq ); -static Word32 divide_32_32_fx( Word32 y, Word32 x, Word32 *rem ); -static Word16 divide_16_16_fx( Word16 y, Word16 x, Word16 *rem ); +#endif +static Word32 divide_32_32_fx( const Word32 y, const Word32 x, Word32 *rem ); +static Word16 divide_16_16_fx( const Word16 y, const Word16 x, Word16 *rem ); +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES static Word16 decode_indexes_ivas_fx( Word16 *index, const Word16 no_bits, const Word16 *p_scales, const Word16 prediction_flag, Word16 *x_lvq, const Word16 mode_glb, Word16 *scales_mslvq ); +#endif + + +/*-----------------------------------------------------------------* + * permute() + * used in CNG-LP coding + *-----------------------------------------------------------------*/ -/* used in CNG-LP coding */ void permute_fx( Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ @@ -98,7 +84,7 @@ void permute_fx( return; } - +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES void init_lvq_fx( Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o : lattice truncation index offset for the first LSF subvector - safety net structures*/ Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o : lattice truncation index offset for the second LSF subvector - safety net structures*/ @@ -185,7 +171,6 @@ void init_lvq_fx( return; } - /* make_offset_scale_fx() - calculates scale offset values for a particular MSLVQ structure */ static void make_offset_scale_fx( Word16 j, /* i : MSLVQ structure index */ @@ -207,8 +192,34 @@ static void make_offset_scale_fx( return; } +#endif + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * make_offset_scale() + * + *-----------------------------------------------------------------*/ + +static void make_offset_scale_fx( + const Word32 tab_no_cv[], + const Word8 *no_ld, + const Word16 no_scl, + UWord32 *offset_scale ) +{ + Word16 i; + + offset_scale[0] = 1; + move32(); + FOR( i = 1; i <= no_scl; i++ ) + { + offset_scale[i] = UL_addNsD( offset_scale[i - 1], tab_no_cv[(Word16) no_ld[i - 1]] ); + move32(); + } + return; +} +#else static void make_offset_scale( const UWord32 tab_no_cv[], const Word8 *no_ld, @@ -227,8 +238,9 @@ static void make_offset_scale( return; } +#endif - +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES void init_offset_fx( Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o : lattice truncation index offset for the first LSF subvector - safety net structures*/ Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o : lattice truncation index offset for the second LSF subvector - safety net structures*/ @@ -263,7 +275,169 @@ void init_offset_fx( return; } +#endif +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * decode_indexes() + * + *-----------------------------------------------------------------*/ + +static Word16 decode_indexes_fx( + Word16 *index, + const Word16 no_bits, + const Word16 *p_scales, + Word16 *x_lvq, + const Word16 mode_glb, + Word16 *scales_mslvq, + const Word16 prediction_flag ) +{ + Word32 index1 = 0, index2 = 0; + Word16 i, im1 = 0, idx_scale = 0; + Word16 len_scales = shl( MAX_NO_SCALES, 1 ); + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + move32(); + move32(); + move16(); + move16(); + + IF( LE_16( no_bits, shl( LEN_INDICE, 1 ) ) ) /* the third short is not used */ + { + index[2] = 0; + move16(); + IF( LE_16( no_bits, LEN_INDICE ) ) + { + index[1] = 0; + move16(); + } + } + + /* Safety check for bit errors (common) */ + FOR( i = 0; i < 3; i++ ) + { + IF( index[i] < 0 ) + { + set16_fx( x_lvq, 0, shl( LATTICE_DIM, 1 ) ); + scales_mslvq[0] = 0; + move16(); + scales_mslvq[1] = 0; + move16(); + index[i] = 0; + move16(); + return 1; + } + } + + create_offset_fx( offset_scale1, offset_scale2, mode_glb, prediction_flag ); + + /* Divide using second subvector's max scale index */ + IF( offset_scale2[MAX_NO_SCALES - 1] > 0 ) + { + divide_64_32_fx( index, offset_scale2[MAX_NO_SCALES], &index1, &index2 ); + } + ELSE + { + index1 = L_deposit_l( index[0] ); + move32(); + index2 = L_deposit_l( 0 ); + move32(); + } + + /* Common: handle index1 == 0 */ + IF( index1 == 0 ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + x_lvq[i] = 0; + move16(); + } + scales_mslvq[0] = 0; + move16(); + } + ELSE + { + /* safety check in case of bit errors */ + IF( GE_32( index1, offset_scale1[MAX_NO_SCALES] ) ) + { + set16_fx( x_lvq, 0, shl( LATTICE_DIM, 1 ) ); + scales_mslvq[0] = 0; + move16(); + scales_mslvq[1] = 0; + move16(); + return 1; + } + + /* Find idx_scale */ + i = 1; + move16(); + WHILE( LE_16( i, MAX_NO_SCALES ) && GE_32( index1, offset_scale1[i] ) ) + { + i = add( i, 1 ); + } + idx_scale = sub( i, 1 ); + move16(); + index1 = L_sub( index1, offset_scale1[idx_scale] ); + move32(); + + /* Find idx_leader (common) */ + i = 1; + move16(); + + WHILE( GE_32( index1, table_no_cv_fx[i] ) ) + { + i = add( i, 1 ); + } + im1 = sub( i, 1 ); + decode_comb_fx( L_sub( index1, table_no_cv_fx[im1] ), x_lvq, im1 ); + scales_mslvq[0] = p_scales[add( i_mult2( mode_glb, len_scales ), idx_scale )]; + move16(); + } + + /* Second subvector (common structure, offset logic differs) */ + IF( index2 == 0 ) + { + FOR( i = LATTICE_DIM; i < shl( LATTICE_DIM, 1 ); i++ ) + { + x_lvq[i] = 0; + move16(); + } + scales_mslvq[1] = 0; + move16(); + } + ELSE + { + /* find the index for the scale/truncation */ + i = 1; + move16(); + WHILE( GE_32( index2, offset_scale2[i] ) ) + { + i = add( i, 1 ); + } + idx_scale = sub( i, 1 ); + move16(); + index2 = L_sub( index2, offset_scale2[idx_scale] ); + move32(); + + /* Find leader (common) */ + i = 1; + move16(); + + WHILE( GE_32( index2, (Word32) table_no_cv_fx[i] ) ) + { + i = add( i, 1 ); + } + im1 = sub( i, 1 ); + decode_comb_fx( index2 - table_no_cv_fx[im1], &x_lvq[LATTICE_DIM], im1 ); + scales_mslvq[1] = p_scales[add( i_mult2( mode_glb, len_scales ), add( MAX_NO_SCALES, idx_scale ) )]; + move16(); + } + /* Why is x_lvq not multiplied with scales_mslvq? */ + + return 0; +} + + +#else static Word16 decode_indexes_fx( Word16 *index, /* i : LSF vector index, written as array of Word16 because it generally uses more than 16 bits */ @@ -567,7 +741,116 @@ static Word16 decode_indexes_ivas_fx( return 0; } +#endif + + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * deindex_lvq() + * + *-----------------------------------------------------------------*/ +Word16 deindex_lvq_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + const Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + const Word16 sf_flag, /* i : safety net flag */ + const Word16 no_bits /* i : number of bits for lattice */ +) +{ + Word16 i; + const Word16 *p_scales; + Word16 mode_glb; + Word32 L_tmp; + // note_ : renamed from scales + Word16 scales_mslvq[2]; + Word16 ber_flag; + + IF( EQ_16( sf_flag, 1 ) ) + { + IF( LT_16( mode, 6 ) ) /* for NB */ + { + mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub( no_bits, min_lat_bits_SN_fx[mode] )] ); + } + ELSE + { + mode_glb = add( offset_lvq_modes_SN_fx[mode], sub( no_bits, min_lat_bits_SN_fx[mode] ) ); /* there is granularity of 1 bit */ + } + p_scales = &scales_fx[0][0]; // Q11 + move16(); + } + ELSE + { + test(); + IF( ( LT_16( mode, 6 ) ) || ( EQ_16( mode, 12 ) ) ) /* for NB */ + { + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub( no_bits, min_lat_bits_pred_fx[mode] )] ); + } + ELSE + { + mode_glb = add( offset_lvq_modes_pred_fx[mode], sub( no_bits, min_lat_bits_pred_fx[mode] ) ); + } + p_scales = &scales_p_fx[0][0]; // Q11 + move16(); + } + + /* decode the lattice index into the lattice codevectors for the two subvectors */ + ber_flag = decode_indexes_fx( index, no_bits, p_scales, x_lvq, mode_glb, scales_mslvq, 1 - sf_flag ); /* x_lvq is here Q1 */ + + IF( EQ_16( sf_flag, 1 ) ) + { + /* safety-net case*/ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + move16(); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_MSLVQ_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + move16(); + } + } + } + ELSE + { + /* predictive mode AR or MA */ + IF( scales_mslvq[0] ) + { + FOR( i = 0; i < LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + move16(); + } + } + IF( scales_mslvq[1] ) + { + FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ ) + { + L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */ + x_lvq[i] = round_fx( L_tmp ); + move16(); + } + } + } + + return ber_flag; +} + +#else Word16 deindex_lvq_fx( Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ @@ -601,6 +884,7 @@ Word16 deindex_lvq_fx( } /* decode the lattice index into the lattice codevectors for the two subvectors */ + ber_flag = decode_indexes_fx( index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq ); /* x_lvq is here Q1 */ @@ -707,9 +991,7 @@ Word16 deindex_lvq_ivas_fx( create_offset( offset_scale1, offset_scale2, mode_glb, 1 - sf_flag ); /* decode the lattice index into the lattice codevectors for the two subvectors */ - // ber_flag = - // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, offset_scale1, - // offset_scale2, x_lvq, mode_glb, scales_mslvq); /* x_lvq is here Q1 */ + ber_flag = decode_indexes_ivas_fx( index, no_bits, p_scales, 1 - sf_flag, x_lvq, mode_glb, scales_mslvq ); /* x_lvq is here Q1 */ @@ -765,6 +1047,8 @@ Word16 deindex_lvq_ivas_fx( return ber_flag; } +#endif + /*----------------------------------------------------------------------------------------------------* * deindex_lvq_cng() @@ -774,6 +1058,14 @@ Word16 deindex_lvq_ivas_fx( * not needed for deindex_lvq_cng(), since it is embedded inside the LSF codebooks. *----------------------------------------------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +Word16 deindex_lvq_cng_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q9 */ + const Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + const Word16 no_bits /* i : number of bits for lattice */ +) +#else Word16 deindex_lvq_cng_fx( Word16 *index, /* i : index to be decoded, as an array of 3 short */ Word16 *x_lvq, /* o : decoded codevector Q9 */ @@ -783,6 +1075,7 @@ Word16 deindex_lvq_cng_fx( Word32 *p_offset_scale2, /* i : scale index offset for second LSF subvector */ Word16 *p_no_scales /* i : number of scales for each MSLVQ structure and each subvector */ ) +#endif { Word16 i; Word32 L_tmp; @@ -799,8 +1092,12 @@ Word16 deindex_lvq_cng_fx( p_scales = &scales_fx[0][0]; move16(); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + ber_flag = decode_indexes_fx( index, no_bits, p_scales, x_lvq, mode_glb, scales_mslvq, 0 ); /* prediction_flag=0 */ +#else ber_flag = decode_indexes_fx( index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq ); +#endif FOR( i = 0; i < LATTICE_DIM; i++ ) { @@ -826,7 +1123,7 @@ Word16 deindex_lvq_cng_fx( return ber_flag; } - +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES /*----------------------------------------------------------------------------------------------------* * deindex_lvq_cng() * Note: @@ -857,11 +1154,11 @@ Word16 deindex_lvq_cng_ivas_fx( p_scales = &scales_ivas_fx[0][0]; move16(); - // ber_flag = - // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq); + ber_flag = decode_indexes_ivas_fx( index, no_bits, p_scales, 0, x_lvq, mode_glb, scales_mslvq ); + FOR( i = 0; i < LATTICE_DIM; i++ ) { L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */ @@ -885,13 +1182,20 @@ Word16 deindex_lvq_cng_ivas_fx( return ber_flag; } +#endif + + +/*-----------------------------------------------------------------* + * idx2c() + * + * decode index of binomial combinations, find the positions of k components out of n total components + *-----------------------------------------------------------------*/ -/* combinatorial indexing */ static void idx2c_fx( - Word16 n, /* i : total number of positions (components)*/ - Word16 *p, /* o : array with positions of the k components */ - Word16 k, /* i : number of components whose position is to be determined */ - Word16 val /* i : index to be decoded */ + Word16 n, /* i : total number of positions (components) */ + Word16 *p, /* o : array with positions of the k components */ + const Word16 k, /* i : number of components whose position is to be determined */ + Word16 val /* i : index to be decoded */ ) { Word16 i, skip, pos, k1; @@ -930,11 +1234,19 @@ static void idx2c_fx( return; } -/* combinatorial deindexing */ + + +/*-----------------------------------------------------------------* + * decode_comb() + * + * combinatorial deindexing of a codevector including the signs + * + *-----------------------------------------------------------------*/ + static void decode_comb_fx( - Word32 index, /* i : index to be decoded */ - Word16 *cv, /* o : decoded codevector Q1*/ - Word16 idx_lead /* i : leader class index */ + Word32 index, /* i : index to be decoded */ + Word16 *cv, /* o : decoded codevector Q1*/ + const Word16 idx_lead /* i : leader class index */ ) { Word16 idx_sign; @@ -947,19 +1259,29 @@ static void decode_comb_fx( { idx_sign = extract_l( div_l( L_shl( index, 1 ), pi0[idx_lead] ) ); /*(index/pi0_fx[idx_lead]); */ } + index = L_sub( index, L_mult0( idx_sign, pi0[idx_lead] ) ); decode_leaders_fx( extract_l( index ), idx_lead, cv ); decode_sign_pc1_fx( cv, idx_sign, pl_par[idx_lead] ); return; } -void decode_sign_pc1_fx( - Word16 *c, /* o : decoded codevector Q1*/ - Word16 idx_sign, /* i : sign index */ - Word16 parity /* i : parity flag (+1/-1/0) */ + + +/*-----------------------------------------------------------------* + * decode_sign_pc1() + * + *-----------------------------------------------------------------*/ + +static void decode_sign_pc1_fx( + Word16 *c, /* o : decoded codevector Q1*/ + Word16 idx_sign, /* i : sign index */ + const Word16 parity /* i : parity flag (+1/-1/0) */ ) { Word16 i, len = LATTICE_DIM, cnt_neg = 1; + move16(); + move16(); if ( parity ) { @@ -995,10 +1317,16 @@ void decode_sign_pc1_fx( } +/*-----------------------------------------------------------------* + * decode_leaders() + * + * decode index of a codevector from the leader class idx_lead + *-----------------------------------------------------------------*/ + static void decode_leaders_fx( - Word16 index, /* i : index to be decoded */ - Word16 idx_lead, /* i : leader class index */ - Word16 *cv /* o : decoded codevector Q1*/ + Word16 index, /* i : index to be decoded */ + const Word16 idx_lead, /* i : leader class index */ + Word16 *cv /* o : decoded codevector Q1*/ ) { Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt; @@ -1061,15 +1389,14 @@ static void decode_leaders_fx( /* divide_32_32_fx() :Division reminder - rem is the reminder of the division between y and x. */ static Word32 divide_32_32_fx( - Word32 y, /* i */ - Word32 x, /* i */ - Word32 *rem /* o */ + const Word32 y, /* i */ + const Word32 x, /* i */ + Word32 *rem /* o */ ) { Word32 result, t, L_tmp; Word16 i, ny, nx, nyx; - IF( LT_32( y, x ) ) { result = L_deposit_l( 0 ); @@ -1117,14 +1444,15 @@ static Word32 divide_32_32_fx( *rem = t; move32(); } + return result; } /* divide_32_32_fx() :Division reminder for Word16 - rem is the reminder of the division between y and x. */ static Word16 divide_16_16_fx( - Word16 y, /* i */ - Word16 x, /* i */ - Word16 *rem /* o */ + const Word16 y, /* i */ + const Word16 x, /* i */ + Word16 *rem /* o */ ) { Word16 result, t, tmp; @@ -1139,7 +1467,6 @@ static Word16 divide_16_16_fx( } ELSE { - result = 0; move16(); IF( y == 0 ) @@ -1185,9 +1512,9 @@ static Word16 divide_16_16_fx( static void divide_64_32_fx( - Word16 *xs, /* i : denominator as array of two int32 */ - Word32 y, /* i : nominator on 32 bits */ - Word32 *result, /* o : integer division result on 32 bits */ + Word16 *xs, /* i : denominator as array of two int32 */ + Word32 y, /* i : nominator on 32 bits */ + Word32 *result, /* o : integer division result on 32 bits */ Word32 *rem /* o : integer division reminder on 32 bits */ ) { @@ -1211,6 +1538,7 @@ static void divide_64_32_fx( { nb_x1 = sub( 31, norm_l( x[1] ) ); /*get_no_bits_fx(x[1]); */ } + /* take the first 31 bits */ IF( nb_x1 > 0 ) { @@ -1234,12 +1562,19 @@ static void divide_64_32_fx( return; } + +/*-----------------------------------------------------------------* + * put_value() + * + * inserts no_new_val values of val in the codevector cv at the positions given by the array p + *-----------------------------------------------------------------*/ + static void put_value_fx( - Word16 *cv, /* i/o: input codevector Q1*/ - Word16 *p, /* i : array with positions */ - Word16 val, /* i : value to be inserted Q1*/ - Word16 dim, /* i : vector dimension */ - Word16 no_new_val /* i : number of values to be inserted */ + Word16 *cv, /* i/o: input codevector Q1*/ + const Word16 *p, /* i : array with positions */ + const Word16 val, /* i : value to be inserted Q1*/ + const Word16 dim, /* i : vector dimension */ + const Word16 no_new_val /* i : number of values to be inserted */ ) { Word16 cv_out[LATTICE_DIM]; @@ -1280,13 +1615,14 @@ static void put_value_fx( return; } + /*-----------------------------------------------------------------* * create_offset() * * *-----------------------------------------------------------------*/ -void create_offset( +void create_offset_fx( UWord32 *offset_scale1, UWord32 *offset_scale2, const Word16 mode, @@ -1294,39 +1630,60 @@ void create_offset( { Word16 tmp, tmp1; - if ( prediction_flag == 0 ) + IF( prediction_flag == 0 ) { /* safety_net */ tmp = no_lead_idx[mode][0]; - if ( ( tmp <= LIMIT_LEADER ) && ( tmp < no_lead_idx[mode][1] - 2 ) ) + move16(); + + test(); + if ( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, no_lead_idx[mode][1] - 2 ) ) { - tmp += DELTA_LEADER; + tmp = add( tmp, DELTA_LEADER ); } - make_offset_scale( table_no_cv, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); - make_offset_scale( table_no_cv, leaders_short[no_lead_idx[mode][1]], MAX_NO_SCALES, offset_scale2 ); + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + make_offset_scale_fx( table_no_cv_fx, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); + make_offset_scale_fx( table_no_cv_fx, leaders_short[no_lead_idx[mode][1]], MAX_NO_SCALES, offset_scale2 ); +#else + make_offset_scale( table_no_cv_fx, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); + make_offset_scale( table_no_cv_fx, leaders_short[no_lead_idx[mode][1]], MAX_NO_SCALES, offset_scale2 ); +#endif } - else + ELSE { tmp = no_lead_p_idx[mode][0]; tmp1 = no_lead_p_idx[mode][1]; - if ( ( tmp <= LIMIT_LEADER ) && ( tmp < tmp1 - 2 ) ) + move16(); + move16(); + + test(); + IF( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) { - tmp += DELTA_LEADER; + tmp = add( tmp, DELTA_LEADER ); } - if ( ( tmp == LIMIT_LEADER ) && ( tmp1 == 0 ) ) + test(); + IF( EQ_16( tmp, LIMIT_LEADER ) && tmp1 == 0 ) { - tmp += DELTA_LEADER; + tmp = add( tmp, DELTA_LEADER ); tmp1 = DELTA_LEADER; + move16(); } - make_offset_scale( table_no_cv, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); - make_offset_scale( table_no_cv, leaders_short[tmp1], MAX_NO_SCALES, offset_scale2 ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + make_offset_scale_fx( table_no_cv_fx, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); + make_offset_scale_fx( table_no_cv_fx, leaders_short[tmp1], MAX_NO_SCALES, offset_scale2 ); +#else + make_offset_scale( table_no_cv_fx, leaders_short[tmp], MAX_NO_SCALES, offset_scale1 ); + make_offset_scale( table_no_cv_fx, leaders_short[tmp1], MAX_NO_SCALES, offset_scale2 ); +#endif } return; } + /*-----------------------------------------------------------------* * sort_desc_ind() * @@ -1379,6 +1736,12 @@ void sort_desc_ind_32_fx( } +/*-----------------------------------------------------------------* + * deindex_lvq_SHB() + * + * + *-----------------------------------------------------------------*/ + void deindex_lvq_SHB_fx( UWord32 index, Word16 *out, @@ -1403,7 +1766,6 @@ void deindex_lvq_SHB_fx( p_scales = &scales_BWE_3b_fx[i_mult( sub( nbits, mslvq_SHB_min_bits[1] ), 3 )]; } - IF( index == 0 ) { set16_fx( out, 0, LATTICE_DIM ); @@ -1415,7 +1777,11 @@ void deindex_lvq_SHB_fx( move32(); FOR( i = 0; i < MAX_NO_SCALES; i++ ) { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + offsets[i + 1] = UL_addNsD( table_no_cv_fx[p_no_lead[i]], offsets[i] ); +#else offsets[i + 1] = UL_addNsD( table_no_cv[p_no_lead[i]], offsets[i] ); +#endif move32(); } @@ -1433,13 +1799,21 @@ void deindex_lvq_SHB_fx( /* find idx_leader */ i = 1; move16(); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + WHILE( GT_32( index, table_no_cv_fx[i] ) ) +#else WHILE( GT_32( index, table_no_cv[i] ) ) +#endif { i = add( i, 1 ); } i = sub( i, 1 ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + decode_comb_fx( (Word32) ( L_sub( L_sub( index, table_no_cv_fx[i] ), 1 ) ), out, i ); +#else decode_comb_fx( (Word32) ( L_sub( L_sub( index, table_no_cv[i] ), 1 ) ), out, i ); +#endif scale = p_scales[idx_scale]; move16(); diff --git a/lib_com/options.h b/lib_com/options.h index 09025f757a2939d98ff3d9d29b69a4a4e172ba65..e6c34d48f294a339c4d7abe68926fa8945c605ae 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -113,6 +113,7 @@ #define HARMONIZE_2553_TonalConceal_SaveFreqSignal /* FhG: Harmonize TonalConceal_SaveFreqSignal with its ivas derivate */ #define HARMONIZE_2553_TonalConceal_SaveTimeSignal /* FhG: Harmonize TonalConceal_SaveTimeSignal with its ivas derivate */ + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ @@ -123,6 +124,9 @@ #define FIX_BASOP_2023_TDREND_DISTATT_PRECISION_BUGFIX /* Eri: Bug discovered in cleanup of basop issue 2023 */ #define FIX_1576_LCLD_CRASH_DIFFERENT_CODEC_ISAR_FRAME_SIZE /* Dolby: float issue 1576: fix for crash in LCLD mode when codec frame size is less than isar frame size */ #define FIX_1548_HARMONIZE_NON_DIEGETIC_PANNING_LAW /* Orange: float issue 1548: Harmonize non diegetic panning law in ISM and renderers */ +#define FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES /* Nokia: basop issue 2492: remove duplicates for decode_indexes() unify the use of offset scales between IVAS and EVS, which also allows to remove some duplicated tables and parameters */ +#define FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE +#define FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE_IVAS #define FIX_1452_DEFAULT_REVERB /* Nokia/Philips/FhG: Fix default room presets and their usage in renderer */ #define NONBE_FIX_ISSUE_2206_MDCT_STEREO_FIX_2549 /* FhG: Correct scale inconsistency of old_inp_16k_fx buffer scale. */ #define FIX_BASOP_2548_ProcessIGF_fx_PREDICTIONGAIN /* FhG: fixes obvious bug for IVAS path. For EVS path, issue is still not resolved */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c434a6fc125d15fe89f35bd31ae64afdb8a895c8..9ae9f7d8ec9d6abb5c35e06803c39ebc68fe1fec 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -30,6 +30,10 @@ *******************************************************************************************************/ +/*==================================================================================== + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 + ====================================================================================*/ + #ifndef PROT_FX2_H #define PROT_FX2_H @@ -175,6 +179,7 @@ Word16 sign16_fx( mslvq_com_fx.c /========================================================================================================*/ +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES Word32 encode_comb_fx( Word16 *cv, Word16 idx_lead ); @@ -190,7 +195,7 @@ Word32 mslvq_ivas_16( const Word16 mode_glb, /* i : LVQ coding mode */ const Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ ); - +#endif UWord32 index_lvq_SHB_fx( const Word16 idx_lead, const Word16 idx_scale, @@ -209,6 +214,22 @@ void permute_fx( const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +Word16 deindex_lvq_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ + Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ + const Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ + const Word16 sf_flag, /* i : safety net flag */ + const Word16 no_bits /* i : number of bits for lattice */ +); + +Word16 deindex_lvq_cng_fx( + Word16 *index, /* i : index to be decoded, as an array of 3 short */ + Word16 *x_lvq, /* o : decoded codevector Q9 */ + const Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + const Word16 no_bits /* i : number of bits for lattice */ +); +#else void init_lvq_fx( Word32 offset_scale1[][MAX_NO_SCALES + 1], Word32 offset_scale2[][MAX_NO_SCALES + 1], @@ -250,6 +271,7 @@ Word16 deindex_lvq_cng_ivas_fx( Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */ Word16 no_bits /* i: number of bits for lattice */ ); +#endif /*========================================================================================================/ swb_bwe_com_fx.c @@ -831,12 +853,12 @@ void lsf_syn_mem_restore_fx( Word16 pstreaklen /* i : LSF quantizer */ ); -void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qisf[], /* i : quantized xSF coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ +void lsf_update_memory_fx( + const Word16 narrowband, /* i : narrowband flag */ + const Word16 qisf[], /* i : quantized xSF coefficients */ + Word16 old_mem_MA[], /* i : MA memory */ + Word16 mem_MA[], /* o : updated MA memory */ + Word16 lpcorder /* i : LPC order */ ); void lsf_syn_mem_backup_fx( @@ -862,11 +884,6 @@ void lsf_syn_mem_backup_fx( Word16 *streaklimit, Word16 *pstreaklen ); -void tcvq_Dec_fx( - Word16 *ind, - Word16 *d_out_fx, - const Word16 safety_net ); - Word16 qlsf_ARSN_tcvq_Dec_16k_fx( Word16 *y_fx, /* o : Quantized LSF vector */ Word16 *indice, /* i : Indices */ @@ -959,6 +976,17 @@ ivas_error lsf_allocate_fx( Word16 bits1[] /* o : Number of bits for each stage pred */ ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +Word16 vq_dec_lvq_fx( + const Word16 sf_flag, /* i : safety net flag */ + Word16 x[], /* o : Decoded vector Q(x2.56)*/ + Word16 indices[], /* i : Indices */ + const Word16 stages, /* i : Number of stages */ + const Word16 N, /* i : Vector dimension */ + const Word16 mode, /* i : mode_lvq, or mode_lvq_p */ + const Word16 no_bits /* i : no. bits for lattice */ +); +#else Word16 vq_dec_lvq_fx( Word16 sf_flag, /* i : safety net flag */ Word16 x[], /* o : Decoded vector Q(x2.56)*/ @@ -983,21 +1011,16 @@ Word16 vq_dec_lvq_ivas_fx( Word16 mode, /* i : mode_lvq, or mode_lvq_p */ Word16 no_bits /* i : no. bits for lattice */ ); - +#endif void a2rc_fx( const Word16 *a, Word16 *refl, Word16 lpcorder ); -Word16 vq_dec_lvq_ivas_fx( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* i : mode_lvq, or mode_lvq_p */ - Word16 no_bits /* i : no. bits for lattice */ -); +void a2rc_fx( + const Word16 *a, + Word16 *refl, + Word16 lpcorder ); void lsp_weights_fx( Word16 lsp_nq_fx[], @@ -3442,7 +3465,7 @@ Word16 lsp_convert_poly_fx( ); void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ + const Word32 core_brate, /* i : core bitrate */ const Word16 L_frame, /* i : length of the frame */ Word32 *Enew, /* i/o: decoded SID energy Q6 */ Word16 *seed, /* i/o: random generator seed */ @@ -5357,13 +5380,6 @@ void lsf_end_dec_fx( const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ); -void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ - Word16 coder_type, /* i : Coder type Q0*/ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ -); - void CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 last_element_mode, /* i : last element mode Q0 */ @@ -9924,7 +9940,7 @@ void preemph_ivas_fx( Word32 *mem /* i/o: memory (x[-1]) Qx*/ ); -void create_offset( +void create_offset_fx( UWord32 *offset_scale1, UWord32 *offset_scale2, const Word16 mode, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 9a2caa064f9cb9df9437f8b6944e336475e46830..d285ea67ea7d0b632cf4654d3da4f81a5a956fc9 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -401,27 +401,34 @@ extern const Word16 no_vals[NO_LEADERS]; // Q0 extern const Word16 no_vals_ind[NO_LEADERS][MAX_NO_VALS]; // Q0 extern const Word16 C_VQ[LATTICE_DIM + 1][LATTICE_DIM + 1]; // Q0 -extern const Word16 BitsVQ[]; // Q0 -extern const Word16 BitsVQ_p[]; // Q0 -extern const UWord8 no_lead_idx[][2]; // Q0 -extern const UWord8 no_lead_p_idx[][2]; // Q0 -extern const Word8 leaders_short[][MAX_NO_SCALES]; // Q0 -extern const Word16 sigma_MSLVQ_fx[][16]; // Qlog2(2.56) -extern const Word16 sigma_p_fx[][16]; // Qlog2(2.56) -extern const Word16 sigma_p_ivas_fx[][16]; // Qlog2(2.56) -extern const Word16 inv_sigma_MSLVQ_fx[][16]; // Q15 -extern const Word16 inv_sigma_p_fx[][16]; // Q15 -extern const Word16 inv_sigma_p_ivas_fx[][16]; // Qlog2(2.56) -extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 BitsVQ[]; // Q0 +extern const Word16 BitsVQ_p[]; // Q0 +extern const UWord8 no_lead_idx[][2]; // Q0 +extern const UWord8 no_lead_p_idx[][2]; // Q0 +extern const Word8 leaders_short[][MAX_NO_SCALES]; // Q0 +extern const Word16 sigma_MSLVQ_fx[][16]; // Qlog2(2.56) +extern const Word16 sigma_p_fx[][16]; // Qlog2(2.56) +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +extern const Word16 sigma_p_ivas_fx[][16]; // Qlog2(2.56) +#endif +extern const Word16 inv_sigma_MSLVQ_fx[][16]; // Q15 +extern const Word16 inv_sigma_p_fx[][16]; // Q15 +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +extern const Word16 inv_sigma_p_ivas_fx[][16]; // Qlog2(2.56) +#endif +extern const Word16 scales_fx[][MAX_NO_SCALES * 2]; // Q11 +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 -extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; // Q11 -extern const Word16 predmode_tab[][6]; // Q0 -extern const Word16 pl_HQ_fx[]; // Q1 +#endif +extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2]; // Q11 +extern const Word16 predmode_tab[][6]; // Q0 +extern const Word16 pl_HQ_fx[]; // Q1 extern const Word16 pi0[]; // Q0 - -extern const UWord32 table_no_cv[]; // Q0 +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +extern const UWord32 table_no_cv[]; // Q0 +#endif extern const Word32 table_no_cv_fx[]; // Q0 extern const Word16 pl_par[]; // Q0 @@ -432,6 +439,14 @@ extern const Word16 cng_sort[]; // Q0 extern const Word16 perm_MSLVQ[][4]; // Q0 +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +extern const Word16 min_lat_bits_SN_fx[]; // Q0 +extern const Word16 min_lat_bits_pred_fx[]; // Q0 +extern const Word16 offset_in_lvq_mode_SN_fx[][21]; // Q0 +extern const Word16 offset_in_lvq_mode_pred_fx[][32]; // Q0 +extern const Word16 offset_lvq_modes_SN_fx[]; // Q0 +extern const Word16 offset_lvq_modes_pred_fx[]; // Qlog2(1.6) +#else extern const Word16 min_lat_bits_SN[]; extern const Word16 min_lat_bits_SN_fx[]; // Q0 @@ -449,7 +464,7 @@ extern const Word16 offset_lvq_modes_SN_fx[]; // Q0 extern const Word16 offset_lvq_modes_pred[]; extern const Word16 offset_lvq_modes_pred_fx[]; // Qlog2(1.6) - +#endif /*-----------------------------------------------------------------* * LSF quantization - BC-TCVQ tables *-----------------------------------------------------------------*/ @@ -1540,8 +1555,10 @@ extern const Word16 sin_scale_tbl_640[640]; // Q15 extern const Word16 sin_scale_tbl_512[512]; // Q15 extern const Word16 cos_scale_tbl_512[512]; // Q15 +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES extern const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 extern const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2]; // Q11 +#endif /*------------------------------------------------------------------------------* * FFT transform tables diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index d2f077a3e6dd87475ea2743aa88f7dbe4bfa128e..62d20e39970e75384ec2f73c22cf9c388142ab25 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -12569,6 +12569,7 @@ const Word16 C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] = {1,8,28,56,70,56,28,8,1} }; +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES const UWord32 table_no_cv[] = //Q0 { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, @@ -12576,6 +12577,7 @@ const UWord32 table_no_cv[] = //Q0 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648, 423760, 425104, 425232, 446736, 500496, 522000, 0 }; //Q0 +#endif const Word32 table_no_cv_fx[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 @@ -12678,6 +12680,7 @@ const Word16 pl_par[] = /* 1 if even number of signs */ 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1 }; // Q0 +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES const Word16 scales_fx[][6] =//Q11 { {3129, 0, 0, 3138, 0, 0, }, /* 14 */ @@ -12826,7 +12829,7 @@ const Word16 scales_fx[][6] =//Q11 {1999, 4485, 11706, 3084, 1315, 8624, }, {2267, 5315, 0, 2666, 1237, 1802}, /* CNG */ -};/* An 6-by-146 matrix in Scale = 2048.00f */ +}; const Word16 scales_p_fx[][6] = {//Q11 @@ -12986,7 +12989,7 @@ const Word16 scales_p_fx[][6] = {1612, 2574, 1221, 2265, 1505, 3398}, /* 37 (36.993) */ /* AUDIO 16k */ }; - +#endif const Word16 sigma_MSLVQ_fx[][16] = {//Qlog2(2.56) {3}, @@ -13025,7 +13028,7 @@ const Word16 sigma_MSLVQ_fx[][16] = {192, 249, 256, 235, 231, 230, 213, 215, 210, 247, 284, 237, 214, 210, 199, 181}, }; -/* An 16-by-33 matrix in Scale = 32768.00f */ + const Word16 inv_sigma_MSLVQ_fx[][16] =//Q15 { {32767}, @@ -13064,6 +13067,7 @@ const Word16 inv_sigma_MSLVQ_fx[][16] =//Q15 {438, 337, 327, 357, 363, 365, 394, 390, 400, 340, 295, 354, 392, 399, 421, 462}, }; + /* An 16-by-19 matrix in Scale = 32768.00f */ const Word16 inv_sigma_p_fx[][16] =//Q15 { @@ -13081,7 +13085,11 @@ const Word16 inv_sigma_p_fx[][16] =//Q15 {641, 523, 458, 434, 415, 410, 412, 395, 397, 394, 386, 381, 366, 392, 413, 419}, {449, 380, 364, 366, 354, 362, 362, 356, 337, 323, 293, 296, 336, 352, 353, 283}, {32767}, +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE_IVAS + {659, 486, 371, 386, 318, 328, 289, 284, 283, 258, 251, 257, 278, 290, 305, 330}, +#else {601, 485, 348, 262, 267, 266, 276, 285, 255, 233, 227, 235, 216, 237, 233, 212}, +#endif {338, 279, 247, 244, 233, 239, 231, 232, 228, 215, 194, 194, 207, 210, 222, 180}, {32767}, {594, 466, 394, 376, 362, 358, 346, 350, 336, 332, 313, 329, 343, 358, 370, 419}, @@ -13104,13 +13112,17 @@ const Word16 sigma_p_fx[][16] = {131, 160, 183, 193, 202, 205, 203, 212, 212, 213, 217, 220, 229, 214, 203, 200}, {187, 221, 231, 229, 237, 232, 232, 236, 249, 259, 286, 284, 250, 238, 238, 296}, {3}, +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE_IVAS + {127, 173, 226, 217, 264, 256, 290, 295, 297, 325, 334, 326, 302, 290, 275, 254}, +#else {140, 173, 241, 320, 314, 315, 304, 295, 329, 359, 369, 357, 388, 354, 359, 396}, - {248, 300, 339, 344, 360, 350, 363, 361, 368, 391, 431, 433, 406, 400, 377, 467}, +#endif +{248, 300, 339, 344, 360, 350, 363, 361, 368, 391, 431, 433, 406, 400, 377, 467}, {3}, {141, 180, 213, 223, 232, 234, 242, 240, 250, 253, 268, 255, 245, 235, 227, 200}, {178, 205, 259, 258, 273, 285, 275, 289, 299, 300, 310, 320, 335, 329, 316, 269}, }; - +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES const Word16 sigma_p_ivas_fx[][16] = {//Qlog2(2.56) {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110}, @@ -13156,7 +13168,7 @@ const Word16 inv_sigma_p_ivas_fx[][16] = {594, 466, 394, 376, 362, 358, 346, 350, 336, 332, 313, 329, 343, 358, 370, 419}, {471, 409, 323, 325, 308, 295, 304, 290, 281, 280, 271, 262, 251, 255, 266, 312} }; - +#endif const Word8 leaders_short[][MAX_NO_SCALES] = // Q0 {{ 0, 0, 0}, { 1, 0, 0}, @@ -13846,17 +13858,76 @@ const UWord8 no_lead_p_idx[][2] = { // Q0 { 8, 181}, }; +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +const Word16 min_lat_bits_SN_fx[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; +//Q0 + +const Word16 min_lat_bits_pred_fx[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; +//Q0 + +const Word16 offset_lvq_modes_SN_fx[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, 112 }; /* CNG */ +//Q0 + + +const Word16 offset_lvq_modes_pred_fx[] = {119, 153, 31, 67, -1, 102, 126, 160, 0, 46, -1, 82, 146, -1, 175, 191, -1, 225, 203}; +//Qlog2(1.6) + +const Word16 offset_in_lvq_mode_SN_fx[][21] = +{ + {0}, /* I NB */ + {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ + {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0}, /* I WB */ + {0}, /* UV WB*/ + {1}, /* V WB */ /* granularity 1 */ + {1}, /* G WB */ /* granularity 1 */ + {1}, /* T WB */ /* granularity 1 */ + {1}, /* A WB */ /* granularity 1 */ + {0}, /* I 16k */ + {0}, /* UV 16k */ + {1}, /* V 16k */ /* granularity 1 */ + {0}, /* G 16k */ + {0,1}, /* T 16k */ + {0}, /* A 16k */ +}; + + +const Word16 offset_in_lvq_mode_pred_fx[][32] = +{ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {1}, /* I WB */ + {1}, /* UV WB */ /* granularity 1 */ + {1}, /* V WB */ /* granularity 1 */ + {1}, /* G WB */ + {0}, /* T WB */ + {1}, /* A WB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ + {0}, /* UV 16k */ + {1}, /* V 16k */ + {1}, /* G 16k */ + {0}, /* T 16k */ + {1}, /* A 16k */ + {1}, /* G WB MA*/ +}; + +#else const Word16 min_lat_bits_SN[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; //Q0 const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 }; -const Word16 min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; +const Word16 min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16}; //Q0 const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16 }; -const Word16 offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, - 112 - }; /* CNG */ +const Word16 offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135, 112 }; /* CNG */ //Q0 const Word16 offset_lvq_modes_SN_fx[] = { -1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102,112 }; /* CNG */ @@ -13864,6 +13935,7 @@ const Word16 offset_lvq_modes_pred[] = {119, 153, 31, 67, -1, 102, 126, 160, 0, //Qlog2(1.6) const Word16 offset_lvq_modes_pred_fx[] = { 74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124 }; + const Word16 offset_in_lvq_mode_SN[][21] = { {0}, /* I NB */ @@ -13953,6 +14025,7 @@ const Word16 offset_in_lvq_mode_pred_fx[][32] = {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ }; +#endif /*-----------------------------------------------------------------* * BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf) @@ -27331,6 +27404,924 @@ const Word16 cos_scale_tbl_512[512] = /* Q15 */ 201, 100 }; +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +const Word16 scales_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors Q11*/ + { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE_IVAS + { 3129, 0, 0, 3137, 0, 0 }, /* 14 */ + { 3287, 0, 0, 3137, 0, 0 }, /* 15 */ + { 2611, 5033, 0, 3137, 0, 0 }, /* 18 */ + { 2611, 5033, 0, 3340, 0, 0 }, /* 19 */ + { 2164, 3674, 5931, 2363, 3809, 6281 }, /* 25 */ + { 1898, 2985, 4745, 2115, 3667, 7045 }, + /* 28*/ /* mode 0 UV WB*/ + { 2629, 5480, 0, 2971, 0, 0 }, /* 18 */ + { 2801, 0, 0, 2869, 5072, 0 }, /* 19 */ + { 1763, 2545, 3723, 2514, 4558, 21108 }, /* 24 */ + { 2195, 3960, 7440, 2500, 6017, 21960 }, /* 25 */ + { 1841, 2902, 1386, 2115, 3762, 22308 }, /* 29 */ + { 1699, 2709, 1288, 1865, 3246, 20660 }, + /* 32 */ /* mode 1 UV NB*/ + { 3221, 0, 0, 3391, 0, 0 }, /* 17 */ + { 2537, 4923, 0, 3186, 0, 0 }, /* 18 */ + { 2816, 4229, 6397, 3676, 0, 0 }, /* (18.745) 19 */ + { 2816, 4229, 6397, 3893, 0, 0 }, /* (19.838) 20 */ + { 2160, 3481, 9091, 3391, 0, 0 }, /* 21 */ + { 2560, 4923, 8462, 2775, 4835, 0 }, /* 22 */ + { 2551, 3803, 5619, 3072, 5537, 0 }, /* (22.959) 23 */ + { 2545, 4206, 7450, 3229, 0, 0 }, /* (23.949) 24 */ + { 2163, 3656, 9263, 2699, 5296, 0 }, /* 25 */ + { 2040, 3082, 6871, 2427, 3637, 5587 }, + { 1903, 2841, 6875, 2212, 3484, 5908 }, + { 1888, 3058, 6900, 2212, 3484, 5908 }, + { 1888, 3058, 6900, 2183, 3469, 6420 }, + { 1888, 3058, 6900, 1970, 3174, 8081 }, /* 30 */ + { 2633, 1855, 4960, 2301, 3477, 5083 }, /* (30.994) 31 */ + { 1528, 2269, 5876, 1964, 3033, 8002 }, /* 32 */ + { 1577, 2445, 5782, 1858, 2871, 4334 }, /* 33*/ + { 1532, 2259, 5870, 2421, 1661, 6824 }, /* 34*/ + { 1566, 2318, 3776, 2543, 3876, 1888 }, /* (34.981) 35 */ + { 1568, 2320, 3780, 2183, 3360, 1665 }, /* (35.998) 36 */ + { 1386, 1972, 4356, 1486, 2215, 4513 }, + /* 37*/ /* mode 2 V WB*/ + { 3356, 0, 0, 2494, 4425, 0 }, /* 17 */ + { 2633, 5009, 0, 2887, 0, 0 }, /* 18 */ + //{ 2224, 3538, 7696, 2494, 4425, 0 }, /* 22 */ + { 2224, 3539, 7696, 2494, 4426, 0 }, /* 22 */ + { 2119, 3225, 9861, 2494, 4425, 0 }, /* 23 */ + { 1974, 3139, 10121, 2494, 4425, 0 }, /* 24 */ + { 1722, 2453, 4059, 2494, 4425, 0 }, /* 25 */ + { 1839, 2658, 4472, 2490, 5455, 0 }, /* 27 */ + { 1722, 2533, 4581, 2037, 3393, 5808 }, /* 29 */ + { 1427, 2009, 4184, 1914, 3082, 1349 }, /* 34 */ + { 1370, 1861, 2719, 2017, 1339, 3913 }, + /* 37 */ /* mode 3 V NB*/ + { 2482, 3885, 0, 0, 0, 0 }, /* 12 (11.883) */ + { 2375, 3827, 6975, 0, 0, 0 }, /* (12.997) 13 */ + { 3395, 0, 0, 3883, 0, 0 }, /* (13.640) 14 */ + { 3563, 0, 0, 3883, 0, 0 }, /* (14.733) 15 */ + { 3346, 0, 0, 3418, 0, 0 }, /* 16 (15.826) */ + { 3563, 0, 0, 4128, 0, 0 }, /* (15.826) 16 */ + { 2820, 5218, 0, 3883, 0, 0 }, /* (17.479) 18 */ + { 2637, 4962, 0, 3418, 0, 0 }, /* 19 (18.572) */ + { 2482, 3885, 0, 3418, 0, 0 }, /* 20 (19.796) */ + { 2217, 3616, 6502, 3418, 0, 0 }, /* 21 (20.910) */ + { 2123, 3295, 8658, 3418, 0, 0 }, /* 22 (21.776) */ + { 2242, 3397, 5562, 2693, 5132, 0 }, /* 23 (22.959) */ + { 2387, 4024, 7483, 3452, 0, 0 }, /* (23.949) 24 */ + { 1927, 2838, 4548, 2693, 5132, 0 }, /* 25 (24.992) */ + { 1859, 2674, 3893, 2703, 5371, 0 }, /* 26 (25.904) */ + { 2202, 3619, 1618, 2703, 5372, 0 }, /* 27 (26.829) */ + { 2093, 3135, 1554, 2273, 3594, 5312 }, /* 28 (27.989) */ + { 2201, 3618, 1617, 2238, 3895, 6172 }, /* 29 (28.984) */ + { 1828, 3014, 1382, 2258, 3624, 5820 }, /* 30 (29.980) */ + { 1863, 3170, 1402, 2113, 3381, 5146 }, /* 31 (30.966) */ + { 1691, 2572, 1294, 2009, 3158, 4540 }, + /* 32 (31.995) */ /* G WB*/ + { 2424, 3706, 5654, 0, 0, 0 }, /* 12 (11.925) */ + { 3299, 0, 0, 3313, 0, 0 }, /* 16 (15.826) */ + //{ 2424, 3706, 5654, 3174, 0, 0 }, /* 19 (18.745) */ + { 2425, 3707, 5655, 3174, 0, 0 }, /* 19 (18.745) */ + { 2424, 3706, 5654, 3313, 0, 0 }, /* 20 (19.838) */ + { 2177, 3557, 6113, 3313, 0, 0 }, /* 21 (20.910) */ + { 2207, 3737, 6475, 3008, 4605, 0 }, /* 22 (21.985) */ + { 2816, 1873, 4263, 3008, 4605, 0 }, /* 23 (22.815) */ + { 1966, 2914, 1433, 2682, 4366, 0 }, /* 25 (24.996) */ + { 2301, 1626, 3895, 2627, 4714, 0 }, /* 26 (25.993) */ + { 2205, 3536, 1570, 2560, 3995, 6105 }, /* 27 (26.954) */ + { 1910, 3012, 1402, 2560, 3995, 6105 }, /* 28 (27.992) */ + { 1898, 3276, 1380, 2363, 3637, 5844 }, /* 29 (28.996) */ + { 2144, 1478, 3655, 2162, 3362, 5531 }, /* 30 (29.988) */ + { 1988, 1409, 3090, 2136, 3543, 6002 }, /* 31 (30.962) */ + { 1882, 1355, 2799, 2164, 3702, 6285 }, + /* 32 (31.987) */ /* G NB*/ + { 3311, 0, 0, 3393, 0, 0 }, /* 17 */ + { 2611, 4706, 0, 3201, 0, 0 }, /* 18 */ + { 2820, 5218, 0, 4128, 0, 0 }, + /* (18.572) 19 */ /* from GEWB */ + { 2660, 4134, 0, 4128, 0, 0 }, /* (19.796) 20 */ + { 2678, 4820, 0, 2840, 0, 0 }, /* 21 */ + { 2643, 4952, 0, 2775, 5003, 0 }, /* 22 */ + { 2402, 3618, 5726, 3252, 6201, 0 }, + /* (22.959) 23 */ /* from GEWB */ + { 2209, 3622, 6168, 2840, 0, 0 }, /* 24 */ + { 2209, 3622, 6168, 2713, 5232, 0 }, /* 25 */ + { 1992, 2850, 4124, 3262, 6518, 0 }, + /* (25.904) 26 */ /* from GEWB */ + { 2353, 3835, 1736, 3262, 6518, 0 }, /* (26.829) 27 */ + { 1837, 2744, 5332, 2191, 3459, 5175 }, /* 28 */ + { 2353, 3835, 1736, 2701, 4685, 7550 }, + /* (28.984) 29 */ /* from GEWB */ + { 1837, 2744, 5332, 1923, 2974, 4265 }, /* 30 */ + { 1853, 2717, 5322, 2271, 1591, 3491 }, + { 1560, 2254, 4831, 1923, 2977, 4265 }, + { 1626, 2510, 6512, 2271, 1591, 3491 }, + /* 33 */ /* mode 6 T WB */ + { 3336, 0, 0, 2439, 4528, 0 }, /* 17 */ + { 2615, 5236, 0, 2799, 0, 0 }, /* 18 */ + { 2215, 3606, 8046, 2439, 4528, 0 }, /* 22 */ + { 2084, 3143, 5750, 2439, 4528, 0 }, /* 23 */ + { 1933, 3024, 5658, 2439, 4528, 0 }, /* 24 */ + //{ 1863, 3571, 6793, 2439, 4528, 0 }, /* 25 */ + { 1864, 3572, 6793, 2439, 4528, 0 }, /* 25 */ + { 1884, 3375, 6283, 1984, 3446, 8095 }, /* 28 */ + { 1513, 2275, 5517, 1800, 2889, 4720 }, /* 31 */ + { 1452, 2113, 5564, 1658, 2549, 3735 }, + /* 32*/ /* mode 7 T NB*/ + { 1552, 2285, 4022, 4139, 1634, 2496 }, /* 31 */ + { 1431, 2117, 4050, 4139, 1634, 2496 }, + /* 32 */ /* mode 8 G 16k */ + { 1486, 2150, 3778, 2775, 1761, 4515 }, /* 32 (31.998) */ + { 1386, 2041, 3418, 2775, 1761, 4515 }, /* 33 (32.983) mode 9 T16k */ + { 3371, 0, 0, 2568, 5036, 0 }, /* 17 */ + { 3031, 6023, 0, 3733, 0, 0 }, /* (17.479) 18 */ + { 2801, 4704, 0, 3733, 0, 0 }, /* (18.703) 19 */ + { 2801, 4704, 0, 4065, 0, 0 }, /* (19.796) 20 */ + { 2197, 3815, 6617, 3436, 0, 0 }, /* 21 */ + { 2197, 3815, 6617, 2568, 5036, 0 }, /* 22 */ + { 2162, 3229, 5052, 3698, 6123, 0 }, /* (22.917) 23 */ + { 2314, 3723, 1712, 4065, 0, 0 }, /* (23.978) 24 */ + { 1947, 3055, 5111, 2570, 6084, 0 }, /* 25 */ + { 2351, 3770, 1665, 2570, 6084, 0 }, /* 26 */ + { 2351, 1656, 3932, 3133, 5603, 0 }, /* (26.953) 27 */ + { 2469, 1742, 4464, 3098, 6504, 0 }, /* (27.992) 28 */ + { 1646, 2457, 4046, 3080, 6574, 0 }, /* (28.992) 29 */ + { 2336, 1650, 3921, 4040, 2387, 7604 }, /* (29.976) 30 */ + { 2289, 1593, 4149, 2537, 4380, 7731 }, /* (30.963) 31 */ + { 1576, 2322, 3921, 2521, 4706, 7946 }, /* (31.995) 32 */ + { 2099, 1452, 3545, 2521, 4706, 7946 }, /* (32.996) 33 */ + { 1980, 1460, 3385, 3768, 2252, 5793 }, /* (33.994) 34 */ + { 2025, 1429, 3278, 2224, 4022, 5902 }, /* (34.954) 35 */ + { 1233, 1780, 2904, 2588, 1564, 4542 }, /* */ + /* 36 */ /* mode 10 AUDIO_WB LVQ bitrate 15-36 + 4 + 1*/ + // { 1746, 3622, 9062, 2048, 2048, 2048, }, + { + 1747, + 3623, + 9062, + 2048, + 2048, + 2048, + }, /* 17 */ + { 2070, 3405, 9017, 3231, 0, 0 }, /* 21 */ + { 2070, 3405, 9017, 2461, 4964, 0 }, /* 22 */ + { 1804, 3313, 8470, 2461, 4964, 0 }, /* 25 */ + { 1734, 3667, 9146, 2461, 4964, 0 }, /* 26 */ + { 1372, 2277, 4892, 2461, 4964, 0 }, + /* 28 */ /* mode 11 AUDIO_NB */ + { 2316, 3717, 1630, 2590, 5722, 0 }, /* 26 */ + { 1167, 1646, 2451, 2379, 3991, 1490 }, + /* 36*/ /* mode 12 AUDIO_WB 16k bitrate 15-36 + 4 + 1*/ + { 2140, 3248, 7688, 3418, 0, 0 }, /* 22 (21.776) */ + { 2252, 3284, 4700, 2732, 4962, 0 }, /* (22.959) 23 */ + { 2234, 3588, 6479, 2881, 0, 0 }, /* (23.949) 24 */ + { 2234, 3588, 6479, 2756, 5171, 0 }, /* (24.889) 25 */ + { 2234, 3588, 6479, 2230, 3448, 5167 }, /* (25.821) 26 */ + { 1925, 2762, 3897, 2455, 3665, 5251 }, /* (26.982) 27 */ + { 1802, 2621, 5783, 2250, 3553, 0 }, /* 28 (27.994) */ + { 1701, 2488, 5994, 2230, 3497, 5076 }, /* 29 (28.996) */ + { 1781, 2717, 5951, 2183, 3520, 5480 }, /* 30 (29.991) */ + { 1566, 6379, 3723, 2299, 4728, 9779 }, /* (30.985) 31 */ + { 1581, 2297, 4814, 2961, 1933, 4243 }, /* 32 (31.992) */ + { 1435, 2000, 3559, 1939, 2975, 4263 }, /* 33 (32.993) */ + { 1472, 2091, 3483, 2291, 1626, 3473 }, /* 34 (33.968) */ + { 1718, 1310, 3117, 2289, 3475, 1630 }, /* (34.968) 35 */ + { 1718, 1310, 3117, 1968, 3008, 1447 }, /* (35.990) 36 */ + { 1310, 1810, 3547, 1546, 2232, 3170 }, + /* 37 (36.995) */ /* VOICED 16k */ + { 2494, 1630, 4676, 2642, 6810, 0 }, /* 25 (24.980) */ + { 3256, 1710, 9084, 2246, 6287, 0 }, /* 25 (24.974) */ + { 2035, 5359, 0, 2234, 4573, 7079 }, /* 25 (24.852) */ + { 1816, 3221, 7256, 2228, 3741, 6281 }, /* 25 (24.994) */ + { 1714, 2535, 3897, 2658, 5728, 0 }, /* 25 (24.996) */ + { 2330, 5787, 0, 2265, 5726, 8992 }, /* 25 (24.671) */ + { 1927, 3954, 9160, 1394, 2592, 4767 }, /* 25 (24.936) */ + { 2768, 8871, 0, 1679, 3164, 8550 }, /* 25 (24.955) */ + { 2750, 7387, 0, 1759, 2975, 5304 }, /* 25 (24.853) */ + { 2473, 5611, 0, 1554, 2539, 4468 }, /* 25 (24.881) */ + { 2299, 5603, 0, 1789, 3067, 5296 }, /* 25 (24.939) */ + { 1882, 5060, 0, 1259, 2195, 4292 }, /* 25 (24.996) */ + { 3170, 9232, 0, 1689, 4460, 8816 }, /* 25 (24.310) */ + { 2492, 5935, 0, 1509, 2492, 3952 }, /* 25 (24.955) */ + { 1998, 4485, 11706, 3084, 1314, 8624 }, /* 25 (24.984) */ + { 2267, 5314, 0, 2666, 1236, 1802 } /* 25 (24.866) */ +#else + { 3129, 0, 0, 3138, 0, 0 }, /* 14 */ + { 3287, 0, 0, 3138, 0, 0 }, /* 15 */ + { 2611, 5034, 0, 3138, 0, 0 }, /* 18 */ + { 2611, 5034, 0, 3340, 0, 0 }, /* 19 */ + { 2165, 3674, 5931, 2363, 3809, 6281 }, /* 25 */ + { 1898, 2986, 4745, 2116, 3668, 7045 }, + /* 28*/ /* mode 0 UV WB*/ + { 2630, 5480, 0, 2972, 0, 0 }, /* 18 */ + { 2802, 0, 0, 2869, 5073, 0 }, /* 19 */ + { 1763, 2546, 3723, 2515, 4559, 21109 }, /* 24 */ + { 2195, 3961, 7440, 2501, 6017, 21961 }, /* 25 */ + { 1841, 2902, 1386, 2116, 3762, 22309 }, /* 29 */ + { 1700, 2710, 1288, 1866, 3246, 20660 }, + /* 32 */ /* mode 1 UV NB*/ + { 3222, 0, 0, 3391, 0, 0 }, /* 17 */ + { 2537, 4923, 0, 3187, 0, 0 }, /* 18 */ + { 2816, 4229, 6397, 3676, 0, 0 }, /* (18.745) 19 */ + { 2816, 4229, 6397, 3893, 0, 0 }, /* (19.838) 20 */ + { 2161, 3482, 9091, 3391, 0, 0 }, /* 21 */ + { 2560, 4923, 8462, 2775, 4835, 0 }, /* 22 */ + { 2551, 3803, 5619, 3072, 5537, 0 }, /* (22.959) 23 */ + { 2545, 4206, 7450, 3229, 0, 0 }, /* (23.949) 24 */ + { 2163, 3656, 9263, 2699, 5296, 0 }, /* 25 */ + { 2040, 3082, 6871, 2427, 3637, 5587 }, + { 1903, 2841, 6875, 2212, 3484, 5908 }, + { 1888, 3058, 6900, 2212, 3484, 5908 }, + { 1888, 3058, 6900, 2183, 3469, 6420 }, + { 1888, 3058, 6900, 1970, 3174, 8081 }, /* 30 */ + { 2633, 1855, 4960, 2301, 3477, 5083 }, /* (30.994) 31 */ + { 1528, 2269, 5876, 1964, 3033, 8002 }, /* 32 */ + { 1577, 2445, 5782, 1858, 2871, 4334 }, /* 33*/ + { 1532, 2259, 5870, 2421, 1661, 6824 }, /* 34*/ + { 1566, 2318, 3776, 2543, 3876, 1888 }, /* (34.981) 35 */ + { 1568, 2320, 3780, 2183, 3360, 1665 }, /* (35.998) 36 */ + { 1386, 1972, 4356, 1487, 2216, 4514 }, + /* 37*/ /* mode 2 V WB*/ + { 3357, 0, 0, 2494, 4426, 0 }, /* 17 */ + { 2634, 5009, 0, 2888, 0, 0 }, /* 18 */ + { 2224, 3539, 7696, 2494, 4426, 0 }, /* 22 */ + { 2120, 3226, 9861, 2494, 4426, 0 }, /* 23 */ + { 1974, 3140, 10121, 2494, 4426, 0 }, /* 24 */ + { 1722, 2454, 4059, 2494, 4426, 0 }, /* 25 */ + { 1839, 2658, 4473, 2490, 5456, 0 }, /* 27 */ + { 1722, 2533, 4581, 2038, 3394, 5808 }, /* 29 */ + { 1427, 2009, 4184, 1915, 3082, 1350 }, /* 34 */ + { 1370, 1862, 2720, 2017, 1339, 3914 }, + /* 37 */ /* mode 3 V NB*/ + { 2482, 3885, 0, 0, 0, 0 }, /* 12 (11.883) */ + { 2375, 3827, 6975, 0, 0, 0 }, /* (12.997) 13 */ + { 3395, 0, 0, 3883, 0, 0 }, /* (13.640) 14 */ + { 3563, 0, 0, 3883, 0, 0 }, /* (14.733) 15 */ + { 3346, 0, 0, 3418, 0, 0 }, /* 16 (15.826) */ + { 3563, 0, 0, 4128, 0, 0 }, /* (15.826) 16 */ + { 2820, 5218, 0, 3883, 0, 0 }, /* (17.479) 18 */ + { 2638, 4962, 0, 3418, 0, 0 }, /* 19 (18.572) */ + { 2482, 3885, 0, 3418, 0, 0 }, /* 20 (19.796) */ + { 2218, 3617, 6502, 3418, 0, 0 }, /* 21 (20.910) */ + { 2124, 3295, 8659, 3418, 0, 0 }, /* 22 (21.776) */ + { 2243, 3398, 5562, 2693, 5132, 0 }, /* 23 (22.959) */ + { 2387, 4024, 7483, 3452, 0, 0 }, /* (23.949) 24 */ + { 1927, 2839, 4549, 2693, 5132, 0 }, /* 25 (24.992) */ + { 1860, 2675, 3893, 2703, 5372, 0 }, /* 26 (25.904) */ + { 2202, 3619, 1618, 2703, 5372, 0 }, /* 27 (26.829) */ + { 2093, 3135, 1554, 2273, 3594, 5313 }, /* 28 (27.989) */ + { 2202, 3619, 1618, 2238, 3895, 6173 }, /* 29 (28.984) */ + { 1829, 3015, 1382, 2259, 3625, 5820 }, /* 30 (29.980) */ + { 1864, 3170, 1403, 2114, 3381, 5147 }, /* 31 (30.966) */ + { 1692, 2572, 1294, 2009, 3158, 4540 }, + /* 32 (31.995) */ /* G WB*/ + { 2425, 3707, 5655, 0, 0, 0 }, /* 12 (11.925) */ + { 3299, 0, 0, 3314, 0, 0 }, /* 16 (15.826) */ + { 2425, 3707, 5655, 3174, 0, 0 }, /* 19 (18.745) */ + { 2425, 3707, 5655, 3314, 0, 0 }, /* 20 (19.838) */ + { 2177, 3557, 6113, 3314, 0, 0 }, /* 21 (20.910) */ + { 2208, 3738, 6476, 3009, 4606, 0 }, /* 22 (21.985) */ + { 2816, 1874, 4264, 3009, 4606, 0 }, /* 23 (22.815) */ + { 1966, 2914, 1434, 2683, 4366, 0 }, /* 25 (24.996) */ + { 2302, 1626, 3895, 2628, 4714, 0 }, /* 26 (25.993) */ + { 2206, 3537, 1571, 2560, 3996, 6105 }, /* 27 (26.954) */ + { 1911, 3013, 1403, 2560, 3996, 6105 }, /* 28 (27.992) */ + { 1898, 3277, 1380, 2363, 3637, 5845 }, /* 29 (28.996) */ + { 2144, 1479, 3656, 2163, 3363, 5532 }, /* 30 (29.988) */ + { 1989, 1409, 3090, 2136, 3543, 6003 }, /* 31 (30.962) */ + { 1882, 1356, 2800, 2165, 3703, 6285 }, + /* 32 (31.987) */ /* G NB*/ + { 3312, 0, 0, 3394, 0, 0 }, /* 17 */ + { 2611, 4706, 0, 3201, 0, 0 }, /* 18 */ + { 2820, 5218, 0, 4128, 0, 0 }, + /* (18.572) 19 */ /* from GEWB */ + { 2660, 4134, 0, 4128, 0, 0 }, /* (19.796) 20 */ + { 2679, 4821, 0, 2841, 0, 0 }, /* 21 */ + { 2644, 4952, 0, 2775, 5003, 0 }, /* 22 */ + { 2402, 3618, 5726, 3252, 6201, 0 }, + /* (22.959) 23 */ /* from GEWB */ + { 2210, 3623, 6169, 2841, 0, 0 }, /* 24 */ + { 2210, 3623, 6169, 2714, 5233, 0 }, /* 25 */ + { 1992, 2850, 4124, 3262, 6518, 0 }, + /* (25.904) 26 */ /* from GEWB */ + { 2353, 3835, 1736, 3262, 6518, 0 }, /* (26.829) 27 */ + { 1837, 2744, 5333, 2191, 3459, 5175 }, /* 28 */ + { 2353, 3835, 1736, 2701, 4685, 7550 }, + /* (28.984) 29 */ /* from GEWB */ + { 1837, 2744, 5333, 1923, 2978, 4266 }, /* 30 */ + { 1853, 2718, 5323, 2271, 1591, 3492 }, + { 1561, 2255, 4831, 1923, 2978, 4266 }, + { 1626, 2511, 6513, 2271, 1591, 3492 }, + /* 33 */ /* mode 6 T WB */ + { 3336, 0, 0, 2439, 4528, 0 }, /* 17 */ + { 2615, 5237, 0, 2800, 0, 0 }, /* 18 */ + { 2216, 3607, 8047, 2439, 4528, 0 }, /* 22 */ + { 2085, 3144, 5751, 2439, 4528, 0 }, /* 23 */ + { 1933, 3025, 5659, 2439, 4528, 0 }, /* 24 */ + { 1864, 3572, 6793, 2439, 4528, 0 }, /* 25 */ + { 1884, 3375, 6283, 1985, 3447, 8096 }, /* 28 */ + { 1513, 2275, 5517, 1800, 2890, 4721 }, /* 31 */ + { 1452, 2114, 5564, 1659, 2550, 3736 }, + /* 32*/ /* mode 7 T NB*/ + { 1552, 2285, 4022, 4139, 1634, 2496 }, /* 31 */ + { 1431, 2117, 4050, 4139, 1634, 2496 }, + /* 32 */ /* mode 8 G 16k */ + { 1487, 2150, 3779, 2775, 1761, 4516 }, /* 32 (31.998) */ + { 1386, 2042, 3418, 2775, 1761, 4516 }, /* 33 (32.983) mode 9 T16k */ + { 3371, 0, 0, 2568, 5036, 0 }, /* 17 */ + { 3031, 6023, 0, 3733, 0, 0 }, /* (17.479) 18 */ + { 2801, 4704, 0, 3733, 0, 0 }, /* (18.703) 19 */ + { 2801, 4704, 0, 4065, 0, 0 }, /* (19.796) 20 */ + { 2198, 3815, 6617, 3437, 0, 0 }, /* 21 */ + { 2198, 3815, 6617, 2568, 5036, 0 }, /* 22 */ + { 2162, 3229, 5052, 3698, 6123, 0 }, /* (22.917) 23 */ + { 2314, 3723, 1712, 4065, 0, 0 }, /* (23.978) 24 */ + { 1948, 3056, 5112, 2570, 6085, 0 }, /* 25 */ + { 2351, 3770, 1665, 2570, 6085, 0 }, /* 26 */ + { 2351, 1656, 3932, 3133, 5603, 0 }, /* (26.953) 27 */ + { 2469, 1742, 4464, 3098, 6504, 0 }, /* (27.992) 28 */ + { 1646, 2457, 4046, 3080, 6574, 0 }, /* (28.992) 29 */ + { 2336, 1650, 3921, 4040, 2387, 7604 }, /* (29.976) 30 */ + { 2289, 1593, 4149, 2537, 4380, 7731 }, /* (30.963) 31 */ + { 1576, 2322, 3921, 2521, 4706, 7946 }, /* (31.995) 32 */ + { 2099, 1452, 3545, 2521, 4706, 7946 }, /* (32.996) 33 */ + { 1980, 1460, 3385, 3768, 2252, 5793 }, /* (33.994) 34 */ + { 2025, 1429, 3278, 2224, 4022, 5902 }, /* (34.954) 35 */ + { 1233, 1780, 2904, 2589, 1565, 4542 }, +/* 36 */ /* mode 10 AUDIO_WB LVQ bitrate 15-36 + 4 + 1*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE + { + 1747, + 3623, + 9062, + 2048, + 2048, + 2048, + }, /* 17 */ +#else + { 1746, 3622, 9062, 2048, 2048, 2048 }, /* 17 */ +#endif + { 2071, 3406, 9017, 3232, 0, 0 }, /* 21 */ + { 2071, 3406, 9017, 2462, 4964, 0 }, /* 22 */ + { 1804, 3314, 8471, 2462, 4964, 0 }, /* 25 */ + { 1735, 3668, 9146, 2462, 4964, 0 }, /* 26 */ + { 1372, 2277, 4893, 2462, 4964, 0 }, + /* 28 */ /* mode 11 AUDIO_NB */ + { 2316, 3717, 1630, 2591, 5722, 0 }, /* 26 */ + { 1167, 1647, 2451, 2380, 3992, 1491 }, + /* 36*/ /* mode 12 AUDIO_WB 16k bitrate 15-36 + 4 + 1*/ + { 2140, 3248, 7688, 3418, 0, 0 }, /* 22 (21.776) */ + { 2252, 3284, 4700, 2732, 4962, 0 }, /* (22.959) 23 */ + { 2234, 3588, 6479, 2881, 0, 0 }, /* (23.949) 24 */ + { 2234, 3588, 6479, 2756, 5171, 0 }, /* (24.889) 25 */ + { 2234, 3588, 6479, 2230, 3448, 5167 }, /* (25.821) 26 */ + { 1925, 2762, 3897, 2455, 3665, 5251 }, /* (26.982) 27 */ + { 1802, 2621, 5784, 2251, 3553, 0 }, /* 28 (27.994) */ + { 1702, 2488, 5994, 2230, 3498, 5077 }, /* 29 (28.996) */ + { 1782, 2718, 5951, 2183, 3521, 5480 }, /* 30 (29.991) */ + { 1566, 6379, 3723, 2299, 4728, 9779 }, /* (30.985) 31 */ + { 1581, 2298, 4815, 2961, 1933, 4243 }, /* 32 (31.992) */ + { 1436, 2001, 3559, 1939, 2976, 4264 }, /* 33 (32.993) */ + { 1473, 2091, 3484, 2292, 1626, 3473 }, /* 34 (33.968) */ + { 1718, 1310, 3117, 2289, 3475, 1630 }, /* (34.968) 35 */ + { 1718, 1310, 3117, 1968, 3008, 1447 }, /* (35.990) 36 */ + { 1311, 1810, 3547, 1546, 2232, 3170 }, + /* 37 (36.995) */ /* VOICED 16k */ + { 2494, 1630, 4676, 2642, 6810, 0 }, /* 25 (24.980) */ + { 3256, 1710, 9085, 2247, 6287, 0 }, /* 25 (24.974) */ + { 2036, 5360, 0, 2234, 4573, 7080 }, /* 25 (24.852) */ + { 1817, 3222, 7256, 2228, 3742, 6281 }, /* 25 (24.994) */ + { 1714, 2535, 3897, 2658, 5728, 0 }, /* 25 (24.996) */ + { 2331, 5788, 0, 2265, 5726, 8993 }, /* 25 (24.671) */ + { 1927, 3955, 9161, 1395, 2593, 4768 }, /* 25 (24.936) */ + { 2769, 8872, 0, 1679, 3164, 8550 }, /* 25 (24.955) */ + { 2750, 7387, 0, 1759, 2976, 5304 }, /* 25 (24.853) */ + { 2474, 5612, 0, 1554, 2540, 4469 }, /* 25 (24.881) */ + { 2300, 5603, 0, 1790, 3068, 5296 }, /* 25 (24.939) */ + { 1882, 5061, 0, 1260, 2195, 4293 }, /* 25 (24.996) */ + { 3170, 9232, 0, 1690, 4461, 8817 }, /* 25 (24.310) */ + { 2492, 5935, 0, 1509, 2492, 3953 }, /* 25 (24.955) */ + { 1999, 4485, 11706, 3084, 1315, 8624 }, /* 25 (24.984) */ + { 2267, 5315, 0, 2666, 1237, 1802 } /* 25 (24.866) */ +#endif + }; +const Word16 scales_p_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors 20 modes Q11 */ + { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE_IVAS + { 2998, 4861, 0, 0, 0, 0 }, /* 9 (8.464) */ + { 2629, 4421, 0, 0, 0, 0 }, /* (8.910) 9 */ + { 2549, 5304, 0, 0, 0, 0 }, /* (10.659) 11 */ + { 2338, 3805, 5994, 0, 0, 0 }, /* (11.925) 12 */ + { 2125, 3762, 6162, 0, 0, 0 }, /* (12.997) 13 */ + { 3102, 0, 0, 3153, 0, 0 }, /* (13.640) 14 */ + { 3244, 0, 0, 3153, 0, 0 }, /* (14.733) 15 */ + { 3244, 0, 0, 3317, 0, 0 }, /* (15.826) 16 */ + { 2629, 4421, 0, 3317, 0, 0 }, /* (16.823) 17 */ + { 2549, 5304, 0, 3153, 0, 0 }, /* (17.479) 18 */ + { 2590, 5251, 0, 3354, 0, 0 }, /* 19 (18.572) */ + { 2338, 3805, 5994, 3317, 0, 0 }, /* (19.838) 20 */ + { 2125, 3762, 6162, 3317, 0, 0 }, /* (20.910) 21 */ + { 2023, 3401, 5199, 3317, 0, 0 }, /* (21.776) 22 */ + { 2177, 3487, 5744, 2650, 4818, 0 }, /* 23 (22.959) */ + { 2177, 3926, 6273, 2795, 0, 0 }, /* 24 (23.949) */ + { 1871, 2891, 4552, 2650, 4818, 0 }, /* 25 (24.992) */ + { 1843, 2887, 4616, 2658, 4941, 0 }, /* (25.718) 26 */ + { 1806, 2869, 4919, 2689, 4999, 0 }, /* 27 (26.902) */ + { 2777, 1775, 4868, 2191, 3453, 5214 }, /* 28 (27.996) */ + { 1732, 2760, 5214, 2203, 3567, 5443 }, /* 29 (28.937) */ + { 1730, 2824, 5255, 2086, 3229, 5003 }, /* 30 (29.954) */ + { 1548, 2435, 5732, 2220, 3694, 5648 }, /* 31 (30.978) */ + { 1546, 2494, 5777, 1933, 2934, 4040 }, /* 32 (31.978) */ + { 1525, 2451, 5935, 2543, 1726, 3997 }, /* (32.988) 33 */ + { 1482, 2529, 6025, 2570, 1736, 4096 }, /* 34 (33.975) */ + { 1406, 2279, 4788, 1746, 2719, 3981 }, /* 35 (34.975) */ + { 1327, 2107, 3760, 1748, 2777, 4016 }, /* 36 (35.889) */ + { 1243, 1912, 3106, 1603, 2484, 3141 }, /* (36.996) 37 */ + { 1226, 1853, 3131, 1497, 2275, 3072 }, /* (37.993) 38 */ + { 1327, 2107, 3760, 1406, 2166, 3891 }, + /* 39 (38.488) */ /* V WB*/ + { 3303, 0, 0, 0, 0, 0 }, /* 8 (7.913) */ + //{ 2594, 5068, 0, 3315, 0, 0 }, /* 19 (18.572) */ + { 2595, 5069, 0, 3316, 0, 0 }, /* 19 (18.572) */ + //{ 2076, 3338, 5046, 2631, 4405, 0 }, /* 23 (22.773) */ + { 2077, 3338, 5046, 2632, 4405, 0 }, /* 23 (22.773) */ + //{ 1828, 2846, 4739, 3000, 4708, 0 }, /* 24 (23.999) */ + { 1829, 2847, 4739, 3000, 4708, 0 }, /* 24 (23.999) */ + { 1904, 2869, 4403, 2621, 4616, 0 }, /* 25 (24.992) */ + { 1828, 2846, 4739, 2613, 4517, 6111 }, /* 27 (26.962) */ + { 1828, 2846, 4739, 2121, 3371, 5060 }, /* 28 (27.835) */ + { 1755, 2738, 5046, 2136, 3543, 5376 }, /* 29 (28.937) */ + { 1566, 2496, 3180, 2121, 3371, 5060 }, /* 30 (29.969) */ + { 1615, 2719, 3383, 2154, 3653, 5541 }, /* 31 (30.952) */ + { 1564, 2506, 3184, 1884, 2955, 4167 }, /* 32 (31.978) */ + { 1357, 2172, 2535, 2824, 1839, 3995 }, /* 34 (33.992) */ + { 1378, 2260, 2674, 2578, 1695, 4001 }, /* 35 (35.000) */ + { 1363, 2193, 2557, 1644, 2541, 3540 }, /* 36 (35.980) */ + { 1347, 2127, 2486, 1945, 1333, 2926 }, + /* 39 (38.512) */ /* V NB*/ + { 3276, 0, 0, 3180, 0, 0 }, /* 15 (14.733) */ + { 2674, 4970, 0, 3235, 0, 0 }, /* (15.730) 16 */ + { 2674, 4970, 0, 3432, 0, 0 }, /* (16.823) 17 */ + { 2560, 5926, 0, 3235, 0, 0 }, /* (17.479) 18 */ + { 2322, 4067, 6748, 3180, 0, 0 }, /* 19 (18.745) */ + { 2340, 4202, 6850, 3432, 0, 0 }, /* (19.838) 20 */ + { 2138, 4159, 7141, 3432, 0, 0 }, /* (20.910) 21 */ + { 2021, 3661, 5445, 3373, 0, 0 }, /* 22 (21.776) */ + { 1841, 3280, 5281, 3373, 0, 0 }, /* 23 (22.791) */ + { 1632, 2650, 4382, 3373, 0, 0 }, /* 24 (23.999) */ + { 1632, 2650, 4382, 2734, 4556, 0 }, /* 25 (24.996) */ + { 1517, 2357, 3719, 2734, 4556, 0 }, /* 26 (25.934) */ + { 2007, 3485, 1445, 2697, 5382, 0 }, /* (26.887) 27 */ + { 1632, 2650, 4382, 2428, 3956, 0 }, /* 28 (27.969) */ + { 1517, 2357, 3719, 2383, 3733, 5670 }, /* 29 (28.996) */ + { 1449, 2306, 3999, 2203, 3543, 5687 }, /* 30 (29.988) */ + { 1351, 2148, 3217, 2203, 3543, 5687 }, /* 31 (30.931) */ + { 1355, 2101, 3182, 2199, 3917, 6189 }, /* 32 (31.987) */ + { 1351, 2148, 3217, 2947, 1896, 4364 }, /* 33 (32.982) */ + { 1290, 1978, 3117, 2686, 1804, 4519 }, /* 34 (33.967) */ + { 1263, 1886, 2963, 2113, 3172, 1548 }, + /* 35 (34.994) */ /* G WB*/ + { 3266, 0, 0, 3076, 0, 0 }, /* 15 (14.733) */ + { 2299, 3985, 7643, 3076, 0, 0 }, /* 19 (18.792) */ + //{ 2115, 4249, 8886, 2906, 5009, 0 }, /* 22 (21.985) */ + { 2116, 4250, 8886, 2906, 5009, 0 }, /* 22 (21.985) */ + { 2017, 3672, 12216, 2623, 4759, 0 }, /* 23 (22.773) */ + { 1804, 3289, 14325, 2906, 5009, 0 }, /* 24 (23.932) */ + { 1728, 3239, 14376, 2623, 4759, 0 }, /* 25 (24.955) */ + { 1615, 3112, 14751, 2623, 4759, 0 }, /* 26 (25.991) */ + { 1779, 3168, 14325, 2109, 3592, 6352 }, /* 28 (27.979) */ + { 1673, 3055, 14581, 2109, 3592, 6352 }, /* 29 (28.878) */ + { 1546, 2830, 14608, 2109, 3592, 6352 }, /* 30 (29.954) */ + { 1445, 2693, 14796, 2109, 3592, 6352 }, /* 31 (30.893) */ + { 1411, 2654, 14929, 2080, 3840, 6633 }, /* 32 (31.963) */ + { 1429, 2611, 14764, 1871, 3170, 4982 }, /* 33 (32.997) */ + { 1390, 2693, 14929, 2516, 3778, 1665 }, /* 34 (33.986) */ + { 1390, 2693, 14929, 2433, 1581, 4003 }, + /* 35 (34.952) */ /* G NB*/ + { 2070, 3639, 5652, 3305, 0, 0 }, /* 21 */ + { 1974, 3235, 8183, 3540, 0, 0 }, /* (21.776) 22 */ + { 1798, 2949, 4687, 3540, 0, 0 }, /* (22.784) 23 */ + { 1744, 3364, 4974, 3540, 0, 0 }, /* (23.980) 24 */ + { 1746, 2830, 4231, 2549, 5486, 0 }, /* 25 */ + { 2471, 1593, 4521, 2549, 5486, 0 }, /* 26 */ + { 1646, 2772, 5421, 2883, 5355, 0 }, /* (26.931) 27 */ + { 1601, 2568, 5732, 2822, 5545, 0 }, /* (27.977) 28 */ + { 2471, 1593, 4521, 2074, 3751, 6252 }, /* 29 */ + { 2471, 1593, 4521, 2908, 1785, 4771 }, /* 30 */ + { 1398, 2080, 3661, 2306, 3862, 5988 }, /* (30.993) 31 */ + { 1284, 1878, 2965, 2306, 3862, 5988 }, /* (31.998) 32 */ + { 1347, 2105, 3188, 3035, 1996, 4397 }, /* (32.996) 33 */ + { 1626, 1187, 2725, 3035, 1996, 4397 }, /* (33.994) 34 */ + { 1685, 1212, 2709, 2756, 1832, 4726 }, /* (34.999) 35 */ + { 2248, 1511, 1136, 1779, 2641, 3813 }, /* (35.984) 36 */ + { 1552, 2275, 1126, 1783, 2799, 3903 }, /* (36.969) 37 */ + { 1128, 1568, 2285, 1619, 2459, 3405 }, /* (37.971) 38 */ + { 1128, 1568, 2285, 1972, 1427, 2709 }, /* (38.973) 39 */ + { 1075, 1576, 2197, 1669, 2533, 1161 }, + /* 40 */ /* mode 7 AUDIO_WB 19-40 + 0 + 1 */ + //{ 2191, 3667, 7993, 3274, 0, 0 }, /* 21 */ + { 2191, 3668, 7993, 3275, 0, 0 }, /* 21 */ + { 1679, 2492, 4278, 2570, 4689, 0 }, /* 25 */ + { 1597, 2394, 5109, 2570, 4689, 0 }, /* 26 */ + { 2201, 1480, 4835, 2273, 4016, 7149 }, /* 30 */ + { 1415, 2107, 4786, 2117, 3667, 8200 }, /* 31 */ + { 1374, 2203, 5337, 1955, 3168, 5148 }, + /* 32 */ /*mode 8 AUDIO_NB */ + { 2424, 1589, 4335, 2164, 3420, 1380 }, /* 30 */ + { 1937, 2965, 5576, 2854, 5416, 9381 }, /* (30.967) 31 */ + { 1941, 2977, 5576, 4034, 2404, 7135 }, /* (31.990) 32 */ + { 1812, 2879, 5658, 4034, 2404, 7135 }, /* (32.979) 33 */ + { 2549, 1724, 4870, 4093, 2392, 7540 }, /* (33.989) 34 */ + { 1781, 2756, 5763, 3571, 2166, 5933 }, /* (34.991) 35 */ + { 1693, 2496, 4456, 3252, 5324, 2037 }, /* (35.990) 36 */ + { 1673, 2428, 4079, 3262, 1994, 5363 }, /* (36.986) 37 */ + { 1683, 2467, 4298, 2998, 1851, 4911 }, /* (37.982) 38 */ + { 1683, 2467, 4298, 4204, 1714, 2783 }, /* (38.995) 39 */ + { 1067, 1529, 2115, 1630, 2729, 1110 }, + /* 40 */ /* mode 9 AUDIO_WB 16k 30-40 + 5 MA pred for WB2 (AV: not used?)*/ + { 3438, 0, 0, 2625, 5060, 0 }, /* 17 (16.823) */ + { 2228, 3786, 6543, 3454, 0, 0 }, /* 21 (20.910) */ + { 2228, 3786, 6543, 2625, 5060, 0 }, /* 22 (21.907) */ + { 2306, 3459, 1617, 2625, 5060, 0 }, /* 25 (24.863) */ + { 1904, 2830, 1396, 2625, 5060, 0 }, /* 26 (25.921) */ + { 2283, 1626, 3792, 2623, 6211, 0 }, /* 27 (26.837) */ + { 1720, 2818, 1275, 1638, 2899, 8724 }, + /* 36 (35.998) */ /* INACTIVE NB */ + { 1640, 2351, 3690, 0, 0, 0 }, /* 17 (16.932) */ + { 2752, 5380, 0, 3223, 0, 0 }, /* (17.479) 18 */ + { 2580, 4188, 0, 3223, 0, 0 }, /* (18.703) 19 */ + { 2580, 4188, 0, 3430, 0, 0 }, /* (19.796) 20 */ + { 2230, 3710, 6496, 3434, 0, 0 }, /* 21 (20.910) */ + { 2230, 3899, 6596, 3115, 5396, 0 }, /* 22 (21.985) */ + { 1972, 2949, 4335, 3430, 0, 0 }, /* (22.934) 23 */ + { 1972, 2949, 4335, 2666, 4935, 0 }, /* (23.931) 24 */ + { 1730, 2482, 3960, 2689, 4954, 0 }, /* 25 (24.845) */ + { 1595, 2242, 3481, 2689, 4954, 0 }, /* 26 (25.999) */ + { 1480, 2078, 3407, 2689, 4954, 0 }, /* 27 (26.981) */ + { 2066, 3414, 1540, 2676, 6187, 0 }, /* (27.988) 28 */ + { 2058, 3373, 1533, 2179, 3831, 6856 }, /* (28.936) 29 */ + { 1832, 3051, 1396, 2179, 3831, 6856 }, /* (29.855) 30 */ + { 1611, 2605, 1245, 2179, 3831, 6856 }, /* (30.968) 31 */ + { 1763, 1327, 2988, 2179, 3831, 6856 }, /* (31.943) 32 */ + { 1697, 1292, 2738, 2168, 4161, 7020 }, /* (32.999) 33 */ + { 1763, 1327, 2988, 3155, 1884, 5142 }, /* (33.994) 34 */ + { 1736, 1296, 2781, 2883, 1800, 5552 }, /* (34.989) 35 */ + { 1828, 1335, 2945, 2203, 1474, 3674 }, + /* 36 (35.929) */ /* INACTIVE WB*/ + { 2783, 4722, 0, 3418, 0, 0 }, /* 17 (16.823) */ + { 2205, 3946, 7262, 3418, 0, 0 }, /* 21 (20.910) */ + { 2205, 4161, 7327, 2926, 5552, 0 }, /* 22 (21.985) */ + { 1705, 2566, 4311, 2627, 5234, 0 }, /* 25 (24.845) */ + { 1589, 2359, 3805, 2627, 5234, 0 }, /* 26 (25.934) */ + { 1472, 2183, 3547, 2627, 5234, 0 }, /* 27 (26.914) */ + { 1927, 1333, 3205, 1478, 2437, 3973 }, + /* 36 (35.915) */ /* INACTIVE 16k*/ + { 2646, 5076, 0, 3155, 0, 0 }, /* 18 (17.479) */ + { 2461, 3897, 0, 3155, 0, 0 }, /* 19 (18.703) */ + { 2105, 3360, 5027, 3375, 0, 0 }, /* 22 (21.776) */ + { 2553, 1798, 4769, 3375, 0, 0 }, /* 23 (22.791) */ + { 1767, 2781, 5165, 3375, 0, 0 }, /* 24 (23.999) */ + { 1673, 2502, 4116, 2199, 3655, 5597 }, /* 29 (28.966) */ + { 1669, 1253, 2623, 2160, 3530, 6045 }, + /* 32 (31.990) */ /* UNVOICED NB */ + { 3164, 0, 0, 3170, 0, 0 }, /* 14 (13.640) */ + { 3358, 0, 0, 3170, 0, 0 }, /* 15 (14.733) */ + { 2723, 0, 0, 3270, 0, 0 }, /* (15.826) 16 */ + { 2529, 4743, 0, 3270, 0, 0 }, /* (16.376) 17 */ + { 2635, 5629, 0, 3170, 0, 0 }, /* 18 (17.479) */ + { 2635, 5629, 0, 3387, 0, 0 }, /* 19 (18.572) */ + { 2437, 4149, 0, 3387, 0, 0 }, /* 20 (19.796) */ + { 1949, 3428, 5656, 3270, 0, 0 }, /* (20.910) 21 */ + { 1880, 3217, 6574, 3270, 0, 0 }, /* (21.776) 22 */ + { 2572, 1622, 4255, 3270, 0, 0 }, /* (22.784) 23 */ + { 1550, 2463, 3837, 3270, 0, 0 }, /* (23.999) 24 */ + { 1906, 2985, 5017, 2650, 5615, 0 }, /* 25 (24.992) */ + { 2287, 1507, 3840, 2562, 5257, 0 }, /* (25.993) 26 */ + { 1581, 2531, 3934, 2562, 5257, 0 }, /* (26.883) 27 */ + { 1796, 2859, 5605, 2213, 3719, 6881 }, + /* 28 (27.996) */ /* UNVOICED WB*/ + { 2316, 3350, 0, 2807, 0, 0 }, /* 24 (23.818) */ + { 1826, 3260, 7012, 2658, 6565, 0 }, /* (24.961) 25 */ + { 1792, 3168, 7084, 2631, 5937, 8499 }, /* (25.964) 26 */ + { 1732, 3379, 6772, 2611, 5009, 8202 }, /* (26.946) 27 */ + { 1654, 6285, 3514, 2611, 5009, 8202 }, /* (27.856) 28 */ + { 1566, 6406, 3733, 2611, 5009, 8202 }, /* (28.977) 29 */ + { 1912, 2615, 1490, 2369, 3475, 0 }, /* 30 (29.992) */ + { 1705, 2379, 1347, 2357, 3454, 0 }, /* 31 (30.998) */ + { 1538, 2113, 1224, 2357, 3454, 0 }, /* 32 (31.987) */ + { 1554, 6426, 3778, 1888, 3088, 6369 }, /* (32.975) 33 */ + { 1452, 2058, 1167, 2170, 3629, 5568 }, /* 34 (33.994) */ + { 1527, 2050, 1230, 2056, 3692, 5922 }, /* 35 (35.000) */ + { 1521, 2048, 1226, 1916, 3811, 5885 }, /* 36 (35.994) */ + { 1536, 6492, 3942, 1509, 2914, 5502 }, /* (36.977) 37 */ + { 1536, 6492, 3942, 1349, 2168, 4044 }, /* (37.984) 38 */ + { 1587, 1257, 2123, 1630, 2670, 3901 }, + /* 39 (38.301) */ /* VOICED 16k */ + { 1830, 2742, 5220, 2678, 5326, 0 }, /* 26 (25.917) */ + { 1703, 2568, 3966, 2676, 5353, 0 }, /* (26.887) 27 */ + { 1703, 2523, 3923, 2371, 4048, 0 }, /* (27.974) 28 */ + { 1689, 2580, 4081, 2095, 3561, 5726 }, /* (28.910) 29 */ + { 1536, 2281, 3201, 2140, 3690, 5490 }, /* (29.976) 30 */ + { 1417, 2048, 2930, 2095, 3561, 5726 }, /* (30.956) 31 */ + { 1474, 2072, 3272, 3096, 1896, 4376 }, /* 32 (31.980) */ + { 1394, 1992, 3377, 2828, 1794, 4360 }, /* 33 (32.990) */ + { 1400, 1974, 3358, 2392, 3637, 1611 }, /* 34 (33.974) */ + { 1368, 1914, 3176, 2080, 3108, 1458 }, /* 35 (34.989) */ + { 1349, 1865, 2918, 2738, 1820, 1314 }, /* 36 (35.988) */ + { 1349, 1865, 2918, 1718, 2635, 1243 }, + /* 37 (36.989) */ /* GENERIC 16k*/ + { 3344, 0, 0, 3454, 0, 0 }, /* 16 (15.826) */ + { 3463, 0, 0, 3428, 0, 0 }, /* (15.826) 16 */ + { 2719, 5251, 0, 3180, 0, 0 }, /* (17.479) 18 */ + { 2560, 4079, 0, 3180, 0, 0 }, /* (18.703) 19 */ + { 2560, 4079, 0, 3428, 0, 0 }, /* (19.796) 20 */ + { 2203, 3665, 6025, 3454, 0, 0 }, /* 21 (20.910) */ + { 2183, 3446, 8349, 3428, 0, 0 }, /* (21.776) 22 */ + { 2621, 1865, 5072, 3428, 0, 0 }, /* (22.791) 23 */ + { 1708, 2516, 3870, 3454, 0, 0 }, /* 24 (23.999) */ + { 1921, 2875, 4409, 2674, 5386, 0 }, /* 25 (24.992) */ + { 2744, 1814, 4751, 2674, 5386, 0 }, /* 26 (25.917) */ + { 1705, 2560, 3907, 2674, 5386, 0 }, /* 27 (26.883) */ + { 1705, 2484, 3835, 2304, 3766, 5773 }, /* 28 (27.901) */ + { 1748, 2594, 3743, 2138, 3604, 5902 }, /* (28.937) 29 */ + { 1566, 2379, 3461, 2097, 3559, 5812 }, /* 30 (29.916) */ + { 1484, 2150, 3667, 3031, 1888, 6356 }, /* 31 (30.993) */ + { 1458, 2072, 3172, 3059, 1849, 6889 }, /* 32 (31.980) */ + { 1349, 1898, 2779, 3059, 1849, 6889 }, /* 33 (32.958) */ + { 1683, 1257, 2637, 1863, 3090, 4618 }, /* 34 (33.987) */ + { 1722, 1277, 2617, 2377, 1560, 3702 }, /* 35 (34.994) */ + { 1716, 1273, 2592, 2211, 1456, 3502 }, /* 36 (35.968) */ + { 1703, 1267, 2611, 1921, 2928, 1318 }, + /* 37 (36.971) */ /* GENERIC 12.8k MA*/ + { 1810, 2762, 5263, 2691, 5343, 0 }, /* 26 (25.917) */ + { 2009, 3016, 5701, 3461, 6844, 0 }, /* (26.981) 27 */ + { 1976, 3100, 5500, 2885, 5089, 8081 }, /* (27.989) 28 */ + { 1998, 2983, 5453, 4405, 2603, 8552 }, /* (28.976) 29 */ + { 2029, 3080, 6320, 5091, 2693, 9277 }, /* (29.968) 30 */ + { 1937, 2965, 5576, 2854, 5416, 9381 }, /* (30.967) 31 */ + { 1456, 2084, 3307, 3035, 1886, 7026 }, /* 32 (31.980) */ + { 1390, 1994, 3397, 1941, 3172, 7061 }, /* 33 (32.995) */ + { 1701, 1265, 3033, 1910, 3100, 4730 }, /* 34 (33.993) */ + { 1671, 1249, 2871, 2920, 1796, 4638 }, /* 35 (34.992) */ + { 1611, 2574, 1220, 1759, 2963, 4978 }, /* 36 (35.997) */ + { 1611, 2574, 1220, 2265, 1505, 3397 } /* 37 (36.961) */ /* AUDIO 16k */ +#else + { 2998, 4862, 0, 0, 0, 0 }, /* 9 (8.464) */ + { 2629, 4421, 0, 0, 0, 0 }, /* (8.910) 9 */ + { 2549, 5304, 0, 0, 0, 0 }, /* (10.659) 11 */ + { 2338, 3805, 5994, 0, 0, 0 }, /* (11.925) 12 */ + { 2125, 3762, 6162, 0, 0, 0 }, /* (12.997) 13 */ + { 3102, 0, 0, 3153, 0, 0 }, /* (13.640) 14 */ + { 3244, 0, 0, 3153, 0, 0 }, /* (14.733) 15 */ + { 3244, 0, 0, 3317, 0, 0 }, /* (15.826) 16 */ + { 2629, 4421, 0, 3317, 0, 0 }, /* (16.823) 17 */ + { 2549, 5304, 0, 3153, 0, 0 }, /* (17.479) 18 */ + { 2591, 5251, 0, 3355, 0, 0 }, /* 19 (18.572) */ + { 2338, 3805, 5994, 3317, 0, 0 }, /* (19.838) 20 */ + { 2125, 3762, 6162, 3317, 0, 0 }, /* (20.910) 21 */ + { 2023, 3401, 5199, 3317, 0, 0 }, /* (21.776) 22 */ + { 2177, 3488, 5745, 2650, 4819, 0 }, /* 23 (22.959) */ + { 2177, 3926, 6273, 2796, 0, 0 }, /* 24 (23.949) */ + { 1872, 2892, 4553, 2650, 4819, 0 }, /* 25 (24.992) */ + { 1843, 2887, 4616, 2658, 4941, 0 }, /* (25.718) 26 */ + { 1806, 2869, 4919, 2689, 4999, 0 }, /* 27 (26.902) */ + { 2777, 1776, 4868, 2191, 3453, 5214 }, /* 28 (27.996) */ + { 1733, 2761, 5214, 2204, 3568, 5444 }, /* 29 (28.937) */ + { 1731, 2824, 5255, 2087, 3230, 5003 }, /* 30 (29.954) */ + { 1548, 2435, 5732, 2220, 3695, 5648 }, /* 31 (30.978) */ + { 1546, 2494, 5777, 1933, 2935, 4041 }, /* 32 (31.978) */ + { 1525, 2451, 5935, 2543, 1726, 3997 }, /* (32.988) 33 */ + { 1483, 2529, 6025, 2570, 1737, 4096 }, /* 34 (33.975) */ + { 1407, 2279, 4788, 1747, 2720, 3981 }, /* 35 (34.975) */ + { 1327, 2107, 3760, 1749, 2777, 4016 }, /* 36 (35.889) */ + { 1243, 1912, 3106, 1603, 2484, 3141 }, /* (36.996) 37 */ + { 1226, 1853, 3131, 1497, 2275, 3072 }, /* (37.993) 38 */ + { 1327, 2107, 3760, 1407, 2167, 3891 }, + /* 39 (38.488) */ /* V WB*/ + { 3303, 0, 0, 0, 0, 0 }, /* 8 (7.913) */ + { 2595, 5069, 0, 3316, 0, 0 }, /* 19 (18.572) */ + { 2077, 3338, 5046, 2632, 4405, 0 }, /* 23 (22.773) */ + { 1829, 2847, 4739, 3000, 4708, 0 }, /* 24 (23.999) */ + { 1905, 2869, 4403, 2621, 4616, 0 }, /* 25 (24.992) */ + { 1829, 2847, 4739, 2613, 4518, 6111 }, /* 27 (26.962) */ + { 1829, 2847, 4739, 2122, 3371, 5061 }, /* 28 (27.835) */ + { 1755, 2738, 5046, 2136, 3543, 5376 }, /* 29 (28.937) */ + { 1567, 2497, 3181, 2122, 3371, 5061 }, /* 30 (29.969) */ + { 1616, 2720, 3383, 2154, 3654, 5542 }, /* 31 (30.952) */ + { 1565, 2507, 3185, 1884, 2955, 4168 }, /* 32 (31.978) */ + { 1358, 2173, 2535, 2824, 1839, 3996 }, /* 34 (33.992) */ + { 1378, 2261, 2675, 2578, 1696, 4002 }, /* 35 (35.000) */ + { 1364, 2193, 2558, 1645, 2542, 3541 }, /* 36 (35.980) */ + { 1348, 2128, 2486, 1946, 1333, 2927 }, + /* 39 (38.512) */ /* V NB*/ + { 3277, 0, 0, 3181, 0, 0 }, /* 15 (14.733) */ + { 2674, 4970, 0, 3235, 0, 0 }, /* (15.730) 16 */ + { 2674, 4970, 0, 3432, 0, 0 }, /* (16.823) 17 */ + { 2560, 5926, 0, 3235, 0, 0 }, /* (17.479) 18 */ + { 2322, 4067, 6748, 3181, 0, 0 }, /* 19 (18.745) */ + { 2340, 4202, 6850, 3432, 0, 0 }, /* (19.838) 20 */ + { 2138, 4159, 7141, 3432, 0, 0 }, /* (20.910) 21 */ + { 2021, 3662, 5446, 3373, 0, 0 }, /* 22 (21.776) */ + { 1841, 3281, 5282, 3373, 0, 0 }, /* 23 (22.791) */ + { 1632, 2650, 4383, 3373, 0, 0 }, /* 24 (23.999) */ + { 1632, 2650, 4383, 2734, 4557, 0 }, /* 25 (24.996) */ + { 1518, 2357, 3719, 2734, 4557, 0 }, /* 26 (25.934) */ + { 2007, 3485, 1445, 2697, 5382, 0 }, /* (26.887) 27 */ + { 1632, 2650, 4383, 2429, 3957, 0 }, /* 28 (27.969) */ + { 1518, 2357, 3719, 2384, 3734, 5671 }, /* 29 (28.996) */ + { 1450, 2306, 4000, 2204, 3543, 5687 }, /* 30 (29.988) */ + { 1352, 2148, 3217, 2204, 3543, 5687 }, /* 31 (30.931) */ + { 1356, 2101, 3183, 2200, 3918, 6189 }, /* 32 (31.987) */ + { 1352, 2148, 3217, 2947, 1896, 4364 }, /* 33 (32.982) */ + { 1290, 1978, 3117, 2687, 1804, 4520 }, /* 34 (33.967) */ + { 1264, 1886, 2963, 2114, 3172, 1548 }, + /* 35 (34.994) */ /* G WB*/ + { 3267, 0, 0, 3076, 0, 0 }, /* 15 (14.733) */ + { 2300, 3985, 7643, 3076, 0, 0 }, /* 19 (18.792) */ + { 2116, 4250, 8886, 2906, 5009, 0 }, /* 22 (21.985) */ + { 2017, 3672, 12216, 2623, 4760, 0 }, /* 23 (22.773) */ + { 1804, 3289, 14326, 2906, 5009, 0 }, /* 24 (23.932) */ + { 1729, 3240, 14377, 2623, 4760, 0 }, /* 25 (24.955) */ + { 1616, 3113, 14752, 2623, 4760, 0 }, /* 26 (25.991) */ + { 1780, 3168, 14326, 2109, 3592, 6353 }, /* 28 (27.979) */ + { 1673, 3056, 14582, 2109, 3592, 6353 }, /* 29 (28.878) */ + { 1546, 2830, 14608, 2109, 3592, 6353 }, /* 30 (29.954) */ + { 1446, 2693, 14797, 2109, 3592, 6353 }, /* 31 (30.893) */ + { 1411, 2654, 14930, 2081, 3840, 6633 }, /* 32 (31.963) */ + { 1430, 2611, 14764, 1872, 3170, 4983 }, /* 33 (32.997) */ + { 1391, 2693, 14930, 2517, 3779, 1665 }, /* 34 (33.986) */ + { 1391, 2693, 14930, 2433, 1581, 4004 }, + /* 35 (34.952) */ /* G NB*/ + { 2070, 3639, 5652, 3305, 0, 0 }, /* 21 */ + { 1974, 3235, 8183, 3540, 0, 0 }, /* (21.776) 22 */ + { 1798, 2949, 4687, 3540, 0, 0 }, /* (22.784) 23 */ + { 1744, 3364, 4974, 3540, 0, 0 }, /* (23.980) 24 */ + { 1747, 2830, 4231, 2550, 5487, 0 }, /* 25 */ + { 2472, 1593, 4522, 2550, 5487, 0 }, /* 26 */ + { 1646, 2772, 5421, 2883, 5355, 0 }, /* (26.931) 27 */ + { 1601, 2568, 5732, 2822, 5545, 0 }, /* (27.977) 28 */ + { 2472, 1593, 4522, 2075, 3752, 6253 }, /* 29 */ + { 2472, 1593, 4522, 2908, 1786, 4772 }, /* 30 */ + { 1398, 2080, 3661, 2306, 3862, 5988 }, /* (30.993) 31 */ + { 1284, 1878, 2965, 2306, 3862, 5988 }, /* (31.998) 32 */ + { 1347, 2105, 3188, 3035, 1996, 4397 }, /* (32.996) 33 */ + { 1626, 1187, 2725, 3035, 1996, 4397 }, /* (33.994) 34 */ + { 1685, 1212, 2709, 2756, 1832, 4726 }, /* (34.999) 35 */ + { 2248, 1511, 1136, 1779, 2641, 3813 }, /* (35.984) 36 */ + { 1552, 2275, 1126, 1783, 2799, 3903 }, /* (36.969) 37 */ + { 1128, 1568, 2285, 1619, 2459, 3405 }, /* (37.971) 38 */ + { 1128, 1568, 2285, 1972, 1427, 2709 }, /* (38.973) 39 */ + { 1075, 1577, 2198, 1669, 2533, 1161 }, + /* 40 */ /* mode 7 AUDIO_WB 19-40 + 0 + 1 */ + { 2191, 3668, 7993, 3275, 0, 0 }, /* 21 */ + { 1679, 2492, 4278, 2570, 4690, 0 }, /* 25 */ + { 1597, 2394, 5110, 2570, 4690, 0 }, /* 26 */ + { 2202, 1481, 4835, 2273, 4016, 7150 }, /* 30 */ + { 1415, 2107, 4786, 2118, 3668, 8200 }, /* 31 */ + { 1374, 2204, 5337, 1956, 3168, 5149 }, + /* 32 */ /*mode 8 AUDIO_NB */ + { 2424, 1589, 4335, 2164, 3420, 1380 }, /* 30 */ + { 1937, 2965, 5576, 2854, 5416, 9381 }, /* (30.967) 31 */ + { 1941, 2977, 5576, 4034, 2404, 7135 }, /* (31.990) 32 */ + { 1812, 2879, 5658, 4034, 2404, 7135 }, /* (32.979) 33 */ + { 2549, 1724, 4870, 4093, 2392, 7540 }, /* (33.989) 34 */ + { 1781, 2756, 5763, 3571, 2166, 5933 }, /* (34.991) 35 */ + { 1693, 2496, 4456, 3252, 5324, 2037 }, /* (35.990) 36 */ + { 1673, 2428, 4079, 3262, 1994, 5363 }, /* (36.986) 37 */ + { 1683, 2467, 4298, 2998, 1851, 4911 }, /* (37.982) 38 */ + { 1683, 2467, 4298, 4204, 1714, 2783 }, /* (38.995) 39 */ + { 1067, 1530, 2116, 1630, 2730, 1110 }, + /* 40 */ /* mode 9 AUDIO_WB 16k 30-40 + 5 MA pred for WB2 (AV: not used?)*/ + { 3439, 0, 0, 2626, 5061, 0 }, /* 17 (16.823) */ + { 2228, 3787, 6543, 3455, 0, 0 }, /* 21 (20.910) */ + { 2228, 3787, 6543, 2626, 5061, 0 }, /* 22 (21.907) */ + { 2306, 3459, 1618, 2626, 5061, 0 }, /* 25 (24.863) */ + { 1905, 2830, 1397, 2626, 5061, 0 }, /* 26 (25.921) */ + { 2284, 1626, 3793, 2623, 6212, 0 }, /* 27 (26.837) */ + { 1720, 2818, 1276, 1638, 2900, 8724 }, + /* 36 (35.998) */ /* INACTIVE NB */ + { 1640, 2351, 3690, 0, 0, 0 }, /* 17 (16.932) */ + { 2752, 5380, 0, 3223, 0, 0 }, /* (17.479) 18 */ + { 2580, 4188, 0, 3223, 0, 0 }, /* (18.703) 19 */ + { 2580, 4188, 0, 3430, 0, 0 }, /* (19.796) 20 */ + { 2230, 3711, 6496, 3434, 0, 0 }, /* 21 (20.910) */ + { 2230, 3899, 6597, 3115, 5396, 0 }, /* 22 (21.985) */ + { 1972, 2949, 4335, 3430, 0, 0 }, /* (22.934) 23 */ + { 1972, 2949, 4335, 2666, 4935, 0 }, /* (23.931) 24 */ + { 1731, 2482, 3961, 2689, 4954, 0 }, /* 25 (24.845) */ + { 1595, 2243, 3482, 2689, 4954, 0 }, /* 26 (25.999) */ + { 1481, 2079, 3408, 2689, 4954, 0 }, /* 27 (26.981) */ + { 2066, 3414, 1540, 2676, 6187, 0 }, /* (27.988) 28 */ + { 2058, 3373, 1533, 2179, 3831, 6856 }, /* (28.936) 29 */ + { 1832, 3051, 1396, 2179, 3831, 6856 }, /* (29.855) 30 */ + { 1611, 2605, 1245, 2179, 3831, 6856 }, /* (30.968) 31 */ + { 1763, 1327, 2988, 2179, 3831, 6856 }, /* (31.943) 32 */ + { 1697, 1292, 2738, 2168, 4161, 7020 }, /* (32.999) 33 */ + { 1763, 1327, 2988, 3155, 1884, 5142 }, /* (33.994) 34 */ + { 1736, 1296, 2781, 2883, 1800, 5552 }, /* (34.989) 35 */ + { 1829, 1335, 2945, 2204, 1475, 3674 }, + /* 36 (35.929) */ /* INACTIVE WB*/ + { 2783, 4723, 0, 3418, 0, 0 }, /* 17 (16.823) */ + { 2206, 3946, 7262, 3418, 0, 0 }, /* 21 (20.910) */ + { 2206, 4162, 7328, 2927, 5552, 0 }, /* 22 (21.985) */ + { 1706, 2566, 4311, 2628, 5235, 0 }, /* 25 (24.845) */ + { 1589, 2359, 3805, 2628, 5235, 0 }, /* 26 (25.934) */ + { 1473, 2183, 3547, 2628, 5235, 0 }, /* 27 (26.914) */ + { 1927, 1333, 3205, 1479, 2437, 3973 }, + /* 36 (35.915) */ /* INACTIVE 16k*/ + { 2646, 5077, 0, 3156, 0, 0 }, /* 18 (17.479) */ + { 2462, 3897, 0, 3156, 0, 0 }, /* 19 (18.703) */ + { 2105, 3361, 5028, 3375, 0, 0 }, /* 22 (21.776) */ + { 2554, 1798, 4770, 3375, 0, 0 }, /* 23 (22.791) */ + { 1767, 2781, 5165, 3375, 0, 0 }, /* 24 (23.999) */ + { 1673, 2503, 4116, 2200, 3656, 5597 }, /* 29 (28.966) */ + { 1669, 1253, 2623, 2161, 3531, 6046 }, + /* 32 (31.990) */ /* UNVOICED NB */ + { 3164, 0, 0, 3170, 0, 0 }, /* 14 (13.640) */ + { 3359, 0, 0, 3170, 0, 0 }, /* 15 (14.733) */ + { 2723, 0, 0, 3270, 0, 0 }, /* (15.826) 16 */ + { 2529, 4743, 0, 3270, 0, 0 }, /* (16.376) 17 */ + { 2636, 5630, 0, 3170, 0, 0 }, /* 18 (17.479) */ + { 2636, 5630, 0, 3387, 0, 0 }, /* 19 (18.572) */ + { 2437, 4149, 0, 3387, 0, 0 }, /* 20 (19.796) */ + { 1949, 3428, 5656, 3270, 0, 0 }, /* (20.910) 21 */ + { 1880, 3217, 6574, 3270, 0, 0 }, /* (21.776) 22 */ + { 2572, 1622, 4255, 3270, 0, 0 }, /* (22.784) 23 */ + { 1550, 2463, 3837, 3270, 0, 0 }, /* (23.999) 24 */ + { 1907, 2986, 5018, 2650, 5616, 0 }, /* 25 (24.992) */ + { 2287, 1507, 3840, 2562, 5257, 0 }, /* (25.993) 26 */ + { 1581, 2531, 3934, 2562, 5257, 0 }, /* (26.883) 27 */ + { 1796, 2859, 5605, 2214, 3719, 6881 }, + /* 28 (27.996) */ /* UNVOICED WB*/ + { 2316, 3351, 0, 2808, 0, 0 }, /* 24 (23.818) */ + { 1826, 3260, 7012, 2658, 6565, 0 }, /* (24.961) 25 */ + { 1792, 3168, 7084, 2631, 5937, 8499 }, /* (25.964) 26 */ + { 1732, 3379, 6772, 2611, 5009, 8202 }, /* (26.946) 27 */ + { 1654, 6285, 3514, 2611, 5009, 8202 }, /* (27.856) 28 */ + { 1566, 6406, 3733, 2611, 5009, 8202 }, /* (28.977) 29 */ + { 1913, 2615, 1491, 2370, 3475, 0 }, /* 30 (29.992) */ + { 1706, 2380, 1348, 2357, 3455, 0 }, /* 31 (30.998) */ + { 1538, 2114, 1225, 2357, 3455, 0 }, /* 32 (31.987) */ + { 1554, 6426, 3778, 1888, 3088, 6369 }, /* (32.975) 33 */ + { 1452, 2058, 1167, 2171, 3629, 5569 }, /* 34 (33.994) */ + { 1528, 2050, 1231, 2056, 3693, 5923 }, /* 35 (35.000) */ + { 1522, 2048, 1227, 1917, 3811, 5886 }, /* 36 (35.994) */ + { 1536, 6492, 3942, 1509, 2914, 5502 }, /* (36.977) 37 */ + { 1536, 6492, 3942, 1349, 2168, 4044 }, /* (37.984) 38 */ + { 1587, 1257, 2124, 1630, 2671, 3901 }, + /* 39 (38.301) */ /* VOICED 16k */ + { 1831, 2742, 5220, 2679, 5327, 0 }, /* 26 (25.917) */ + { 1703, 2568, 3966, 2676, 5353, 0 }, /* (26.887) 27 */ + { 1703, 2523, 3923, 2371, 4048, 0 }, /* (27.974) 28 */ + { 1689, 2580, 4081, 2095, 3561, 5726 }, /* (28.910) 29 */ + { 1536, 2281, 3201, 2140, 3690, 5490 }, /* (29.976) 30 */ + { 1417, 2048, 2930, 2095, 3561, 5726 }, /* (30.956) 31 */ + { 1475, 2073, 3273, 3097, 1896, 4377 }, /* 32 (31.980) */ + { 1395, 1993, 3377, 2828, 1794, 4360 }, /* 33 (32.990) */ + { 1401, 1974, 3359, 2392, 3637, 1612 }, /* 34 (33.974) */ + { 1368, 1915, 3176, 2081, 3109, 1458 }, /* 35 (34.989) */ + { 1350, 1866, 2918, 2738, 1821, 1315 }, /* 36 (35.988) */ + { 1350, 1866, 2918, 1718, 2636, 1243 }, + /* 37 (36.989) */ /* GENERIC 16k*/ + { 3344, 0, 0, 3455, 0, 0 }, /* 16 (15.826) */ + { 3463, 0, 0, 3428, 0, 0 }, /* (15.826) 16 */ + { 2719, 5251, 0, 3180, 0, 0 }, /* (17.479) 18 */ + { 2560, 4079, 0, 3180, 0, 0 }, /* (18.703) 19 */ + { 2560, 4079, 0, 3428, 0, 0 }, /* (19.796) 20 */ + { 2204, 3666, 6025, 3455, 0, 0 }, /* 21 (20.910) */ + { 2183, 3446, 8349, 3428, 0, 0 }, /* (21.776) 22 */ + { 2621, 1865, 5072, 3428, 0, 0 }, /* (22.791) 23 */ + { 1708, 2517, 3871, 3455, 0, 0 }, /* 24 (23.999) */ + { 1921, 2875, 4409, 2675, 5386, 0 }, /* 25 (24.992) */ + { 2744, 1815, 4751, 2675, 5386, 0 }, /* 26 (25.917) */ + { 1706, 2560, 3908, 2675, 5386, 0 }, /* 27 (26.883) */ + { 1706, 2484, 3836, 2304, 3766, 5773 }, /* 28 (27.901) */ + { 1748, 2594, 3743, 2138, 3604, 5902 }, /* (28.937) 29 */ + { 1567, 2380, 3461, 2097, 3559, 5812 }, /* 30 (29.916) */ + { 1485, 2150, 3668, 3031, 1888, 6357 }, /* 31 (30.993) */ + { 1458, 2073, 3172, 3060, 1849, 6889 }, /* 32 (31.980) */ + { 1350, 1898, 2779, 3060, 1849, 6889 }, /* 33 (32.958) */ + { 1683, 1257, 2638, 1864, 3090, 4618 }, /* 34 (33.987) */ + { 1722, 1278, 2617, 2378, 1561, 3703 }, /* 35 (34.994) */ + { 1716, 1274, 2593, 2212, 1456, 3502 }, /* 36 (35.968) */ + { 1704, 1268, 2611, 1921, 2929, 1319 }, + /* 37 (36.971) */ /* GENERIC 12.8k MA*/ + { 1810, 2763, 5263, 2691, 5343, 0 }, /* 26 (25.917) */ + { 2009, 3016, 5701, 3461, 6844, 0 }, /* (26.981) 27 */ + { 1976, 3100, 5500, 2885, 5089, 8081 }, /* (27.989) 28 */ + { 1998, 2983, 5453, 4405, 2603, 8552 }, /* (28.976) 29 */ + { 2029, 3080, 6320, 5091, 2693, 9277 }, /* (29.968) 30 */ + { 1937, 2965, 5576, 2854, 5416, 9381 }, /* (30.967) 31 */ + { 1456, 2085, 3308, 3035, 1886, 7027 }, /* 32 (31.980) */ + { 1391, 1995, 3398, 1942, 3172, 7062 }, /* 33 (32.995) */ + { 1702, 1266, 3033, 1911, 3101, 4731 }, /* 34 (33.993) */ + { 1671, 1249, 2871, 2920, 1796, 4639 }, /* 35 (34.992) */ + { 1612, 2574, 1221, 1759, 2963, 4979 }, /* 36 (35.997) */ + { 1612, 2574, 1221, 2265, 1505, 3398 } /* 37 (36.961) */ /* AUDIO 16k */ +#endif + }; + +#else const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors Q11*/ { { @@ -30585,7 +31576,7 @@ const Word16 scales_p_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors 20 modes Q1 3397, } }; - +#endif /*-----------------------------------------------------------------* * FFT transform tables diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 56d2bd29c3e33ac9724922d7936ab0c301c0c909..95714eba42d9ccba04ba6a2ee09f35d19bac5eb5 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -74,9 +74,11 @@ void CNG_dec_fx( m = 0; move16(); + /*-----------------------------------------------------------------* * Decode CNG spectral envelope (only in SID frame) *-----------------------------------------------------------------*/ + test(); IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 6293b10c4bbcb7f81cd2fbb2f38a892d8a857099..c04926277de077fb9eeed9b2919a8bf4b0d36b60 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -1,3 +1,35 @@ +/****************************************************************************************************** + + (C) 2022-2026 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.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -291,7 +323,7 @@ void decoder_LPD_fx( } /* update mem_MA and mem_AR memories */ - lsf_update_memory( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); + lsf_update_memory_fx( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); Copy( &lsf[M], st->mem_AR_fx, M ); FOR( k = 0; k < st->numlpc; ++k ) @@ -321,7 +353,7 @@ void decoder_LPD_fx( E_LPC_lsf_lsp_conversion( &lsf[M], &lsp[M], M ); - lsf_update_memory( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); + lsf_update_memory_fx( (Word16) st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); Copy( &lsf[M], st->mem_AR_fx, M ); hTcxDec->envWeighted = 1; diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 9ab72547bb6918c76b1b55aceb2e1dfca2260996..cfe00f78d03d6d6f9621d5c60bcf190fc2ed4844 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -132,9 +132,9 @@ ivas_error init_decoder_fx( /* LSF initilaizations */ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - +#endif set16_fx( st_fx->mem_MA_fx, 0, M ); st_fx->dm_fx.prev_state = 0; /* This corresponds to st_fx->dispMem in FLP */ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 486896dc0b9fc79d2336ffbb267780e65d75616c..e820f98fbc5435d266ec0e4ad63859261887c87d 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -357,7 +357,7 @@ void stereo_tcx_core_dec_fx( lsf2lsp_fx( &lsf_fx[M], &lsp_fx[M], M, st->sr_core ); - lsf_update_memory( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); + lsf_update_memory_fx( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); Copy( &lsf_fx[M], st->mem_AR_fx, M ); /* Q2.56 */ hTcxDec->envWeighted = 1; move16(); diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index b44441aaa07e70b31e1286fa30fc740e20454639..3d063e3696197d151935a0f9cc4efcba097246de 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -1,3 +1,35 @@ +/****************************************************************************************************** + + (C) 2022-2026 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.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -9,12 +41,16 @@ #include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ +static void lsf_mid_dec_fx( Decoder_State *st_fx, const Word16 lsp_new[], const Word16 coder_type, Word16 lsp_mid[] ); + static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); + /*--------------------------------------------------------------------------------------* * dqlsf_CNG_fx() * @@ -43,6 +79,10 @@ static void dqlsf_CNG_fx( move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + ber_flag = + deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */ +#else IF( st_fx->element_mode == EVS_MONO ) { ber_flag = @@ -53,6 +93,7 @@ static void dqlsf_CNG_fx( ber_flag = deindex_lvq_cng_ivas_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4 ); /* Q0 */ } +#endif st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */ move16(); @@ -177,12 +218,11 @@ void lsf_dec_fx( } /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc, - tdm_lsfQ_PCh ); + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc, tdm_lsfQ_PCh ); /* convert quantized LSFs to LSPs */ - lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); + /* set seed_acelp used in UC mode */ test(); IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) @@ -196,6 +236,7 @@ void lsf_dec_fx( move16(); } } + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* return if SID frame (conversion to A(z) done in the calling function) */ @@ -248,10 +289,10 @@ void lsf_dec_fx( Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ } - { - /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); - } + + /* Mid-frame LSF decoding */ + lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); + test(); test(); IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) @@ -392,13 +433,12 @@ void lsf_end_dec_fx( const Word16 *Bit_alloc1 = NULL, *bits; Word16 num_bits; Word16 *p_lpc_param; - Word16 nBits; - Word16 coder_type; Word16 ber_flag; Word16 flag_1bit_gran; Word16 pred3[M]; + flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */ nBits = nBits_in; /* Q0 */ @@ -440,19 +480,19 @@ void lsf_end_dec_fx( return; } - find_pred_mode( &predmode, coder_type, bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); + /*----------------------------------------------------------------* * Calculate number of stages and levels for each stage based on the allowed bit allocation * (subtract one bit for LSF predictor selection) *----------------------------------------------------------------*/ - lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, - bits0, bits1 ); + lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); /*--------------------------------------------------------------------------* * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ + test(); test(); IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) @@ -461,10 +501,10 @@ void lsf_end_dec_fx( /*predmode += 3;*/ predmode = add( predmode, 3 ); /* Q0 */ } - p_lpc_param = lpc_param; /* Q0 */ - + p_lpc_param = lpc_param; /* Q0 */ move16(); + IF( predmode == 0 ) { safety_net = 1; /* Q0 */ @@ -499,8 +539,9 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Read indices from array *--------------------------------------------------------------------------*/ - test(); + /* Make sure there are the correct bit allocations */ + test(); IF( EQ_16( st->idchan, 1 ) && GT_16( predmode, 2 ) ) { /* use same AR prediction bit allocation for intra and inter modes*/ @@ -673,20 +714,22 @@ void lsf_end_dec_fx( } ELSE { - /* Safety-net */ Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ + /* for mem_MA update */ FOR( i = 0; i < M; i++ ) { pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */ move16(); } + /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } + IF( safety_net ) { /* LVQ */ @@ -694,10 +737,14 @@ void lsf_end_dec_fx( test(); IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { - /* intra mode*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + st->BER_detect = s_or( st->BER_detect, + vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ +#else st->BER_detect = s_or( st->BER_detect, vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ +#endif move16(); Vr_add( qlsf, pred3, qlsf, M ); @@ -705,6 +752,9 @@ void lsf_end_dec_fx( } ELSE { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ +#else IF( st->element_mode != EVS_MONO ) { ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ @@ -715,6 +765,7 @@ void lsf_end_dec_fx( &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } +#endif st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); Vr_add( qlsf, pred0, qlsf, M ); @@ -730,6 +781,10 @@ void lsf_end_dec_fx( move16(); move16(); } + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ +#else IF( st->element_mode != EVS_MONO ) { ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ @@ -740,8 +795,10 @@ void lsf_end_dec_fx( &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } +#endif st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); + test(); IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */ { @@ -809,11 +866,12 @@ void lsf_end_dec_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ -void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ - Word16 coder_type, /* i : Coder type Q0*/ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + +static void lsf_mid_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ + const Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -822,10 +880,10 @@ void lsf_mid_dec_fx( Word32 L_tmp; Word16 bad_spacing; const Word16 *ratio = NULL; + bad_spacing = 0; move16(); - /* Convert LSPs to LSFs */ lsp2lsf_fx( st_fx->lsp_old_fx, qlsf0, M, st_fx->sr_core ); lsp2lsf_fx( lsp_new, qlsf1, M, st_fx->sr_core ); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 58056843eb6fc00397370916450dd4c7d3b2be26..954f5c1f463b415476b7b6f8a0628cd7b50958c4 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1086,13 +1086,14 @@ typedef struct Decoder_State Word16 stab_fac_smooth_lt_fx; /*In range of word16*/ /*Q-15*/ Word32 log_energy_old_fx; +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - +#endif Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 94a306091a3df4c17b49c0dbb6dae776a32d777d..d6575181b144eeb6896bf563a35677458277a299 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -422,7 +422,7 @@ void core_encode_openloop_fx( move16(); /* Update ACELP quantizer state */ - lsf_update_memory( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); + lsf_update_memory_fx( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); st->pstreaklen = 0; st->streaklimit_fx = 32767; /*1 Q15*/ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 52fb9b6252e45c2fcab9025193443c7955e0bef6..9143395dad5d208cc456a9071143ed058975a864 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -170,8 +170,9 @@ ivas_error init_encoder_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES init_lvq_fx( st->offset_scale1_fx, st->offset_scale2_fx, st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_fx, st->no_scales_p_fx ); - +#endif st->next_force_safety_net = 0; move16(); diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 65f097eaa883f916661fad0cdf62e44f512c2d06..5ed43dbee77e9f6d503f337c683ae53ac9e39711 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -638,7 +638,7 @@ void stereo_tcx_core_enc( move16(); /* Update ACELP quantizer state */ - lsf_update_memory( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); + lsf_update_memory_fx( st->narrowBand, st->lsf_old_fx, st->mem_MA_fx, st->mem_MA_fx, M ); st->pstreaklen = 0; st->streaklimit_fx = 32767; // 1.0 in Q15 move16(); diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index bc1f4cb3a979d6ec7b864bbe8a8505f500d48877..ff5b99c87cf58eba441c315312ae3f9029b1a536 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -1,3 +1,35 @@ +/****************************************************************************************************** + + (C) 2022-2026 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.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -20,16 +52,19 @@ #define MSVQ_MAXCNT 3000 #define MAXINT32 MAX_32 + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf ); +static Word32 vq_lvq_lsf_enc_fx( const Word16 pred_flag, const Word16 mode, const Word16 u[], const Word16 *levels, const Word16 stages, const Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq, const Word16 flag_1bit_gran ); +#else static void lsfq_CNG_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); - static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); - static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq ); - +#endif static void lsf_mid_enc_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); @@ -355,15 +390,24 @@ void lsf_enc_fx( * either NB or WB LSF data. *-------------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static void lsfq_CNG_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ + const Word16 *lsf, /*x2.56 unquantized LSF vector */ + const Word16 *wghts, /*Q10 LSF weights */ + Word16 *qlsf /*x2.56 quantized LSF vector */ +) +#else static void lsfq_CNG_fx( const Word16 element_mode, /* i : element mode */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ const Word16 *lsf, /*x2.56 unquantized LSF vector */ const Word16 *wghts, /*Q10 LSF weights */ - Word16 *qlsf, /*x2.56 quantized LSF vecotor */ + Word16 *qlsf, /*x2.56 quantized LSF vector */ Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ) +#endif { Word16 i, j, idx_cv, idx_lvq[3]; Word32 min_dist, dist; @@ -432,6 +476,14 @@ static void lsfq_CNG_fx( /* quantize the difference with LVQ */ /* MSVQ_ROM to be updated */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE + index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, 0 ); +#else + index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG_IVAS + idx_cv, idx_lvq, 0 ); +#endif +#else IF( element_mode == EVS_MONO ) { mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); @@ -445,7 +497,7 @@ static void lsfq_CNG_fx( index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG_IVAS + idx_cv, idx_lvq, 0 ); } - +#endif Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); /* write the VQ index to the bitstream */ @@ -466,10 +518,10 @@ static void lsfq_CNG_fx( *-------------------------------------------------------------------*/ static Word16 qlsf_Mode_Select_fx( - const Word16 *w, /* i : weighting vector Q8 */ - const Word16 *pred1, /* i : prediction vector x2.56 */ - const Word16 streaklimit, /* i : predictive streak limit Q15 */ - const Word32 op_loop_thr /* i : Open-loop Threshold */ + const Word16 *w, /* i : weighting vector Q8 */ + const Word16 *pred1, /* i : prediction vector x2.56 */ + const Word16 streaklimit, /* i : predictive streak limit Q15 */ + const Word32 op_loop_thr /* i : Open-loop Threshold */ ) { Word16 pred_pow2[M]; @@ -669,7 +721,11 @@ void lsf_end_enc_fx( IF( EQ_32( st->core_brate, SID_2k40 ) ) { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + lsfq_CNG_fx( hBstr, lsf, wghts, qlsf ); +#else lsfq_CNG_fx( st->element_mode, hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); +#endif sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); @@ -720,6 +776,9 @@ void lsf_end_enc_fx( Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[0] = vq_lvq_lsf_enc_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq, flag_1bit_gran ); +#else IF( flag_1bit_gran == 0 ) { Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, @@ -729,6 +788,7 @@ void lsf_end_enc_fx( { Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); } +#endif safety_net = 1; move16(); @@ -739,6 +799,9 @@ void lsf_end_enc_fx( { Vr_subt( lsf, pred1, Tmp1, M ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[1] = vq_lvq_lsf_enc_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq, flag_1bit_gran ); +#else IF( flag_1bit_gran == 0 ) { Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, @@ -748,6 +811,7 @@ void lsf_end_enc_fx( { Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); } +#endif safety_net = 0; move16(); @@ -819,6 +883,9 @@ void lsf_end_enc_fx( ELSE { /* Switched Safety-Net/AR prediction */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[0] = vq_lvq_lsf_enc_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq, flag_1bit_gran ); +#else IF( flag_1bit_gran == 0 ) { Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); @@ -827,11 +894,15 @@ void lsf_end_enc_fx( { Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); } +#endif /* Predictive quantizer is calculated only if it can be selected */ test(); IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[1] = vq_lvq_lsf_enc_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M], flag_1bit_gran ); +#else IF( flag_1bit_gran == 0 ) { Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, @@ -841,6 +912,7 @@ void lsf_end_enc_fx( { Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); } +#endif } test(); @@ -902,7 +974,12 @@ void lsf_end_enc_fx( /* use G AR pred for the intra mode (as a safety mode, this is why the indexes 0/1 are interchanged)*/ lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages1, &stages0, levels1, levels0, bits1, bits0 ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[0] = vq_lvq_lsf_enc_fx( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M], flag_1bit_gran ); +#else Err[0] = vq_lvq_lsf_enc_ivas_fx( 2, 9, Tmp2, levels0, stages0, wghts, Idx0, lsf, pred3, &resq[M], &lsfq[M] ); +#endif + IF( force_sf ) { safety_net = 1; /* intra-frame prediction */ @@ -913,7 +990,13 @@ void lsf_end_enc_fx( /* AR inter-frame prediction */ lsf_allocate_fx( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + Err[1] = vq_lvq_lsf_enc_fx( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq, flag_1bit_gran ); +#else Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); +#endif + IF( LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) ) { safety_net = 1; @@ -1137,12 +1220,19 @@ void lsf_end_enc_fx( IF( EQ_16( st->tdm_LRTD_flag, 0 ) && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages0, M, 9, levels0[stages0 - 1] ); +#else vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages0, M, 9, levels0[stages0 - 1] ); +#endif Vr_add( qlsf, pred3, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } ELSE { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); +#else IF( flag_1bit_gran == 0 ) { vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], @@ -1153,7 +1243,7 @@ void lsf_end_enc_fx( { vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); } - +#endif Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -1161,6 +1251,7 @@ void lsf_end_enc_fx( } ELSE { + test(); test(); IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) { @@ -1171,6 +1262,9 @@ void lsf_end_enc_fx( ELSE { /* LVQ */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); +#else IF( flag_1bit_gran == 0 ) { vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], @@ -1181,6 +1275,7 @@ void lsf_end_enc_fx( { vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); } +#endif IF( EQ_16( predmode, 1 ) ) { @@ -1214,6 +1309,381 @@ void lsf_end_enc_fx( * *-------------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static void first_VQstages_fx( + const Word16 *const *cb, + const Word16 u[], /* i : vector to be encoded (prediction and mean removed) */ + const Word16 *levels, /* i : number of levels in each stage */ + const Word16 stagesVQ, /* i : number of stages */ + const Word16 w[], /* i : weights */ + const Word16 N, /* i : vector dimension */ + const Word16 max_inner, /* i : maximum number of swaps in inner loop */ + Word16 indices_VQstage[] ) +{ + Word16 resid_buf[2 * LSFMBEST * M], *resid[2]; + Word32 dist_buf[2 * LSFMBEST], *dist[2], en; + Word32 f_tmp, L_tmp, L_tmp1, *pTmp32; + Word16 Tmp[M], *pTmp, cs; + Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j, m, s, c, c2, p_max, *indices[2]; + Word16 maxC = LSFMBEST; + /*float dd[16];*/ + const Word16 *cb_stage, *cbp; + + /* Set pointers to previous (parent) and current node (parent node is indexed [0], current node is indexed [1]) */ + indices[0] = idx_buf; + move16(); + indices[1] = idx_buf + maxC * stagesVQ; + move16(); + resid[0] = resid_buf; + move16(); + resid[1] = resid_buf + maxC * N; + move16(); + dist[0] = dist_buf; + move16(); + dist[1] = dist_buf + maxC; + move16(); + + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( parents, 0, maxC ); + + /* Set up inital distance vector */ + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < N; j++ ) + { + L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */ + L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ + } + + set32_fx( dist[1], L_shr( L_tmp, 1 ), maxC ); /*Q-1 + x2.56 +x2.56 */ + + /* Set up initial error (residual) vectors */ + pTmp = resid[1]; + move16(); + FOR( c = 0; c < maxC; c++ ) + { + Copy( u, pTmp, N ); + pTmp += N; + } + + /*----------------------------------------------------------------* + * LSF quantization + *----------------------------------------------------------------*/ + + /* Loop over all stages */ + m = 1; + move16(); + FOR( s = 0; s < stagesVQ; s++ ) + { + /* set codebook pointer to point to first stage */ + cbp = cb[s]; + move16(); + + /* save pointer to the beginning of the current stage */ + cb_stage = cbp; + move16(); + + /* swap pointers to parent and current nodes */ + pTmp_short = indices[0]; + indices[0] = indices[1]; + move16(); + indices[1] = pTmp_short; + move16(); + + pTmp = resid[0]; + resid[0] = resid[1]; + move16(); + resid[1] = pTmp; + move16(); + + pTmp32 = dist[0]; + dist[0] = dist[1]; + move32(); + dist[1] = pTmp32; + move32(); + + /* p_max points to maximum distortion node (worst of best) */ + p_max = 0; + move16(); + + /* set distortions to a large value */ + set32_fx( dist[1], MAXINT32, maxC ); + + FOR( j = 0; j < levels[s]; j++ ) + { + /* compute weighted codebook element and its energy */ + FOR( c2 = 0; c2 < N; c2++ ) + { + Tmp[c2] = extract_h( L_shl( L_mult0( w[c2], cbp[c2] ), 6 ) ); /* Q8 + x2.56 + q6 -q16 */ + move16(); + } + + en = L_mult( cbp[0], Tmp[0] ); /*x2.56 + x2.56 + Q-2 +Q1 */ + + FOR( c2 = 1; c2 < N; c2++ ) + { + en = L_mac( en, cbp[c2], Tmp[c2] ); /*x2.56 + x2.56 + Q-2 +Q1 */ + } + cbp += N; + move16(); + + /* iterate over all parent nodes */ + FOR( c = 0; c < m; c++ ) + { + pTmp = &resid[0][c * N]; /*x2.56*/ + move16(); + L_tmp = L_mult( pTmp[0], Tmp[0] ); /*x2.56 + x2.56 + Q-2 +Q1 */ + FOR( c2 = 1; c2 < N; c2++ ) + { + L_tmp = L_mac( L_tmp, pTmp[c2], Tmp[c2] ); /*x2.56 + x2.56 + Q-2 +Q1 */ + } + + L_tmp = L_add( dist[0][c], L_sub( en, L_shl( L_tmp, 1 ) ) ); /*x2.56 + x2.56 -1*/ + + IF( LE_32( L_tmp, dist[1][p_max] ) ) + { + /* replace worst */ + dist[1][p_max] = L_tmp; + move32(); + indices[1][p_max * stagesVQ + s] = j; + move16(); + parents[p_max] = c; + move16(); + + /* limit number of times inner loop is entered */ + IF( LT_16( counter, max_inner ) ) + { + counter = add( counter, 1 ); + IF( LT_16( counter, max_inner ) ) + { + /* find new worst */ + p_max = maximum_32_fx( dist[1], maxC, &f_tmp ); + } + ELSE + { + /* find minimum distortion */ + p_max = minimum_32_fx( dist[1], maxC, &f_tmp ); + } + } + } + } + } + + /*------------------------------------------------------------* + * Compute error vectors for each node + *------------------------------------------------------------*/ + + cs = 0; + move16(); + FOR( c = 0; c < maxC; c++ ) + { + /* subtract codebook entry from the residual vector of the parent node */ + pTmp = resid[1] + c * N; + move16(); + Copy( resid[0] + parents[c] * N, pTmp, N ); + Vr_subt( pTmp, cb_stage + ( indices[1][cs + s] ) * N, pTmp, N ); + + /* get indices that were used for parent node */ + Copy( indices[0] + parents[c] * stagesVQ, indices[1] + cs, s ); + cs = add( cs, stagesVQ ); + } + + m = maxC; + move16(); + } + + Copy( indices[1], indices_VQstage, maxC * stagesVQ ); + + return; +} + +static void first_VQstages_evs_fx( + const Word16 *const *cb, + const Word16 u[], /* i : vector to be encoded (prediction and mean removed) x2.56*/ + const Word16 *levels, /* i : number of levels in each stage */ + const Word16 stagesVQ, /* i : number of stages */ + const Word16 w[], /* i : weights Q8*/ + const Word16 N, /* i : vector dimension */ + const Word16 max_inner, /* i : maximum number of swaps in inner loop */ + Word16 indices_VQstage[] ) +{ + Word16 resid_buf[2 * LSFMBEST * M], *resid[2]; + Word32 dist_buf[2 * LSFMBEST], *dist[2], en; + Word32 f_tmp, L_tmp, L_tmp1, *pTmp32; + Word16 Tmp[M], *pTmp, cs; + Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j, + m, s, c, c2, p_max, *indices[2]; + Word16 maxC = LSFMBEST; + /*float dd[16];*/ + const Word16 *cb_stage, *cbp; + + /* Set pointers to previous (parent) and current node (parent node is indexed [0], current node is indexed [1]) */ + indices[0] = idx_buf; + move16(); + indices[1] = idx_buf + maxC * stagesVQ; + move16(); + resid[0] = resid_buf; + move16(); + resid[1] = resid_buf + maxC * N; + move16(); + dist[0] = dist_buf; + move16(); + dist[1] = dist_buf + maxC; + move16(); + + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( parents, 0, maxC ); + + /* Set up inital distance vector */ + L_tmp = L_deposit_l( 0 ); + FOR( j = 0; j < N; j++ ) + { + L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */ + L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ + } + set32_fx( dist[1], L_tmp, maxC ); + + /* Set up initial error (residual) vectors */ + pTmp = resid[1]; + move16(); + FOR( c = 0; c < maxC; c++ ) + { + Copy( u, pTmp, N ); + pTmp += N; + } + + /*----------------------------------------------------------------* + * LSF quantization + *----------------------------------------------------------------*/ + + /* Loop over all stages */ + m = 1; + move16(); + FOR( s = 0; s < stagesVQ; s++ ) + { + /* set codebook pointer to point to first stage */ + cbp = cb[s]; + move16(); + + /* save pointer to the beginning of the current stage */ + cb_stage = cbp; + move16(); + + /* swap pointers to parent and current nodes */ + pTmp_short = indices[0]; + indices[0] = indices[1]; + move16(); + indices[1] = pTmp_short; + move16(); + + pTmp = resid[0]; + resid[0] = resid[1]; + move16(); + resid[1] = pTmp; + move16(); + + pTmp32 = dist[0]; + dist[0] = dist[1]; + move32(); + dist[1] = pTmp32; + move32(); + + /* p_max points to maximum distortion node (worst of best) */ + p_max = 0; + move16(); + + /* set distortions to a large value */ + set32_fx( dist[1], MAXINT32, maxC ); + + FOR( j = 0; j < levels[s]; j++ ) + { + /* compute weighted codebook element and its energy */ + FOR( c2 = 0; c2 < N; c2++ ) + { + Tmp[c2] = shl( mult( w[c2], cbp[c2] ), 2 ); /* Q8 + x2.56 -Q15 +Q2 */ + move16(); + } + + en = L_mult( cbp[0], Tmp[0] ); + + FOR( c2 = 1; c2 < N; c2++ ) + { + en = L_mac( en, cbp[c2], Tmp[c2] ); /*x2.56 + x2.56 + Q-5 +Q1 */ + } + cbp += N; + move16(); + + /* iterate over all parent nodes */ + FOR( c = 0; c < m; c++ ) + { + pTmp = &resid[0][c * N]; + move16(); + L_tmp = L_mult( pTmp[0], Tmp[0] ); + FOR( c2 = 1; c2 < N; c2++ ) + { + L_tmp = L_mac( L_tmp, pTmp[c2], Tmp[c2] ); /* */ + } + + L_tmp = L_add( dist[0][c], L_sub( en, L_shl( L_tmp, 1 ) ) ); + + IF( LE_32( L_tmp, dist[1][p_max] ) ) + { + /* replace worst */ + dist[1][p_max] = L_tmp; + move32(); + indices[1][p_max * stagesVQ + s] = j; + move16(); + parents[p_max] = c; + move16(); + + /* limit number of times inner loop is entered */ + IF( LT_16( counter, max_inner ) ) + { + counter = add( counter, 1 ); + IF( LT_16( counter, max_inner ) ) + { + /* find new worst */ + p_max = maximum_32_fx( dist[1], maxC, &f_tmp ); + } + ELSE + { + /* find minimum distortion */ + p_max = minimum_32_fx( dist[1], maxC, &f_tmp ); + } + } + } + } + } + + /*------------------------------------------------------------* + * Compute error vectors for each node + *------------------------------------------------------------*/ + + cs = 0; + move16(); + FOR( c = 0; c < maxC; c++ ) + { + /* subtract codebook entry from the residual vector of the parent node */ + pTmp = resid[1] + c * N; + move16(); + Copy( resid[0] + parents[c] * N, pTmp, N ); + Vr_subt( pTmp, cb_stage + ( indices[1][cs + s] ) * N, pTmp, N ); + + /* get indices that were used for parent node */ + Copy( indices[0] + parents[c] * stagesVQ, indices[1] + cs, s ); + cs = add( cs, stagesVQ ); + } + + m = maxC; + move16(); + } + + Copy( indices[1], indices_VQstage, maxC * stagesVQ ); + + return; +} +#else static void first_VQstages( const Word16 *const *cb, Word16 u[], /* i : vector to be encoded (prediction and mean removed) x2.56*/ @@ -1590,6 +2060,7 @@ static void first_VQstages_ivas_fx( return; } +#endif /*--------------------------------------------------------------------------- @@ -1606,6 +2077,144 @@ static void first_VQstages_ivas_fx( * Weighted error *--------------------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static Word32 vq_lvq_lsf_enc_fx( + const Word16 pred_flag, + const Word16 mode, + const Word16 u[], // x2.56 + const Word16 *levels, + const Word16 stages, + const Word16 w[], // Q8 + Word16 Idx[], + const Word16 *lsf, + const Word16 *pred, + Word16 *resq, + Word16 *lsfq, + const Word16 flag_1bit_gran ) +{ + Word16 i; + const Word16 *const *cb, *cb_stage; + Word16 cand[LSFMBEST][M]; + Word16 maxC = LSFMBEST, stagesVQ; + Word16 mode_glb, j, indices_firstVQ[LSFMBEST * MAX_VQ_STAGES], c2; + Word32 e[LSFMBEST], L_tmp, L_ftmp; + Word16 quant[LSFMBEST][M], diff[M], dd[M]; + Word16 lat_cv[LSFMBEST][M]; + Word16 idx_lead[LSFMBEST][2], idx_scale[LSFMBEST][2]; + + stagesVQ = sub( stages, 1 ); + /* Codebook selection */ + IF( pred_flag == 0 ) /* safety net*/ + { + cb = &Quantizers_fx[CB_lsf[mode]]; + move16(); + IF( LT_16( mode, 6 ) ) + { + mode_glb = add( offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][( levels[stagesVQ] - min_lat_bits_SN_fx[mode] )] ); + } + ELSE + { + mode_glb = add( offset_lvq_modes_SN_fx[mode], levels[stagesVQ] - min_lat_bits_SN_fx[mode] ); + } + } + ELSE /* predictive */ + { + cb = &Quantizers_p_fx[CB_p_lsf[mode]]; + IF( LT_16( mode, 6 ) || EQ_16( mode, 12 ) ) + { + move16(); + mode_glb = add( offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][( levels[stagesVQ] - min_lat_bits_pred_fx[mode] )] ); + } + ELSE + { + move16(); + mode_glb = sub( add( offset_lvq_modes_pred_fx[mode], levels[stagesVQ] ), min_lat_bits_pred_fx[mode] ); + } + } + + IF( stagesVQ > 0 ) + { + /* first VQ stages */ + IF( flag_1bit_gran == 0 ) + { + first_VQstages_evs_fx( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); + } + ELSE + { + first_VQstages_fx( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); + } + } + + FOR( i = 0; i < maxC; i++ ) + { + Copy( pred, cand[i], M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[i * stagesVQ + j]; + move16(); + } + + FOR( j = 0; j < stagesVQ; j++ ) + { + cb_stage = cb[j]; + move16(); + Vr_add( cand[i], cb_stage + Idx[j] * M, cand[i], M ); + } + + /* LVQ quantization */ + Vr_subt( lsf, cand[i], dd, M ); + + mslvq_fx( dd, quant[i], lat_cv[i], idx_lead[i], idx_scale[i], w, mode, mode_glb, pred_flag ); + + Vr_add( cand[i], quant[i], cand[i], M ); + + /* arrange the LSF candidate vector prior to selection to an ascending order*/ + sort_fx( cand[i], 0, M - 1 ); + + /* calculate the spectral distortion using weighted MSE of sorted LSF vector*/ + Vr_subt( cand[i], lsf, diff, M ); + FOR( j = 0; j < M; j++ ) + { + diff[j] = shl_sat( diff[j], 4 ); + move16(); + } + L_tmp = L_mult( mult( diff[0], shl_sat( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ + IF( flag_1bit_gran == 0 ) + { + FOR( j = 1; j < M; j++ ) + { + L_tmp = L_mac( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ + } + } + ELSE + { + FOR( j = 1; j < M; j++ ) + { + L_tmp = L_mac_sat( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ + } + } + e[i] = L_tmp; + move32(); + } + + /* find the optimal candidate */ + c2 = minimum_32_fx( e, maxC, &L_ftmp ); + set16_fx( resq, 0, M ); + FOR( j = 0; j < stagesVQ; j++ ) + { + Idx[j] = indices_firstVQ[c2 * stagesVQ + j]; + move16(); + cb_stage = cb[j]; + move16(); + Vr_add( resq, cb_stage + Idx[j] * M, resq, M ); + } + Vr_add( resq, quant[c2], resq, M ); /* quantized prediction residual */ + Copy( cand[c2], lsfq, M ); + index_lvq_fx( lat_cv[c2], idx_lead[c2], idx_scale[c2], mode_glb, &Idx[stagesVQ], pred_flag ); + + return e[c2]; +} +#else static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, @@ -1828,7 +2437,7 @@ static Word32 vq_lvq_lsf_enc_ivas_fx( return e[c2]; } - +#endif static void BcTcvq_1st_fx( Word16 x_fx[][2], /*x2.56*/ diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index ab7122ad2ac932945bae5cad4f5b0b24d5628563..8b6d3ce7ff633783aeef639c52c32e1e1fd2b5c9 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -6,9 +6,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" #include "rom_com.h" -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ -#include "basop32.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -16,18 +14,23 @@ * Local functions *-----------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, const Word16 *no_lead ); +static Word32 q_data_fx( Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, const Word16 *p_no_lead ); +#else static Word32 quantize_data_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, Word16 no_scales, const Word16 *no_lead ); Word32 quantize_data_ivas_fx( Word16 *data, const Word16 *w_in, Word16 *qin, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *sigma, const Word16 *inv_sigma, const Word16 *scales, const Word16 *no_lead ); static Word32 q_data_fx( Word16 *pTmp1, const Word16 *w1, Word16 *quant, Word16 *cv_out, Word16 *idx_lead, Word16 *idx_scale, const Word16 *p_sigma, const Word16 *p_inv_sigma, const Word16 *p_scales, Word16 *p_no_scales, const Word16 *p_no_lead ); +#endif static void prepare_data_fx( Word16 *xsort, Word16 *sign, Word16 *data, Word32 *w, const Word16 *w_in, const Word16 *sigma, const Word16 *inv_sigma, Word16 *p_sig ); -static Word32 calculate_min_dist_fx( Word16 cv_pot[LATTICE_DIM], Word16 no_scales, const Word16 *scale, const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, Word16 sig, Word16 *indx ); -static Word16 find_pos_fx( Word16 *c, Word16 len, Word16 arg, Word16 *p ); -static void take_out_val_fx( Word16 *v, Word16 *v_out, Word16 val, Word16 len ); -static Word16 index_leaders_fx( Word16 *cv, Word16 idx_lead, Word16 dim ); -static Word16 c2idx_fx( Word16 n, Word16 *p, Word16 k ); -static Word16 encode_sign_pc1_fx( Word16 parity, Word16 *cv ); -Word32 encode_comb_fx( Word16 *cv, Word16 idx_lead ); -static void sort_desc_ind_fx( Word16 *s, Word16 len, Word16 *ind ); +static Word32 calculate_min_dist_fx( const Word16 cv_pot[LATTICE_DIM], const Word16 no_scales, const Word16 *scale, const Word32 *w, Word16 *p_best_scale, Word16 *p_best_idx, const Word16 *no_leaders, const Word16 sig, const Word16 *indx ); +static Word16 find_pos_fx( const Word16 *c, const Word16 len, const Word16 arg, Word16 *p ); +static void take_out_val_fx( const Word16 *v, Word16 *v_out, const Word16 val, const Word16 len ); +static Word16 index_leaders_fx( const Word16 *cv, const Word16 idx_lead, const Word16 dim ); +static Word16 c2idx_fx( const Word16 n, Word16 *p, const Word16 k ); +static Word16 encode_sign_pc1_fx( const Word16 parity, const Word16 *cv ); +static Word32 encode_comb_fx( Word16 *cv, const Word16 idx_lead ); +static void sort_desc_ind_fx( Word16 *s, const Word16 len, Word16 *ind ); /*-----------------------------------------------------------------* @@ -35,6 +38,135 @@ static void sort_desc_ind_fx( Word16 *s, Word16 len, Word16 *ind ); * * Encodes the LSF residual *-----------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + +/*Returns dist in q 22*/ +Word32 mslvq_fx( + Word16 *pTmp, /* i : M-dimensional input vector */ + Word16 *quant, /* o : quantized vector */ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w, /* i : weights for LSF quantization */ + const Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + const Word16 mode_glb, /* i : LVQ coding mode */ + const Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ +) +{ + Word32 dist, L_tmp; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 i, tmp, tmp1; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + + dist = L_deposit_l( 0 ); + + IF( pred_flag == 0 ) + { + p_sigma = sigma_MSLVQ_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + p_scales = scales_fx[mode_glb]; + + tmp = no_lead_idx[mode_glb][0]; + move16(); + tmp1 = no_lead_idx[mode_glb][1]; + move16(); + + test(); + if ( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[tmp][i]; + move16(); + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; + move16(); + } + } + ELSE + { + IF( GE_16( pred_flag, 5 ) ) + { + /* assert( pred_flag >= 12 && pred_flag <= 15 ); */ + /* pred_flag is here the number of bits for MSLVQ */ + + p_sigma = &modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = &inv_modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; + IF( mode_glb == 0 ) + { + p_scales = &scales_BWE_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) no_lead_BWE[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; + move16(); + } + } + ELSE + { + p_scales = &scales_BWE_3b_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) no_lead_BWE_3b[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; + move16(); + } + } + } + ELSE + { + p_sigma = sigma_p_fx[mode]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_fx[mode]; + + p_scales = scales_p_fx[mode_glb]; + + tmp = no_lead_p_idx[mode_glb][0]; + move16(); + tmp1 = no_lead_p_idx[mode_glb][1]; + move16(); + + test(); + IF( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + + test(); + IF( EQ_16( tmp, LIMIT_LEADER ) && ( tmp1 == 0 ) ) + { + tmp = add( tmp, DELTA_LEADER ); + tmp1 = add( tmp1, DELTA_LEADER ); + } + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[tmp][i]; + move16(); + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; + move16(); + } + } + } + + /* first subvector */ + dist = quantize_data_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + + IF( LT_16( pred_flag, 5 ) ) + { + /* second subvector */ + L_tmp = quantize_data_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + } + + return dist; +} +#else Word32 mslvq_fx( Word16 *pTmp, /* i : M-dimensional input vector x2.56*/ Word16 *quant, /* o : quantized vector x2.56*/ @@ -87,8 +219,174 @@ Word32 mslvq_fx( return dist; } +/*-----------------------------------------------------------------* + * mslvq() + * + * Encodes the LSF residual + *-----------------------------------------------------------------*/ + +/*Return dist in q 22*/ +Word32 mslvq_ivas_16( + Word16 *pTmp, /* i : M-dimensional input vector */ + Word16 *quant, /* o : quantized vector */ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w, /* i : weights for LSF quantization */ + const Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + const Word16 mode_glb, /* i : LVQ coding mode */ + const Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ +) +{ + Word32 dist, L_tmp; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 i, tmp, tmp1; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + dist = L_deposit_l( 0 ); + IF( pred_flag == 0 ) + { + p_sigma = sigma_MSLVQ_fx[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; + p_scales = scales_ivas_fx[mode_glb]; + + tmp = no_lead_idx[mode_glb][0]; + move16(); + tmp1 = no_lead_idx[mode_glb][1]; + move16(); + test(); + if ( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[tmp][i]; + move16(); + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; + move16(); + } + } + ELSE + { + IF( GE_16( pred_flag, 5 ) ) + { + /* assert( pred_flag >= 12 && pred_flag <= 15 ); */ + /* pred_flag is here the number of bits for MSLVQ */ + + p_sigma = &modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = &inv_modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; + IF( mode_glb == 0 ) + { + p_scales = &scales_BWE_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) no_lead_BWE[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; + move16(); + } + } + ELSE + { + p_scales = &scales_BWE_3b_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) no_lead_BWE_3b[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; + move16(); + } + } + } + ELSE + { + p_sigma = sigma_p_ivas_fx[mode]; + + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p_ivas_fx[mode]; + + p_scales = scales_p_ivas_fx[mode_glb]; + + tmp = no_lead_p_idx[mode_glb][0]; + move16(); + tmp1 = no_lead_p_idx[mode_glb][1]; + move16(); + + test(); + IF( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) + { + tmp = add( tmp, DELTA_LEADER ); + } + + test(); + IF( EQ_16( tmp, LIMIT_LEADER ) && ( tmp1 == 0 ) ) + { + tmp = add( tmp, DELTA_LEADER ); + tmp1 = add( tmp1, DELTA_LEADER ); + } + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[tmp][i]; + move16(); + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; + move16(); + } + } + } + + /* first subvector */ + dist = quantize_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + + IF( LT_16( pred_flag, 5 ) ) + { + /* second subvector */ + L_tmp = quantize_data_ivas_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, p_no_lead + MAX_NO_SCALES ); + + dist = L_add( dist, L_tmp ); + } + + return dist; +} +#endif + + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * q_data() + * + * (used for LSF quantization in CNG) + *-----------------------------------------------------------------*/ + +static Word32 q_data_fx( + Word16 *pTmp1, /* i : M-dimensional input vector x2.56 */ + const Word16 *w1, /* i : M-dimensional weight vector Q8 */ + Word16 *quant, /* o : quantized vector x2.56 */ + Word16 *cv_out, /* o : non-scaled lattice codevector x2.56 */ + Word16 *idx_lead, /* o : leader indexes for each subvector */ + Word16 *idx_scale, /* o : scale indexes for each subvector */ + const Word16 *p_sigma, /* i : standard deviation x2.56 */ + const Word16 *p_inv_sigma, /* i : inverse standard deviation Q15 */ + const Word16 *p_scales, /* i : scale values Q11 */ + const Word16 *p_no_lead /* i : number of leaders for each truncation and each subvector */ +) +{ + Word32 dist, L_tmp; + /* first subvector */ + dist = quantize_data_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, + p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* second subvector */ + L_tmp = quantize_data_fx( pTmp1 + LATTICE_DIM, w1 + LATTICE_DIM, + quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, + p_no_lead + MAX_NO_SCALES ); + dist = L_add( dist, L_tmp ); + return dist; +} +#else /*-----------------------------------------------------------------* * q_data() * @@ -151,8 +449,98 @@ static Word32 q_data_ivas_fx( return dist; } +#endif + + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * mslvq_cng() + * + * Encodes the LSF residual in SID frames with LVQ + * LVQ has separate codebook for each individual first stage index + *-----------------------------------------------------------------*/ + +Word32 mslvq_cng_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +) +{ + Word32 dist; + const Word16 *p_scales, *p_sigma, *p_inv_sigma; + Word16 no_scales[2]; + Word16 mode_glb, mode, i; + Word16 pTmp1[M], w1[M]; + Word16 p_no_lead[MAX_NO_SCALES * 2]; + + dist = L_deposit_l( 0 ); + mode = add( LVQ_COD_MODES, idx_cv ); + move16(); + + /* for CNG there is only one bitrate but several lattice quantizer structures, + depending on the previous VQ stage */ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES_VE + mode_glb = add( START_CNG, idx_cv ); +#else + mode_glb = add( START_CNG_IVAS, idx_cv ); +#endif + move16(); + + p_sigma = sigma_MSLVQ_fx[mode]; // x2.56 + move16(); + p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; // Q15 + move16(); + p_scales = scales_fx[mode_glb]; // Q11 + move16(); + + no_scales[0] = 0; + no_scales[1] = 0; + + FOR( i = 0; i < MAX_NO_SCALES; i++ ) + { + p_no_lead[i] = (Word16) leaders_short[no_lead_idx[mode_glb][0]][i]; + p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[no_lead_idx[mode_glb][1]][i]; + + IF( p_scales[i] > 0 ) + { + no_scales[0] += 1; + } + IF( p_scales[i + MAX_NO_SCALES] > 0 ) + { + no_scales[1] += 1; + } + } + /* check if LSF component permutation is needed or not */ + IF( cng_sort[idx_cv] ) + { + FOR( i = 0; i < M; i++ ) + { + pTmp1[i] = pTmp[i]; + move16(); + w1[i] = w[i]; + move16(); + } + /* sorting the quantizer input and the corresponding weights according to the specified permutations */ + permute_fx( pTmp1, perm_MSLVQ[idx_cv] ); + permute_fx( w1, perm_MSLVQ[idx_cv] ); + dist = q_data_fx( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + /* permute back */ + permute_fx( quant, perm_MSLVQ[idx_cv] ); + } + ELSE + { + dist = q_data_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, p_sigma, p_inv_sigma, p_scales, p_no_lead ); + } + + return dist; +} +#else /*-----------------------------------------------------------------* * mslvq_cng() * @@ -300,7 +688,7 @@ Word32 mslvq_cng_ivas_fx( return dist; } - +#endif /*-----------------------------------------------------------------* * prepare_data_fx() @@ -369,18 +757,20 @@ return; *-----------------------------------------------------------------*/ static Word32 calculate_min_dist_fx( - Word16 cv_pot[LATTICE_DIM], /* i : sorted absolute valued normalized input vector Q10 */ - Word16 no_scales, /* i : number of scales */ - const Word16 *scale, /* i : scale values Q11 */ - const Word32 *w, /* i : scaled weights Q-4 */ - Word16 *p_best_scale, /* o : pointer to obtained scale value */ - Word16 *p_best_idx, /* o : pointer to obtained leader index */ - const Word16 *no_leaders, /* i : number of leaders for each truncation */ - Word16 sig, /* i : parity of input vector */ - Word16 *indx /* i : permutation vector indicating the order of the sorted input vector */ + const Word16 cv_pot[LATTICE_DIM], /* i : sorted absolute valued normalized input vector Q10 */ + const Word16 no_scales, /* i : number of scales */ + const Word16 *scale, /* i : scale values Q11 */ + const Word32 *w, /* i : scaled weights Q-4 */ + Word16 *p_best_scale, /* o : pointer to obtained scale value */ + Word16 *p_best_idx, /* o : pointer to obtained leader index */ + const Word16 *no_leaders, /* i : number of leaders for each truncation */ + const Word16 sig, /* i : parity of input vector */ + const Word16 *indx /* i : permutation vector indicating the order of the sorted input vector */ ) { Word16 k, l, j, best_scale = -1, best_idx = -1; + move16(); + move16(); Word16 s, p; Word32 tmp_dist, min_dist; Word32 w_norm[LATTICE_DIM]; @@ -390,9 +780,11 @@ static Word32 calculate_min_dist_fx( Word32 sum1[NO_LEADERS], sum2[NO_LEADERS]; Word16 s2, p1; Word16 low_prec = 0; + move16(); Word16 max_nb, nb, max_nb1; max_nb = 0; + move16(); FOR( l = 0; l < LATTICE_DIM; l++ ) { nb = sub( 31, norm_l( w[l] ) ); @@ -402,7 +794,9 @@ static Word32 calculate_min_dist_fx( move16(); } } + max_nb1 = 0; + move16(); FOR( l = 0; l < LATTICE_DIM; l++ ) { nb = sub( 15, norm_s( cv_pot[l] ) ); @@ -463,6 +857,7 @@ static Word32 calculate_min_dist_fx( move16(); } } + IF( EQ_16( l, LATTICE_DIM - 1 ) ) { p = *pl_crt; @@ -492,6 +887,7 @@ static Word32 calculate_min_dist_fx( pl_crt++; } } + /* distance between the potential codevector and the input calculated in ordered space */ tmp_dist = L_sub( Mult_32_16( sum2[j], s2 ), Mult_32_16( L_shl( sum1[j], 3 ), s ) ); /* Q(13-nb) + Q10 -Q15= Q(8-nb) Q(9-nb) + Q3+Q11 -Q15 = Q(8-nb) */ IF( LT_32( tmp_dist, min_dist ) ) @@ -503,6 +899,7 @@ static Word32 calculate_min_dist_fx( move16(); /* leader class index of potential codevector */ } } + tmp_dist = L_add( min_dist, 1 ); /* initialization */ FOR( k = 1; k < no_scales; k++ ) { @@ -517,38 +914,149 @@ static Word32 calculate_min_dist_fx( { s2 = extract_h( L_shl( L_mult( s, s ), 3 ) ); /*Q11+Q11++Q1+Q3-Q16 = Q10 */ } + FOR( j = 0; j < no_leaders[k]; j++ ) { - /* distance between the potential codevector and the input calculated in ordered space */ - IF( EQ_16( low_prec, 1 ) ) + /* distance between the potential codevector and the input calculated in ordered space */ + IF( EQ_16( low_prec, 1 ) ) + { + tmp_dist = L_sub( L_shl( Mult_32_16( sum2[j], s2 ), 2 ), Mult_32_16( L_shl( sum1[j], 3 ), s ) ); /* Q-1 + Q7 + 3-Q15= Q-6 Q-5 + Q3+Q11 -Q15 = Q-6 */ + } + ELSE + { + tmp_dist = L_sub( Mult_32_16( sum2[j], s2 ), Mult_32_16( L_shl( sum1[j], 3 ), s ) ); /* Q-1 + Q10 -Q15= Q-6 Q-5 + Q3+Q11 -Q15 = Q-6 */ + } + + IF( LT_32( tmp_dist, min_dist ) ) + { + min_dist = L_add( tmp_dist, 0 ); + best_scale = k; + move16(); /* scale(truncation) index of the potential codevector */ + best_idx = j; + move16(); /* leader class index of the potential codevector */ + } + } + + low_prec = 0; + move16(); + } + + *p_best_scale = best_scale; + move16(); + *p_best_idx = best_idx; + move16(); + + return min_dist; +} + +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +/*-----------------------------------------------------------------* + * quantize_data() + * + *-----------------------------------------------------------------*/ + +static Word32 quantize_data_fx( + Word16 *data, /* i : residual LSF data to quantize x2.56*/ + const Word16 *w_in, /* i : weights Q10*/ + Word16 *qin, /* o : quantized output (scaled) x2.56*/ + Word16 *cv_out, /* o : codevectors Q1*/ + Word16 *idx_lead, /* o : leader indexes for each subvector */ + Word16 *idx_scale, /* o : scale indexes for each subvector */ + const Word16 *sigma, /* i : standard deviation x2.56 */ + const Word16 *inv_sigma, /* i : inverse of standard deviation Q15 */ + const Word16 *scale, /* i : scales for each truncation Q11*/ + const Word16 *no_leaders /* i : number of leader vectors for each truncation of each subvector */ +) +{ + Word16 j; + Word32 w[LATTICE_DIM]; + Word32 min_dist = 0; + Word16 best_idx = 0, best_scale = -1; + Word16 s; + Word16 indx[LATTICE_DIM]; + Word16 sig, sign[LATTICE_DIM]; + Word16 cv_pot[LATTICE_DIM]; + Word16 id[8]; + Word16 smallest; + Word32 L_tmp; + + IF( scale[0] > 0 ) + { + prepare_data_fx( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); + move16(); + /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ + sort_desc_ind_fx( cv_pot, LATTICE_DIM, indx ); + smallest = indx[LATTICE_DIM - 1]; + move16(); + + min_dist = calculate_min_dist_fx( cv_pot, MAX_NO_SCALES, scale, w, &best_scale, &best_idx, no_leaders, sig, indx ); + + IF( GT_16( best_scale, -1 ) ) + { + FOR( j = 0; j < LATTICE_DIM; j++ ) { - tmp_dist = L_sub( L_shl( Mult_32_16( sum2[j], s2 ), 2 ), Mult_32_16( L_shl( sum1[j], 3 ), s ) ); /* Q-1 + Q7 + 3-Q15= Q-6 Q-5 + Q3+Q11 -Q15 = Q-6 */ + id[indx[j]] = j; } - ELSE + FOR( j = 0; j < LATTICE_DIM; j++ ) { - tmp_dist = L_sub( Mult_32_16( sum2[j], s2 ), Mult_32_16( L_shl( sum1[j], 3 ), s ) ); /* Q-1 + Q10 -Q15= Q-6 Q-5 + Q3+Q11 -Q15 = Q-6 */ + cv_out[j] = i_mult2( sign[j], pl_HQ_fx[best_idx * LATTICE_DIM + id[j]] ); + move16(); } - IF( LT_32( tmp_dist, min_dist ) ) + IF( pl_par[best_idx] ) { - min_dist = L_add( tmp_dist, 0 ); - best_scale = k; - move16(); /* scale(truncation) index of the potential codevector */ - best_idx = j; - move16(); /* leader class index of the potential codevector */ + IF( NE_16( sig, pl_par[best_idx] ) ) + { + cv_out[smallest] = negate( cv_out[smallest] ); + } + } + s = scale[best_scale]; + move16(); /*Q11 */ + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + /*qin[j] = s * cv_out[j] * sigma[j]; */ + L_tmp = L_mult( cv_out[j], s ); /* Q1+Q11+Q1 = Q13 */ + L_tmp = Mult_32_16( L_tmp, shl( sigma[j], 2 ) ); /* Q13 + Q2 +x2.56 -Q15 */ + + qin[j] = extract_l( L_tmp ); /*x2.56 */ } + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); } - low_prec = 0; + ELSE + { + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + qin[j] = 0; + move16(); + } + + *idx_lead = best_idx; + move16(); + *idx_scale = best_scale; + move16(); + } + } + ELSE + { + *idx_lead = 0; + move16(); + *idx_scale = -1; move16(); + + FOR( j = 0; j < LATTICE_DIM; j++ ) + { + cv_out[j] = 0; + move16(); + qin[j] = 0; + move16(); + } } - *p_best_scale = best_scale; - move16(); - *p_best_idx = best_idx; - move16(); return min_dist; } - - +#else /*-----------------------------------------------------------------* * quantize_data_fx() * @@ -758,6 +1266,9 @@ Word32 quantize_data_ivas_fx( return min_dist; } +#endif + + /*-----------------------------------------------------------------* * sort_desc_ind() * @@ -765,9 +1276,9 @@ Word32 quantize_data_ivas_fx( *-----------------------------------------------------------------*/ static void sort_desc_ind_fx( - Word16 *s, /* i/o: vector to be sorted Q10*/ - Word16 len, /* i : vector length */ - Word16 *ind /* o : array of indices */ + Word16 *s, /* i/o: vector to be sorted Q10*/ + const Word16 len, /* i : vector length */ + Word16 *ind /* o : array of indices */ ) { Word16 i, k, sorted, a; @@ -819,6 +1330,54 @@ static void sort_desc_ind_fx( * sorts in descending order and computes indices in the sorted vector *-----------------------------------------------------------------*/ +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +void index_lvq_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i : scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ) +{ + Word32 index1, index2; + UWord32 offset_scale1[MAX_NO_SCALES + 1], offset_scale2[MAX_NO_SCALES + 1]; + Word64 idx64; + Word64 index2_64; + + index1 = 0; + move16(); + + create_offset_fx( offset_scale1, offset_scale2, mode, prediction_flag ); + + /* for first subvector */ + IF( GT_16( idx_scale[0], -1 ) ) + { + index1 = L_add( encode_comb_fx( quant, idx_lead[0] ), L_add( table_no_cv_fx[idx_lead[0]], offset_scale1[idx_scale[0]] ) ); + } + + /* for second subvector */ + index2 = L_deposit_l( 0 ); + + IF( GT_16( idx_scale[1], -1 ) ) + { + index2 = L_add( encode_comb_fx( &quant[LATTICE_DIM], idx_lead[1] ), L_add( table_no_cv_fx[idx_lead[1]], offset_scale2[idx_scale[1]] ) ); + } + + idx64 = W_mult0_32_32( index1, offset_scale2[MAX_NO_SCALES] ); + index2_64 = W_deposit32_l( index2 ); + idx64 = W_add_nosat( idx64, index2_64 ); + + /* convert to 3 short */ + index[0] = ( ( idx64 ) & ( 0x7fff ) ); + move16(); + index[1] = ( W_shr( idx64, 15 ) ) & ( 0x7fff ); + move16(); + index[2] = ( W_shr( idx64, 30 ) ) & ( 0x7fff ); + move16(); + + return; +} +#else void index_lvq_fx( Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ Word16 *idx_lead, /* i : leader class index for each subvector */ @@ -915,6 +1474,7 @@ void index_lvq_ivas_fx( return; } +#endif /*-----------------------------------------------------------------* @@ -924,9 +1484,9 @@ void index_lvq_ivas_fx( *-----------------------------------------------------------------*/ /* o: index of the absolute valued codevector */ -Word32 encode_comb_fx( - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead /* i : leader class index, to know the values */ +static Word32 encode_comb_fx( + Word16 *cv, /* i : codevector to be indexed Q13*/ + const Word16 idx_lead /* i : leader class index, to know the values */ ) { Word16 idx_sign, idx_ld_class; @@ -942,6 +1502,7 @@ Word32 encode_comb_fx( return L_tmp; } + /*-----------------------------------------------------------------* * index_leaders() * @@ -950,9 +1511,9 @@ Word32 encode_comb_fx( /* o : index */ static Word16 index_leaders_fx( - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead, /* i : leader class index */ - Word16 dim /* i : vector dimension */ + const Word16 *cv, /* i : codevector to be indexed Q13*/ + const Word16 idx_lead, /* i : leader class index */ + const Word16 dim /* i : vector dimension */ ) { Word16 index; @@ -1013,6 +1574,7 @@ static Word16 index_leaders_fx( return index; } + /*-----------------------------------------------------------------* * find_pos() * @@ -1021,11 +1583,11 @@ static Word16 index_leaders_fx( *-----------------------------------------------------------------*/ /* o : number of positions */ -Word16 find_pos_fx( - Word16 *c, /* i : input vector Q13*/ - Word16 len, /* i : input vector dim */ - Word16 arg, /* i : argument to be compared with Q13*/ - Word16 *p /* o : vector of positions */ +static Word16 find_pos_fx( + const Word16 *c, /* i : input vector Q13*/ + const Word16 len, /* i : input vector dim */ + const Word16 arg, /* i : argument to be compared with Q13*/ + Word16 *p /* o : vector of positions */ ) { Word16 i = 0, j = 0; @@ -1054,8 +1616,8 @@ Word16 find_pos_fx( /* o : index of signs */ static Word16 encode_sign_pc1_fx( - Word16 parity, /* i : parity of the leader class to which the codevector belongs */ - Word16 *cv /* i : input codevector Q13*/ + const Word16 parity, /* i : parity of the leader class to which the codevector belongs */ + const Word16 *cv /* i : input codevector Q13*/ ) { Word16 idx_sign; @@ -1096,10 +1658,10 @@ static Word16 encode_sign_pc1_fx( *-----------------------------------------------------------------*/ static void take_out_val_fx( - Word16 *v, /* i : input vector x2.56*/ - Word16 *v_out, /* o : output vector without the value val */ - Word16 val, /* i : value to be removed x2.56*/ - Word16 len /* i : input vector length */ + const Word16 *v, /* i : input vector x2.56*/ + Word16 *v_out, /* o : output vector without the value val */ + const Word16 val, /* i : value to be removed x2.56*/ + const Word16 len /* i : input vector length */ ) { Word16 i, cnt; @@ -1127,10 +1689,10 @@ static void take_out_val_fx( *-----------------------------------------------------------------------*/ /* o: index */ -Word16 c2idx_fx( - Word16 n, /* i : vector lenght */ - Word16 *p, /* i : non null value positions */ - Word16 k /* i : non-nullnumber of values */ +static Word16 c2idx_fx( + const Word16 n, /* i : vector lenght */ + Word16 *p, /* i : non null value positions */ + const Word16 k /* i : non-nullnumber of values */ ) { Word16 skip, i, p0; @@ -1161,138 +1723,13 @@ Word16 c2idx_fx( } } + /*-----------------------------------------------------------------* - * mslvq() + * deindex_lvq_SHB() + * * - * Encodes the LSF residual *-----------------------------------------------------------------*/ -/*Return dist in q 22*/ -Word32 mslvq_ivas_16( - Word16 *pTmp, /* i : M-dimensional input vector */ - Word16 *quant, /* o : quantized vector */ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - const Word16 *w, /* i : weights for LSF quantization */ - const Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ - const Word16 mode_glb, /* i : LVQ coding mode */ - const Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ -) -{ - Word32 dist, L_tmp; - const Word16 *p_scales, *p_sigma, *p_inv_sigma; - Word16 i, tmp, tmp1; - Word16 p_no_lead[MAX_NO_SCALES * 2]; - dist = L_deposit_l( 0 ); - IF( pred_flag == 0 ) - { - p_sigma = sigma_MSLVQ_fx[mode]; - /* inverse sigma is precomputed to save complexity */ - p_inv_sigma = inv_sigma_MSLVQ_fx[mode]; - p_scales = scales_ivas_fx[mode_glb]; - - tmp = no_lead_idx[mode_glb][0]; - move16(); - tmp1 = no_lead_idx[mode_glb][1]; - move16(); - test(); - if ( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) - { - tmp = add( tmp, DELTA_LEADER ); - } - FOR( i = 0; i < MAX_NO_SCALES; i++ ) - { - p_no_lead[i] = (Word16) leaders_short[tmp][i]; - move16(); - p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; - move16(); - } - } - ELSE - { - IF( GE_16( pred_flag, 5 ) ) - { - /* assert( pred_flag >= 12 && pred_flag <= 15 ); */ - /* pred_flag is here the number of bits for MSLVQ */ - - p_sigma = &modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; - - /* inverse sigma is precomputed to save complexity */ - p_inv_sigma = &inv_modified_sigma_BWE_fx[mode_glb * LATTICE_DIM]; - IF( mode_glb == 0 ) - { - p_scales = &scales_BWE_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; - - FOR( i = 0; i < MAX_NO_SCALES; i++ ) - { - p_no_lead[i] = (Word16) no_lead_BWE[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; - move16(); - } - } - ELSE - { - p_scales = &scales_BWE_3b_fx_new[i_mult( sub( pred_flag, mslvq_SHB_min_bits[mode_glb] ), 3 )]; - FOR( i = 0; i < MAX_NO_SCALES; i++ ) - { - p_no_lead[i] = (Word16) no_lead_BWE_3b[i + ( pred_flag - mslvq_SHB_min_bits[mode_glb] ) * 3]; - move16(); - } - } - } - ELSE - { - p_sigma = sigma_p_ivas_fx[mode]; - - /* inverse sigma is precomputed to save complexity */ - p_inv_sigma = inv_sigma_p_ivas_fx[mode]; - - p_scales = scales_p_ivas_fx[mode_glb]; - - tmp = no_lead_p_idx[mode_glb][0]; - move16(); - tmp1 = no_lead_p_idx[mode_glb][1]; - move16(); - - test(); - IF( LE_16( tmp, LIMIT_LEADER ) && LT_16( tmp, sub( tmp1, 2 ) ) ) - { - tmp = add( tmp, DELTA_LEADER ); - } - - test(); - IF( EQ_16( tmp, LIMIT_LEADER ) && ( tmp1 == 0 ) ) - { - tmp = add( tmp, DELTA_LEADER ); - tmp1 = add( tmp1, DELTA_LEADER ); - } - - FOR( i = 0; i < MAX_NO_SCALES; i++ ) - { - p_no_lead[i] = (Word16) leaders_short[tmp][i]; - move16(); - p_no_lead[i + MAX_NO_SCALES] = (Word16) leaders_short[tmp1][i]; - move16(); - } - } - } - - /* first subvector */ - dist = quantize_data_ivas_fx( pTmp, w, quant, cv_out, idx_lead, idx_scale, - p_sigma, p_inv_sigma, p_scales, p_no_lead ); - - IF( LT_16( pred_flag, 5 ) ) - { - /* second subvector */ - L_tmp = quantize_data_ivas_fx( pTmp + LATTICE_DIM, w + LATTICE_DIM, quant + LATTICE_DIM, cv_out + LATTICE_DIM, &idx_lead[1], &idx_scale[1], p_sigma + LATTICE_DIM, p_inv_sigma + LATTICE_DIM, p_scales + MAX_NO_SCALES, p_no_lead + MAX_NO_SCALES ); - - dist = L_add( dist, L_tmp ); - } - - return dist; -} - - UWord32 index_lvq_SHB_fx( const Word16 idx_lead, const Word16 idx_scale, @@ -1321,13 +1758,21 @@ UWord32 index_lvq_SHB_fx( move32(); FOR( i = 0; i < idx_scale; i++ ) { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + index = index + table_no_cv_fx[p_no_lead[i]]; +#else index = index + table_no_cv[p_no_lead[i]]; +#endif move32(); } IF( idx_lead > 0 ) { +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + index = index + table_no_cv_fx[idx_lead]; +#else index = index + table_no_cv[idx_lead]; +#endif move32(); } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 046f1521137ce63d5eebba1e83b235e10d516a32..780b4b147bc594d0bd93ce841a352c0c0876d576 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3635,7 +3635,17 @@ void FEC_lsf_estim_enc_fx( Encoder_State *st_fx, /* i : Encoder static memory */ Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/ ); - +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +Word32 mslvq_cng_fx( + Word16 idx_cv, /* i : index of cv from previous stage */ + Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ + Word16 *quant, /* o : quantized vector x2.56*/ + Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w /* i : weights for LSF quantization Q10*/ +); +#else Word32 mslvq_cng_fx( Word16 idx_cv, /* i : index of cv from previous stage */ Word16 *pTmp, /* i : 16 dimensional i vector x2.56*/ @@ -3655,7 +3665,7 @@ Word32 mslvq_cng_ivas_fx( Word16 *idx_scale, /* o : scale index for each subvector */ const Word16 *w /* i : weights for LSF quantization Q10*/ ); - +#endif void Unified_weighting_fx( const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, @@ -3675,7 +3685,19 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx( const Word16 nBits, /* i : number of bits */ Word16 safety_net /* i : safety_net flag */ ); - +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +Word32 mslvq_fx( + Word16 *pTmp_fx, /* i : M-dimensional input vector */ + Word16 *quant_fx, /* o : quantized vector */ + Word16 *cv_out_fx, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ + Word16 *idx_scale, /* o : scale index for each subvector */ + const Word16 *w_fx, /* i : weights for LSF quantization */ + const Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ + const Word16 mode_glb, /* i : LVQ coding mode */ + const Word16 pred_flag /* i : prediction flag (0: safety net, 1,2 - predictive )*/ +); +#else Word32 mslvq_fx( Word16 *pTmp, /* i : M-dimensional i vector */ Word16 *quant, /* o : quantized vector */ @@ -3687,7 +3709,7 @@ Word32 mslvq_fx( Word16 mode_glb, /* i : LVQ coding mode */ Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive ) */ Word16 no_scales[][2] ); - +#endif /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_fx( const Word16 element_mode, /* i : IVAS element_mode Q0 */ @@ -3839,6 +3861,15 @@ ivas_error ppp_quarter_encoder_fx( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES +void index_lvq_fx( + Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ + Word16 *idx_lead, /* i : leader class index for each subvector */ + Word16 *idx_scale, /* i : scale index for each subvector */ + Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ + Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + const Word16 prediction_flag ); +#else void index_lvq_fx( Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ Word16 *idx_lead, /* i : leader class index for each subvector */ @@ -3856,7 +3887,7 @@ void index_lvq_ivas_fx( Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ const Word16 prediction_flag ); - +#endif void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 1723edb3fdbb66112941fe71b62a6946a62b5892..591425e0c52a70c30d719b16e4ac3b2f3fbbba48 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1339,26 +1339,28 @@ typedef struct enc_core_structure LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 pstreaklen; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer Q15 */ - Word16 stab_fac_fx; /* LSF stability factor Q15 */ - Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 pstreaklen; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ + Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ +#ifndef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ +#endif Word16 mem_preemph_fx; /* preemphasis filter memory Q(-1) */ Word16 mem_q; /* preemphasis filter memory Q(-1) */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 5128ca77f790a27f9d03869a8ded9f16402dd1cb..b5817212606ee7b7dee058afb8cc1dcf7104ca99 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -5207,8 +5207,11 @@ static void LVQQuant_BWE_LSF_fx( Copy( cand_fx, quant_fx, LPC_SHB_ORDER ); v_sub_16( lsf_fx, cand_fx, dd_fx, LATTICE_DIM ); - +#ifdef FIX_2492_REMOVE_DUPLICATES_FOR_DECODE_INDEXES + mslvq_fx( dd_fx, quant_fx, cv_out_fx, &idx_lead, &idx_scale, w_fx, 0, ( nbits < 19 ), bits_lvq ); +#else mslvq_ivas_16( dd_fx, quant_fx, cv_out_fx, &idx_lead, &idx_scale, w_fx, 0, ( nbits < 19 ), bits_lvq ); +#endif IF( EQ_16( idx_scale, -1 ) ) {