From 3cb163e3b9401a3bc6581ae5f28933c11f5fb666 Mon Sep 17 00:00:00 2001 From: Charles Kinuthia Date: Tue, 24 Jan 2023 21:40:40 +0100 Subject: [PATCH] Low rate encoding of transients for core coder contribution under define LOW_RATE_TRANS_CORE_CODER --- lib_com/ivas_prot.h | 4 ++++ lib_com/options.h | 2 ++ lib_enc/ivas_core_pre_proc_front.c | 16 +++++++++++++--- lib_enc/ivas_cpe_enc.c | 8 ++++++++ lib_enc/ivas_ism_enc.c | 8 ++++++++ lib_enc/ivas_sce_enc.c | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8b4d2b08ce..ba812e8bfb 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -223,8 +223,12 @@ ivas_error pre_proc_front_ivas( const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ +#ifdef LOW_RATE_TRANS_CORE_CODER + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +#else const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t ivas_format /* i : IVAS format */ +#endif ); ivas_error pre_proc_ivas( diff --git a/lib_com/options.h b/lib_com/options.h index 1db2103272..29c490154a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,6 +157,8 @@ #define FIX_268 /* Issue 268: Add low cost dry-run of memory analysis */ #define LOW_RATE_TRANS_FIX /* Eri: Fix for critical item during transitions */ +#define LOW_RATE_TRANS_CORE_CODER /* Eri: Activate low-rate-encoding-of-transients contribution for core coder, affects MC, MASA and SBA */ + #define FIX_197_CREND_INTERFACE /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index e7741a10da..7d4bc7b600 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -107,8 +107,14 @@ ivas_error pre_proc_front_ivas( const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const int32_t ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ - const int16_t ivas_format ) +#ifdef LOW_RATE_TRANS_CORE_CODER + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ +#else + const int32_t ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ + const int16_t ivas_format /* i : IVAS format */ +#endif + +) { float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ @@ -805,7 +811,11 @@ ivas_error pre_proc_front_ivas( } } /* Switch to ACELP for non-harmonic transient signals */ +#ifdef LOW_RATE_TRANS_CORE_CODER + else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) +#else else if ( ( ( ivas_format == STEREO_FORMAT && element_brate <= IVAS_16k4 ) || ( ivas_format == ISM_FORMAT && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC ) +#endif { if ( element_mode == IVAS_SCE ) { @@ -820,7 +830,7 @@ ivas_error pre_proc_front_ivas( { if ( smc_dec != SPEECH && transient_analysis( hCPE->hCoreCoder[i]->hTranDet, st->hNoiseEst->cor_map, st->hNoiseEst->multi_harm_limit ) ) { - smc_dec = SPEECH; /* overwrite initial music decision, intial SPEECH_MUSIC never changed */ + smc_dec = SPEECH; /* overwrite initial music decision, initial SPEECH_MUSIC never changed */ } } } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 598818f70c..bb4e3056f3 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -429,11 +429,19 @@ ivas_error ivas_cpe_enc( for ( n = 0; n < n_CoreChannels; n++ ) { +#ifdef LOW_RATE_TRANS_CORE_CODER + error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], + &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], + &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, + ivas_total_brate ); +#else error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_total_brate, st_ivas->hEncoderConfig->ivas_format ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 58fa1330b9..d64b00ce57 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -146,11 +146,19 @@ ivas_error ivas_ism_enc( * Front Pre-processing *----------------------------------------------------------------*/ +#ifdef LOW_RATE_TRANS_CORE_CODER + error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], + &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], + &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], + fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, + st_ivas->hEncoderConfig->ivas_total_brate ); +#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->ivas_format ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index a67c527081..eae8351d53 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -180,12 +180,21 @@ ivas_error ivas_sce_enc( * Front Pre-processing *----------------------------------------------------------------*/ +#ifdef LOW_RATE_TRANS_CORE_CODER + error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], + &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], + &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], + fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, + st_ivas->hEncoderConfig->ivas_total_brate ); +#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->ivas_format ); +#endif if ( error != IVAS_ERR_OK ) { return error; @@ -251,6 +260,11 @@ ivas_error ivas_sce_enc( hSCE->last_element_brate = hSCE->element_brate; +#ifdef LOW_RATE_TRANS_CORE_CODER + /* Store previous attack detection flag */ + st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; +#endif + #ifdef DEBUG_MODE_INFO { float tmpF = hSCE->element_brate / 1000.0f; -- GitLab