diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 0eb6d1887000dae2413c69c169fdcfe76c23bf1d..f4f9d5651b6de545225ca3cbde830cedbed5ae4e 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -56,7 +56,7 @@ #define SCE_SMC_THR 16000 -static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 *enerBuffer_dft_e ); +static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 enerBuffer_dft_e[] ); #ifdef IVAS_FIXED_ENC static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_dft_fx[], Word16 *enerBuffer_dft_q_fx, const Word16 no_channels, const Word32 input_Fs ); @@ -222,6 +222,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; Word16 Qfact_PS, q_lf_E_fx; + Word16 enerBuffer_fx_exp_buf[CLDFB_NO_CHANNELS_MAX]; #ifdef DEBUG_MODE_INFO Word32 *in_buff_temp; Word16 in_q_temp; @@ -474,7 +475,7 @@ ivas_error pre_proc_front_ivas_fx( } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - calculate_energy_buffer_ivas_fx( hCPE, enerBuffer_fx, st->cldfbAnaEnc->no_channels, input_Fs, enerBuffer_fx_exp ); + calculate_energy_buffer_ivas_fx( hCPE, enerBuffer_fx, st->cldfbAnaEnc->no_channels, input_Fs, enerBuffer_fx_exp_buf ); } ELSE { @@ -841,10 +842,18 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * NB/WB/SWB/FB bandwidth detector *----------------------------------------------------------------*/ - FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - sf_energySum[i] = *enerBuffer_fx_exp; - move16(); + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + sf_energySum[i] = enerBuffer_fx_exp_buf[i]; + move16(); + } + } + ELSE + { + set16_fx( sf_energySum, *enerBuffer_fx_exp, CLDFB_NO_CHANNELS_MAX ); } test(); @@ -856,6 +865,15 @@ ivas_error pre_proc_front_ivas_fx( bw_detect_fx( st, input_fx_tmp, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); } + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + maximum_fx( sf_energySum, CLDFB_NO_CHANNELS_MAX, enerBuffer_fx_exp ); + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + enerBuffer_fx[i] = L_shl( enerBuffer_fx[i], sub( sf_energySum[i], *enerBuffer_fx_exp ) ); + move32(); + } + } IF( NE_16( element_mode, IVAS_CPE_MDCT ) ) /* in MDCT stereo, set_bw_stereo() is used instead */ { @@ -1840,7 +1858,7 @@ static void calculate_energy_buffer_ivas_fx( Word32 enerBuffer_dft_fx[], /* o : energy buffer() exp(enerBuffer_dft_e)*/ const Word16 no_channels, /* i : no. of used CLDFB channels Q0*/ const Word32 input_Fs, /* i : input sampling rate Q0*/ - Word16 *enerBuffer_dft_e ) + Word16 enerBuffer_dft_e[] ) { Word16 i, j, guard_bits; Word64 nrg_DMX_fx[CLDFB_NO_CHANNELS_MAX]; @@ -1848,11 +1866,8 @@ static void calculate_energy_buffer_ivas_fx( Word32 *pDFT_DMX_fx; /*q_DFT_DMX_fx*/ Word32 chan_width_bins_fx; Word16 band_res_dft_fx, chan_width_f_fx, start, stop; - Word16 norm_nrg_DMX_fx; - Word64 max_abs_nrg_DMX_fx; + Word16 norm_nrg_DMX_fx[CLDFB_NO_CHANNELS_MAX]; - max_abs_nrg_DMX_fx = 0; - move64(); Word16 temp_q1 = sub( norm_l( input_Fs ), 1 ); Word16 temp_q2 = norm_s( hCPE->hStereoDft->NFFT ); @@ -1884,30 +1899,28 @@ static void calculate_energy_buffer_ivas_fx( *p_nrg_DMX_fx = W_add( *p_nrg_DMX_fx, W_shr( W_mult_32_32( pDFT_DMX_fx[2 * j + 1], pDFT_DMX_fx[2 * j + 1] ), guard_bits ) ); /* 2 * q_DFT_DMX_fx + 1 - guard_bits */ move64(); } - IF( GT_64( W_abs( *p_nrg_DMX_fx ), max_abs_nrg_DMX_fx ) ) - { - max_abs_nrg_DMX_fx = W_abs( *p_nrg_DMX_fx ); - } + norm_nrg_DMX_fx[i] = W_norm( W_abs( *p_nrg_DMX_fx ) ); + move16(); start = stop; move16(); p_nrg_DMX_fx++; } - norm_nrg_DMX_fx = W_norm( max_abs_nrg_DMX_fx ); FOR( i = 0; i < no_channels; i++ ) /* Consider only used channels, dependent on Fs */ { - enerBuffer_dft_fx[i] = Mpy_32_16_1( W_extract_h( W_shl( nrg_DMX_fx[i], norm_nrg_DMX_fx ) ), 10923 /* 1/3 in Q15 */ ); /* 2 * q_DFT_DMX_fx + 1 - guard_bits + norm_nrg_DMX_fx - 32 */ + enerBuffer_dft_fx[i] = Mpy_32_16_1( W_extract_h( W_shl( nrg_DMX_fx[i], norm_nrg_DMX_fx[i] ) ), 10923 /* 1/3 in Q15 */ ); /* 2 * q_DFT_DMX_fx + 1 - guard_bits + norm_nrg_DMX_fx[i] - 32 */ move32(); + enerBuffer_dft_e[i] = sub( add( shl( hCPE->hStereoDft->DFT_fx_e[0], 1 ), guard_bits ), norm_nrg_DMX_fx[i] ); + move16(); } - *enerBuffer_dft_e = sub( add( shl( hCPE->hStereoDft->DFT_fx_e[0], 1 ), guard_bits ), norm_nrg_DMX_fx ); - move16(); - /* Set remaining entries of enerBuffer to zero */ FOR( ; i < CLDFB_NO_CHANNELS_MAX; i++ ) { enerBuffer_dft_fx[i] = 0; move32(); + enerBuffer_dft_e[i] = 0; + move16(); } return; }