Commit c305ac69 authored by multrus's avatar multrus
Browse files

Merge branch 'basop-2604-harmonize-decoder_tcx_post' into 'main'

Resolve "Harmonize decoder_tcx_post"

See merge request !3048
parents d994d87b 83c6b41f
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define HARMONIZE_2567_init_functions                   /* FhG: harmonize derivates for evs/ivas regarding functions init_acelp*(),init_tcx_cfg*(), init_tcx*(), init_coder_ace_plus*(), init_core_sig_ana*() and init_modes*() */
#define HARMONIZE_2607_GetFilterParameters              /* FhG: Harmonize GetFilterParameters with its ivas derivate */
#define HAMRONIZE_2606_ENC_PRM                          /* FhG: Harmonize enc_prm_fx(), to match floating-point code */
#define HARMONIZE_2604_decoder_tcx_post                 /* FhG: Harmonize decoder_tcx_post with its ivas derivate */

/* #################### End BE switches ################################## */

+19 −8
Original line number Diff line number Diff line
@@ -8000,12 +8000,14 @@ void decoder_tcx_ivas_fx(
    const Word16 frame_cnt,
    const Word16 sba_dirac_stereo_flag );

#ifndef HARMONIZE_2604_decoder_tcx_post
void decoder_tcx_post_fx(
    Decoder_State *st_fx,
    Word16 *synth,
    Word16 *synthFB,
    Word16 *A,
    Word16 bfi );
#endif

