Commit f595cdd4 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Few subfuncs of decoder_tcx_nosieshaping_igf func converted to fxd

parent 4772f5fa
Loading
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -349,6 +349,21 @@ void decoder_tcx_noisefilling_fx(
    const Word16 frame_cnt /* i  : frame counter in the super frame*/
);

void decoder_tcx_noiseshaping_igf_fx(
    Decoder_State *st, /* i/o: coder memory state          */
    const Word16 L_spec,
    const Word16 L_frame,
    const Word16 L_frameTCX,
    const Word16 left_rect,
    float x[],
    Word32 *x_fx,
    Word16 *x_e,
    const Word16 gainlpc2_fx[],
    const Word16 gainlpc2_e[],
    Word16 *temp_concealment_method,
    const Word16 bfi /* i  : Bad frame indicator                 */
);

void init_tcx_info_fx(
    Decoder_State *st,            /* i/o: coder memory state                                               */
    const Word16 L_frame_glob,    /* i  : global frame length                                              */
@@ -990,7 +1005,6 @@ Word16 matrix_product_diag_fx(
    Word32 *Z,            /* o  : resulting matrix after the matrix multiplication                                       */
    Word16 *Z_e );


// ivas_stereo_mdct_core_dec_fx.c
void stereo_mdct_core_dec_fx(
    Decoder_Struct *st_ivas,                     /* i/o: IVAS decoder structure                  */
@@ -1125,5 +1139,3 @@ void FdCngDecodeDiracMDCTStereoSID_fx(
);

#endif

+15 −0
Original line number Diff line number Diff line
@@ -3633,6 +3633,14 @@ void mdct_shaping_16(
  Word16 gains_max_exp, Word32 y[]
);

void mdct_noiseShaping_ivas_fx(
    Word32 x_fx[],
    Word16 *x_e,
    const Word16 lg,
    const Word16 gains_fx[],
    const Word16 gains_exp[]
);

void mdct_noiseShaping_interp(
  Word32 x[],
  const Word16 lg,
@@ -5501,6 +5509,13 @@ void TonalMDCTConceal_Apply(
#endif
   );

void TonalMDCTConceal_Apply_ivas_fx(
    TonalMDCTConcealPtr hTonalMDCTConc, /*IN */
    Word32 *mdctSpectrum,            /*IN/OUT*/
    Word16 *mdctSpectrum_exp,           /*IN */
    const PsychoacousticParameters *psychParamsCurrent
);

/* Conceals the lost frame using the FD signal previously stored using
 * TonalMDCTConceal_SaveFreqSignal.  Stores the concealed noise part of
 * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */
+91 −0
Original line number Diff line number Diff line
@@ -1144,6 +1144,97 @@ void mdct_shaping_16(
    }
}

void mdct_noiseShaping_ivas_fx(
    Word32 x_fx[],
    Word16 *x_e,
    const Word16 lg, 
    const Word16 gains_fx[], 
    const Word16 gains_exp[]
    /*const Word16 nBands*/  /*Parameter added in IVAS, but always equal to FDNS_NPTS */
)
{
    Word16 i, j, k, l;
    Word16 m, n, k1, k2;

    j = 0;
    /* FDNS_NPTS = 64 */
    k = shr(lg, 6);
    m = s_and(lg, 0x3F);

    Word16 max_e = MIN16B;
    FOR(i = 0; i < FDNS_NPTS; i++)
    {
        max_e = s_max(max_e, add(*x_e, gains_exp[i]));
    }

    IF(m != 0)
    {
        IF(LE_16(m, FDNS_NPTS / 2))
        {
            n = idiv1616U(FDNS_NPTS, m);
            k1 = k;
            move16();
            k2 = add(k, 1);
        }
        ELSE
        {
            n = idiv1616U(FDNS_NPTS,sub(FDNS_NPTS,m));
            k1 = add(k,1);
            k2 = k;
            move16();
        }

        i = 0;
        move16();
        j = 0;
        move16();

        WHILE(LT_16(i, lg))
        {
            IF ( j % n != 0 )
            {
                k = k1;
                move16();
            }
            ELSE
            {
                k = k2;
                move16();
            }

            /* Limit number of loops, if end is reached */
            k = s_min(k, sub(lg, i));

            FOR(l = 0; l < k; l++)
            {
                x_fx[i] = Mpy_32_16_1(x_fx[i], gains_fx[j]);
                x_fx[i] = L_shr(x_fx[i], sub(max_e, add(*x_e, gains_exp[j])));
                i = add(i, 1);
            }
            j = add(j, 1);
        }
    }
    ELSE
    {
        FOR ( i = 0; i < lg; )
        {
            FOR ( l = 0; l < k; l++ )
            {
                x_fx[i] = Mpy_32_16_1(x_fx[i], gains_fx[j]);
                x_fx[i] = L_shr(x_fx[i], sub(max_e, add(*x_e, gains_exp[j])));
                i = add(i, 1);
            }
            j = add(j, 1);
        }
    }

    *x_e = max_e;
    move16();

    return;
}


void mdct_noiseShaping_interp(
    Word32 x[], 
    const Word16 lg, 
+197 −1
Original line number Diff line number Diff line
@@ -2664,7 +2664,11 @@ void decoder_tcx_fx(
    decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt );
#endif

#ifdef IVAS_FLOAT_FIXED
    decoder_tcx_noiseshaping_igf_fx( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], x_fx, &x_e, gainlpc2_fx, gainlpc2_e, &tmp_concealment_method, bfi );
#else
    decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi );
#endif

    decoder_tcx_tns( st, L_frame_glob, L_spec, L_frame, L_frameTCX, &x[0], fUseTns, &tnsData, bfi, frame_cnt, 0 );

@@ -3212,7 +3216,7 @@ void decoder_tcx_invQ_fx(
}

/*-------------------------------------------------------------------*
 *  decoder_tcx_noisefilling_fx()
 *  decoder_tcx_noisefilling()
 *
 *  TCX: core noise filling, IGF updates
 *-------------------------------------------------------------------*/
@@ -3604,3 +3608,195 @@ void decoder_tcx_noisefilling_fx(

    return;
}

/*-------------------------------------------------------------------*
 * decoder_tcx_noiseshaping_igf_fx()
 *
 * TCX: FDNS and IGF application
 *-------------------------------------------------------------------*/

void decoder_tcx_noiseshaping_igf_fx(
    Decoder_State *st, /* i/o: coder memory state          */
    const Word16 L_spec,
    const Word16 L_frame,
    const Word16 L_frameTCX,
    const Word16 left_rect,
    float x[],
    Word32 *x_fx,
    Word16 *x_e,
    const Word16 gainlpc2_fx[],
    const Word16 gainlpc2_e[],
    Word16 *temp_concealment_method,
    const Word16 bfi /* i  : Bad frame indicator                 */
)
{
    TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
    Word16 i;

    /*-----------------------------------------------------------*
     * Noise shaping in frequency domain (1/Wz)                  *
     *-----------------------------------------------------------*/

    test();
    test();
    test();
    IF ( st->igf && ( !bfi || ( EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->prev_bfi ) ) )
    {
        test();
        IF ( ( EQ_16(L_frame, shr(st->L_frame, 1) ) ) && ( st->tcxonly ) )
        {
            IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x_fx, *x_e, IGF_GRID_LB_SHORT );
        }
        ELSE
        {
            IF (EQ_16(st->last_core, ACELP_CORE))
            {
                IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x_fx, *x_e, IGF_GRID_LB_TRAN );
            }
            ELSE
            {
                IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x_fx, *x_e, IGF_GRID_LB_NORM );
            }
        }
    }
    /* LPC gains already available */

    test();
    test();
    test();
    test();
    test();
    IF(gainlpc2_fx && gainlpc2_e && NE_16(st->element_mode, IVAS_CPE_MDCT) && (!st->enablePlcWaveadjust || !bfi || (EQ_16(*temp_concealment_method, TCX_TONAL))))
    {
        Word16 spec_side_x_e, frame_side_x_e;

        spec_side_x_e = *x_e;
        move16();

        mdct_noiseShaping_ivas_fx(x_fx, x_e, L_frame, gainlpc2_fx, gainlpc2_e);

        frame_side_x_e = *x_e;
        move16();

        IF(bfi == 0)
        {
            FOR (i = L_frame; i < L_spec; i++)
            {
                x_fx[i] = Mpy_32_16_1(x_fx[i], gainlpc2_fx[FDNS_NPTS - 1]);
                move32();
            }
            spec_side_x_e = add(spec_side_x_e, gainlpc2_e[FDNS_NPTS-1]);
        }

        IF (LT_16(spec_side_x_e, frame_side_x_e))
        {
            /* If the exponent on the spec side (i>L_frame) is lesser, then shift all the values in the
            spec side by the difference to make both sides have the same exponent. */
            FOR (i = L_frame; i < L_spec; i++)
            {
                x_fx[i] = L_shr(x_fx[i], sub(frame_side_x_e, spec_side_x_e));
                move32();
            }
        }
        ELSE IF (GT_16(spec_side_x_e, frame_side_x_e))
        {
            /* If the exponent on the spec side (i>L_frame) is greater, then shift all the values in the
            frame side (i<L_frame) by the difference to make both sides have the same exponent. */
            FOR (i = 0; i < L_frame; i++)
            {
                x_fx[i] = L_shr(x_fx[i], sub(spec_side_x_e, frame_side_x_e));
                move32();
            }
        }
        *x_e = s_max(spec_side_x_e, frame_side_x_e);

        set32_fx(x_fx + L_spec, 0, sub(L_frameTCX, L_spec));

    }
    me2f_buf(x_fx, *x_e, x, L_frameTCX);

    /* PLC: [TCX: Tonal Concealment] */
    test();
    test();
    IF ( bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT) )
    {
#if 1
        // Float to fixed
        IF(!st->hTonalMDCTConc->lastBlockData.blockIsConcealed && st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0)
        {
            st->hTonalMDCTConc->nFramesLost = float_to_fix16(st->hTonalMDCTConc->nFramesLost_float, Q1);
        }
        FOR (i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++)
        {
            float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i];
            if (pd >= PI2)
                pd = fmodf(pd, PI2) - PI2;
            st->hTonalMDCTConc->pTCI_fix->phaseDiff[i] = float_to_fix16(pd, Q12);
        }
        FOR (i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++)
        {
            float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i];
            pd = fmodf(pd, PI2);
            st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13));
        }
        FOR(i = 0; i < FDNS_NPTS; i++)
        {
            f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]);
            st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]);
        }

        TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx, x_e, st->hTcxCfg->psychParamsCurrent );

        // Fix to float
        FOR(i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++)
        {
            FOR(Word16 l = st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI_float->upperIndex[i]; l++)
            {
                x[l] = me2f(x_fx[l], *x_e);
            }
        }
        st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1);
