diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index e200d0f00834bdf4510275df56155aaeb6ba3cf1..98d7fe957f47adb8f9da1b1a1deea27e319e9360 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1184,6 +1184,8 @@ ivas_error init_encoder_ivas_fx( st->mem_preemph_fx = 0; move16(); + st->mem_preemph_fx_q_inp = 0; + move16(); st->mem_preemph16k_fx = 0; move16(); st->mem_preemph_enc = 0; @@ -1298,6 +1300,8 @@ ivas_error init_encoder_ivas_fx( /* stereo switching memories */ st->mem_preemph_DFT_fx = 0; move16(); + st->mem_preemph_DFT_fx_q_inp = 0; + move16(); set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); st->mem_preemph16k_DFT_fx = 0; move16(); @@ -1397,6 +1401,7 @@ ivas_error init_encoder_ivas_fx( st->q_Bin_E_old = Q31; move16(); set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->mem_decim_fx_q_inp, 0, shl( L_FILT_MAX, 1 ) ); set16_fx( st->mem_decim16k_fx, 0, shl( L_FILT_MAX, 1 ) ); set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); @@ -1410,6 +1415,10 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); st->q_inp = Q15; move16(); + st->mem_preemph_q = Q15; + move16(); + st->mem_q = Q15; + move16(); st->q_old_inp = Q15; move16(); set32_fx( st->input_buff32_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index b9a15cd358cceb445b33cd1dc5827faa9708f313..3d7d87bc201f5819e1b2f190d42a6c29dd9c5f54 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -499,15 +499,16 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ - - Scale_sig( st->mem_decim_fx, 2 * L_FILT_MAX, sub( st->q_inp, Q_inp_const ) ); /* st->q_inp */ + Scale_sig( st->mem_decim_fx_q_inp, 2 * L_FILT_MAX, sub( st->q_inp, st->mem_q ) ); /* st->q_inp */ 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 ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ - - Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ + 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_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ + Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ + st->mem_q = st->q_inp; + move16(); + Copy( st->mem_decim_fx_q_inp, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ 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 ); /* st->q_inp */ Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ @@ -521,13 +522,15 @@ ivas_error pre_proc_front_ivas_fx( Word16 length_inp = NS2SA_FX2( input_Fs, L_MEM_RECALC_SCH_NS ); Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); - new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ + new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx_q_inp, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } - 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 ); /* st->q_inp */ - Copy( st->mem_decim_fx, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ + 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_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ + st->mem_q = st->q_inp; + move16(); + Copy( st->mem_decim_fx_q_inp, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* st->q_inp */ + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ IF( lMemRecalc > 0 ) { @@ -541,10 +544,13 @@ ivas_error pre_proc_front_ivas_fx( 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_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ + Copy( signal_in_fx + sub( input_frame, add( NS2SA_FX2( input_Fs, L_MEM_RECALC_NS ), 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ) ), st->mem_decim_fx_q_inp, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ + st->mem_q = st->q_inp; + move16(); scale_sig( old_inp_12k8_fx, L_INP_MEM - STEREO_DFT_OVL_12k8, sub( Q_inp_const, st->q_inp ) ); scale_sig( st->input_fx - input_frame, input_frame_full, sub( Q_inp_const, st->q_inp ) ); - Scale_sig( st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */ + Copy_Scale_sig( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */ + // Scale_sig( st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */ st->q_inp = Q_inp_const; move16(); st->q_old_inp = Q_inp_const; @@ -552,7 +558,7 @@ ivas_error pre_proc_front_ivas_fx( } IF( NE_16( Q_inp_const, st->q_inp ) ) { - Scale_sig( st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */ + Copy_Scale_sig( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( Q_inp_const, st->q_inp ) ); /* Q(-1) */ } Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( -1, sub( 15, st->exp_buf_speech_enc ) ) ); /* Q(-1) */ @@ -585,24 +591,23 @@ ivas_error pre_proc_front_ivas_fx( headroom = 2; move16(); - - st->mem_preemph_fx = shl_sat( st->mem_preemph_fx, sub( st->q_inp, -1 ) ); /*st->q_inp*/ + st->mem_preemph_fx_q_inp = shl_sat( st->mem_preemph_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); - st->mem_preemph_DFT_fx = shl_sat( st->mem_preemph_DFT_fx, sub( st->q_inp, -1 ) ); /*st->q_inp*/ + st->mem_preemph_DFT_fx_q_inp = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy_Scale_sig( 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, sub( Q_inp_const, st->q_inp ) ); /* memory for TD/DFT stereo switching Q_inp_const*/ - st->mem_preemph_fx = st->mem_preemph_DFT_fx; /* st->q_inp */ + st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */ move16(); - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* st->q_inp */ + st->mem_preemph_DFT_fx_q_inp = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* st->q_inp */ 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; + PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + dummy_fx = st->mem_preemph_fx_q_inp; move16(); // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); @@ -618,18 +623,18 @@ ivas_error pre_proc_front_ivas_fx( { IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - st->mem_preemph_fx = st->mem_preemph_DFT_fx; /* st->q_inp */ + st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */ move16(); Copy_Scale_sig( 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, sub( st->q_inp, Q_inp_const ) ); /* st->q_inp */ // 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 ); + 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_q_inp ); 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(); } - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* st->q_inp */ + st->mem_preemph_DFT_fx_q_inp = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* st->q_inp */ move16(); } @@ -640,15 +645,15 @@ ivas_error pre_proc_front_ivas_fx( Word16 length_12k8 = NS2SA( 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 ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx_q_inp ); preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8; preemp_len = length_12k8; move16(); } // 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 + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; /* st->q_inp */ + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + dummy_fx = st->mem_preemph_fx_q_inp; /* st->q_inp */ 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 + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); @@ -669,8 +674,8 @@ ivas_error pre_proc_front_ivas_fx( ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ { // 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; + PREEMPH_32FX( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + dummy_fx = st->mem_preemph_fx_q_inp; 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 + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); @@ -678,11 +683,12 @@ ivas_error pre_proc_front_ivas_fx( preemp_len = L_FRAME + L_FILT; move16(); } - st->mem_preemph_fx = shl_sat( st->mem_preemph_fx, sub( -1, st->q_inp ) ); /*Q(-1) saturation added as float value goes above 65536 for +10 dB test (ltv48_MC512.wav and ltv48_MC51.wav) */ + st->mem_preemph_fx = shl_sat( st->mem_preemph_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1) saturation added as float value goes above 65536 for +10 dB test (ltv48_MC512.wav and ltv48_MC51.wav) */ move16(); - st->mem_preemph_DFT_fx = shl( st->mem_preemph_DFT_fx, sub( -1, st->q_inp ) ); /*Q(-1)*/ + st->mem_preemph_DFT_fx = shl( st->mem_preemph_DFT_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1)*/ + move16(); + st->mem_preemph_q = st->q_inp; move16(); - maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); inp_max = s_max( extract_h( max_32 ), 1 ); diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index 1bd5c936be5d9136f80a1b96d4d7e4d5e7bf9b57..8acbc3e879e8d943c27f8624656c66d7b60d5542 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -370,7 +370,7 @@ void stereo_mdct_core_enc_fx( } } - exp1 = add( exp1, 1 ); /* 1 guard bit to avoid over-flows in stereo_coder_tcx_fx */ + exp1 = add( exp1, 2 ); /* 2 guard bit to avoid over-flows in stereo_coder_tcx_fx */ exp2 = add( exp2, 2 ); /* 2 guard bit to avoid over-flows in stereo_coder_tcx_fx (ms_processing_fx) */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 4fe5bb8a4766bf9f3d85fc12933d44de2d55a3d3..45ec01b3191699bf6ae8614ca9be327a3cfebc71 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1361,7 +1361,10 @@ typedef struct enc_core_structure Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 mem_preemph_fx; /* preemphasis filter memory Q(-1) */ + Word16 mem_preemph_fx; /* preemphasis filter memory Q(-1) */ + Word16 mem_q; /* preemphasis filter memory Q(-1) */ + Word16 mem_preemph_q; /* preemphasis filter memory Q(-1) */ + Word16 mem_preemph_fx_q_inp; /* preemphasis filter memory Q(-1) */ Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ Word16 exp_old_wsp; @@ -1460,10 +1463,11 @@ typedef struct enc_core_structure SIGNAL_BUFFERS_ENC_HANDLE hSignalBuf; Word32 *Bin_E_old_fx; /* per bin energy of old 2nd frames */ Word16 q_Bin_E_old; - Word16 *mem_decim_fx; /* decimation filter memory Q(-1) */ - Word16 *mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz Q(-1) */ - Word16 *old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ - Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ + Word16 *mem_decim_fx; /* decimation filter memory Q(-1) */ + Word16 mem_decim_fx_q_inp[2 * L_FILT_MAX]; /* decimation filter memory Q(-1) */ + Word16 *mem_decim16k_fx; /* ACELP@16kHz - decimation filter memory @16kHz Q(-1) */ + Word16 *old_inp_12k8_fx; /* memory of input signal at 12.8kHz */ + 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*/ @@ -1773,6 +1777,7 @@ typedef struct enc_core_structure /* stereo switching memories */ Word16 mem_preemph_DFT_fx; /* Q(-1) */ + Word16 mem_preemph_DFT_fx_q_inp; /* Q(-1) */ Word16 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; /* Q(-1) */ Word16 mem_preemph16k_DFT_fx; /* Q(-1) */ Word16 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; /* Q(-1) */