Skip to content
......@@ -2763,7 +2763,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx(
/* Do 1st stage scalar quantization */
lfeToTotalEnergyRatioIndices[0] = 1;
move16();
lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q13 ) ), &xq, MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11, 8 );
lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q14 ) ), &xq, MCMASA_LFE_QLOW_Q11, MCMASA_LFE_DELTA_Q10, 8 );
move16();
IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) /* Vector quantization is applied if bitrate >= 24.4 kbps */
......@@ -2771,7 +2771,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx(
/* Remove scalar value from the vector*/
FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q13 ) ); // Q25
log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q14 ) ); // Q25
move32();
}
......
......@@ -809,13 +809,18 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
move16();
move16();
move16();
move16();
move16();
move16();
move16();
move16();
move16();
move16();
FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
{
pcm_in_fx[2 * i] = data_f_fx[chan1s[i]];
pcm_in_fx[2 * i + 1] = data_f_fx[chan2s[i]];
move16();
move16();
Scale_sig32( pcm_in_fx[2 * i], input_frame, sub( Q14, Q_data_f ) );
Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, sub( Q14, Q_data_f ) );
......@@ -842,8 +847,6 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
{
p_fr_realbuffer_fx[i] = fr_realbuffer_fx[i];
p_fr_imagbuffer_fx[i] = fr_imagbuffer_fx[i];
move32();
move32();
}
/* prepare Parameter MDFT analysis */
......@@ -851,8 +854,6 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
{
pp_in_fr_real_fx[i] = p_fr_realbuffer_fx[i];
pp_in_fr_imag_fx[i] = p_fr_imagbuffer_fx[i];
move32();
move32();
}
// l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES;
......@@ -887,8 +888,8 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
{
Scale_sig32( pcm_in_fx[2 * i], input_frame, Q_data_f - Q14 );
Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, Q_data_f - Q14 );
Scale_sig32( pcm_in_fx[2 * i], input_frame, sub( Q_data_f, Q14 ) );
Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, sub( Q_data_f, Q14 ) );
}
/*-----------------------------------------------------------------------------------------*
......@@ -953,15 +954,14 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
FOR( bnd = 0; bnd < maxbands; bnd++ )
{
rxy_fx = hMCParamUpmix->cov_real_fx[b][1][0][bnd];
move32();
ryy_fx = hMCParamUpmix->cov_real_fx[b][1][1][bnd];
move32();
Word16 exp_tmp = 0;
move16();
Word32 tmp = BASOP_Util_Add_Mant32Exp( ryy_fx, sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][1][bnd] ) ), EPSILON_FX_M, EPSILON_FX_E, &exp_tmp );
exp_cmat = 0;
move16();
cmat_fx = BASOP_Util_Divide3232_Scale( rxy_fx, tmp, &exp_cmat );
exp_cmat = sub( add( exp_cmat, sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][0][bnd] ) ) ), exp_tmp );
cmat_fx = BASOP_Util_Divide3232_Scale( rxy_fx, L_add( ryy_fx, EPSILON_FX ), &exp_cmat );
exp_cmat = sub( add( exp_cmat, sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][0][bnd] ) ) ), sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][1][bnd] ) ) );
Word16 alpha_fx = 0, exp_alpha_var = 0;
move16();
......@@ -969,6 +969,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
exp_alpha_var = BASOP_Util_Add_MantExp( cmat_fx, add( exp_cmat, 1 ), negate( ONE_IN_Q14 ), 1, &alpha_fx );
rxx_fx = hMCParamUpmix->cov_real_fx[b][0][0][bnd];
move32();
Word32 tmp_2 = L_mult( cmat_fx, cmat_fx ); // exp_cmat * 2
rxxest_fx = Mpy_32_32( tmp_2, ryy_fx );
......@@ -980,8 +981,8 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
exp_wetaux = 0;
move16();
wetaux_fx = BASOP_Util_Divide3232_Scale( drxx_fx, tmp, &exp_wetaux );
exp_wetaux = sub( add( exp_wetaux, exp_drxx ), exp_tmp );
wetaux_fx = BASOP_Util_Divide3232_Scale( drxx_fx, L_add( ryy_fx, EPSILON_FX ), &exp_wetaux );
exp_wetaux = sub( add( exp_wetaux, exp_drxx ), sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][1][bnd] ) ) );
Word16 sqrt_wetaux_fx = 0, exp_sqrt_wetaux = 0;
move16();
......@@ -993,10 +994,6 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx(
move16();
move16();
BASOP_Util_Sqrt_InvSqrt_MantExp( wetaux_fx, exp_wetaux, &sqrt_wetaux_fx, &exp_sqrt_wetaux, &tmp_4, &exp_tmp4 );
tmp_4 = tmp_4;
exp_tmp4 = exp_tmp4;
move16();
move16();
}
ELSE
{
......
......@@ -713,7 +713,7 @@ void ivas_mcmasa_enc_fx(
/* Determine LFE-to-total energy ratio */
FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
hMasa->data.lfeToTotalEnergyRatio_fx[i] = BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] );
hMasa->data.lfeToTotalEnergyRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ) );
hMasa->data.lfeToTotalEnergyRatio_e[i] = add( sub( hMcMasa->lfeLfEne_e[i], hMcMasa->totalLfEne_e[i] ), hMasa->data.lfeToTotalEnergyRatio_e[i] );
move32();
move16();
......@@ -1220,8 +1220,12 @@ void ivas_mcmasa_param_est_enc_fx(
hMcMasa->buffer_energy_q[index - 1] = sub( Q31, ref_e );
move16();
computeDiffuseness_mdft_fx( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, hMcMasa->no_col_avg_diff, diffuseness_vector_fx, hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q, out_exp );
computeDiffuseness_mdft_fx( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, hMcMasa->no_col_avg_diff, diffuseness_vector_fx, hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q, &out_exp[0] );
FOR( i = 1; i < num_freq_bands; i++ )
{
out_exp[i] = out_exp[0];
move16();
}
/* Compute vertical diffuseness, and tune original diffuseness if needed */
IF( !hMcMasa->isHorizontalSetup )
{
......@@ -1243,9 +1247,9 @@ void ivas_mcmasa_param_est_enc_fx(
move32();
IF( hMcMasa->combineRatios )
{
diffuseness_m_fx[0][band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[0][band_m_idx], diffuseness_e[0][band_m_idx], Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), sub( 31, sub( shl( inp_q, 1 ), 31 ) ), &diffuseness_e[0][band_m_idx] );
diffuseness_m_fx[0][band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[0][band_m_idx], diffuseness_e[0][band_m_idx], Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), ref_e, &diffuseness_e[0][band_m_idx] );
move32();
renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( 31, sub( shl( inp_q, 1 ), 31 ) ), &renormalization_factor_diff_e[band_m_idx] );
renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], ref_e, &renormalization_factor_diff_e[band_m_idx] );
move32();
}
ELSE
......@@ -1458,11 +1462,11 @@ void ivas_mcmasa_param_est_enc_fx(
cohPanCoh_e = tempCoh2_e;
move16();
}
IF( GT_32( cohPanCoh_fx, ONE_IN_Q30 ) )
/* IF( GT_32( cohPanCoh_fx, ONE_IN_Q30 ) )
{
cohPanCoh_fx = ONE_IN_Q30;
move32();
}
}*/
cohPanCoh_fx = L_shl_sat( cohPanCoh_fx, cohPanCoh_e ); /*Q31*/
cohPanCoh_e = 0;
move16();
......
......@@ -273,9 +273,10 @@ ivas_error ivas_mct_enc_fx(
map_input_to_cpe_channels_ivas_fx( st_ivas, pdata_fx, data_fx );
/* pre-processing */
Word16 Q_new_out[MCT_MAX_BLOCKS][CPE_CHANNELS];
FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK )
IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata, Q_new_out[cpe_id] ) ) != IVAS_ERR_OK )
{
return error;
}
......@@ -523,7 +524,7 @@ ivas_error ivas_mct_enc_fx(
}
#endif
updt_enc_common_ivas_fx( st );
updt_enc_common_ivas_fx( st, Q_new_out[cpe_id][n] );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
IF( st->hTcxEnc != NULL )
......
......@@ -749,7 +749,7 @@ static Word32 quantize_theta_phi_fx( // Q22
/* Note: (id_th % 2 == 1) must be equal to id_th % 2 */
IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) )
{
id_ph = quantize_phi_chan_compand_fx( phi, phi_hat, no_phi_loc[id_th], (Word16) GT_32( theta_cb[id_th], MC_MASA_THR_ELEVATION ), mc_format );
id_ph = quantize_phi_chan_compand_fx( phi, phi_hat, no_phi_loc[id_th], (Word16) GT_32( L_shr( theta_cb[id_th], Q22 ), MC_MASA_THR_ELEVATION ), mc_format );
*id_phi_remap = id_ph;
move16();
}
......
......@@ -90,8 +90,9 @@ ivas_error ivas_sce_enc_fx(
Word32 fr_bands_fx[1][2 * NB_BANDS]; /* energy in frequency bands */
Word32 lf_E_fx[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */
Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */
Word16 old_inp_16k_fx[1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */
Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */
Word16 old_inp_16k_fx[1][L_INP]; /* buffer of input signal @ 12k8 Q_new-1 */
Word16 Q_new[1] = { 0 };
Word16 vad_hover_flag[1]; /* VAD hangover flag */
Word16 attack_flag[1]; /* attack flag (GSC or TC) */
Word16 loc_harm[1]; /* harmonicity flag */
......@@ -105,6 +106,7 @@ ivas_error ivas_sce_enc_fx(
ivas_error error;
Word16 flag_16k_smc;
Word16 q_input; /*stores q for input_fx*/
move16(); // Q_new
push_wmops( "ivas_sce_enc" );
......@@ -243,10 +245,6 @@ ivas_error ivas_sce_enc_fx(
/*----------------------------------------------------------------*
* Front Pre-processing
*----------------------------------------------------------------*/
FOR( Word16 i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ )
{
Scale_sig( &A_fx[0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12
}
set16_fx( old_wsp_fx[0], 0, L_WSP );
q_old_wsp = Q15;
move16();
......@@ -255,7 +253,12 @@ ivas_error ivas_sce_enc_fx(
&ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0],
realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0],
fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc,
st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate );
st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0]
#ifdef DEBUG_MODE_INFO
,
st->id_element
#endif
);
e_old_wsp[0] = sub( Q15, q_old_wsp );
move16();
IF( error != IVAS_ERR_OK )
......@@ -348,7 +351,7 @@ ivas_error ivas_sce_enc_fx(
Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) );
e_old_wsp[0] = 16;
move16();
IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK )
IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK )
{
return error;
}
......
......@@ -232,11 +232,11 @@ static void stereo_td_channel_extrapolate_fx(
IF( LE_16( g_e, 0 ) )
g = g;
ELSE
g = check_bounds_s( g, negate( shl( 1, 15 - g_e ) ), shl( ONE_HALF, ( 1 - g_e ) ) );
g = check_bounds_s_fx( g, negate( shl( 1, 15 - g_e ) ), shl( ONE_HALF, ( 1 - g_e ) ) );
IF( LE_16( nsr_e, 0 ) )
nsr = nsr;
ELSE
nsr = check_bounds_s( nsr, 0, shl( 1, 15 - ( nsr_e ) ) );
nsr = check_bounds_s_fx( nsr, 0, shl( 1, 15 - ( nsr_e ) ) );
g = shl( g, g_e - 1 ); // q14
nsr = shl( nsr, nsr_e ); // Q15
g_lpc_e = 0;
......
......@@ -233,17 +233,7 @@ void stereo_mdct_core_enc_fx(
}
IF( hCPE->hCoreCoder[0]->igf )
{
#ifdef DEBUGGING
int16_t orig_mdct_stereo_mode_cmdl = hCPE->hStereoMdct->mdct_stereo_mode_cmdl;
hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION;
#endif
initMdctStereoEncData_fx( hCPE->hStereoMdct, STEREO_FORMAT, IVAS_CPE_MDCT, hCPE->element_brate, hCPE->hCoreCoder[0]->bwidth, hCPE->hCoreCoder[0]->igf, hCPE->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 );
#ifdef DEBUGGING
hCPE->hStereoMdct->mdct_stereo_mode_cmdl = orig_mdct_stereo_mode_cmdl;
#endif
stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20 ), 16384 /* 1.0f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate );
stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX10 ), 8192 /* 0.5f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate );
stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20afterACELP ), 20480 /* 1.25f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate );
......
......@@ -1301,21 +1301,6 @@ void initMdctStereoEncData_fx(
set16_fx( hStereoMdct->IGFStereoMode, -1, 2 );
#ifdef DEBUG_FORCE_MDCT_STEREO_MODE
/*set all other members to defined states */
hStereoMdct->fDualMono = 0;
hStereoMdct->fMSstereo = 0;
if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_LR )
{
hStereoMdct->fDualMono = 1;
}
else if ( hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_MS )
{
hStereoMdct->fMSstereo = 1;
}
#endif
hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE;
move16();
set16_fx( hStereoMdct->global_ild, SMDCT_ILD_RANGE >> 1, 2 );
......
......@@ -432,7 +432,6 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects(
BREAK;
default:
return IVAS_ERR_INVALID_MASA_CONFIG;
BREAK;
}
st_ivas = hIvasEnc->st_ivas;
......@@ -733,7 +732,6 @@ ivas_error IVAS_ENC_ConfigureForMasa(
BREAK;
default:
return IVAS_ERR_INVALID_MASA_CONFIG;
BREAK;
}
hIvasEnc->maxBandwidthUser = max_bwidth_user;
......
......@@ -375,3 +375,353 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity
}
return harm;
}
Word16 multi_harm_ivas_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */
const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */
Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */
Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */
Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */
const Word32 total_brate, /* i : total bitrate Q0 */
const Word16 bwidth, /* i : input signal bandwidth Q0 */
Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */
Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */
Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */
Word16 *cor_map_sum, /* i : sum of correlation map Q8 */
Word16 *sp_floor, /* o: noise floor estimate Q7 */
Word16 S_map[] /* o : short-term correlation map Q7 */
)
{
Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT / 4], *pt_mins, harm;
Word16 S[L_FFT / 2], flor, step, tmp16, tmp2, Expx2, Expy2;
Word16 corx2, cory2, corxy, cor, cor_map[L_FFT / 2], *pt1, *pt2, cor_strong;
Word32 L_acc;
Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum;
Word16 mean_dyn;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
/*------------------------------------------------------------------*
* initialization
*------------------------------------------------------------------*/
/* length of the useful part of the spectrum (up to 6.4kHz) */
L = L_FFT / 2;
move16();
if ( EQ_16( bwidth, NB ) )
{
/* length of the useful part of the spectrum (up to 3.6kHz) */
L = 76;
move16();
}
Copy( Bin_E, S, L );
/*------------------------------------------------------------------*
* searching of spectral maxima and minima
*------------------------------------------------------------------*/
pt_mins = ind_mins;
/* index of the first minimum */
if ( LT_16( Bin_E[0], Bin_E[1] ) )
{
*pt_mins++ = 0;
move16();
}
FOR( i = 1; i < L - 1; i++ )
{
/* minimum found */
test();
if ( LT_16( Bin_E[i], Bin_E[i - 1] ) && LT_16( Bin_E[i], Bin_E[i + 1] ) )
{
*pt_mins++ = i;
move16();
}
}
/* index of the last minimum */
IF( LT_16( Bin_E[L - 1], Bin_E[L - 2] ) )
{
*pt_mins++ = sub( L, 1 );
move16();
}
/* total number of minimas found */
N_mins = (Word16) ( pt_mins - ind_mins - 1 );
move16();
/*------------------------------------------------------------------*
* calculation of the spectral floor
* subtraction of the spectral floor
*------------------------------------------------------------------*/
set16_fx( S, 0, L );
IF( N_mins > 0 )
{
L_acc = L_deposit_l( 0 );
FOR( i = 0; i < N_mins; ++i )
{
L_acc = L_mac0( L_acc, Bin_E[ind_mins[i]], 1 );
}
*sp_floor = extract_l( Mult_32_16( L_acc, div_s( 1, N_mins ) ) );
move16();
set16_fx( S, 0, ind_mins[0] );
set16_fx( &S[ind_mins[N_mins]], 0, sub( shr( L_FFT, 1 ), ind_mins[N_mins] ) );
pt_mins = ind_mins;
flor = 0;
move16();
step = 0;
move16();
FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ )
{
/* we are at the end of the next minimum */
IF( EQ_16( i, *pt_mins ) )
{
pt_mins++;
flor = Bin_E[i];
move16(); /*Q7*/
/* calculate the new step */
/*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/
tmp16 = div_s( 1, sub( *pt_mins, i ) ); // Q15
step = msu_r( L_mult( Bin_E[*pt_mins], tmp16 ), Bin_E[i], tmp16 ); // Q7 (15+7+1-16)
}
/* subtract the floor */
S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 );
move16();
/* update the floor */
flor = add( flor, step ); /*Q7*/
}
}
/* Calculate the maximum dynamic per band */
/* since we are processing 40 bins we will use 1/40 in Q15 to find the mean */
/* mean_dyn = mean(&S[L-40], 40);*/
L_acc = L_deposit_l( 0 );
FOR( i = L - 40; i < L; i++ )
{
L_acc = L_mac( L_acc, S[i], 819 /* 1 / 40 in Q15 */ );
}
mean_dyn = round_fx( L_acc ); /*Q7*/
/*mean_dyn = 0.6f * *st_mean_avr_dyn + 0.4f * mean_dyn;*/
L_acc = L_mult( 13107 /*0.4f*/, mean_dyn ); /*Q23*/
L_acc = L_mac( L_acc, 19661 /*0.6f*/, *st_mean_avr_dyn ); /*Q23*/
mean_dyn = round_fx( L_acc ); /*Q7*/
test();
IF( LT_16( mean_dyn, 1229 ) /*9.6f*/ && *cor_strong_limit != 0 )
{
*cor_strong_limit = 0;
move16();
*st_last_sw_dyn = mean_dyn;
move16();
}
ELSE IF( GT_16( sub( mean_dyn, *st_last_sw_dyn ), 576 ) /*4.5f*/ )
{
*cor_strong_limit = 1;
move16();
}
test();
if ( LT_32( total_brate, ACELP_9k60 ) || GT_32( total_brate, ACELP_16k40 ) )
{
*cor_strong_limit = 1;
move16();
}
*st_mean_avr_dyn = mean_dyn;
move16();
/*------------------------------------------------------------------*
* calculation of the correlation map
*------------------------------------------------------------------*/
set16_fx( cor_map, 0, L );
IF( N_mins > 0 )
{
Lcorx2 = L_deposit_l( 0 );
Lcorxy = L_deposit_l( 0 );
stemp = ind_mins[0];
move16();
Lcory2 = L_mult( old_S[stemp], old_S[stemp] );
k = 1;
move16();
FOR( i = add( stemp, 1 ); i <= ind_mins[N_mins]; i++ )
{
IF( EQ_16( i, ind_mins[k] ) )
{
/* include the last peak point (new minimum) to the corr. sum */
#ifdef BASOP_NOGLOB
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
#else /* BASOP_NOGLOB */
Lcory2 = L_mac( Lcory2, old_S[i], old_S[i] );
#endif /* BASOP_NOGLOB */
/* calculation of the norm. peak correlation */
test();
IF( Lcorx2 != 0 && Lcory2 != 0 )
{
/* corxy * corxy*/
tmp16 = sub( norm_l( Lcorxy ), 1 );
corxy = extract_h( L_shl( Lcorxy, tmp16 ) );
corxy = mult_r( corxy, corxy );
/* (corx2 * cory2) */
Expx2 = norm_l( Lcorx2 );
Expy2 = norm_l( Lcory2 );
corx2 = extract_h( L_shl( Lcorx2, Expx2 ) );
cory2 = extract_h( L_shl( Lcory2, Expy2 ) );
corx2 = mult_r( corx2, cory2 );
Expx2 = add( Expy2, Expx2 );
/* Validate num < den */
cor = sub( corx2, corxy );
cor = shr( cor, 15 );
/* Add 1 to tmp16 & shr by 2 if corxy > corx2 */
tmp16 = sub( tmp16, cor );
corxy = shl( corxy, cor );
corxy = shl( corxy, cor );
/* cor = corxy * corxy / (corx2 * cory2) */
corxy = div_s( corxy, corx2 );
#ifdef BASOP_NOGLOB
cor = shr_o( corxy, sub( shl( tmp16, 1 ), Expx2 ), &Overflow ); /* Q15 */
#else /* BASOP_NOGLOB */
cor = shr( corxy, sub( shl( tmp16, 1 ), Expx2 ) ); /* Q15 */
#endif /* BASOP_NOGLOB */
}
ELSE
{
cor = 0;
move16();
}
/* save the norm. peak correlation in the correlation map */
FOR( j = ind_mins[k - 1]; j < ind_mins[k]; j++ )
{
old_S[j] = S[j];
move16();
S[j] = shr( cor, 8 );
move16();
cor_map[j] = cor;
move16();
}
Lcorx2 = L_deposit_l( 0 );
Lcory2 = L_deposit_l( 0 );
Lcorxy = L_deposit_l( 0 );
k++;
}
#ifdef BASOP_NOGLOB
Lcorx2 = L_mac_o( Lcorx2, S[i], S[i], &Overflow );
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
Lcorxy = L_mac_o( Lcorxy, S[i], old_S[i], &Overflow );
#else /* BASOP_NOGLOB */
Lcorx2 = L_mac( Lcorx2, S[i], S[i] );
Lcory2 = L_mac( Lcory2, old_S[i], old_S[i] );
Lcorxy = L_mac( Lcorxy, S[i], old_S[i] );
#endif
}
Copy( S, old_S, ind_mins[0] );
Copy( &S[ind_mins[N_mins]], &old_S[ind_mins[N_mins]], sub( L, ind_mins[N_mins] ) );
}
ELSE
{
*sp_floor = Bin_E[0];
move16();
}
*sp_floor = mult( *sp_floor, 14231 /* 1.0f / logf( 10.0f ) in Q15 */ );
move16(); /* Convert to log10() */
/*------------------------------------------------------------------*
* updating of the long-term correlation map
* summation of the long-term correlation map
*------------------------------------------------------------------*/
Lcor_map_LT_sum = L_deposit_l( 0 );
tmp2 = 0;
move16();
cor_strong = 0;
move16();
pt1 = cor_map_LT;
move16();
pt2 = cor_map;
move16();
FOR( i = 0; i < L; i++ )
{
/* tmp2 += S[i]; */
tmp2 = add( tmp2, shl( S[i], 1 ) ); /* tmp2 in Q8; max value is 128) */
/* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */
*pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 );
move16();
/* cor_map_LT_sum += *pt1 */
Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */
if ( GT_16( *pt1, 31130 ) /*0.95f*/ )
{
cor_strong = 1;
move16();
}
pt1++;
pt2++;
}
IF( EQ_16( bwidth, NB ) )
{
/* cor_map_LT_sum *= 1.53f; */
/* tmp2 *= 1.53f; */
Lcor_map_LT_sum = L_shl( Mult_32_16( Lcor_map_LT_sum, 25068 /* 1.53f in Q14 */ ), 1 );
tmp2 = round_fx( L_mac( L_mult( tmp2, 32767 ), tmp2, 17367 /* 0.53 in Q15 */ ) );
}
*cor_map_sum = tmp2;
move16();
/* final decision about multi-harmonicity */
harm = 0;
move16();
test();
if ( ( L_msu0( Lcor_map_LT_sum, *multi_harm_limit, 64 ) > 0 ) || ( cor_strong != 0 ) )
{
harm = 1;
move16();
}
/*------------------------------------------------------------------*
* updating of the decision threshold
*------------------------------------------------------------------*/
stemp = add( *multi_harm_limit, THR_CORR_STEP_FX );
if ( GT_32( Lcor_map_LT_sum, THR_CORR_FX ) ) /* Q15 */
{
/* *multi_harm_limit -= THR_CORR_STEP_FX */
stemp = sub( *multi_harm_limit, THR_CORR_STEP_FX );
}
stemp = s_min( stemp, THR_CORR_MAX_FX );
*multi_harm_limit = s_max( stemp, THR_CORR_MIN_FX );
move16();
IF( N_mins <= 0 )
{
set16_fx( old_S, 0, L );
}
IF( S_map != NULL )
{
Copy( S, S_map, L );
}
return harm;
}
......@@ -31,7 +31,6 @@
*******************************************************************************************************/
#include <stdint.h>
#include "control.h"
#include "options.h" /* Compilation switches */
#include "cnst.h" /* Common constants */
#include "prot.h" /* Function prototypes */
......
......@@ -2353,7 +2353,7 @@ void noise_est_ivas_fx(
{
i = 0;
move16();
*loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
*loc_harm = multi_harm_ivas_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
move16();
}
......
......@@ -4449,6 +4449,21 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity
Word16 S_map[] /* o : short-term correlation map Q7 */
);
Word16 multi_harm_ivas_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */
const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */
Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */
Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */
Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */
const Word32 total_brate, /* i : total bitrate Q0 */
const Word16 bwidth, /* i : i signal bandwidth Q0 */
Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */
Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */
Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */
Word16 *cor_map_sum, /* i : sum of correlation map Q8 */
Word16 *sp_floor, /* o: noise floor estimate Q7 */
Word16 S_map[] /* o : short-term correlation map Q7 */
);
void pvq_encode_frame_fx(
BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
const Word16 *coefs_norm, /* i : normalized coefficients to encode */
......
......@@ -36,6 +36,7 @@
#include <stdint.h>
#include "options.h"
#include "typedef.h"
#include "cnst.h"
#include "wmc_auto.h"
......
......@@ -35,7 +35,7 @@
#include "prot_fx.h" /* Function prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
#include "rom_com.h"
#include "enh32.h"
#include "stl.h"
#include "prot.h"
/*--------------------------------------------------------------------------*
......
......@@ -2469,7 +2469,11 @@ void swb_tbe_enc_fx(
FOR( i = 0; i < L_SHB_LAHEAD; i++ )
{
L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */
#ifdef BASOP_NOGLOB
shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */
#else
shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */
#endif
}
IF( exp < 0 )
{
......
......@@ -690,7 +690,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur
pWindow = tnsAcfWindow_fx;
n = sub( iEndLine, iStartLine );
assert( n < (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) );
assert( n <= (Word16) ( sizeof( tmpbuf ) / sizeof( Word16 ) ) );
FOR( i = 0; i < n; i++ )
{
tmpbuf[i] = round_fx_sat( L_shl( pSpectrum[iStartLine + i], shift ) ); // using round_fx_sat to address corner case
......
......@@ -52,7 +52,8 @@
void updt_enc_common_ivas_fx(
Encoder_State *st /* i/o: encoder state structure */
Encoder_State *st, /* i/o: encoder state structure */
const Word16 Q_new /* i : CUrrent frame scaling */
)
{
/*---------------------------------------------------------------------*
......@@ -81,6 +82,8 @@ void updt_enc_common_ivas_fx(
move16();
st->last_coder_type_raw = st->coder_type_raw;
move16();
st->prev_Q_new = Q_new;
move16();
test();
IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )
......
......@@ -4,7 +4,6 @@
#include <stdint.h>
#include "options.h"
#include "control.h"
#include "cnst.h"
//#include "prot_fx.h"
#include "rom_com_fx.h"
......