Commit 6a11f5d1 authored by Nicolas Roussin's avatar Nicolas Roussin
Browse files

Merge branch 'main' into 2142-implement-basop-w_min-and-w_max-functions

parents 0134533b e18c9336
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ target_link_libraries(ISAR_post_rend lib_basop lib_isar lib_util lib_com)
target_include_directories(ISAR_post_rend PRIVATE lib_basop lib_isar)

add_executable(ambi_converter apps/ambi_converter.c)
target_link_libraries(ambi_converter lib_util lib_com lib_basop)
target_link_libraries(ambi_converter lib_util lib_com lib_basop lib_debug)
if(UNIX)
  target_link_libraries(ambi_converter m)
endif()
+2 −0
Original line number Diff line number Diff line
@@ -83,7 +83,9 @@
#define FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT            /* Nokia: Issue 2164: Prevent overflow when calculating equalization coefficient for editing before clamping to safe range */
#define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC                   /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */
#define OPT_2146_BASOP_UTIL_ADD_MANT32EXP                    /* Dlb: optimized version of BASOP_Util_Add_Mant32Exp() */
#define FIX_2166_ASSERT_OSBA_PLC_STEREO_OUT                  /* FhG: fix for issue 2166 - add missing averaging factor 0.5 in for the sum of energies in function stereo_dft_dmx_swb_nrg_fx()*/

#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 ############################ */
+3 −0
Original line number Diff line number Diff line
@@ -9101,6 +9101,9 @@ void decoder_tcx_ivas_fx(
    Word16 Aind[],
    Word16 synth_fx[],
    Word16 synthFB_fx[],
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    Word16 *synth_q,
#endif
    const Word16 bfi,
    const Word16 frame_cnt,
    const Word16 sba_dirac_stereo_flag );
+20 −3
Original line number Diff line number Diff line
@@ -3972,8 +3972,14 @@ void decoder_tcx_ivas_fx(
    Word16 prm[],
    Word16 A_fx[], // Q: 14 - norm_s(A_fx[0])
    Word16 Aind[], // Q: 14 - norm_s(Aind[0])
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    Word16 synth_fx[],
    Word16 synthFB_fx[],
    Word16 *synth_q,
#else
    Word16 synth_fx[],   // Q_syn
    Word16 synthFB_fx[], // Q_syn
#endif
    const Word16 bfi,
    const Word16 frame_cnt,
    const Word16 sba_dirac_stereo_flag )
@@ -4063,8 +4069,9 @@ void decoder_tcx_ivas_fx(
    move16();
    q_winFB = st->Q_syn;
    move16();

#ifndef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    assert( q_win == 0 );
#endif

    Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) );        // Scaling to Q_syn
    Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_winFB, st->Q_syn ) ); // Scaling to Q_syn
@@ -4073,8 +4080,18 @@ 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 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ),
                          add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) );
    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 ) );
    *synth_q = 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
+53 −2
Original line number Diff line number Diff line
@@ -105,7 +105,11 @@ void con_tcx_fx(
    Word16 pre_emph_buf;
    Word16 hp_filt[L_FIR_FER2];
    Word16 alpha;
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    Word16 tmp_deemph, gain, gainCNG, gain_inov, scf;
#else
    Word16 tmp_deemph, gain, gainCNG, gain_inov;
#endif
    Word16 *pt_exc, *pt1_exc;
    Word16 Tc, tmpSeed;
    Word16 fUseExtrapolatedPitch;
@@ -190,9 +194,16 @@ void con_tcx_fx(
    IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc )
    {
        /* apply pre-emphasis to the signal */
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        mem = shl( synth[( -( ( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/
#else
        mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/
#endif
        move16();
        Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
#endif
        st->Mode2_lp_gainc = L_deposit_l( 0 );

        st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/
@@ -231,9 +242,16 @@ void con_tcx_fx(
    ELSE
    {
        /* apply pre-emphasis to the signal */
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/
#else
        mem = synth[( -L_frame - 1 )];                                                    /*Q0*/
#endif
        move16();
        Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
        Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
#endif
        Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/

        offset = shr( L_frame, 1 );
@@ -766,9 +784,26 @@ void con_tcx_fx(

    syn = buf + M;             /*Q_syn*/
    Copy( synth - M, buf, M ); /*Q_syn*/
#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness
    {
        scf = norm_s( tmp_deemph );
        new_Q = sub( Q_exc, 4 );
        new_Q = s_max( new_Q, -1 );
        new_Q = s_min( new_Q, scf );
    }
    ELSE
    {
        new_Q = sub( Q_exc, 3 );
        new_Q = s_max( new_Q, -1 );

        scf = 0;
        move16();
    }
#else
    new_Q = sub( Q_exc, 3 );
    new_Q = s_max( new_Q, -1 );
#endif

    tmp16 = s_min( new_Q, st->prev_Q_syn );
    st->prev_Q_syn = new_Q;
@@ -779,8 +814,24 @@ void con_tcx_fx(
    move16();

    Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/

#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE
    IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness
    {
        if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) )
        {
            Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf;
        }
        tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
    }
    ELSE
    {
        tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/
    }
    st->Q_syn_factor = 0;
    move16();
#else
    tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/
#endif
    st->Q_syn = Q_syn;
    move16();

Loading