Commit 6662ba55 authored by Fabian Bauer's avatar Fabian Bauer
Browse files

compute_cov_mtx_fx_16

parent a69ea576
Loading
Loading
Loading
Loading
Loading
+141 −2
Original line number Diff line number Diff line
@@ -72,6 +72,28 @@ static void ivas_mcmasa_dmx_fx(
    const Word16 nchan_transport,
    const Word16 nchan_inp );

#define FUNC_compute_cov_mtx_fx_16
#ifdef FUNC_compute_cov_mtx_fx_16
static void compute_cov_mtx_fx_16(
    Word16 sri[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX * 2],
    const Word16 N,          /* i  : Number of channels                                      */
    CovarianceMatrix *COVls, /* o  : Output matrix, contains upper part of cov mtx           */
    Word16 inp_exp,          /*Stores exponent for temp*/
    Word16 band_grouping[],
    int num_freq_bands,
    int *fb_map );

/* RAM_ALIGN keyword causes memory alignment */
#ifndef RAM_ALIGN
#define ALIGNMENT_DEFAULT 8
#if defined( __GNUC__ )
#define RAM_ALIGN __attribute__( ( aligned( ALIGNMENT_DEFAULT ) ) )
#else
#define RAM_ALIGN
#endif
#endif
 
#else
static void compute_cov_mtx_fx(
    Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i  : Input matrix, real, s[ch][freq]                         */
    Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i  : Input matrix, imag, s[ch][freq]                         */
@@ -80,6 +102,7 @@ static void compute_cov_mtx_fx(
    CovarianceMatrix *COVls,                                /* o  : Output matrix, contains upper part of cov mtx           */
    Word16 inp_exp                                          /*Stores exponent for temp*/
);
#endif

static void computeIntensityVector_enc_fx(
    const Word16 *band_grouping,
@@ -919,7 +942,12 @@ void ivas_mcmasa_param_est_enc_fx(
    Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; // renormalization_factor_diff_e
    Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS];
    Word32 norm_tmp_fx;
#ifndef FUNC_compute_cov_mtx_fx_16
     Word16 mrange[2], brange[2];
#else
    RAM_ALIGN Word16 Chnl_RealImagBuffer_fx_16[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX * 2];
    Word16 mrange[2];
#endif
    Word16 numSubFramesForRatio;
    CovarianceMatrix COVls[MASA_FREQUENCY_BANDS];
    Word32 absCOVls_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS];
@@ -1007,6 +1035,19 @@ void ivas_mcmasa_param_est_enc_fx(
    hMasa->data.q_energy = 0;
    move16();

#ifdef FUNC_compute_cov_mtx_fx_16
    /*get freq/band mapping*/
    int fb_map[DIRAC_NO_FB_BANDS_MAX];
    int const sfCorrection = 3;
    FOR( int b = 0; b < num_freq_bands; b++ )
    {
        FOR( int f = hMcMasa->band_grouping[b]; f < hMcMasa->band_grouping[b + 1]; f++ )
        {
            fb_map[f] = b;
        }
    }
#endif

    /* do processing over all CLDFB time slots */
    FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ )
    {
@@ -1059,12 +1100,49 @@ void ivas_mcmasa_param_est_enc_fx(
            sf = sub( s_min( cr_q, ci_q ), 5 );
            FOR( i = 0; i < numAnalysisChannels; i++ )
            {
#ifdef FUNC_compute_cov_mtx_fx_16
                {
                    Word32 *re = Chnl_RealBuffer_fx[i];       /*in*/
                    Word32 *im = Chnl_ImagBuffer_fx[i];       /*in*/
                    Word16 *x = Chnl_RealImagBuffer_fx_16[i]; /*out*/
                    Word16 k;
                    const Word16 lg = DIRAC_NO_FB_BANDS_MAX;
                    const Word16 exp0 =add( sf , sfCorrection);

                    if ( 0 == exp0 )
                    {
                        k = lg;
                        move16();
                    }

                    FOR( k = 0; k < lg; k++ )
                    {
                        /* saturation can occur here */
                        x[( k << 1 ) + 0] = round_fx( L_shl( re[k], exp0 ) );
                        x[( k << 1 ) + 1] = round_fx( L_shl( im[k], exp0 ) );
                        move32();
                    }
                }
#endif
                scale_sig32( Chnl_RealBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX, sf ); // Q-> inp_q + sf
                scale_sig32( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX, sf ); // Q-> inp_q + sf
            }
            inp_q = add( inp_q, sf );

            /* Compute covariance matrix */
#ifdef FUNC_compute_cov_mtx_fx_16
            compute_cov_mtx_fx_16( Chnl_RealImagBuffer_fx_16, numAnalysisChannels, COVls, sub( 31 + sfCorrection, inp_q ), hMcMasa->band_grouping, (int) num_freq_bands, fb_map );

            FOR( i = 0; i < num_freq_bands; i++ )
            {
                /* Store energies for guiding metadata encoding */
                FOR( j = 0; j < numAnalysisChannels; j++ )
                {
                    move32();
                    hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] );
                }
            }
#else //FUNC_compute_cov_mtx_fx_16
            FOR( i = 0; i < num_freq_bands; i++ )
            {
                brange[0] = hMcMasa->band_grouping[i];
@@ -1083,6 +1161,7 @@ void ivas_mcmasa_param_est_enc_fx(
                    hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] );
                }
            }
#endif

            IF( !hMcMasa->separateChannelEnabled )
            {
@@ -2087,6 +2166,65 @@ static void ivas_mcmasa_dmx_fx(

    return;
}

#ifdef FUNC_compute_cov_mtx_fx_16
 /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */
static void compute_cov_mtx_fx_16(
    Word16 sri[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX * 2],
    const Word16 N,                                         /* i  : Number of channels                                      */
    CovarianceMatrix mCOVls[],                               /* o  : Output matrix pointer, - upper part of cov mtx           */
    Word16 inp_exp,                                          /*Stores exponent for temp*/
    Word16 band_grouping[],
    int num_freq_bands,
    int *fb_map )
{
    int i, j;
    Word32 temp32_1, temp32_2;
    Word16 tmp_16, max_exp;
    Word16 temp_exp = shl( inp_exp, 1 );
    int freq;


    FOR( i = 0; i < N; i++ )
    {
        FOR( j = i; j < N; j++ )
        {
            FOR( freq = band_grouping[0]; freq < band_grouping[num_freq_bands]; freq++ )
            {
                CovarianceMatrix *COVls = &( mCOVls[fb_map[freq]] );

                temp32_1 = L_mac0( L_mult0( sri[i][freq << 1], sri[j][freq << 1] ), sri[i][( freq << 1 ) + 1], sri[j][( freq << 1 ) + 1] ); // exp:2*inp_exp
                temp32_2 = COVls->xr_fx[i][j];                                               // exp:COVls->xr_e[i][j]
                max_exp = s_max( COVls->xr_e[i][j], temp_exp );
                temp32_2 = L_shl( temp32_2, sub( COVls->xr_e[i][j], max_exp ) ); // exp:max_exp
                temp32_1 = L_shl( temp32_1, sub( temp_exp, max_exp ) );          // exp:max_exp
                temp32_1 = L_add( temp32_1, temp32_2 );                          // exp:max_exp
                tmp_16 = norm_l( temp32_1 );

                COVls->xr_fx[i][j] = L_shl( temp32_1, tmp_16 ); // exp:max_exp-tmp_16
                COVls->xr_e[i][j] = sub( max_exp, tmp_16 );
                move32();
                move16();

                temp32_1 = L_msu0( L_mult0( sri[i][( freq << 1 ) + 1], sri[j][freq << 1] ), sri[i][freq << 1], sri[j][(freq << 1) + 1] ); // exp :2*inp_exp
                temp32_2 = COVls->xi_fx[i][j];                                                         // exp:COVls->xi_e[i][j]
                max_exp = s_max( COVls->xi_e[i][j], temp_exp );
                temp32_2 = L_shl( temp32_2, sub( COVls->xi_e[i][j], max_exp ) ); // exp:max_exp
                temp32_1 = L_shl( temp32_1, sub( temp_exp, max_exp ) );          // exp:max_exp
                temp32_1 = L_add( temp32_1, temp32_2 );                          // exp:max_exp
                tmp_16 = norm_l( temp32_1 );

                COVls->xi_fx[i][j] = L_shl( temp32_1, tmp_16 ); // exp:max_exp-tmp_16
                COVls->xi_e[i][j] = sub( max_exp, tmp_16 );
                move32();
            }
        }
    }
    return;
}
#else


    /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */
static void compute_cov_mtx_fx(
    Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i  : Input matrix, real, s[ch][freq]               (inp_exp) */
@@ -2133,6 +2271,7 @@ static void compute_cov_mtx_fx(
    }
    return;
}
#endif

static void computeIntensityVector_enc_fx(
    const Word16 *band_grouping,