void tcx_arith_decode_envelope_fx(
    Word32 q_spectrum[],  /* o: quantised MDCT coefficients     Q31-e */
@@ -8429,14 +8431,23 @@ UWord32 mvl2s_r(
    const Word16 n /* i  : vector size   */
);

void decoder_tcx_post_ivas_fx(
    Decoder_State *st_fx,
    Word16 *synth,
    Word16 *synthFB,
#ifdef HARMONIZE_2604_decoder_tcx_post
void decoder_tcx_post_fx( Decoder_State *st_fx,
                          Word16 *synth,   // Q_syn
                          Word16 *synthFB, // Q_syn
                          Word16 Q_syn,
    Word16 *A,
                          Word16 *A, // Q: 14 - norm_s(A[0])
                          Word16 bfi,
                          Word16 MCT_flag );
#else
void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                               Word16 *synth,   // Q_syn
                               Word16 *synthFB, // Q_syn
                               Word16 Q_syn,
                               Word16 *A, // Q: 14 - norm_s(A[0])
                               Word16 bfi,
                               Word16 MCT_flag );
#endif

void con_tcx_fx(
    Decoder_State *st,      /* i/o: coder memory state          */
+4 −0
Original line number Diff line number Diff line
@@ -770,7 +770,11 @@ void decoder_LPD_fx(
        {
            TonalMDCTConceal_SaveTimeSignal_fx( st->element_mode, st->hTonalMDCTConc, synthFB, 0, L_frameTCX );
        }
#ifdef HARMONIZE_2604_decoder_tcx_post
        decoder_tcx_post_fx( st, synth, synthFB, 0, Aq, bfi, 0 );
#else
        decoder_tcx_post_fx( st, synth, synthFB, Aq, bfi );
#endif
        IF( EQ_16( st->core, TCX_20_CORE ) )
        {
            /* LPC Interpolation for BWE/post-processing */
+202 −65
Original line number Diff line number Diff line
@@ -1256,7 +1256,7 @@ void decoder_tcx_fx(
    Copy( xn_bufFB + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synthFB, L_frameTCX_glob );
}


#ifndef HARMONIZE_2604_decoder_tcx_post
void decoder_tcx_post_fx( Decoder_State *st_fx,
                          Word16 *synth,
                          Word16 *synthFB,
@@ -1517,7 +1517,17 @@ void decoder_tcx_post_fx( Decoder_State *st_fx,
        move16();
    }
}
#endif /*HARMONIZE_2604_decoder_tcx_post*/

#ifdef HARMONIZE_2604_decoder_tcx_post
void decoder_tcx_post_fx( Decoder_State *st_fx,
                          Word16 *synth,   // Q_syn
                          Word16 *synthFB, // Q_syn
                          Word16 Q_syn,
                          Word16 *A, // Q: 14 - norm_s(A[0])
                          Word16 bfi,
                          Word16 MCT_flag ) /*EVS: 0*/
#else
void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                               Word16 *synth,   // Q_syn
                               Word16 *synthFB, // Q_syn
@@ -1525,6 +1535,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                               Word16 *A, // Q: 14 - norm_s(A[0])
                               Word16 bfi,
                               Word16 MCT_flag )
#endif
{
    Word16 i;
    Word16 level_syn;
@@ -1536,6 +1547,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
    Word16 tmp1, tmp2, s;
    Word32 tmp32;
    Word32 tmp32_1, tmp32_2;
#ifdef HARMONIZE_2604_decoder_tcx_post
    Word16 tcxltp_last_gain_unmodified_tmp;
#endif
    TCX_DEC_HANDLE hTcxDec;

    hTcxDec = st_fx->hTcxDec;
@@ -1641,6 +1655,32 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        Word16 Qnew_levelBackgroundTrace;
        Qnew_levelBackgroundTrace = 0;
        move16();
#ifdef HARMONIZE_2604_decoder_tcx_post
        Word16 *NoiseLevelIndex_tmp, *CurrLevelIndex_tmp;
        IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
        {
            NoiseLevelIndex_tmp = &hTcxDec->conNoiseLevelIndex;
            CurrLevelIndex_tmp = &hTcxDec->conCurrLevelIndex;
        }
        ELSE
        {
            NoiseLevelIndex_tmp = &hTcxDec->NoiseLevelIndex_bfi;
            CurrLevelIndex_tmp = &hTcxDec->CurrLevelIndex_bfi;
        }

        minimumStatistics_fx( hTcxDec->conNoiseLevelMemory,         /*Q15*/
                              NoiseLevelIndex_tmp,                  /*Q0 */
                              CurrLevelIndex_tmp,                   /*Q0 */
                              &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/
                              &hTcxDec->conLastFrameLevel,          /*Q15*/
                              level_syn,                            /*Q15*/
                              hTcxDec->conNoiseLevelMemory_e,
                              hTcxDec->conCngLevelBackgroundTrace_e,
                              &Qnew_levelBackgroundTrace,
                              &hTcxDec->conLastFrameLevel_e,
                              level_syn_e /*scaling of level_syn*/
        );
#else
        minimumStatistics_fx( hTcxDec->conNoiseLevelMemory,         /*Q15*/
                              &hTcxDec->NoiseLevelIndex_bfi,        /*Q0 */
                              &hTcxDec->CurrLevelIndex_bfi,         /*Q0 */
@@ -1653,6 +1693,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                              &hTcxDec->conLastFrameLevel_e,
                              level_syn_e /*scaling of level_syn*/
        );
#endif

        /*note: All parameters being different from Q0 have to have the same Q-format*/

@@ -1664,6 +1705,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
     * PLC: fade-out in time domain */
    IF( bfi != 0 )
    {
#ifdef HARMONIZE_2604_decoder_tcx_post
        Word32 conceal_eof_gain32;
#endif
        Word32 conceal_eof_gainFB;
        Word16 conceal_eof_gainFB_e;
        move16();
@@ -1673,6 +1717,10 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        IF( st_fx->tcxonly != 0 )
        {
            /*gainCNG = st_fx->conCngLevelBackgroundTrace/(tracingLevel+0.01f);*/
#ifdef HARMONIZE_2604_decoder_tcx_post
            IF( GT_16( st_fx->element_mode, EVS_MONO ) )
            {
#endif
                IF( level_syn )
                {
                    level_syn_e = BASOP_Util_Add_MantExp( level_syn, level_syn_e, 20992, -6, &level_syn ); /* 0.01 in Q21*/
@@ -1684,6 +1732,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                    move16();
                    move16();
                }
#ifdef HARMONIZE_2604_decoder_tcx_post
            }
#endif

            IF( level_syn != 0 )
            {
@@ -1714,6 +1765,10 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
        ELSE
        {
            /*gainCNG = st_fx->cngTDLevel/(tracingLevel+0.01f);*/
#ifdef HARMONIZE_2604_decoder_tcx_post
            IF( GT_16( st_fx->element_mode, EVS_MONO ) )
            {
#endif
                IF( level_syn )
                {
                    level_syn_e = BASOP_Util_Add_MantExp( level_syn, level_syn_e, 20992, -6, &level_syn ); /* 0.01 in Q21*/
@@ -1725,6 +1780,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                    move16();
                    move16();
                }
#ifdef HARMONIZE_2604_decoder_tcx_post
            }
#endif

            IF( level_syn != 0 )
            {
@@ -1738,6 +1796,70 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
            }
        }


#ifdef HARMONIZE_2604_decoder_tcx_post
        IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
        {
            IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) )
            {
                hTcxDec->conceal_eof_gain = 16384 /*1.0f Q14*/; /*Q14*/
                move16();
            }

            /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame; */
            tmp2 = BASOP_Util_Add_MantExp(
                mult_r( hTcxDec->conceal_eof_gain /*Q14*/,
                        hTcxDec->damping /*Q14*/ ),
                15 - 13 /*->Q15*/,
                mult_r( gainCNG /*Q15*/, sub( 0x4000, hTcxDec->damping /*Q14*/ ) ) /*Q14*/,
                add( gainCNG_e, 15 - 14 ) /*->Q15*/,
                &tmp1 );
            tmp2 = BASOP_Util_Add_MantExp( hTcxDec->conceal_eof_gain, 15 - 14, negate( tmp1 ), tmp2, &tmp1 );

            step = L_shl_sat( L_mult( tmp1, getInvFrameLen( st_fx->L_frame ) ), sub( tmp2, 6 /*scaling from table lookup*/ + 1 /*go to Q30*/ ) ); /*Q30*/
            {
                Word32 stepFB;
                UWord32 dmy;
                conceal_eof_gainFB = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/
                Mpy_32_32_ss( step, L_shl( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ), &stepFB, &dmy );
                stepFB = L_shl_sat( stepFB, 3 - 1 ); /*Q30*/
                FOR( i = 0; i < hTcxDec->L_frameTCX; i++ )
                {
                    synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), 1 ) );
                    move16();
                    conceal_eof_gainFB = L_sub_sat( conceal_eof_gainFB, stepFB );
                }
            }
            conceal_eof_gain32 = L_deposit_h( hTcxDec->conceal_eof_gain ); /*Q30*/
            FOR( i = 0; i < st_fx->L_frame; i++ )
            {
                xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gain32 /*Q30*/, xn_buf[i] ), 1 ) );
                move16();
                conceal_eof_gain32 = L_sub_sat( conceal_eof_gain32, step );
            }
            hTcxDec->conceal_eof_gain = round_fx_sat( conceal_eof_gain32 ); /*Q14*/
            move16();
            /* run lpc gain compensation not for waveform adjustment */
            test();
            IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->hPlcInfo->concealment_method, TCX_TONAL ) )
            {
                st_fx->hPlcInfo->recovery_gain = extract_h( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB,
                                                                                    st_fx->last_concealed_gain_syn_deemph ),
                                                                       st_fx->last_concealed_gain_syn_deemph_e ) );
                /*Q30->Q14*/
                move16();
            }
            ELSE
            {
                st_fx->hPlcInfo->recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/
                move16();
            }
            st_fx->hPlcInfo->step_concealgain_fx = round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/
            move16();
        }
        ELSE
        {
#endif
            IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) )
            {
                hTcxDec->conceal_eof_gain32 = ONE_IN_Q30 /*1.0f Q30*/;
@@ -1803,6 +1925,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
                st_fx->hPlcInfo->step_concealgain_fx = round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( L_shr_sat( step, sub( 1, step_e ) ) ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 4 ) ); /*Q15*/
                move16();
            }
