Commit 94fd13cb authored by vaclav's avatar vaclav
Browse files

Merge branch 'basop-2347-remove-various-duplicated-code-in-core-decoder' into 'main'

Remove various duplicated code in core-coder

Closes #2347

See merge request !2734
parents f4115b1a ea15f288
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@
#define FIX_BASOP_2329_UNINIT_VALUE                     /* Nokia: basop issue 2329: Fix issue by checking for structure instead of length */
#define FIX_BASOP_2332_ASAN_OVERFLOW_IN_EXT_DIRAC_REND  /* Nokia: basop issue 2332: Uses predefined memory sizes instead computing wrong */
#define FIX_BASOP_2333_MCMASA_ANA_MEMORY_LEAK           /* Nokia: basop issue 2333: Add missing free for direction_vector_e to ivas_mcmasa_ana_fx.c */
#define HARM_COREDECODER_FUNCTIONS                      /* VA: basop issue 2347: Remove various duplicated code in core-decoder  */

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

+12 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ static Word16 PutIntoBitstream_fx(

    return value;
}
#ifndef HARM_COREDECODER_FUNCTIONS
static Word16 PutIntoBitstream_ivas_fx(
    const Word16 **pStream,
    TEncodeValue EncodeValue,
@@ -43,6 +44,7 @@ static Word16 PutIntoBitstream_ivas_fx(

    return value;
}
#endif

static Word16 FixedWidthEncoding( Word16 value, Word16 index )
{
@@ -252,6 +254,8 @@ void SetParameters_fx(
            }
        }
    }

    return;
}


@@ -266,13 +270,11 @@ void WriteToBitstream_fx(
    Word16 index;
    Word16 iParam, nParams;


    assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
    nParams = paramsBitMap->nParams;

    FOR( index = 0; index < nArrayLength; index++ )
    {

        FOR( iParam = 0; iParam < nParams; iParam++ )
        {
            ParamBitMap const *param;
@@ -321,7 +323,11 @@ void WriteToBitstream_fx(
            }
        }
    }

    return;
}

#ifndef HARM_COREDECODER_FUNCTIONS
void WriteToBitstream_ivas_fx(
    ParamsBitMap const *paramsBitMap,
    const Word16 nArrayLength,
@@ -389,6 +395,7 @@ void WriteToBitstream_ivas_fx(
        }
    }
}
#endif

/** Get nBits long value from bitstream into *pStream. */
static Word16 GetFromBitstream(
@@ -457,6 +464,9 @@ void ReadFromBitstream_fx(
            }
        }
    }

    move16();
    *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) );

    return;
}
+10 −4
Original line number Diff line number Diff line
@@ -6189,10 +6189,11 @@ void concealment_init_x(
    const Word16 L_frameTCX,
    T_PLCInfo_HANDLE hPlcInfo );
#ifdef HARM_COREDECODER_FUNCTIONS
void concealment_init_ivas_fx(
    const Word16 L_frameTCX,
    T_PLCInfo_HANDLE hPlcInfo );
