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

Merge branch 'dec_tcx_changes' into 'main'

dec_tcx and fd_cng changes

See merge request !26
parents 5c0b7809 29d13627
Loading
Loading
Loading
Loading
Loading
+178 −0
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@

#include <stdint.h>
#include <assert.h>
#include <math.h>
#include "options.h"
#include "prot.h"
#include "prot_fx2.h"
#include "prot_fx1.h"
#include "basop_util.h"
@@ -215,6 +217,182 @@ void tcxFormantEnhancement(

}

void tcxFormantEnhancement_with_shift(
    Word16 xn_buf[],
    Word16 *xn_buf_e_out,
    const Word16 gainlpc[],
    const Word16 gainlpc_e[],
    Word32 spectrum[],
    Word16 *spectrum_e,
    const Word16 L_frame,
    const Word16 L_frameTCX )
{
    Word16 i, j, k, l, n;
    Word16 fac, fac0, fac1, fac_e, d, tmp;
    Word16 xn_buf_e, xn_one, m, e;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
#endif

    k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */
    l = 0;
    move16();

    /* get exponent */
    xn_buf_e = 0;
    move16();
    FOR( i = 0; i < FDNS_NPTS; i++ )
    {
        xn_buf_e = s_max( xn_buf_e, gainlpc_e[i] );
    }
    xn_buf_e = shr( add( xn_buf_e, 1 ), 1 );    /* max exponent after sqrt */
    xn_one = shr( 0x4000, sub( xn_buf_e, 1 ) ); /* 1.0 scaled to xn_buf_e */

    /* Formant enhancement via square root of the LPC gains */
    e = gainlpc_e[0];
    move16();
    m = Sqrt16( gainlpc[0], &e );
    xn_buf[0] = shl( m, sub( e, xn_buf_e ) );
    move16();

    e = gainlpc_e[1];
    move16();
    m = Sqrt16( gainlpc[1], &e );
    xn_buf[1] = shl( m, sub( e, xn_buf_e ) );
    move16();

    fac0 = s_min( xn_buf[0], xn_buf[1] );
    fac_e = xn_buf_e;
    move16();
    fac0 = Inv16( fac0, &fac_e );

    FOR( i = 1; i < FDNS_NPTS - 1; i++ )
    {
        e = gainlpc_e[i + 1];
        move16();
        m = Sqrt16( gainlpc[i + 1], &e );
        xn_buf[i + 1] = shl( m, sub( e, xn_buf_e ) );
        move16();

        test();
        IF( ( LE_16( xn_buf[i - 1], xn_buf[i] ) ) && ( LE_16( xn_buf[i + 1], xn_buf[i] ) ) )
        {
            m = s_max( xn_buf[i - 1], xn_buf[i + 1] );
            e = xn_buf_e;
            move16();
            m = Inv16( m, &e );

            fac1 = m;
            move16();
            tmp = sub( e, fac_e );

            IF( GT_16( tmp, 0 ) )
            {
                fac0 = shr( fac0, tmp );
            }
            IF ( LT_16( tmp, 0 ) )
            {
                fac1 = shl( fac1, tmp );
            }

            IF ( GT_16( tmp, 0 ) )
            {
                fac_e = e;
                move16();
            }

            d = sub( fac1, fac0 );
            n = sub( i, l );
            assert( n <= 64 );

            xn_buf[l] = xn_one;
            move16();
            FOR( j = 1; j < n; j++ )
            {
                fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) );
                BASOP_SATURATE_WARNING_OFF_EVS;
#ifdef BASOP_NOGLOB
                xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) );
#else
                xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) );
#endif
                move16();
                BASOP_SATURATE_WARNING_ON_EVS;
            }

            l = i;
            move16();

            fac0 = m;
            move16();
            fac_e = e;
            move16();
        }
    }
    /* i = FDNS_NPTS - 1; Completing changes to gains */
    m = s_min( xn_buf[i - 1], xn_buf[i] );
    e = xn_buf_e;
    move16();
    m = Inv16( m, &e );

    fac1 = m;
    move16();
    tmp = sub( e, fac_e );

    if ( tmp > 0 )
        fac0 = shr( fac0, tmp );
    if ( tmp < 0 )
        fac1 = shl( fac1, tmp );

    if ( tmp > 0 )
    {
        fac_e = e;
        move16();
    }

    d = sub( fac1, fac0 );
    n = sub( i, l );
    assert( n <= 64 );

    xn_buf[l] = xn_one;
    move16();
    FOR( j = 1; j < n; j++ )
    {
        fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) );
        BASOP_SATURATE_WARNING_OFF_EVS;
        xn_buf[l + j] = s_min( xn_one, shl( mult( xn_buf[l + j], fac ), fac_e ) );
        move16();
        BASOP_SATURATE_WARNING_ON_EVS;
    }

    xn_buf[i] = xn_one;
    move16();

    /* Application of changed gains onto decoded MDCT lines */
    FOR( i = 0; i < L_frame; i += k )
    {
        FOR( l = 0; l < k; l++ )
        {
            *spectrum = Mpy_32_16_1( *spectrum, *xn_buf );
            move32();
            spectrum++;
        }
        xn_buf++;
    }

    tmp = sub( L_frameTCX, L_frame );
    FOR( i = 0; i < tmp; i++ )
    {
        spectrum[i] = L_shr( spectrum[i], xn_buf_e );
        move32();
    }
    *spectrum_e = add( *spectrum_e, xn_buf_e );
    move16();

    *xn_buf_e_out = xn_buf_e;
    move16();
}