#else
        TonalMDCTConceal_Apply_ivas( st->hTonalMDCTConc, x, st->hTcxCfg->psychParamsCurrent );
#endif
    }

    if ( st->hTonalMDCTConc != NULL && st->element_mode != IVAS_CPE_MDCT )
    {
        TonalMDCTConceal_UpdateState_ivas( st->hTonalMDCTConc, L_frameTCX, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, bfi, bfi && st->tonal_mdct_plc_active );
    }

    if ( st->enablePlcWaveadjust )
    {
        /* spectrum concealment */
        if ( bfi && *temp_concealment_method == TCX_NONTONAL )
        {
            concealment_decode( st->core, x, st->hPlcInfo );
        }

        /* update spectrum buffer, tonality flag, etc. */
        concealment_update( bfi, st->core, st->tonality_flag, x, st->hPlcInfo );
    }

    /*-----------------------------------------------------------*
     * IGF                                                       *
     *-----------------------------------------------------------*/

    if ( st->igf && !( ( L_frame == st->L_frame >> 1 ) && st->tcxonly ) )
    {
        if ( st->element_mode != IVAS_CPE_MDCT )
        {
            IGFDecApplyMono_flt( st->hIGFDec, x, ( st->last_core == ACELP_CORE || ( left_rect && bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, bfi, st->element_mode );
        }
    }

    if ( st->igf && ( ( L_frame == st->L_frame >> 1 ) && st->tcxonly ) )
    {
        if ( st->element_mode != IVAS_CPE_MDCT )
        {
            IGFDecApplyMono_flt( st->hIGFDec, x, IGF_GRID_LB_SHORT, bfi, st->element_mode );
        }
    }

    return;
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -2007,7 +2007,7 @@ void IGFDecCopyLPCFlatSpectrum_fx(
        /* TODO: remove float dependency */
        for ( i = hGrid->minSrcSubband - IGF_MID_WHITENING_LEVEL2; i < hGrid->startLine; i++ )
        {
            hPrivateData->pSpecFlat_float[i] = fix_to_float( hPrivateData->pSpecFlat[i], 31 - hPrivateData->pSpecFlat_exp ) * 1024.f;
            hPrivateData->pSpecFlat_float[i] = me2f( hPrivateData->pSpecFlat[i], hPrivateData->pSpecFlat_exp );
        }
    }
}
Loading