From e051afd7b0062698fee0545b0fae03212e3a5f36 Mon Sep 17 00:00:00 2001 From: gaoyuy Date: Thu, 23 Mar 2023 23:48:22 +0800 Subject: [PATCH 1/4] Fixed issue-84 --- lib_com/bits_alloc.c | 7 +++++++ lib_com/options.h | 7 ++++++- lib_com/prot.h | 5 +++++ lib_dec/acelp_core_dec.c | 23 +++++++++++++++++++++++ lib_dec/acelp_core_switch_dec.c | 4 ++++ lib_dec/gs_dec.c | 4 ++++ lib_enc/acelp_core_enc.c | 25 +++++++++++++++++++++++++ lib_enc/acelp_core_switch_enc.c | 4 ++++ lib_enc/evs_enc.c | 4 ++++ lib_enc/ivas_core_enc.c | 4 ++++ lib_enc/transition_enc.c | 8 ++++++++ 11 files changed, 94 insertions(+), 1 deletion(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 41acc25b48..0c019efa1f 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -536,6 +536,9 @@ ivas_error config_acelp1( const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const int16_t idchan, /* i : stereo channel ID */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + const int16_t active_cnt, /* i :active counts*/ +#endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */ @@ -754,7 +757,11 @@ ivas_error config_acelp1( bits -= acelp_cfg->mid_lsf_bits; } #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1) +#else else if ( tdm_lp_reuse_flag == 1 && idchan == 1 ) +#endif { bits -= TDM_IC_LSF_PRED_BITS; } diff --git a/lib_com/options.h b/lib_com/options.h index 1c133b109b..6d11ff8b8d 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -136,7 +136,12 @@ #define LSF_RE_USE_SECONDARY_CHANNEL /* TD stereo Secondary channel LSF Q improvement */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL -/*#define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE */ /* switch to isolate the reuse mode case */ +#define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE /* switch to isolate the reuse mode case */ + +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE +#define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX /* lsf reuse mode bug fix */ +#endif + #endif #define DISABLE_ADAP_RES_COD_TMP /* temporary fix for IVAS-403, disables adaptive residual coding */ /*#define ITD_WINNER_GAIN_MODIFY */ /* ITD optimization - WORK IN PROGRESS */ diff --git a/lib_com/prot.h b/lib_com/prot.h index de6c521048..d8823d54dd 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2327,7 +2327,9 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ +#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ +#endif const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); @@ -8984,6 +8986,9 @@ ivas_error config_acelp1( const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel*/ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ const int16_t idchan, /* i : channel id */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + const int16_t active_cnt, /* i :active counts*/ +#endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t GSC_IVAS_mode /* i : GSC IVAS mode */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index b0d30e88dd..e3e0c818af 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -614,11 +614,19 @@ ivas_error acelp_core_dec( nb_bits = -1; } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif if ( st->coder_type == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME ) /* ISfm: why is this called again after above */ { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } } @@ -661,10 +669,25 @@ ivas_error acelp_core_dec( { const float *pt_interp_2; #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + if ( st->active_cnt != 1 ) + { + int16_t beta_index[1]; + + beta_index[0] = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); + tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, beta_index ); + } + else + { + mvr2r( tdm_lspQ_PCh, lsp_new, M ); + mvr2r( tdm_lsfQ_PCh, lsf_new, M ); + } +#else int16_t beta_index[1]; beta_index[0] = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, beta_index ); +#endif #else mvr2r( tdm_lspQ_PCh, lsp_new, M ); mvr2r( tdm_lsfQ_PCh, lsf_new, M ); diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index 6953551452..f90be841db 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -158,7 +158,11 @@ ivas_error acelp_core_switch_dec( * Excitation decoding *----------------------------------------------------------------*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, st->active_cnt, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); +#else config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); +#endif decod_gen_voic_core_switch( st, L_frame_for_cs, 0, Aq, exc, cbrate ); diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index e8112c6c4d..5a8b56e33c 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -111,7 +111,11 @@ void decod_audio( } /* set bit-allocation */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif /*---------------------------------------------------------------* * Decode energy dynamics diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 48cdb5c536..b99aebff31 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -75,7 +75,9 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ +#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ +#endif const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { @@ -374,7 +376,11 @@ ivas_error acelp_core_enc( uc_two_stage_flag = 0; if ( !nelp_mode && !ppp_mode ) { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } /*-----------------------------------------------------------------* @@ -434,12 +440,14 @@ ivas_error acelp_core_enc( push_indice( hBstr, IND_IC_LSF_PRED, beta_index[0], TDM_IC_LSF_PRED_BITS ); } +#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX if ( st->active_cnt == 1 ) { mvr2r( lsp_new, st->lsp_old, M ); lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); } +#endif #else if ( st->active_cnt != 1 ) { @@ -452,6 +460,14 @@ ivas_error acelp_core_enc( { pt_interp_2 = interpol_frac2; } +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + if ( st->active_cnt == 1 ) + { + mvr2r( lsp_new, st->lsp_old, M ); + lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); + lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); + } +#else #ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE if ( st->active_cnt == 1 ) { @@ -459,6 +475,7 @@ ivas_error acelp_core_enc( lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); } +#endif #endif /* LSP interpolation and conversion of LSPs to A(z) */ int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); @@ -503,7 +520,11 @@ ivas_error acelp_core_enc( { tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } /*---------------------------------------------------------------* @@ -561,7 +582,11 @@ ivas_error acelp_core_enc( lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); /* Configure ACELP bit allocation */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif /* redo LSF quantization */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c index 291c2128a1..be2331c7ae 100644 --- a/lib_enc/acelp_core_switch_enc.c +++ b/lib_enc/acelp_core_switch_enc.c @@ -151,7 +151,11 @@ void acelp_core_switch_enc( * Excitation encoding *----------------------------------------------------------------*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); +#endif encod_gen_voic_core_switch( st, st->last_L_frame, inp, Aq, A, T_op, st->voicing, exc, cbrate ); diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index b90f10359b..a8b3fbd4b7 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -242,7 +242,11 @@ ivas_error evs_enc( if ( st->core == ACELP_CORE ) { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL ) ) != IVAS_ERR_OK ) +#else if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index e53033ab98..35bb7ef504 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -219,7 +219,11 @@ ivas_error ivas_core_enc( if ( st->core == ACELP_CORE ) { /* ACELP core encoder */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) +#else if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index ce13d7fa36..5736cfe5e0 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -178,7 +178,11 @@ void transition_enc( if ( *tc_subfr == TC_0_0 ) { /* this is called only to compute unused bits */ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#endif } *clip_gain = gp_clip( st->element_mode, st->core_brate, st->voicing, i_subfr, TRANSITION, xn, gp_cl ); @@ -274,7 +278,11 @@ void transition_enc( if ( i_subfr - *tc_subfr <= L_SUBFR ) { +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#endif } /*-----------------------------------------------------------------* -- GitLab From 2566c5e4fdb2093b228d76a6ad927739007da31e Mon Sep 17 00:00:00 2001 From: advasila Date: Fri, 21 Apr 2023 18:49:25 +0300 Subject: [PATCH 2/4] format --- lib_enc/acelp_core_enc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index b99aebff31..002ddce270 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -76,9 +76,9 @@ ivas_error acelp_core_enc( int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ #ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ #endif - const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { int16_t i, nBits; /* reserved bits */ -- GitLab From b195273797d153914e2a7d4a9f39e0ed4078514d Mon Sep 17 00:00:00 2001 From: advasila Date: Fri, 21 Apr 2023 19:21:10 +0300 Subject: [PATCH 3/4] clang-formatting --- lib_com/bits_alloc.c | 44 +++++++++++++++++++++--------------------- lib_com/prot.h | 46 ++++++++++++++++++++++---------------------- lib_enc/evs_enc.c | 2 +- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 0c019efa1f..d01d7e9fa4 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -516,28 +516,28 @@ static ivas_error acelp_FCB_allocator( *--------------------------------------------------------------------*/ ivas_error config_acelp1( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t total_brate, /* i : total bitrate */ - const int32_t core_brate_inp, /* i : core bitrate */ - const int16_t core, /* i : core */ - const int16_t extl, /* i : extension layer */ - const int32_t extl_brate, /* i : extension layer bitrate */ - const int16_t L_frame, /* i : frame length at internal Fs */ - const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const int16_t signaling_bits, /* i : number of signaling bits */ - const int16_t coder_type, /* i : coder type */ - const int16_t tc_subfr, /* i : TC subfr ID */ - const int16_t tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - int16_t *unbits, /* o : number of unused bits */ - const int16_t element_mode, /* i : element mode */ - int16_t *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const int16_t idchan, /* i : stereo channel ID */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t core_brate_inp, /* i : core bitrate */ + const int16_t core, /* i : core */ + const int16_t extl, /* i : extension layer */ + const int32_t extl_brate, /* i : extension layer bitrate */ + const int16_t L_frame, /* i : frame length at internal Fs */ + const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ + const int16_t signaling_bits, /* i : number of signaling bits */ + const int16_t coder_type, /* i : coder type */ + const int16_t tc_subfr, /* i : TC subfr ID */ + const int16_t tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ + int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ + int16_t *unbits, /* o : number of unused bits */ + const int16_t element_mode, /* i : element mode */ + int16_t *uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ + const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const int16_t idchan, /* i : stereo channel ID */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const int16_t active_cnt, /* i :active counts*/ + const int16_t active_cnt, /* i :active counts*/ #endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ @@ -758,7 +758,7 @@ ivas_error config_acelp1( } #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1) + else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) #else else if ( tdm_lp_reuse_flag == 1 && idchan == 1 ) #endif diff --git a/lib_com/prot.h b/lib_com/prot.h index e3a446abff..02a5c82822 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2324,9 +2324,9 @@ ivas_error acelp_core_enc( int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ #ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ #endif - const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); ivas_error acelp_core_switch_dec_bfi( @@ -8976,28 +8976,28 @@ int16_t BITS_ALLOC_config_acelp( ); ivas_error config_acelp1( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t total_brate, /* i : total bitrate */ - const int32_t core_brate_inp, /* i : core bitrate */ - const int16_t core, /* i : core */ - const int16_t extl, /* i : extension layer */ - const int32_t extl_brate, /* i : extension layer bitrate */ - const int16_t L_frame, /* i : frame length at internal Fs */ - const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const int16_t signaling_bits, /* i : number of signaling bits */ - const int16_t coder_type, /* i : coder type */ - const int16_t tc_subfr, /* i : TC subfr ID */ - const int16_t tc_call, /* i : TC call number (0,1,2) */ - int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - int16_t *unbits, /* o : number of unused bits */ - const int16_t element_mode, /* i : element mode */ - int16_t *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel*/ - const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ - const int16_t idchan, /* i : channel id */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t core_brate_inp, /* i : core bitrate */ + const int16_t core, /* i : core */ + const int16_t extl, /* i : extension layer */ + const int32_t extl_brate, /* i : extension layer bitrate */ + const int16_t L_frame, /* i : frame length at internal Fs */ + const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ + const int16_t signaling_bits, /* i : number of signaling bits */ + const int16_t coder_type, /* i : coder type */ + const int16_t tc_subfr, /* i : TC subfr ID */ + const int16_t tc_call, /* i : TC call number (0,1,2) */ + int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ + int16_t *unbits, /* o : number of unused bits */ + const int16_t element_mode, /* i : element mode */ + int16_t *uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel*/ + const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ + const int16_t idchan, /* i : channel id */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const int16_t active_cnt, /* i :active counts*/ + const int16_t active_cnt, /* i :active counts*/ #endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index 353e432d18..9855b334ea 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -243,7 +243,7 @@ ivas_error evs_enc( if ( st->core == ACELP_CORE ) { #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL ) ) != IVAS_ERR_OK ) #else if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) #endif -- GitLab From dcbfaed7e3b202c4b91cbd084a9600d270c9fe7c Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Apr 2023 13:55:22 +0200 Subject: [PATCH 4/4] formal improvements --- lib_com/bits_alloc.c | 10 +-- lib_com/ivas_cnst.h | 2 +- lib_com/ivas_prot.h | 8 +- lib_com/ivas_rom_com.c | 8 +- lib_com/ivas_rom_com.h | 8 +- lib_com/ivas_stereo_td_bit_alloc.c | 135 ++++++++++++++--------------- lib_com/options.h | 5 -- lib_com/prot.h | 22 ++--- lib_dec/acelp_core_dec.c | 26 +++--- lib_dec/acelp_core_switch_dec.c | 2 +- lib_dec/cng_dec.c | 10 +-- lib_dec/dlpc_stoch.c | 23 +++-- lib_dec/gs_dec.c | 2 +- lib_dec/lsf_dec.c | 18 ++-- lib_enc/acelp_core_enc.c | 38 +++----- lib_enc/acelp_core_switch_enc.c | 2 +- lib_enc/evs_enc.c | 2 +- lib_enc/ivas_core_enc.c | 2 +- lib_enc/lsf_enc.c | 13 +-- lib_enc/qlpc_stoch.c | 15 ++-- lib_enc/transition_enc.c | 4 +- 21 files changed, 161 insertions(+), 194 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index d01d7e9fa4..a162e40be3 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -536,8 +536,8 @@ ivas_error config_acelp1( const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const int16_t idchan, /* i : stereo channel ID */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const int16_t active_cnt, /* i :active counts*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE + const int16_t active_cnt, /* i : Active frame counter */ #endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ @@ -757,15 +757,12 @@ ivas_error config_acelp1( bits -= acelp_cfg->mid_lsf_bits; } #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) -#else - else if ( tdm_lp_reuse_flag == 1 && idchan == 1 ) -#endif { bits -= TDM_IC_LSF_PRED_BITS; } #endif + /* gain Q bit-budget - part 1 */ if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) || ( coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE ) ) { @@ -1330,6 +1327,7 @@ ivas_error config_acelp1( else { int16_t nb_prm = 4; + if ( tdm_low_rate_mode == 1 ) { nb_prm = 2; diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index afda1b66f4..424df1878e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -793,7 +793,7 @@ enum fea_names #define TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS + STEREO_BITS_TCA ) #ifdef LSF_RE_USE_SECONDARY_CHANNEL #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE -#define TDM_IC_LSF_PRED_BITS 1 /* Number of bits to code the inter channel lsf prediction mode */ +#define TDM_IC_LSF_PRED_BITS 1 /* number of bits to code the inter channel LSF prediction mode */ #endif #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a5fd75ef21..261b1d38a8 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1919,18 +1919,18 @@ void tdm_low_rate_dec( void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ - float *pred_lsf_secondary /* o : predicted secondary channel LSFs */ + float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ ); #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE void tdm_SCh_lsf_reuse( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t element_brate, /* i : element bitrate */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t element_brate, /* i : element bitrate */ float lsf_new[M], /* i/o: LSFs at the end of the frame */ float lsp_new[M], /* i/o: LSPs at the end of the frame */ const float tdm_lsfQ_PCh[M], /* i : primary channel LSFs */ const float lsf_wgts[M], /* i : LSF weights */ - int16_t beta_index[] /* i/o: quantization index */ + int16_t *beta_index /* i/o: quantization index */ ); #endif #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 952a32cb4c..6677b53a9f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -669,10 +669,10 @@ const float tdm_LSF_MEAN_RE_USE[M] = 3299.107307F, 3686.249102F, 4034.473656F, 4393.818819F, 4781.683038F, 5155.954294F, 5542.569582F, 5927.377309F }; -const float tdm_Beta_Q1bit_re_use_132[2] = { 0.97F, 0.75F }; -const float tdm_Beta_Q1bit_re_use_164[2] = { 0.95F, 0.71F }; -const float tdm_Beta_Q1bit_re_use_244_320[2] = { 0.93F, 0.73F }; -const float tdm_Beta_Q1bit_re_use_480[2] = { 0.97F, 0.77F }; +const float tdm_Beta_Q1bit_re_use_13k2[2] = { 0.97F, 0.75F }; +const float tdm_Beta_Q1bit_re_use_16k4[2] = { 0.95F, 0.71F }; +const float tdm_Beta_Q1bit_re_use_24k4_32k[2] = { 0.93F, 0.73F }; +const float tdm_Beta_Q1bit_re_use_48k[2] = { 0.97F, 0.77F }; const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15] = { diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 87e4f62dcf..9e3c431e70 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -115,10 +115,10 @@ extern const float tdm_LSF_MEAN_RE_USE_OUT[M]; extern const float tdm_LSF_MEAN_RE_USE_IN[M]; extern const float tdm_LSF_MEAN_RE_USE[M]; -extern const float tdm_Beta_Q1bit_re_use_132[2]; -extern const float tdm_Beta_Q1bit_re_use_164[2]; -extern const float tdm_Beta_Q1bit_re_use_244_320[2]; -extern const float tdm_Beta_Q1bit_re_use_480[2]; +extern const float tdm_Beta_Q1bit_re_use_13k2[2]; +extern const float tdm_Beta_Q1bit_re_use_16k4[2]; +extern const float tdm_Beta_Q1bit_re_use_24k4_32k[2]; +extern const float tdm_Beta_Q1bit_re_use_48k[2]; extern const float tdm_RE_USE_adaptive_beta_prd_diag_3[15 + 16 + 15]; #endif diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 8b93558b21..b1fa0a49c8 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -487,7 +487,7 @@ void td_stereo_param_updt( static void tdm_SCh_LSF_intra_pred_zero_bits( const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ - float *pred_lsf_secondary, /* o : predicted secondary channel LSFs */ + float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */ const float *lsf_mean, /* i : secondary channel mean LSFs */ const float beta /* i : pull to average beta factor */ ) @@ -497,7 +497,7 @@ static void tdm_SCh_LSF_intra_pred_zero_bits( /* pulling the LSFs closer to the average */ for ( i = 0; i < M; i++ ) { - pred_lsf_secondary[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i]; + pred_lsf_SCh[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i]; } return; @@ -511,7 +511,7 @@ static void tdm_SCh_LSF_intra_pred_zero_bits( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( - float *lsf_secondary, /* i/o: secondary channel LSFs */ + float *lsf_SCh, /* i/o: secondary channel LSFs */ const float *lsf_mean_in, /* i : secondary channel mean LSFs (in) */ const float *lsf_mean_out, /* i : secondary channel mean LSFs (out) */ const float *prd_diag_3 /* i : secondary channel mean LSFs */ @@ -522,37 +522,38 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( const float *prd_ptr; float *lsf_tmp_ptr1; float *lsf_tmp_ptr2; - float *lsf_second_ptr; + float *lsf_SCh_ptr; prd_ptr = prd_diag_3; - v_sub( lsf_secondary, lsf_mean_in, lsf_tmp, M ); + v_sub( lsf_SCh, lsf_mean_in, lsf_tmp, M ); lsf_tmp_ptr1 = lsf_tmp; - lsf_second_ptr = lsf_secondary; + lsf_SCh_ptr = lsf_SCh; lsf_tmp_ptr2 = lsf_tmp_ptr1; - *lsf_second_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); - ( *lsf_second_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ ); + *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); + ( *lsf_SCh_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ ); for ( i = 1; i < M - 1; i++ ) { lsf_tmp_ptr1 = lsf_tmp_ptr2; - *lsf_second_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); + *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); lsf_tmp_ptr2 = lsf_tmp_ptr1; - *lsf_second_ptr += ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); - ( *lsf_second_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ ); + *lsf_SCh_ptr += ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); + ( *lsf_SCh_ptr++ ) += ( *lsf_tmp_ptr1 ) * ( *prd_ptr++ ); } lsf_tmp_ptr1 = lsf_tmp_ptr2; - *lsf_second_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); - *lsf_second_ptr += ( *lsf_tmp_ptr1 ) * ( *prd_ptr ); + *lsf_SCh_ptr = ( *lsf_tmp_ptr1++ ) * ( *prd_ptr++ ); + *lsf_SCh_ptr += ( *lsf_tmp_ptr1 ) * ( *prd_ptr ); - v_add( lsf_secondary, lsf_mean_out, lsf_secondary, M ); + v_add( lsf_SCh, lsf_mean_out, lsf_SCh, M ); return; } + /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred() * @@ -562,7 +563,7 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ - float *pred_lsf_secondary /* o : predicted secondary channel LSFs */ + float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ ) { float fixed_beta; @@ -588,15 +589,45 @@ void tdm_SCh_LSF_intra_pred( fixed_beta = 0.91F; } - tdm_SCh_LSF_intra_pred_zero_bits( tdm_lsfQ_PCh, pred_lsf_secondary, tdm_LSF_MEAN_PRED_QNT, fixed_beta ); + tdm_SCh_LSF_intra_pred_zero_bits( tdm_lsfQ_PCh, pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT, fixed_beta ); - tdm_SCh_LSF_intra_pred_tri_diag_mat( pred_lsf_secondary, tdm_LSF_MEAN_PRED_QNT_IN, tdm_LSF_MEAN_PRED_QNT_OUT, tdm_PRED_QNT_fixed_beta_prd_diag_3 ); + tdm_SCh_LSF_intra_pred_tri_diag_mat( pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT_IN, tdm_LSF_MEAN_PRED_QNT_OUT, tdm_PRED_QNT_fixed_beta_prd_diag_3 ); return; } #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE + +/*-------------------------------------------------------------------* + * tdm_SCh_LSF_intra_pred_one_bit_dec() + * + * + *-------------------------------------------------------------------*/ + +static void tdm_SCh_LSF_intra_pred_one_bit_dec( + const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ + float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */ + const float *lsf_mean, /* i : secondary channel mean LSFs */ + const float *Beta_Q_x, /* i : beta quantization values */ + const int16_t beta_index /* i : the quantization bits for beta (-1 if beta fixed)*/ +) +{ + int16_t i; + float beta; + + beta = Beta_Q_x[beta_index]; + + /* pulling the LSFs closer to the avergae */ + for ( i = 0; i < M; i++ ) + { + pred_lsf_SCh[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i]; + } + + return; +} + + /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_enc() * @@ -604,29 +635,28 @@ void tdm_SCh_LSF_intra_pred( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_one_bit_enc( - const float *lsf_secondary, /* i : secondary channel LSFs */ - const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ - float *pred_lsf_secondary, /* o : predicted secondary channel LSFs */ - const float *lsf_mean, /* i : secondary channel mean LSFs */ - const float *lsf_wgts_new, /* i : Improved wgts for LSFs */ - const float *Beta_Q_x, /* i : beta quantization values */ - int16_t *beta_index /* o : the quantization bits for beta (-1 if beta fixed) */ + const float *lsf_SCh, /* i : secondary channel LSFs */ + const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ + float *pred_lsf_SCh, /* o : predicted secondary channel LSFs */ + const float *lsf_mean, /* i : secondary channel mean LSFs */ + const float *lsf_wgts_new, /* i : Improved wgts for LSFs */ + const float *Beta_Q_x, /* i : beta quantization values */ + int16_t *beta_index /* o : the quantization bits for beta (-1 if beta fixed) */ ) { int16_t i; float A_temp[M]; float B_temp[M]; float WD[2]; - float beta; for ( i = 0; i < M; i++ ) { - A_temp[i] = lsf_secondary[i] - lsf_mean[i]; + A_temp[i] = lsf_SCh[i] - lsf_mean[i]; B_temp[i] = lsf_mean[i] - tdm_lsfQ_PCh[i]; } - WD[0] = 0.; - WD[1] = 0.; + WD[0] = 0.f; + WD[1] = 0.f; for ( i = 0; i < M; i++ ) { WD[0] += lsf_wgts_new[i] * SQR( A_temp[i] ) + 2.0f * Beta_Q_x[0] * lsf_wgts_new[i] * A_temp[i] * B_temp[i] + lsf_wgts_new[i] * SQR( Beta_Q_x[0] ) * SQR( B_temp[i] ); @@ -635,49 +665,14 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( if ( WD[0] < WD[1] ) { - beta = Beta_Q_x[0]; *beta_index = 0; } else { - beta = Beta_Q_x[1]; *beta_index = 1; } - /* pulling the LSFs closer to the avergae */ - for ( i = 0; i < M; i++ ) - { - pred_lsf_secondary[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i]; - } - - return; -} - - -/*-------------------------------------------------------------------* - * tdm_SCh_LSF_intra_pred_one_bit_dec() - * - * - *-------------------------------------------------------------------*/ - -static void tdm_SCh_LSF_intra_pred_one_bit_dec( - const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ - float *pred_lsf_secondary, /* o : predicted secondary channel LSFs */ - const float *lsf_mean, /* i : secondary channel mean LSFs */ - const float *Beta_Q_x, /* i : beta quantization values */ - const int16_t beta_index /* i : the quantization bits for beta (-1 if beta fixed)*/ -) -{ - int16_t i; - float beta; - - beta = Beta_Q_x[beta_index]; - - /* pulling the LSFs closer to the avergae */ - for ( i = 0; i < M; i++ ) - { - pred_lsf_secondary[i] = beta * tdm_lsfQ_PCh[i] + ( 1.0f - beta ) * lsf_mean[i]; - } + tdm_SCh_LSF_intra_pred_one_bit_dec( tdm_lsfQ_PCh, pred_lsf_SCh, tdm_LSF_MEAN_RE_USE, Beta_Q_x, *beta_index ); return; } @@ -696,26 +691,26 @@ void tdm_SCh_lsf_reuse( float lsp_new[M], /* i/o: LSPs at the end of the frame */ const float tdm_lsfQ_PCh[M], /* i : primary channel LSFs */ const float lsf_wgts[M], /* i : LSF weights */ - int16_t beta_index[] /* i/o: quantization index */ + int16_t *beta_index /* i/o: quantization index */ ) { const float *Beta_Q1bit_re_use; if ( element_brate <= IVAS_13k2 ) { - Beta_Q1bit_re_use = &tdm_Beta_Q1bit_re_use_132[0]; + Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_13k2; } else if ( element_brate <= IVAS_16k4 ) { - Beta_Q1bit_re_use = &tdm_Beta_Q1bit_re_use_164[0]; + Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_16k4; } else if ( element_brate <= IVAS_32k ) { - Beta_Q1bit_re_use = &tdm_Beta_Q1bit_re_use_244_320[0]; + Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_24k4_32k; } else { - Beta_Q1bit_re_use = &tdm_Beta_Q1bit_re_use_480[0]; + Beta_Q1bit_re_use = tdm_Beta_Q1bit_re_use_48k; } if ( enc_dec == ENC ) @@ -729,7 +724,7 @@ void tdm_SCh_lsf_reuse( tdm_SCh_LSF_intra_pred_tri_diag_mat( lsf_new, tdm_LSF_MEAN_RE_USE_IN, tdm_LSF_MEAN_RE_USE_OUT, tdm_RE_USE_adaptive_beta_prd_diag_3 ); - lsf2lsp( lsf_new, lsp_new, M, 12800 ); + lsf2lsp( lsf_new, lsp_new, M, INT_FS_12k8 ); return; } diff --git a/lib_com/options.h b/lib_com/options.h index 86ce9ed1d9..9f016d519a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -137,11 +137,6 @@ #define LSF_RE_USE_SECONDARY_CHANNEL /* TD stereo Secondary channel LSF Q improvement */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL #define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE /* switch to isolate the reuse mode case */ - -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE -#define LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX /* lsf reuse mode bug fix */ -#endif - #endif #define DISABLE_ADAP_RES_COD_TMP /* temporary fix for IVAS-403, disables adaptive residual coding */ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ diff --git a/lib_com/prot.h b/lib_com/prot.h index a4bf2529ec..f3829d914f 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2323,7 +2323,7 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ -#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ #endif const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ @@ -8216,14 +8216,14 @@ void lsf_end_enc( ); void lsf_end_dec( - Decoder_State *st, - const int16_t coder_type_org, - const int16_t bwidth, - const int16_t nBits, - float *qlsf, - int16_t *lpc_param, - int16_t *LSF_Q_prediction, /* o : LSF prediction mode */ - int16_t *nb_indices + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t coder_type_org, /* i : coding type */ + const int16_t bwidth, /* i : input signal bandwidth */ + const int16_t nBits, /* i : number of bits used for ISF quantization*/ + float *qlsf, /* o : quantized LSFs in the cosine domain */ + int16_t *lpc_param, /* i : LPC parameters */ + int16_t *LSF_Q_prediction, /* o : LSF prediction mode */ + int16_t *nb_indices /* o : number of indices */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL , const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ @@ -8988,8 +8988,8 @@ ivas_error config_acelp1( const int16_t tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel*/ const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ const int16_t idchan, /* i : channel id */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - const int16_t active_cnt, /* i :active counts*/ +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE + const int16_t active_cnt, /* i : Active frame counter */ #endif const int16_t tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 5573b7d541..c89c5f53b0 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -627,7 +627,7 @@ ivas_error acelp_core_dec( nb_bits = -1; } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -635,7 +635,7 @@ ivas_error acelp_core_dec( if ( st->coder_type == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME ) /* ISfm: why is this called again after above */ { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -671,40 +671,34 @@ ivas_error acelp_core_dec( if ( !tdm_lp_reuse_flag ) { - lsf_dec( st, tc_subfr, Aq, &LSF_Q_prediction, lsf_new, lsp_new, lsp_mid, tdm_low_rate_mode #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - tdm_lsfQ_PCh + lsf_dec( st, tc_subfr, Aq, &LSF_Q_prediction, lsf_new, lsp_new, lsp_mid, tdm_low_rate_mode, tdm_lsfQ_PCh ); +#else + lsf_dec( st, tc_subfr, Aq, &LSF_Q_prediction, lsf_new, lsp_new, lsp_mid, tdm_low_rate_mode ); #endif - ); } else { const float *pt_interp_2; + #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX if ( st->active_cnt != 1 ) { - int16_t beta_index[1]; + int16_t beta_index; - beta_index[0] = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); - tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, beta_index ); + beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); + tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index ); } else { mvr2r( tdm_lspQ_PCh, lsp_new, M ); mvr2r( tdm_lsfQ_PCh, lsf_new, M ); } -#else - int16_t beta_index[1]; - - beta_index[0] = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); - tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, beta_index ); -#endif #else mvr2r( tdm_lspQ_PCh, lsp_new, M ); mvr2r( tdm_lsfQ_PCh, lsf_new, M ); #endif + if ( st->rate_switching_reset ) { /* extrapolation in case of unstable LSF convert */ diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index f90be841db..4a49d6b2db 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -158,7 +158,7 @@ ivas_error acelp_core_switch_dec( * Excitation decoding *----------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, st->active_cnt, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); #else config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c index b780db062f..6d02f18309 100644 --- a/lib_dec/cng_dec.c +++ b/lib_dec/cng_dec.c @@ -109,13 +109,13 @@ void CNG_dec( } else { - lsf_dec( st, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL -#endif - ); + lsf_dec( st, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, NULL ); + } +#else + lsf_dec( st, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 ); } +#endif } else { diff --git a/lib_dec/dlpc_stoch.c b/lib_dec/dlpc_stoch.c index 1bbba46b1b..9a86d06224 100644 --- a/lib_dec/dlpc_stoch.c +++ b/lib_dec/dlpc_stoch.c @@ -81,32 +81,31 @@ void lpc_unquantize( { if ( st->sr_core == INT_FS_16k && coder_type == UNVOICED ) { - lsf_end_dec( st, GENERIC, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL + lsf_end_dec( st, GENERIC, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices, NULL ); +#else + lsf_end_dec( st, GENERIC, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices ); #endif - ); } else { if ( st->core == TCX_20_CORE ) { - lsf_end_dec( st, AUDIO, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL + lsf_end_dec( st, AUDIO, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices, NULL ); +#else + lsf_end_dec( st, AUDIO, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices ); #endif - ); } else { - lsf_end_dec( st, coder_type, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL -#endif + lsf_end_dec( st, coder_type, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices, NULL ); +#else + lsf_end_dec( st, coder_type, 1 - st->narrowBand /* st->bwidth */, ENDLSF_NBITS, &lsf[M], param_lpc, LSF_Q_prediction, &nb_indices + ); +#endif } } diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index 5a8b56e33c..29e134db25 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -111,7 +111,7 @@ void decod_audio( } /* set bit-allocation */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); diff --git a/lib_dec/lsf_dec.c b/lib_dec/lsf_dec.c index e29cc480a2..6aa31243af 100644 --- a/lib_dec/lsf_dec.c +++ b/lib_dec/lsf_dec.c @@ -264,12 +264,12 @@ void lsf_end_dec( const int16_t bwidth, /* i : input signal bandwidth */ const int16_t nBits_in, /* i : number of bits used for ISF quantization*/ float *qlsf, /* o : quantized LSFs in the cosine domain */ - int16_t *lpc_param, - int16_t *LSF_Q_prediction, /* o : LSF prediction mode */ - int16_t *nb_indices + int16_t *lpc_param, /* i : LPC parameters */ + int16_t *LSF_Q_prediction, /* o : LSF prediction mode */ + int16_t *nb_indices /* o : number of indices */ #ifdef LSF_RE_USE_SECONDARY_CHANNEL , - const float tdm_lsfQ_PCh[M] + const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif ) { @@ -295,6 +295,7 @@ void lsf_end_dec( #ifdef LSF_RE_USE_SECONDARY_CHANNEL float pred3[M]; #endif + flag_1bit_gran = ( st->element_mode > EVS_MONO ); nBits = nBits_in; *nb_indices = 0; @@ -343,6 +344,8 @@ void lsf_end_dec( * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ + p_lpc_param = lpc_param; + #ifdef LSF_RE_USE_SECONDARY_CHANNEL if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { @@ -350,7 +353,6 @@ void lsf_end_dec( predmode += 3; } #endif - p_lpc_param = lpc_param; if ( predmode == 0 ) { @@ -579,11 +581,11 @@ void lsf_end_dec( st->BER_detect = st->BER_detect | vq_dec_lvq( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); - if ( predmode == 1 #ifdef LSF_RE_USE_SECONDARY_CHANNEL - || ( predmode == 4 ) + if ( predmode == 1 || ( predmode == 4 ) ) /* MA only */ +#else + if ( predmode == 1 ) /* MA only */ #endif - ) /* MA only */ { mvr2r( qlsf, st->mem_MA, M ); v_add( qlsf, pred1, qlsf, M ); diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 002ddce270..0310a713e3 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -75,7 +75,7 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ -#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ #endif const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ @@ -374,9 +374,10 @@ ivas_error acelp_core_enc( nb_bits = 0; st->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; + if ( !nelp_mode && !ppp_mode ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -425,10 +426,11 @@ ivas_error acelp_core_enc( else { const float *pt_interp_2; + #ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE if ( st->active_cnt != 1 ) { - int16_t beta_index[1]; + int16_t beta_index; float lsf_wgts[M]; /* intra_frame prediction for the LSFs */ @@ -436,18 +438,10 @@ ivas_error acelp_core_enc( Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); - tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, beta_index ); + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); - push_indice( hBstr, IND_IC_LSF_PRED, beta_index[0], TDM_IC_LSF_PRED_BITS ); + push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); } -#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - if ( st->active_cnt == 1 ) - { - mvr2r( lsp_new, st->lsp_old, M ); - lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); - lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); - } -#endif #else if ( st->active_cnt != 1 ) { @@ -455,28 +449,20 @@ ivas_error acelp_core_enc( mvr2r( tdm_lsfQ_PCh, lsf_new, M ); } #endif + pt_interp_2 = interpol_frac_12k8; if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) { pt_interp_2 = interpol_frac2; } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX - if ( st->active_cnt == 1 ) - { - mvr2r( lsp_new, st->lsp_old, M ); - lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); - lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); - } -#else -#ifndef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE + if ( st->active_cnt == 1 ) { mvr2r( lsp_new, st->lsp_old, M ); lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core ); lsp2lsf( lsp_new, lsf_new, M, st->sr_core ); } -#endif -#endif + /* LSP interpolation and conversion of LSPs to A(z) */ int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 ); @@ -520,7 +506,7 @@ ivas_error acelp_core_enc( { tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -582,7 +568,7 @@ ivas_error acelp_core_enc( lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); /* Configure ACELP bit allocation */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); #else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c index be2331c7ae..5813968434 100644 --- a/lib_enc/acelp_core_switch_enc.c +++ b/lib_enc/acelp_core_switch_enc.c @@ -151,7 +151,7 @@ void acelp_core_switch_enc( * Excitation encoding *----------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); #else config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index b8f6ab90ef..2e2a379ec9 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -242,7 +242,7 @@ ivas_error evs_enc( if ( st->core == ACELP_CORE ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL ) ) != IVAS_ERR_OK ) #else if ( ( error = acelp_core_enc( st, inp, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 3233d96a19..a7c37a79af 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -219,7 +219,7 @@ ivas_error ivas_core_enc( if ( st->core == ACELP_CORE ) { /* ACELP core encoder */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) #else if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index 052bfbe96e..62e93912ed 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -185,8 +185,7 @@ void lsf_enc( *-------------------------------------------------------------------------------------*/ #ifdef LSF_RE_USE_SECONDARY_CHANNEL - lsf_end_enc( st, lsf_new, lsf_new, nBits, coder_type, force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw, - tdm_lsfQ_PCh ); + lsf_end_enc( st, lsf_new, lsf_new, nBits, coder_type, force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw, tdm_lsfQ_PCh ); #else lsf_end_enc( st, lsf_new, lsf_new, nBits, coder_type, force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw ); #endif @@ -734,7 +733,6 @@ void lsf_end_enc( /* AR inter-frame prediction */ lsf_allocate( nBits - 1, mode_lvq, mode_lvq_p, &dummy, &stages1, dummy_v, levels1, dummy_v, bits1 ); - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp, levels1, stages1, wghts, Idx1, lsf, pred2, resq, lsfq ); if ( Err[0] * ( st->streaklimit ) < PREFERSFNET * Err[1] ) @@ -751,6 +749,7 @@ void lsf_end_enc( } } #endif + /*--------------------------------------------------------------------------* * Write indices to array *--------------------------------------------------------------------------*/ @@ -758,11 +757,13 @@ void lsf_end_enc( if ( st->codec_mode == MODE1 && st->core == ACELP_CORE ) { /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ - if ( coder_type_org == GENERIC && st->sr_core == INT_FS_16k #ifdef LSF_RE_USE_SECONDARY_CHANNEL - && ( st->idchan == 0 ) -#endif + if ( coder_type_org == GENERIC && st->sr_core == INT_FS_16k && st->idchan == 0 + ) +#else + if ( coder_type_org == GENERIC && st->sr_core == INT_FS_16k ) +#endif { /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ push_indice( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, coder_type - 2, 1 ); diff --git a/lib_enc/qlpc_stoch.c b/lib_enc/qlpc_stoch.c index 8defb07034..b7103bc169 100644 --- a/lib_enc/qlpc_stoch.c +++ b/lib_enc/qlpc_stoch.c @@ -103,7 +103,6 @@ void lpc_quantization( /****** Low-rate LPC quantizer *******/ else if ( st->lpcQuantization == 1 ) { - lsp2lsf( lsp, lsf, M, st->sr_core ); force_sf = 0; @@ -122,23 +121,21 @@ void lpc_quantization( if ( st->sr_core == INT_FS_16k && coder_type == UNVOICED ) { - lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL + lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); +#else + lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); #endif - ); nb_indices = *no_param_lpc; } else { - lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type #ifdef LSF_RE_USE_SECONDARY_CHANNEL - , - NULL + lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); +#else + lsf_end_enc( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); #endif - ); nb_indices = *no_param_lpc; } diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index 5736cfe5e0..1ba6c37852 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -178,7 +178,7 @@ void transition_enc( if ( *tc_subfr == TC_0_0 ) { /* this is called only to compute unused bits */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); #else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); @@ -278,7 +278,7 @@ void transition_enc( if ( i_subfr - *tc_subfr <= L_SUBFR ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE_BUGFIX +#ifdef LSF_RE_USE_SECONDARY_CHANNEL_REUSEMODE config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); #else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); -- GitLab