diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index 077463885fa8f9b4bf86e4986b37cbf1126b4df7..9ae92e61ff1bcf658acf5354191a1a6d844c87fa 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -106,7 +106,6 @@ void bands_and_bit_alloc_ivas_fx( Word32 sum_bit /*Q0*/, bit_fracf /*Q18*/; Word16 etmp; Word16 tmp; - Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; // Q13 Word16 pos, band; Word32 SWB_bit_budget; // Q0 -> Q18 Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; // Q18 @@ -126,7 +125,6 @@ void bands_and_bit_alloc_ivas_fx( nb_tot_bands = MBANDS_GN_BITALLOC16k; move16(); } - Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands ); set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); @@ -138,7 +136,7 @@ void bands_and_bit_alloc_ivas_fx( ener_vec[0] = add( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ #endif move16(); - Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ + Copy( Ener_per_bd_iQ + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; move16(); IF( EQ_16( L_frame, L_FRAME16k ) ) diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index e0fed0fa671dfebbef9516a9d790bf0094c9efb4..e23a926bea6c2edbf4e5ec3c3bf181cb394be6c7 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -322,20 +322,19 @@ static void house_refl_fx( Word32 rcp_fx = L_deposit_h( tmp ); // rcp_q Word16 rcp_q = sub( Q31, exp ); - rcp_fx = L_shr( rcp_fx, sub( rcp_q, Q31 ) ); // making rcp_fx in Q31 FOR( i = 0; i < sizex; i++ ) { norm = norm_l( pu_fx[i] ); L_tmp = L_shl( pu_fx[i], norm ); - pu_fx[i] = Mpy_32_32( L_tmp, rcp_fx ); // px_q + Q31 - Q31 -> px_q - pu_e[i] = sub( 31, add( px_q, norm ) ); + pu_fx[i] = Mpy_32_32( L_tmp, rcp_fx ); // ( px_q + norm ) + rcp_q - 31 -> exp: 31 + 31 - (px_q + norm + rcp_q) + pu_e[i] = sub( 62, add( add( px_q, norm ), rcp_q ) ); move32(); move16(); } IF( pu_fx[0] >= 0 ) { - pu_fx[0] = L_add( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); + pu_fx[0] = BASOP_Util_Add_Mant32Exp( pu_fx[0], pu_e[0], ONE_IN_Q30, 1, &pu_e[0] ); ( *normu_fx ) = L_negate( *normu_fx ); move32(); @@ -343,7 +342,7 @@ static void house_refl_fx( } ELSE { - pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); + pu_fx[0] = BASOP_Util_Add_Mant32Exp( pu_fx[0], pu_e[0], -ONE_IN_Q30, 1, &pu_e[0] ); move32(); } @@ -357,8 +356,8 @@ static void house_refl_fx( FOR( i = 0; i < sizex; i++ ) { pu_fx[i] = Mpy_32_32( pu_fx[i], rcp_fx ); // pu_e[i] + exp2 - pu_fx[i] = L_shl( pu_fx[i], exp2 ); // pu_e[i] + exp2 move32(); + pu_e[i] = add( pu_e[i], exp2 ); move32(); } @@ -489,6 +488,7 @@ static void house_qr_fx( Word32 U_fx[FOA_CHANNELS * FOA_CHANNELS]; Word16 U_e[FOA_CHANNELS * FOA_CHANNELS]; Word32 pu_fx[FOA_CHANNELS]; + Word16 tmp_pu_e[FOA_CHANNELS]; Word16 pv_exp[FOA_CHANNELS]; Word32 pa_fx[FOA_CHANNELS]; Word16 tmp_e; @@ -573,8 +573,10 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); // pu_fx_q + pu_fx[i] = U_fx[i * n + k]; move32(); + tmp_pu_e[i] = U_e[i * n + k]; + move16(); } FOR( s = k; s < n_rows; s++ ) @@ -586,8 +588,8 @@ static void house_qr_fx( } - pv_fx[s - k] = dotp_fixed( &pu_fx[k], &pa_fx[k], sub( n_rows, k ) ); // pu_fx_q + Q31 - Q31 - pv_exp[s - k] = sub( 31, pu_fx_q ); + pv_fx[s - k] = dotp_fixed( &pu_fx[k], &pa_fx[k], sub( n_rows, k ) ); // exp: tmp_pu_e[k] + pv_exp[s - k] = tmp_pu_e[k]; move32(); move16(); } diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5a71e41c757fe864302b1899d31873c347a1b8e9..668aca945216955c6120356c8b4dc1eba488eab2 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -779,6 +779,10 @@ void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); +void destroy_evs_core_enc_fx( + ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ +); + ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sce_id, /* i : SCE # identifier */ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 6a4800d4f6df04cec245c6c6af563dd75f6fc4e1..3c47c0e627b501b68e395e8ed81f8a8aa26ce972 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -481,7 +481,7 @@ ivas_error acelp_core_enc( Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn1_fx + add( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); + Copy( syn1_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); /* save and delay synthesis to be used by SWB BWE */ IF( st->hBWE_FD != NULL ) @@ -785,7 +785,11 @@ ivas_error acelp_core_enc( IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { Copy( syn1_fx + shr( st->L_frame, 1 ), st->hTcxEnc->Txnq, shr( st->L_frame, 1 ) ); +#ifdef MSAN_FIX + Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 1 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) ); +#else Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 2 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) ); +#endif st->hTcxEnc->q_Txnq = st->Q_syn; move16(); } @@ -810,7 +814,11 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) ); +#ifdef MSAN_FIX + Scale_sig( res_fx, st->L_frame, sub( s_min( st->Q_syn, Q_new ), Q_new ) ); +#else Scale_sig( res_fx, L_FRAME16k, sub( s_min( st->Q_syn, Q_new ), Q_new ) ); +#endif FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) ); IF( st->hBWE_TD != NULL ) { diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 392411e68bfb9c1543e896d4cfa7ec239a195c91..171e57bfa7d24c17fbc4f428150c0b43c6ceab4b 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -310,7 +310,8 @@ static void find_enr_dft_fx( move32(); BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); - band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); + // To Be Checked + band_fx[i] = L_add_sat( BinE_fx[bin_cnt], band_fx[i] ); move32(); ptR_fx += 2; ptI_fx += 2; @@ -409,8 +410,10 @@ static void find_enr_dft_fx( } *Etot_fx = tmp_fx; - scale_sig32( band_fx, NB_BANDS, 2 ); - scale_sig32( band_ener_fx, NB_BANDS, 2 ); + // To Be Checked + Scale_sig32( band_fx, NB_BANDS, 2 ); + // To Be Checked + Scale_sig32( band_ener_fx, NB_BANDS, 2 ); move32(); return; } diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index 1af9e346388cb7ec4b3a2a0d65a4e4a65a65af32..106f6e83638bea5ba35c069fb80608bb4335c1fb 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -76,7 +76,87 @@ void gauss_L2_fx( } tmp16 = norm_l( tmp32 ); +#ifdef BASOP_NOGLOB + g_corr->y1y1 = round_fx_sat( L_shl( tmp32, tmp16 ) ); +#else g_corr->y1y1 = round_fx( L_shl( tmp32, tmp16 ) ); +#endif + g_corr->y1y1_e = sub( 31 - 18, tmp16 ); + move16(); + + tmp16 = norm_l( tmp32_2 ); +#ifdef BASOP_NOGLOB + g_corr->y1y2 = round_fx_sat( L_shl( tmp32_2, tmp16 ) ); +#else + g_corr->y1y2 = round_fx( L_shl( tmp32_2, tmp16 ) ); +#endif + g_corr->y1y2_e = sub( 31 - 18, tmp16 ); + move16(); +} + +void gauss_L2_ivas_fx( + const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ + Word16 code[], /* o : gaussian excitation Q9 */ + const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ + Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ + Word32 *gain, /* o : excitation gain Q16 */ + ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ + const Word16 gain_pit, /* i : unquantized gain of code Q14 */ + const Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 *Aq, /* i : quantized LPCs Q12 */ + const Word16 formant_enh_num, /* i : formant enhancement numerator factor Q15 */ + Word16 *seed_acelp, /*i/o : random seed Q0 */ + const Word16 shift ) +{ + Word16 i, tmp16; + Word32 tmp32, tmp32_2; + + + assert( gain_pit == 0 ); + + /*-----------------------------------------------------------------* + * Find new target for the Gaussian codebook + *-----------------------------------------------------------------*/ + + /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ + FOR( i = 0; i < L_SUBFR; i++ ) + { + Random( seed_acelp ); + tmp32 = L_mac( 0, *seed_acelp, 1 << 9 ); + + Random( seed_acelp ); + tmp32 = L_mac( tmp32, *seed_acelp, 1 << 9 ); + + Random( seed_acelp ); + code[i] = mac_r( tmp32, *seed_acelp, 1 << 9 ); + move16(); + } + + /*Shape the gaussian excitation*/ + cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1, L_SUBFR ); + + /*compute 0s memory weighted synthesis contribution and find gain*/ + E_UTIL_f_convolve( code, h, y11, L_SUBFR ); /* y11: Q8+shift */ + Scale_sig( y11, L_SUBFR, sub( 1, shift ) ); /* Q9 */ + *gain = L_deposit_l( 0 ); + + /*Update correlations for gains coding */ + tmp32 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ + tmp32_2 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */ + + FOR( i = 0; i < L_SUBFR; i++ ) + { + tmp32 = L_mac0( tmp32, y11[i], y11[i] ); /* Q18 */ + tmp32_2 = L_mac0( tmp32_2, y11[i], y2[i] ); /* Q18 */ + } + + tmp16 = norm_l( tmp32 ); + // To be checked +#ifdef BASOP_NOGLOB + g_corr->y1y1 = round_fx_sat( L_shl( tmp32, tmp16 ) ); +#else + g_corr->y1y1 = round_fx( L_shl( tmp32, tmp16 ) ); +#endif g_corr->y1y1_e = sub( 31 - 18, tmp16 ); move16(); diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 9e8e133b4ecadbf8b56b161f65ea8e3657100daf..1711e2c56a6cd2679f8cbfc07e1b52785a907fb8 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -545,9 +545,6 @@ void init_coder_ace_plus( init_modes_ivas_fx( st, last_total_brate ); #endif /* Adaptive BPF */ - set_zero( st->mem_bpf, 2 * L_FILT16k ); - set_zero( st->mem_error_bpf, 2 * L_FILT16k ); - if ( st->total_brate >= HQ_48k ) { st->enablePlcWaveadjust = 1; diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 10ac4d570cb2229b54bf5b40b7c98a4b60bf3f05..bdb5f5bc1daf92f9d5b7e271bd736a3e35a429ff 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -207,13 +207,8 @@ void core_coder_mode_switch_ivas_fx( move32(); /* Initialize Signal Buffers */ - f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); - - /* Adaptive BPF */ - set_zero( st->mem_bpf, 2 * L_FILT16k ); - set_zero( st->mem_error_bpf, 2 * L_FILT16k ); #endif init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); IF( st->hLPDmem != NULL ) diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index ae445a35b738bd738d32f69c07a85de777b40b58..af773cac453fa0e258ffb57e8936fc6cd0c5b302 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -822,7 +822,11 @@ void E_ACELP_4tsearchx_ivas_fx( alp = shr( alp, 1 ); Scale_sig( cor, L_SUBFR, -1 ); Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 ); +#ifndef MSAN_FIX Scale_sig( dn, 2 * L_SUBFR, -1 ); +#else + Scale_sig( dn, L_SUBFR, -1 ); +#endif } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index 70a63105d660db565d99ce6fd7ce6bb0d6198d41..898a8b49a26a31b3319b088628a47873d27e728f 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -405,7 +405,7 @@ void encod_unvoiced_ivas_fx( move16(); assert( gain_pit_fx == 0 ); - gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); /*----------------------------------------------------------* * - Compute the fixed codebook gain * diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index c17dc9245fa3c8802160cac0b081c15bd6cb4ba6..fb98e8b7ccbe7f858091d8af12042c53ef543470 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -1366,7 +1366,12 @@ void gain_enc_SQ_ivas_fx( *gain_pit = round_fx( L_shl( L_div, add( exp, exp_div ) ) ); /*Q14*/ #endif /* BASOP_NOGLOB */ - L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ + // To be checked +#ifdef BASOP_NOGLOB + L_tmp1 = L_mult_o( coeff[1], coeff[4], &Overflow ); /*Q31*/ +#else /* BASOP_NOGLOB */ + L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ +#endif /* BASOP_NOGLOB */ exp1 = add( exp_coeff[1], exp_coeff[4] ); L_tmp2 = L_mult( coeff[0], coeff[3] ); /*Q31*/ diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index f701a53a4dd5b86794cb78ba61e62760c9a70f33..8fb4481483157d49d5b2f34cacb63fafcc3927b6 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -169,13 +169,15 @@ ivas_error init_encoder( #ifndef IVAS_FLOAT_FIXED init_gp_clip( st->clip_var ); pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + set_f( st->old_wsp, 0, L_WSP_MEM ); #else init_gp_clip_fx( st->clip_var_fx ); pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); #endif - set_f( st->old_wsp, 0, L_WSP_MEM ); #ifdef IVAS_FLOAT_FIXED set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); + st->exp_old_wsp = 0; + move16(); #endif #ifndef IVAS_FLOAT_FIXED set_f( st->old_wsp2, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); @@ -192,6 +194,11 @@ ivas_error init_encoder( st->mem_deemp_preQ_fx = 0; #endif /* AVQ pre-quantizer memory */ +#ifndef IVAS_FLOAT_FIXED + st->mem_preemp_preQ = 0.0f; +#else + st->mem_preemp_preQ_fx = 0; +#endif st->last_nq_preQ = 0; st->last_code_preq = 0; st->use_acelp_preq = 0; @@ -199,11 +206,23 @@ ivas_error init_encoder( /* (Decimated) Weighted Speech Memory */ #ifndef IVAS_FLOAT_FIXED - st->mem_preemp_preQ = 0.0f; st->mem_wsp_enc_flt = 0.0; st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); +#else +#ifdef MSAN_FIX + st->mem_wsp_enc = 0; + move16(); + st->mem_wsp_fx = 0; + move16(); + st->mem_wsp_q = 0; + move16(); + set16_fx( st->mem_decim2_fx, 0, 3 ); + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + st->Q_old_wsp2 = Q15; + move16(); +#endif #endif #ifndef IVAS_FLOAT_FIXED @@ -892,6 +911,10 @@ ivas_error init_encoder( fd_bwe_enc_init( st->hBWE_FD ); #else fd_bwe_enc_init_fx( st->hBWE_FD ); +#ifdef MSAN_FIX + st->Q_old_wtda = 0; + move16(); +#endif #endif } else @@ -999,8 +1022,9 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } #ifdef MSAN_FIX - set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + // set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); + st->hTcxEnc->spectrum_long_e = 0; #endif // MSAN_FIX /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ @@ -1012,8 +1036,8 @@ ivas_error init_encoder( move16(); #endif // IVAS_FLOAT_FIXED - st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; - st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; + // st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; + // st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; #ifdef MSAN_FIX set32_fx( st->hTcxEnc->spectrum_fx[0], 0, N_TCX10_MAX ); @@ -1359,6 +1383,8 @@ ivas_error init_encoder_ivas_fx( init_gp_clip_fx( st->clip_var_fx ); pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); + st->exp_old_wsp = 0; + move16(); set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. st->Q_old_wsp2 = 0; move16(); @@ -1373,7 +1399,6 @@ ivas_error init_encoder_ivas_fx( move16(); #if 1 // TODO: Float Initializations. To be removed later - set_f( st->old_wsp, 0, L_WSP_MEM ); st->mem_preemph = 0.0f; st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); @@ -1584,7 +1609,11 @@ ivas_error init_encoder_ivas_fx( st->exp_buf_wspeech_enc = 0; move16(); /* initializations */ +#ifndef MSAN_FIX set32_fx( st->Bin_E_old_fx, 0, shr( L_FFT, 2 ) ); +#else + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); +#endif st->q_Bin_E_old = Q31; move16(); set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); @@ -2028,6 +2057,10 @@ ivas_error init_encoder_ivas_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); +#ifdef MSAN_FIX + st->Q_old_wtda = 0; + move16(); +#endif } ELSE { @@ -2133,6 +2166,8 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } + set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); + st->hTcxEnc->spectrum_long_e = 0; /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; @@ -2141,10 +2176,10 @@ ivas_error init_encoder_ivas_fx( move16(); move16(); #if 1 - set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); - st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; - st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; - // set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); + // set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + // st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; + // st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; + // set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); #endif set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); @@ -2290,14 +2325,10 @@ ivas_error init_encoder_ivas_fx( #endif /* Initialize Signal Buffers */ - f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); /* Initialize ACELP */ - /* Adaptive BPF */ - set_zero( st->mem_bpf, 2 * L_FILT16k ); - set_zero( st->mem_error_bpf, 2 * L_FILT16k ); #endif init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 803dbe595c4b510577ed647ea78b0a317d2d333c..a7b6b402fe98881d77d841f2799213abc8d30a48 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -149,8 +149,6 @@ ivas_error init_encoder_fx( { st_fx->hBstr = NULL; } - st_fx->hBstr->nb_bits_tot = 0; - move16(); Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); @@ -665,22 +663,6 @@ ivas_error init_encoder_fx( st_fx->hTECEnc = NULL; } - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - IF( !vad_only_flag ) - { - IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); - } - } - ELSE - { - st_fx->hBstr = NULL; - } - /*-----------------------------------------------------------------* * SWB BWE parameters *-----------------------------------------------------------------*/ @@ -781,6 +763,9 @@ ivas_error init_encoder_fx( /*st_fx->hTcxEnc->spectrum[0] = st_fx->hTcxEnc->spectrum_long; st_fx->hTcxEnc->spectrum[1] = st_fx->hTcxEnc->spectrum_long + N_TCX10_MAX;*/ + st_fx->hTcxEnc->spectrum_fx[0] = st_fx->hTcxEnc->spectrum_long_fx; + st_fx->hTcxEnc->spectrum_fx[1] = st_fx->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + set16_fx( st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k ); st_fx->hTcxEnc->Q_old_out = 0; @@ -1013,13 +998,16 @@ void LPDmem_enc_init_ivas_fx( set16_fx( hLPDmem->mem_syn2, 0, M ); set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); set16_fx( hLPDmem->mem_syn3, 0, M ); - + hLPDmem->q_lpd_syn = Q15; + move16(); hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; move16(); hLPDmem->gc_threshold = 0; move32(); + hLPDmem->q_mem_syn = Q15; + move16(); #if 0 //set16_fx(hLPDmem->dispMem, 0, 8); #else diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 3cfe0ff6bf84df1b440a5a963109fa290d61863f..0284cacf345829d11cd77df1ce96025a1420efd6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -327,7 +327,6 @@ ivas_error ivas_core_enc( Word16 old_inp_16k_fx[L_INP]; Word16 old_inp_12k8_fx[L_INP_12k8]; Word16 Q_old_syn_12k8_16k; - Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; q_old_inp_12k8_fx = Q_factor_arr( old_inp_12k8[n], L_INP_12k8 ); q_old_inp_16k_fx = Q_factor_arr( old_inp_16k[n], L_INP ); @@ -335,8 +334,6 @@ ivas_error ivas_core_enc( floatToFixed_arr16( old_inp_12k8[n], old_inp_12k8_fx, q_old_inp_12k8_fx, L_INP_12k8 ); floatToFixed_arr16( old_inp_16k[n], old_inp_16k_fx, q_old_inp_16k_fx, L_INP ); - inp_fx[n] = &inp_buff[n][M + 1]; - floatToFixed_arr( &inp[n][-M - 1], &inp_fx[n][-M - 1], Q_new[n] - 1, L_FRAME16k + M + 1 ); #endif core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx, q_old_inp_12k8_fx, old_inp_16k_fx, q_old_inp_16k_fx, sts[0]->active_cnt, last_element_mode ); @@ -349,6 +346,11 @@ ivas_error ivas_core_enc( IF( st->core == ACELP_CORE ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 inp_buff[CPE_CHANNELS][L_FRAME16k + M + 1]; + inp_fx[n] = &inp_buff[n][M]; + floatToFixed_arr( &inp[n][-M], &inp_fx[n][-M], Q_new[n] - 1, L_FRAME16k + M ); +#endif /* ACELP core encoder */ IF( ( error = acelp_core_enc( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ) != IVAS_ERR_OK ) { @@ -366,31 +368,25 @@ ivas_error ivas_core_enc( Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 nSubframes; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) - { - nSubframes = 1; - } - ELSE - { - nSubframes = 2; - } - Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); - hTcxEnc->spectrum_e[0] = 31 - q_spectrum; - floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); - IF( hTcxEnc->tcxMode != TCX_20 ) - { - q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[1], st->hTcxEnc->L_frameTCX / nSubframes ); - hTcxEnc->spectrum_e[1] = 31 - q_spectrum; - floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); - } + // Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); + // hTcxEnc->spectrum_e[0] = 31 - q_spectrum; + // floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + // IF( hTcxEnc->tcxMode != TCX_20 ) + //{ + // q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[1], st->hTcxEnc->L_frameTCX / nSubframes ); + // hTcxEnc->spectrum_e[1] = 31 - q_spectrum; + // floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + // } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS floatToFixed_arr( old_inp_12k8[n], old_inp_12k8_fx, 0, L_INP_12k8 ); floatToFixed_arr( old_inp_16k[n], old_inp_16k_fx, 0, L_INP ); #endif + Word16 Q_spec_old, L_spec; + Q_spec_old = hTcxEnc->spectrum_long_e; + move16(); Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( -1, st->hTcxEnc->q_Txnq ) ); st->hTcxEnc->q_Txnq = -Q1; move16(); @@ -399,16 +395,36 @@ ivas_error ivas_core_enc( Scale_sig( st->hTcxEnc->old_out_fx, L_FRAME32k, -st->hTcxEnc->Q_old_out ); // scaling back to Q0 st->hTcxEnc->Q_old_out = 0; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int k = 0; k < nSubframes; k++ ) + + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { -#ifndef MSAN_FIX - fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], 720 ); -#else - fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], 31 - st->hTcxEnc->spectrum_e[k], st->hTcxEnc->L_frameTCX / nSubframes ); -#endif + L_spec = st->hTcxCfg->tcx_coded_lines; + move16(); + Word16 e_max = s_max( hTcxEnc->spectrum_e[0], Q_spec_old ); + e_max = sub( e_max, L_norm_arr( hTcxEnc->spectrum_long_fx, N_MAX ) ); + scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old, e_max ) ); + + hTcxEnc->spectrum_long_e = e_max; + move16(); } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + ELSE + { + Word16 e_max = s_max( Q_spec_old, s_max( hTcxEnc->spectrum_e[0], hTcxEnc->spectrum_e[1] ) ); + e_max = sub( e_max, L_norm_arr( hTcxEnc->spectrum_long_fx, N_MAX ) ); + L_spec = shr( st->hTcxCfg->tcx_coded_lines, 1 ); + scale_sig32( hTcxEnc->spectrum_fx[0], L_spec, sub( hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( hTcxEnc->spectrum_fx[1], L_spec, sub( hTcxEnc->spectrum_e[1], e_max ) ); + scale_sig32( hTcxEnc->spectrum_fx[0] + L_spec, N_TCX10_MAX - L_spec, sub( Q_spec_old, e_max ) ); + scale_sig32( hTcxEnc->spectrum_fx[1] + L_spec, sub( N_MAX - N_TCX10_MAX, L_spec ), sub( Q_spec_old, e_max ) ); + + hTcxEnc->spectrum_long_e = s_max( Q_spec_old, s_max( hTcxEnc->spectrum_e[0], hTcxEnc->spectrum_e[1] ) ); + move16(); + } + hTcxEnc->spectrum_e[0] = hTcxEnc->spectrum_long_e; + move16(); + hTcxEnc->spectrum_e[1] = hTcxEnc->spectrum_long_e; + move16(); } IF( EQ_16( st->core, HQ_CORE ) ) @@ -478,22 +494,85 @@ ivas_error ivas_core_enc( move16(); } #endif + Word16 Q_spec_old[2], L_spec; + Q_spec_old[0] = hCPE->hCoreCoder[0]->hTcxEnc->spectrum_long_e; + move16(); + Q_spec_old[1] = hCPE->hCoreCoder[1]->hTcxEnc->spectrum_long_e; + move16(); + ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id], hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Encoder_State *st1 = sts[i]; + Word16 nSubframes = NB_DIV; + move16(); + if ( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + } + + hMCT->q_mdst_spectrum_long_fx[cpe_id][i][0] = sub( Q31, mdst_spectrum_e[i][0] ); + move16(); + IF( EQ_16( nSubframes, NB_DIV ) ) + { + hMCT->q_mdst_spectrum_long_fx[cpe_id][i][1] = sub( Q31, mdst_spectrum_e[i][1] ); + move16(); + } + IF( EQ_16( nSubframes, NB_DIV ) ) + { + Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] ); + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); + hMCT->q_orig_spectrum_long_fx[cpe_id][i] = max_e; + move16(); + } + ELSE + { + hMCT->q_orig_spectrum_long_fx[cpe_id][i] = orig_spectrum_e[i][0]; + move16(); + } + } for ( i = 0; i < CPE_CHANNELS; i++ ) { Encoder_State *st1 = sts[i]; - Word16 nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - fixedToFloat_arrL( st1->hTcxEnc->spectrum_fx[0], st1->hTcxEnc->spectrum[0], 31 - st1->hTcxEnc->spectrum_e[0], st1->hTcxEnc->L_frameTCX / nSubframes ); - fixedToFloat_arrL( hMCT->p_orig_spectrum_long_fx[cpe_id][i], hMCT->p_orig_spectrum_long[cpe_id][i], 31 - orig_spectrum_e[i][0], N_TCX10_MAX ); - fixedToFloat_arrL( hMCT->p_mdst_spectrum_long_fx[cpe_id][i], hMCT->p_mdst_spectrum_long[cpe_id][i], 31 - mdst_spectrum_e[i][0], N_TCX10_MAX ); - if ( nSubframes == NB_DIV ) + IF( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + { + Word16 e_max = s_max( st1->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); + L_spec = st1->hTcxEnc->L_frameTCX; + move16(); + scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); + + st1->hTcxEnc->spectrum_long_e = e_max; + move16(); + } + ELSE { - fixedToFloat_arrL( st1->hTcxEnc->spectrum_fx[1], st1->hTcxEnc->spectrum[1], 31 - st1->hTcxEnc->spectrum_e[1], st1->hTcxEnc->L_frameTCX / nSubframes ); - fixedToFloat_arrL( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, hMCT->p_orig_spectrum_long[cpe_id][i] + N_TCX10_MAX, 31 - orig_spectrum_e[i][1], N_TCX10_MAX ); - fixedToFloat_arrL( hMCT->p_mdst_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, hMCT->p_mdst_spectrum_long[cpe_id][i] + N_TCX10_MAX, 31 - mdst_spectrum_e[i][1], N_TCX10_MAX ); + Word16 e_max = s_max( s_max( st1->hTcxEnc->spectrum_e[0], st1->hTcxEnc->spectrum_e[1] ), Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); + L_spec = shr( st1->hTcxEnc->L_frameTCX, 1 ); + scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[1], L_spec, sub( st1->hTcxEnc->spectrum_e[1], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); + + st1->hTcxEnc->spectrum_long_e = e_max; + move16(); } + + st1->hTcxEnc->spectrum_e[0] = st1->hTcxEnc->spectrum_long_e; + move16(); + st1->hTcxEnc->spectrum_e[1] = st1->hTcxEnc->spectrum_long_e; + move16(); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < CPE_CHANNELS; i++ ) + { + fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); } #endif @@ -521,17 +600,58 @@ ivas_error ivas_core_enc( } } #endif + + Word16 Q_spec_old[2], L_spec; + Q_spec_old[0] = hCPE->hCoreCoder[0]->hTcxEnc->spectrum_long_e; + move16(); + Q_spec_old[1] = hCPE->hCoreCoder[1]->hTcxEnc->spectrum_long_e; + move16(); + stereo_mdct_core_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 k; + for ( i = 0; i < CPE_CHANNELS; i++ ) { - fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); - Word16 length = sts[i]->hTcxEnc->L_frameTCX / ( ( sts[i]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); - FOR( k = 0; k <= ( ( sts[i]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + Encoder_State *st1 = sts[i]; + IF( EQ_16( st1->hTcxEnc->tcxMode, TCX_20 ) ) + { + L_spec = st1->hTcxEnc->L_frameTCX; + move16(); + Word16 e_max = s_max( st1->hTcxEnc->spectrum_e[0], Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_long_fx + L_spec, sub( N_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); + st1->hTcxEnc->spectrum_long_e = e_max; + move16(); + } + ELSE { - fixedToFloat_arrL32( sts[i]->hTcxEnc->spectrum_fx[k], sts[i]->hTcxEnc->spectrum[k], 31 - sts[i]->hTcxEnc->spectrum_e[k], length ); + L_spec = shr( st1->hTcxEnc->L_frameTCX, 1 ); + Word16 e_max = s_max( s_max( st1->hTcxEnc->spectrum_e[1], st1->hTcxEnc->spectrum_e[0] ), Q_spec_old[i] ); + e_max = sub( e_max, L_norm_arr( st1->hTcxEnc->spectrum_long_fx, N_MAX ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[0], L_spec, sub( st1->hTcxEnc->spectrum_e[0], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[0] + L_spec, sub( N_TCX10_MAX, L_spec ), sub( Q_spec_old[i], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[1], L_spec, sub( st1->hTcxEnc->spectrum_e[1], e_max ) ); + scale_sig32( st1->hTcxEnc->spectrum_fx[1] + L_spec, sub( ( N_MAX - N_TCX10_MAX ), L_spec ), sub( Q_spec_old[i], e_max ) ); + st1->hTcxEnc->spectrum_long_e = e_max; + move16(); } + + st1->hTcxEnc->spectrum_e[0] = st1->hTcxEnc->spectrum_long_e; + move16(); + st1->hTcxEnc->spectrum_e[1] = st1->hTcxEnc->spectrum_long_e; + move16(); + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Word16 k; + for ( i = 0; i < CPE_CHANNELS; i++ ) + { + fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP ); + // Word16 length = sts[i]->hTcxEnc->L_frameTCX / ( ( sts[i]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); + // FOR( k = 0; k <= ( ( sts[i]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + //{ + // fixedToFloat_arrL32( sts[i]->hTcxEnc->spectrum_fx[k], sts[i]->hTcxEnc->spectrum[k], 31 - sts[i]->hTcxEnc->spectrum_e[k], length ); + // } } #endif } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index ceecc30f906d193acf0f06d2e631dd9270209cf1..d19f9a06fa9cb30e85d118b2d227348f01777ab5 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -641,7 +641,6 @@ ivas_error pre_proc_ivas( st->mem_preemph16k_DFT = fixedToFloat_16( st->mem_preemph16k_DFT_fx, Q_old_inp_16k ); fixedToFloat_arr( old_inp_16k_fx, old_inp_16k, *Q_new - 1, L_INP ); - fixedToFloat_arr( st->old_wsp_fx, st->old_wsp, 15 - st->exp_old_wsp, L_WSP_MEM ); fixedToFloat_arr( st->old_inp_16k_fx, st->old_inp_16k, *Q_new - 1, 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_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 0cb19b371c774f18870b3869240010513ba6d765..8982be68d1c2f7a308898f279cdab665782285ea 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -86,20 +86,6 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len ) } return 0; } -static Word16 norm_arr( - Word16 *arr, - Word16 size /* Q0 */ -) -{ - Word16 q = 15; - move16(); - FOR( Word16 i = 0; i < size; i++ ) - IF( arr[i] != 0 ) - { - q = s_min( q, norm_s( arr[i] ) ); - } - return q; -} #endif #ifndef IVAS_FLOAT_FIXED @@ -963,7 +949,6 @@ ivas_error pre_proc_front_ivas_fx( float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ float Etot; /* total energy */ - float fr_bands[2 * NB_BANDS]; /* energy in frequency bands */ float lf_E[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ float tmpN[NB_BANDS]; /* Temporary noise update */ float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ @@ -1043,9 +1028,10 @@ ivas_error pre_proc_front_ivas_fx( Word16 corr_shiftR_fx; /* correlation shift */ Word16 corr_shift_fx; /* correlation shift */ Word32 ee_fx[2]; /* Spectral tilt */ - Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands */ - Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - Word32 hp_E_fx[2]; /* Energy in HF */ + Word32 fr_bands_fx[2 * NB_BANDS]; /* energy in frequency bands Q_new + QSCALE */ + Word16 fr_bands_fx_q; + Word32 lf_E_fx[2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word32 hp_E_fx[2]; /* Energy in HF */ Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; @@ -1088,7 +1074,13 @@ ivas_error pre_proc_front_ivas_fx( } #endif Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; - Word16 max_e; + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_to_be_looked_into = -1; + Word16 headroom = 0, preemp_len = 0, inp_max = 0; + Word16 *preemp_start_idx = NULL; + Word32 sig_out[960], max_32; +#endif /*------------------------------------------------------------------* * Initialization @@ -1254,15 +1246,10 @@ ivas_error pre_proc_front_ivas_fx( L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - // int x = L_INP_MEM - L_look; - inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ -#endif - new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ +#ifndef IVAS_FLOAT_FIXED + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8 -= L_FILT; @@ -1280,29 +1267,55 @@ ivas_error pre_proc_front_ivas_fx( { mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM - L_FILT ); } - mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + + st->rf_mode = st->Opt_RF_ON; + + last_core_orig = st->last_core; +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Float to fix block start + /* + !!!! Scaling whole old_inp_12k8 to -1. Needs to be check later !!! + */ + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); + floatToFixed_arr( st->old_inp_12k8, st->old_inp_12k8_fx, Q_to_be_looked_into, L_INP_MEM ); + + // Float to fix block end + + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ + + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) + { + new_inp_12k8 -= L_FILT; + } #endif - Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); - wsp_fx = old_wsp_fx + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + new_inp_12k8_fx = old_inp_12k8_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8_fx = new_inp_12k8_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - IF( NE_16( element_mode, IVAS_CPE_DFT ) ) + if ( NE_16( element_mode, IVAS_CPE_DFT ) ) { new_inp_12k8_fx -= L_FILT; } - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + if ( element_mode == IVAS_CPE_DFT ) { Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8 ); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) + else if ( element_mode == IVAS_CPE_TD ) { Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - lMemRecalc_12k8 - L_FILT ); } - ELSE + else { Copy( st->old_inp_12k8_fx, old_inp_12k8_fx, L_INP_MEM - L_FILT ); } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( st->old_wsp_fx, old_wsp, Q15 - st->exp_old_wsp, L_WSP_MEM ); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ +#endif Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ @@ -1311,6 +1324,11 @@ ivas_error pre_proc_front_ivas_fx( last_core_orig = st->last_core; move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); + fixedToFloat_arr( st->old_inp_12k8_fx, st->old_inp_12k8, Q_to_be_looked_into, L_INP_MEM ); +#endif +#endif /*--------------------------------------------------------------* * energy analysis @@ -1348,32 +1366,65 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ - // Word16 scale_factor = sub( getScaleFactor16( st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ) ), 1 ); - Word16 scale_factor = sub( norm_arr( st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ) ), 1 ); - Word16 q_input = s_min( add( -1, scale_factor ), sub( 16, old_inp_12k8_e ) ); - Copy_Scale_sig32_16( st->input32_fx - input_frame, st->input_fx - input_frame, (Word16) ( st->input_Fs / 25 ), add( 16 - 11, q_input ) ); /*scaling down from q11 to q_input*/ - st->q_inp = q_input; - move16(); - st->q_old_inp = q_input; - move16(); - Scale_sig( st->mem_decim_fx, 90, sub( q_input, 15 - mem_decim_e ) ); /*scaling from q(15-mem_decim_e) to q_input*/ - Scale_sig( old_inp_12k8_fx, 496, sub( q_input, sub( 15, old_inp_12k8_e ) ) ); /*scaling from q(15-old_inp_12k8_e) to q_input*/ +#ifndef IVAS_FLOAT_FIXED + if ( element_mode == IVAS_SCE ) + { + modify_Fs( signal_in, input_frame, input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + /* reconstruct past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_inp = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + + modify_Fs( signal_in - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8 - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim, 0 ); + } + + modify_Fs( signal_in - lMemRecalc, input_frame, input_Fs, new_inp_12k8 - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim, ( st->max_bwidth == NB ) ); + mvr2r( st->mem_decim, mem_decim_dummy, 2 * L_FILT_MAX ); + + if ( lMemRecalc > 0 ) + { + modify_Fs( signal_in + input_frame - lMemRecalc, lMemRecalc, input_Fs, new_inp_12k8 + L_FRAME - lMemRecalc_12k8, INT_FS_12k8, mem_decim_dummy, ( st->max_bwidth == NB ) ); + } + set_f( temp1F_icatdmResampBuf, 0, L_FILT_MAX ); + modify_Fs( temp1F_icatdmResampBuf, NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8 + L_FRAME, INT_FS_12k8, mem_decim_dummy, 0 ); + } + else /* DFT stereo */ + { + /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ + mvr2r( signal_in + input_frame - NS2SA( input_Fs, L_MEM_RECALC_NS ) - 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim, 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ); + } +#else +#endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Float to fix block start + /* + !!!! Scaling st->input_buff to -1. Needs to be check later. old_input_signal and input point to this common buffer !!! + */ + + // floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff + floatToFixed_arr( st->mem_decim, st->mem_decim_fx, Q_to_be_looked_into, 2 * L_FILT_MAX ); + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); +#endif test(); IF( EQ_16( element_mode, IVAS_SCE ) ) { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx, new_inp_12k8, q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -1385,41 +1436,41 @@ ivas_error pre_proc_front_ivas_fx( Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - add( lMemRecalc, length_inp ), length_inp, input_Fs, new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_12k8 - add( lMemRecalc_12k8, length_12k8 ), q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx - add( lMemRecalc_12k8, length_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_12k8 - lMemRecalc_12k8, q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ + IF( lMemRecalc > 0 ) { new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_12k8 + sub( L_FRAME, lMemRecalc_12k8 ), q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to q_input*/ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - fixedToFloat_arr( new_inp_12k8_fx + L_FRAME, new_inp_12k8 + L_FRAME, q_input, new_inp_out_size ); -#endif + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to Q_to_be_looked_into*/ } ELSE /* DFT stereo */ { /* update the FIR resampling filter memory, needed for switching to time-domain (FIR) resampling */ Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); } - old_inp_12k8_e = sub( 15, q_input ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Float to fix block start + /* + !!!! Scaling st->input_buff to -1. Needs to be check later. old_input_signal and input point to this common buffer !!! + */ + + // fixedToFloat_arr( st->input_buff_fx, st->input_buff, Q_to_be_looked_into, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + // input_fx and old_input_signal_fx already in Q(-1). All these point to input_buff + fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, Q_to_be_looked_into, 2 * L_FILT_MAX ); + fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); +#endif + old_inp_12k8_e = sub( 15, Q_to_be_looked_into ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#ifndef IVAS_FLOAT_FIXED /* save input resampled at 12.8kHz, non-preemhasised */ if ( element_mode == IVAS_CPE_DFT ) { @@ -1464,126 +1515,248 @@ ivas_error pre_proc_front_ivas_fx( st->exp_buf_speech_enc = s_max( tmp, st->exp_buf_speech_enc ); #endif } -#endif // DEBUG - -#ifndef MSAN_FIX /*To be enabled when updations related to new_inp_12k8_fx is enabled */ - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); + // floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, Q_to_be_looked_into, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, -1 - ( 15 - st->exp_buf_speech_enc ) ); + st->exp_buf_speech_enc = 16; +#endif + /* save input resampled at 12.8kHz, non-preemhasised */ + if ( element_mode == IVAS_CPE_DFT ) { Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8 ); - Scale_sig( st->buf_speech_enc + L_FRAME32k - STEREO_DFT_OVL_12k8, L_FRAME + STEREO_DFT_OVL_12k8, 1 ); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) { Copy( new_inp_12k8_fx - lMemRecalc_12k8, st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT ); - Scale_sig( st->buf_speech_enc + L_FRAME32k - lMemRecalc_12k8 - L_FILT, L_FRAME + lMemRecalc_12k8 + L_FILT, 1 ); } - ELSE + else { Copy( new_inp_12k8_fx, st->buf_speech_enc + L_FRAME32k, L_FRAME ); - Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); } -#endif // !MSAN_FIX + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_to_be_looked_into, L_INP_12k8 ); + // fixedToFloat_arr( st->buf_speech_enc, st->buf_speech_enc_flt, Q_to_be_looked_into, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); +#endif +#endif + /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ - max_e = old_inp_12k8_e; - move16(); - max_e = s_max( max_e, mem_preemph_e ); - max_e = s_max( max_e, mem_preemph_DFT_e ); - Scale_sig( old_inp_12k8_fx, 496, sub( old_inp_12k8_e, max_e ) ); - st->mem_preemph_DFT_fx = shr( st->mem_preemph_DFT_fx, sub( max_e, mem_preemph_DFT_e ) ); - st->mem_preemph_fx = shr( st->mem_preemph_fx, sub( max_e, mem_preemph_e ) ); - old_inp_12k8_e = mem_preemph_DFT_e = mem_preemph_e = max_e; - move16(); - move16(); - move16(); - move16(); - move16(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + +#ifndef IVAS_FLOAT_FIXED + if ( element_mode == IVAS_CPE_DFT ) { - Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ - inp_12k8_mem_stereo_sw_e = old_inp_12k8_e; - move16(); + mvr2r( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ - st->mem_preemph_fx = st->mem_preemph_DFT_fx; - move16(); - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; - move16(); + st->mem_preemph = st->mem_preemph_DFT; + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; - PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; - move16(); + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy ); + } + else if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_MDCT ) + { + if ( st->idchan == 0 ) + { + if ( hCPE->last_element_mode == IVAS_CPE_DFT ) + { + st->mem_preemph = st->mem_preemph_DFT; + mvr2r( st->inp_12k8_mem_stereo_sw, new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + preemph( new_inp_12k8 - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph ); + } + + st->mem_preemph_DFT = old_inp_12k8[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + if ( hCPE->last_element_mode == IVAS_CPE_DFT && st->idchan == 1 ) + { + int16_t length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + preemph( new_inp_12k8 - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph ); + } - PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + preemph( new_inp_12k8 - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy ); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + else /* IVAS_SCE or IVAS_CPE_MDCT */ + { + preemph( new_inp_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); + dummy = st->mem_preemph; + preemph( new_inp_12k8 + L_FRAME, PREEMPH_FAC, L_FILT, &dummy ); + } +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( old_inp_12k8, old_inp_12k8_fx, Q_to_be_looked_into, L_INP_12k8 ); + floatToFixed_arr( st->inp_12k8_mem_stereo_sw, st->inp_12k8_mem_stereo_sw_fx, Q_to_be_looked_into, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + floatToFixed_arr( &st->mem_preemph, &st->mem_preemph_fx, Q_to_be_looked_into, 1 ); + floatToFixed_arr( &st->mem_preemph_DFT, &st->mem_preemph_DFT_fx, Q_to_be_looked_into, 1 ); +#endif + + Word16 Q_new = 1; + + IF( Q_new ) { - IF( st->idchan == 0 ) + Q_new = 0; + move16(); + set32_fx( sig_out, 0, 960 ); + + headroom = 1; + + if ( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) { - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + headroom = add( headroom, 1 ); + } + + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + move16(); + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + move16(); + + // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + move16(); + + // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + preemp_start_idx = new_inp_12k8_fx - STEREO_DFT_OVL_12k8; + move16(); + preemp_len = STEREO_DFT_OVL_12k8 + L_FRAME; + move16(); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( st->idchan == 0 ) { - st->mem_preemph_fx = st->mem_preemph_DFT_fx; - move16(); - IF( GT_16( inp_12k8_mem_stereo_sw_e, old_inp_12k8_e ) ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - Scale_sig( new_inp_12k8_fx - ( L_INP_MEM - L_FILT ), L_FRAME + L_INP_MEM, old_inp_12k8_e - inp_12k8_mem_stereo_sw_e ); - old_inp_12k8_e = inp_12k8_mem_stereo_sw_e; - st->mem_preemph_fx = shr( st->mem_preemph_fx, inp_12k8_mem_stereo_sw_e - mem_preemph_e ); - mem_preemph_e = inp_12k8_mem_stereo_sw_e; + st->mem_preemph_fx = st->mem_preemph_DFT_fx; move16(); + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); move16(); + preemp_len = STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT; move16(); } - ELSE - { - Scale_sig( st->inp_12k8_mem_stereo_sw_fx, 4, inp_12k8_mem_stereo_sw_e - old_inp_12k8_e ); - inp_12k8_mem_stereo_sw_e = old_inp_12k8_e; - move16(); - } - Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + } + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + test(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + { + Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + move16(); + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8; + preemp_len = length_12k8; + move16(); } - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ - mem_preemph_DFT_e = old_inp_12k8_e; + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; move16(); - } + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); - /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ - test(); - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) + IF( preemp_start_idx && preemp_len ) + { + preemp_len = add( preemp_len, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); + move16(); + } + ELSE + { + preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8; + preemp_len = add( L_FRAME + L_FILT, lMemRecalc_12k8 ); + move16(); + } + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ { - Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + // PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + move16(); + // PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx + L_FRAME, sig_out, PREEMPH_FAC, L_FILT, &dummy_fx ); + preemp_start_idx = new_inp_12k8_fx; + preemp_len = L_FRAME + L_FILT; move16(); - PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); } - PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; + maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); + inp_max = s_max( extract_h( max_32 ), 1 ); + + Word16 shift = sub( norm_s( inp_max ), headroom ); + Word16 Q_min; + shift = s_max( shift, 0 ); + shift = s_min( shift, Q_MAX ); + minimum_fx( st->Q_max, L_Q_MEM, &Q_min ); + Q_new = s_min( shift, Q_min ); move16(); - PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); - } - ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ - { - PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; + IF( inp_max == 0 ) + { + IF( NE_16( st->last_coder_type, UNVOICED ) ) + { + Q_new = s_min( Q_new, 1 ); + move16(); + } + } + + FOR( i = L_Q_MEM - 1; i > 0; i-- ) + { + st->Q_max[i] = st->Q_max[i - 1]; + move16(); + } + st->Q_max[i] = shift; move16(); - PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); - } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - /*fixed to float from modify_fs block*/ - fixedToFloat_arr( st->mem_decim_fx, st->mem_decim, q_input, 90 ); // To be removed + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, Q_new ); - /*fixed to float conversions for preemph_fx block*/ - st->mem_preemph = me2f_16( st->mem_preemph_fx, mem_preemph_e ); - st->mem_preemph_DFT = me2f_16( st->mem_preemph_DFT_fx, mem_preemph_DFT_e ); - fixedToFloat_arr( st->inp_12k8_mem_stereo_sw_fx, st->inp_12k8_mem_stereo_sw, 15 - inp_12k8_mem_stereo_sw_e, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, 15 - old_inp_12k8_e, L_INP_MEM + L_FRAME ); // To be removed + /* + Q_exp = sub(*Q_new, st->Q_old); + st->prev_Q_old = st->Q_old; + move16(); + st->Q_old = *Q_new; + move16(); + + // Scaling of memories + + Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, Q_new, old_inp_12k8, &( st->mem_wsp_fx ), hNoiseEst->enrO_fx, hNoiseEst->bckr_fx, + hNoiseEst->ave_enr_fx, hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx ); + */ + + Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), Q_new ); + + Q_new = add( Q_new, Q_to_be_looked_into ); + } + else + { + // See if needed + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( old_inp_12k8_fx, old_inp_12k8, Q_new, L_INP_12k8 ); + fixedToFloat_arr( st->inp_12k8_mem_stereo_sw_fx, st->inp_12k8_mem_stereo_sw, Q_to_be_looked_into, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + st->mem_preemph = fixedToFloat_16( st->mem_preemph_fx, Q_to_be_looked_into ); + st->mem_preemph_DFT = fixedToFloat_16( st->mem_preemph_DFT_fx, Q_to_be_looked_into ); cldfbScale.hb_scale = cldfbScale.lb_scale; #endif +#endif #if 0 /*------------------------------------------------------------------* @@ -1614,28 +1787,18 @@ ivas_error pre_proc_front_ivas_fx( { lgBin_E_fx = &st->lgBin_E_fx[0]; } - Word16 Q_new; - Word16 Scale_fac[2]; - set16_fx( Scale_fac, 0, 2 ); - Q_new = sub( Q15, old_inp_12k8_e ); - Word16 tmp16, scale = 0; - move16(); - if ( hCPE != NULL && hCPE->hStereoDft != NULL ) - { - tmp16 = BASOP_Util_Divide3216_Scale( input_Fs, hCPE->hStereoDft->NFFT, &scale ); - tmp16 = shr( tmp16, negate( add( 1, scale ) ) ); - Word16 gb = find_guarded_bits_fx( tmp16 ); - Q_new = sub( Q_new, gb ); - } + + Word16 Scale_fac[2] = { 0 }; #endif - Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E_old ) ); - st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 - 1 ); + Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); + st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); move16(); - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 - 1 ), st->q_Bin_E ) ); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); move16(); Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); + fr_bands_fx_q = add( Q_new, QSCALE ); IF( lgBin_E_fx != NULL ) { @@ -1643,7 +1806,6 @@ ivas_error pre_proc_front_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( fr_bands_fx, fr_bands, Q_new + QSCALE, 40 ); fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE, 40 ); fixedToFloat_arrL( lf_E_fx, lf_E, Q_new + QSCALE - 2, 148 ); fixedToFloat_arrL( PS_fx, PS, Q_new + QSCALE - 2, 128 ); @@ -1669,19 +1831,18 @@ ivas_error pre_proc_front_ivas_fx( Etot_fx = (Word16) ( Etot * ( 1 << 8 ) ); /*float to fix conversions for wb_vad_ivas_fx*/ - Q_new = Q_factor_arr( fr_bands, 40 ) + 3; - floatToFixed_arrL( fr_bands, fr_bands_fx, Q_new + QSCALE, 40 ); - floatToFixed_arrL( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, Q_new + QSCALE, 20 ); - floatToFixed_arrL( st->hNoiseEst->enrO, st->hNoiseEst->enrO_fx, Q_new + QSCALE, 20 ); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; - - Word16 Q_bands0 = 0, Q_bands1 = 0; - IF( lr_vad_enabled && st->idchan == 0 ) - { - floatToFixed_arrL( hCPE->hFrontVad[0]->hNoiseEst->bckr, hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, fr_bands_LR_fx_q + QSCALE, NB_BANDS ); - floatToFixed_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr, hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, fr_bands_LR_fx_q + QSCALE, NB_BANDS ); - } #endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED + Word16 Q_bands0 = 0, Q_bands1 = 0; + move16(); + move16(); + + Scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( Q_new + QSCALE, st->hNoiseEst->q_bckr ) ); + st->hNoiseEst->q_bckr = add( Q_new, QSCALE ); + move16(); + Scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( Q_new + QSCALE, st->hNoiseEst->q_enrO ) ); + st->hNoiseEst->q_enrO = add( Q_new, QSCALE ); + move16(); IF( hStereoClassif != NULL ) { @@ -1733,7 +1894,6 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { - *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, vad_hover_flag, NULL, NULL ); move16(); } @@ -1773,11 +1933,11 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( EQ_16( st->idchan, 0 ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { - Scale_sig( st->input_fx, 480, negate( q_input ) ); /*scaling from q_input to q0*/ + Scale_sig( st->input_fx, 480, negate( Q_to_be_looked_into ) ); /*scaling from Q_to_be_looked_into to q0*/ bw_detect_fx( st, st->input_fx, NULL, enerBuffer_fx, sf_energySum, ivas_format, 0 ); - Scale_sig( st->input_fx, 480, q_input ); /*scaling back to q_input*/ + Scale_sig( st->input_fx, 480, Q_to_be_looked_into ); /*scaling back to Q_to_be_looked_into*/ } @@ -1806,15 +1966,24 @@ ivas_error pre_proc_front_ivas_fx( Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); + st->hNoiseEst->q_bckr = add( Q_new, QSCALE ); + move16(); test(); IF( lr_vad_enabled && st->idchan == 0 ) { + Scale_sig32( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[0]->hNoiseEst->q_bckr ) ); + Scale_sig32( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[1]->hNoiseEst->q_bckr ) ); + Word32 Le_min_scaled0, Le_min_scaled1; Le_min_scaled0 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands0, QSCALE ) ) ), 1 ), 1 ); - Le_min_scaled1 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands1, QSCALE ) ) ), 1 ), 1 ); noise_est_down_fx( fr_bands_LR_fx[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, tmpN_LR_fx[0], tmpE_LR_fx[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, Etot_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, Q_bands0, Le_min_scaled0 ); + hCPE->hFrontVad[0]->hNoiseEst->q_bckr = add( Q_bands0, QSCALE ); + move16(); + Le_min_scaled1 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands1, QSCALE ) ) ), 1 ), 1 ); noise_est_down_fx( fr_bands_LR_fx[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, tmpN_LR_fx[1], tmpE_LR_fx[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, Etot_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, Q_bands1, Le_min_scaled1 ); + hCPE->hFrontVad[1]->hNoiseEst->q_bckr = add( Q_bands1, QSCALE ); + move16(); corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx ); corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx ); @@ -1823,15 +1992,12 @@ ivas_error pre_proc_front_ivas_fx( st->flag_noisy_speech_snr = (Word16) st->flag_noisy_speech_snr_fx; /*fixed to float for noise_est_down*/ - fixedToFloat_arrL( st->hNoiseEst->bckr_fx, st->hNoiseEst->bckr, Q_new + QSCALE, NB_BANDS ); fixedToFloat_arrL( tmpN_fx, tmpN, Q_new + QSCALE, 20 ); fixedToFloat_arrL( tmpE_fx, tmpE, Q_new + QSCALE, 20 ); /*fixed to float for noise_est_down_fx concerned with fr_bands_LR*/ IF( lr_vad_enabled && st->idchan == 0 ) { - fixedToFloat_arrL( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, hCPE->hFrontVad[0]->hNoiseEst->bckr, Q_bands0 + QSCALE, NB_BANDS ); - fixedToFloat_arrL( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, hCPE->hFrontVad[1]->hNoiseEst->bckr, Q_bands1 + QSCALE, NB_BANDS ); fixedToFloat_arrL( tmpN_LR_fx[0], tmpN_LR[0], Q_bands0 + QSCALE, 20 ); fixedToFloat_arrL( tmpE_LR_fx[0], tmpE_LR[0], Q_bands0 + QSCALE, 20 ); fixedToFloat_arrL( tmpN_LR_fx[1], tmpN_LR[1], Q_bands1 + QSCALE, 20 ); @@ -2179,7 +2345,6 @@ ivas_error pre_proc_front_ivas_fx( Word16 exp_wsp = 0, Q_wsp = 0; move16(); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q_factor_arr( st->old_wsp, L_WSP_MEM ), L_WSP_MEM ); Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; f2me_buf_16( wsp, wsp_fx, &exp_wsp, L_WSP - L_WSP_MEM ); @@ -2209,12 +2374,10 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_fr_bands = Q30; q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN, NB_BANDS ) ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( fr_bands, 2 * NB_BANDS ) - 4 /* needs 4 gaurd bits for summation */ ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( st->hNoiseEst->bckr, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( st->hNoiseEst->fr_bands1, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( st->hNoiseEst->fr_bands2, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( st->hNoiseEst->ave_enr, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( st->hNoiseEst->ave_enr2, NB_BANDS ) ); + q_fr_bands = min( q_fr_bands, fr_bands_fx_q - 4 /* needs 4 gaurd bits for summation */ ); + q_fr_bands = min( q_fr_bands, st->hNoiseEst->q_bckr ); + q_fr_bands = min( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ); + q_fr_bands = min( q_fr_bands, st->hNoiseEst->ave_enr_q ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( lf_E, 2 * VOIC_BINS ) + 2 ); if ( lr_vad_enabled && st->idchan == 0 ) @@ -2225,25 +2388,13 @@ ivas_error pre_proc_front_ivas_fx( q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN_LR[j], NB_BANDS ) ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE_LR[j], NB_BANDS ) ); q_fr_bands = min( q_fr_bands, fr_bands_LR_fx_q ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( hCPE->hFrontVad[j]->hNoiseEst->bckr, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( hCPE->hFrontVad[j]->hNoiseEst->ave_enr, NB_BANDS ) ); - q_fr_bands = min( q_fr_bands, Q_factor_arrL( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2, NB_BANDS ) ); + q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ); + q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ); + q_fr_bands = min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ); } for ( int j = 0; j < 2; j++ ) { - floatToFixed_arr32( hCPE->hFrontVad[j]->hNoiseEst->bckr, hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2, hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, q_fr_bands, NB_BANDS ); - for ( int k = 0; k < NB_BANDS; k++ ) - { - hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] = max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] ); - hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] = max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] ); - } floatToFixed_arr32( tmpN_LR[j], tmpN_LR_fx[j], q_fr_bands, NB_BANDS ); floatToFixed_arr32( tmpE_LR[j], tmpE_LR_fx[j], q_fr_bands, NB_BANDS ); } @@ -2251,24 +2402,14 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr32( tmpN, tmpN_fx, q_fr_bands, NB_BANDS ); floatToFixed_arr32( tmpE, tmpE_fx, q_fr_bands, NB_BANDS ); floatToFixed_arr32( lf_E, lf_E_fx, q_fr_bands - 2, 2 * VOIC_BINS ); - floatToFixed_arr32( st->hNoiseEst->bckr, st->hNoiseEst->bckr_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( st->hNoiseEst->fr_bands1, st->hNoiseEst->fr_bands1_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( st->hNoiseEst->fr_bands2, st->hNoiseEst->fr_bands2_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( st->hNoiseEst->ave_enr, st->hNoiseEst->ave_enr_fx, q_fr_bands, NB_BANDS ); - floatToFixed_arr32( st->hNoiseEst->ave_enr2, st->hNoiseEst->ave_enr2_fx, q_fr_bands, NB_BANDS ); - - for ( int k = 0; k < NB_BANDS; k++ ) - { - st->hNoiseEst->fr_bands1_fx[k] = max( 1, st->hNoiseEst->fr_bands1_fx[k] ); - st->hNoiseEst->fr_bands2_fx[k] = max( 1, st->hNoiseEst->fr_bands2_fx[k] ); - } - - floatToFixed_arr32( fr_bands, fr_bands_fx, q_fr_bands, 2 * NB_BANDS ); q_inp_12k8 = Q_factor_arr( old_inp_12k8, L_INP_12k8 ); // inp_12k8_fx floatToFixed_arr16( old_inp_12k8, old_inp_12k8_fx, q_inp_12k8, L_INP_12k8 ); #endif // IVAS_FLOAT_FIXED_CONVERSIONS + scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( q_fr_bands, fr_bands_fx_q ) ); + fr_bands_fx_q = q_fr_bands; + move16(); Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Detection of very short stable pitch period */ @@ -2308,12 +2449,85 @@ ivas_error pre_proc_front_ivas_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ + scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->q_bckr ) ); + st->hNoiseEst->q_bckr = q_fr_bands; + move16(); + scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) ); + st->hNoiseEst->fr_bands_fx_q = q_fr_bands; + move16(); + scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) ); + scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) ); + st->hNoiseEst->ave_enr_q = q_fr_bands; + move16(); + + FOR( Word16 k = 0; k < NB_BANDS; k++ ) + { + fr_bands_fx[k] = L_max( 1, fr_bands_fx[k] ); + move32(); + /*st->hNoiseEst->fr_bands1_fx[k] = L_max(1, st->hNoiseEst->fr_bands1_fx[k]); + move32(); + st->hNoiseEst->fr_bands2_fx[k] = L_max(1, st->hNoiseEst->fr_bands2_fx[k]); + move32();*/ + } + noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div, &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame ); + /*Scaling to avoid 0 values*/ + Word16 shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) ); + scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, shift ); + scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, shift ); + st->hNoiseEst->fr_bands_fx_q = add( st->hNoiseEst->fr_bands_fx_q, shift ); + move16(); + shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ); + scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, shift ); + scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, shift ); + st->hNoiseEst->ave_enr_q = add( st->hNoiseEst->ave_enr_q, shift ); + move16(); + shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS ); + scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, shift ); + st->hNoiseEst->q_bckr = add( st->hNoiseEst->q_bckr, shift ); + move16(); + shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS ); + scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift ); + st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift ); + move16(); + test(); IF( lr_vad_enabled && st->idchan == 0 ) { + FOR( Word16 j = 0; j < 2; j++ ) + { + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ) ); + hCPE->hFrontVad[j]->hNoiseEst->q_bckr = q_fr_bands; + move16(); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) ); + hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = q_fr_bands; + move16(); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) ); + hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_fr_bands; + move16(); + shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, shift ); + hCPE->hFrontVad[j]->hNoiseEst->q_bckr = add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift ); + move16(); + shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift ); + hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift ); + move16(); + + FOR( Word16 k = 0; k < NB_BANDS; k++ ) + { + hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] ); + move32(); + hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] ); + move32(); + } + } + /* Run noise_est for Left and Right channel */ *loc_harmLR_fx = *loc_harm; noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], epsP_h, epsP_l, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, tmpE_LR_fx[0], fr_bands_LR_fx[0], &cor_map_sum_LR_fx[0], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR, @@ -2322,6 +2536,20 @@ ivas_error pre_proc_front_ivas_fx( /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */ noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[1], epsP_h, epsP_l, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, tmpE_LR_fx[1], fr_bands_LR_fx[1], &cor_map_sum_LR_fx[1], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR, &non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame ); + + + /*Scaling to avoid 0 values*/ + FOR( Word16 j = 0; j < 2; j++ ) + { + shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, shift ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, shift ); + hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift ); + shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, shift ); + scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, shift ); + hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift ); + } } /*------------------------------------------------------------------* @@ -2345,23 +2573,6 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - - if ( lr_vad_enabled && st->idchan == 0 ) - { - for ( int j = 0; j < 2; j++ ) - { - fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, hCPE->hFrontVad[j]->hNoiseEst->bckr, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, hCPE->hFrontVad[j]->hNoiseEst->ave_enr, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, hCPE->hFrontVad[j]->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); - } - } - fixedToFloat_arrL32( st->hNoiseEst->bckr_fx, st->hNoiseEst->bckr, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( st->hNoiseEst->fr_bands1_fx, st->hNoiseEst->fr_bands1, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( st->hNoiseEst->fr_bands2_fx, st->hNoiseEst->fr_bands2, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( st->hNoiseEst->ave_enr_fx, st->hNoiseEst->ave_enr, q_fr_bands, NB_BANDS ); - fixedToFloat_arrL32( st->hNoiseEst->ave_enr2_fx, st->hNoiseEst->ave_enr2, q_fr_bands, NB_BANDS ); #endif /*-----------------------------------------------------------------* @@ -2431,7 +2642,9 @@ ivas_error pre_proc_front_ivas_fx( ivas_long_enr_fx( st, Etot_fx, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL ); - mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS ); + Copy32( fr_bands_fx + NB_BANDS, st->hNoiseEst->enrO_fx, NB_BANDS ); + st->hNoiseEst->q_enrO = fr_bands_fx_q; + move16(); test(); IF( lr_vad_enabled && st->idchan == 0 ) @@ -2444,10 +2657,6 @@ ivas_error pre_proc_front_ivas_fx( Copy32( fr_bands_LR_fx[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO_fx, NB_BANDS ); hCPE->hFrontVad[1]->hNoiseEst->q_enrO = fr_bands_LR_fx_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( hCPE->hFrontVad[0]->hNoiseEst->enrO_fx, hCPE->hFrontVad[0]->hNoiseEst->enrO, hCPE->hFrontVad[0]->hNoiseEst->q_enrO, 20 ); - fixedToFloat_arrL32( hCPE->hFrontVad[1]->hNoiseEst->enrO_fx, hCPE->hFrontVad[1]->hNoiseEst->enrO, hCPE->hFrontVad[1]->hNoiseEst->q_enrO, 20 ); -#endif } /*----------------------------------------------------------------* @@ -2509,8 +2718,15 @@ ivas_error pre_proc_front_ivas_fx( Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX]; Word16 wsp_fx_temp[L_WSP]; Word16 *wsp_fx_l; - floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); + // floatToFixed_arrL( st->hTcxEnc->spectrum_long, st->hTcxEnc->spectrum_long_fx, Q15, N_MAX ); #endif + Scale_sig32( st->hTcxEnc->spectrum_long_fx, N_MAX, sub( st->hTcxEnc->spectrum_long_e, 16 ) ); + st->hTcxEnc->spectrum_long_e = 16; + move16(); + st->hTcxEnc->spectrum_e[0] = 16; + move16(); + st->hTcxEnc->spectrum_e[1] = 16; + move16(); IF( flag_16k_smc ) { #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index ea41ff2511d80f21e0480972e64bb481aa36082e..43f7f994da57cd78c6e6145c73656f186bf8637f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -254,21 +254,27 @@ ivas_error ivas_cpe_enc_fx( Q_buffer[n] = 15; move16(); } - if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) +#endif + test(); + IF( hCPE->hFrontVad[0] != NULL && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { Word16 Qband = -1; move16(); - Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); + Word16 Q_new_old = add( add( sub( Q_inp, Qband ), Q_add ), QSCALE ); - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Q_buffer[n] = hCPE->hFrontVad[n]->q_buffer_12k8; - floatToFixed_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr, hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, Q_new_old + QSCALE, 20 ); - floatToFixed_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO, hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, Q_new_old + QSCALE, 20 ); + move16(); + Scale_sig32( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, 20, sub( Q_new_old, hCPE->hFrontVad[n]->hNoiseEst->q_bckr ) ); + hCPE->hFrontVad[n]->hNoiseEst->q_bckr = Q_new_old; + move16(); + Scale_sig32( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, 20, sub( Q_new_old, hCPE->hFrontVad[n]->hNoiseEst->q_enrO ) ); + hCPE->hFrontVad[n]->hNoiseEst->q_enrO = Q_new_old; + move16(); } } -#endif + IF( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, Etot_LR_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { @@ -278,23 +284,10 @@ ivas_error ivas_cpe_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) { - Word16 Qband = -1; - move16(); - Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); for ( n = 0; n < CPE_CHANNELS; n++ ) { // Scale_sig( hCPE->hFrontVad[n]->buffer_12k8_fx + 384, 3 * L_FRAME / 2 - 384, sub( Q_buffer[n], hCPE->hFrontVad[n]->q_buffer_12k8 ) ); hCPE->hFrontVad[n]->q_buffer_12k8 = Q_buffer[n]; - - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->enrO_fx, hCPE->hFrontVad[n]->hNoiseEst->enrO, Q_new_old + QSCALE, 20 ); - if ( front_create_flag ) - { - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->fr_bands1_fx, hCPE->hFrontVad[n]->hNoiseEst->fr_bands1, Q17, NB_BANDS ); - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->fr_bands2_fx, hCPE->hFrontVad[n]->hNoiseEst->fr_bands2, Q17, NB_BANDS ); - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->ave_enr_fx, hCPE->hFrontVad[n]->hNoiseEst->ave_enr, Q8, NB_BANDS ); - fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->ave_enr2_fx, hCPE->hFrontVad[n]->hNoiseEst->ave_enr2, Q8, NB_BANDS ); - } } } #endif diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 2a4ec05e1e58278865c9a5ec0afe83ed14497c9e..71e394074df81ae3ac35235dddfbf4ade8c44396 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -825,8 +825,6 @@ ivas_error front_vad_spar_fx( IF( tmp != 0 ) { Scale_sig( st->input_fx, input_frame, s ); - st->q_inp = add( st->q_inp, s ); - move16(); } Q_inp = s; move16(); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 136ab1071187b914b228cd16865e4dd090f3699d..aeec8f5682bbccc524cd0a1fef6ea2bd334e7056 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -2112,6 +2112,159 @@ void destroy_core_enc_fx( return; } +void destroy_evs_core_enc_fx( + ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ +) +{ + Word16 i; + + destroy_encoder_fx( hCoreCoder ); + + IF( hCoreCoder->hSignalBuf != NULL ) + { + free( hCoreCoder->hSignalBuf ); + hCoreCoder->hSignalBuf = NULL; + } + + IF( hCoreCoder->hBstr != NULL ) + { + /* reset buffer of indices */ + FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) + { + hCoreCoder->hBstr->ind_list[i].nb_bits = -1; + move16(); + } + free( hCoreCoder->hBstr ); + hCoreCoder->hBstr = NULL; + } + + IF( hCoreCoder->hLPDmem != NULL ) + { + free( hCoreCoder->hLPDmem ); + hCoreCoder->hLPDmem = NULL; + } + + IF( hCoreCoder->hTranDet != NULL ) + { + free( hCoreCoder->hTranDet ); + hCoreCoder->hTranDet = NULL; + } + + IF( hCoreCoder->hNoiseEst != NULL ) + { + free( hCoreCoder->hNoiseEst ); + hCoreCoder->hNoiseEst = NULL; + } + + IF( hCoreCoder->hVAD != NULL ) + { + free( hCoreCoder->hVAD ); + hCoreCoder->hVAD = NULL; + } + + IF( hCoreCoder->hVAD_CLDFB != NULL ) + { + /* This is not required as we are not allocating memory dynamically */ + // free( hCoreCoder->hVAD_CLDFB ); + hCoreCoder->hVAD_CLDFB = NULL; + } + + IF( hCoreCoder->hTdCngEnc != NULL ) + { + free( hCoreCoder->hTdCngEnc ); + hCoreCoder->hTdCngEnc = NULL; + } + + IF( hCoreCoder->hDtxEnc != NULL ) + { + free( hCoreCoder->hDtxEnc ); + hCoreCoder->hDtxEnc = NULL; + } + + IF( hCoreCoder->hSpMusClas != NULL ) + { + free( hCoreCoder->hSpMusClas ); + hCoreCoder->hSpMusClas = NULL; + } + + IF( hCoreCoder->hGSCEnc != NULL ) + { + free( hCoreCoder->hGSCEnc ); + hCoreCoder->hGSCEnc = NULL; + } + + IF( hCoreCoder->hSC_VBR != NULL ) + { + free( hCoreCoder->hSC_VBR ); + hCoreCoder->hSC_VBR = NULL; + } + + IF( hCoreCoder->hAmrwb_IO != NULL ) + { + free( hCoreCoder->hAmrwb_IO ); + hCoreCoder->hAmrwb_IO = NULL; + } + + IF( hCoreCoder->hBWE_TD != NULL ) + { + free( hCoreCoder->hBWE_TD ); + hCoreCoder->hBWE_TD = NULL; + } + + IF( hCoreCoder->hBWE_FD != NULL ) + { + free( hCoreCoder->hBWE_FD ); + hCoreCoder->hBWE_FD = NULL; + } + + IF( hCoreCoder->hRF != NULL ) + { + free( hCoreCoder->hRF ); + hCoreCoder->hRF = NULL; + } + + IF( hCoreCoder->hTECEnc != NULL ) + { + free( hCoreCoder->hTECEnc ); + hCoreCoder->hTECEnc = NULL; + } + + IF( hCoreCoder->hTcxEnc != NULL ) + { + free( hCoreCoder->hTcxEnc ); + hCoreCoder->hTcxEnc = NULL; + } + + IF( hCoreCoder->hTcxCfg != NULL ) + { + free( hCoreCoder->hTcxCfg ); + hCoreCoder->hTcxCfg = NULL; + } + + IF( hCoreCoder->hIGFEnc != NULL ) + { + free( hCoreCoder->hIGFEnc ); + hCoreCoder->hIGFEnc = NULL; + } + + IF( hCoreCoder->hPlcExt != NULL ) + { + free( hCoreCoder->hPlcExt ); + hCoreCoder->hPlcExt = NULL; + } + + IF( hCoreCoder->hHQ_core != NULL ) + { + free( hCoreCoder->hHQ_core ); + hCoreCoder->hHQ_core = NULL; + } + + free( hCoreCoder ); + + return; +} + + /*------------------------------------------------------------------------- * ivas_destroy_enc() * diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index a5b543d854f1a1c952f3632c1edd3bd8b83c9f7c..a2e290d49c4bf75a04f865872f125efb7d079150 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -842,7 +842,7 @@ void ivas_mct_core_enc_fx( i = add( i, 1 ); } } - q_origSpec = hMCT->q_orig_spectrum_long_fx; + q_origSpec = hMCT->q_orig_spectrum_long_com; move16(); hBstr = sts[0]->hBstr; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 0ce7e11aef6b188b875193fb0ba2080407669533..e9c94b0326540762bb875a10a5b78923821b6ba2 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -429,16 +429,14 @@ ivas_error ivas_mct_enc_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { hCPE = st_ivas->hCPE[cpe_id]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMCT->p_mdst_spectrum_long[cpe_id][n] = mdst_spectrum_long[cpe_id][n]; - hMCT->p_orig_spectrum_long[cpe_id][n] = orig_spectrum_long[cpe_id][n]; #ifdef MSAN_FIX set_zero( mdst_spectrum_long[cpe_id][n], L_FRAME48k ); set_zero( orig_spectrum_long[cpe_id][n], L_FRAME48k ); -#endif #endif set32_fx( orig_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); set32_fx( mdst_spectrum_long_fx[cpe_id][n], 0, L_FRAME48k ); + set16_fx( hMCT->q_mdst_spectrum_long_fx[cpe_id][n], Q31, CPE_CHANNELS ); + set16_fx( hMCT->q_orig_spectrum_long_fx[cpe_id], Q31, CPE_CHANNELS ); hMCT->p_mdst_spectrum_long_fx[cpe_id][n] = mdst_spectrum_long_fx[cpe_id][n]; hMCT->p_orig_spectrum_long_fx[cpe_id][n] = orig_spectrum_long_fx[cpe_id][n]; @@ -508,6 +506,9 @@ ivas_error ivas_mct_enc_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // Float to Fixed, to be removed Word16 q_spec = Q31; Word16 q_origSpec = Q31; + Word16 q_com = Q31, q_com_spec = Q31; + move16(); + move16(); Word16 length, ch, nCPE; nCPE = ( hMCT->nchan_out_woLFE % 2 ) == 0 ? ( hMCT->nchan_out_woLFE / 2 ) : ( hMCT->nchan_out_woLFE / 2 ) + 1; @@ -526,22 +527,40 @@ ivas_error ivas_mct_enc_fx( } for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) { - if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) - { - q_spec = s_min( q_spec, Q_factor_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[k], length ) - 1 ); - } - if ( hMCT->p_mdst_spectrum_long[cpe_id][ch] ) + IF( hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] ) { - q_spec = s_min( q_spec, Q_factor_arrL( &hMCT->p_mdst_spectrum_long[cpe_id][ch][k * N_TCX10_MAX], length ) - 1 ); + q_spec = s_min( q_spec, hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] ); + q_com_spec = s_min( q_com_spec, L_norm_arr( &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], length ) ); } } - if ( hMCT->p_orig_spectrum_long[cpe_id][ch] ) + IF( hMCT->p_orig_spectrum_long_fx[cpe_id][ch] ) { - q_origSpec = s_min( q_origSpec, Q_factor_arrL( hMCT->p_orig_spectrum_long[cpe_id][ch], L_FRAME48k ) - 1 ); + q_origSpec = s_min( q_origSpec, hMCT->q_orig_spectrum_long_fx[cpe_id][ch] ); + q_com = s_min( q_com, L_norm_arr( hMCT->p_orig_spectrum_long_fx[cpe_id][ch], L_FRAME48k ) ); } } } - hMCT->q_orig_spectrum_long_fx = q_origSpec; + q_spec = sub( add( q_spec, q_com_spec ), 1 ); + q_origSpec = sub( add( q_origSpec, q_com ), 1 ); + + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( EQ_32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + CONTINUE; + } + IF( hMCT->p_orig_spectrum_long_fx[cpe_id][ch] ) + { + Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][ch], L_FRAME48k, sub( q_origSpec, hMCT->q_orig_spectrum_long_fx[cpe_id][ch] ) ); + hMCT->q_orig_spectrum_long_fx[cpe_id][ch] = q_origSpec; + move16(); + } + } + } + hMCT->q_orig_spectrum_long_com = q_origSpec; + move16(); for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { for ( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -553,21 +572,19 @@ ivas_error ivas_mct_enc_fx( } for ( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) { - if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) + /*if ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[0] ) { floatToFixed_arrL32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum[k], st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[k], q_spec, length ); st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] = sub( Q31, q_spec ); st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[1] = sub( Q31, q_spec ); - } - if ( hMCT->p_mdst_spectrum_long[cpe_id][ch] ) + }*/ + IF( hMCT->p_mdst_spectrum_long_fx[cpe_id][ch] ) { - floatToFixed_arrL32( &hMCT->p_mdst_spectrum_long[cpe_id][ch][k * N_TCX10_MAX], &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], q_spec, length ); + Scale_sig32( &hMCT->p_mdst_spectrum_long_fx[cpe_id][ch][k * N_TCX10_MAX], length, sub( q_spec, hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] ) ); + hMCT->q_mdst_spectrum_long_fx[cpe_id][ch][k] = q_spec; + move16(); } } - if ( hMCT->p_orig_spectrum_long[cpe_id][ch] ) - { - floatToFixed_arrL32( hMCT->p_orig_spectrum_long[cpe_id][ch], hMCT->p_orig_spectrum_long_fx[cpe_id][ch], hMCT->q_orig_spectrum_long_fx, L_FRAME48k ); - } } } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -597,30 +614,93 @@ ivas_error ivas_mct_enc_fx( #endif #endif // 1 + + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + Word16 norm = L_norm_arr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX ); + q_spec = s_min( q_spec, add( sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ), norm ) ); + q_spec = s_min( q_spec, add( sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ), norm ) ); + } + } + + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( EQ_16( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core, TCX_20 ) ) + { + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); + } + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX, sub( q_spec, sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ) ) ); + + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] = sub( 31, q_spec ); + move16(); + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[1] = sub( 31, q_spec ); + move16(); + } + } + /* joint MCT encoding */ ivas_mct_core_enc_fx( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE, ivas_total_brate, switch_bw, ( ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) ? (int16_t) st_ivas->hLFE->lfe_bits : 0, st_ivas->hEncoderConfig->sba_order ); + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20 ) + { + length = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX; + move16(); + } + ELSE + { + length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); + } + Word16 e_spec = sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], L_norm_arr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX ) ); + IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) + { + length = add( length, shr( length, 2 ) ); + } + IF( EQ_16( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core, TCX_20 ) ) + { + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx + length, sub( N_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e = e_spec; + move16(); + } + ELSE + { + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[0] + length, sub( N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1], length, sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], e_spec ) ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_fx[1] + length, sub( N_MAX - N_TCX10_MAX, length ), sub( sub( 31, q_spec ), e_spec ) ); + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e = e_spec; + move16(); + } + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e; + move16(); + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[1] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e; + move16(); + } + } + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS q_spec = 31; move16(); for ( ch = 0; ch < hMCT->nchan_out_woLFE; ch++ ) { - if ( sts_tmp[ch]->hTcxEnc->spectrum[0] ) - { - q_spec = 31 - sts_tmp[ch]->hTcxEnc->spectrum_e[0]; - } length = sts_tmp[ch]->hTcxEnc->L_frameTCX / ( ( sts_tmp[ch]->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV ); if ( sts_tmp[ch]->last_core == ACELP_CORE ) { length += length / 4; } - for ( Word16 k = 0; k <= ( ( sts_tmp[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) - { - if ( sts_tmp[ch]->hTcxEnc->spectrum[0] ) - { - fixedToFloat_arrL32( sts_tmp[ch]->hTcxEnc->spectrum_fx[k], sts_tmp[ch]->hTcxEnc->spectrum[k], q_spec, length ); - } - } } #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index e99d89efd957f59d9ce3dbea168d3dc6b9cc6d70..5d749e1a313f0343efd668996b11a35b48cb1eaa 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -400,6 +400,8 @@ void ivas_omasa_enc_close_fx( } free( ( *hOMasa )->direction_vector_m_fx[i] ); ( *hOMasa )->direction_vector_m_fx[i] = NULL; + free( ( *hOMasa )->direction_vector_e[i] ); + ( *hOMasa )->direction_vector_e[i] = NULL; } free( *hOMasa ); diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index aa9b891e7de361548ae6117ecafa426fcd41e3d5..7b25e5ac39755ace7a7802e2c38f406eab7786d3 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -1009,7 +1009,7 @@ void destroy_sce_enc( test(); IF( ( st->element_mode == EVS_MONO ) && is_evs ) { - destroy_encoder_fx( hSCE->hCoreCoder[0] ); + destroy_evs_core_enc_fx( st ); st = NULL; } ELSE diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index de3f77c9d25cae5b812fed0780121123d2168e80..b4a7638bf5eca9af7557ba4c6fbcb40d6b5d6c35 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1589,12 +1589,13 @@ typedef struct mct_enc_data_structure uint16_t mc_global_ild[MCT_MAX_CHANNELS]; int16_t nBitsMCT; /* number of bits spent on mct side info */ /* pointers to local buffers */ - float *p_mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; - float *p_orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED Word32 *p_mdst_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS]; Word32 *p_orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS]; - Word16 q_orig_spectrum_long_fx; + Word16 q_orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS]; + Word16 q_orig_spectrum_long_com; + Word16 q_mdst_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + #endif int16_t tnsBits[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns bits in the frame */ int16_t tnsSize[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; /* number of tns parameters put into prm */ diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index b1c490c784cddf71bd829a9748945f26192bcca6..310e2ec724f90b7e6a87ef2633f36fa1bee041e7 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -265,7 +265,7 @@ Word16 adapt_GR_ief_fx( L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_ABS_SELECT_Q31, *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16 L_tmp1 = Mpy_32_16_1( STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31, side_gain_counter ); // (Q31, Q0) -> Q16 L_tmp = Mpy_32_32( L_tmp, L_tmp1 ); // (*q_side_gain_bitdiff_lp + Q16, Q16) -> *q_side_gain_bitdiff_lp + Q1 - IF( GT_32( L_shl( L_deposit_l( bitdiff ), add( *q_side_gain_bitdiff_lp, Q1 ) ), L_tmp ) ) + IF( GT_64( W_shl( W_deposit32_l( L_deposit_l( bitdiff ) ), add( *q_side_gain_bitdiff_lp, Q1 ) ), W_deposit32_l( L_tmp ) ) ) { flag = add( no_GR_ord, flag_diff ); *nbits = add( nb_diff, 1 ); diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index e3ff9b07ba8a384485119e8a0145afffdaa56517..eaafe3bdfd2f4ae3d7b30e692295c8f9e7872ba0 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -442,7 +442,10 @@ static void stereo_td_channel_extrapolate_fx( Copy( shift_combined + size_ovl, shift_input, input_frame ); // q_shift - FOR( i = input_frame - itd_shift; i < input_frame; i++ ) + Word16 offset = sub( input_frame, itd_shift ); + Word16 offset_pred_ovlp = sub( offset, pred_ovlp ); + + FOR( i = offset; i < input_frame; i++ ) { shift_input[i] = extract_h( L_mac0( L_mult0( g_lpc, shift_input[i] ), g, sts[leading_channel]->input_fx[i] ) ); // Q = 14 + q_shift - 16 move16(); @@ -451,25 +454,28 @@ static void stereo_td_channel_extrapolate_fx( /* smooth transition (currently done by blending over linearly, could be replaced by something more elaborate.) */ Word16 e_shift = 0; - FOR( i = input_frame - itd_shift - pred_ovlp; i < input_frame - itd_shift; i++ ) + move16(); + FOR( i = offset_pred_ovlp; i < offset; i++ ) { - Word32 temp1 = L_mult0( ( i - input_frame + itd_shift + pred_ovlp ), add( mult( g_lpc, shift_input[i] ), mult( g, sts[leading_channel]->input_fx[i] ) ) ); // q_shift-1(14 + q_shift - 15); - Word32 temp2 = L_mult0( ( input_frame - itd_shift - i ), shift_input[i] ); // q_shift - temp2 = L_shr( temp2, 1 ); // q_shift-1 - temp1 = L_add( temp1, temp2 ); // q_shift-1 - shift_input[i] = BASOP_Util_Divide3232_Scale( temp1, pred_ovlp, &e_shift ); // Q=15-e_shift+q_shift-1 + /*shift_input[i] = ( i - input_frame + itd_shift + pred_ovlp ) * ( ( g_lpc * shift_input[i] ) + ( g * sts[leading_channel]->input[i] ) ) / pred_ovlp + ( input_frame - itd_shift - i ) * shift_input[i] / pred_ovlp;*/ + L_tmp = L_shr( L_mult0( shift_input[i], sub( offset, i ) ), 1 ); // q_shift - 1 + L_tmp = Madd_32_16( L_tmp, L_mac0( L_mult0( g_lpc, shift_input[i] ), g, sts[leading_channel]->input_fx[i] ), sub( i, offset_pred_ovlp ) ); // q_shift - 1 + + shift_input[i] = BASOP_Util_Divide3232_Scale( L_tmp, pred_ovlp, &e_shift ); // Q=15-e_shift+q_shift-1 = 14-e_shift+q_shift move16(); - shift_input[i] = shr( shift_input[i], sub( add( sub( 15, e_shift ), sub( q_shift, 1 ) ), q_temp ) ); // q_temp + shift_input[i] = shr( shift_input[i], sub( add( sub( 14, e_shift ), q_shift ), q_temp ) ); // q_temp move16(); } // scaling whole buffer to q_temp// - FOR( i = 0; i < input_frame - itd_shift - pred_ovlp; i++ ) + FOR( i = 0; i < offset_pred_ovlp; i++ ) { - shift_input[i] = shr( shift_input[i], q_shift - q_temp ); + shift_input[i] = shr( shift_input[i], sub( q_shift, q_temp ) ); + move16(); } *q_new_shift = q_temp; + move16(); return; } #endif diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 4f6e3daa29c97b04a4ded2a30f8882a920d44e4f..5f00f3e35016c474e7fa12079d863b5cf01afbae 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -669,8 +669,8 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } - st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; - st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; + // st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; + // st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; #ifdef IVAS_FLOAT_FIXED st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; @@ -679,9 +679,10 @@ ivas_error stereo_memory_enc_fx( move16(); #endif // set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); - set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + // set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); #ifdef IVAS_FLOAT_FIXED set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); + st->hTcxEnc->spectrum_long_e = 0; #endif #ifndef IVAS_FLOAT_FIXED st->hTcxEnc->tfm_mem = 0.75f; @@ -1455,6 +1456,8 @@ void stereo_switching_enc_fx( set16_fx( sts[1]->buf_synth, 0, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); sts[1]->mem_wsp_fx = 0; move16(); + sts[1]->mem_wsp_q = 0; + move16(); sts[1]->mem_wsp_enc = 0; move16(); init_gp_clip_fx( sts[1]->clip_var_fx ); diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index f2c1a8bbc0e8fdd7e010f4ad5cb8cc7b03775dc1..5297df6599fd8af26bed01755b23b24c08ac9b55 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1582,6 +1582,10 @@ Word16 ivas_acelp_tcx20_switching_fx( L_frame = L_FRAME; move16(); } +#ifdef MSAN_FIX + set16_fx( window_fx, 0, L_LOOK_16k ); + set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); +#endif L_frame_tmp = L_frame; move16(); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 5e198f19f61049219a2eff556b10c0a2a178fa3e..95f063597af33e230011dc2c6c4273f638045ee6 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -178,17 +178,20 @@ void noise_est_init_fx( move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_FX; move32(); - hNoiseEst->q_enrO = Q7; - move16(); hNoiseEst->bckr_fx[i] = E_MIN_FX; move32(); - hNoiseEst->q_bckr = Q7; - move16(); hNoiseEst->ave_enr_fx[i] = E_MIN_FX; move32(); - hNoiseEst->ave_enr_q = Q7; - move16(); } + hNoiseEst->fr_bands_fx_q = 17; + move16(); /*1e-5f; */ + hNoiseEst->q_enrO = Q7; + move16(); + hNoiseEst->q_bckr = Q7; + move16(); + hNoiseEst->ave_enr_q = Q7; + move16(); + move16(); hNoiseEst->totalNoise_fx = 0; move16(); @@ -270,16 +273,6 @@ void noise_est_init_ivas_fx( { Word16 i; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NB_BANDS; i++ ) - { - hNoiseEst->fr_bands1[i] = 1e-5f; - hNoiseEst->fr_bands2[i] = 1e-5f; - hNoiseEst->ave_enr2[i] = E_MIN; - - hNoiseEst->enrO[i] = E_MIN; - hNoiseEst->bckr[i] = E_MIN; - hNoiseEst->ave_enr[i] = E_MIN; - } hNoiseEst->first_noise_updt = 0; hNoiseEst->first_noise_updt_cnt = 0; @@ -299,17 +292,20 @@ void noise_est_init_ivas_fx( move32(); /*Q7//E_MIN; */ hNoiseEst->enrO_fx[i] = E_MIN_Q11_FX; move32(); - hNoiseEst->q_enrO = Q11; - move16(); hNoiseEst->bckr_fx[i] = E_MIN_Q11_FX; move32(); - hNoiseEst->q_bckr = Q11; - move16(); hNoiseEst->ave_enr_fx[i] = E_MIN_Q11_FX; move32(); - hNoiseEst->ave_enr_q = Q11; - move16(); } + hNoiseEst->fr_bands_fx_q = 17; + move16(); /*1e-5f; */ + hNoiseEst->q_enrO = Q11; + move16(); + hNoiseEst->q_bckr = Q11; + move16(); + hNoiseEst->ave_enr_q = Q11; + move16(); + move16(); hNoiseEst->totalNoise_fx = 0; move16(); diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index f5352b75b887d73e9dc5f08da662dc7c6366d897..bd66fda139e28f53c4564560776f148ba8d5e4d2 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -227,6 +227,7 @@ void pitch_ol2_fx( return; } + /*-------------------------------------------------------------------* * StableHighPitchDetect() * diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d296e5692fe01f3c619fcda2c3f89bb9fce85078..45850a1f7cbd201d542e78b88d5f04406465583f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2321,6 +2321,20 @@ void gauss_L2_fx( Word16 *seed_acelp, /*i/o : random seed Q0 */ const Word16 shift ); +void gauss_L2_ivas_fx( + const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ + Word16 code2[], /* o : gaussian excitation Q9 */ + const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ + Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ + Word32 *gain, /* o : excitation gain */ + ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ + const Word16 gain_pit, /* i : unquantized gain of code */ + const Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 *Aq, /* i : quantized LPCs Q12 */ + const Word16 formant_enh, /* i : formant enhancement factor Q15 */ + Word16 *seed_acelp, /*i/o : random seed Q0 */ + const Word16 shift ); + Word32 SFM_Cal_fx( Word32 magn[], Word16 n ); /* Returns: PeriodicityIndex */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 4921a22ac0179b5ef66f1c04c3d08e5215344069..8d8ffbc794233f07df9e875ead500f24445956a5 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -105,8 +105,8 @@ typedef struct signal_buffers_enc_data_structure { #ifndef IVAS_FLOAT_FIXED float input_buff_flt[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; + float Bin_E_old_flt[L_FFT / 2]; /* per bin energy of old 2nd frames */ #endif - float Bin_E_old_flt[L_FFT / 2]; /* per bin energy of old 2nd frames */ float mem_decim_flt[2 * L_FILT_MAX]; /* decimation filter memory */ float mem_decim16k_flt[2 * L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ float old_inp_12k8_flt[L_INP_MEM]; /* memory of input signal at 12.8kHz */ @@ -711,33 +711,34 @@ typedef struct igf_enc_instance_struct typedef struct noise_estimation_structure { - float fr_bands1[NB_BANDS]; /* spectrum per critical bands of the previous frame */ - float fr_bands2[NB_BANDS]; /* spectrum per critical bands 2 frames ago */ - Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame */ - Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago */ -#ifndef IVAS_FLOAT_FIXED - float old_S[L_FFT / 2]; /* Tonal detector - prev. log-energy spectrum with subtracted floor */ - float cor_map[L_FFT / 2]; /* Tonal detector - LT correlation map */ - float noise_char; /* Tonal detector - LT noise character */ - float act_pred; /* Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ - float multi_harm_limit; /* Tonal detector - adaptive threshold */ -#endif - float ave_enr2[NB_BANDS]; /* Tonal detector - LT average E per crit. band (for non_sta2) */ - Word16 ave_enr_q; - float enrO[NB_BANDS]; /* Noise estimator - previous energy per critical band */ - float bckr[NB_BANDS]; /* Noise estimator - background noise estimation per critical band */ - float ave_enr[NB_BANDS]; /* Noise estimator - long-term average energy per critical band */ +#ifndef IVAS_FLOAT_FIXED + float fr_bands1[NB_BANDS]; /* spectrum per critical bands of the previous frame */ + float fr_bands2[NB_BANDS]; /* spectrum per critical bands 2 frames ago */ + float old_S[L_FFT / 2]; /* Tonal detector - prev. log-energy spectrum with subtracted floor */ + float cor_map[L_FFT / 2]; /* Tonal detector - LT correlation map */ + float noise_char; /* Tonal detector - LT noise character */ + float act_pred; /* Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ + float multi_harm_limit; /* Tonal detector - adaptive threshold */ + float ave_enr2[NB_BANDS]; /* Tonal detector - LT average E per crit. band (for non_sta2) */ + float enrO[NB_BANDS]; /* Noise estimator - previous energy per critical band */ + float bckr[NB_BANDS]; /* Noise estimator - background noise estimation per critical band */ + float ave_enr[NB_BANDS]; /* Noise estimator - long-term average energy per critical band */ +#endif + Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame fr_bands_fx_q */ + Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago fr_bands_fx_q */ + Word16 fr_bands_fx_q; Word16 old_S_fx[L_FFT / 2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ Word16 cor_map_fx[L_FFT / 2]; /* Q15 Tonal detector - LT correlation map */ Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ - Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ + Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) ave_enr_q */ Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ Word16 q_enrO; Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ Word16 q_bckr; - Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ + Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band ave_enr_q */ + Word16 ave_enr_q; Word16 aEn; /* Noise estimator - noise estimator adaptation flag */ #ifndef IVAS_FLOAT_FIXED @@ -1790,8 +1791,10 @@ typedef struct tcx_enc_structure int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ /* Core Signal Analysis Outputs */ +#ifndef IVAS_FLOAT_FIXED float *spectrum[2]; /* MDCT output for a short block */ float spectrum_long[N_MAX]; /* MDCT output for a long block. Points to spectrum */ +#endif #ifndef IVAS_FLOAT_FIXED float noiseTiltFactor_flt; /* compensation for LPC tilt in noise filling */ @@ -1914,6 +1917,7 @@ typedef struct tcx_enc_structure Word32 *spectrum_fx[2]; /* MDCT output for a short block */ Word16 spectrum_e[2]; Word32 spectrum_long_fx[N_MAX]; /* MDCT output for a long block. Points to spectrum */ + Word16 spectrum_long_e; /* MDCT output for a long block. Points to spectrum */ Word16 q_spectrum_long_fx; } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -2069,9 +2073,9 @@ typedef struct enc_core_structure Word16 streaklimit_fx; /* LSF quantizer Q15 */ Word16 stab_fac_fx; /* LSF stability factor Q15 */ #endif - float mem_preemph; /* preemphasis filter memory */ - float old_wsp[L_WSP_MEM]; /* old weighted signal vector */ + float mem_preemph; /* preemphasis filter memory */ #ifndef IVAS_FLOAT_FIXED + float old_wsp[L_WSP_MEM]; /* old weighted signal vector */ float old_wsp2[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector */ float mem_wsp; /* weighted signal vector memory */ float mem_decim2[3]; /* weighted signal decimation filter memory */ @@ -2487,9 +2491,9 @@ typedef struct enc_core_structure float *new_speech_enc_flt; float *speech_enc_pe_flt; float *new_speech_enc_pe_flt; -#endif - float *wspeech_enc_flt; float *synth_flt; + float *wspeech_enc_flt; +#endif Word16 *speech_enc; Word16 *speech_enc_pe; Word16 *new_speech_enc; @@ -2569,9 +2573,10 @@ typedef struct enc_core_structure /*Adaptive BPF*/ int16_t bpf_gain_param; +#ifndef IVAS_FLOAT_FIXED float mem_bpf[2 * L_FILT16k]; float mem_error_bpf[2 * L_FILT16k]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 mem_bpf_fx1[2 * L_FILT16k]; Word32 mem_error_bpf_fx[2 * L_FILT16k]; #endif @@ -2593,15 +2598,15 @@ typedef struct enc_core_structure float mean_gc_flt[2]; float prev_lsf4_mean_flt; #else - Word32 mean_gc[2]; /* Q15 */ - Word16 prev_lsf4_mean; /* Qlog2(2.56) */ + Word32 mean_gc[2]; /* Q15 */ + Word16 prev_lsf4_mean; /* Qlog2(2.56) */ #endif int16_t glr_reset; int32_t last_sr_core; #ifndef IVAS_FLOAT_FIXED float last_stab_fac_flt; #else - Word16 last_stab_fac; /* Q15 */ + Word16 last_stab_fac; /* Q15 */ #endif Word32 gain_code[NB_SUBFR16k];