#endif
void concealment_update_x(
    const Word16 bfi,
    const Word16 core,
@@ -6572,6 +6573,7 @@ void formant_post_filt_fx(
    const Word16 off_flag  /* i  : off flag                          */
);
#ifndef HARM_COREDECODER_FUNCTIONS
void Filt_mu_fx(
    Word16 *sig_in,  /* i  : signal (beginning at sample -1)     */
    Word16 *sig_out, /* o  : signal with tilt                    */
@@ -6585,7 +6587,7 @@ void Filt_mu_ivas_fx(
    Word16 parcor0,  /* i  : parcor0 (mu = parcor0 * gamma3)     */
    Word16 L_subfr,  /* i  : the length of subframe              */
    const Word16 extl );
#endif
void scale_st_fx(
    const Word16 *sig_in, /* i  : postfilter i signal             */
    Word16 *sig_out,      /* i/o: postfilter o signal             */
@@ -6772,6 +6774,7 @@ void gain_dec_tc_fx(
    Word32 *norm_gain_code_fx /* o  : norm. gain of the codebook excit.   */
);
#ifndef HARM_COREDECODER_FUNCTIONS
void gain_dec_tc_ivas_fx(
    Decoder_State *st_fx,     /* i/o: decoder state structure */
    const Word16 *code_fx,    /* i  : algebraic code excitation           */
@@ -6782,7 +6785,7 @@ void gain_dec_tc_ivas_fx(
    Word16 *gain_inov_fx,     /* o  : unscaled innovation gain            */
    Word32 *norm_gain_code_fx /* o  : norm. gain of the codebook excit.   */
);
#endif
void gain_dec_mless_fx(
    Decoder_State *st_fx,     /* i/o: decoder state structure                   */
    const Word16 L_frame_fx,  /* i  : length of the frame                       */
@@ -8784,12 +8787,14 @@ Word16 dlpc_avq_fx(
    Word32 sr_core );
Word16 decode_lpc_avq_fx(
#ifndef HARM_COREDECODER_FUNCTIONS
    Decoder_State *st,   /* i/o: decoder state structure     */
    const Word16 numlpc, /* i  : Number of sets of lpc       */
    Word16 *param_lpc    /* o  : lpc parameters              */
);
Word16 decode_lpc_avq_ivas_fx(
#endif
    Decoder_State *st,           /* i/o: decoder state structure     */
    const Word16 numlpc,         /* i  : Number of sets of lpc       */
    Word16 *param_lpc,           /* o  : lpc parameters              */
@@ -10874,6 +10879,7 @@ void WriteToBitstream_fx(
    BSTR_ENC_HANDLE hBstr,
    Word16 *pnBits );
#ifndef HARM_COREDECODER_FUNCTIONS
void WriteToBitstream_ivas_fx(
    ParamsBitMap const *paramsBitMap,
    const Word16 nArrayLength,
@@ -10881,7 +10887,7 @@ void WriteToBitstream_ivas_fx(
    Word16 *pnSize,
    BSTR_ENC_HANDLE hBstr,
    Word16 *pnBits );
#endif
/*===========================================================================================*/
/*----------------------------------------------------------------------------------*
+4 −0
Original line number Diff line number Diff line
@@ -1978,7 +1978,11 @@ void open_decoder_LPD_ivas_fx(

        IF( st->hTcxDec != NULL && ( st->ini_frame == 0 || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) )
        {
#ifdef HARM_COREDECODER_FUNCTIONS
            concealment_init_x( st->hTcxDec->L_frameTCX, st->hPlcInfo );
#else
            concealment_init_ivas_fx( st->hTcxDec->L_frameTCX, st->hPlcInfo );
#endif
        }
    }
    ELSE
+68 −51
Original line number Diff line number Diff line
@@ -35,7 +35,11 @@ static void modify_pst_param_fx( const Word16 lp_noise, Word16 *g1, Word16 *g2,

static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 );

#ifdef HARM_COREDECODER_FUNCTIONS
static void Filt_mu_fx( Word16 *sig_in, Word16 *sig_out, Word16 parcor0, Word16 L_subfr );
#else
static void calc_st_filt_ivas_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero, const Word16 extl );
#endif


/*--------------------------------------------------------------------------
@@ -72,11 +76,13 @@ void Init_post_filter_fx(
    return;
}


/*--------------------------------------------------------------------------
 *  NB_post_filt:
 *
 *  Main routine to perform post filtering on NB synthesis
 *--------------------------------------------------------------------------*/

void nb_post_filt_fx(
    const Word16 L_frame,    /* i  : frame length                            */
    PFSTAT_HANDLE hPFstat,   /* i : core decoder parameters                  */
@@ -132,7 +138,6 @@ void nb_post_filt_fx(
        move16();
    }


    /* run the post filter */
    p_Aq = Aq; // Q12
    move16();
@@ -148,10 +153,10 @@ void nb_post_filt_fx(
        j = add( j, 1 );
    }


    return;
}


/*----------------------------------------------------------------------------
 * Dec_postfilt()
 *
@@ -175,6 +180,7 @@ void nb_post_filt_fx(
 *       1. search around 1st subframe delay (3 integer values)
 *       2. search around best integer with fract. delays (1/8)
 *----------------------------------------------------------------------------*/

static void Dec_postfilt_fx(
    PFSTAT_HANDLE hPFstat,    /* i : core decoder parameters */
    const Word16 t0,          /* i  : pitch delay given by coder Q0                   */
@@ -191,14 +197,11 @@ static void Dec_postfilt_fx(
    Word16 apond2[LONG_H_ST];    // Q12
    Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal  */
    Word16 res2[SIZ_RES2];       // Q0

    Word16 *sig_ltp_ptr;
    Word16 *res2_ptr;
    Word16 *ptr_mem_stp;

    Word16 parcor0; // Q15


    /* Init pointers and restore memories */
    res2_ptr = res2 + DECMEM_RES2;
    ptr_mem_stp = hPFstat->mem_stp + L_SYN_MEM - 1;
@@ -244,10 +247,10 @@ static void Dec_postfilt_fx(
    /* Update for next subframe */
    Copy( &res2[L_SUBFR], hPFstat->mem_res2, DECMEM_RES2 );


    return;
}


/*--------------------------------------------------------------------------
 *  formant_post_filt_fx:
 *
@@ -445,7 +448,11 @@ static void Dec_formant_postfilt_fx(
    }

    /* Controls short term pst filter gain and compute parcor0 */
#ifdef HARM_COREDECODER_FUNCTIONS
    calc_st_filt_local_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero );
#else
    calc_st_filt_ivas_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero, -1 );
#endif

    /* 1/A(gamma1) filtering, mem_stp is updated */
    resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) );
@@ -463,7 +470,12 @@ static void Dec_formant_postfilt_fx(
    }

    /* Tilt filtering */
#ifdef HARM_COREDECODER_FUNCTIONS
    Filt_mu_fx( resynth, sig_out, parcor0, L_SUBFR );
#else
    Filt_mu_ivas_fx( resynth, sig_out, parcor0, L_SUBFR, -1 );
#endif

    IF( scale_down )
    {
        Scale_sig( sig_out, L_SUBFR, 1 );
@@ -472,10 +484,10 @@ static void Dec_formant_postfilt_fx(
    /* Gain control */
    scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR );


    return;
}


/*------------------------------------------------------------------------------------
 * modify_pst_param()
 *
@@ -494,7 +506,6 @@ static void modify_pst_param_fx(
    Word16 lp_noiseQ12;
    Word32 L_tmp;


    test();
    IF( NE_16( coder_type, INACTIVE ) && LT_16( lp_noise, LP_NOISE_THR_FX ) )
    {
@@ -534,15 +545,16 @@ static void modify_pst_param_fx(

    *gain_factor = extract_h( L_shl( L_tmp, 7 ) ); /* Q24=>Q31=>Q15 */


    return;
}


/*----------------------------------------------------------------------------
 * pst_ltp_fx
 *
 * Perform harmonic postfilter
 *----------------------------------------------------------------------------*/

static void pst_ltp_fx(
    Word16 t0,            /* i  : pitch delay given by coder Q0       */
    Word16 *ptr_sig_in,   /* i  : postfilter i  filter (residu2) Qx   */
@@ -570,7 +582,6 @@ static void pst_ltp_fx(
    Word16 off_yup;
    Word16 nb_sh_sig;


    /* i  signal justified on 13 bits */
    ptr_sig = ptr_sig_in - DECMEM_RES2; // Qx
    nb_sh_sig = getScaleFactor16( ptr_sig, DECMEM_RES2 + L_SUBFR );
@@ -587,7 +598,6 @@ static void pst_ltp_fx(
    /* Sub optimal delay search */
    search_del_fx( t0, ptr_sig_cadr, &ltpdel, &phase, &num_gltp, &den_gltp, &sh_num, &sh_den, y_up, &off_yup );


    IF( num_gltp == 0 )
    {
        Copy( ptr_sig_in, ptr_sig_pst0, L_SUBFR );
@@ -603,7 +613,6 @@ static void pst_ltp_fx(
            /* Filtering with long filter */
            compute_ltp_l_fx( ptr_sig_cadr, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, &sh_num2, &sh_den2 );


            IF( EQ_16( select_ltp_fx( num_gltp, den_gltp, sh_num, sh_den, num2_gltp, den2_gltp, sh_num2, sh_den2 ), 1 ) )
            {
                /* select short filter */
@@ -672,13 +681,17 @@ static void pst_ltp_fx(
        /** filtering by H0(z) = harmonic filter **/
        filt_plt_fx( ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt );
    }

    return;
}


/*----------------------------------------------------------------------------
 * search_del_fx:
 *
 * Computes best (shortest) integer LTP delay + fine search
 *---------------------------------------------------------------------------*/

static void search_del_fx(
    Word16 t0,           /* i  : pitch delay given by coder Q0     */
    Word16 *ptr_sig_in,  /* i  : i  signal (with delay line)       */
@@ -715,7 +728,6 @@ static void search_del_fx(
    Word16 i_max, lambda, phi, phi_max, ioff;
    Word16 temp;


    /*-------------------------------------
     * Computes energy of current signal
     *-------------------------------------*/
@@ -747,6 +759,7 @@ static void search_del_fx(
     * Selects best of 3 integer delays
     * Maximum of 3 numerators around t0
     *-------------------------------------*/

    lambda = sub( t0, 1 );
    ptr_sig_past = ptr_sig_in - lambda;
    L_num_int = L_deposit_l( -1 );
@@ -947,7 +960,6 @@ static void search_del_fx(
    ptr_L_den1 = L_den1;
    ptr_y_up = y_up;


    /* if den_max = 0 : will be selected and declared unvoiced */
    /* if num!=0 & den=0 : will be selected and declared unvoiced */
    /* degenerated seldom cases, switch off LT is OK */
@@ -1025,6 +1037,7 @@ static void search_del_fx(
    /*---------------------------------------------------
     * test if normalized crit0[iopt] > THRESHCRIT
     *--------------------------------------------------*/

    test();
    IF( num_max == 0 || LE_16( den_max, 1 ) )
    {
@@ -1093,15 +1106,16 @@ static void search_del_fx(
        move16();
    }


    return;
}


/*----------------------------------------------------------------------------
 *  filt_plt_fx:
 *
 * Perform long term postfilter
 *----------------------------------------------------------------------------*/

static void filt_plt_fx(
    Word16 *s_in,   /* i  : i  signal with past Qx        */
    Word16 *s_ltp,  /* i  : filtered signal with gain 1 Qx*/
@@ -1109,14 +1123,11 @@ static void filt_plt_fx(
    Word16 gain_plt /* i  : filter gain Q15               */
)
{

    /* Local variables */
    Word32 L_acc;

    Word16 n;
    Word16 gain_plt_1;


    gain_plt_1 = sub( 32767, gain_plt ); // Q15
    gain_plt_1 = add( gain_plt_1, 1 );   /* 2**15 (1 - g) */

@@ -1128,7 +1139,6 @@ static void filt_plt_fx(
        move16();                                        /* no overflow */
    }


    return;
}

@@ -1139,6 +1149,7 @@ static void filt_plt_fx(
 * compute delayed signal, num & den of gain for fractional delay
 * with long interpolation filter
 *----------------------------------------------------------------------------*/

static void compute_ltp_l_fx(
    Word16 *s_in,   /* i/o: signal with past            */
    Word16 ltpdel,  /* i  : delay factor                */
@@ -1214,10 +1225,10 @@ static void compute_ltp_l_fx(
    move16();
    move16();


    return;
}


/*----------------------------------------------------------------------------
 *  select_ltp_fx:
 *
@@ -1225,7 +1236,8 @@ static void compute_ltp_l_fx(
 *  with gain1 = num1 * 2** sh_num1 / den1 * 2** sh_den1
 *  and  gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2
 *----------------------------------------------------------------------------*/
static Word16 select_ltp_fx(                 /* o  : 1 = 1st gain, 2 = 2nd gain  */
/* o  : 1 = 1st gain, 2 = 2nd gain  */
static Word16 select_ltp_fx(
    Word16 num1,    /* i  : numerator of gain1 Q(sh_num1)          */
    Word16 den1,    /* i  : denominator of gain1 Q(sh_den1)       */
    Word16 sh_num1, /* i  : just. factor for num1       */
@@ -1238,10 +1250,8 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain
{
    Word32 L_temp1, L_temp2;
    Word32 L_temp;

    Word16 temp1, temp2;


    IF( den2 == 0 )
    {
        return 1;
@@ -1283,6 +1293,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain
    return temp1;
}


/*----------------------------------------------------------------------------
 * calc_st_filt_local_fx
 *
@@ -1290,6 +1301,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain
 * controls gain : computation of energy impulse response as
 *                 SUMn  (abs (h[n])) and computes parcor0
 *---------------------------------------------------------------------------- */

static void calc_st_filt_local_fx(
    Word16 *apond2,      /* i  : coefficients of numerator Q12            */
    Word16 *apond1,      /* i  : coefficients of denominator Q12          */
@@ -1299,13 +1311,10 @@ static void calc_st_filt_local_fx(
)
{
    Word32 L_g0;

    Word16 h[LONG_H_ST];

    Word16 g0, temp;
    Word16 i;


    temp = sub( 2, norm_s( apond2[0] ) );

    /* compute i.r. of composed filter apond2 / apond1 */
@@ -1333,10 +1342,10 @@ static void calc_st_filt_local_fx(
        }
    }


    return;
}

#ifndef HARM_COREDECODER_FUNCTIONS
static void calc_st_filt_ivas_fx(
    Word16 *apond2,      /* i  : coefficients of numerator Q12             */
    Word16 *apond1,      /* i  : coefficients of denominator Q12          */
@@ -1391,13 +1400,20 @@ static void calc_st_filt_ivas_fx(

    return;
}
#endif

/*----------------------------------------------------------------------------
 * filt_mu
 *
 * tilt filtering with : (1 + mu z-1) * (1/1-|mu|)
 *      computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1])
 *---------------------------------------------------------------------------*/

#ifdef HARM_COREDECODER_FUNCTIONS
static void Filt_mu_fx(
#else
void Filt_mu_fx(
#endif
    Word16 *sig_in,  /* i  : signal (beginning at sample -1)     */
    Word16 *sig_out, /* o  : signal with tilt                    */
    Word16 parcor0,  /* i  : parcor0 (mu = parcor0 * gamma3)     */
@@ -1405,14 +1421,11 @@ void Filt_mu_fx(
)
{
    Word32 L_acc, L_temp, L_fact;

    Word16 *ptrs;

    Word16 n;
    Word16 mu, mu2, ga, temp;
    Word16 fact, sh_fact;


    IF( parcor0 > 0 )
    {
        mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15
@@ -1458,10 +1471,10 @@ void Filt_mu_fx(
        BASOP_SATURATE_WARNING_ON_EVS;
    }


    return;
}

#ifndef HARM_COREDECODER_FUNCTIONS
void Filt_mu_ivas_fx(
    Word16 *sig_in,  /* i  : signal (beginning at sample -1)     */
    Word16 *sig_out, /* o  : signal with tilt                    */
@@ -1551,12 +1564,16 @@ void Filt_mu_ivas_fx(

    return;
}

#endif

/*----------------------------------------------------------------------------
 * scale_st_fx()
 *
 * control of the subframe gain
 * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out
 *---------------------------------------------------------------------------*/

void scale_st_fx(
    const Word16 *sig_in, /* i  : postfilter i signal Qx             */
    Word16 *sig_out,      /* i/o: postfilter o signal Qx             */
@@ -1564,12 +1581,11 @@ void scale_st_fx(
    Word16 L_subfr )
{
    Word32 L_acc, L_temp;

    Word16 i;
    Word16 scal_in, scal_out;
    Word16 s_g_in, s_g_out, temp, sh_g0, g0;
    Word16 gain = 0;

    move16();

    /* compute i  gain */
    L_acc = L_deposit_l( 0 );
@@ -1648,10 +1664,10 @@ void scale_st_fx(
    *gain_prec = gain;
    move16();


    return;
}


/*----------------------------------------------------------------------------
 * blend_subfr2_fx()
 *
@@ -1671,6 +1687,7 @@ void blend_subfr2_fx(
    move16();
    move16();
    move16();

    FOR( i = 0; i < L_SUBFR / 2; i++ )
    {
        sigOut[i] = mac_r_sat( L_mult_sat( fac1, sigIn1[i] ), fac2, sigIn2[i] ); // Qx
Loading