Commit b30aef1b authored by multrus's avatar multrus
Browse files

[cleanup] accept ERI_MSVQ_CLEANUP

parent c1127fd0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@



#define ERI_MSVQ_CLEANUP                                /* Eri: Contribution #31  BE modularization of msvq encoder side DCT21&DCT24 within msvq_enc()        */
#define FIX_416_ISM_BR_SWITCHING                        /* FhG: add missing CLDFB reconfig to ISM BR switching */
#define FIX_SP2A                                        /* VA: Issue 412: Adjust threshold for the S_p2a feature in the tonal detector */

+0 −2
Original line number Diff line number Diff line
@@ -8169,7 +8169,6 @@ void extend_dctN_input(
    const int16_t n_cols,   /* i: number of columns ==  truncation length */
    DCTTYPE dcttype );      /* i: matrix  type    */

#ifdef ERI_MSVQ_CLEANUP
int16_t msvq_stage1_dct_search(                                           /* o  : (p_max , best candidate sofar )                                  */
                                const float *u,                           /* i  : target                                   */
                                const int16_t N,                          /* i  : target length and  IDCT synthesis length */
@@ -8203,7 +8202,6 @@ int16_t msvq_stage1_dct_recalc_candidates_fdcng_wb(
    const int16_t maxC_st1,       /* i  : number of candidates in stage1 */
    float *dist_ptr               /* i/o: updated  MSE vector for stage1 */
);
#endif

void PulseResynchronization(
    const float *src_exc,       /* i  : Input excitation buffer                 */
+0 −212
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@
// void dctT2_N_apply_matrix( const float *input, float *output, const int16_t dct_dim, int16_t fdcngvq_dim, const float *idctT2_24_X_matrixQ16, const int16_t matrix_1st_dim, DCTTYPE dcttype );


#ifdef ERI_MSVQ_CLEANUP

int16_t msvq_stage1_dct_search(
    /* o  : (p_max , best candidate sofar )                          */
@@ -304,7 +303,6 @@ int16_t msvq_stage1_dct_recalc_candidates_fdcng_wb(

    return p_max_local;
}
#endif


/*--------------------------------------------------------------------------*
@@ -337,36 +335,9 @@ void msvq_enc(
    float resid_buf[2 * LSFMBEST_MAX * M_MAX], dist_buf[2 * LSFMBEST_MAX], Tmp[M_MAX];
    int16_t idx_buf[2 * LSFMBEST_MAX * MAX_VQ_STAGES_USED], parents[LSFMBEST_MAX];
    int16_t n, maxn, start;
#ifndef ERI_MSVQ_CLEANUP
    /* buffers */
    float dct_target[FDCNG_VQ_DCT_MAXTRUNC];
    float u_mr[FDCNG_VQ_MAX_LEN];
    float u_mr_scaled[FDCNG_VQ_MAX_LEN];
    float mse_trunc_all_segms;
    float mse_trunc_segm[FDCNG_VQ_DCT_NSEGM];
    float mse;

    const Word8 *cbpW8;
    const Word16 *dct_col_shift_tab;

    float *st1_mse_pair;
    int16_t *st1_idx_pair;
    int16_t indices_st1_local[FDCNG_VQ_DCT_NSEGM * 2]; /* after stage#1 DCT search  this is copied to the global  indices[1][s*stages] structure */
    int16_t n_ana, p_mins[2], idx_min[2];
    DCTTYPE dcttype = DCT_T2_24_XX;
    float tmp2;

    int16_t check_ind[FDCNG_VQ_DCT_NPOST];
    int16_t segm, j_full, maxC_pre;
#endif
    float *st1_syn_vec_ptr; /* ptr to buffer in dynRAM */
    float *st1_mse_ptr;     /* ptr to  buffer in existing dRAM used for stage 1 candidate analysis */
#ifdef ERI_MSVQ_CLEANUP
    int16_t indices_st1_local[FDCNG_VQ_DCT_NSEGM * 2]; /* after stage#1 DCT search  this is copied to the global  indices[1][s*stages] structure */
#else
    float res24, high_diff[FDCNG_VQ_MAX_LEN - FDCNG_VQ_MAX_LEN_WB];
    maxC_pre = ( FDCNG_VQ_DCT_NSEGM * 2 );
#endif
    assert( maxC <= LSFMBEST_MAX );
    assert( ( LSFMBEST_MAX * M_MAX ) > ( N * maxC ) );
    /*   top of resid_buf  is   resid[1]  and used for stage#1 residuals (input target u),
@@ -375,9 +346,6 @@ void msvq_enc(

    st1_syn_vec_ptr = &( resid_buf[1 * LSFMBEST_MAX * M_MAX] ) - FDCNG_VQ_MAX_LEN * maxC; /*   reuse top of resid[0] scratch RAM for residual */

#ifndef ERI_MSVQ_CLEANUP
    dcttype = DCT_T2_24_XX;
#endif


    /*----------------------------------------------------------------*
@@ -462,7 +430,6 @@ void msvq_enc(
            dist[1][j] = FLT_MAX;
        }

#ifdef ERI_MSVQ_CLEANUP
        if ( !s && applyDCT_flag != 0 ) /* means: m==1 */
        {
            /* stage 1 candidates search in truncated dct24  domain without any weights  */
@@ -495,167 +462,6 @@ void msvq_enc(
                indices[1][c * stages] = indices_st1_local[c];
            }
        }
#else
        if ( !s && applyDCT_flag != 0 ) /* means: m==1 */
        {                               /* stage 1 search in truncated dct domain without any weights  */

            n_ana = FDCNG_VQ_MAX_LEN; /*  VQ stage#1 core is always using stored DCT24 coeffs */
            /*remove mean/mid fdcng stage#1 vector,  in original subband domain */
            v_sub( u, cdk1r_tr_midQ_truncQ, u_mr, n_ana );

            v_multc( u_mr, fdcng_dct_invScaleF[1], u_mr_scaled, n_ana ); /*scale up target to upscaled  W8x storage  domain  */
            /* 16.0-->scale up from Q0 to  search  domain  in Q4,  not really  needed in BASOP , impl. by shifts */

            assert( n_ana >= FDCNG_VQ_DCT_MAXTRUNC ); /* check for  WB , SWB, FB operation  */

            dctT2_N_apply_matrix( (const float *) u_mr_scaled, dct_target, min( FDCNG_VQ_DCT_MAXTRUNC, n_ana ), n_ana, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, dcttype );

            mse_trunc_all_segms = 0;
            mse = 0;

            /* init search state   ptr's  at the top */
            for ( segm = 0; segm < FDCNG_VQ_DCT_NSEGM; segm++ )
            {
                /*  point to a    new paired location  */
                st1_mse_pair = &( dist[1][2 * segm] );           /* req. ptr init +=2  */
                st1_mse_pair[0] = FLT_MAX;                       /* req */
                st1_mse_pair[1] = FLT_MAX;                       /* req */
                st1_idx_pair = &( indices_st1_local[2 * segm] ); /* +=2 */
                p_max = 0;                                       /* req. to point to  1 or 0  */

                /* compute segment common trunction error in dct domain */
                mse_trunc_segm[segm] = mse_trunc_all_segms;
                mse_trunc_segm[segm] += sum2_f( (const float *) ( &( dct_target[cdk1_ivas_cols_per_segment[segm]] ) ), cdk1_ivas_trunc_dct_cols_per_segment[segm] );

                cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm]; /* Word8 column variable Qx storage*/

                for ( j = 0; j < cdk1_ivas_entries_per_segment[segm]; j++ )
                {
                    /* unweighted segmented search DCT domain loop */
                    j_full = j + cdk1_ivas_cum_entries_per_segment[segm]; /* or simply use j_full++ */

                    mse = mse_trunc_segm[segm]; /* move32() init mse with with common mse truncation part */

                    dct_col_shift_tab = stage1_dct_col_syn_shift[segm]; /* ptr init */

                    for ( c2 = 0; c2 < cdk1_ivas_cols_per_segment[segm]; c2++ )
                    {

#define WMC_TOOL_SKIP
                        tmp = dct_target[c2] - (float) ( ( (Word16) cbpW8[c2] ) << dct_col_shift_tab[c2] ); /* Word8 storage MSE inner loop */
                        LOGIC( 1 );
                        SHIFT( 1 );
                        ADD( 1 ); /* in BASOP:    s_and(for W8->W16), shl(), sub()*/
#undef WMC_TOOL_SKIP

                        mse += tmp * tmp; /*  L_mac or L_mac0()   square Word16 -> Word32*/
                    }
                    st1_mse_ptr[j_full] = mse;                 /* save MSE in shared dynamic 2^7=128 RAM,  move32() in BASOP */

#define WMC_TOOL_SKIP
                    cbpW8 += cdk1_ivas_cols_per_segment[segm]; /*    pointer increment  */
#undef WMC_TOOL_SKIP
                    /* overwrite with a new worst index at p_max  */

                    /* The three inner loop if's below are not really properly instrumented by WMC tool */
                    /* a ptr to worst index will be in use */
                    if ( mse < st1_mse_pair[p_max] ) /* L_sub  */
                    {
                        st1_idx_pair[p_max] = j_full; /* simplified */
                    }                                 /* BASOP 2 ops */

                    if ( st1_idx_pair[p_max] == j_full ) /* simplified */
                    {                                    /*idx updated to j_full -->  also update mse */
                        st1_mse_pair[p_max] = mse;       /* move32(), single BASOP  */
                    }                                    /* BASOP 3 ops */
                    /* avoid WC costly list management by always updating p_max,  as  we have only a pair to maintain */
                    p_max = 0;                                       /* move16() */
                    if ( ( st1_mse_pair[0] - st1_mse_pair[1] ) < 0 ) /* L_sub()*/
                    {
                        p_max = 1; /*  move16() */
                    }              /* BASOP 3 ops  ,Note  2 ops possible in BASOP with L_sub and  L_lshr  */

                    /* Note: logical shift right not available in ANSI-C */
                    /* p_max = (st1_mse_pair[0] - st1_mse_pair[1]) ">>>" 31; */
                    /* in java logical shift right is available as  >>> ,  in BASOP  it is L_lshr */

                    /* Cost: weighted sum with cond moves ('if') => 8 in float ,   7 in BASOP with L_lshr  */
                } /* j in section */

            } /* next segment */

            for ( j = 0; j < maxC_pre; j++ )
            {
                /* compute_full mse using stored DCT24 domain  MSE's   */
                /* calculate MSE  from stage1 inner using existing  inner  DCT domain variables */
                dist[1][j] *= fdcng_dct_scaleF[2]; /*  single multiplication to get the MSE scale to the correct input domain   */
            }

            p_max = maximum( dist[1], maxC_pre, NULL ); /* establish  current worst candidate for stage#2  among all  maxC_pre candidates */

            p_mins[0] = minimum( dist[1], maxC_pre, NULL ); /* find best  entry among all maxC_pre   */
            tmp = dist[1][p_mins[0]];
            dist[1][p_mins[0]] = FLT_MAX; /* exclude 1st */

            p_mins[1] = minimum( dist[1], maxC_pre, NULL ); /* find 2nd best entry  */
            tmp2 = dist[1][p_mins[1]];
            dist[1][p_mins[1]] = FLT_MAX; /* exclude 2nd*/

            dist[1][p_mins[0]] = tmp;  /* restore 1st */
            dist[1][p_mins[1]] = tmp2; /* restore 2nd */

            idx_min[0] = indices_st1_local[p_mins[0]];
            idx_min[1] = indices_st1_local[p_mins[1]];


            /* use global exclusion list to never reselect  the two  (best)  mse values sofar  */
            st1_mse_ptr[idx_min[0]] = FLT_MAX; /* move32() */
            st1_mse_ptr[idx_min[1]] = FLT_MAX; /* move32() */

            /*  circular MSE-neigbour list in use to potentially replace some segment search candidates */
            /* using both 1st and 2nd best neighbours   in fwd and rev directions */
            check_ind[0] = cdk1_ivas_segm_neighbour_fwd[idx_min[0]];
            check_ind[1] = cdk1_ivas_segm_neighbour_rev[idx_min[0]];

            check_ind[2] = cdk1_ivas_segm_neighbour_fwd[idx_min[1]];
            check_ind[3] = cdk1_ivas_segm_neighbour_rev[idx_min[1]];

            check_ind[4] = cdk1_ivas_segm_neighbour_fwd[check_ind[0]];
            check_ind[5] = cdk1_ivas_segm_neighbour_rev[check_ind[1]];

            check_ind[6] = cdk1_ivas_segm_neighbour_fwd[check_ind[2]];
            check_ind[7] = cdk1_ivas_segm_neighbour_rev[check_ind[3]];

            for ( i = 0; i < FDCNG_VQ_DCT_NPOST; i++ )
            {
                float check_mse = st1_mse_ptr[check_ind[i]] * fdcng_dct_scaleF[2];
                /*  *= fdcng_dct_scaleF[2]; */ /*   multiplication in use to get the float outer loop scale correct */

                if ( check_mse < dist[1][p_max] )
                {
                    /* new winner , replace */
                    dist[1][p_max] = check_mse;
                    indices_st1_local[p_max] = check_ind[i];
                    st1_mse_ptr[check_ind[i]] = FLT_MAX;        /* BASOP: move32() */
                    p_max = maximum( dist[1], maxC_pre, NULL ); /* establish a new  current worst candidate   among all maxC */
                }
            }

            for ( c = 0; c < maxC_pre; c++ )
            {
                indices[1][c * stages] = indices_st1_local[c]; /*    move established stage#1  indices  to global MSVQ list structure */
            }

            /* extract the selected stage one vectors in DCT domain , apply IDCT_N and scale up */
            /*always extract full length signal(24) to be able to update WB( N==21) candidate MSE values  */
            for ( c = 0; c < maxC_pre; c++ )
            {
                dec_FDCNG_MSVQ_stage1( indices_st1_local[c], FDCNG_VQ_MAX_LEN, invTrfMatrix, dcttype + 1, &( st1_syn_vec_ptr[c * FDCNG_VQ_MAX_LEN] ), NULL );
            }

            assert( maxC == maxC_pre );
        }
#endif
        else
            /* non-DCT Stage #1 code below */
            if ( !s ) /* means: m==1 */
@@ -784,28 +590,10 @@ void msvq_enc(
           essentially subtract res21^2 ,res22^2, res23^2 that was included in stage1  MSE in the DCT24 domain truncated search,
           excludes the waveform contributions at pos 21,22,23 to the MSE, important to keep WB MSEs update for the subsequent stages
           */
#ifdef ERI_MSVQ_CLEANUP
        if ( s == 0 && applyDCT_flag != 0 && n == FDCNG_VQ_MAX_LEN_WB )
        {
            p_max = msvq_stage1_dct_recalc_candidates_fdcng_wb( st1_syn_vec_ptr, u, maxC, dist[1] );
        }
#else
        if ( s == 0 && applyDCT_flag != 0 && n == FDCNG_VQ_MAX_LEN_WB )
        {
            assert( start == 0 );
            for ( c = 0; c < maxC; c++ )
            {                                                                                          /* point to extended  synthesis part */
                p2 = (const float *) &( st1_syn_vec_ptr[c * FDCNG_VQ_MAX_LEN + FDCNG_VQ_MAX_LEN_WB] ); /* ptr init */
                /* for stage#1 use "u" instead of the shortened resid[0], to access the extended/extrapolated  input target */
                v_sub( p2, &( u[FDCNG_VQ_MAX_LEN_WB] ), high_diff, FDCNG_VQ_MAX_LEN - FDCNG_VQ_MAX_LEN_WB );
                res24 = dotp( high_diff, high_diff, FDCNG_VQ_MAX_LEN - FDCNG_VQ_MAX_LEN_WB ); /* sum squared over 3 env. values */

                dist[1][c] -= res24; /* remove DCT24 high band error contribution */
            }
            /* update p_max,  as it may potentially change, due to the core DCT24 search originally optimizing over longer basis vectors than 21 */
            p_max = maximum( dist[1], maxC, NULL );
        }
#endif
        m = maxC;
    } /* for (m=1, s=0; s<stages; s++) */