diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index e9173e6e931619f4a1318119829a2dbc9d453bb0..95008d17f591a37b883dc49b8a38ac08039c380c 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1335,34 +1335,49 @@ typedef struct { unsigned short length[81]; } HUFF_ELEMENTS; +#ifdef FIX_891_PARAMUPMIX_CLEANUP +typedef struct { + HUFF_ELEMENTS df0; + HUFF_ELEMENTS df; +} HUFF_TABLE; +#else typedef struct { HUFF_ELEMENTS df0; HUFF_ELEMENTS df; HUFF_ELEMENTS dt; } HUFF_TABLE; +#endif typedef enum { ALPHA, BETA } PAR_TYPE; +#ifndef FIX_891_PARAMUPMIX_CLEANUP typedef enum { FINE, COARSE } QUANT_TYPE; +#endif typedef struct { int16_t nquant; int16_t offset; float data[35]; } ACPL_QUANT_TABLE; - +#ifdef FIX_891_PARAMUPMIX_CLEANUP +typedef struct +{ + const int16_t (*alpha)[2]; + const int16_t (*beta)[2]; +} HUFF_NODE_TABLE; +#else typedef struct { const int16_t (*alpha[2])[2]; const int16_t (*beta[2])[2]; } HUFF_NODE_TABLE; - +#endif /*----------------------------------------------------------------------------------* * Parametric MC Constants diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 50892fcf53e2ceea0c6a45e07c042494e79a1b0a..9727f39fddda2738e82ccd2d3099383b3d6a83a8 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2518,7 +2518,7 @@ const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_ 1, 1, 1, 2, 24, 69, 122, 194, 285, 487, 690, 1173, 2255, 4709, 10599, 24635, 10862, 4709, 2204, 1059, 566, 330, 221, 150, 95, 59, 28, 2, 1, 1, 1 }; - +#ifndef FIX_891_PARAMUPMIX_CLEANUP /*----------------------------------------------------------------------------------* * Parametric Upmix MC ROM tables *----------------------------------------------------------------------------------*/ @@ -2528,7 +2528,7 @@ const int16_t ivas_param_upmx_mx_qmap[2][33] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 } }; - +#endif /*----------------------------------------------------------------------------------* * MASA ROM tables @@ -6439,6 +6439,71 @@ const int16_t sns_1st_means_32k[2][16] = * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ +#ifdef FIX_891_PARAMUPMIX_CLEANUP +const int16_t ivas_param_upmx_mx_qmap[33] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 +}; + +const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table = +{ + 33, /* nquant */ + 16, /* offset */ + { -2.000000e+000f, -1.809375e+000f, -1.637500e+000f, -1.484375e+000f, -1.350000e+000f, -1.234375e+000f, -1.137500e+000f, -1.059375e+000f, -1.000000e+000f, -9.406250e-001f, + -8.625000e-001f, -7.656250e-001f, -6.500000e-001f, -5.156250e-001f, -3.625000e-001f, -1.906250e-001f, +0.000000e+000f, +1.906250e-001f, +3.625000e-001f, +5.156250e-001f, + +6.500000e-001f, +7.656250e-001f, +8.625000e-001f, +9.406250e-001f, +1.000000e+000f, +1.059375e+000f, +1.137500e+000f, +1.234375e+000f, +1.350000e+000f, +1.484375e+000f, + +1.637500e+000f, +1.809375e+000f, +2.000000e+000f } /* data */ +}; + +const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9] = +{ + { + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +2.375000e-001f, +5.500000e-001f, +9.375000e-001f, +1.400000e+000f, +1.937500e+000f, +2.550000e+000f, +3.237500e+000f, +4.000000e+000f } /* data */ + }, + { /* Beta #2 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +2.035449e-001f, +4.713672e-001f, +8.034668e-001f, +1.199844e+000f, +1.660498e+000f, +2.185430e+000f, +2.774639e+000f, +3.428125e+000f } /* data */ + }, + { /* Beta #3 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +1.729297e-001f, +4.004688e-001f, +6.826172e-001f, +1.019375e+000f, +1.410742e+000f, +1.856719e+000f, +2.357305e+000f, +2.912500e+000f } /* data */ + }, + { /* Beta #4 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +1.456543e-001f, +3.373047e-001f, +5.749512e-001f, +8.585938e-001f, +1.188232e+000f, +1.563867e+000f, +1.985498e+000f, +2.453125e+000f } /* data */ + }, + { /* Beta #5 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +1.217188e-001f, +2.818750e-001f, +4.804688e-001f, +7.175000e-001f, +9.929688e-001f, +1.306875e+000f, +1.659219e+000f, +2.050000e+000f } /* data */ + }, + { /* Beta #6 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +1.011230e-001f, +2.341797e-001f, +3.991699e-001f, +5.960938e-001f, +8.249512e-001f, +1.085742e+000f, +1.378467e+000f, +1.703125e+000f } /* data */ + }, + { /* Beta #7 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +8.386719e-002f, +1.942188e-001f, +3.310547e-001f, +4.943750e-001f, +6.841797e-001f, +9.004688e-001f, +1.143242e+000f, +1.412500e+000f } /* data */ + }, + { /* Beta #8 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +6.995117e-002f, +1.619922e-001f, +2.761230e-001f, +4.123438e-001f, +5.706543e-001f, +7.510547e-001f, +9.535449e-001f, +1.178125e+000f } /* data */ + }, + { /* Beta #9 */ + 9, /* nquant */ + 0, /* offset */ + { +0.000000e+000f, +5.937500e-002f, +1.375000e-001f, +2.343750e-001f, +3.500000e-001f, +4.843750e-001f, +6.375000e-001f, +8.093750e-001f, +1.000000e+000f } /* data */ + } +}; +#else const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table[] = { /* Alfa Fine */ @@ -6537,5 +6602,6 @@ const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[2][9] = } } }; +#endif /* clang-format on */ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index d851e2c971b6e5625c06c669ac6aa3b4c776b4bb..89086987ebdc3f2b1742879deed47cfd519e5185 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -259,12 +259,12 @@ extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /*----------------------------------------------------------------------------------* * Parametric Upmix MC ROM tables *----------------------------------------------------------------------------------*/ - extern const int16_t ivas_param_upmx_mx_qmap[2][33]; - +#endif /*----------------------------------------------------------------------------------* * MASA ROM tables @@ -453,9 +453,15 @@ extern const int16_t sns_1st_means_32k[2][16]; /*----------------------------------------------------------------------* * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ +#ifdef FIX_891_PARAMUPMIX_CLEANUP +extern const int16_t ivas_param_upmx_mx_qmap[33]; +extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table; +extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9]; +#else extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table[]; extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[2][9]; +#endif /* IVAS_ROM_COM_H */ #endif diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index 2c04e3772d596165540d1ff152daa49bc14fdbf6..df335b3fe6bf30b7e6530aa683935a69429e50e9 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,16 +153,16 @@ #define FIX_643_PCA_OPTION /* VA: issue 643: rename PCA bypass command-line option */ #define FIX_902_HACK_IN_CORECODER /* VA: issue 902: remove a hack in ivas_core_dec() */ #define FIX_881_REMOVE_LFE_ADDITION_IN_ISM /* VA: issue 881: remove LFE addition in ISM format */ +#define FIX_899_VARIABLE_SPEED_DECODING /* FhG: Fix variable speed decoding */ +#define FIX_887_ARRAY_SIZE_DFT_MDCT_STEREO /* VA: Fix the definition of buffers/arrays in DFT and MDCT stereo to satisfy gcc v 11.4.0 */ +#define FIX_891_PARAMUPMIX_CLEANUP /* Dlb: issue 891: remove unneeded code from ParamUpmix */ /* #################### End BE switches ################################## */ -#define FIX_899_VARIABLE_SPEED_DECODING /* FhG: Fix variable speed decoding */ -#define FIX_887_ARRAY_SIZE_DFT_MDCT_STEREO /* VA: Fix the definition of buffers/arrays in DFT and MDCT stereo to satisfy gcc v 11.4.0 */ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt selection floating point code */ /* all switches in this category should start with "NONBE_" */ - #define NONBE_FIX_788_SBA_DTX_BR_SWITCHING /* VA: issue 787: fix Msan error in SBA BR switching with dtx in FOA encoding */ #define NONBE_FIX_856_TCX_LTP_SYNTH_FILTER /* FhG: issue 856: correct filtering length for tcx-ltp synth filtering*/ #define NONBE_UNIFIED_DECODING_PATHS /* FhG: unify decoding paths */ diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index fe93a65ee7a9a4c5794ffc2561515dcfcac51a5c..bfc9ca3b18f14343463542b0a142329c3bf69e57 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -80,6 +80,15 @@ static void paramupmix_td_decorr_process( ivas_td_decorr_state_t *hTdDecorr[], f static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] ); +#ifdef FIX_891_PARAMUPMIX_CLEANUP +static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, int32_t *vq ); + +static void dequant_alpha( int32_t *vq, float *v ); + +static void dequant_beta( int32_t *aq, int32_t *bq, float *beta ); + +static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ); +#else static void huffman_decode( Decoder_State *st, const int16_t nv, const int16_t ivStart, PAR_TYPE parType, QUANT_TYPE quant_type, const int16_t bNoDt, int32_t *vq ); static void dequant_alpha( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *vq, float *v ); @@ -87,6 +96,7 @@ static void dequant_alpha( const int16_t nv, const int16_t ivStart, const QUANT_ static void dequant_beta( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta ); static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t nParBand, const int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ); +#endif /*------------------------------------------------------------------------- @@ -141,11 +151,17 @@ void ivas_mc_paramupmix_dec_read_BS( for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] ); + + get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] ); +#else get_ec_data( st0, ALPHA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, 0 /*parBandStart*/, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] ); get_ec_data( st0, BETA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, 0 /*parBandStart*/, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] ); +#endif } *nb_bits += st0->next_bit_pos; st0->bit_stream = bit_stream_orig; @@ -1334,16 +1350,37 @@ static int16_t huff_read( static void huffman_decode( Decoder_State *st, +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, const int16_t ivStart, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t bNoDt, +#else + const PAR_TYPE parType, +#endif int32_t *vq ) { const int16_t( *huff_node_table )[2]; - int16_t iv, bdt, nquant, offset; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + int16_t iv, nquant, offset; + + nquant = 0; + switch ( parType ) + { + case ALPHA: + nquant = ivas_mc_paramupmix_alpha_quant_table.nquant; + break; + case BETA: + nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant; + break; + default: + assert( 0 ); + } + offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */ +#else + int16_t iv, bdt, nquant, offset; nquant = 0; switch ( parType ) { @@ -1358,7 +1395,11 @@ static void huffman_decode( } offset = nquant - 1; /* range of df/dt [-(nquant - 1), nquant - 1] */ +#endif +#ifdef FIX_891_PARAMUPMIX_CLEANUP + st->next_bit_pos++; +#else if ( bNoDt ) { bdt = 0; @@ -1368,7 +1409,39 @@ static void huffman_decode( bdt = st->bit_stream[st->next_bit_pos]; st->next_bit_pos++; } +#endif +#ifdef FIX_891_PARAMUPMIX_CLEANUP + switch ( parType ) + { + case ALPHA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha; + break; + case BETA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta; + break; + default: + huff_node_table = NULL; + assert( 0 ); + } + vq[0] = huff_read( st, huff_node_table ); + switch ( parType ) + { + case ALPHA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha; + break; + case BETA: + huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta; + break; + default: + assert( 0 ); + } + + for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset; + } +#else if ( bdt ) { /* Get dt */ switch ( parType ) @@ -1421,19 +1494,31 @@ static void huffman_decode( vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset; } } +#endif return; } static void dequant_alpha( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, +#endif int32_t *vq, float *v ) { int16_t iv; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table; + + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + v[iv] = quant_table->data[vq[iv]]; + } + +#else const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table[quant_type]; for ( iv = 0; iv < ivStart; iv++ ) @@ -1445,15 +1530,17 @@ static void dequant_alpha( { v[iv] = quant_table->data[vq[iv]]; } - +#endif return; } static void dequant_beta( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, +#endif int32_t *aq, int32_t *bq, float *beta ) @@ -1461,6 +1548,14 @@ static void dequant_beta( int16_t iv; const ACPL_QUANT_TABLE *quant_table; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]]; + beta[iv] = quant_table->data[bq[iv]]; + } + +#else for ( iv = 0; iv < ivStart; iv++ ) { beta[iv] = 0; @@ -1471,7 +1566,7 @@ static void dequant_beta( quant_table = &ivas_mc_paramupmix_beta_quant_table[quant_type][ivas_param_upmx_mx_qmap[quant_type][aq[iv]]]; beta[iv] = quant_table->data[bq[iv]]; } - +#endif return; } @@ -1479,23 +1574,38 @@ static void dequant_beta( static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, +#ifndef FIX_891_PARAMUPMIX_CLEANUP const QUANT_TYPE quant_type, const int16_t nParBand, const int16_t parBandStart, +#endif int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + huffman_decode( st, parType, parQ ); +#else huffman_decode( st, nParBand, parBandStart, parType, quant_type, 0, parQ ); +#endif if ( parType == ALPHA ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + dequant_alpha( parQ, ab ); + mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS ); +#else dequant_alpha( nParBand, parBandStart, quant_type, parQ, ab ); mvl2l( parQ, alphaQEnv, (int16_t) nParBand ); +#endif } else { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + dequant_beta( alphaQEnv, parQ, ab ); +#else dequant_beta( nParBand, parBandStart, quant_type, alphaQEnv, parQ, ab ); +#endif } return; diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 26846d6254bbcf90fcb29720cda571a9a30c8b84..4516fcff4b8527ce1ecbd30b7a0c6af78161f8a5 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -724,6 +724,7 @@ static const int16_t huff_nodes_first_band_alpha[32][2] = { -2, -32 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Alpha Coarse Huffman table df0 */ static const int16_t huff_nodes_first_band_alpha_coarse[16][2] = { @@ -745,6 +746,7 @@ static const int16_t huff_nodes_first_band_alpha_coarse[16][2] = { -1, -17 } }; +#endif /* Alpha Fine Huffman table df */ static const int16_t huff_nodes_alpha_1D_DF[64][2] = { @@ -814,6 +816,7 @@ static const int16_t huff_nodes_alpha_1D_DF[64][2] = { -2, -62 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Alpha Coarse Huffman table df */ static const int16_t huff_nodes_alpha_1D_DF_coarse[32][2] = { @@ -851,6 +854,7 @@ static const int16_t huff_nodes_alpha_1D_DF_coarse[32][2] = { -2, -32 } }; +#endif /* Alpha Fine Huffman table dt */ static const int16_t huff_nodes_alpha_1D_DT[64][2] = { @@ -920,6 +924,7 @@ static const int16_t huff_nodes_alpha_1D_DT[64][2] = { -2, -63 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Alpha Coarse Huffman table dt */ static const int16_t huff_nodes_alpha_1D_DT_coarse[32][2] = { @@ -957,48 +962,73 @@ static const int16_t huff_nodes_alpha_1D_DT_coarse[32][2] = { -2, -32 } }; +#endif /* Beta Fine Huffman table df0 */ static const int16_t huff_nodes_first_band_beta[8][2] = { { -1, 1 }, { -2, 2 }, { -3, 3 }, { -4, 4 }, { -5, 5 }, { -6, 6 }, { -7, 7 }, { -8, -9 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Beta Coarse Huffman table df0 */ static const int16_t huff_nodes_first_band_beta_coarse[4][2] = { { -1, 1 }, { -2, 2 }, { -3, 3 }, { -4, -5 } }; +#endif /* Beta Fine Huffman table df */ static const int16_t huff_nodes_beta_1D_DF[16][2] = { { -9, 1 }, { -10, 2 }, { -8, 3 }, { -11, 4 }, { -7, 5 }, { 7, 6 }, { -6, -12 }, { 9, 8 }, { -5, -13 }, { 11, 10 }, { -4, -14 }, { -15, 12 }, { -3, 13 }, { -16, 14 }, { -2, 15 }, { -1, -17 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Beta Coarse Huffman table df */ static const int16_t huff_nodes_beta_1D_DF_coarse[8][2] = { { -5, 1 }, { -6, 2 }, { -4, 3 }, { -3, 4 }, { -7, 5 }, { -2, 6 }, { -8, 7 }, { -1, -9 } }; +#endif /* Beta Fine Huffman table dt */ static const int16_t huff_nodes_beta_1D_DT[16][2] = { { -9, 1 }, { -10, 2 }, { -8, 3 }, { -11, 4 }, { -7, 5 }, { 7, 6 }, { -6, -12 }, { -13, 8 }, { -5, 9 }, { -14, 10 }, { -4, 11 }, { -15, 12 }, { -3, 13 }, { -16, 14 }, { -2, 15 }, { -1, -17 } }; +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Beta Coarse Huffman table dt */ static const int16_t huff_nodes_beta_1D_DT_coarse[8][2] = { { -5, 1 }, { -6, 2 }, { -4, 3 }, { -7, 4 }, { -3, 5 }, { -8, 6 }, { -2, 7 }, { -1, -9 } }; +#endif + +#ifdef FIX_891_PARAMUPMIX_CLEANUP +const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_df0 = +{ + huff_nodes_first_band_alpha, + huff_nodes_first_band_beta +}; +const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_df = +{ + huff_nodes_alpha_1D_DF, + huff_nodes_beta_1D_DF +}; + +const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_dt = +{ + huff_nodes_alpha_1D_DT, + huff_nodes_beta_1D_DT +}; +#else const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_df0 = { { huff_nodes_first_band_alpha, huff_nodes_first_band_alpha_coarse }, { huff_nodes_first_band_beta, huff_nodes_first_band_beta_coarse } }; - const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_df = { { huff_nodes_alpha_1D_DF, huff_nodes_alpha_1D_DF_coarse }, @@ -1010,5 +1040,7 @@ const HUFF_NODE_TABLE ivas_mc_paramupmix_huff_nodes_dt = { huff_nodes_alpha_1D_DT, huff_nodes_alpha_1D_DT_coarse }, { huff_nodes_beta_1D_DT, huff_nodes_beta_1D_DT_coarse } }; +#endif + /* clang-format on */ diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index d3c431a1bd8b3dd04e278cac2b856a010faee614..2d1e6d37fadc7017bed547e8a3c0b9a43cafca81 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -56,21 +56,35 @@ static void ivas_mc_paramupmix_dmx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *data_f[], const int16_t input_frame ); static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float *input_frame_t[], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); +#ifdef FIX_891_PARAMUPMIX_CLEANUP +static void get_huff_table( const PAR_TYPE par_type, HUFF_TAB *df0, HUFF_TAB *df ); +#else static void get_huff_table( const PAR_TYPE par_type, const QUANT_TYPE quant_type, HUFF_TAB *df0, HUFF_TAB *df, HUFF_TAB *dt ); +#endif static void write_huff_bits( const int32_t value, const uint16_t length, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +#ifdef FIX_891_PARAMUPMIX_CLEANUP +static void huffman_encode( const int32_t *vqPrev, const int32_t *vq, const PAR_TYPE parType, const int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +#else static void huffman_encode( const int16_t bdfOnly, const int16_t bdtAllowed, const int16_t nv, const int16_t ivStart, const int32_t *vqPrev, const int32_t *vq, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +#endif static void put_ec_data( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, const int16_t ch, const float pars[IVAS_MAX_NUM_BANDS], const float alphas[IVAS_MAX_NUM_BANDS], const PAR_TYPE parType, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +#ifdef FIX_891_PARAMUPMIX_CLEANUP +static void quantize_alpha( const float *alpha, int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ); + +static void quantize_pars( const float *v, const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); +#else static void quantize_alpha( const int16_t nv, const float *alpha, const QUANT_TYPE quant_type, int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ); static void quantize_pars( const int16_t nv, const float *v, const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); static void quantize_pars( const int16_t nv, const float *v, const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); +#endif /*------------------------------------------------------------------------- * ivas_mc_paramupmix_enc() @@ -360,13 +374,32 @@ void ivas_mc_paramupmix_enc_close( static void get_huff_table( const PAR_TYPE par_type, +#ifndef FIX_891_PARAMUPMIX_CLEANUP const QUANT_TYPE quant_type, HUFF_TAB *df0, HUFF_TAB *df, HUFF_TAB *dt ) +#else + HUFF_TAB *df0, + HUFF_TAB *df ) +#endif { switch ( par_type ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + case ALPHA: + df0->value = huff_alpha_table.df0.value; + df0->length = huff_alpha_table.df0.length; + df->value = huff_alpha_table.df.value; + df->length = huff_alpha_table.df.length; + break; + case BETA: + df0->value = huff_beta_table.df0.value; + df0->length = huff_beta_table.df0.length; + df->value = huff_beta_table.df.value; + df->length = huff_beta_table.df.length; + break; +#else case ALPHA: df0->value = huff_alpha_table[quant_type].df0.value; df0->length = huff_alpha_table[quant_type].df0.length; @@ -383,6 +416,7 @@ static void get_huff_table( dt->value = huff_beta_table[quant_type].dt.value; dt->length = huff_beta_table[quant_type].dt.length; break; +#endif } return; @@ -407,53 +441,103 @@ static void write_huff_bits( static void huffman_encode( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t bdfOnly, const int16_t bdtAllowed, const int16_t nv, const int16_t ivStart, +#endif const int32_t *vqPrev, const int32_t *vq, const PAR_TYPE parType, +#ifndef FIX_891_PARAMUPMIX_CLEANUP const QUANT_TYPE quant_type, +#endif const int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + int16_t iv; +#else int16_t iv, ndf, ndt; +#endif int32_t icode; int16_t offset; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + HUFF_TAB df0, df; +#else HUFF_TAB df0, df, dt; +#endif +#ifdef FIX_891_PARAMUPMIX_CLEANUP + get_huff_table( parType, &df0, &df ); +#else get_huff_table( parType, quant_type, &df0, &df, &dt ); +#endif offset = nq - 1; /* range [-(nquant - 1), nquant - 1] */ +#ifndef FIX_891_PARAMUPMIX_CLEANUP /* Get code length for time and freq diff coding */ ndf = 0; ndt = 0; +#endif +#ifdef FIX_891_PARAMUPMIX_CLEANUP + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) +#else for ( iv = ivStart; iv < nv; iv++ ) +#endif { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + if ( iv == 0 ) +#else if ( iv == ivStart ) +#endif { icode = vq[iv]; +#ifndef FIX_891_PARAMUPMIX_CLEANUP ndf += df0.length[icode]; +#endif } else { icode = vq[iv] - vq[iv - 1] + offset; +#ifndef FIX_891_PARAMUPMIX_CLEANUP ndf += df.length[icode]; +#endif } icode = vq[iv] - vqPrev[iv] + offset; +#ifndef FIX_891_PARAMUPMIX_CLEANUP ndt += dt.length[icode]; +#endif } +#ifndef FIX_891_PARAMUPMIX_CLEANUP if ( !bdtAllowed ) /* Time diff not allowed due to conformance or other reason even if bdfOnly = 0 */ { ndt = ndf + 1; } +#endif /* Write the bitstream */ +#ifdef FIX_891_PARAMUPMIX_CLEANUP + bit_buffer[( *bit_pos )++] = (uint16_t) 0 & 1; + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) + { + if ( iv == 0 ) + { + icode = vq[iv]; + write_huff_bits( df0.value[icode], df0.length[icode], bit_buffer, bit_pos ); + } + else + { + icode = vq[iv] - vq[iv - 1] + offset; + write_huff_bits( df.value[icode], df.length[icode], bit_buffer, bit_pos ); + } + } +#else if ( bdfOnly || ndf < ndt ) { bit_buffer[( *bit_pos )++] = (uint16_t) 0 & 1; @@ -486,13 +570,16 @@ static void huffman_encode( write_huff_bits( dt.value[icode], dt.length[icode], bit_buffer, bit_pos ); } } +#endif return; } static void quantize_pars( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, +#endif const float *v, const int16_t nq, const float *data, @@ -501,7 +588,11 @@ static void quantize_pars( { int16_t iv, iq, iq0, iq1; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) +#else for ( iv = 0; iv < nv; iv++ ) +#endif { iq0 = 0; iq1 = nq - 1; @@ -536,9 +627,13 @@ static void quantize_pars( static void quantize_alpha( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, +#endif const float *alpha, +#ifndef FIX_891_PARAMUPMIX_CLEANUP const QUANT_TYPE quant_type, +#endif int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ) @@ -546,11 +641,17 @@ static void quantize_alpha( int16_t nq; const float *data; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + nq = ivas_mc_paramupmix_alpha_quant_table.nquant; + data = ivas_mc_paramupmix_alpha_quant_table.data; + + quantize_pars( alpha, nq, data, aq, adeq ); +#else nq = ivas_mc_paramupmix_alpha_quant_table[quant_type].nquant; data = ivas_mc_paramupmix_alpha_quant_table[quant_type].data; quantize_pars( nv, alpha, nq, data, aq, adeq ); - +#endif *pnq = nq; return; @@ -558,21 +659,37 @@ static void quantize_alpha( static void quantize_beta( +#ifndef FIX_891_PARAMUPMIX_CLEANUP const int16_t nv, +#endif const float *beta, const int32_t aq[IVAS_MAX_NUM_BANDS], +#ifndef FIX_891_PARAMUPMIX_CLEANUP const QUANT_TYPE quant_type, +#endif int16_t *pnq, int32_t bq[IVAS_MAX_NUM_BANDS], float *bdeq ) { int16_t iv, iq, iq0, iq1; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + const ACPL_QUANT_TABLE *tables = ivas_mc_paramupmix_beta_quant_table; +#else const ACPL_QUANT_TABLE *tables = ivas_mc_paramupmix_beta_quant_table[quant_type]; +#endif ACPL_QUANT_TABLE quant_table; +#ifdef FIX_891_PARAMUPMIX_CLEANUP + for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) +#else for ( iv = 0; iv < nv; iv++ ) +#endif { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + quant_table = tables[ivas_param_upmx_mx_qmap[aq[iv]]]; +#else quant_table = tables[ivas_param_upmx_mx_qmap[quant_type][aq[iv]]]; +#endif iq0 = 0; iq1 = quant_table.nquant - 1; @@ -602,7 +719,11 @@ static void quantize_beta( } } +#ifdef FIX_891_PARAMUPMIX_CLEANUP + *pnq = ivas_mc_paramupmix_beta_quant_table[0].nquant; +#else *pnq = ivas_mc_paramupmix_beta_quant_table[quant_type][0].nquant; +#endif return; } @@ -617,10 +738,14 @@ static void put_ec_data( uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ) { +#ifndef FIX_891_PARAMUPMIX_CLEANUP int16_t npar = IVAS_MAX_NUM_BANDS; int16_t onlyFreq = 1; +#endif int16_t nq; +#ifndef FIX_891_PARAMUPMIX_CLEANUP QUANT_TYPE quant_type = FINE; +#endif int32_t alphaQuant[IVAS_MAX_NUM_BANDS]; int32_t betaQuant[IVAS_MAX_NUM_BANDS]; float alphaDequant[IVAS_MAX_NUM_BANDS]; @@ -628,12 +753,21 @@ static void put_ec_data( if ( parType == ALPHA ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + quantize_alpha( pars, &nq, alphaQuant, alphaDequant ); +#else quantize_alpha( npar, pars, quant_type, &nq, alphaQuant, alphaDequant ); +#endif } else { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + quantize_alpha( alphas, &nq, alphaQuant, alphaDequant ); + quantize_beta( pars, alphaQuant, &nq, betaQuant, betaDequant ); +#else quantize_alpha( npar, alphas, quant_type, &nq, alphaQuant, alphaDequant ); quantize_beta( npar, pars, alphaQuant, quant_type, &nq, betaQuant, betaDequant ); +#endif } if ( hMCParamUpmix->first_frame ) @@ -652,11 +786,19 @@ static void put_ec_data( /* Always one parameter set per frame for transient frames. Original PS framing is used internally. */ if ( parType == ALPHA ) { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + huffman_encode( hMCParamUpmix->alpha_quant_prev[ch], alphaQuant, ALPHA, nq, bit_buffer, bit_pos ); +#else huffman_encode( onlyFreq, 1, npar, 0, hMCParamUpmix->alpha_quant_prev[ch], alphaQuant, ALPHA, quant_type, nq, bit_buffer, bit_pos ); +#endif } else { +#ifdef FIX_891_PARAMUPMIX_CLEANUP + huffman_encode( hMCParamUpmix->beta_quant_prev[ch], betaQuant, BETA, nq, bit_buffer, bit_pos ); +#else huffman_encode( onlyFreq, 1, npar, 0, hMCParamUpmix->beta_quant_prev[ch], betaQuant, BETA, quant_type, nq, bit_buffer, bit_pos ); +#endif } if ( parType == ALPHA ) diff --git a/lib_enc/ivas_rom_enc.c b/lib_enc/ivas_rom_enc.c index ce24de702d8382fd4b7d14d8f6d348cc0bd5f891..2bb4efdd835d74c21fe2b9edcc42104da9eec397 100644 --- a/lib_enc/ivas_rom_enc.c +++ b/lib_enc/ivas_rom_enc.c @@ -723,6 +723,55 @@ const float Stereo_dmx_wnd_coef_48k[L_FRAME48k] = { }; +#ifdef FIX_891_PARAMUPMIX_CLEANUP +/*----------------------------------------------------------------------------------* + * ParamUpmix ROM tables + *----------------------------------------------------------------------------------*/ + +const HUFF_TABLE huff_alpha_table = +{ + { /* df0 */ + { 0x0002ce, 0x000b5e, 0x0004fe, 0x0005ae, 0x00027e, 0x0002de, 0x00016a, 0x0000b2, 0x00004a, 0x00004b, + 0x0000b6, 0x00004e, 0x000024, 0x00002e, 0x00000a, 0x000006, 0x000000, 0x000007, 0x000008, 0x00002f, + 0x000026, 0x000058, 0x0000b4, 0x00009e, 0x00016e, 0x000166, 0x0002df, 0x0002cf, 0x00027c, 0x00027d, + 0x0004ff, 0x000b5f, 0x0002d6 }, + { 10, 12, 11, 11, 10, 10, 9, 8, 7, 7, + 8, 7, 6, 6, 4, 3, 1, 3, 4, 6, + 6, 7, 8, 8, 9, 9, 10, 10, 10, 10, + 11, 12, 10 } + }, + { /* df */ + { 0x0011de, 0x011ffe, 0x013dea, 0x013df6, 0x008eea, 0x013df7, 0x013dee, 0x013deb, 0x013dec, 0x008eee, + 0x008ffe, 0x009efe, 0x0047fe, 0x004f7c, 0x0023fe, 0x0011fe, 0x0013fe, 0x0008f6, 0x0009ee, 0x000476, + 0x00047a, 0x0004f6, 0x00023a, 0x00027a, 0x00027e, 0x00013e, 0x00009a, 0x00004c, 0x00004e, 0x000012, + 0x00000a, 0x000006, 0x000000, 0x000007, 0x00000b, 0x000010, 0x000022, 0x000046, 0x00009b, 0x00013c, + 0x00011c, 0x00023e, 0x00023c, 0x0004fe, 0x00047e, 0x0009fe, 0x0008fe, 0x0008f7, 0x0013ff, 0x0011df, + 0x0027bc, 0x004f7e, 0x004776, 0x009efa, 0x009ef4, 0x013dfe, 0x008eeb, 0x008ee8, 0x013dff, 0x008ee9, + 0x008eef, 0x011fff, 0x013ded, 0x013def, 0x0011dc }, + { 13, 17, 17, 17, 16, 17, 17, 17, 17, 16, + 16, 16, 15, 15, 14, 13, 13, 12, 12, 11, + 11, 11, 10, 10, 10, 9, 8, 7, 7, 5, + 4, 3, 1, 3, 4, 5, 6, 7, 8, 9, + 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, + 14, 15, 15, 16, 16, 17, 16, 16, 17, 16, + 16, 17, 17, 17, 13 } + } +}; + +const HUFF_TABLE huff_beta_table = +{ + { /* df0 */ + { 0x000000, 0x000002, 0x000006, 0x00000e, 0x00001e, 0x00003e, 0x00007e, 0x0000fe, 0x0000ff }, + { 1, 2, 3, 4, 5, 6, 7, 8, 8 } + }, + { /* df */ + { 0x001f1e, 0x000f8e, 0x0003e2, 0x0001f2, 0x0000fa, 0x00007e, 0x00001e, 0x000006, 0x000000, 0x000002, + 0x00000e, 0x00007f, 0x0000fb, 0x0001f3, 0x0001f0, 0x0007c6, 0x001f1f }, + { 13, 12, 10, 9, 8, 7, 5, 3, 1, 2, + 4, 7, 8, 9, 9, 11, 13 } + } +}; +#else const HUFF_TABLE huff_alpha_table[2] = { { /* Alfa Fine */ @@ -834,6 +883,7 @@ const HUFF_TABLE huff_beta_table[2] = } } /* End Beta Coarse */ }; +#endif const int16_t mc_paramupmix_fb_remix_order[4] = {0, 1, 2, 3}; diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h index fa45706cab5082c87232c012f9ce9fcc36602433..9e6363fb06ec947ccab5b1a2d6ed6826c1b47e3c 100644 --- a/lib_enc/ivas_rom_enc.h +++ b/lib_enc/ivas_rom_enc.h @@ -126,10 +126,21 @@ extern const float Stereo_dmx_s_wnd_coef_48k[L_FRAME48k >> 4]; extern const float Stereo_dmx_wnd_coef_32k[L_FRAME32k]; extern const float Stereo_dmx_wnd_coef_48k[L_FRAME48k]; +#ifdef FIX_891_PARAMUPMIX_CLEANUP +/*----------------------------------------------------------------------------------* + * ParamUpmix ROM tables + *----------------------------------------------------------------------------------*/ + +extern const HUFF_TABLE huff_alpha_table; +extern const HUFF_TABLE huff_beta_table; +extern const int16_t mc_paramupmix_fb_remix_order[4]; + +#else extern const HUFF_TABLE huff_alpha_table[2]; extern const HUFF_TABLE huff_beta_table[2]; extern const int16_t mc_paramupmix_fb_remix_order[4]; +#endif /*----------------------------------------------------------------------------------* * ParamMC ROM tables *----------------------------------------------------------------------------------*/