diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 75df71db44e1a1b2517708c65c1a57f0e92bc2ea..defa7561f9c9e6e59f59dd38fdf23c5fa7de57c1 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1508,9 +1508,9 @@ ivas_error acelp_core_enc_ivas_fx( IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { /* Apply a non linearity to the SHB excitation */ - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc } test(); diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 76c9930b68d67bb4fe9b5130ed14fee450a07a22..787e5f701eea596acda5b8070587c54387bf0116 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -22,9 +22,10 @@ *--------------------------------------------------------------------*/ void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal Q0*/ - const Word16 n_samples /* i : number of input samples Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_sp[], /* i : input signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, delay; @@ -107,7 +108,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = st->input_frame_fx; + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); /* frame length of the input signal */ st->extl = -1; move16(); @@ -181,7 +182,7 @@ void amr_wb_enc_fx( st->input_fx[i] = 0; move16(); } - hp20( st->input_fx, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs ); + hp20( st->input_fx, 1, input_frame, mem_hp20_in_fx, st->input_Fs ); /*-----------------------------------------------------------------* * switching from ACELP@16k core to AMR-WB IO mode diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 2483fe95d7dfd61525827fcbe15d94cdb8d96aa9..5147550c0affc2995377aa4f12940fe7227395fe 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -254,7 +254,7 @@ void core_encode_openloop_fx( /* reset TBE buffers previous frame frame wasn't ACELP*/ IF( st->last_core != ACELP_CORE ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 440c02d049d133739642b664faa1f4021c7eb079..19bfd425cb8f16203de2d78eab457e6ff0936702 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -173,7 +173,7 @@ void core_coder_mode_switch_fx( ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { /* reset TBE buffers as previous frame wasn't using TBE */ - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { @@ -415,7 +415,7 @@ void core_coder_mode_switch_ivas_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index 337e1200bc2e89648068ff2c00f556bfd7378c2a..b7cdbc99472340e7ebac0a1cdf2b67eed6018c02 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -44,8 +44,6 @@ void core_switching_pre_enc_fx( { IF( hLPDmem != NULL ) { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /*hLPDmem->q_mem_syn*/ } @@ -199,7 +197,6 @@ void core_switching_pre_enc_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } - st_fx->mem_deemph_fx = 0; /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { @@ -484,7 +481,7 @@ void core_switching_post_enc_fx( } ELSE IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st_fx, st_fx->bwidth ); + TBEreset_enc_fx( st_fx->hBWE_TD, st_fx->last_core, st_fx->bwidth ); } test(); test(); @@ -659,8 +656,6 @@ void core_switching_pre_enc_ivas_fx( { IF( hLPDmem != NULL ) { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); } @@ -817,8 +812,6 @@ void core_switching_pre_enc_ivas_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } - st_fx->mem_deemph_fx = 0; - move16(); /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { @@ -1158,7 +1151,7 @@ void core_switching_post_enc_ivas_fx( } ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } test(); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8e9a82378ad94cb3d5046e9e4943f57a63ef1be7..3380583c09d687238d218c91cd635a18e6fe4227 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -100,7 +100,7 @@ ivas_error evs_enc_fx( * Initializiation *-----------------------------------------------------------------*/ - input_frame = st->input_frame_fx; + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); st->core = -1; move16(); diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index e26d5abbf5320377e19d1ae7d404208fa46b034e..1e3da9fdbbb51045234ec365fca2aee76e0249f9 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1003,7 +1003,7 @@ void gsc_enc_fx( highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, + hGSCEnc->last_exc_dct_in_fx, &hGSCEnc->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index b3ddbf663f702cbd1db6b37f5bdc9dc3563b2b73..487b42bf7ad63805ef292409c6a79fb5f0ddd2b6 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -25,7 +25,7 @@ ivas_error init_encoder_fx( const int16_t interval_SID /* i : interval for SID update */ ) { - Word16 i; + Word16 i, input_frame; Word32 L_tmp; Word16 idchan = 0; /* i : channel ID */ Word16 vad_only_flag = 0; /* i : channel ID */ @@ -36,6 +36,8 @@ ivas_error init_encoder_fx( error = IVAS_ERR_OK; + input_frame = extract_l( Mpy_32_32_r( st_fx->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ @@ -179,8 +181,6 @@ ivas_error init_encoder_fx( move16(); set16_fx( st_fx->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - st_fx->mem_deemph_fx = 0; - move16(); st_fx->mem_preemph_fx = 0; move16(); st_fx->mem_preemph16k_fx = 0; @@ -226,7 +226,6 @@ ivas_error init_encoder_fx( move16(); st_fx->old_voicing_la = 0; move16(); - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); st_fx->old_hpfilt_in_fx = 0; move16(); @@ -305,9 +304,6 @@ ivas_error init_encoder_fx( st_fx->hGSCEnc = NULL; } - st_fx->last_ener_fx = 0; - move16(); - st_fx->old_dE1_fx = 0; move16(); st_fx->old_ind_deltaMax = 0; @@ -572,7 +568,7 @@ ivas_error init_encoder_fx( *-----------------------------------------------------------------*/ /* open analysis for input SR */ - if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), input_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -684,8 +680,8 @@ ivas_error init_encoder_fx( // return error; // } - InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); - ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); + InitSWBencBuffer_fx( st_fx->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st_fx->hBWE_TD ); } ELSE { @@ -716,7 +712,7 @@ ivas_error init_encoder_fx( st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); + st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), input_frame ); st_fx->Energy_Old_fx = 0; @@ -884,9 +880,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, INV_FRAME_PER_SEC_Q15 ) ), - NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), - st_fx->hTranDet ); + InitTransientDetection_fx( input_frame, NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); st_fx->Q_syn2 = 0; move16(); @@ -905,40 +899,30 @@ ivas_error init_encoder_fx( st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ move16(); st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ move16(); st_fx->element_mode = EVS_MONO; /* element mode */ move16(); - st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - move16(); st_fx->element_brate = -1; /* element bitrate */ move32(); - // PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") st_fx->low_rate_mode = 0; /* low-rate mode flag */ move16(); // st_fx->coder_type = GENERIC; /* low-rate mode flag */ set16_fx( st_fx->pitch, L_SUBFR, 3 ); set16_fx( st_fx->voicing_fx, 0, 3 ); - - #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ move16(); #endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move32(); + return error; } /*-----------------------------------------------------------------------* - * LPDmem_enc_init_fx() + * LPDmem_enc_init() * * Initialization of ACELP LPDmem state variables *-----------------------------------------------------------------------*/ @@ -957,44 +941,13 @@ void LPDmem_enc_init_fx( set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); set16_fx( hLPDmem->mem_syn3, 0, M ); - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - return; -} - -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -) -{ - Word16 i; - - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - 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_old_exc = Q15; move16(); hLPDmem->q_lpd_syn = Q15; move16(); hLPDmem->q_mem_syn = Q15; move16(); + hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -1044,13 +997,15 @@ ivas_error init_encoder_ivas_fx( const Word32 element_brate /* i : element bitrate */ ) { - Word16 i; + Word16 i, input_frame; ivas_error error; Word32 igf_brate; error = IVAS_ERR_OK; move32(); + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*-----------------------------------------------------------------* * General parameters *-----------------------------------------------------------------*/ @@ -1667,9 +1622,7 @@ ivas_error init_encoder_ivas_fx( IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* open analysis for input SR */ - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - - if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), st->input_frame_fx ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), input_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -1748,7 +1701,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } ELSE { @@ -1806,8 +1759,8 @@ ivas_error init_encoder_ivas_fx( return error; } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE { @@ -2146,15 +2099,13 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 frame_length = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( GT_16( st->element_mode, EVS_MONO ) ) { - InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); + InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); + InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } /*-----------------------------------------------------------------* @@ -2181,8 +2132,6 @@ ivas_error init_encoder_ivas_fx( move16(); st->old_wsp_shift = 0; move16(); - st->sharpFlag = 0; - move16(); return error; } diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 8ad20a539678a179572b2d572f72e6da7ad6a578..841f4bea2341bbf260c181512c25696083901945 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -472,7 +472,6 @@ ivas_error create_sce_enc_fx( move32(); st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { @@ -556,9 +555,6 @@ ivas_error create_evs_sce_enc_fx( st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; move32(); - st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - move16(); - IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 3bee884824a9fd1af85a79e4c36727efa40b4d54..e6f43ad054fc2a65b926a12276f948de2a190bf9 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -58,7 +58,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } IF( st->hGSCEnc == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -435,8 +435,8 @@ ivas_error stereo_memory_enc_fx( } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index e617e1a9ab707d744a1a3d6a97498694ba3d0812..1e16544e91e2767953ff99b63a6cfdc02ffde68b 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -327,8 +327,8 @@ ivas_error stereo_set_tdm_fx( return error; } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 295608d6fb902cc09274d92c175fc9668df4ddf9..f64bdfd1e561e52e96a6b1bc54ed8d084c771e90 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1489,16 +1489,14 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hEncoderConfig->Opt_AMR_WB ) { - amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + amr_wb_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ); } ELSE { #ifdef DEBUG_MODE_INFO dbgwrite( inputBuffer, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) ); #endif - hCoreCoder->input_frame_fx = inputBufferSize; - move32(); - IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index e64c18468db76ef4f161075c927b97b44f1e13e2..58faf15f17ecd16a48f64c5bddd19fcced4a3806 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -883,10 +883,6 @@ void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -); - void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ @@ -1078,7 +1074,7 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ); /** Runs transient detection. @@ -1131,7 +1127,6 @@ Word16 GetTCXMaxenergyChange_fx( const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks ); - Word16 GetTCXMaxenergyChange_ivas_fx( TRAN_DET_HANDLE hTranDet, const Word8 isTCX10, @@ -3666,8 +3661,9 @@ void re8_cod_fx( ); void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ); void acelp_core_switch_enc_fx( @@ -4395,17 +4391,19 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); +Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, Word16 L_subfr /*Q0*/, Word16 bits /*Q0*/ ); + Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, @@ -4778,8 +4776,9 @@ void destroy_encoder_fx( ); void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_sp[], /* i : i signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ const Word16 n_samples /* i : number of i samples Q0*/ ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index d9afb7f996e8e889ddcf74a95f8a68dda943d4a8..760bbcb87dfcbc97952c455e4a1896a7d2a96992 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -708,8 +708,6 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { - - /* signal memory */ Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ Word16 q_lpd_syn; @@ -803,7 +801,6 @@ typedef struct hq_enc_structure Word16 last_env_fx[BANDS_MAX]; /* Q1 */ Word16 last_max_pos_pulse; - } HQ_ENC_DATA, *HQ_ENC_HANDLE; /* PVQ range coder state */ @@ -1007,6 +1004,13 @@ typedef struct td_bwe_enc_structure Word16 gain_prec_swb_fx; /* Q14 */ Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; + + Word16 prev_Q_bwe_exc; + Word16 prev_Q_bwe_syn; + } TD_BWE_ENC_DATA, *TD_BWE_ENC_HANDLE; @@ -1152,20 +1156,17 @@ typedef struct tcx_enc_structure Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling Q15 */ Word16 noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth Q15 */ STnsData tnsData[2]; - // Word16 fUseTns[2]; + Word8 fUseTns[2]; Word16 bTnsOnWhithenedSpectra[2]; - // Word16 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word16 *speech_TCX; Word16 *new_speech_TCX; - // Word16 q_speech_TCX; Word16 tcxltp; Word16 tcxltp_pitch_int; @@ -1219,6 +1220,7 @@ typedef struct tcx_enc_structure Word16 spectrum_long_e; /* MDCT output for a long block. Points to spectrum */ Word16 q_spectrum_long_fx; Word16 spectrum_length; /* corresponds to L_frameTCX, used for scaling of MDCT/MDST buffers */ + } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -1237,10 +1239,7 @@ typedef struct enc_core_structure Word16 idchan; /* channel ID (audio channel number) */ Word16 id_element; /* element ID */ Word16 element_mode; /* element mode */ - Word16 last_element_mode; /* element mode */ Word32 element_brate; /* element bitrate */ - Word16 extl_orig; /* extension layer */ - Word32 extl_brate_orig; /* extension layer bitrate */ Word16 codec_mode; /* Mode1 or Mode2 */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ @@ -1249,9 +1248,7 @@ typedef struct enc_core_structure Word16 mdct_sw_enable; /* MDCT switching enable flag */ Word16 mdct_sw; /* MDCT switching indicator */ - BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ - Word16 last_enerBuffer_exp; - + BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ @@ -1290,34 +1287,8 @@ typedef struct enc_core_structure char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ #endif #endif - Word16 nTimeSlots; /* for CLDFB */ - Word16 ini_frame; /* initialization frames counter */ - // Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - // Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - // Word32 core_brate_fx; /* core bitrate */ - // Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - // Word16 extl_fx; /* extension layer */ - // Word16 last_extl_fx; /* previous extension layer */ - // Word32 extl_brate_fx; /* extension layer bitrate */ - // Word16 input_bwidth_fx; /* input signal bandwidth */ - // Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - // Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - // Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - // Word16 L_frame_fx; /* ACELP core internal frame length */ - // Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - // Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - // Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - // Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - // Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ - /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ @@ -1328,27 +1299,25 @@ typedef struct enc_core_structure Word16 fmerit_dt; /* signal classification score difference Q15 */ Word16 Nb_ACELP_frames; - Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ - // Word16 pitch_fx[3]; + Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ Word16 voicing_fx[3]; /* open-loop normalized correlation values for three half-frames Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 pstreaklen; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer Q15 */ - Word16 stab_fac_fx; /* LSF stability factor Q15 */ - Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ - // Word16 pstreaklen_fx; /* LSF quantizer */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 pstreaklen; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ + Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ @@ -1364,15 +1333,12 @@ typedef struct enc_core_structure Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ Word16 exp_old_wsp; Word16 Q_old_wsp2; - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_wsp_q; - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ Word16 GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; @@ -1381,7 +1347,6 @@ typedef struct enc_core_structure Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ Word16 next_force_safety_net; /* FEC - flag to force safety net in next frame */ - // Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ Word16 act_count; /* Stationary noise UV modification - activation counter */ @@ -1467,7 +1432,7 @@ typedef struct enc_core_structure Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ Word16 *buf_speech_enc_pe; // exp_buf_speech_enc_pe - Word16 *buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + Word16 *buf_synth; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ Word16 *buf_speech_enc; // exp_buf_speech_enc Word16 *buf_wspeech_enc; // exp_buf_wspeech_enc @@ -1478,6 +1443,8 @@ typedef struct enc_core_structure Word16 exp_buf_wspeech_enc; Word16 exp_buf_synth; + Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ + /*----------------------------------------------------------------------------------* * Noise estimation *----------------------------------------------------------------------------------*/ @@ -1490,8 +1457,6 @@ typedef struct enc_core_structure SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ - Word16 sp_aud_decision0; /* 1st stage speech/music decision flag */ Word16 sp_aud_decision1; /* 1st stage speech/music classification flag */ Word16 sp_aud_decision2; /* 2nd stage speech/music classification flag */ @@ -1530,9 +1495,6 @@ typedef struct enc_core_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynTd; /* synthesis filterbank - used for HB signal generation */ - // HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - // HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; /*----------------------------------------------------------------------------------* * FD CNG handle @@ -1563,7 +1525,6 @@ typedef struct enc_core_structure HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - PVQ_ENC_HANDLE hPVQ; /*----------------------------------------------------------------------------------* * TD BWE parameters *----------------------------------------------------------------------------------*/ @@ -1662,7 +1623,7 @@ typedef struct enc_core_structure Word16 inv_gamma; /* Q14 */ TRAN_DET_HANDLE hTranDet; - Word16 transient_info[3]; + Word16 acelpFramesCount; Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E Q7 in EVS */ /* Q4 in IVAS */ Word32 prevTempFlatness_32fx; /* Q21 in IVAS */ @@ -1685,7 +1646,6 @@ typedef struct enc_core_structure Word16 encoderLookahead_FB; /* pitch_ol for adaptive lag window */ - Word16 old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ @@ -1762,8 +1722,7 @@ typedef struct enc_core_structure * IVAS parameters *---------------------------------------------------------------*/ - Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ - Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ /* stereo switching memories */ Word16 mem_preemph_DFT_fx; /* Q(-1) */ @@ -1779,16 +1738,13 @@ typedef struct enc_core_structure Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ + Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + /*----------------------------------------------------------------------------------* * Fixed point only variables *----------------------------------------------------------------------------------*/ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - Word16 Q_exc; - - Word16 prev_Q_bwe_exc; - Word16 prev_Q_bwe_syn; Word16 Q_stat_noise_ge; Word16 Q_stat_noise; Word16 Q_syn2; @@ -1802,13 +1758,8 @@ typedef struct enc_core_structure Word16 prev_Q_new; Word16 prev_Q_shb; Word16 Q_max_enc[2]; - Word16 EnergyLT_fx_exp; - Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; - - Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + Word16 last_enerBuffer_exp; } Encoder_State, *ENC_CORE_HANDLE; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0d9a3d0cb1cc1b21c135f9d323fdc5502e98f026..927120771b8cf62b2c3cc481fae1a7a1e772f9d9 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -369,12 +369,12 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) * * Initialize SWB buffers *-------------------------------------------------------------------*/ + void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; @@ -398,15 +398,8 @@ void InitSWBencBuffer_fx( set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); // IVAS_CODE - // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); - // hBWE_TD->old_mean_EnvSHBres = 0.0f; - // hBWE_TD->prev_enr_EnvSHBres = 1.0f; - // hBWE_TD->prev_shb_env_tilt = 0.0f; - // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - // hBWE_TD->prev_mix_factor = 1.0f; - // hBWE_TD->prev_Env_error = 0.0f; - set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + // InitSWBencBufferStates_fx(hBWE_TD, NULL ); + set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; move16(); @@ -456,25 +449,29 @@ void InitSWBencBuffer_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_Q_bwe_exc = 31; move16(); - st_fx->prev_Q_bwe_syn = 31; + hBWE_TD->prev_Q_bwe_syn = 31; move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); return; } + +/*-------------------------------------------------------------------* + * InitSWBencBufferStates() + * + * Initialize SWB buffer states + *-------------------------------------------------------------------*/ + void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; @@ -551,33 +548,30 @@ void InitSWBencBuffer_ivas_fx( set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); - hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 15; + hBWE_TD->prev_Q_bwe_exc = 15; move16(); - st_fx->prev_Q_bwe_syn = 15; + hBWE_TD->prev_Q_bwe_syn = 15; move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); return; } + /*-------------------------------------------------------------------* * ResetSHBbuffer_Enc() * *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - /* states for the filters used in generating SHB excitation from WB excitation*/ set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); @@ -608,7 +602,6 @@ void ResetSHBbuffer_Enc_fx( hBWE_TD->tbe_premph_fx = 0; move16(); - return; } @@ -756,11 +749,11 @@ void wb_tbe_enc_fx( move32(); } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; + hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; move16(); } @@ -809,11 +802,11 @@ void wb_tbe_enc_fx( lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -833,12 +826,12 @@ void wb_tbe_enc_fx( Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } @@ -869,12 +862,11 @@ void wb_tbe_enc_fx( move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -894,12 +886,11 @@ void wb_tbe_enc_fx( } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -952,9 +943,9 @@ void wb_tbe_enc_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); + Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) @@ -970,7 +961,7 @@ void wb_tbe_enc_fx( move32(); IF( st_fx->element_mode > EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); + tmp = sub( shl( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -978,7 +969,7 @@ void wb_tbe_enc_fx( prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); @@ -989,11 +980,9 @@ void wb_tbe_enc_fx( } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, @@ -1016,8 +1005,7 @@ void wb_tbe_enc_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { @@ -1098,7 +1086,6 @@ void wb_tbe_enc_fx( move16(); /* Q15 */ } - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) @@ -1137,7 +1124,6 @@ void wb_tbe_enc_fx( EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1191,7 +1177,6 @@ void wb_tbe_enc_fx( /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ } - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ L_tmp = L_mult( voice_factors[0], 8192 ); FOR( i = 1; i < NB_SUBFR; i++ ) @@ -1223,7 +1208,7 @@ void wb_tbe_enc_fx( ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); return; @@ -1368,11 +1353,11 @@ void wb_tbe_enc_ivas_fx( move32(); } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; + hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; move16(); } @@ -1421,11 +1406,11 @@ void wb_tbe_enc_ivas_fx( lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -1445,12 +1430,12 @@ void wb_tbe_enc_ivas_fx( Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } @@ -1481,12 +1466,11 @@ void wb_tbe_enc_ivas_fx( move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -1498,11 +1482,11 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -1557,9 +1541,9 @@ void wb_tbe_enc_ivas_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); + Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) @@ -1584,7 +1568,7 @@ void wb_tbe_enc_ivas_fx( shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); move16(); } - Q_prev_pow = shl_r( sub( sub( st_fx->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); move16(); } ELSE @@ -1594,7 +1578,7 @@ void wb_tbe_enc_ivas_fx( shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; move16(); } - Q_prev_pow = shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ); + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); move16(); } @@ -1608,7 +1592,7 @@ void wb_tbe_enc_ivas_fx( prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ } - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) @@ -1747,7 +1731,6 @@ void wb_tbe_enc_ivas_fx( move16(); /* Q15 */ } - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) @@ -1882,7 +1865,6 @@ void wb_tbe_enc_ivas_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); @@ -1890,7 +1872,7 @@ void wb_tbe_enc_ivas_fx( &Q_bwe_exc_ext, &dummy, dummy, dummy ); Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); return; @@ -2389,7 +2371,7 @@ void swb_tbe_enc_fx( /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; @@ -2397,7 +2379,7 @@ void swb_tbe_enc_fx( } /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); IF( sc != 0 ) { rescale_genSHB_mem_enc( st_fx, sc ); @@ -2418,7 +2400,7 @@ void swb_tbe_enc_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ @@ -2439,7 +2421,7 @@ void swb_tbe_enc_fx( coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -2472,7 +2454,7 @@ void swb_tbe_enc_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } @@ -2480,12 +2462,9 @@ void swb_tbe_enc_fx( { PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ @@ -2861,7 +2840,7 @@ void swb_tbe_enc_fx( } /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); return; @@ -3714,7 +3693,7 @@ void swb_tbe_enc_ivas_fx( /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; @@ -3722,7 +3701,7 @@ void swb_tbe_enc_ivas_fx( } /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); IF( sc != 0 ) { rescale_genSHB_mem_enc( st_fx, sc ); @@ -3740,7 +3719,7 @@ void swb_tbe_enc_ivas_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ @@ -3753,7 +3732,7 @@ void swb_tbe_enc_ivas_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, - &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, + &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); @@ -3805,7 +3784,7 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } @@ -4154,7 +4133,6 @@ void swb_tbe_enc_ivas_fx( } } - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; move16(); @@ -4170,7 +4148,6 @@ void swb_tbe_enc_ivas_fx( /* Quantization of the gain shape parameter */ QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); - /* o: GainShape_fx in Q15 */ /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4538,7 +4515,7 @@ void swb_tbe_enc_ivas_fx( move16(); /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); return; @@ -7872,22 +7849,23 @@ void tbe_write_bitstream_fx( { push_next_indice( hBstr, hBWE_TD->idxGain, 4 ); } + + return; } void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - IF( NE_16( st_fx->last_core, ACELP_CORE ) ) + IF( NE_16( last_core, ACELP_CORE ) ) { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); move32(); - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_Q_bwe_exc = 31; move16(); } @@ -7917,6 +7895,8 @@ void TBEreset_enc_fx( fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } } + + return; } /*-------------------------------------------------------------------* diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index bb8239f90a4ab6ae55edc1b245017274bec24154..8f99df8840192b4d91f490a8355a5725e96c264b 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -387,29 +387,32 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ) { /* Init the delay buffer. */ - InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); + InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); + /* Init the TCX Short/Long transient detector. */ - InitTransientDetector_ivas_fx( &pTransientDetection->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ IF( ext_mem_flag ) { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); move16(); } ELSE { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); move16(); } @@ -514,7 +517,6 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( return i; } - Word16 GetTCXMaxenergyChange_fx( TRAN_DET_HANDLE hTranDet, const Word8 isTCX10,