Commit 00fe242e authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'ivas_stereo_mdct_front_vad_spar_changes_enc' into 'main'

ivas_front_vad_spar() functions/sub funcs, stereo mdct stereo enc funcs

See merge request !448
parents a5964b23 e535eec7
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
 *-------------------------------------------------------------------*/

/*! r: index of next coefficient */
#ifndef IVAS_FLOAT_FIXED
int16_t get_next_coeff_mapped_ivas(
    int16_t ii[2],            /* i/o: coefficient indexes       */
    int32_t *pp,              /* o  : peak(1)/hole(0) indicator */
@@ -64,6 +65,28 @@ int16_t get_next_coeff_mapped_ivas(

    return hm_cfg->indexBuffer[*idx];
}
#else
Word16 get_next_coeff_mapped_ivas(
    Word16 ii[2],             /* i/o: coefficient indexes       */
    Word32 *pp,               /* o  : peak(1)/hole(0) indicator */
    Word16 *idx,              /* o  : index in unmapped domain  */
    CONTEXT_HM_CONFIG *hm_cfg /* i  : HM configuration          */
)
{
    UWord32 p;

    p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) );
    p >>= sub( sizeof( p ) * 8, 1 );
    *pp = p;
    move32();
    *idx = ii[p];
    move16();
    ii[p] = add( ii[p], 1 );
    move16();

    return hm_cfg->indexBuffer[*idx];
}
#endif


/*-------------------------------------------------------------------*
+1 −0
Original line number Diff line number Diff line
@@ -1919,6 +1919,7 @@ typedef enum _DCTTYPE
#define N_SMC_MIXTURES                      6                       /* number of mixtures */
#define N_PCA_COEF                          12                      /* number of PCA components */
#define SMC_ST_MEAN_FACT                    0.5                     /* forgetting factor of short-term IIR mean filter */
#define SMC_ST_MEAN_RSHIFT_FACT_FX            1                     /* SMC_ST_MEAN_FACT equivalent right shift factor */

#define M_LSP_SPMUS                         6                       /* number of LSPs used in speech/music classifier */
#define NB_BANDS_SPMUS                      15
+53 −7
Original line number Diff line number Diff line
@@ -720,7 +720,27 @@ int16_t ivas_smc_gmm(
    int16_t *high_lpn_flag,                                     /* i/o: sp/mus LPN flag                                 */
    const int16_t flag_spitch                                   /* i  : flag to indicate very short stable pitch        */
);

