From fae2f2e230854833b55e1fd9ed351397a3e10f4f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 20 Nov 2024 09:43:33 +0530 Subject: [PATCH] Updates to core encoder and float structure elements cleanup --- lib_com/core_com_config.c | 4 + lib_com/stat_com.h | 7 +- lib_enc/core_enc_init.c | 73 ++-- lib_enc/core_enc_switch.c | 7 - lib_enc/ext_sig_ana.c | 505 +--------------------------- lib_enc/init_enc.c | 4 - lib_enc/ivas_core_enc.c | 26 -- lib_enc/ivas_core_pre_proc_front.c | 34 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_ism_enc.c | 2 +- lib_enc/ivas_mct_enc.c | 9 - lib_enc/ivas_mdct_core_enc.c | 61 ++-- lib_enc/ivas_sce_enc.c | 4 +- lib_enc/ivas_stereo_mdct_core_enc.c | 52 +-- lib_enc/ivas_stereo_switching_enc.c | 4 + lib_enc/ivas_tcx_core_enc.c | 7 +- lib_enc/prot_fx_enc.h | 2 +- lib_enc/stat_enc.h | 29 +- lib_enc/tcx_ltp_enc_fx.c | 14 +- lib_enc/tcx_utils_enc.c | 90 +---- lib_enc/tcx_utils_enc_fx.c | 78 +++++ lib_enc/transient_detection_fx.c | 57 ++-- 22 files changed, 240 insertions(+), 831 deletions(-) diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index 6c9c8fa32..a87ab8e40 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -1416,7 +1416,11 @@ void init_tcx_cfg( hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt; /* TCX bandwidth */ +#ifndef IVAS_FLOAT_FIXED hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth ); +#else + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); +#endif /* set number of coded lines */ hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 8a6da6ead..2bdba82b2 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -325,9 +325,12 @@ typedef struct TCX_config_structure /*Bandwidth*/ float preemph_fac_flt; /* preemphasis factor */ + Word16 preemph_fac; /* preemphasis factor Q15 */ +#ifndef IVAS_FLOAT_FIXED float bandwidth_flt; - Word16 preemph_fac; /*preemphasis factorQ15*/ - Word16 bandwidth; +#else + Word16 bandwidth; /* Q15 */ +#endif /* Context HM - Residual Quantization*/ Word16 ctx_hm; /* Flag for enabling Context HM */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index fe9077d33..783a30cb1 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -151,7 +151,7 @@ void init_coder_ace_plus_ivas_fx( { st->acelpFramesCount = 0; move16(); - st->prevTempFlatness_fx = 128 /*1.0f Q7*/; + st->prevTempFlatness_fx = 16 /*1.0f Q4*/; move16(); } @@ -389,7 +389,7 @@ void init_coder_ace_plus( #endif #ifdef IVAS_FLOAT_FIXED #ifdef MSAN_FIX - st->prevTempFlatness_fx = 128; // Q7 + st->prevTempFlatness_fx = 16; // Q4 #endif #endif } @@ -476,11 +476,6 @@ void init_coder_ace_plus( /* Initialize ACELP */ init_acelp( st, L_frame_old, st->total_brate, last_total_brate ); #ifdef IVAS_FLOAT_FIXED - if ( st->lspold_enc != NULL ) - { - floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); - } - init_acelp_ivas_fx( st, L_frame_old, 0 ); #endif @@ -638,11 +633,7 @@ static void init_tcx_ivas_fx( hTcxEnc->kernel_switch_corr_past = 0; hTcxEnc->kernel_symmetry_past = 0; /* MDCT_IV & 1 */ hTcxEnc->enc_ste_pre_corr_past = 0; - // hTcxEnc->tfm_mem_fx = 12288 /*0.75 in Q14*/; - hTcxEnc->tfm_mem_fx = 1610612736; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hTcxEnc->tfm_mem = 0.75f; -#endif + hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ hTcxEnc->tcxltp_on_mem = 0; move16(); move16(); @@ -747,13 +738,11 @@ static void init_tcx( /* Init TCX target bits correction factor */ #ifndef IVAS_FLOAT_FIXED hTcxEnc->tcx_target_bits_fac_flt = 1.0f; -#else - hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; -#endif hTcxEnc->measuredBwRatio_flt = 1.0f; -#ifndef IVAS_FLOAT_FIXED hTcxEnc->noiseTiltFactor_flt = 0.5625f; #else + hTcxEnc->tcx_target_bits_fac = ONE_IN_Q14; + hTcxEnc->measuredBwRatio = ONE_IN_Q14; hTcxEnc->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ #endif hTcxEnc->noiseLevelMemory_cnt = 0; @@ -774,18 +763,22 @@ static void init_tcx( hTcxEnc->tcxltp_pitch_fr_past = 0; #ifndef IVAS_FLOAT_FIXED hTcxEnc->tcxltp_gain_past_flt = 0.f; -#else - hTcxEnc->tcxltp_gain_past = 0; -#endif + hTcxEnc->tcxltp_norm_corr_past_flt = 0.f; hTcxEnc->tcxltp_norm_corr_mem_flt = 0.f; -#ifndef IVAS_FLOAT_FIXED hTcxEnc->kernel_switch_corr_past_flt = 0.f; #else + hTcxEnc->tcxltp_gain_past = 0; + hTcxEnc->tcxltp_norm_corr_past = 0; + hTcxEnc->tcxltp_norm_corr_mem = 0; hTcxEnc->kernel_switch_corr_past = 0; #endif hTcxEnc->kernel_symmetry_past = 0; /* MDCT_IV & 1 */ hTcxEnc->enc_ste_pre_corr_past = 0; +#ifndef IVAS_FLOAT_FIXED hTcxEnc->tfm_mem = 0.75f; +#else + hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ +#endif hTcxEnc->tcxltp_on_mem = 0; } else if ( st->L_frame != L_frame_old && !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && @@ -1270,28 +1263,26 @@ static void init_acelp( } /* unquantized LPC*/ +#ifndef IVAS_FLOAT_FIXED if ( !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && total_brate == last_total_brate && st->last_bwidth == st->bwidth ) ) { -#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ -#else - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); -#endif -#endif if ( st->L_frame == L_FRAME16k ) { lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } } -#ifndef IVAS_FLOAT_FIXED mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); -#endif + IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + { + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); + } + } Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ IF( st->tcxonly == 0 ) { @@ -1355,9 +1346,6 @@ static void init_acelp( { Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); -#endif #endif /* Update wsyn */ @@ -1412,23 +1400,18 @@ static void init_acelp( /* unquantized LPC*/ #ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ -#else - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); -#endif -#endif if ( st->L_frame == L_FRAME16k ) { lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } -#ifndef IVAS_FLOAT_FIXED mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); -#endif + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 ); + } Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ IF( st->tcxonly == 0 ) { @@ -1607,7 +1590,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh test(); test(); test(); - IF( !( ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) + IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( st->total_brate, st->last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) ) { Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ IF( EQ_16( st->L_frame, L_FRAME16k ) ) diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 9e6ffbcf4..a0c400ae3 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -230,12 +230,6 @@ void core_coder_mode_switch_ivas_fx( f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); - /* Initialize ACELP */ - if ( st->lspold_enc != NULL ) - { - floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); - } - /* Adaptive BPF */ set_zero( st->mem_bpf, 2 * L_FILT16k ); set_zero( st->mem_error_bpf, 2 * L_FILT16k ); @@ -243,7 +237,6 @@ void core_coder_mode_switch_ivas_fx( init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index eaf71b952..ce7f82c17 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -41,517 +41,14 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx.h" -#include "prot_fx_enc.h" -#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * core_signal_analysis_high_bitrate() * * *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void core_signal_analysis_high_bitrate( - const float *new_samples, - const int16_t T_op[3], /* i : open-loop pitch values for quantiz. */ - float lsp_new[], - float lsp_mid[], - Encoder_State *st, - float *mdst_spectrum[2], - int16_t pTnsSize[], - int16_t pTnsBits[], - int16_t param_core[], - int16_t *ltpBits, - float *windowed_samples, /* i/o: backup of windowed time signal */ - const int16_t L_frame, - const int16_t L_frameTCX, - const int16_t last_element_mode, - const int16_t vad_hover_flag /* i : VAD hangover flag */ -) -{ - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - - const int16_t last_overlap = st->hTcxCfg->tcx_last_overlap_mode; - const int16_t curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode; - const int16_t minWindowLen = st->hTcxCfg->tcx_mdct_window_min_lengthFB - 1; - int16_t i, frameno; - int16_t L_subframe; - int16_t left_overlap = -1, right_overlap = -1, folding_offset; - float buf[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ - float mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ - float *powerSpec; - float *tcx20Win; - float tcx5Win[N_TCX10_MAX / 2 + L_MDCT_OVLP_MAX]; /* Buffer for TCX5 windowing and interleaving. */ - float *interleaveBuf = tcx5Win; - int16_t nSubframes; - int16_t overlap_mode[3]; - int16_t *transform_type = hTcxEnc->transform_type; - float r[M + 1]; - float A[M + 1]; - float *lsp[2]; - const int16_t tcx10SizeFB = 2 * st->hTcxCfg->tcx5SizeFB; - const int16_t tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; - const int16_t tcx10Size = 2 * st->hTcxCfg->tcx5Size; - int16_t alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1; - float alw_voicing[2], alw_voicing_wc = -1; - int16_t disable_ltp = 0; -#ifdef IVAS_FLOAT_FIXED - Word16 q_fac; - Word16 buf_speech_enc_fx[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - Word16 buf_wspeech_enc_fx[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; - Word16 buf_speech_ltp_fx[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - Word16 *speech_ltp_fx = NULL; - Word16 *wspeech_fx = NULL; - Word16 *speech_fx = NULL; - q_fac = 0; - move16(); -#endif - - if ( last_element_mode != st->element_mode ) - { - disable_ltp = 1; /* disable TCX-LTP in stereo switching to avoid discontinuities in synthesis */ - } - - powerSpec = tcx20Win = buf; /* Share memory for windowed TD signal and for the power spectrum */ - - /*--------------------------------------------------------------* - * Input Signal Processing: copy, HP filter, pre-emphasis - *---------------------------------------------------------------*/ - - if ( st->tcxonly && st->element_mode != IVAS_CPE_MDCT ) - { - /* Copy Samples */ - mvr2r( new_samples, st->new_speech_enc_flt, L_frame ); - } - - /*--------------------------------------------------------------* - * TCX-LTP - *---------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->element_mode == IVAS_CPE_DFT ) - { - q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - floatToFixed_arr( st->buf_wspeech_enc_flt, buf_wspeech_enc_fx, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - - if ( st->element_mode > EVS_MONO ) - { - wspeech_fx = buf_wspeech_enc_fx + st->L_frame + L_SUBFR; - } - else - { - wspeech_fx = buf_wspeech_enc_fx + st->L_frame + idiv1616( st->L_frame, st->nb_subfr ); - } - } - else if ( st->element_mode != IVAS_CPE_MDCT ) - { - q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr( st->buf_speech_enc_flt, buf_speech_enc_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - speech_fx = buf_speech_enc_fx + +st->encoderPastSamples_enc; - - floatToFixed_arr( st->hTcxEnc->buf_speech_ltp_flt, buf_speech_ltp_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - speech_ltp_fx = buf_speech_ltp_fx + st->encoderPastSamples_enc; - } -#endif - - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, wspeech_fx, NULL, wspeech_fx, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); - } - ELSE IF( st->element_mode != IVAS_CPE_MDCT ) - { - tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, speech_fx + st->encoderLookahead_enc, speech_ltp_fx + st->encoderLookahead_enc, speech_fx + st->encoderLookahead_enc, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); - } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->element_mode == IVAS_CPE_DFT ) - { - fixedToFloat_arr( buf_wspeech_enc_fx, st->buf_wspeech_enc_flt, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - } - else if ( st->element_mode != IVAS_CPE_MDCT ) - { - fixedToFloat_arr( buf_speech_ltp_fx, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } -#endif -#else - if ( st->element_mode == IVAS_CPE_DFT ) - { - tcx_ltp_encode( st, hTcxEnc->tcxMode, L_frame, st->wspeech_enc_flt, NULL, st->wspeech_enc_flt, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); - } - else if ( st->element_mode != IVAS_CPE_MDCT ) - { - tcx_ltp_encode( st, hTcxEnc->tcxMode, L_frame, st->speech_enc_flt + st->encoderLookahead_enc, hTcxEnc->speech_ltp_flt + st->encoderLookahead_enc, st->speech_enc_flt + st->encoderLookahead_enc, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); - } -#endif - - if ( st->tcxonly && st->element_mode != IVAS_CPE_MDCT ) - { - mvr2r( st->speech_enc_flt + st->encoderLookahead_enc, st->new_speech_enc_pe_flt, L_frame ); - - preemph( st->new_speech_enc_pe_flt, st->preemph_fac_flt, L_frame, &( st->mem_preemph_enc_flt ) ); - } - - if ( hTcxEnc->tcxMode == TCX_10 ) - { - mvs2s( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); - } - - if ( st->element_mode != IVAS_CPE_MDCT ) - { - lsp[0] = lsp_new; - lsp[1] = lsp_mid; - } - - /*-------------------------------------------------------------------------* - * Decision matrix for the transform and overlap length - *--------------------------------------------------------------------------*/ - - if ( st->element_mode != IVAS_CPE_MDCT ) - { - alw_pitch_lag_12k8[0] = st->pitch[0]; - alw_pitch_lag_12k8[1] = st->pitch[1]; - alw_voicing[0] = st->voicing[0]; - alw_voicing[1] = st->voicing[1]; - alw_pitch_lag_12k8_wc = min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); - alw_voicing_wc = max( alw_voicing[0], alw_voicing[1] ); - } - - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ - - if ( hTcxEnc->tcxMode == TCX_20 ) - { - nSubframes = 1; - transform_type[0] = TCX_20; - transform_type[1] = TCX_20; - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ - - if ( st->element_mode != IVAS_CPE_MDCT ) - { - alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; - alw_voicing[0] = alw_voicing_wc; - } - } - else - { - nSubframes = 2; - if ( curr_overlap == FULL_OVERLAP ) - { - transform_type[0] = TCX_5; - transform_type[1] = TCX_10; - overlap_mode[1] = ( last_overlap == HALF_OVERLAP ) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ - } - else if ( last_overlap == FULL_OVERLAP ) - { - transform_type[0] = TCX_10; - transform_type[1] = TCX_5; - overlap_mode[1] = ( curr_overlap == HALF_OVERLAP ) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ - } - else - { - transform_type[0] = transform_type[1] = TCX_5; - overlap_mode[1] = ( last_overlap == HALF_OVERLAP && curr_overlap == HALF_OVERLAP ) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ - } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ - } - - if ( st->igf && transform_type[0] != TCX_20 ) - { - IGFEncResetTCX10BitCounter( st->hIGFEnc ); - } - - for ( frameno = 0; frameno < nSubframes; frameno++ ) - { - /*-------------------------------------------------------------------------* - * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed - *--------------------------------------------------------------------------*/ - - L_subframe = L_frameTCX / nSubframes; - - if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) - { - wtda( hTcxEnc->new_speech_TCX_flt, tcx20Win, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX ); - - if ( windowed_samples != NULL ) /* store overlap data for later */ - { - assert( frameno == 0 ); - windowed_samples[0] = (float) overlap_mode[frameno]; - windowed_samples[1] = (float) overlap_mode[frameno + 1]; - } - if ( st->element_mode != IVAS_CPE_MDCT ) - { - /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal_flt( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX_flt[frameno * tcx10SizeFB], &L_subframe, mdstWin, 1, 1 ); - } - } - else - { - /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal_flt( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno], overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX_flt[frameno * tcx10SizeFB], &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT, 1 ); - - if ( windowed_samples != NULL ) /* save windowed speech_TCX_flt samples */ - { - assert( L_subframe + ( left_overlap + right_overlap ) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8 ); - windowed_samples[frameno * L_FRAME_MAX + 0] = (float) overlap_mode[frameno]; - windowed_samples[frameno * L_FRAME_MAX + 1] = (float) overlap_mode[frameno + 1]; - mvr2r( tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2 ); - } - } - - if ( transform_type[frameno] == TCX_5 ) - { - /* Outer left folding */ - for ( i = 0; i < left_overlap / 2; i++ ) - { - tcx20Win[left_overlap / 2 + i] -= tcx20Win[left_overlap / 2 - 1 - i]; - } - - if ( st->element_mode == IVAS_CPE_MDCT && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) - { - for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ - { - tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX_flt[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB_flt[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB_flt[minWindowLen - i]; - } - } - - /* Outer right folding */ - for ( i = 0; i < right_overlap / 2; i++ ) - { - tcx20Win[L_subframe + left_overlap / 2 - 1 - i] += tcx20Win[L_subframe + left_overlap / 2 + i]; - } - - /* 2xTCX5 */ - L_subframe = tcx5SizeFB; - folding_offset = left_overlap / 2; - - for ( i = 0; i < 2; i++ ) - { - WindowSignal_flt( st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, tcx20Win + i * tcx5SizeFB, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1 ); - - TCX_MDCT_flt( tcx5Win, hTcxEnc->spectrum[frameno] + i * tcx5SizeFB, left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); - - /* high-band gain control in case of BWS */ - if ( st->bwidth_sw_cnt > 0 ) - { - v_multc( hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); - } - } - } - else /* transform_type[frameno] != TCX_5 */ - { - assert( transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20 ); - - if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) - { - edct( tcx20Win, hTcxEnc->spectrum[frameno], L_subframe, st->element_mode ); - - v_multc( hTcxEnc->spectrum[frameno], (float) sqrt( (float) NORM_MDCT_FACTOR / L_subframe ), hTcxEnc->spectrum[frameno], L_subframe ); - } - else - { - /* TCX20/TCX10 */ - if ( st->element_mode == IVAS_CPE_MDCT && frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) - { - for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ - { - tcx20Win[left_overlap + i] -= hTcxEnc->speech_TCX_flt[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB_flt[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB_flt[minWindowLen - i]; - } - } - - TCX_MDCT_flt( tcx20Win, hTcxEnc->spectrum[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); - } - - /* high-band gain control in case of BWS */ - if ( st->bwidth_sw_cnt > 0 ) - { - v_multc( hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, hTcxEnc->spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes ); - } - - if ( st->element_mode != IVAS_CPE_MDCT ) - { - /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */ - if ( hTcxEnc->tcxMode == TCX_20 && ( st->total_brate < HQ_96k || st->igf ) ) - { - /* Compute noise-measure flags for spectrum filling and quantization */ - AnalyzePowerSpectrum( st, L_subframe * st->L_frame / hTcxEnc->L_frameTCX, L_subframe, left_overlap, right_overlap, hTcxEnc->spectrum[frameno], ( ( hTcxEnc->tcxMode == TCX_20 ) && ( st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) ) ? mdstWin : tcx20Win, powerSpec ); - } - } - } - - if ( st->element_mode == IVAS_CPE_MDCT ) - { - L_subframe = L_frameTCX / nSubframes; - - if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) - { - wtda_ext( hTcxEnc->new_speech_TCX_flt, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3 ); - } - else - { - /* Windowing for the MDST */ - WindowSignal_flt( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX_flt[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1 ); - } - - if ( transform_type[frameno] == TCX_5 ) - { - /* Outer left folding */ - for ( i = 0; i < left_overlap / 2; i++ ) - { - mdstWin[left_overlap / 2 + i] += mdstWin[left_overlap / 2 - 1 - i]; - } - - if ( frameno == 0 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) - { - for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ - { - mdstWin[left_overlap + i] += hTcxEnc->speech_TCX_flt[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB_flt[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB_flt[minWindowLen - i]; - } - } - - /* Outer right folding */ - for ( i = 0; i < right_overlap / 2; i++ ) - { - mdstWin[L_subframe + left_overlap / 2 - 1 - i] -= mdstWin[L_subframe + left_overlap / 2 + i]; - } - - /* 2xTCX5 */ - L_subframe = tcx5SizeFB; - folding_offset = left_overlap / 2; - - for ( i = 0; i < 2; i++ ) - { - WindowSignal_flt( st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1 ); - - TCX_MDST_flt( tcx5Win, mdst_spectrum[frameno] + i * tcx5SizeFB, left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); - /* high-band gain control in case of BWS */ - if ( st->bwidth_sw_cnt > 0 ) - { - v_multc( mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, mdst_spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); - } - } - } - else /* transform_type[frameno] != TCX_5 */ - { - if ( transform_type[frameno] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) - { - edst( mdstWin, mdst_spectrum[frameno], L_subframe, st->element_mode ); - - v_multc( mdst_spectrum[frameno], (float) sqrt( (float) NORM_MDCT_FACTOR / L_subframe ), mdst_spectrum[frameno], L_subframe ); - } - else - { - if ( frameno == 0 && transform_type[0] == TCX_10 && overlap_mode[0] == FULL_OVERLAP && L_subframe - left_overlap > minWindowLen ) - { - for ( i = minWindowLen; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ - { - mdstWin[left_overlap + i] += hTcxEnc->speech_TCX_flt[-1 - i] * st->hTcxCfg->tcx_aldo_window_1_FB_flt[left_overlap / 2 + minWindowLen - i] * st->hTcxCfg->tcx_mdct_window_minimumFB_flt[minWindowLen - i]; - } - } - - TCX_MDST_flt( mdstWin, mdst_spectrum[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); - } - - /* high-band gain control in case of BWS */ - if ( st->bwidth_sw_cnt > 0 ) - { - v_multc( mdst_spectrum[frameno] + L_FRAME16k / nSubframes, (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD, mdst_spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes ); - } - } - } - - if ( st->element_mode != IVAS_CPE_MDCT ) - { -#ifndef IVAS_FLOAT_FIXED - TNSAnalysis( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), hTcxEnc->spectrum[frameno], st->hTranDet, -1, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // q factor of spectrum - Word16 q_factor_spectrum = Q_factor_arrL( hTcxEnc->spectrum[frameno], N_TCX10_MAX ) - 1; - - /* conv params to fix */ - // -1 = -32768 , Q=15 , ltp_gain - // spectrum_fx[]=fixed( (float)spectrum[]) , Q=q_factor_spectrum - floatToFixed_arrL( hTcxEnc->spectrum_long, hTcxEnc->spectrum_long_fx, q_factor_spectrum, N_MAX ); -#endif - test(); - TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st->hTcxCfg->fIsTNSAllowed ) - { // conv params to float - // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum - fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); - } -#endif -#endif - if ( st->hTcxCfg->fIsTNSAllowed ) - { - EncodeTnsData( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); - } - - if ( transform_type[frameno] == TCX_5 ) - { - /* group sub-windows: interleave bins according to their frequencies */ - for ( i = 0; i < tcx5SizeFB; i++ ) - { - interleaveBuf[2 * i] = hTcxEnc->spectrum[frameno][i]; - interleaveBuf[2 * i + 1] = hTcxEnc->spectrum[frameno][tcx5SizeFB + i]; - } - mvr2r( interleaveBuf, hTcxEnc->spectrum[frameno], tcx10SizeFB ); - } - - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ - - if ( st->tcxonly ) - { - HBAutocorrelation( st->hTcxCfg, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &st->speech_enc_pe_flt[frameno * tcx10Size], L_frame / nSubframes, r ); - - adapt_lag_wind_fx( r, M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - - lev_dur( A, r, M, NULL ); - - a2lsp_stab( A, lsp[nSubframes - 1 - frameno], st->lspold_enc ); - } - - if ( st->igf ) - { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_spectrum; - q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[frameno], hTcxEnc->L_frameTCX / nSubframes ); - if ( st->hIGFEnc ) - { - q_spectrum = min( q_spectrum, 31 - st->hIGFEnc->spec_be_igf_e ); - } - floatToFixed_arrL32( hTcxEnc->spectrum[frameno], hTcxEnc->spectrum_fx[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); - - Word32 powerSpec_fx[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ - Word16 q_powerSpec; - q_powerSpec = L_get_q_buf1( powerSpec, L_subframe ); - floatToFixed_arrL32( powerSpec, powerSpec_fx, q_powerSpec, L_subframe ); -#endif - ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec_fx, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum[frameno], q_spectrum, hTcxEnc->L_frameTCX / nSubframes ); - fixedToFloat_arrL32( powerSpec_fx, powerSpec, q_powerSpec, L_subframe ); -#endif -#else - ProcessIGF( st, hTcxEnc->spectrum[frameno], hTcxEnc->spectrum[frameno], powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); -#endif - } - } - } - if ( st->element_mode != IVAS_CPE_MDCT ) - { - /* Copy memory */ - mvr2r( lsp_new, st->lspold_enc, M ); - } - - return; -} -#else void core_signal_analysis_high_bitrate( const float *new_samples, const int16_t T_op[3], /* i : open-loop pitch values for quantiz. */ diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 8c2cff48b..637da29ac 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -261,9 +261,6 @@ ivas_error init_encoder( Copy( st->lsp_old1_fx, st->lsp_old_fx, M ); Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); -#endif #endif #ifndef IVAS_FLOAT_FIXED @@ -2295,7 +2292,6 @@ ivas_error init_encoder_ivas_fx( init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); IF( st->hLPDmem != NULL ) { // me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 9c187d031..9ef70a1b9 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -231,14 +231,8 @@ ivas_error ivas_core_enc( st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, Q15, M ); floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); - } - f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); f2me_buf_16( fft_buff[n], fft_buff_fx, &e_fft_buff, ( 2 * L_FFT ) ); @@ -296,13 +290,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->preemph_fac_flt = fixedToFloat_16( st->preemph_fac, Q15 ); - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); - - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); - } #endif if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE ) @@ -427,7 +415,6 @@ ivas_error ivas_core_enc( floatToFixed_arr( Aw_flt[n], Aw_fx[n], Q12, st->nb_subfr * ( M + 1 ) ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); floatToFixed_arr( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq, -1, L_FRAME32k / 2 + 64 ); st->hTcxEnc->Q_old_out = Q_factor_arr( st->hTcxEnc->old_out, L_FRAME32k ) - 1; @@ -442,8 +429,6 @@ ivas_error ivas_core_enc( { nSubframes = 2; } - // hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); - floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, Q15, M ); Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); hTcxEnc->spectrum_e[0] = 31 - q_spectrum; @@ -472,8 +457,6 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( lsp_new_fx[n], lsp_new[n], Q15, M ); fixedToFloat_arr( lsp_mid_fx[n], lsp_mid[n], Q15, M ); - - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS_ if ( st->element_mode == IVAS_CPE_DFT ) @@ -494,13 +477,10 @@ ivas_error ivas_core_enc( } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); fixedToFloat_arr( pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); fixedToFloat_arr( st->hTcxEnc->old_out_fx, st->hTcxEnc->old_out, st->hTcxEnc->Q_old_out, L_FRAME32k ); - st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - for ( int k = 0; k < 2; k++ ) { fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); @@ -1244,7 +1224,6 @@ ivas_error ivas_core_enc( f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - #endif updt_enc_common_ivas_fx( st ); @@ -1259,11 +1238,6 @@ ivas_error ivas_core_enc( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) - { - st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); - } - IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) { IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 532b59ed4..11d22768f 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2002,10 +2002,7 @@ ivas_error pre_proc_front_ivas_fx( break; } } - for ( int idx = 0; idx < L_INP_12k8; idx++ ) - { - old_inp_12k8_loc_fx[idx] = (Word16) ( old_inp_12k8[idx] * ( 1 << Q_new_loc ) ); - } + floatToFixed_arr( old_inp_12k8, old_inp_12k8_loc_fx, Q_new_loc, L_INP_12k8 ); for ( int idx = 0; idx < 3; idx++ ) { st->voicing_fx[idx] = (Word16) ( st->voicing[idx] * 32767 ); @@ -2449,33 +2446,6 @@ ivas_error pre_proc_front_ivas_fx( if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) { #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( ( NE_32( imult1616( st->last_bits_frame_nominal, FRAMES_PER_SEC ), st->total_brate ) ) || - ( NE_16( st->last_bwidth, st->bwidth ) ) || - ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) || - ( ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) || - ( NE_16( st->rf_mode_last, st->rf_mode ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && st->ini_frame == 0 ) ) - { - Word16 bSwitchFromAmrwbIO = 0, switchWB = 0, fscale; - Word32 sr_core; - move16(); - move16(); - - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) - { - bSwitchFromAmrwbIO = 1; - move16(); - } - sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - fscale = sr2fscale_fx( sr_core ); - IF( EQ_32( fscale, st->fscale ) && !bSwitchFromAmrwbIO && !switchWB ) - { - st->hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( st->bwidth ); - } - } -#endif - SetModeIndex_ivas_fx( st, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), element_mode, MCT_flag ); st->sba_br_sw_while_no_data = 0; @@ -2510,7 +2480,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_old_inp_16k = -1; floatToFixed_arr16( st->input, st->input_fx, -1, 960 ); - floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, 15, 16 ); st->mem_preemph_enc = (Word16) floatToFixed( st->mem_preemph_enc_flt, Q_old_inp_16k ); st->mem_preemph16k_fx = (Word16) floatToFixed( st->mem_preemph16k, Q_old_inp_16k ); st->mem_preemph16k_DFT_fx = (Word16) floatToFixed( st->mem_preemph16k_DFT, Q_old_inp_16k ); @@ -2554,7 +2523,6 @@ ivas_error pre_proc_front_ivas_fx( } fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, Q_old_inp_16k, L_INP ); - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, 15, 16 ); fixedToFloat_arr( st->input_fx, st->input, -1, 960 ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, Q_old_inp_16k, L_INP_MEM ); fixedToFloat_arr( st->mem_decim16k_fx, st->mem_decim16k, Q_old_inp_16k, 2 * L_FILT_MAX ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index fbef1542f..d9fa043e8 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -478,7 +478,7 @@ ivas_error ivas_cpe_enc_fx( move16(); } - currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); + currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q4 move16(); } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2d7ba881e..3ef3cbb66 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -579,7 +579,7 @@ ivas_error ivas_ism_enc_fx( move16(); move16(); - currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q4 move16(); /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index a83b9eb7d..262ad660e 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -605,8 +605,6 @@ ivas_error ivas_mct_enc_fx( move16(); for ( ch = 0; ch < hMCT->nchan_out_woLFE; ch++ ) { - sts_tmp[ch]->hTcxEnc->measuredBwRatio_flt = 1.f; /* No bandwidth limit for the noise filling */ - if ( sts_tmp[ch]->hTcxEnc->spectrum[0] ) { q_spec = 31 - sts_tmp[ch]->hTcxEnc->spectrum_e[0]; @@ -641,9 +639,7 @@ ivas_error ivas_mct_enc_fx( { sts = hCPE->hCoreCoder; st = sts[ch]; - st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); } #endif ivas_mdct_quant_coder_fx( hCPE, hMCT->tnsBits[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], 1 ); @@ -686,11 +682,6 @@ ivas_error ivas_mct_enc_fx( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) - { - st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); - } - IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) { IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 819596af2..a672563d2 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -53,6 +53,7 @@ *---------------------------------------------------------------*/ #define MAX_STE_PRE_NRG 0.875f +#define MAX_STE_PRE_NRG_Q15 28672 #define MIN_STE_PRE_LEN 36 #define SILENT_CHANNEL_THRES 100 @@ -1630,7 +1631,11 @@ void ivas_mdct_core_whitening_enc( Word32 powerSpec_fx[N_MAX]; #endif float *mdst_spectrum[CPE_CHANNELS][NB_DIV]; +#ifndef IVAS_FLOAT_FIXED float nrg; +#else + Word16 nrg_fx; /* Q15 */ +#endif Encoder_State *st, **sts; float scf[CPE_CHANNELS][NB_DIV][M]; float scf_q[CPE_CHANNELS][NB_DIV][M]; @@ -1740,8 +1745,21 @@ void ivas_mdct_core_whitening_enc( if ( mct_on ) { +#ifndef IVAS_FLOAT_FIXED sts[0]->hTcxEnc->tfm_mem = sts[1]->hTcxEnc->tfm_mem = sqrtf( 0.5f * ( sts[0]->hTcxEnc->tfm_mem * sts[0]->hTcxEnc->tfm_mem + sts[1]->hTcxEnc->tfm_mem * sts[1]->hTcxEnc->tfm_mem ) ); /* RMS */ - sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = add( shr( sts[0]->hTcxEnc->tcxltp_norm_corr_past, 1 ), shr( sts[1]->hTcxEnc->tcxltp_norm_corr_past, 1 ) ); + sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt ); +#else + Word16 tmp_e = 0; + move16(); + Word32 L_tmp; + L_tmp = Sqrt32( L_add( L_shr( Mpy_32_32( sts[0]->hTcxEnc->tfm_mem_fx, sts[0]->hTcxEnc->tfm_mem_fx ), 1 ), L_shr( Mpy_32_32( sts[1]->hTcxEnc->tfm_mem_fx, sts[1]->hTcxEnc->tfm_mem_fx ), 1 ) ), &tmp_e ); /* RMS */ + sts[0]->hTcxEnc->tfm_mem_fx = sts[1]->hTcxEnc->tfm_mem_fx = L_shl( L_tmp, tmp_e ); /* Q31 */ + move32(); + move32(); + sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = extract_l( L_shr( L_add( sts[0]->hTcxEnc->tcxltp_norm_corr_past, sts[1]->hTcxEnc->tcxltp_norm_corr_past ), 1 ) ); + move16(); + move16(); +#endif for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; @@ -1753,18 +1771,8 @@ void ivas_mdct_core_whitening_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); - } #endif SetTCXModeInfo_ivas_fx( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); - } -#endif #else SetTCXModeInfo( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); #endif @@ -2098,8 +2106,12 @@ void ivas_mdct_core_whitening_enc( nSampCore = tcx_subframe_coded_lines; } - nrg = 0.25f * ( fix16_to_float( hTcxEnc0->tcxltp_norm_corr_past, 15 ) + hTcxEnc0->tcxltp_norm_corr_mem_flt + /* tcxltp_norm_corr_past already contains the */ - fix16_to_float( hTcxEnc1->tcxltp_norm_corr_past, 15 ) + hTcxEnc1->tcxltp_norm_corr_mem_flt ); /* normalized correlation of the current frame */ +#ifndef IVAS_FLOAT_FIXED + nrg = 0.25f * ( hTcxEnc0->tcxltp_norm_corr_past_flt + hTcxEnc0->tcxltp_norm_corr_mem_flt + /* tcxltp_norm_corr_past already contains the */ + hTcxEnc1->tcxltp_norm_corr_past_flt + hTcxEnc1->tcxltp_norm_corr_mem_flt ); /* normalized correlation of the current frame */ +#else + nrg_fx = extract_l( L_shr( L_add( L_add( L_add( hTcxEnc0->tcxltp_norm_corr_past, hTcxEnc0->tcxltp_norm_corr_mem ), hTcxEnc1->tcxltp_norm_corr_past ), hTcxEnc1->tcxltp_norm_corr_mem ), 2 ) ); /* normalized correlation of the current frame */ +#endif L_subframe = max( 512, L_subframe ); nSubframes = ( hTcxEnc0->tcxMode == TCX_20 ) ? 1 : NB_DIV; @@ -2124,7 +2136,7 @@ void ivas_mdct_core_whitening_enc( kernel_switch_detect_fx( hTcxEnc0->spectrum_fx[n], hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[0][n], mdst_spectrum_fx[1][n], q_com, nSampCore / nSubframes, L_subframeTCX / nSubframes, hTcxEnc0->transform_type[n], &hTcxEnc0->kernel_switch_corr_past, ( totalRate * L_subframe ) / nSubframes ); #else - const int16_t switchKernel = /* these 4 transform types can be applied: 0 = MDCT-IV, 1 = MDST-II, 2 = MDCT-II, 3 = MDST-IV */ + const int16_t switchKernel = /* these 4 transform types can be applied: 0 = MDCT-IV, 1 = MDST-II, 2 = MDCT-II, 3 = MDST-IV */ kernel_switch_detect( hTcxEnc0->spectrum[n], hTcxEnc1->spectrum[n], mdst_spectrum[0][n], mdst_spectrum[1][n], nSampCore / nSubframes, L_subframeTCX / nSubframes, hTcxEnc0->transform_type[n], &hTcxEnc0->kernel_switch_corr_past_flt, ( totalRate * L_subframe ) / nSubframes ); #endif @@ -2246,6 +2258,18 @@ void ivas_mdct_core_whitening_enc( sts[0]->hTcxCfg->tcx_curr_overlap_mode == sts[1]->hTcxCfg->tcx_curr_overlap_mode && sts[0]->hTcxCfg->tcx_last_overlap_mode == sts[1]->hTcxCfg->tcx_last_overlap_mode ) { + +#ifdef IVAS_FLOAT_FIXED + // nrg > MAX_STE_PRE_NRG ? 1 : 0 + Word16 tmp = 0; + move16(); + if ( GT_16( nrg_fx, MAX_STE_PRE_NRG_Q15 ) ) + { + tmp = 1; + move16(); + } +#endif + if ( hTcxEnc0->transform_type[n] == TCX_5 ) { const int16_t tcx5SizeFB = sts[1]->hTcxCfg->tcx5SizeFB; @@ -2266,7 +2290,7 @@ void ivas_mdct_core_whitening_enc( hTcxEnc0->enc_ste_pre_corr_past = enc_ste_pre_mdct( hTcxEnc0->spectrum_fx[n], hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[0][n], mdst_spectrum_fx[1][n], &q_com, nSampCore / ( 2 * NB_DIV ), - L_subframeTCX / ( 2 * NB_DIV ), ( nrg > MAX_STE_PRE_NRG ? 1 : 0 ), hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / ( 2 * NB_DIV ) ); + L_subframeTCX / ( 2 * NB_DIV ), tmp, hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / ( 2 * NB_DIV ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( hTcxEnc0->spectrum_fx[n], hTcxEnc0->spectrum[n], q_com, length ); @@ -2288,7 +2312,7 @@ void ivas_mdct_core_whitening_enc( hTcxEnc0->enc_ste_pre_corr_past = enc_ste_pre_mdct( hTcxEnc0->spectrum_fx[n] + tcx5SizeFB, hTcxEnc1->spectrum_fx[n] + tcx5SizeFB, mdst_spectrum_fx[0][n] + tcx5SizeFB, mdst_spectrum_fx[1][n] + tcx5SizeFB, &q_com, nSampCore / ( 2 * NB_DIV ), - L_subframeTCX / ( 2 * NB_DIV ), ( nrg > MAX_STE_PRE_NRG ? 1 : 0 ), hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / ( 2 * NB_DIV ) ); + L_subframeTCX / ( 2 * NB_DIV ), tmp, hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / ( 2 * NB_DIV ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( hTcxEnc0->spectrum_fx[n] + tcx5SizeFB, hTcxEnc0->spectrum[n] + tcx5SizeFB, q_com, length ); @@ -2324,7 +2348,7 @@ void ivas_mdct_core_whitening_enc( #endif hTcxEnc0->enc_ste_pre_corr_past = enc_ste_pre_mdct( hTcxEnc0->spectrum_fx[n], hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[0][n], mdst_spectrum_fx[1][n], &q_com, nSampCore / nSubframes, - L_subframeTCX / nSubframes, ( nrg > MAX_STE_PRE_NRG ? 1 : 0 ), hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / nSubframes ); + L_subframeTCX / nSubframes, tmp, hTcxEnc0->enc_ste_pre_corr_past, ( totalRate * L_subframe ) / nSubframes ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL( hTcxEnc0->spectrum_fx[n], hTcxEnc0->spectrum[n], q_com, length ); fixedToFloat_arrL( hTcxEnc1->spectrum_fx[n], hTcxEnc1->spectrum[n], q_com, length ); @@ -2858,9 +2882,6 @@ void ivas_mdct_core_whitening_enc( } #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); -#endif test(); test(); IF( ( ch > 0 ) && ( add( sts[0]->hTcxEnc->fUseTns[0], sts[0]->hTcxEnc->fUseTns[1] ) > 0 ) && !mct_on ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index e45170c6d..5e1e6c428 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -182,13 +182,11 @@ ivas_error ivas_sce_enc_fx( IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input ); - st->hTranDet->subblockEnergies.subblockNrg_e = 31 - Q7; - st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - Q7; move16(); move16(); } - currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q4 move16(); /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 88830ea7c..c94b2a81c 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -613,8 +613,21 @@ void stereo_mdct_core_enc( * Initialization *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED sts[0]->hTcxEnc->tfm_mem = sts[1]->hTcxEnc->tfm_mem = sqrtf( 0.5f * ( sts[0]->hTcxEnc->tfm_mem * sts[0]->hTcxEnc->tfm_mem + sts[1]->hTcxEnc->tfm_mem * sts[1]->hTcxEnc->tfm_mem ) ); /* RMS */ - sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = add( shr( sts[0]->hTcxEnc->tcxltp_norm_corr_past, 1 ), shr( sts[1]->hTcxEnc->tcxltp_norm_corr_past, 1 ) ); + sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt = sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past_flt + sts[1]->hTcxEnc->tcxltp_norm_corr_past_flt ); +#else + Word16 tmp_e = 0; + move16(); + Word32 L_tmp; + L_tmp = Sqrt32( L_add( L_shr( Mpy_32_32( sts[0]->hTcxEnc->tfm_mem_fx, sts[0]->hTcxEnc->tfm_mem_fx ), 1 ), L_shr( Mpy_32_32( sts[1]->hTcxEnc->tfm_mem_fx, sts[1]->hTcxEnc->tfm_mem_fx ), 1 ) ), &tmp_e ); /* RMS */ + sts[0]->hTcxEnc->tfm_mem_fx = sts[1]->hTcxEnc->tfm_mem_fx = L_shl( L_tmp, tmp_e ); /* Q31 */ + move32(); + move32(); + sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = extract_l( L_shr( L_add( sts[0]->hTcxEnc->tcxltp_norm_corr_past, sts[1]->hTcxEnc->tcxltp_norm_corr_past ), 1 ) ); + move16(); + move16(); +#endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -626,29 +639,13 @@ void stereo_mdct_core_enc( st->prevEnergyHF_fx = floatToFixed_32( st->prevEnergyHF, q_com ); st->currEnergyHF_fx = floatToFixed_32( st->currEnergyHF, q_com ); st->currEnergyHF_e_fx = sub( Q31, q_com ); - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); - } } #endif - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; SetTCXModeInfo_ivas_fx( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - if ( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); - } - } -#endif #else for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -1128,16 +1125,6 @@ void stereo_mdct_core_enc( st->hTcxEnc->measuredBwRatio = ONE_IN_Q14; /* No bandwidth limit for the noise filling */ } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - if ( st->hTcxEnc ) - { - st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); - } - } -#endif #else for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -1438,17 +1425,6 @@ void stereo_mdct_core_enc( push_next_indice( hBstr, hStereoMdct->split_ratio, SMDCT_NBBITS_SPLIT_RATIO ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - sts = hCPE->hCoreCoder; - st = sts[ch]; - st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); - st->hTcxCfg->preemph_fac = float_to_fix16( st->hTcxCfg->preemph_fac_flt, Q15 ); - st->hTcxEnc->measuredBwRatio = float_to_fix16( st->hTcxEnc->measuredBwRatio_flt, Q14 ); - } -#endif - ivas_mdct_quant_coder_fx( hCPE, tnsBits, tnsSize, p_param, 0 ); pop_wmops(); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 3d0b9a22d..eee950911 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -620,7 +620,11 @@ ivas_error stereo_memory_enc_fx( #endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); +#ifndef IVAS_FLOAT_FIXED st->hTcxEnc->tfm_mem = 0.75f; +#else + st->hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ +#endif IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 2b6e1907d..f4841867b 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -516,7 +516,6 @@ void stereo_tcx_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Q_new = 0; - st->hTcxCfg->bandwidth = float_to_fix16( st->hTcxCfg->bandwidth_flt, Q15 ); Word16 exp_exc; f2me_buf_16( st->hLPDmem->old_exc_flt, st->hLPDmem->old_exc, &exp_exc, L_EXC_MEM ); Q_exc = 15 - exp_exc; @@ -2067,7 +2066,7 @@ Word16 ivas_acelp_tcx20_switching_fx( if ( ( GT_32( snr_acelp, tcx_snr ) ) && ( LT_32( snr_acelp, L_add( tcx_snr, 131072 /*2.0f Q16*/ ) ) ) && ( LT_16( add_o( st->prevTempFlatness_fx, currFlatness, &Overflow ), 52 /*3.25f Q4*/ ) || EQ_16( stab_fac, 0x7fff ) || - ( !flag_16k_smc && ( st->sp_aud_decision0 > 0 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && + ( !flag_16k_smc && ( st->sp_aud_decision0 > 0 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 320 /*20.f Q4*/ ) ) ) && ( LE_16( st->Nb_ACELP_frames, 6 ) ) ) { dsnr = -131072 /*-2.0f Q16*/; @@ -2079,7 +2078,7 @@ Word16 ivas_acelp_tcx20_switching_fx( test(); if ( ( LT_32( snr_acelp, tcx_snr ) ) && ( GT_32( snr_acelp, L_sub( tcx_snr, 131072 /*2.0f Q16*/ ) ) ) && - ( GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) && + ( GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 52 /*3.25f Q4*/ ) ) && ( GE_16( st->Nb_ACELP_frames, 6 ) ) ) { dsnr = 131072 /*2.0f Q16*/; @@ -2125,7 +2124,7 @@ Word16 ivas_acelp_tcx20_switching_fx( /* Select ACELP or TCX */ test(); test(); - IF( GT_32( L_add( snr_acelp, dsnr ), tcx_snr ) && ( st->sp_aud_decision0 == 0 || GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) ) ) + IF( GT_32( L_add( snr_acelp, dsnr ), tcx_snr ) && ( st->sp_aud_decision0 == 0 || GT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 52 /*3.25f Q4*/ ) ) ) { smc_dec_ol = 0; move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0a9bc483e..d3432bdc4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1110,7 +1110,7 @@ void RunTransientDetection_ivas_fx( * @return average temporal flatness measure with exponent AVG_FLAT_E */ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); -Word16 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( TRAN_DET_HANDLE pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); +Word16 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); /** Get the maximum energy change using subblock energies aligned with the TCX. * @param pTransientDetection Structure that contains transient detectors to be run. diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 4558945b9..8859acced 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1809,26 +1809,22 @@ typedef struct tcx_enc_structure int16_t tcxltp_pitch_fr_past; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_past_flt; -#else - Word16 tcxltp_gain_past; /* Q15 */ -#endif -#ifndef IVAS_FLOAT_FIXED float tcxltp_norm_corr_past_flt; -#endif - Word16 tcxltp_norm_corr_past; /* Q15 */ float tcxltp_norm_corr_mem_flt; - Word16 tcxltp_norm_corr_mem; /* Q15 */ -#ifndef IVAS_FLOAT_FIXED float kernel_switch_corr_past_flt; #else + Word16 tcxltp_gain_past; /* Q15 */ + Word16 tcxltp_norm_corr_past; /* Q15 */ + Word16 tcxltp_norm_corr_mem; /* Q15 */ Word16 kernel_switch_corr_past; /* Q15 */ #endif uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ uint16_t kernel_symmetry_past; /* last TDA symmetry (0 for MDCT, 1 for MDST type) */ uint16_t enc_ste_pre_corr_past; +#ifndef IVAS_FLOAT_FIXED float tfm_mem; /* state of IIR filtered temporal flatness measure */ -#ifdef IVAS_FLOAT_FIXED - Word32 tfm_mem_fx; /* state of IIR filtered temporal flatness measure */ /* Q31 */ +#else + Word32 tfm_mem_fx; /* state of IIR filtered temporal flatness measure Q31 */ #endif float buf_speech_ltp_flt[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; float *speech_ltp_flt; @@ -1844,9 +1840,12 @@ typedef struct tcx_enc_structure int16_t tcxltp_param[LTPSIZE]; int16_t tcxltp_on_mem; +#ifndef IVAS_FLOAT_FIXED float measuredBwRatio_flt; /* measured bw; used for TCX noise-filling */ - Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ - int16_t nmStartLine; /* Starting line for the noise measurement */ +#else + Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ +#endif + int16_t nmStartLine; /* Starting line for the noise measurement */ int16_t tcx_lpc_shaped_ari; @@ -2024,16 +2023,16 @@ typedef struct enc_core_structure float lsp_old[M]; /* old LSP vector at the end of the frame */ float lsf_old[M]; /* old LSF vector at the end of the frame */ float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ + float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ #else Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ #endif - float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - int16_t pstreaklen; /* LSF quantizer */ + int16_t pstreaklen; /* LSF quantizer */ #ifndef IVAS_FLOAT_FIXED float streaklimit; /* LSF quantizer */ float stab_fac; /* LSF stability factor */ diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 6d9ae393b..5355386df 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -952,7 +952,7 @@ void tcx_ltp_encode_ivas_fx( Word16 alpha_fx, step_fx; // Q15 Word16 norm_corr_fx; // Q15 Word16 border_case; - Word16 tempFlatness_fx; // Q7 + Word16 tempFlatness_fx; // Q4 Word16 maxEnergyChange_fx; // Q7 Word16 pred_speech_fx[L_FRAME_PLUS]; // Qspeech Word16 buf_zir_fx[M + L_FRAME_PLUS / 4], *zir_fx; // Qspeech @@ -1076,13 +1076,13 @@ void tcx_ltp_encode_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - tempFlatness_fx = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q7 + tempFlatness_fx = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q4 maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q7 } ELSE { - tempFlatness_fx = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, nPrevSubblocks ); + tempFlatness_fx = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, nPrevSubblocks ); // Q4 maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS, nPrevSubblocks ); } @@ -1108,7 +1108,7 @@ void tcx_ltp_encode_ivas_fx( ( tcxOnly == 0 ) && EQ_16( tcxMode, TCX_20 ) && GT_16( mult( norm_corr_fx, hTcxEnc->tcxltp_norm_corr_past ), 0x2000 ) && /*mult returns Q15*/ - LT_16( tempFlatness_fx, 448 /*3.5f Q7*/ ) ) || + LT_16( tempFlatness_fx, 56 /*3.5f Q4*/ ) ) || ( EQ_16( tcxOnly, 1 ) && EQ_16( tcxMode, TCX_10 ) && GT_16( s_max( norm_corr_fx, hTcxEnc->tcxltp_norm_corr_past ), 0x4000 ) && @@ -1121,8 +1121,8 @@ void tcx_ltp_encode_ivas_fx( ( EQ_16( tcxOnly, 1 ) && EQ_16( tcxMode, TCX_20 ) && GT_16( norm_corr_fx, 14418 /*0.44f Q15*/ ) && - ( LT_16( tempFlatness_fx, 768 /*6.0f Q7*/ ) || - ( LT_16( tempFlatness_fx, 896 /*7.0f Q7*/ ) && + ( LT_16( tempFlatness_fx, 96 /*6.0f Q4*/ ) || + ( LT_16( tempFlatness_fx, 112 /*7.0f Q4*/ ) && LT_16( maxEnergyChange_fx, 2816 /*22.0f Q7*/ ) ) ) ) ) { IF( disable_ltp == 0 ) @@ -1147,7 +1147,7 @@ void tcx_ltp_encode_ivas_fx( sqr = Sqrt16( hTcxEnc->tcxltp_on_mem, &exponent ); move16(); sqr = shl_sat( sqr, exponent ); - IF( ( EQ_16( tcxOnly, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( GT_16( ( mult( sqr, mult( ( norm_corr_fx ), 29492 ) ) ), 14419 ) && ( LT_16( tempFlatness_fx, 768 ) || ( LT_16( tempFlatness_fx, 896 ) && LT_16( maxEnergyChange_fx, 2816 ) ) ) ) ) ) // 0.9f Q15, 6.0f Q7, 7.0f Q7, 22.0f Q7 + IF( ( EQ_16( tcxOnly, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( GT_16( ( mult( sqr, mult( ( norm_corr_fx ), 29492 ) ) ), 14419 ) && ( LT_16( tempFlatness_fx, 96 ) || ( LT_16( tempFlatness_fx, 112 ) && LT_16( maxEnergyChange_fx, 2816 ) ) ) ) ) ) // 0.9f Q15, 6.0f Q4, 7.0f Q4, 22.0f Q7 { ltp_on = 1; move16(); diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index f10b01afb..90ffd2f2f 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -48,6 +48,7 @@ #define ONE_POINT_ONE_FIVE_Q7 147 #define ONE_POINT_ONE_FIVE_Q23 9646899 +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * ComputeSpectrumNoiseMeasure() * @@ -286,6 +287,7 @@ void mdct_preShaping( return; } +#endif /*---------------------------------------------------------------------* @@ -440,6 +442,7 @@ void PsychAdaptLowFreqEmph( return; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * SQ_gain() * @@ -618,88 +621,6 @@ void tcx_scalar_quantization( return; } -#ifdef IVAS_FLOAT_FIXED -void tcx_scalar_quantization_ivas_fx( - Word32 *x, - /* i: input coefficients */ // x_e - Word16 x_e, /* i: exponent */ - Word16 *xq, /* o: quantized coefficients */ - Word16 L_frame, /* i: frame length */ - Word16 gain, - /* i: quantization gain */ // gain_e - Word16 gain_e, /* i: quantization gain exponent */ - Word16 offset, /* i: rounding offset (deadzone) */ - Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ - const Word16 alfe_flag ) -{ - Word16 i, tmp16, s; - Word32 tmp32, offs32; - - - /* common exponent for x and gain for comparison */ - tmp16 = sub( gain_e, x_e ); - tmp32 = L_shl( L_deposit_h( gain ), s_max( -31, s_min( tmp16, 0 ) ) ); - tmp16 = negate( s_max( tmp16, 0 ) ); - - i = sub( L_frame, 1 ); - IF( memQuantZeros_fx != NULL ) - { - test(); - WHILE( ( memQuantZeros_fx[i] != 0 ) && ( LT_32( L_abs( L_shl( x[i], tmp16 ) ), tmp32 ) ) ) - { - test(); - xq[i] = 0; - move16(); - i = sub( i, 1 ); - } - } - - /* invert gain */ - gain = Inv16( gain, &gain_e ); - - s = sub( add( x_e, gain_e ), 15 ); - - /*It should almost never happen and if so the quantization will be discarded later on (saturation of gain Quantizer).*/ - IF( GT_16( s, 31 ) ) - { - /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ - gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ - gain_e = 2; - - s = sub( add( x_e, gain_e ), 15 ); - } - - /* substract 0x8000 to affect the mac_r in the following loop - so it acts like extract_h. the 0x4000 will be multiplied by 2 - by the mac_r to get to 0x8000 and disable the round. */ - offset = sub( offset, 0x4000 ); - - FOR( ; i >= 0; i-- ) - { - offs32 = Mpy_32_16_1( L_abs( x[i] ), gain ); /* multiply */ -#ifdef BASOP_NOGLOB - offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ - tmp16 = mac_r_sat( offs32, offset, 1 ); /* add offset and truncate */ -#else - offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ - tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ -#endif - if ( x[i] < 0 ) - tmp16 = negate( tmp16 ); /* restore sign */ - - xq[i] = tmp16; - move16(); - } - - IF( alfe_flag == 0 ) - { - AdaptLowFreqEmph_fx( x, x_e, xq, gain, gain_e, - 0, NULL, NULL, - L_frame ); - } -} -#endif - /*---------------------------------------------------------------------* * tcx_scalar_quantization_rateloop() * @@ -1092,7 +1013,6 @@ void tcx_noise_factor( } -#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * tcx_encoder_memory_update() * @@ -1154,7 +1074,6 @@ void tcx_encoder_memory_update( return; } -#endif /*---------------------------------------------------------------------* @@ -1506,6 +1425,7 @@ int16_t tcx_res_Q_spec( return bits; } +#endif #ifdef IVAS_FLOAT_FIXED @@ -1865,6 +1785,7 @@ void ProcessStereoIGF( } #endif +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * attenuateNbSpectrum() * @@ -1889,3 +1810,4 @@ void attenuateNbSpectrum( return; } +#endif diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 950856d73..ee08dd9ad 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1098,6 +1098,84 @@ void tcx_scalar_quantization_fx( } } +void tcx_scalar_quantization_ivas_fx( + Word32 *x, /* i: input coefficients exponent = x_e */ + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, /* i: quantization gain exponent = gain_e */ + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ + const Word16 alfe_flag ) +{ + Word16 i, tmp16, s; + Word32 tmp32, offs32; + + + /* common exponent for x and gain for comparison */ + tmp16 = sub( gain_e, x_e ); + tmp32 = L_shl( L_deposit_h( gain ), s_max( -31, s_min( tmp16, 0 ) ) ); + tmp16 = negate( s_max( tmp16, 0 ) ); + + i = sub( L_frame, 1 ); + IF( memQuantZeros_fx != NULL ) + { + test(); + WHILE( ( memQuantZeros_fx[i] != 0 ) && ( LT_32( L_abs( L_shl( x[i], tmp16 ) ), tmp32 ) ) ) + { + test(); + xq[i] = 0; + move16(); + i = sub( i, 1 ); + } + } + + /* invert gain */ + gain = Inv16( gain, &gain_e ); + + s = sub( add( x_e, gain_e ), 15 ); + + /*It should almost never happen and if so the quantization will be discarded later on (saturation of gain Quantizer).*/ + IF( GT_16( s, 31 ) ) + { + /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ + gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ + gain_e = 2; + + s = sub( add( x_e, gain_e ), 15 ); + } + + /* substract 0x8000 to affect the mac_r in the following loop + so it acts like extract_h. the 0x4000 will be multiplied by 2 + by the mac_r to get to 0x8000 and disable the round. */ + offset = sub( offset, 0x4000 ); + + FOR( ; i >= 0; i-- ) + { + offs32 = Mpy_32_16_1( L_abs( x[i] ), gain ); /* multiply */ +#ifdef BASOP_NOGLOB + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat( offs32, offset, 1 ); /* add offset and truncate */ +#else + offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ +#endif + if ( x[i] < 0 ) + tmp16 = negate( tmp16 ); /* restore sign */ + + xq[i] = tmp16; + move16(); + } + + IF( alfe_flag == 0 ) + { + AdaptLowFreqEmph_fx( x, x_e, xq, gain, gain_e, + 0, NULL, NULL, + L_frame ); + } +} + Word16 tcx_scalar_quantization_rateloop_fx( Word32 *x, /* i : input coefficients */ Word16 x_e, /* i : exponent */ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index f15a3862e..6d237279c 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -317,7 +317,7 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTr return i; } -Word16 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( TRAN_DET_HANDLE pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ) +Word16 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ) { Word16 i; TransientDetector const *pTransientDetector; @@ -343,14 +343,14 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( TRAN_DET_HANDLE pTransientDetec assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); - pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[sub( nRelativeDelay, nPrevSubblocks )]; // subblockNrgChange Q7 + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[sub( nRelativeDelay, nPrevSubblocks )]; // subblockNrgChange Q3 FOR( i = 0; i < nTotBlocks; i++ ) { sumTempFlatness = L_add( sumTempFlatness, L_deposit_l( pSubblockNrgChange[i] ) ); } /* exponent = AVG_FLAT_E */ - i = div_l( L_shl( sumTempFlatness, 16 - 15 + SUBBLOCK_NRG_CHANGE_E - AVG_FLAT_E ), nTotBlocks ); // Q7 + i = div_l( L_shl( sumTempFlatness, 2 ), nTotBlocks ); // Q4 return i; } @@ -561,17 +561,11 @@ void RunTransientDetection_ivas_fx( /* Update subblock energies. */ #ifdef MSAN_FIX - Scale_sig( filteredInput_fx, length, sub( 7, q_input ) ); // q7 + Scale_sig( filteredInput_fx, length, sub( 0, q_input ) ); // q0 #else Scale_sig( filteredInput_fx, L_FRAME_MAX, 8 ); #endif - Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, 3 ); - Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, 3 ); - Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, 3 ); UpdateSubblockEnergies_ivas_fx( filteredInput_fx, length, pSubblockEnergies ); - Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, -3 ); - Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, -3 ); - Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, -3 ); /* Run transient detectors. */ RunTransientDetector( pTransientDetector ); @@ -723,8 +717,8 @@ void SetTCXModeInfo_ivas_fx( move16(); } } - tmp = BASOP_Util_Divide3216_Scale( ONE_IN_Q31, GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); - tmp = shl( tmp, sub( exp_diff, AVG_FLAT_E ) ); // Q15 + tmp = BASOP_Util_Divide3216_Scale( ONE_IN_Q20, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); + tmp = shl( tmp, exp_diff ); // Q15 test(); IF( isLongTermTransient_fx( L_deposit_h( tmp ), &hTcxEnc->tfm_mem_fx ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -753,8 +747,8 @@ void SetTCXModeInfo_ivas_fx( *tcxModeOverlap = ALDO_WINDOW; move16(); } - tmp = BASOP_Util_Divide3216_Scale( ONE_IN_Q31, GetTCXAvgTemporalFlatnessMeasure_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); - tmp = shl( tmp, sub( exp_diff, AVG_FLAT_E ) ); // Q15 + tmp = BASOP_Util_Divide3216_Scale( ONE_IN_Q20, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); + tmp = shl_sat( tmp, exp_diff ); // Q15 test(); IF( isLongTermTransient_fx( L_deposit_h( tmp ), &hTcxEnc->tfm_mem_fx ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -966,7 +960,7 @@ static void InitSubblockEnergies_ivas_fx( Word16 nFrameLength, Word16 nDelay, De assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set32_fx( pSubblockEnergies->subblockNrg, 13743, nMaxBuffSize ); + set32_fx( pSubblockEnergies->subblockNrg, 107 /* 107.37 in Q0 */, nMaxBuffSize ); set32_fx( pSubblockEnergies->accSubblockNrg, 13743, nMaxBuffSize + 1 ); set16_fx( pSubblockEnergies->subblockNrgChange, ONE_IN_Q7, nMaxBuffSize ); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; @@ -1314,12 +1308,14 @@ static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamp IF( nWindows > 0 ) { /* Process left over samples from the previous frame. */ - accu = L_add( 109568, 0 ); // 107 in Q10 + accu = 107; // 107.37f in Q0 + move32(); assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); FOR( k = 0; k < nPartialDelay; k++ ) { - tmp = shr( delayBuffer[k], SUBBLOCK_NRG_E / 2 ); - accu = L_mac0( accu, tmp, tmp ); + tmp = delayBuffer[k]; // Q0 + move16(); + accu = L_mac0( accu, tmp, tmp ); // Q0 } /* Process new samples in the 0. subblock. */ @@ -1327,39 +1323,46 @@ static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamp assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); FOR( k = 0; k < w; k++ ) { - tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); + tmp = input[k]; // Q0 + move16(); #ifdef BASOP_NOGLOB - accu = L_mac0_sat( accu, tmp, tmp ); + accu = L_mac0_sat( accu, tmp, tmp ); // Q0 #else accu = L_mac0( accu, tmp, tmp ); #endif } + pSubblockNrg[0] = accu; // Q0 move32(); - pSubblockNrg[0] = accu; // Q10 /* Set accumulated subblock energy at this point. */ UpdatedAndStoreAccWindowNrg( pSubblockNrg[0], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[0] ); FOR( w = 1; w < nWindows; w++ ) { - accu = L_add( 109568, 0 ); // 107 in Q10 + accu = 107; // 107.37f in Q0 + move32(); /* Process new samples in the w. subblock. */ k2 = add( k, nSubblockSize ); assert( ( SUBBLOCK_NRG_E & 1 ) == 0 ); FOR( ; k < k2; k++ ) { - tmp = shr( input[k], SUBBLOCK_NRG_E / 2 ); + tmp = input[k]; // Q0 + move16(); #ifdef BASOP_NOGLOB - accu = L_mac0_sat( accu, tmp, tmp ); + accu = L_mac0_sat( accu, tmp, tmp ); // Q0 #else accu = L_mac0( accu, tmp, tmp ); #endif } + pSubblockNrg[w] = accu; // Q0 move32(); - pSubblockNrg[w] = accu; /* Set accumulated subblock energy at this point. */ UpdatedAndStoreAccWindowNrg( pSubblockNrg[w], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[w] ); } + pSubblockEnergies->subblockNrg_e = 31; + pSubblockEnergies->accSubblockNrg_e = 31; + move16(); + move16(); /* Calculate energy change for each block. */ FOR( w = 0; w < nWindows; w++ ) @@ -1377,10 +1380,10 @@ static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, Word16 nSamp } move16(); pSubblockNrgChange[w] = MAX_16; - IF( LT_16( k, 5 ) ) + IF( LT_16( k, 12 ) ) { move16(); - pSubblockNrgChange[w] = shr( k2, sub( 5, k ) ); + pSubblockNrgChange[w] = shr_r( k2, sub( 12, k ) ); } } } -- GitLab