Commit b5caf21f authored by Manuel Jander's avatar Manuel Jander
Browse files

Avoid fixed format Q15 for sts[0]->input32_fx to avoid overflow from issue...

Avoid fixed format Q15 for sts[0]->input32_fx to avoid overflow from issue #2206. Apparently also fixes #2205 crash. Put on your helmet, regressions may income.
parent 921d8b38
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -58,7 +58,11 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val
    Word16 i, a;
    Word16 y;

#ifdef NONBE_FIX_ISSUE_2206
    if ( L_x <= 1 )
#else
    if ( L_x <= 0 )
#endif
        L_x = L_deposit_h( 0x4000 );

    L_x = L_shr( L_x, 9 );
+2 −0
Original line number Diff line number Diff line
@@ -161,6 +161,8 @@
#define FIX_2193_ISM_GAINS_WITH_OE                      /* FhG: fix issue 2193: use edited angles in ISM gain calculation */
#define FIX_2192_OBJ_EDITING_EXT_METADATA               /* Eri: Add support for extended metadata in object editing */

#define NONBE_FIX_ISSUE_2206

/* #################### End BASOP porting switches ############################ */

#endif
+4 −0
Original line number Diff line number Diff line
@@ -545,13 +545,17 @@ ivas_error pre_proc_front_ivas_fx(
        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 ) );
#ifndef NONBE_FIX_ISSUE_2206
        scale_sig( st->input_fx - input_frame, input_frame_full, sub( Q_inp_const, st->q_inp ) );
#endif
        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) */
#ifndef NONBE_FIX_ISSUE_2206
        st->q_inp = Q_inp_const;
        move16();
        st->q_old_inp = Q_inp_const;
        move16();
#endif
    }
    IF( NE_16( Q_inp_const, st->q_inp ) )
    {
+38 −0
Original line number Diff line number Diff line
@@ -826,7 +826,40 @@ ivas_error ivas_cpe_enc_fx(
        move16();

        stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL );
#ifdef NONBE_FIX_ISSUE_2206
        // Normalise the input buffer
        Word16 Qs0, Qs1, Qs2, Qs3, Qold2, Qnew2;
        assert( out_start_ind <= 0 && out_end_ind >= 0 );
        Qs0 = L_norm_arr( sts[0]->input32_fx - input_frame, add( input_frame, out_start_ind ) );
        Qs1 = L_norm_arr( sts[0]->input32_fx + out_start_ind, sub( 0, out_start_ind ) );
        Qs2 = L_norm_arr( sts[0]->input32_fx, out_end_ind );
        Qs3 = L_norm_arr( sts[0]->input32_fx + out_end_ind, sub( input_frame, out_end_ind ) );
        Qold2 = s_min( add( sts[0]->q_old_inp32, Qs0 ), add( Q15, Qs1) );
        Qnew2 = s_min( add( Q15, Qs2 ), add( sts[0]->q_inp32, Qs3 ) );
#if 1
        /* Somewhere else sts[0]->q_old_inp32 needs to be the same as sts[0]->q_inp32 */
        Qnew2 = s_min( Qnew2, Qold2 );
        Qold2 = Qnew2;
        move16();
#endif
        scale_sig32( sts[0]->input32_fx - input_frame,  add( input_frame, out_start_ind ), sub( Qold2, sts[0]->q_old_inp32 ) );
        scale_sig32( sts[0]->input32_fx + out_start_ind, sub( 0, out_start_ind ), sub( Qold2, Q15 ) );
        scale_sig32( sts[0]->input32_fx, out_end_ind, sub( Qnew2, Q15 ) );
        scale_sig32( sts[0]->input32_fx + out_end_ind, sub( input_frame, out_end_ind ), sub( Qnew2, sts[0]->q_inp32 ) );
        sts[0]->q_old_inp32 = Qold2;
        sts[0]->q_inp32 = Qnew2;
        move16();
        move16();

        // Copy the old input, input and FIR delay section of input buffer to 16 bit
        Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, shl( input_frame, 1 ), 0 );

        // Update the Q-factors
        sts[0]->q_inp = sub( sts[0]->q_inp32, Q16 );
        move16();
        sts[0]->q_old_inp = sub( sts[0]->q_old_inp32, Q16 );
        move16();
#else
        scale_sig32( sts[0]->input32_fx - input_frame, add( out_start_ind, input_frame ), sub( Q15, sts[0]->q_old_inp32 ) ); // scaling initial part of the input buffer
        scale_sig32( sts[0]->input32_fx + out_end_ind, sub( input_frame, out_end_ind ), sub( Q15, sts[0]->q_inp32 ) );       // scaling initial part of the input buffer
        sts[0]->q_inp32 = Q15;
@@ -847,6 +880,7 @@ ivas_error ivas_cpe_enc_fx(
        move16();
        sts[0]->q_old_inp = q_inp;
        move16();
#endif

        /* iDFT & resampling to 12.8kHz internal sampling rate */
        stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_inp_12k8_fx[0] + L_INP_MEM, &out_12k8_start_ind[0], &out_12k8_end_ind[0], 0, input_Fs, INT_FS_12k8, 0, NULL );
@@ -855,7 +889,11 @@ ivas_error ivas_cpe_enc_fx(
        /* iDFT & resampling to 16kHz internal sampling rate for M channel */
        IF( EQ_32( input_Fs, internal_Fs ) )
        {
#ifdef NONBE_FIX_ISSUE_2206
            Copy_Scale_sig32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, add( input_frame, STEREO_DFT_OVL_16k ), sub( Q15, sts[0]->q_inp32 ) ); /* sts[0]->q_inp32 */
#else
            Copy32( sts[0]->input32_fx - STEREO_DFT_OVL_16k, old_inp_16k_fx[0] + L_INP_MEM - STEREO_DFT_OVL_16k, add( input_frame, STEREO_DFT_OVL_16k ) ); /* sts[0]->q_inp32 */
#endif
            out_16k_start_ind = -STEREO_DFT_OVL_16k;
            out_16k_end_ind = add( out_16k_start_ind, add( input_frame, STEREO_DFT_OVL_16k ) );
            move16();