#ifdef HARMONIZE_2604_decoder_tcx_post
        }
#endif
    }

    /*-----------------------------------------------------------*
@@ -1834,11 +1959,23 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx,
    st_fx->mem_pitch_gain[st_fx->nb_subfr * 2] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; // Q14
    move16();

#ifdef HARMONIZE_2604_decoder_tcx_post
    tcxltp_last_gain_unmodified_tmp = hTcxDec->tcxltp_last_gain_unmodified;
    if ( GT_16( st_fx->element_mode, EVS_MONO ) )
    {
        tcxltp_last_gain_unmodified_tmp = shr( tcxltp_last_gain_unmodified_tmp, 1 );
    }
#endif

    FOR( i = 0; i < st_fx->nb_subfr; i++ )
    {
        st_fx->mem_pitch_gain[( st_fx->nb_subfr * 2 - 1 ) - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; // Q14
        move16();
#ifdef HARMONIZE_2604_decoder_tcx_post
        st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = tcxltp_last_gain_unmodified_tmp; /* Q14 */
#else
        st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */
#endif
        move16();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1259,7 +1259,11 @@ void ivas_mdct_core_reconstruct_fx(
            {
                TonalMDCTConceal_SaveTimeSignal_fx( st->element_mode, st->hTonalMDCTConc, synthFB_fx, q_winFB, L_frameTCX[ch] );
            }
#ifdef HARMONIZE_2604_decoder_tcx_post
            decoder_tcx_post_fx( st, synth_fx, synthFB_fx, q_winFB, NULL, bfi, MCT_flag );
#else
            decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, q_winFB, NULL, bfi, MCT_flag );
#endif

            // norm(synth_buf) >= q_syn - q_win
            // norm(synth_buf) + q_win >= q_syn
Loading