From 4986967baf841403bd3666b2ffcb5f8b608d1364 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 9 Jan 2024 20:50:54 +0530 Subject: [PATCH] Subfunctions for dec_prm_tcx converted. [x] Few functions from files dec_prm.c,bitstream_fx.c converted. --- lib_com/bitstream_fx.c | 10 +- lib_com/prot.h | 8 +- lib_com/prot_fx2.h | 21 ++++ lib_dec/dec_prm.c | 146 ++++++++++++++++-------- lib_dec/dec_prm_fx.c | 79 +++++++++++++ lib_dec/dlpc_avq_fx.c | 209 ++++++++++++++++++++++++++++++++--- lib_dec/lsf_msvq_ma_dec_fx.c | 16 +-- 7 files changed, 415 insertions(+), 74 deletions(-) diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 9cb1518bb..eed1ede38 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -389,13 +389,15 @@ UWord16 get_next_indice_fx( /* o : value of the indice */ { UWord16 value; Word16 i; + Word32 nbits_total; assert(nb_bits <= 16); value = 0; move16(); + nbits_total = st_fx->total_brate / FRAMES_PER_SEC; /* detect corrupted bitstream */ - IF(GT_16(add(st_fx->next_bit_pos, nb_bits), st_fx->total_num_bits)) + IF(GT_16(add(st_fx->next_bit_pos, nb_bits), nbits_total)) { st_fx->BER_detect = 1; move16(); @@ -423,12 +425,14 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice */ Decoder_State *st_fx /* i/o: decoder state structure */ ) { + Word32 nbits_total; + nbits_total = st_fx->total_brate / FRAMES_PER_SEC; /* detect corrupted bitstream */ test(); test(); test(); - IF((GT_16(add(st_fx->next_bit_pos, 1), st_fx->total_num_bits) && EQ_16(st_fx->codec_mode, MODE1)) || - (GT_16(add(st_fx->next_bit_pos, 1), add(st_fx->total_num_bits, 2 * 8)) && EQ_16(st_fx->codec_mode, MODE2)) /* add two zero bytes for arithmetic coder flush */ + IF((GT_16(add(st_fx->next_bit_pos, 1), nbits_total) && EQ_16(st_fx->codec_mode, MODE1)) || + (GT_16(add(st_fx->next_bit_pos, 1), add(nbits_total, 2 * 8)) && EQ_16(st_fx->codec_mode, MODE2)) /* add two zero bytes for arithmetic coder flush */ ) { st_fx->BER_detect = 1; diff --git a/lib_com/prot.h b/lib_com/prot.h index cb2498379..ff46aa029 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -6706,13 +6706,13 @@ void enc_acelp_tcx_main( void getTCXMode_ivas( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0, /* i : bitstream */ - const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ ); void getTCXWindowing_ivas( - const int16_t core, /* i : current frame mode */ - const int16_t last_core, /* i : last frame mode */ - const int16_t element_mode, /* i : element mode */ + const Word16 core, /* i : current frame mode */ + const Word16 last_core, /* i : last frame mode */ + const Word16 element_mode, /* i : element mode */ TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ Decoder_State *st0 /* i : bitstream */ ); diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 5b00e8f4f..d5952d04a 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -985,6 +985,10 @@ UWord16 get_next_indice_1( /* o : value of the indice */ Decoder_State *st_fx /* i/o: decoder state structure */ ); +UWord16 get_next_indice_1_fx( /* o : value of the indice */ + Decoder_State *st_fx /* i/o: decoder state structure */ +); + void get_next_indice_tmp_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 nb_bits /* i : number of bits that were used to quantize the indice */ @@ -7264,6 +7268,13 @@ void dec_prm( Word16 *bitsRead ); +void getLPCparam( + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param_lpc[], /* o : LTP parameters */ + Decoder_State *st0, /* i : bitstream */ + const Word16 ch, /* i : channel */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ +); //ari_hm_fx.c void UnmapIndex( @@ -7451,6 +7462,16 @@ Word16 decode_lpc_avq( #endif ); +//decode_lpc_avq declaration with IVAS_CODE_AVQ_LPC enabled +Word16 decode_lpc_avq_ivas( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16 *param_lpc /* o : lpc parameters */ + , + const Word16 ch, /* i : channel */ + const Word16 element_mode, /* i : element mode */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ +); //vlpc_1st_dec_fx.c void vlpc_1st_dec( Word16 index, /* i : codebook index */ diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index 83f180d2d..9561a2fd2 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -41,7 +41,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#include "prot_fx2.h" /*-------------------------------------------------------------------* * getTCXMode_ivas() @@ -52,133 +52,175 @@ void getTCXMode_ivas( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0, /* i : bitstream */ - const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) { - uint16_t ind; + UWord16 ind; - if ( st->tcxonly ) + IF ( st->tcxonly ) { /* get core */ +#ifdef IVAS_FLOAT_FIXED + ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */ +#else ind = get_next_indice( st0, 1 ); - st->core = ind + TCX_20_CORE; +#endif // IVAS_FLOAT_FIXED + + st->core =add( ind , TCX_20_CORE); /* get class */ +#ifdef IVAS_FLOAT_FIXED + ind = get_next_indice_fx( st0, 2 ); +#else ind = get_next_indice( st0, 2 ); +#endif // IVAS_FLOAT_FIXED st->clas_dec = ONSET; - if ( ind == 0 ) + IF ( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; } - else if ( ind == 1 ) + ELSE IF ( ind == 1 ) { - if ( st->last_good >= VOICED_TRANSITION ) + IF (GE_16( st->last_good , VOICED_TRANSITION )) { st->clas_dec = VOICED_TRANSITION; } - else + ELSE { st->clas_dec = UNVOICED_TRANSITION; } } - else if ( ind == 2 ) + ELSE IF ( ind == 2 ) { st->clas_dec = VOICED_CLAS; } st->coder_type = INACTIVE; - if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) + IF ( EQ_16( st->element_mode , IVAS_CPE_MDCT ) && !MCT_flag ) { +#ifdef IVAS_FLOAT_FIXED + st->VAD = get_next_indice_fx( st0, 1 ); +#else st->VAD = get_next_indice( st0, 1 ); +#endif // IVAS_FLOAT_FIXED } - else + ELSE { st->VAD = 0; } } - else + ELSE { - if ( st->mdct_sw == MODE1 ) + IF ( EQ_16( st->mdct_sw , MODE1 ) ) { /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; +#ifdef IVAS_FLOAT_FIXED + st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 ); +#else st->hTcxCfg->coder_type = get_next_indice( st0, 2 ); +#endif // IVAS_FLOAT_FIXED st->coder_type = st->hTcxCfg->coder_type; } - else + ELSE { - if ( st->mdct_sw_enable == MODE2 ) + IF ( EQ_16( st->mdct_sw_enable , MODE2 ) ) { - if ( get_next_indice_1( st0 ) ) /* TCX */ + +#ifdef IVAS_FLOAT_FIXED + IF( get_next_indice_1_fx( st0 ) ) +#else + IF ( get_next_indice_1( st0 ) ) /* TCX */ +#endif // IVAS_FLOAT_FIXED { +#ifdef IVAS_FLOAT_FIXED + ind = get_next_indice_fx( st0, 3 ); +#else ind = get_next_indice( st0, 3 ); +#endif assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" ); st->core = TCX_20_CORE; st->hTcxCfg->coder_type = ind; st->coder_type = st->hTcxCfg->coder_type; } - else /* ACELP */ + ELSE /* ACELP */ { st->core = ACELP_CORE; +#ifdef IVAS_FLOAT_FIXED + st->coder_type = get_next_indice_fx( st0, 2 ); +#else st->coder_type = get_next_indice( st0, 2 ); +#endif // IVAS_FLOAT_FIXED } } - else + ELSE { - if ( st->rf_flag == 1 ) + IF ( EQ_16( st->rf_flag , 1 ) ) { - if ( !st->use_partial_copy ) + IF ( !st->use_partial_copy ) { +#ifdef IVAS_FLOAT_FIXED + ind = get_next_indice_fx( st0, 1 ); +#else ind = get_next_indice( st0, 1 ); - if ( ind == 0 ) +#endif // IVAS_FLOAT_FIXED + IF ( ind == 0 ) { st->core = ACELP_CORE; } - else + ELSE { st->core = TCX_20_CORE; st->hTcxCfg->coder_type = st->coder_type; } } } - else + ELSE { +#ifdef IVAS_FLOAT_FIXED + ind = get_next_indice_fx( st, 3 ); +#else ind = get_next_indice( st, 3 ); - if ( ind < ACELP_MODE_MAX ) +#endif // IVAS_FLOAT_FIXED + IF (LT_16( ind , ACELP_MODE_MAX )) { st->core = ACELP_CORE; st->coder_type = ind; } - else + ELSE { st->core = TCX_20_CORE; - st->hTcxCfg->coder_type = ind - ACELP_MODE_MAX; + st->hTcxCfg->coder_type =sub( ind , ACELP_MODE_MAX ); st->coder_type = st->hTcxCfg->coder_type; } } } } - if ( st->element_mode == EVS_MONO ) + IF(EQ_16( st->element_mode , EVS_MONO )) { - if ( st->igf && st->core == ACELP_CORE ) + IF ( st->igf && EQ_16( st->core , ACELP_CORE ) ) { +#ifdef IVAS_FLOAT_FIXED + st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); +#else st->bits_frame_core -= get_tbe_bits( st->total_brate, st->bwidth, st->rf_flag ); +#endif // IVAS_FLOAT_FIXED } - if ( st->rf_flag ) + IF ( st->rf_flag ) { - st->bits_frame_core -= ( st->rf_target_bits + 1 ); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits , 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ } } /* Inactive frame detection on non-DTX mode */ - if ( st->coder_type == INACTIVE ) + IF(EQ_16( st->coder_type , INACTIVE )) { st->VAD = 0; } - else + ELSE { st->VAD = 1; } @@ -186,7 +228,7 @@ void getTCXMode_ivas( /*Core extended mode mapping for correct PLC classification*/ st->core_ext_mode = st->coder_type; - if ( st->coder_type == INACTIVE ) + IF(EQ_16( st->coder_type , INACTIVE )) { st->core_ext_mode = UNVOICED; } @@ -202,29 +244,29 @@ void getTCXMode_ivas( *--------------------------------------------------------------------*/ void getTCXWindowing_ivas( - const int16_t core, /* i : current core */ - const int16_t last_core, /* i : last frame core */ - const int16_t element_mode, /* i : element mode */ + const Word16 core, /* i : current core */ + const Word16 last_core, /* i : last frame core */ + const Word16 element_mode, /* i : element mode */ TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ Decoder_State *st0 /* i : bitstream */ ) { - int16_t overlap_code; + Word16 overlap_code; /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ - if ( last_core == ACELP_CORE || last_core == AMR_WB_CORE ) + IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) ) { hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; } - else if ( core == TCX_10_CORE && hTcxCfg->tcx_curr_overlap_mode == ALDO_WINDOW ) + ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) ) { hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; } - else if ( core != TCX_10_CORE && hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) + ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; } - else + ELSE { hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; } @@ -232,33 +274,47 @@ void getTCXWindowing_ivas( /* Set the current overlap mode based on the current frame type and coded overlap mode */ hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; - if ( core != ACELP_CORE ) + IF( NE_16( core, ACELP_CORE ) ) { overlap_code = 0; +#ifdef IVAS_FLOAT_FIXED + IF( get_next_indice_fx( st0, 1 ) ) + { + overlap_code = add( 2, get_next_indice_fx( st0, 1 ) ); + } +#else if ( get_next_indice( st0, 1 ) ) { overlap_code = 2 + get_next_indice( st0, 1 ); } +#endif assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 ); hTcxCfg->tcx_curr_overlap_mode = overlap_code; /*TCX10 : always symmetric windows*/ - if ( core == TCX_20_CORE && overlap_code == 0 && last_core != ACELP_CORE && last_core != AMR_WB_CORE ) + IF( EQ_16( core, TCX_20_CORE ) && EQ_16( overlap_code, 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) ) { hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; } } - if ( element_mode != EVS_MONO && core == TCX_10_CORE ) + IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) ) { /* also read last overlap */ overlap_code = 0; +#ifdef IVAS_FLOAT_FIXED + IF( get_next_indice_fx( st0, 1 ) ) + { + overlap_code = add( 2, get_next_indice_fx( st0, 1 ) ); + } +#else if ( get_next_indice( st0, 1 ) ) { overlap_code = 2 + get_next_indice( st0, 1 ); } +#endif hTcxCfg->tcx_last_overlap_mode = overlap_code; } diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index a8c37abf1..0c5d65554 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -14,6 +14,85 @@ #include "prot_fx2.h" #include "basop_util.h" + /*-------------------------------------------------------------------* + * getLPCparam_ivas() + * + * get LPC parameters + *--------------------------------------------------------------------*/ + +void getLPCparam( + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param_lpc[], /* o : LTP parameters */ + Decoder_State *st0, /* i : bitstream */ + const Word16 ch, /* i : channel */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ +) +{ + IF( EQ_16( st->use_partial_copy, 0 ) ) + { + /* Number of sets of LPC parameters (does not include mid-lpc) */ + IF( ( st->tcxonly, 0 ) || LT_16( st->core, TCX_10_CORE ) ) + { + st->numlpc = 1; + } + ELSE + { + st->numlpc = 2; + } + + /* Decode LPC parameters */ + IF( st->hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + { + Word16 tcx_lpc_cdk; + tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); + dec_lsf_tcxlpc( st0, ¶m_lpc, st->narrowBand, tcx_lpc_cdk ); + } + ELSE + { + IF( EQ_16( st->lpcQuantization, 0 ) ) + { + decode_lpc_avq_ivas( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); + } + ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) + { + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + { + assert( EQ_16( st->element_mode, EVS_MONO ) ); + lsf_bctcvq_decprm( st0, param_lpc ); + } + ELSE + { + lsf_msvq_ma_decprm( st0, param_lpc ); + } + } + ELSE + { + assert( 0 ); + } + } + } + ELSE + { + st->numlpc = 1; + + IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) + { + param_lpc[0] = 0; + param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ + } + ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) + { + /* LSF indices */ + param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ + } + } + + return; +} + static void dec_prm_hm( Decoder_State *st, Word16 *prm_hm, diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index b0a485de1..1610e1727 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -108,13 +108,13 @@ static Word16 unary_decode( move16(); *ind = 0; - WHILE ((get_next_indice_1(st) != 0) && !st->BER_detect) + WHILE ((get_next_indice_1_fx(st) != 0) && !st->BER_detect) { move16(); *ind = add(*ind,1); } - if (*ind != 0) + IF (*ind != 0) { move16(); *ind = add(*ind, 1); @@ -139,12 +139,12 @@ static Word16 pack4bits( FOR ( ; nbits > 4; nbits -= 4 ) { move16(); - prm[i] = get_next_indice(st, 4); + prm[i] = get_next_indice_fx(st, 4); i = add(i,1); } - prm[i] = get_next_indice(st, nbits); + prm[i] = get_next_indice_fx(st, nbits); move16(); i = add(i,1); @@ -156,9 +156,9 @@ Word16 decode_lpc_avq( const Word16 numlpc, /* i : Number of sets of lpc */ Word16* param_lpc /* o : lpc parameters */ #ifdef IVAS_CODE_AVQ_LPC - ,const int16_t ch, /* i : channel */ - const int16_t element_mode, /* i : element mode */ - const int16_t sns_low_br_mode /* i : SNS low-bitrate mode */ + ,const Word16 ch, /* i : channel */ + const Word16 element_mode, /* i : element mode */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ #endif ) { @@ -189,7 +189,7 @@ Word16 decode_lpc_avq( { move16(); nb = 1; - q_type = get_next_indice(st, nb); + q_type = get_next_indice_fx(st, nb); move16(); param_lpc[j] = q_type; j = add(j,1); @@ -219,11 +219,11 @@ Word16 decode_lpc_avq( { IF (NE_16(stereo_mode, 3) ) { - param_lpc[j] = get_next_indice(st, SNS_ABS_QUANT_BITS); + param_lpc[j] = get_next_indice_fx(st, SNS_ABS_QUANT_BITS); } ELSE { - param_lpc[j] = sub(get_next_indice(st, 1), 2); + param_lpc[j] = sub(get_next_indice_fx(st, 1), 2); } move16(); } @@ -231,7 +231,7 @@ Word16 decode_lpc_avq( #endif { move16(); - param_lpc[j] = get_next_indice(st, 8); + param_lpc[j] = get_next_indice_fx(st, 8); } j = add(j,1); } @@ -241,12 +241,12 @@ Word16 decode_lpc_avq( * - OR the side-SNS-is-zero flag is set for joint SNS */ #ifdef IVAS_CODE_AVQ_LPC - IF(NE_16(element_mode, IVAS_CPE_MDCT) || (!(sns_low_br_mode && (EQ_16(stereo_mode, 0) || EQ_16(stereo_mode, 1)) && !(EQ_16(q_type, 0) && EQ_16(param_lpc[j - 1], -2)))) + IF(NE_16(element_mode, IVAS_CPE_MDCT) || (!(sns_low_br_mode && (EQ_16(stereo_mode, 0) || EQ_16(stereo_mode, 1)) && !(EQ_16(q_type, 0) && EQ_16(param_lpc[j - 1], -2))))) #endif { /* 2 bits to specify Q2,Q3,Q4,ext */ - qn1 = add(2, get_next_indice(st, 2)); - qn2 = add(2, get_next_indice(st, 2)); + qn1 = add(2, get_next_indice_fx(st, 2)); + qn2 = add(2, get_next_indice_fx(st, 2)); /* Unary code */ /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ @@ -341,3 +341,184 @@ Word16 decode_lpc_avq( return sub(st->next_bit_pos, start_bit_pos); } +Word16 decode_lpc_avq_ivas( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 numlpc, /* i : Number of sets of lpc */ + Word16 *param_lpc /* o : lpc parameters */ + , + const Word16 ch, /* i : channel */ + const Word16 element_mode, /* i : element mode */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ +) +{ + Word16 k, j; + Word16 nb, qn1, qn2, avqBits, q_type; + Word16 start_bit_pos; + Word16 stereo_mode = 0; + + // #endif + move16(); + move16(); + move16(); + j = 0; + start_bit_pos = st->next_bit_pos; + + FOR( k = 0; k < numlpc; k++ ) + { + /* Decode quantizer type */ + + IF( k == 0 ) + { + move16(); + move16(); + q_type = 0; + nb = 0; + } + ELSE + { + move16(); + nb = 1; + q_type = get_next_indice_fx( st, nb ); + move16(); + param_lpc[j] = q_type; + j = add( j, 1 ); + } + test(); + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && k == 0 ) + { + stereo_mode = ch; + move16(); + if ( ch == 0 ) + { + stereo_mode = param_lpc[j]; + move16(); + } + param_lpc[j++] = stereo_mode; + move16(); + } + // #endif + /* Decode quantization indices */ + + IF( q_type == 0 ) + { + /* Absolute quantizer with 1st stage stochastic codebook */ + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( NE_16( stereo_mode, 3 ) ) + { + param_lpc[j] = get_next_indice_fx( st, SNS_ABS_QUANT_BITS ); + } + ELSE + { + param_lpc[j] = sub( get_next_indice_fx( st, 1 ), 2 ); + } + move16(); + } + ELSE + { + move16(); + param_lpc[j] = get_next_indice_fx( st, LPC_ABS_QUANT_BITS); + } + j = add( j, 1 ); + } + /* + * 2nd stage decoding is skipped if: + * - we are in low bitrate mode and no joint SNS coding is used + * - OR the side-SNS-is-zero flag is set for joint SNS + */ + IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( EQ_16( stereo_mode, 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( EQ_16( q_type, 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) + { + /* 2 bits to specify Q2,Q3,Q4,ext */ + qn1 = add( 2, get_next_indice_fx( st, 2 ) ); + qn2 = add( 2, get_next_indice_fx( st, 2 ) ); + /* Unary code */ + /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ + + IF( GT_16( qn1, 4 ) ) + { + nb = unary_decode( st, &qn1 ); + + if ( EQ_16( nb, 1 ) ) + { + qn1 = add( qn1, 5 ); + } + if ( EQ_16( nb, 2 ) ) + { + qn1 = add( qn1, 4 ); + } + if ( EQ_16( nb, 3 ) ) + { + move16(); + qn1 = 0; + } + if ( GT_16( nb, 3 ) ) + { + qn1 = add( qn1, 3 ); + } + } + + IF( GT_16( qn2, 4 ) ) + { + nb = unary_decode( st, &qn2 ); + + if ( EQ_16( nb, 1 ) ) + { + qn2 = add( qn2, 5 ); + } + if ( EQ_16( nb, 2 ) ) + { + qn2 = add( qn2, 4 ); + } + if ( EQ_16( nb, 3 ) ) + { + move16(); + qn2 = 0; + } + if ( GT_16( nb, 3 ) ) + { + qn2 = add( qn2, 3 ); + } + } + + /* check for potential bit errors */ + test(); + IF( ( GT_16( qn1, NB_SPHERE ) ) || ( GT_16( qn2, NB_SPHERE ) ) ) + { + qn1 = 0; + move16(); + qn2 = 0; + move16(); + st->BER_detect = 1; + move16(); + } + + move16(); + param_lpc[j] = qn1; + j = add( j, 1 ); + move16(); + param_lpc[j] = qn2; + j = add( j, 1 ); + + /* Decode Split-by-2 algebraic VQ */ + avqBits = shl( qn1, 2 ); + + pack4bits( avqBits, st, ¶m_lpc[j] ); + j = add( j, qn1 ); + + avqBits = shl( qn2, 2 ); + pack4bits( avqBits, st, ¶m_lpc[j] ); + j = add( j, qn2 ); + } + ELSE + { + param_lpc[j] = 0; + j = add( j, 1 ); + param_lpc[j] = 0; + j = add( j, 1 ); + move16(); + move16(); + } + } + + return sub( st->next_bit_pos, start_bit_pos ); +} diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index f5ab44b59..aac31151e 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -60,7 +60,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State * st, Word16 *param_lpc) IF (EQ_16(predmode, 2)) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice(st, 1); + safety_net = get_next_indice_fx(st, 1); IF (EQ_16(safety_net,1)) { @@ -94,17 +94,17 @@ Word16 lsf_msvq_ma_decprm( Decoder_State * st, Word16 *param_lpc) tmp = sub(stages,1); FOR (i=0; icoder_type_fx, VOICED) && st->core==0 && st->acelp_cfg.midLpc) { - *param_lpc = get_next_indice(st, bits_midlpc); + *param_lpc = get_next_indice_fx(st, bits_midlpc); nbits_lpc = add(nbits_lpc, bits_midlpc); } @@ -140,7 +140,7 @@ Word16 lsf_bctcvq_decprm( FOR (i=0; i