#ifdef IVAS_FLOAT_FIXED
/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */
Word16 ivas_smc_gmm_fx(
    Encoder_State *st,                    /* i/o: state structure                                     */
    STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure                         */
    const Word16 localVAD_HE_SAD,         /* i  : HE-SAD flag without hangover                        */
    const Word16 Etot_fx,                     /* i  : total frame energy                                  */
    Word16 lsp_new_fx[M],                     /* i  : LSPs in current frame   TODO:For now removing 'const'  to avoid warning                            */
    Word16 cor_map_sum_fx,                    /* i  : correlation map sum (from multi-harmonic anal.)     */
    Word32 epsP_fx[M + 1],                    /* i  : LP prediciton error TODO:For now removing 'const'  to avoid warning                                */
    Word32 PS_fx[],                           /* i  : energy spectrum    TODO:For now removing 'const'  to avoid warning                               */
    const Word16 non_sta_fx,                  /* i  : unbound non-stationarity                            */
    const Word16 relE_fx,                     /* i  : relative frame energy                               */
    Word16 *high_lpn_flag,                /* i/o: sp/mus LPN flag                                     */
    const Word16 flag_spitch              /* i  : flag to indicate very short stable pitch            */
    ,
    Word16 Qfact_PS,
    Word16 Q_esp,
    Word16 Qfact_PS_past
);
#endif
void ivas_smc_mode_selection(
    Encoder_State *st,                                          /* i/o: encoder state structure                         */
    const int32_t element_brate,                                /* i  : element bitrate                                 */
@@ -2900,11 +2920,6 @@ ivas_error initMdctItdHandling(
    const int32_t input_Fs                                      /* i  : input sampling rate                     */
);

ivas_error initMdctItdHandling_fx(
  STEREO_MDCT_ENC_DATA *hStereoMdct,                          /* i/o: mdct stereo parameters structure        */
  const Word32 input_Fs                                      /* i  : input sampling rate                     */
);

void stereo_mdct_enc_destroy(
    STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct                    /* i/o: encoder MDCT stereo handle              */
);
@@ -3195,10 +3210,12 @@ void parse_stereo_from_bitstream(
);
#endif

#ifndef IVAS_FLOAT_FIXED
void FindSplitRatio(
    CPE_ENC_HANDLE hCPE,                                        /* i/o: CPE encoder structure                   */
    Encoder_State **sts                                         /* i/o: Encoder state structure                 */
);
#endif

void ComputeSpectrumNoiseMeasure(
    const float *powerSpec,
@@ -3514,6 +3531,20 @@ void v_add_inc_fx(
  const Word16 y_inc, /* i  : increment for vector y[]              */
  const Word16 N      /* i  : Vector length                         */
);
Word32 logsumexp_fx(
    const Word32 x[], /* i  : input array x                           */
    const Word16 x_e,
    const Word16 N  /* i  : number of elements in array x           */
);
Word32 lin_interp32_fx(
    const Word32 x,       /* i  : the value to be mapped                       */
    const Word32 x1,      /* i  : source range interval: low end               */
    const Word32 y1,      /* i  : source range interval: high end              */
    const Word32 x2,      /* i  : target range interval: low                   */
    const Word32 y2,      /* i  : target range interval: high                  */
    const Word16 flag_sat, /* i  : flag to indicate whether to apply saturation */
    Word16 *Q_io            /*i/o : i/o Q factor of the output*/
);
#endif

void v_mult_inc(
@@ -3624,6 +3655,13 @@ Word32 dot_product_cholesky_fx(
    const Word32 *A, /* i  : Cholesky  matrix A              */
    const Word16 N   /* i  : vector & matrix size            */
);
Word32 dot_product_cholesky_fixed(
    const Word32 *x, /* i  : vector x                        */
    const Word32 *A, /* i  : Cholesky  matrix A              */
    const Word16 N,  /* i  : vector & matrix size            */
    const Word16 exp_x,
    const Word16 exp_A,
    Word16 *exp_sum );
#endif

#ifdef IVAS_FLOAT_FIXED
@@ -3637,6 +3675,14 @@ void v_mult_mat_fx(
    const Word16 N,                                             /* i  : number of rows                          */
    const Word16 C                                              /* i  : number of columns                       */
);
void v_mult_mat_fixed(
    Word32 *y,         /* o  : the product x*A               */
    const Word32 *x,   /* i  : vector x                      */
    const Word32 *A,   /* i  : matrix A                      */
    const Word16 Nr, /* i  : number of rows                */
    const Word16 Nc,  /* i  : number of columns             */
    Word16 guardbits
);
#endif

void v_mult_mat(
+57 −0
Original line number Diff line number Diff line
@@ -2445,4 +2445,61 @@ void ivas_ari_encode_14bits_ext_fx(
    Tastat *s,
    Word32 symbol,
    const UWord16 *cum_freq );

void ms_inv_mask_processing_fx(
    STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure                  */
    Encoder_State **sts,                     /* i/o: Encoder state structure                 */
    int16_t ms_mask[NB_DIV][MAX_SFB],        /* i  : bandwise MS mask                        */
    const int16_t iSubframe,                 /* i  : subframe number                         */
    const Word32 x_0_fx[],                   /* i  : spectrum 1                              */
    const Word32 x_1_fx[],                   /* i  : spectrum 2                              */
    Word32 x_inv_0_fx[],                     /* o  : inverse spectrum 1                      */
    Word32 x_inv_1_fx[],                     /* o  : inverse spectrum 2                      */
    int16_t maxSfb                           /* i  : number of stereo frequency bands        */
);

void ms_processing_fx(
    STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure   */
    Encoder_State **sts,                     /* i/o: Encoder state structure         */
    Word16 ms_mask[NB_DIV][MAX_SFB],         /* i  : bandwise MS mask                */
    const int16_t iSubframe,                 /* i  : subframe number                 */
    Word32 x_0_fx[],                         /* i/o: spectrum 1                      */
    Word32 x_1_fx[],                         /* i/o: spectrum 1                      */
    Word16 maxSfb                            /* i  : number of stereo frequency bands*/
);

void convertToMS_fx(
    const int16_t L_frame, /* i  : frame length                    */
    Word32 x0[],           /* i/o: mid/left channel coefficients   */
    Word32 x1[],           /* i/o: side/right channel coefficients */
    const Word32 norm_fac  /* i  : normalization factor            */
);

void FindSplitRatio_fx(
    CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure       */
    Encoder_State **sts  /* i/o: Encoder state structure     */
);

void IGFEncStereoEncoder_fx(
    STEREO_MDCT_BAND_PARAMETERS *sfbParam, /* i/o: sfb parameters for the right channel    */
    const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i  : IGF handle                              */
    const Word32 *mdctSpectrumL_fx,        /* i  : left spectrum                           */
    const Word32 *mdctSpectrumR_fx,        /* i  : right spectrum                          */
    Word16 q_mdctSpectrum,
    Word16 *msMask,                /* i/o: MS mask                                 */
    Word16 *igfStereoMode,         /* o  : IGF stereo mode                         */
    const Word16 mdct_stereo_mode, /* i  : MDCT stereo mode                        */
    const Word16 isTCX20,          /* i  : flag for indicating TCX20               */
    const Word16 isTransition      /* i  : flag for transtition                    */
);

void stereo_coder_tcx_fx(
    STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct,            /* i/o: Stereo MDCT encoder structure   */
    Encoder_State **sts,                                /* i/o: encoder state structure         */
    Word16 ms_mask[NB_DIV][MAX_SFB],                    /* i  : bandwise MS mask                */
    Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV],     /* i/o: MDST spectrum                   */
    Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV],      /* i/o: inverse spectrum                */
    Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum           */
    const Word16 mct_on,                                /* i  : flag mct block (1) or stereo (0)  */
    Word16 q_spec );
#endif
+172 −1
Original line number Diff line number Diff line
@@ -809,6 +809,27 @@ void v_sub_s16_fx(
    return;
}
#endif // IVAS_FLOAT_FIXED


#ifdef IVAS_FLOAT_FIXED
void v_sub32_fx(
    const Word32 x1[], /* i  : Input vector 1                                   */
    const Word32 x2[], /* i  : Input vector 2                                   */
    Word32 y[],        /* o  : Output vector that contains vector 1 - vector 2  */
    const Word16 N     /* i  : Vector length                                    */
)
{
    Word16 i;

    FOR( i = 0; LT_16( i, N ); i++ )
    {
        y[i] = L_sub( x1[i], x2[i] );
    }

    return;
}
#endif // IVAS_FLOAT_FIXED

void v_sub_s(
    const int16_t x1[], /* i  : Input vector 1                                   */
    const int16_t x2[], /* i  : Input vector 2                                   */
@@ -855,7 +876,8 @@ float dot_product_cholesky(
        pt_x = x;
        for ( j = 0; j <= i; j++ )
        {
            tmp_sum += *pt_x++ * *pt_A++;
            float mul = *pt_x++ * *pt_A++;
            tmp_sum += mul;
        }

        suma += tmp_sum * tmp_sum;
@@ -863,8 +885,73 @@ float dot_product_cholesky(

    return suma;
}
#ifdef IVAS_FLOAT_FIXED
Word32 dot_product_cholesky_fixed(
    const Word32 *x, /* i  : vector x                        */
    const Word32 *A, /* i  : Cholesky  matrix A              */
    const Word16 N,  /* i  : vector & matrix size            */
    const Word16 exp_x,
    const Word16 exp_A,
    Word16 *exp_sum )
{
    Word16 i, j;
    Word32 suma, tmp_sum, mul;
    const Word32 *pt_x, *pt_A;
    Word16 mul_exp, tmp_sum_exp;
    mul_exp = add( exp_x, exp_A );
    pt_A = A;
    suma = 0;
    move32();
    FOR( i = 0; i < N; i++ )
    {
        tmp_sum = 0;
        move32();
        tmp_sum_exp = 0;
        move16();
        pt_x = x;

        FOR( j = 0; j <= i; j++ )
        {
            mul = Mpy_32_32( *pt_x++, *pt_A++ );
            tmp_sum = BASOP_Util_Add_Mant32Exp( tmp_sum, tmp_sum_exp, mul, mul_exp, &tmp_sum_exp ); // exp_x+exp_A
        }

        suma = BASOP_Util_Add_Mant32Exp( suma, *exp_sum, Mpy_32_32( tmp_sum, tmp_sum ), shl( tmp_sum_exp, 1 ), exp_sum );
    }

    return suma;
}
#endif
#ifdef IVAS_FLOAT_FIXED
void v_mult_mat_fixed(
    Word32 *y,       /* o  : the product x*A               */
    const Word32 *x, /* i  : vector x                      */
    const Word32 *A, /* i  : matrix A                      */
    const Word16 Nr, /* i  : number of rows                */
    const Word16 Nc, /* i  : number of columns             */
    Word16 guardbits )
{
    Word16 i, j;
    const Word32 *pt_x, *pt_A;
    Word32 tmp_y[MAX_V_MULT_MAT];
    Word32 *pt_y;

    pt_y = tmp_y;
    pt_A = A;

    FOR( i = 0; i < Nc; i++ )
    {
        pt_x = x;
        *pt_y = 0;
        FOR( j = 0; j < Nr; j++ )
        {
            *pt_y = L_add( *pt_y, L_shr( Mpy_32_32( ( *pt_x++ ), ( *pt_A++ ) ), guardbits ) );
        }
        pt_y++;
    }

    mvr2r_Word32( tmp_y, y, Nc );
}
Word32 dot_product_cholesky_fx(
    const Word32 *x, /* i  : vector x                        */
    const Word32 *A, /* i  : Cholesky  matrix A              */
@@ -1045,14 +1132,98 @@ float logsumexp(

    return logf( sum ) + max_exp;
}
#ifdef IVAS_FLOAT_FIXED
Word32 logsumexp_fx(
    const Word32 x[], /* i  : input array x                           */
    const Word16 x_e,
    const Word16 N /* i  : number of elements in array x           */
)
{
    Word32 max_exp, temp32_sub;
    Word32 sum, temp32, pow_temp;
    Word32 log2_e_fx = 1549082005; // Q30 of log2(e);
    Word16 log2_e_fx_e = 1;
    move16();
    move16();
    Word16 i;
    Word16 pow_e, sum_e = 0;
    move16();
    max_exp = x[0];
    move32();
    sum = 0;
    move32();
    FOR( i = 1; i < N; i++ )
    {
        IF( GT_32( x[i], max_exp ) )
        {
            max_exp = x[i];
            move32();
        }
    }

    FOR( i = 0; i < N; i++ )
    {
        temp32_sub = L_sub( x[i], max_exp );
        pow_e = 0;
        move16();
        temp32 = Mpy_32_32( log2_e_fx, temp32_sub );
        pow_temp = BASOP_util_Pow2( temp32, add( x_e, log2_e_fx_e ), &pow_e );
        sum = BASOP_Util_Add_Mant32Exp( sum, sum_e, pow_temp, pow_e, &sum_e );
    }
    temp32 = L_add( BASOP_Util_Log2( sum ), L_shl( sum_e, Q25 ) );
    temp32 = Mpy_32_32( temp32, 1488522239 );                  /*logf(x) = log2(x)*logf(2)*/
    temp32 = L_add( L_shr( temp32, sub( x_e, 6 ) ), max_exp ); // q = 31-x_e
    return temp32;
}
#endif

/*---------------------------------------------------------------------*
 * lin_interp()
 *
 * Linearly maps x from source range <x1, x2> to the target range <y1, y2>
 *---------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
/*! r: mapped output value */
Word32 lin_interp32_fx(
    const Word32 x,        /* i  : the value to be mapped                       */
    const Word32 x1,       /* i  : source range interval: low end               */
    const Word32 y1,       /* i  : source range interval: high end              */
    const Word32 x2,       /* i  : target range interval: low                   */
    const Word32 y2,       /* i  : target range interval: high                  */
    const Word16 flag_sat, /* i  : flag to indicate whether to apply saturation */
    Word16 *Q_io           /*i/o : i/o Q factor of the output*/
)
{
    Word32 temp32;
    Word32 temp_div;
    Word16 temp_e = 0;
    Word16 exp_out = 0;
    move16();
    move16();
    IF( L_sub( x2, x1 ) == 0 )
    {
        return y1;
    }
    ELSE IF( flag_sat )
    {
        IF( GE_32( x, L_max( x1, x2 ) ) )
        {
            return GT_32( x1, x2 ) ? y1 : y2;
        }
        ELSE IF( LE_32( x, L_min( x1, x2 ) ) )
        {
            return LT_32( x1, x2 ) ? y1 : y2;
        }
    }

    temp32 = Mpy_32_32( L_sub( x, x1 ), L_sub( y2, y1 ) );                                                          // Qin*2 -31
    temp_div = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, L_sub( x2, x1 ), &temp_e ) );                      // 31-temp_e + 2*Qin -31 - Qin = Qin-temp_e
    temp32 = BASOP_Util_Add_Mant32Exp( y1, sub( 31, *Q_io ), temp_div, sub( 31, sub( *Q_io, temp_e ) ), &exp_out ); // Qin-temp_e
    *Q_io = sub( 31, exp_out );
    return temp32;
}

#endif
/*! r: mapped output value */
float lin_interp(
    const float x,         /* i  : the value to be mapped                       */
Loading