diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 11891c6ca34ddd684bd234e68cc13d555c1951f1..d87207a908def528694a9b3dc597f32dd6e43f2a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1587,8 +1587,12 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length */ const Word16 hq_core_type, /* i : HQ core type */ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +#else Word16 output[], Word16 *Q_output +#endif ); #ifndef HARMONIZE_TBE @@ -1890,7 +1894,11 @@ void GenShapedWBExcitation_ivas_fx( /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + #endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -2088,7 +2096,11 @@ void ivas_buffer_deinterleaved_to_interleaved_fx( void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11 */ +#else Word16 *signal_out, /* o : synthesis @internal_Fs, Q0 */ +#endif Word16 *signal_outFB, /* o : synthesis @output_Fs, Q0 */ Word16 pitch_buf[], /* o : floating pitch for each subframe, Q6 */ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ diff --git a/lib_com/options.h b/lib_com/options.h index 26252f3feef2ca4646aa8c45182707317884496f..523ba0ab821e9f6d47c4568d427fc38ed50afa87 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -87,6 +87,9 @@ #define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ #define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ +#define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ +#define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d914126abf993113758582808114dfcb9b182f17..252d0646984ef618bc8effd23a89c6c43bbf60ff 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7572,10 +7572,15 @@ ivas_error core_switching_pre_dec_fx( Word16 *Q_olapBufferSynth2 ); ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#else + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ + Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -10109,10 +10114,18 @@ Word16 swb_bwe_dec_fx32( ); ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs */ - Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ + Decoder_State *st, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + Word16 output_fx[], /* o : synthesis @internal Fs */ +#endif + Word16 synth_fx16[], /* o : synthesis */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ +#else + Word16 save_hb_synth_fx16[], /* o : HB synthesis */ +#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 033683a0a94c9877b0c8d12bcc0ac41a9f3c1cc7..07ebbcdb8e08342731d71ab89eaa2e290d67748e 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -52,10 +52,18 @@ *-------------------------------------------------------------------*/ ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ - Word16 synth_fx16[], /* o : synthesis Q_syn2*/ - Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ +#endif + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ +#else + Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ +#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ @@ -205,7 +213,11 @@ ivas_error acelp_core_dec_fx( Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ } - set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + set32_fx( output_fx32, 0, st->L_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#else + set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#endif set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ @@ -2008,7 +2020,11 @@ ivas_error acelp_core_dec_fx( } } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( save_hb_synth_fx32 != NULL ) +#else IF( save_hb_synth_fx16 != NULL ) +#endif { /* save and then zero-out lowband */ max_real = 0; @@ -2049,9 +2065,13 @@ ivas_error acelp_core_dec_fx( } } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx32, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); +#else cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*tmp buffer for save_hb_synth_fx[] */, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); Copy_Scale_sig_32_16( synth_fx, save_hb_synth_fx16, output_frame, 0 ); // Q0 +#endif /* restore lowband */ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -2194,10 +2214,14 @@ ivas_error acelp_core_dec_fx( /* Copy output signal */ Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 +#else IF( st->element_mode > EVS_MONO ) { Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ } +#endif Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 st->Q_syn2 = 0; diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index ae891ae534676f7265334f0a70620214affd4825..ee7fdb5a82efad09496b3aa8d2bf7c8c908c8f67 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -172,7 +172,6 @@ void bw_switching_pre_proc_fx( } } - test(); test(); test(); @@ -207,11 +206,25 @@ void bw_switching_pre_proc_fx( } +/*---------------------------------------------------------------------* + * core_switching_post_dec() + * + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ +#else + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ +#endif +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#else + Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -433,7 +446,11 @@ ivas_error core_switching_post_dec_fx( test(); IF( ( ( NE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_core_brate, FRAME_NO_DATA ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) && NE_16( st_fx->element_mode, IVAS_CPE_TD ) ) || EQ_16( nchan_out, 1 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_fx->idchan, 1 ) && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) ) { - Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output_fx, L_FRAME48k, Q10 - Q11 ); /* Q10 */ +#else + Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */ +#endif core_switch_lb_upsamp_fx( st_fx, output_fx ); } @@ -491,7 +508,11 @@ ivas_error core_switching_post_dec_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ +#else Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ +#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -540,7 +561,11 @@ ivas_error core_switching_post_dec_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ +#else Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ +#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -602,10 +627,18 @@ ivas_error core_switching_post_dec_fx( hHQ_core->Q_old_wtda = Qtmp; move16(); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 output_mem_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; + IF( output_mem_fx32 != NULL ) + { + Copy_Scale_sig_32_16( output_mem_fx32, output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Qtmp, Q11 ) ); // Qtmp + } +#else IF( output_mem_fx != NULL ) { Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */ } +#endif *Qsynth = Qtmp; move16(); @@ -795,7 +828,6 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) @@ -871,6 +903,7 @@ ivas_error core_switching_post_dec_fx( return error; } + /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -954,9 +987,17 @@ void core_switching_hq_prepare_dec_fx( /* reset state of old_out if switching */ set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame ); + return; } + +/*---------------------------------------------------------------------* + * core_switch_lb_upsamp() + * + * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz) + *---------------------------------------------------------------------*/ + static void core_switch_lb_upsamp_fx( Decoder_State *st, /* i/o: Decoder state */ Word32 *output /* i/o: LB synth/upsampled LB synth Q10*/ @@ -1032,17 +1073,36 @@ static void core_switch_lb_upsamp_fx( no_col = s_min( no_col, temp ); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( st->hTcxDec->L_frameTCX, imult1616( no_col, st->cldfbSyn->no_channels ) ), Q11 - Q10 ); /* Q11 */ +#else Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */ +#endif /* save synthesis - needed in case of core switching */ IF( st->hTcxDec != NULL ) { - Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -4 ); /* Q0 */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ +#else + Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ +#endif } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output, imult1616( no_col, st->cldfbSyn->no_channels ), Q11 - Q4 ); /* Q11 */ +#endif + return; } + +/*---------------------------------------------------------------------* + * smoothTransitionDtxToTcx() + * + * apply smoothing to the transition part for inactive to active transitions in DTX + *---------------------------------------------------------------------*/ + #define TRANSITION_SMOOTHING_LEN_16k 15 #define TRANSITION_SMOOTHING_LEN_32k 31 #define TRANSITION_SMOOTHING_LEN_48k 47 diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index e34527da088bf6dae44a94234ce3aa1b7715c0e2..dcc99bbdc980ea25aa9fe8066a50ef78303a1313 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -468,8 +468,13 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length Q0*/ const Word16 hq_core_type, /* i : HQ core type Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ - Word16 output[], /* Q_ouput */ - Word16 *Q_output ) +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +#else + Word16 output[], /* Q_ouput */ + Word16 *Q_output +#endif +) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; Word16 i, j, flag_uv, num_Sb, nb_sfm; @@ -504,7 +509,19 @@ void ivas_hq_core_dec_fx( Word16 mdctWindowLength; Word16 mdctWindowLengthFB; Word16 tmp_e; +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 tmp_out[L_FRAME48k]; +#else + Word16 output[L_FRAME16k]; + Word16 Q_output; + + Q_output = 0; + move16(); + *Q_synth = 0; + move16(); + st_fx->Q_syn_factor = 0; + move16(); +#endif /*-------------------------------------------------------------------------- * Initializations @@ -886,7 +903,11 @@ void ivas_hq_core_dec_fx( move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Q_output = Q_audio; +#else *Q_output = Q_audio; +#endif move16(); } @@ -912,7 +933,11 @@ void ivas_hq_core_dec_fx( IF( st_fx->element_mode > EVS_MONO ) { /* LB synthesis for potential switch to ACELP */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + window_ola_fx( wtda_audio_LB, output, &Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); +#else window_ola_fx( wtda_audio_LB, output, Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); +#endif } test(); test(); @@ -974,12 +999,21 @@ void ivas_hq_core_dec_fx( Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } + /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */ + + Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11 + st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) ); +#else IF( st_fx->element_mode > EVS_MONO ) { Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } +#endif + return; } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 0f9bf2d9b67d32d97579d7e920da4daa139a7494..0b7e13a808921b9ee0de8d6a139cfc5a0d35a488 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -93,7 +93,9 @@ ivas_error ivas_core_dec_fx( ivas_error error; Word32 L_tmp; Word16 Q_synth; +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; +#endif Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; @@ -282,6 +284,9 @@ ivas_error ivas_core_dec_fx( } set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + set32_fx( output_32_fx[n], 0, L_FRAME48k ); +#endif set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ @@ -465,11 +470,13 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE set16_fx( output_16_fx[n], 0, L_FRAME48k ); /* this is needed for instances like L_norm_arr( p_output_fx[i], L_FRAME48k ) */ - +#endif IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; IF( save_hb_synth_32_fx ) @@ -480,7 +487,7 @@ ivas_error ivas_core_dec_fx( { save_hb_synth_16_fx = NULL; } - +#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 @@ -520,13 +527,19 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = 0; move16(); +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = acelp_core_dec_fx( st, output_32_fx[n], synth_16_fx[n], save_hb_synth_32_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#endif { return error; } +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); // Q0 +#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q10 - Q11 ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) , Q10 */ @@ -549,7 +562,11 @@ ivas_error ivas_core_dec_fx( IF( save_hb_synth_32_fx ) { +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_DEPREC( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); // Q11 +#else + Scale_sig32( save_hb_synth_32_fx, output_frame, Q11 ); // Q0 -> Q11 +#endif hSCE->q_save_hb_synth_fx = Q11; move16(); } @@ -590,9 +607,13 @@ ivas_error ivas_core_dec_fx( move32(); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + stereo_tcx_core_dec_fx( st, frameMode[n], output_32_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); +#else stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11 +#endif IF( st->hTcxDec ) { @@ -610,6 +631,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); + + Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor +#else Word16 Q_output; Q_output = 0; @@ -625,6 +651,7 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor +#endif } /*---------------------------------------------------------------------* @@ -804,6 +831,7 @@ ivas_error ivas_core_dec_fx( /*core_switching_post_dec*/ Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor ); +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING /*------------------fix-to-fix-end-----------------------*/ Word16 output_mem_16_fx[L_FRAME48k]; @@ -824,7 +852,7 @@ ivas_error ivas_core_dec_fx( /*size of synth is choosen as delay comp to start with*/ /*-------------------cldfb-start-------------------------*/ - +#endif IF( st->cldfbSyn != NULL ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q4 - Q11 ); // Q4 @@ -832,7 +860,6 @@ ivas_error ivas_core_dec_fx( move16(); } - test(); test(); test(); @@ -884,7 +911,11 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_fx, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -925,7 +956,14 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Scale_sig32( output_32_fx[n], output_frame, ( Q4 - Q11 ) ); // Q4 + Scale_sig32( output_32_fx[n], output_frame, ( Q11 - Q4 ) ); // Q11 +#endif +#else Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); // Q11 +#endif /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -966,8 +1004,18 @@ ivas_error ivas_core_dec_fx( * WB BWE decoding *---------------------------------------------------------------------*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Word16 Q_hb_synth_fx, Q_synth_fx; + Word16 Q_syn_hb; + + Q_hb_synth_fx = 0; + move16(); + Q_synth_fx = Q_synth; + move16(); +#else Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; Word16 Q_syn_hb, sf; +#endif flaf_swb_tbe = 0; move16(); @@ -985,6 +1033,7 @@ ivas_error ivas_core_dec_fx( move16(); } +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE sf = getScaleFactor32( output_32_fx[n], L_FRAME48k ); Q_input = 0; @@ -999,7 +1048,8 @@ ivas_error ivas_core_dec_fx( move16(); Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); // Q_input - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 +#endif + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); test(); test(); @@ -1022,7 +1072,11 @@ ivas_error ivas_core_dec_fx( ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_32_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); +#else Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); +#endif } /* Memories Re-Scaling */ @@ -1030,7 +1084,9 @@ ivas_error ivas_core_dec_fx( { Copy_Scale_sig_16_32_no_sat( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 } - Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 +#endif Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], output_frame, sub( Q11, Q_synth_fx ) ); // Q11 IF( hBWE_FD != NULL ) @@ -1140,6 +1196,14 @@ ivas_error ivas_core_dec_fx( IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 + Copy_Scale_sig_32_16( synth_32_fx[n], synth_16_fx[n], output_frame, -( Q11 + Q2 ) ); // Q0 + Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 + Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 + + swb_CNG_dec_fx( st, synth_16_fx[n], hb_synth_16_fx[n], sid_bw[n], -Q2 ); +#else Word16 synth_fxl[960]; /* Q-2 */ Word16 q; @@ -1151,6 +1215,7 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 swb_CNG_dec_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); +#endif test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) @@ -1170,10 +1235,11 @@ ivas_error ivas_core_dec_fx( IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { Word16 q; - q = 11; + q = Q11; move16(); stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q, Q_white_exc ); + test(); test(); test(); diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 62a33352c76c4b1e00f61f8f243ea46c4559dfee..73993d99a213655b8e8e08b7937877f6a7ad88af 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -358,6 +358,7 @@ ivas_error ivas_mct_dec_fx( } /* Postprocessing for ACELP/MDCT core switching and synchronization */ +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { @@ -367,7 +368,7 @@ ivas_error ivas_mct_dec_fx( { set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) ); } - +#endif Word16 Q_synth = sub( 15, e_sig[n] ); move16(); @@ -382,7 +383,11 @@ ivas_error ivas_mct_dec_fx( dirac_stereo_flag = 0; } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], hCPE->output_mem_fx[1], 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index a3feb62ff24c407342543da582dee56a38670a22..bea7d8e320a0714356d25070997ee4cec41ce075 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -188,9 +188,13 @@ void stereo_tcx_init_dec_fx( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ +#else + Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ +#endif Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ @@ -232,6 +236,9 @@ void stereo_tcx_core_dec_fx( Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 signal_out_fx[L_FRAME48k]; +#endif TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -869,7 +876,9 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 signal_out_32_fx[L_FRAME48k]; +#endif Word16 exp; Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); @@ -885,6 +894,10 @@ void stereo_tcx_core_dec_fx( } } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_16_32_DEPREC( signal_out_fx, signal_out_32_fx, st->L_frame, sub( Q11, st->Q_syn_factor ) ); +#endif + pop_wmops(); return; } diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 1845b32e4dd244574a21a025fbf7db78d3aac582..61d5b345162cb15fb9ad075e970461d11e969152 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -355,8 +355,12 @@ Word16 WB_BWE_gain_deq_fx( /* o : Q_syn_hb */ Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Decoder_State *st_fx, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ +#endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -370,6 +374,10 @@ Word16 ivas_wb_bwe_dec_fx( Word16 ysynth_fx[L_FRAME48k]; Word16 Q_syn, exp, Q_syn_hb; Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k]; +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 output[L_FRAME16k]; + Word16 Q_input, sf; +#endif Word16 scl, new_input_fx_exp; Word16 i; FD_BWE_DEC_HANDLE hBWE_FD; @@ -380,12 +388,24 @@ Word16 ivas_wb_bwe_dec_fx( hBWE_FD = st_fx->hBWE_FD; /* MDCT of the core synthesis signal */ - new_input_fx_exp = *Qpost; move16(); test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + sf = getScaleFactor32( output_fx32, st_fx->L_frame ); + + Q_input = 0; + move16(); + if ( LT_16( sf, 5 ) ) + { + Q_input = sub( sf, 5 ); + } + + Copy_Scale_sig_32_16( output_fx32, output, st_fx->L_frame, sub( Q_input, Q11 ) ); // Q_input + +#endif /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ /* IVAS_fmToDo: delay output[] by 1.25ms ? */ lerp( output, ysynth_fx, L_FRAME16k, st_fx->L_frame );