Commit bfd0340d authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow

parent 4707ded0
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@
#define FIX_1785_ASSERT_IN_IVAS_JBM_DEC_RENDER_FX            /* Orange: 10ms Rendering: Assert in ivas_jbm_dec_render_fx() -> scale_sig32 */
#define FIX_2081_REVISE_H1_SCALING                           /* VA: accommodate for H1 overshoot that was causing assert in set_impule. Not BE with MASA on LTV with bitrate switching for only 2 instances */
#define TEMP_FIX_2088_MSAN_INIT_ERROR                        /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */

#define FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE                /* FhG: Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow */
/* ################### End FIXES switches ########################### */

/* #################### Start BASOP porting switches ############################ */
+11 −0
Original line number Diff line number Diff line
@@ -4073,8 +4073,19 @@ void decoder_tcx_ivas_fx(
                          fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag );

    /* Scaling up again */
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    Word16 scf_min = s_min( getScaleFactor16( synth_fx, L_frame_glob ), getScaleFactor16( synthFB_fx, L_frameTCX_glob ) );
    Word16 q_min = add( s_min( q_win, q_winFB ), scf_min );
    q_min = s_min( q_min, st->Q_syn );
    scale_sig( synth_fx, L_frame_glob, sub( q_min, q_win ) );
    scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_min, q_winFB ) );
    st->Q_syn_factor = sub( q_min, st->Q_syn );
    st->Q_syn = q_min;
#else
    Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) );
    Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_winFB ) );
#endif

    // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 );

    Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2
+8 −1
Original line number Diff line number Diff line
@@ -597,8 +597,11 @@ ivas_error ivas_core_dec_fx(
            }

            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 );

#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
            Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11
#else
            Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, Q11 ); // Q11
#endif

            IF( st->hTcxDec )
            {
@@ -805,7 +808,11 @@ ivas_error ivas_core_dec_fx(
         *---------------------------------------------------------------------*/

        /*core_switching_post_dec*/
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor );
#else
        Q_synth = sub( 15, e_sig[0] );
#endif

        /*------------------fix-to-fix-end-----------------------*/

+12 −2
Original line number Diff line number Diff line
@@ -309,7 +309,10 @@ void stereo_tcx_core_dec_fx(
    set16_fx( synth_fx, 0, L_FRAME_PLUS + M );
#endif
    set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M );

#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    st->Q_syn_factor = 0;
    move16();
#endif
    /*--------------------------------------------------------------------------------*
     * BITSTREAM DECODING
     *--------------------------------------------------------------------------------*/
@@ -670,10 +673,17 @@ void stereo_tcx_core_dec_fx(
#endif
        IF( !bfi && st->hTonalMDCTConc != NULL )
        {
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
            TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, st->Q_syn_factor, hTcxDec->L_frameTCX );
#else
            TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, 0, hTcxDec->L_frameTCX );
#endif
        }

#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, st->Q_syn_factor, Aq_fx, bfi, 0 );
#else
        decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 );
#endif

        IF( EQ_16( st->core, TCX_20_CORE ) )
        {
+4 −0
Original line number Diff line number Diff line
@@ -1310,7 +1310,11 @@ typedef struct Decoder_State
    Word16 Q_syn;
    Word16 Q_syn2;
    Word16 Q_syn_cng;
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    Word16 Q_syn_factor; // This q_factor is used to avoid using fix Q0 for synth[] at the output of con_tcx_ivas_fx() and ivas_core_dec_fx(). For con_tcx_ivas_fx, it is used for two consecutive TCX concealment processes and It cannot be greater than 0.
#else
    Word16 Q_syn_factor; // This q_factor is used to avoid using fixed Q0 for synth[] at the output of con_tcx_ivas_fx(). It is then used for two consecutive TCX concealment processes. It cannot be greater than 0.
#endif
    Word16 prev_Q_syn;
    Word16 prev_Q_bwe_exc;