diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 514a9f894b77eb32b33951070a88e105c4019ad8..5d3fc0dcfc9dc22f6d74167f19e00997f7374cfd 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -823,7 +823,7 @@ ivas_error config_acelp1( bits -= acelp_cfg->mid_lsf_bits; } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) { bits -= TDM_IC_LSF_PRED_BITS; @@ -1384,7 +1384,7 @@ ivas_error config_acelp1( { if ( idchan > 0 && element_mode == IVAS_CPE_TD ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE if ( !tdm_lp_reuse_flag ) { acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e91e31d232ffa985866bd50a8ae600e8eec6c2c5..91be1b984d0532881d4157656e91fcf57ef156f5 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -828,15 +828,19 @@ void ivas_lfe_dec_close_fx( void td_stereo_param_updt_fx( - const Word16 lsp_old_PCh[], /* i : primary channel old LSPs */ - const Word16 lsf_old_PCh[], /* i : primary channel old LSFs */ - const Word16 pitch_buf_PCh[], /* i : primary channel pitch buffer */ - Word16 tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */ - Word16 tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */ - Word16 tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc, /* i : flag to indicate the usage of mean inactive LP coefficients */ - Word16 Q_var ); + const Word16 lsp_old_PCh[], /* i : primary channel old LSPs */ + const Word16 lsf_old_PCh[], /* i : primary channel old LSFs */ + const Word16 pitch_buf_PCh[], /* i : primary channel pitch buffer */ + Word16 tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */ + Word16 tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */ + Word16 tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Word16 Q_var +#endif +); void updateBuffersForDmxMdctStereo_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 1458bc8e60658854b910b3a34088c0c2bd07352f..2ca004b6ecb45b47d511a706e3664d8e43ffadb6 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -864,15 +864,19 @@ void td_stereo_param_updt( #ifdef IVAS_FLOAT_FIXED void td_stereo_param_updt_fx( - const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15*/ - const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qx2.56*/ - const Word16 pitch_buf_PCh_fx[], /* i : primary channel pitch buffer Q_var*/ - Word16 tdm_lspQ_PCh_fx[], /* o : Q LSPs for primary channel Q15*/ - Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qx2.56*/ - Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q_var */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc, /* i : flag to indicate the usage of mean inactive LP coefficients */ - Word16 Q_var ) + const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15*/ + const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qx2.56*/ + const Word16 pitch_buf_PCh_fx[], /* i : primary channel pitch buffer Q_var*/ + Word16 tdm_lspQ_PCh_fx[], /* o : Q LSPs for primary channel Q15*/ + Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qx2.56*/ + Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q_var */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Word16 Q_var +#endif +) { Word16 i; /* Copy some primary channel information into the secondary channel structure for later usage */ @@ -893,7 +897,24 @@ void td_stereo_param_updt_fx( Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); } +#ifdef FIX_798_WRONG_CPY_OF_PITCH + IF( EQ_16( flag_ACELP16k, 1 ) ) + { + Word16 tmp16; + Word16 mult_factor = 26214 /*0.8f in Q15*/; + FOR( i = 0; i < NB_SUBFR; i++ ) + { + tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values */ + tdm_Pri_pitch_buf_fx[i] = s_max( tmp16, PIT_MIN << 6 ); /* pitch is represented in Q6*/ + move16(); + } + } + ELSE + { + Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); + } +#else /* This is only to keep the buffer up-to-date */ Word16 mult_factor = 26214 /*0.8f in Q15*/; Word16 min_tdm_Pri_pitch_buf_fx = 0; @@ -919,7 +940,7 @@ void td_stereo_param_updt_fx( { Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); } - +#endif return; } #endif diff --git a/lib_com/options.h b/lib_com/options.h index 5a623804108a9d8c1f56c331da01da89e2f05840..54efb5ce124eaa1848f1cd7f6902b441c68bec17 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -146,6 +146,8 @@ #define FIX_778_STEREO_BRATE_SWITCHING #define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ #define FIX_729_MISSING_RESCALING +#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ +#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 12927bceb3449339952af06bf8fca169565281da..131a12285d012ee49e84671c2a3c4f3cbb9e3ee6 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -5501,7 +5501,7 @@ void lsf_dec_fx( Word16 *lsp_new, /* o : de-quantized LSP vector */ Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -5615,9 +5615,9 @@ void lsf_end_dec_fx( Word16 *lpc_param, Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ Word16 *nb_indices -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const float tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] #endif ); diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index dd25918d25b859f3281838248f80369b6b316485..c3cf9be3b05ec2c1dd87855be901d29e1bff9399 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -801,7 +801,7 @@ ivas_error acelp_core_dec_fx( #endif { lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , tdm_lsfQ_PCh #endif diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 3679bde9824c1958c816a91bbefcc5de0eef00ff..905db1091f9d46f81613c803a14e11d537251de5 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -848,7 +848,11 @@ ivas_error acelp_core_dec_ivas_fx( IF( !tdm_lp_reuse_flag ) { +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); +#else lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); +#endif } ELSE { diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 2b938920f98bda4ffbc7de45fe2bb5fa8086aa72..d6b5984a61f95175b1656d6a95a200f4677a136d 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -114,7 +114,7 @@ void CNG_dec_fx( ELSE { lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index c024f1622ba66c2404f94f5edd2b4ef93eb1c0d2..83436ea9968adfe12a5ac6b23d075df55b69ca7e 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -51,7 +51,7 @@ void lpc_unquantize_fx( IF( ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( EQ_16( coder_type, UNVOICED ) ) ) { lsf_end_dec_fx( st, 1, GENERIC, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif @@ -62,7 +62,7 @@ void lpc_unquantize_fx( IF( EQ_16( st->core, TCX_20_CORE ) ) { lsf_end_dec_fx( st, 1, AUDIO, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif @@ -71,7 +71,7 @@ void lpc_unquantize_fx( ELSE { lsf_end_dec_fx( st, 1, coder_type, sub( 1, st->narrowBand ) /* st->bwidth */, ENDLSF_NBITS, &lsf[m], param_lpc, LSF_Q_prediction, &nb_indices -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 6ccf133f1fb78f5a46675a32941a10b25682c41b..8bbbd12e8b1480a97ae8de2e333f78aef3fdc950 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -671,7 +671,12 @@ ivas_error ivas_core_dec( Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, - tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q6 ); + tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Q6 +#endif + ); Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); } diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 407ea463fc54328a388afbe49d050213a4636194..9ba2e84d79bb4aa303e0b994630e1f774599af3c 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -8,9 +8,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE #include "ivas_prot.h" -#include "ivas_rom_com.h" +//#include "ivas_rom_com.h" #endif /*-------------------------------------------------------------------* * Local functions @@ -110,7 +110,7 @@ void lsf_dec_fx( Word16 *lsp_new, /* o : de-quantized LSP vector */ Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector */ const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -124,9 +124,7 @@ void lsf_dec_fx( Word16 tmp_old[M + 1], tmp_new[M + 1]; Word16 enr_old = 0, enr_new = 0; Word16 lsf_diff, coder_type; -#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void) ( tdm_low_rate_mode ); -#endif + /* initialize */ coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) @@ -180,7 +178,12 @@ 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 ); + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + tdm_lsfQ_PCh +#endif + ); /* convert quantized LSFs to LSPs */ @@ -367,7 +370,7 @@ void lsf_end_dec_fx( Word16 *lpc_param, /* i : LPC parameters */ Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ Word16 *nb_indices /* o : number of indices */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -395,7 +398,7 @@ void lsf_end_dec_fx( Word16 coder_type; Word16 ber_flag; Word16 flag_1bit_gran; -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); @@ -456,7 +459,7 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ @@ -500,16 +503,15 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Read indices from array *--------------------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Make sure there are the correct bit allocations */ - IF( st->idchan == 1 && predmode > 2 ) + IF( EQ_16( st->idchan, 1 ) && GT_16( predmode, 2 ) ) { - PMTE() /* use same AR prediction bit allocation for intra and inter modes*/ - lsf_allocate( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); stages0 = stages1; - mvs2s( levels1, levels0, stages0 ); - mvs2s( bits1, bits0, stages0 ); + Copy( levels1, levels0, stages0 ); + Copy( bits1, bits0, stages0 ); } #endif @@ -680,26 +682,26 @@ void lsf_end_dec_fx( { pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) + if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { - tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } #endif IF( safety_net ) { /* LVQ */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ st->BER_detect = st->BER_detect | - vq_dec_lvq( 0, qlsf, &lindice[1], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ); - v_add( qlsf, pred3, qlsf, M ); - v_sub( qlsf, pred1, st->mem_MA, M ); + Vr_add( qlsf, pred3, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } else #endif @@ -721,7 +723,7 @@ void lsf_end_dec_fx( } ELSE { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE IF( EQ_16( predmode, 4 ) ) { mode_lvq_p = 9; @@ -741,7 +743,7 @@ void lsf_end_dec_fx( &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); } st->BER_detect = s_or( st->BER_detect, ber_flag ); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */ #else