diff --git a/lib_enc/ivas_mcmasa_enc_fx.c b/lib_enc/ivas_mcmasa_enc_fx.c index 280da94568e28c042476055c9fef075341e20982..486c6b1bd5c91f2bebca5983a1f7d6ed4d57e4e4 100644 --- a/lib_enc/ivas_mcmasa_enc_fx.c +++ b/lib_enc/ivas_mcmasa_enc_fx.c @@ -72,6 +72,29 @@ 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 *sf_c, + 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 +103,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 +943,13 @@ 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]; + Word16 sf_c[MCMASA_MAX_ANA_CHANS]; +#endif Word16 numSubFramesForRatio; CovarianceMatrix COVls[MASA_FREQUENCY_BANDS]; Word32 absCOVls_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; @@ -1007,6 +1037,18 @@ 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]; + 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++ ) { @@ -1051,20 +1093,68 @@ void ivas_mcmasa_param_est_enc_fx( FOR( i = 0; i < numAnalysisChannels; i++ ) { +#ifdef FUNC_compute_cov_mtx_fx_16 + Word16 scal_imag, scal_real; + scal_imag = L_norm_arr( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ); + scal_real = L_norm_arr( Chnl_RealBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ); + sf_c[i] = sub( s_min( scal_real, scal_imag ), 1 ); + pcm_in[i] += l_ts; + cr_q = s_min( cr_q, scal_imag ); + ci_q = s_min( ci_q, scal_real ); +#else pcm_in[i] += l_ts; cr_q = s_min( cr_q, L_norm_arr( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); ci_q = s_min( ci_q, L_norm_arr( Chnl_RealBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ) ); +#endif } 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*/ + int k; + const int lg = DIRAC_NO_FB_BANDS_MAX; + const Word16 exp0 = add( sf_c[i], 0 ); + + 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 ); +#ifdef FUNC_compute_cov_mtx_fx_16 /* Compute covariance matrix */ + compute_cov_mtx_fx_16( Chnl_RealImagBuffer_fx_16, numAnalysisChannels, COVls, sub( 31, inp_q ), sf_c, hMcMasa->band_grouping, (int) num_freq_bands, fb_map ); + + inp_q = add( inp_q, sf ); + + 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 +1173,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 +2178,69 @@ 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 *sf_c, + 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; + int freq; + + + FOR( i = 0; i < N; i++ ) + { + FOR( j = i; j < N; j++ ) + { + temp_exp = add( sub( inp_exp, sf_c[i] ), sub( inp_exp, sf_c[j] ) ); + FOR( freq = band_grouping[0]; freq < band_grouping[num_freq_bands]; freq++ ) + { + CovarianceMatrix *COVls = &( mCOVls[fb_map[freq]] ); + // Ri(Rsre-Rs[0] *Rj(Rtre-Rt[0] + Ii(Rsim-Rs[1] * Ij(Rtim-Rt[1] + 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 = add( s_max( COVls->xr_e[i][j], temp_exp ), 1 ); + 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(); + + // Ii(Rsim-Rs[1] * Rj(Rtre-Rt[0] - Ri(Rsre-Rs[0] * Ii(Rtim-Rt[1] + 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 = add( s_max( COVls->xr_e[i][j], temp_exp ), 1 ); + 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(); + move16(); + } + } + } + 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 +2287,7 @@ static void compute_cov_mtx_fx( } return; } +#endif static void computeIntensityVector_enc_fx( const Word16 *band_grouping,