void tcxInvertWindowGrouping(
	TCX_CONFIG_HANDLE hTcxCfg, /* i  : configuration of TCX               */
	Word32 xn_buf[],
+41 −0
Original line number Diff line number Diff line
@@ -157,4 +157,45 @@ void ECSQ_init_instance_fx(
    const Word16 config_index,
    void *ac_handle );

void decoder_tcx_invQ_fx(
    Decoder_State *st, /* i/o: coder memory state                      */
    Word16 prm[],      /* i  : parameters                              */
    Word16 A[],        /* i  : coefficients NxAz[M+1]                  */
    Word16 Aind[],     /* i  : frame-independent coefficients Az[M+1]  */
    const Word16 L_spec,
    const Word16 L_frame,
    const Word16 L_frameTCX,
    Word32 x_fx[],
    Word16 *x_e,
    Word16 gainlpc2[],
    Word16 gainlpc2_e[],
    Word16 xn_buf[], /* Q14 */
    Word16 *fUseTns, /* o  : flag that is set if TNS data is present */
    STnsData *tnsData,
    Word16 *gain_tcx,
    Word16 *gain_tcx_e,
    const Word16 **prm_sqQ1,
    Word16 *nf_seed,
    const Word16 bfi,      /* i  : Bad frame indicator                     */
    const Word16 frame_cnt /* i  : frame counter in the super frame        */
);

void init_tcx_info_fx(
    Decoder_State *st,            /* i/o: coder memory state                                               */
    const Word16 L_frame_glob,    /* i  : global frame length                                              */
    const Word16 L_frameTCX_glob, /* i  : FB global frame length                                           */
    const Word16 frame_cnt,       /* i  : frame counter in the super_frame                                 */
    const Word16 bfi,             /* i  : bad frame indicator                                              */
    Word16 *tcx_offset,           /* o  : folding point offset relative to the end of the previous frame   */
    Word16 *tcx_offsetFB,         /* o  : FB folding point offset relative to the end of the previous frame*/
    Word16 *L_frame,              /* o  : frame length                                                     */
    Word16 *L_frameTCX,           /* o  : TCX frame length                                                 */
    Word16 *left_rect,            /* o  : left part is rectangular                                         */
    Word16 *L_spec                /* o  : spectrum length                                                  */
);

void IGFDecReplicateTCX10State_fx(
    IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder          */
);

#endif
 No newline at end of file
+50 −0
Original line number Diff line number Diff line
@@ -178,6 +178,56 @@ void SetParameters(
    return;
}

void SetParameters_fx(
    ParamsBitMap const *paramsBitMap,
    const Word16 nArrayLength,
    void *pParameter,
    const Word16 **pStream,
    Word16 *pnSize )
{
    Word16 index;
    Word16 iParam, nParams;
    Word16 value;
    void *pSubStruct;
    void *pTmp;
    assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
    nParams = paramsBitMap->nParams;

    FOR( index = 0; index < nArrayLength; index++ )
    {
        FOR( iParam = 0; iParam < nParams; iParam++ )
        {
            ParamBitMap const *param;
            /* If a function for encoding/decoding value is defined than it should take care of 0 */

            move16();
            param = &paramsBitMap->params[iParam];

            move16();
            value = 1;
            if ( s_or( param->fZeroAllowed != 0, param->EncodeValue != NULL ) )
            {
                move16();
                value = 0;
            }
            value = add( value, *( *pStream )++ );

#define WMC_TOOL_SKIP
            pSubStruct = param->SetParamValue( pParameter, index, value );
#undef WMC_TOOL_SKIP
            move16();
            *pnSize = add( *pnSize, 1 );

            IF( s_and( param->pSubParamBitMap != NULL, value > 0 ) )
            {
                pTmp = pParameter;
                if ( pSubStruct != NULL )
                    pTmp = pSubStruct;
                SetParameters( param->pSubParamBitMap, value, pTmp, pStream, pnSize );
            }
        }
    }
}

void WriteToBitstream(
    ParamsBitMap const *paramsBitMap,
+74 −0
Original line number Diff line number Diff line
@@ -60,6 +60,17 @@
#define TCX_IMDCT_SCALE 15
#define TCX_IMDCT_HEADROOM 1

/* conversion functions: */

// Float to Word32
Word32 float_to_fix( float number, Word32 Q );
// Word32 to Float
float fix_to_float( Word32 number, Word32 Q );
// Float to Word16
Word16 float_to_fix16( float number, Word16 Q );
// Word16 to Float
float fix16_to_float( Word16 number, Word16 Q );

Word32 Mult_32_16(
	Word32 a,
	Word16 b);
@@ -3183,6 +3194,16 @@ void tcxFormantEnhancement(
	const Word16 L_frameTCX
);

void tcxFormantEnhancement_with_shift(
    Word16 xn_buf[],
    Word16 *xn_buf_e,
    const Word16 gainlpc[],
    const Word16 gainlpc_e[],
    Word32 spectrum[],
    Word16 *spectrum_e,
    const Word16 L_frame,
    const Word16 L_frameTCX );

void tcxInvertWindowGrouping(
	TCX_CONFIG_HANDLE hTcxCfg, /* i  : configuration of TCX               */
	Word32 xn_buf[],
@@ -3466,6 +3487,15 @@ void lpc2mdct(
  const Word16 noInverse
);

void lpc2mdct_2(
    Word16 *lpcCoeffs,
    const int16_t lpcOrder,
    Word16 mdct_gains_fx[],
    Word16 mdct_gains_e[],
    Word16 mdct_inv_gains_fx[],
    Word16 mdct_inv_gains_e[],
    const int16_t length );

void mdct_shaping(
  Word32 x[],
  const Word16 lg,
@@ -7138,6 +7168,12 @@ Word16 DecodeTnsData(STnsConfig const * pTnsConfig,
  Word16 * pnSize,
  STnsData * pTnsData);

Word16 DecodeTnsData_ivas_fx(
    STnsConfig const *pTnsConfig,
    Word16 const *stream,
    Word16 *pnSize,
    STnsData *pTnsData );

//parametr_bitmapping.c using ivas
void GetParameters(
  ParamsBitMap const *paramsBitMap,
@@ -7154,6 +7190,13 @@ void SetParameters(
  const int16_t **pStream,
  int16_t *pnSize);

void SetParameters_fx(
    ParamsBitMap const *paramsBitMap,
    const Word16 nArrayLength,
    void *pParameter,
    const Word16 **pStream,
    Word16 *pnSize );

void WriteToBitstream(
  ParamsBitMap const *paramsBitMap,
  const int16_t nParams,
@@ -7203,12 +7246,25 @@ void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance,
  const Word16                                   igfGridIdx          /**< in:     | IGF grid index                 */
);

void IGFDecUpdateInfo_fx(
    const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder      */
    const Word16 subFrameIdx,              /* i  : subframe index                      */
    const Word16 igfGridIdx                /* i  : IGF grid index                      */
);

void IGFDecCopyLPCFlatSpectrum(const IGF_DEC_INSTANCE_HANDLE         hInstance,          /**< in:     | instance handle of IGF Decoder     */
  const Word32                         *pSpectrumFlat,      /**< in: Q31 | LPC flattend spectrum from TCX dec */
  const Word16                          pSpectrumFlat_exp,  /**< in:     | exponent of pSpectrumFlat          */
  const Word16                          igfGridIdx          /**< in: Q0  | IGF grid index                     */
);

void IGFDecCopyLPCFlatSpectrum_fx(
    const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in:     | instance handle of IGF Decoder     */
    const Word32 *pSpectrumFlat,             /**< in: Q31 | LPC flattend spectrum from TCX dec */
    const Word16 pSpectrumFlat_exp,          /**< in:     | exponent of pSpectrumFlat          */
    const Word16 igfGridIdx                  /**< in: Q0  | IGF grid index                     */
);

void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE      hInstance,          /**< in:     | instance handle of IGF Decoder */
  const Word16                       subFrameIdx         /**< in: Q0  | index of subframe              */
);
@@ -7217,6 +7273,12 @@ void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance,
  const Word16                     subFrameIdx         /**< in: Q0  | index of subframe              */
);

void IGFDecRestoreTCX10SubFrameData_fx(
    const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* o  : instance handle of IGF Decoder      */
    const Word16 subFrameIdx               /* i  : index of subframe                   */
);


void init_igf_dec(
  IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle      */
);
@@ -7460,6 +7522,18 @@ void decoder_tcx(
  Word16 stab_fac      /* i  : stability of isf             */
);

void decoder_tcx_fx(
    Decoder_State *st,
    Word16 prm[],
    float A[],
    Word16 Aind[],
    float synth[],
    float synthFB[],
    const Word16 bfi,
    const Word16 frame_cnt,
    const Word16 sba_dirac_stereo_flag
);

void decoder_tcx_post(Decoder_State *st_fx,
  Word16 *synth,
  Word16 *synthFB,
+150 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include "rom_com.h"
#include "rom_basop_util.h"
#include "basop_util.h"
#include "prot.h"

#define inv_int InvIntTable

@@ -831,6 +832,155 @@ void lpc2mdct(
        }
    }
}

void lpc2mdct_2(
    Word16 *lpcCoeffs,
    const Word16 lpcOrder,
    Word16 mdct_gains_fx[],
    Word16 mdct_gains_e[],
    Word16 mdct_inv_gains_fx[],
    Word16 mdct_inv_gains_e[],
    const Word16 length )
{
    Word16 i, sizeN, j, k, step, scale, s, tmp16;
    Word16 g, g_e, ig, ig_e;
    Word32 tmp32;
    Word32 RealData_fx[2 * FDNS_NPTS], ImagData_fx[2 * FDNS_NPTS];
    const PWord16 *ptwiddle;

    assert( length <= FDNS_NPTS );
    sizeN = shl( length, 1 );

    BASOP_getTables( NULL, &ptwiddle, &step, sizeN );

    /* ODFT */
    FOR ( i = 0; i < lpcOrder + 1; i++ )
    {
        RealData_fx[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re );
        ImagData_fx[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) );
        ptwiddle += step;
    }

    FOR ( ; i < sizeN; i++ )
    {
        RealData_fx[i] = L_deposit_l( 0 );
        ImagData_fx[i] = L_deposit_l( 0 );
    }

    /* half length FFT */
    scale = add( norm_s( lpcCoeffs[0] ), 1 );
    BASOP_cfft_ivas( RealData_fx, ImagData_fx, 1, &scale );

    /*Get amplitude*/
    j = FDNS_NPTS - 1;
    k = 0;
    move16();

    FOR( i = 0; i < FDNS_NPTS / 2; i++ )
    {
        s = sub( norm_l( L_max( L_abs( RealData_fx[i] ), L_abs( ImagData_fx[i] ) ) ), 1 );

        tmp16 = extract_h( L_shl( RealData_fx[i], s ) );
        tmp32 = L_mult( tmp16, tmp16 );

        tmp16 = extract_h( L_shl( ImagData_fx[i], s ) );
        tmp16 = mac_r( tmp32, tmp16, tmp16 );

        s = shl( sub( scale, s ), 1 );

        if ( tmp16 == 0 )
        {
            s = -16;
            move16();
        }
        if ( tmp16 == 0 )
        {
            tmp16 = 1;
            move16();
        }

        BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e );

        if ( mdct_gains_fx != NULL )
        {
            mdct_gains_fx[k] = g;
            move16();
        }

        if ( mdct_gains_e != NULL )
        {
            mdct_gains_e[k] = g_e;
            move16();
        }

        if ( mdct_inv_gains_fx != NULL )
        {
            mdct_inv_gains_fx[k] = ig;
            move16();
        }

        if ( mdct_inv_gains_e != NULL )
        {
            mdct_inv_gains_e[k] = ig_e;
            move16();
        }

        k = add( k, 1 );


        s = sub( norm_l( L_max( L_abs( RealData_fx[j] ), L_abs( ImagData_fx[j] ) ) ), 1 );

        tmp16 = extract_h( L_shl( RealData_fx[j], s ) );
        tmp32 = L_mult( tmp16, tmp16 );

        tmp16 = extract_h( L_shl( ImagData_fx[j], s ) );
        tmp16 = mac_r( tmp32, tmp16, tmp16 );

        s = shl( sub( scale, s ), 1 );

        if ( tmp16 == 0 )
        {
            s = -16;
            move16();
        }
        if ( tmp16 == 0 )
        {
            tmp16 = 1;
            move16();
        }

        BASOP_Util_Sqrt_InvSqrt_MantExp( tmp16, s, &g, &g_e, &ig, &ig_e );

        if ( mdct_gains_fx != NULL )
        {
            mdct_gains_fx[k] = g;
            move16();
        }

        if ( mdct_gains_e != NULL )
        {
            mdct_gains_e[k] = g_e;
            move16();
        }

        if ( mdct_inv_gains_fx != NULL )
        {
            mdct_inv_gains_fx[k] = ig;
            move16();
        }

        if ( mdct_inv_gains_e != NULL )
        {
            mdct_inv_gains_e[k] = ig_e;
            move16();
        }

        j = sub( j, 1 );
        k = add( k, 1 );
    }

    return;
}
/**
 * \brief Perform mdct shaping. In the floating point software there are two functions,
 *        mdct_noiseShaping and mdct_preShaping, which are combined here into a single function.
Loading