diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index e8d44551c4b0a908dc458c4af415c491392201da..7d892f8c813f92e41bfc492d3e1f2edec31d6ff7 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -2170,6 +2170,7 @@ uint16_t get_indice_1( * Reset the buffer of encoder indices *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void reset_indices_enc( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 max_num_indices /* i : max number of indices */ @@ -2187,6 +2188,28 @@ void reset_indices_enc( return; } +#else +void reset_indices_enc( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 max_num_indices /* i : max number of indices */ +) +{ + Word16 i; + + hBstr->nb_bits_tot = 0; + move16(); + hBstr->nb_ind_tot = 0; + move16(); + + FOR( i = 0; i < max_num_indices; i++ ) + { + hBstr->ind_list[i].nb_bits = -1; + move16(); + } + + return; +} +#endif /*-------------------------------------------------------------------* * reset_indices_dec() diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index b84a8b772421828ece91537939e4a693cb332c66..bd8135d8ea2c30980b7199eb29a6a1ece1928099 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -560,6 +560,27 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } +#if 1 // TODO: To be removed later + if ( fb_cfg->num_out_chans == 0 ) + { + hFbMixer->ppFilterbank_inFR_re[i] = NULL; + hFbMixer->ppFilterbank_inFR_im[i] = NULL; + } + else + { + j = fb_cfg->remix_order[i]; + + if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + + if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + } +#endif } IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) @@ -579,6 +600,13 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); +#if 1 // TODO: To be removed later + if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); +#endif } test(); @@ -598,6 +626,22 @@ ivas_error ivas_FB_mixer_open_fx( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } +#if 1 // TODO: To be removed later + float *pTemp_mem; + if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); + } + for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + { + hFbMixer->prior_mixer[i][j] = pTemp_mem; + pTemp_mem += IVAS_MAX_NUM_BANDS; + set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } +#endif } IF( !spar_reconfig_flag ) @@ -618,6 +662,12 @@ ivas_error ivas_FB_mixer_open_fx( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder fixed" ); } +#if 1 // TODO: To be removed later + if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } +#endif } } @@ -634,6 +684,17 @@ ivas_error ivas_FB_mixer_open_fx( FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { +#if 1 // TODO: To be removed later + if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + + if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } +#endif IF( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = (Word32 *) malloc( sizeof( Word32 ) * pActive_bins_per_band[j] ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -666,6 +727,12 @@ ivas_error ivas_FB_mixer_open_fx( { return error; } +#if 1 // TODO: To be removed later + if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } *hFbMixer_out = hFbMixer; diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 82a5ba5884fad693d101e4992c4775fe59cc84e6..458e473aaf848d7093a359a2f0f54cb6e8a2c926 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -1140,6 +1140,10 @@ void ivas_param_ism_config_fx( hParamIsm->last_dmx_gain_e = 1; move16(); set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); +#if 1 // TODO: To be removed later + hParamIsm->last_dmx_gain = 1.0f; + set_f( hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS ); +#endif return; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 670917fdd7a25f4a638fe83ea97ba2350dead88c..8cbf567695e92e24d4b149c86aac6bf550e0d1eb 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -339,19 +339,29 @@ ivas_error pre_proc_ivas( ); ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame*/ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ - float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ - float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* i/o: LP prediction errors */ - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ + Encoder_State *st, /* i/o: encoder state structure */ + float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ + float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ + float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const int16_t input_frame, /* i : frame length */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t sr_core, /* i : core-coder sampling rate */ + float *ener, /* o : residual energy from Levinson-Durbin */ +#ifndef IVAS_FLOAT_FIXED + float A[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ +#else + Word16 A_fx[NB_SUBFR16k * (M + 1)], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_Fx[NB_SUBFR16k * (M + 1)], /* i/o: weighted A(z) unquantized for subframes */ +#endif + float epsP[M + 1], /* i/o: LP prediction errors */ +#ifndef IVAS_FLOAT_FIXED + float lsp_new[M], /* i/o: LSPs at the end of the frame */ + float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ +#else + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ +#endif ); /*! r: number of clipped samples */ @@ -1436,12 +1446,7 @@ ivas_error ivas_ism_metadata_dec( *----------------------------------------------------------------------------------*/ /*! r: ISM format mode */ -#ifdef IVAS_FLOAT_FIXED -ISM_MODE ivas_ism_mode_select( - const Word16 nchan_inp, /* i : number of input objects */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); -#else +#ifndef IVAS_FLOAT_FIXED ISM_MODE ivas_ism_mode_select( const int16_t nchan_inp, /* i : number of input objects */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -2797,7 +2802,21 @@ void stereo_tdm_combine_fx( const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ const Word16 tdm_ratio_idx /* i : TDM ratio index */ ); - +#ifdef IVAS_FLOAT_FIXED +Word16 tdm_lp_comparison_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + Encoder_State *st, /* i/o: Encoder structure */ + Word32 *speech_buff, /* i : Current speech frame Q_speech */ + const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ + const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ + const Word16 m, /* i : filter length */ + const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ + const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 L_frame, /* i : frame length */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ + Word16 Q_speech ); +#else /*! r: replication decision; 1 = Use old LP */ int16_t tdm_lp_comparison( STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ @@ -2812,7 +2831,7 @@ int16_t tdm_lp_comparison( const int16_t L_frame, /* i : frame length */ const int32_t element_brate_wo_meta /* i : element bitrate without metadata */ ); - +#endif /*! r: replication decision; 1 = Use old LP */ void tdm_ol_pitch_comparison( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index adbe2b0fe7c2eacec832bdd1d5fda6c7945c45b1..b3b2914fc1a2c33b1fd53b10efa5670064968097 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1353,6 +1353,15 @@ void stereo_tcx_init_dec_fx( const Word16 last_element_mode /* i : element mode of previous frame */ ); +void stereo_icBWE_enc_ivas_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel */ + const Word16 shb_speech_ref_e, /* i : SHB speech ref channel */ + Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel */ + Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ + const Word32 *voice_factors_fx /* i : voicing factors Q31 */ +); + void initMdctStereoDecData_fx( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const Word16 igf, /* i : flag indicating IGF activity */ @@ -1361,6 +1370,16 @@ void initMdctStereoDecData_fx( const Word16 bwidth /* i : audio bandwidth */ ); +void stereo_tdm_downmix_ivas_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i : TD stereo IVAS encoder structure */ + Word16 *Left_in_fx, /* Qx */ + Word16 *Right_in_fx, /* Qx */ + const Word16 input_frame, /* i : Number of samples */ + const Word16 tdm_ratio_idx, /* i : TDM ratio index */ + const Word16 tdm_SM_flag, /* i : channel combination scheme flag */ + const Word16 tdm_ratio_idx_SM /* i : TDM ratio index for SM mode */ +); + void stereo_mdct_init_bands_fx( const Word16 L_frame, /* i : frame length */ const Word16 tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */ @@ -3068,4 +3087,9 @@ void unclr_classifier_td_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); #endif + +ISM_MODE ivas_ism_mode_select( + const Word16 nchan_inp, /* i : number of input objects */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 86f6fdadf685ec8e03c5494fafbe7ea8b6cda3d2..ad8fe5a8d1b4ce26dc98f9dbfc498a4762411c51 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -564,6 +564,19 @@ const Word16 pow_10_q11[128] = { }; #ifdef IVAS_FLOAT_FIXED + +// Q12 +const Word16 icbwe_gsMapping_tbl_fx[16] = { -8192, -5527, -3935, -2907, -2289, -1824, -1404, -1035, -692, -404, -286, -204, -81, 0, 163, 327 }; + +// Q12 +const Word16 icbwe_gsMappingDFT_tbl_fx[128] = { + -20480, -18432, -16384, -14336, -12288, -10240, -7782, -6338, -6144, -5926, -5694, -5640, -5363, -5164, -4475, -4441, -4237, -4213, -4162, -4111, -4019, -3972, -3921, + -3852, -3808, -3740, -3696, -3629, -3578, -3508, -3442, -3421, -3375, -3292, -3245, -3190, -3145, -3111, -3099, -3075, -3042, -3025, -3006, -2990, -2966, -2944, -2904, + -2886, -2867, -2827, -2803, -2782, -2754, -2736, -2718, -2698, -2670, -2643, -2628, -2601, -2578, -2557, -2532, -2512, -2495, -2474, -2455, -2435, -2415, -2396, -2378, + -2359, -2342, -2322, -2306, -2283, -2257, -2227, -2197, -2163, -2129, -2087, -2042, -1991, -1935, -1880, -1822, -1765, -1707, -1652, -1596, -1542, -1481, -1422, -1362, + -1308, -1253, -1194, -1140, -1082, -1026, -970, -902, -833, -765, -700, -639, -581, -517, -453, -390, -329, -270, -216, -164, -117, -75, -38, 0, 30, 63, 91, 122, 153, 187, 225, 270, 321 +}; + const Word32 pow_10_q23[14] = { 2364231, 2652711, 3339565, 4204263, 5803499, 8011059, 8388608, 6818517, 7222539, 5292854, 4204263, 6977341, 7919357, 8388608 }; diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 0e0714bea27162bea0b81092e5abfb88c5f017fe..67dabdce32a7028ec56b6e7f62a6b34bac99073e 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -110,6 +110,8 @@ extern const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[]; extern const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1]; extern const Word32 tdm_ratio_tabl_fx_Q24[TDM_NQ + 1]; extern const UWord32 tdm_den_ratio_tabl_fx[]; +extern const Word16 icbwe_gsMapping_tbl_fx[]; // Q12 +extern const Word16 icbwe_gsMappingDFT_tbl_fx[]; // Q12 /* LSFs Intra-frame prediction tables */ extern const Word16 tdm_LSF_MEAN_RE_USE_OUT_fx[M]; diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index 495890355d695b3ef9d889936e57645451b42894..ff7a9c5bd6783d0bc3a10e91833ece8cdc33996b 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -238,7 +238,7 @@ void GetParameters_fx( #undef WMC_TOOL_SKIP IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) ) { - GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits ); + GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits ); } } } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d6fedf92ca6264cc2e616aaf759919774a84dcbb..93723ad4816a2b62e045afd676aaf4f8137c7e9c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1769,6 +1769,19 @@ void wtda_fx( const Word16 L /* i : length */ ); +#ifdef IVAS_FLOAT_FIXED +void wtda_ivas_fx( + Word16 *new_audio, /* i : input audio Q0 */ + Word16 *Q, /* i/o : Q of input/Output Audio */ + Word16 *wtda_audio, /* o : windowed audio Qout */ + Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ + Word16 *Qold_wtda, + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ +); +#endif + #ifdef IVAS_FLOAT_FIXED void wtda_ext_fx( const Word16 *new_audio, /* i : input audio (Q_in) */ @@ -5950,6 +5963,14 @@ Word32 dotp_fixed_32( Word16 *res_q /*stores resultant Q*/ ); +Word32 dotp_fixed_ivas_fx( + const Word32 x[], /* i : vector x[] */ + Word16 x_e, + const Word32 y[], /* i : vector y[] */ + Word16 y_e, + const Word16 n, /* i : vector length */ + Word16 *out_e ); + #ifdef IVAS_FLOAT_FIXED Word32 dotp_fixed_guarded( const Word32 x[], /* i : vector x[] */ @@ -9669,6 +9690,11 @@ Word32 sum2_f_16_gb_fx( const Word16 lvec, /* i : length of input vector */ Word16 gb ); +Word32 sum_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ); + Word16 vq_dec_lvq_ivas_fx( Word16 sf_flag, /* i : safety net flag */ Word16 x[], /* o : Decoded vector Q(x2.56)*/ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index e23b7507a6d814ef04f0635424e9c9539cc72dd9..e65652e03e911224c28a8491753311fcffb7809b 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -418,6 +418,29 @@ Word32 sum2_fx( /* o : sum of all squared vector elements return L_tmp; } +Word32 sum_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ) +{ + Word16 i; + Word32 tmp; + + tmp = 0; + Word16 exp = 0; + move32(); + move16(); + FOR( i = 0; i < lvec; i++ ) + { + tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, vec[i], *e, &exp ); + } + + *e = exp; + move16(); + + return tmp; +} + Word32 sum2_fx_mod( /* o : sum of all squared vector elements Q(2x+1 -5)*/ const Word16 *vec, /* i : input vector Qx*/ const Word16 lvec /* i : length of input vector */ @@ -4425,6 +4448,32 @@ Word32 dotp_fixed_guarded( return suma; } #endif + + +Word32 dotp_fixed_ivas_fx( + const Word32 x[], /* i : vector x[] */ + Word16 x_e, + const Word32 y[], /* i : vector y[] */ + Word16 y_e, + const Word16 n, /* i : vector length */ + Word16 *out_e ) +{ + Word16 i, exp; + Word32 suma = 0; + + exp = 31; + move16(); + + FOR( i = 0; i < n; i++ ) + { + suma = BASOP_Util_Add_Mant32Exp( suma, exp, Mpy_32_32( x[i], y[i] ), x_e + y_e, &exp ); + } + + *out_e = exp; + move16(); + return suma; +} + /*-------------------------------------------------------------------* * v_mult() * diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index 12ca93032d7e69fa30d7062fb39fb10aed370992..e94789a6a8cbb08eba68d35fd04d2758a86aa042 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -411,104 +411,167 @@ void wtda_fx( } return; } -#ifdef IVAS_CODE - -void wtda_ext( - const float *new_audio, /* i : input audio */ - float *wtda_audio, /* o : windowed audio */ - const int16_t left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ - const int16_t right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const int16_t L, /* i : length */ - const uint16_t kernel_type /* i : transform kernel type (0 - 3) */ + + +#ifdef IVAS_FLOAT_FIXED +void wtda_ivas_fx( + Word16 *new_audio, /* i : input audio Q0 */ + Word16 *Q, /* i/o : Q of input/Output Audio */ + Word16 *wtda_audio, /* o : windowed audio Qout */ + Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ + Word16 *Qold_wtda, + const Word16 left_mode, /* i : window overlap of previous frame (0: full, 2: none, or 3: half) */ + const Word16 right_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const Word16 L /* i : length */ ) { - const float sign_left = ( kernel_type >= 2 ? -1.f : 1.f ); - const float sign_right = ( kernel_type & 1 ? 1.f : -1.f ); - int16_t i, decimate, decay; - int16_t n, windecay48, windecay16; - const float *allsig_l, *allsig_r; - float win_right[R2_48]; - float win_int_left[R1_16]; - float win_left[R1_48]; - float win_int_right[R2_16]; + Word16 i, decimate, decay; + Word16 n, windecay48, windecay16; + const Word16 *allsig_l, *allsig_r; + Word16 win_right[R2_48]; + Word16 win_int_left[R1_16]; + Word16 win_left[R1_48]; + Word16 win_int_right[R2_16]; tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L ); - decimate = 1; /* L_FRAME 48k */ + decimate = 1; /* L_FRAME48k */ + move16(); decay = 0; - windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48; + move16(); + windecay48 = ( 2 * ( (Word64) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48; + move16(); - if ( L == L_FRAME32k || L == L_FRAME16k ) + test(); + IF( EQ_16( L, L_FRAME32k ) || EQ_16( L, L_FRAME16k ) ) { decimate = 3; + move16(); decay = 1; + move16(); } - else if ( L == L_FRAME8k ) + ELSE IF( EQ_16( L, L_FRAME8k ) ) { decimate = 6; + move16(); decay = 2; + move16(); } - n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); + n = extract_l( Mpy_32_32( L, 603979776 /* N_ZERO_MDCT_NS / FRAME_SIZE_NS in Q31 */ ) ); - windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16; + windecay16 = ( 2 * ( L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16; + move16(); - allsig_r = new_audio + n; - allsig_l = new_audio + n - L; + /* algorithmic delay reduction */ + i = 0; + move16(); - if ( L == L_FRAME32k ) + IF( old_wtda == NULL ) + { + allsig_r = new_audio + n; + allsig_l = new_audio + n - L; + } + ELSE { - for ( i = 0; i < L / 2 - n; i += 2 ) + /* Rescale signals if Q are not identical */ + IF( GT_16( *Qold_wtda, *Q ) ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1] * win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] + sign_right * allsig_r[L / 2 + i] * win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16]; - wtda_audio[i + 1] = -allsig_r[L / 2 - ( i + 1 ) - 1] * win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i + 1] * win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48]; + Copy_Scale_sig( old_wtda, old_wtda, L, sub( *Q, *Qold_wtda ) ); + *Qold_wtda = *Q; + move16(); + } + ELSE IF( LT_16( *Qold_wtda, *Q ) ) + { + Copy_Scale_sig( new_audio, new_audio, L, sub( *Qold_wtda, *Q ) ); + *Q = *Qold_wtda; + move16(); } - for ( i = L / 2 - n; i < L / 2; i += 2 ) + allsig_r = new_audio + n; + allsig_l = old_wtda + n; + } + + IF( EQ_16( L, L_FRAME32k ) ) + { + FOR( i = 0; i < L / 2 - n; i += 2 ) + { + wtda_audio[i] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] ), + allsig_r[L / 2 + i], win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16] ) ); + move16(); + wtda_audio[i + 1] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i + 1], win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48] ) ); + move16(); + } + + FOR( i = L / 2 - n; i < L / 2; i += 2 ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1]; - wtda_audio[i + 1] = -allsig_r[L / 2 - ( i + 1 ) - 1]; + wtda_audio[i] = shr( negate( allsig_r[L / 2 - i - 1] ), 1 ); + move16(); + wtda_audio[i + 1] = shr( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), 1 ); + move16(); } - for ( i = 0; i < n; i += 2 ) + + FOR( i = 0; i < n; i += 2 ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[( i / 2 ) * decimate + decay] - new_audio[n - i - 1]; - wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - new_audio[n - ( i + 1 ) - 1]; + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); + move16(); + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( allsig_l[i + 1], win_int_left[i / 2] ), + new_audio[n - ( i + 1 ) - 1], MAX16B ) ); + move16(); } - for ( i = n; i < L / 2; i += 2 ) + FOR( i = n; i < L / 2; i += 2 ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[( i / 2 ) * decimate + decay] - allsig_l[L - i - 1] * win_left[( L / 2 - i / 2 ) * decimate - 1 - decay]; - wtda_audio[i + L / 2 + 1] = sign_left * allsig_l[i + 1] * win_int_left[i / 2] - allsig_l[L - ( i + 1 ) - 1] * win_int_left[L / 2 - i / 2 - 1]; + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), + allsig_l[L - i - 1], win_left[( L / 2 - i / 2 ) * decimate - 1 - decay] ) ); + move16(); + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( allsig_l[i + 1], win_int_left[i / 2] ), + allsig_l[L - ( i + 1 ) - 1], win_int_left[L / 2 - i / 2 - 1] ) ); + move16(); } } - else + ELSE { - for ( i = 0; i < L / 2 - n; i++ ) + FOR( i = 0; i < L / 2 - n; i++ ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1] * win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] + sign_right * allsig_r[L / 2 + i] * win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48]; + wtda_audio[i] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i], win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48] ) ); + move16(); } - for ( i = L / 2 - n; i < L / 2; i++ ) + FOR( i = L / 2 - n; i < L / 2; i++ ) { - wtda_audio[i] = -allsig_r[L / 2 - i - 1]; + wtda_audio[i] = shr( negate( allsig_r[L / 2 - i - 1] ), 1 ); + move16(); } - for ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[i * decimate + decay] - new_audio[n - i - 1]; + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[i * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); + move16(); } - for ( i = n; i < L / 2; i++ ) + FOR( i = n; i < L / 2; i++ ) { - wtda_audio[i + L / 2] = sign_left * allsig_l[i] * win_left[i * decimate + decay] - allsig_l[L - i - 1] * win_left[L * decimate - i * decimate - 1 - decay]; + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[i * decimate + decay] ), + allsig_l[L - i - 1], win_left[L * decimate - i * decimate - 1 - decay] ) ); + move16(); } } + IF( old_wtda != NULL ) + { + Copy( new_audio, old_wtda, L ); + } + return; } - #endif + #ifdef IVAS_FLOAT_FIXED void wtda_ext_fx( const Word16 *new_audio, /* i : input audio (Q_in) */ @@ -567,11 +630,11 @@ void wtda_ext_fx( { FOR( i = 0; i < L / 2 - n; i += 2 ) { - wtda_audio[i] = round_fx( L_mac( L_mult( negate( allsig_r[L / 2 - i - 1] ), win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] ), - allsig_r[L / 2 + i], win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16] ) ); // q_in + wtda_audio[i] = round_fx( L_mac0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] ), + allsig_r[L / 2 + i], win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16] ) ); // q_in move16(); - wtda_audio[i + 1] = round_fx( L_mac( L_mult( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] ), - allsig_r[L / 2 + i + 1], win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48] ) ); // q_in + wtda_audio[i + 1] = round_fx( L_mac0( L_mult0( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i + 1], win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48] ) ); // q_in move16(); } } @@ -579,20 +642,20 @@ void wtda_ext_fx( { FOR( i = 0; i < L / 2 - n; i += 2 ) { - wtda_audio[i] = round_fx( L_msu( L_mult( negate( allsig_r[L / 2 - i - 1] ), win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] ), - allsig_r[L / 2 + i], win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16] ) ); // q_in + wtda_audio[i] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_int_right[3 * L_FRAME16k / 2 - i / 2 - 1 - windecay16] ), + allsig_r[L / 2 + i], win_int_right[3 * L_FRAME16k / 2 + i / 2 - windecay16] ) ); // q_in move16(); - wtda_audio[i + 1] = round_fx( L_msu( L_mult( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] ), - allsig_r[L / 2 + i + 1], win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48] ) ); // q_in + wtda_audio[i + 1] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), win_right[( 3 * L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i + 1], win_right[( 3 * L_FRAME16k / 2 + 1 + i / 2 ) * decimate - decay - 1 - windecay48] ) ); // q_in move16(); } } FOR( i = L / 2 - n; i < L / 2; i += 2 ) { - wtda_audio[i] = negate( allsig_r[L / 2 - i - 1] ); // q_in + wtda_audio[i] = shr( negate( allsig_r[L / 2 - i - 1] ), 1 ); // q_in move16(); - wtda_audio[i + 1] = negate( allsig_r[L / 2 - ( i + 1 ) - 1] ); // q_in + wtda_audio[i + 1] = shr( negate( allsig_r[L / 2 - ( i + 1 ) - 1] ), 1 ); // q_in move16(); } @@ -600,21 +663,21 @@ void wtda_ext_fx( { FOR( i = 0; i < n; i += 2 ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( negate( allsig_l[i] ), win_left[( i / 2 ) * decimate + decay] ), - new_audio[n - i - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( negate( allsig_l[i] ), win_left[( i / 2 ) * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); // q_in move16(); - wtda_audio[i + L / 2 + 1] = round_fx( L_msu( L_mult( negate( allsig_l[i + 1] ), win_int_left[i / 2] ), - new_audio[n - ( i + 1 ) - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( negate( allsig_l[i + 1] ), win_int_left[i / 2] ), + new_audio[n - ( i + 1 ) - 1], MAX16B ) ); // q_in move16(); } FOR( i = n; i < L / 2; i += 2 ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( negate( allsig_l[i] ), win_left[( i / 2 ) * decimate + decay] ), - allsig_l[L - i - 1], win_left[( L / 2 - i / 2 ) * decimate - 1 - decay] ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( negate( allsig_l[i] ), win_left[( i / 2 ) * decimate + decay] ), + allsig_l[L - i - 1], win_left[( L / 2 - i / 2 ) * decimate - 1 - decay] ) ); // q_in move16(); - wtda_audio[i + L / 2 + 1] = round_fx( L_msu( L_mult( negate( allsig_l[i + 1] ), win_int_left[i / 2] ), - allsig_l[L - ( i + 1 ) - 1], win_int_left[L / 2 - i / 2 - 1] ) ); // q_in + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( negate( allsig_l[i + 1] ), win_int_left[i / 2] ), + allsig_l[L - ( i + 1 ) - 1], win_int_left[L / 2 - i / 2 - 1] ) ); // q_in move16(); } } @@ -622,21 +685,21 @@ void wtda_ext_fx( { FOR( i = 0; i < n; i += 2 ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), - new_audio[n - i - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); // q_in move16(); - wtda_audio[i + L / 2 + 1] = round_fx( L_msu( L_mult( allsig_l[i + 1], win_int_left[i / 2] ), - new_audio[n - ( i + 1 ) - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( allsig_l[i + 1], win_int_left[i / 2] ), + new_audio[n - ( i + 1 ) - 1], MAX16B ) ); // q_in move16(); } FOR( i = n; i < L / 2; i += 2 ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), - allsig_l[L - i - 1], win_left[( L / 2 - i / 2 ) * decimate - 1 - decay] ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[( i / 2 ) * decimate + decay] ), + allsig_l[L - i - 1], win_left[( L / 2 - i / 2 ) * decimate - 1 - decay] ) ); // q_in move16(); - wtda_audio[i + L / 2 + 1] = round_fx( L_msu( L_mult( allsig_l[i + 1], win_int_left[i / 2] ), - allsig_l[L - ( i + 1 ) - 1], win_int_left[L / 2 - i / 2 - 1] ) ); // q_in + wtda_audio[i + L / 2 + 1] = round_fx( L_msu0( L_mult0( allsig_l[i + 1], win_int_left[i / 2] ), + allsig_l[L - ( i + 1 ) - 1], win_int_left[L / 2 - i / 2 - 1] ) ); // q_in move16(); } } @@ -647,8 +710,8 @@ void wtda_ext_fx( { FOR( i = 0; i < L / 2 - n; i++ ) { - wtda_audio[i] = round_fx( L_mac( L_mult( negate( allsig_r[L / 2 - i - 1] ), win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] ), - allsig_r[L / 2 + i], win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48] ) ); // q_in + wtda_audio[i] = round_fx( L_mac0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i], win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48] ) ); // q_in move16(); } } @@ -656,15 +719,15 @@ void wtda_ext_fx( { FOR( i = 0; i < L / 2 - n; i++ ) { - wtda_audio[i] = round_fx( L_msu( L_mult( negate( allsig_r[L / 2 - i - 1] ), win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] ), - allsig_r[L / 2 + i], win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48] ) ); // q_in + wtda_audio[i] = round_fx( L_msu0( L_mult0( negate( allsig_r[L / 2 - i - 1] ), win_right[3 * L / 2 * decimate - ( i + 1 ) * decimate + decay - windecay48] ), + allsig_r[L / 2 + i], win_right[3 * L / 2 * decimate - 1 + ( i + 1 ) * decimate - decay - windecay48] ) ); // q_in move16(); } } FOR( i = L / 2 - n; i < L / 2; i++ ) { - wtda_audio[i] = negate( allsig_r[L / 2 - i - 1] ); // q_in + wtda_audio[i] = shr( negate( allsig_r[L / 2 - i - 1] ), 1 ); // q_in move16(); } @@ -672,15 +735,15 @@ void wtda_ext_fx( { FOR( i = 0; i < n; i++ ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( negate( allsig_l[i] ), win_left[i * decimate + decay] ), - new_audio[n - i - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( negate( allsig_l[i] ), win_left[i * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); // q_in move16(); } FOR( i = n; i < L / 2; i++ ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( negate( allsig_l[i] ), win_left[i * decimate + decay] ), - allsig_l[L - i - 1], win_left[L * decimate - i * decimate - 1 - decay] ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( negate( allsig_l[i] ), win_left[i * decimate + decay] ), + allsig_l[L - i - 1], win_left[L * decimate - i * decimate - 1 - decay] ) ); // q_in move16(); } } @@ -688,15 +751,15 @@ void wtda_ext_fx( { FOR( i = 0; i < n; i++ ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( allsig_l[i], win_left[i * decimate + decay] ), - new_audio[n - i - 1], MAX16B ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[i * decimate + decay] ), + new_audio[n - i - 1], MAX16B ) ); // q_in move16(); } FOR( i = n; i < L / 2; i++ ) { - wtda_audio[i + L / 2] = round_fx( L_msu( L_mult( allsig_l[i], win_left[i * decimate + decay] ), - allsig_l[L - i - 1], win_left[L * decimate - i * decimate - 1 - decay] ) ); // q_in + wtda_audio[i + L / 2] = round_fx( L_msu0( L_mult0( allsig_l[i], win_left[i * decimate + decay] ), + allsig_l[L - i - 1], win_left[L * decimate - i * decimate - 1 - decay] ) ); // q_in move16(); } } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index f25becbc9980b374ad5707c31c12735e162159a2..e45d7a974e05aee643384065c8e291810f027815 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -104,7 +104,6 @@ ivas_error acelp_core_enc( float *bwe_exc; /* excitation for SWB TBE */ Word16 allow_cn_step; Word32 int_fs; - float att; Word16 nb_bits; /* parameters handling */ /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ @@ -841,6 +840,8 @@ ivas_error acelp_core_enc( st->hGSCEnc->last_ener_fx = (Word16) st->hGSCEnc->last_ener; IF( st->hLPDmem ) st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); + IF( st->hTdCngEnc ) + st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); #endif /*-----------------------------------------------------------------* * Configure ACELP bit allocation @@ -976,11 +977,7 @@ ivas_error acelp_core_enc( *---------------------------------------------------------------*/ calc_residu_fx( st, inp_fx, res_fx, Aq_fx ); - -#if 1 // TODO: To be replaced with fixed version once available - calculate_hangover_attenuation_gain( st, &att, vad_hover_flag ); - att_fx = float_to_fix16( att, Q15 ); -#endif + calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) { diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index 8b7281bc30c8d5ac67b75f6701af18cd4b19b526..1196f2bd59da4576b0803420ba1b2e5d9a061c87 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * amr_wb_enc() * @@ -524,6 +525,7 @@ void amr_wb_enc( return; } +#endif /*---------------------------------------------------------------------* * amr_wb_enc_init() diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c index a2517f99fa6fe529a1ae619f392bb541a6bff6a4..21d36d21727a036ac45c587a0950936414cd6270 100644 --- a/lib_enc/arith_coder_enc.c +++ b/lib_enc/arith_coder_enc.c @@ -66,6 +66,7 @@ typedef struct Heap } Heap; +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tcx_arith_estimate_scale() * @@ -683,3 +684,4 @@ void tcx_arith_encode_envelope( return; } +#endif diff --git a/lib_enc/cng_enc.c b/lib_enc/cng_enc.c index 7620f2c4416d0a57147bc93d6555a7c3c40e2ef9..571fc35494de65cb9b181485c4a7ee75a0ef34a5 100644 --- a/lib_enc/cng_enc.c +++ b/lib_enc/cng_enc.c @@ -60,16 +60,18 @@ * Local function prototypes *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t shb_DTX( Encoder_State *st, const float *shb_speech, const float *syn_12k8_16k ); static void shb_CNG_encod( Encoder_State *st, const int16_t update ); - -#ifdef IVAS_FLOAT_FIXED - +#else static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx ); + static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update ); #endif + +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * CNG_enc() * @@ -904,6 +906,7 @@ void swb_CNG_enc( return; } +#endif #ifdef IVAS_FLOAT_FIXED void swb_CNG_enc_ivas_fx( @@ -957,6 +960,7 @@ void swb_CNG_enc_ivas_fx( * SID parameters encoding for SHB signal *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void shb_CNG_encod( Encoder_State *st, /* i/o: State structure */ const int16_t update /* i : SID update flag */ @@ -1031,8 +1035,7 @@ static void shb_CNG_encod( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void shb_CNG_encod_ivas_fx( Encoder_State *st, /* i/o: State structure */ const Word16 update /* i : SID update flag */ @@ -1154,6 +1157,7 @@ static void shb_CNG_encod_ivas_fx( * Decide if encoding SHB SID or not *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t shb_DTX( Encoder_State *st, /* i/o: State structure */ const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ @@ -1284,8 +1288,7 @@ static int16_t shb_DTX( return ( update ); } - -#ifdef IVAS_FLOAT_FIXED +#else static Word16 shb_DTX_ivas_fx( Encoder_State *st, /* i/o: State structure */ const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index b438baa3cfd5f3b665e55358423fddc65b7df866..2acc3bab6ad364348aa55b301d2c92b6bc3f3556 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -278,8 +278,8 @@ void TNSAnalysisStereo_fx( * both filters for the decision */ - meanPredictionGain_fx = shr( add( pFilter[0]->predictionGain, pFilter[1]->predictionGain ), 1 ); // Q7 - maxPredictionGain_fx = s_max( maxPredictionGain_fx, meanPredictionGain_fx ); // Q7 + meanPredictionGain_fx = add( shr( pFilter[0]->predictionGain, 1 ), shr( pFilter[1]->predictionGain, 1 ) ); // Q7 + maxPredictionGain_fx = s_max( maxPredictionGain_fx, meanPredictionGain_fx ); // Q7 test(); test(); @@ -1298,6 +1298,7 @@ void TNSAnalysis( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ShapeSpectrum() * @@ -1474,6 +1475,7 @@ void ShapeSpectrum( return; } +#endif /*-------------------------------------------------------------------* @@ -1504,6 +1506,7 @@ static int16_t GetTransWidth( } +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * EstimateTCXNoiseLevel() * @@ -1563,6 +1566,7 @@ static void EstimateTCXNoiseLevel( return; } +#endif /*-----------------------------------------------------------* @@ -1658,6 +1662,7 @@ void EstimateStereoTCXNoiseLevel( } +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------* * DecideTonalSideInfo() * @@ -2616,6 +2621,7 @@ void InternalTCXDecoder( return; } + /*-------------------------------------------------------------------* * QuantizeSpectrum() * @@ -2793,6 +2799,7 @@ void coder_tcx( return; } +#endif /*-------------------------------------------------------------------* * coder_tcx_post() diff --git a/lib_enc/core_enc_2div.c b/lib_enc/core_enc_2div.c index 870f6e50cd98201a5be3ede97887d8b02c68dff4..019a5658638fc50c6970a00d8346215ef22a88ce 100644 --- a/lib_enc/core_enc_2div.c +++ b/lib_enc/core_enc_2div.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * core_encode_twodiv() * @@ -241,3 +242,4 @@ void core_encode_twodiv( return; } +#endif diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c index e4a1b3ad2c8d591abc809259a22228f0a23cb740..562e28d7706d742b74ad5a501996a728ca909882 100644 --- a/lib_enc/core_enc_ol.c +++ b/lib_enc/core_enc_ol.c @@ -47,6 +47,7 @@ #include "prot_fx_enc.h" #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -673,368 +674,7 @@ static void closest_centroid_rf( * * Open-loop ACELP/TCX20 core decision *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - -void core_acelp_tcx20_switching( - Encoder_State *st, /* i/o: encoder state structure */ - float non_staX, /* i : unbound non-stationarity for sp/mu clas */ - float *pitch_fr, /* i/o: fraction pitch values */ - float *voicing_fr, /* i/o: fractional voicing values */ - const float currFlatness, /* i : flatness */ - const float lsp_mid[M], /* i : LSPs at the middle of the frame */ - const float stab_fac /* i : LP filter stability */ -) -{ - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - int16_t i, j; - float A_q_tcx[NB_SUBFR16k * ( M + 1 )]; - float dsnr, snr_tcx, snr_acelp; - int16_t iter; - float xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; - float Ap[M + 1]; - float gainlpc[FDNS_NPTS]; - float en[N_MAX / 4]; - float sqGain, ener, tmp, fac, offset; - int16_t L_frame = st->L_frame; - int16_t overlap; - int16_t tcx_offset = st->hTcxCfg->tcx_offset; - float *x = hTcxEnc->spectrum_long; - float target; - int16_t T0; - float gain, noise, scale; - float *pt_ener_sfr, ener_sfr[NB_SUBFR16k]; - Word16 q_fac; - Word16 *speech_fx; - Word16 *speech_ltp_fx; - Word16 A_q_tcx_fx[NB_SUBFR16k * ( M + 1 )]; - Word16 buf_speech_enc_fx[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - Word16 buf_speech_ltp_fx[L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k]; - Word16 buf_wspeech_enc_fx[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; - Word16 *wspeech_fx; - Word16 q_fac_wsp; - - /* Check minimum pitch for quantization */ - for ( i = 0; i < 3; i++ ) - { - /* check minimum pitch for quantization */ - if ( st->pitch[i] < PIT_MIN_SHORTER ) - { - st->pitch[i] *= 2; - } - - /* convert pitch values to 16kHz domain */ - if ( st->L_frame == L_FRAME16k ) - { - st->pitch[i] = (int16_t) ( st->pitch[i] * 1.25f + 0.5f ); - } - } - if ( st->narrowBand == 1 ) - { - pitchDoubling_det( st->wspeech_enc_flt, st->pitch, pitch_fr, voicing_fr ); - } - - lsp2a_stab( lsp_mid, A_q_tcx, M ); - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, NSUBBLOCKS + MAX_TD_DELAY ); - hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); - hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); - q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - floatToFixed_arr( st->buf_speech_enc_flt, buf_speech_enc_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - speech_fx = buf_speech_enc_fx + st->encoderPastSamples_enc; - - floatToFixed_arr( st->hTcxEnc->buf_speech_ltp_flt, buf_speech_ltp_fx, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - speech_ltp_fx = buf_speech_ltp_fx + st->encoderPastSamples_enc; - - q_fac_wsp = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - floatToFixed_arr( st->buf_wspeech_enc_flt, buf_wspeech_enc_fx, q_fac_wsp, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - - floatToFixed_arr( A_q_tcx, A_q_tcx_fx, q_fac, NB_SUBFR16k * ( M + 1 ) ); - - Word16 L_subfr = idiv1616( st->L_frame, st->nb_subfr ); - - if ( st->element_mode > EVS_MONO ) - { - wspeech_fx = buf_wspeech_enc_fx + st->L_frame + L_SUBFR; - } - else - { - wspeech_fx = buf_wspeech_enc_fx + st->L_frame + L_subfr; - } - -#endif - - tcx_ltp_encode_ivas_fx( st, TCX_20, st->L_frame, speech_fx + st->encoderLookahead_enc, speech_ltp_fx + st->encoderLookahead_enc, wspeech_fx + st->encoderLookahead_enc, st->pitch, hTcxEnc->tcxltp_param, &hTcxEnc->tcxltp_bits, A_q_tcx_fx, 0, st->element_mode ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( A_q_tcx_fx, A_q_tcx, q_fac, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( buf_wspeech_enc_fx, st->buf_wspeech_enc_flt, q_fac_wsp, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - fixedToFloat_arr( buf_speech_ltp_fx, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); - hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); - hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); -#endif -#else - tcx_ltp_encode( st, TCX_20, st->L_frame, st->speech_enc_flt + st->encoderLookahead_enc, hTcxEnc->speech_ltp_flt + st->encoderLookahead_enc, st->wspeech_enc_flt + st->encoderLookahead_enc, st->pitch, hTcxEnc->tcxltp_param, &hTcxEnc->tcxltp_bits, A_q_tcx, 0, st->element_mode ); -#endif - - /* Force TCX when TCX20 in MODE1 is selected */ - if ( st->mdct_sw == MODE1 ) - { - st->core = TCX_20_CORE; - } - else - { - /*--------------------------------------------------------------* - * Estimate TCX SNR - *---------------------------------------------------------------*/ - - target = 1000.f; - if ( st->sr_core == INT_FS_16k ) - { - target = 850.f; - } - else if ( st->sr_core == INT_FS_12k8 ) - { - target = 850.f; - } - - if ( st->narrowBand == 1 ) - { - target = 500.f; - } - - if ( st->last_core == ACELP_CORE ) - { - L_frame += tcx_offset; - - if ( st->hTcxCfg->lfacNext < 0 ) - { - L_frame -= st->hTcxCfg->lfacNext; - tcx_offset = st->hTcxCfg->lfacNext; - } - else - { - tcx_offset = 0; - } - } - - overlap = st->hTcxCfg->tcx_mdct_window_delay; - - mvr2r( hTcxEnc->speech_ltp_flt - ( overlap >> 1 ) + tcx_offset, xn_buf, L_frame + overlap ); - - if ( st->last_core == ACELP_CORE ) - { - if ( tcx_offset < 0 ) - { - set_f( xn_buf, 0.0f, overlap >> 1 ); - } - } - else - { - for ( i = 0; i < overlap; i++ ) - { - xn_buf[i] *= st->hTcxCfg->tcx_mdct_window_flt[i]; - } - } - - for ( i = 0; i < overlap; i++ ) - { - xn_buf[L_frame + i] *= st->hTcxCfg->tcx_mdct_window_flt[overlap - 1 - i]; - } - - TCX_MDCT_flt( xn_buf, x, overlap, L_frame - overlap, overlap, st->element_mode ); - - for ( i = 0; i < L_frame; i++ ) - { - x[i] *= (float) ( L_frame / sqrt( 2 * NORM_MDCT_FACTOR ) ); - } - - weight_a( A_q_tcx, Ap, st->gamma_flt, M ); - - lpc2mdct_flt( Ap, M, gainlpc, FDNS_NPTS, 0 ); - - mdct_preShaping( x, L_frame, gainlpc ); - - if ( st->narrowBand == 1 ) - { - j = (int16_t) ( (float) L_frame * 0.625f ); - - set_f( x + j, 0.0f, L_frame - j ); - } - - for ( i = 0; i < L_frame; i += 4 ) - { - ener = 0.01f + x[i] * x[i] + x[i + 1] * x[i + 1] + x[i + 2] * x[i + 2] + x[i + 3] * x[i + 3]; - en[i / 4] = 9.0f + 10.0f * (float) log10( ener ); - } - - fac = 128.0f; - offset = fac; - - for ( iter = 0; iter < 10; iter++ ) - { - fac *= 0.5f; - offset -= fac; - ener = 0.0f; - - for ( i = 0; i < L_frame / 4; i++ ) - { - tmp = en[i] - offset; - - if ( tmp > 3.0f ) - { - ener += tmp; - } - - if ( ener > target ) - { - offset += fac; - break; - } - } - } - - if ( offset <= 32.f ) - { - offset = -128.f; - } - - sqGain = (float) pow( 10.0f, offset / 20.0f ); - ener = sqGain * sqGain / 12.f * (float) sqrt( 2.f ) / (float) L_frame; - - snr_tcx = 0.0f; - pt_ener_sfr = ener_sfr; - - for ( i = 0; i < st->L_frame; i += L_SUBFR ) - { - *pt_ener_sfr = sum2_f( st->wspeech_enc_flt + i, L_SUBFR ) + 1e-6f; - - snr_tcx += (float) log10( *pt_ener_sfr / ( ener * L_SUBFR ) ); - pt_ener_sfr++; - } - snr_tcx *= ( (float) ( 10 * L_SUBFR ) ) / (float) st->L_frame; - - - /*--------------------------------------------------------------* - * Estimate ACELP SNR - *---------------------------------------------------------------*/ - - scale = 0.055f; - if ( st->sr_core == INT_FS_16k ) - { - scale = 0.092f; - } - else if ( st->sr_core == INT_FS_12k8 ) - { - scale = 0.059f; - } - - if ( st->narrowBand ) - { - scale = 0.15f; - } - - snr_acelp = 0.0f; - fac = (float) st->sr_core / (float) INT_FS_12k8; - pt_ener_sfr = ener_sfr; - - for ( i = 0; i < st->L_frame; i += L_SUBFR ) - { - T0 = (int16_t) ( ( fac * pitch_fr[(int16_t) ( (float) ( i / L_SUBFR ) / fac + 0.5f )] ) + 0.5f ); - gain = get_gain_flt( st->wspeech_enc_flt + i, st->wspeech_enc_flt + i - T0, L_SUBFR, NULL ); - - noise = 1e-6f; - for ( j = 0; j < L_SUBFR; j++ ) - { - tmp = st->wspeech_enc_flt[i + j] - gain * st->wspeech_enc_flt[i + j - T0]; - noise += tmp * tmp; - } - - noise *= scale; - snr_acelp += (float) log10( *pt_ener_sfr / noise ); - pt_ener_sfr++; - } - - snr_acelp *= ( (float) ( 10 * L_SUBFR ) ) / (float) st->L_frame; - - - /*--------------------------------------------------------------* - * Switching Decision - *---------------------------------------------------------------*/ - - dsnr = 0.0f; - /* hysteresis for very small SNR differences between ACELP and TCX */ - - /* try to use TCX instead of ACELP on temporally stationary frames */ - if ( ( snr_acelp > snr_tcx ) && - ( snr_acelp < snr_tcx + 2.0f ) && - ( st->prevTempFlatness + currFlatness < 3.25f || stab_fac == 1.0f || ( st->sr_core == INT_FS_12k8 && st->sp_aud_decision0 == 1 && st->prevTempFlatness + currFlatness < 20.f ) ) && - ( st->acelpFramesCount <= 6 ) ) - { - dsnr = -2.0f; - } - /* try to use ACELP instead of TCX on transient and "buzzy" frames */ - if ( ( snr_acelp < snr_tcx ) && - ( snr_acelp > snr_tcx - 2.0f ) && - ( st->prevTempFlatness + currFlatness > 3.25f ) && - ( st->acelpFramesCount >= 6 ) ) - { - dsnr = 2.0f; - } - - if ( ( st->sr_core == INT_FS_12k8 ) && ( offset < 74.0f ) && ( non_staX > 5.0f ) && ( snr_acelp >= snr_tcx - 4 ) && st->acelpFramesCount >= 1 && ( ( ( st->hSpMusClas->lps > st->hSpMusClas->lpm ) && mean( voicing_fr, 4 ) >= 0.3f ) || ( st->acelpFramesCount >= 6 && ( st->hSpMusClas->lps > st->hSpMusClas->lpm - 1.5f ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) - { - /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ - dsnr = 4.0f; - } - - if ( st->flag_noisy_speech_snr ) - { - if ( st->vad_flag || st->Opt_DTX_ON ) - { - dsnr += 2.f; - } - else - { - dsnr -= 2.f; - } - } - - if ( st->sr_core == INT_FS_12k8 && ( non_staX < 2.f || ( st->flag_noisy_speech_snr == 0 && st->vad_flag == 1 && offset == -128.f && st->acelpFramesCount >= 6 ) ) && ( st->last_core == ACELP_CORE || st->last_core == TCX_20_CORE ) ) - { - st->core = st->last_core; - } - else if ( snr_acelp + dsnr > snr_tcx ) - { - st->core = ACELP_CORE; - st->acelpFramesCount = min( MAX16B - 1, st->acelpFramesCount + 1 ); - } - else - { - st->core = TCX_20_CORE; - st->acelpFramesCount = 0; - } - } - - /* Fixed Decision (using -C) */ - if ( st->acelpEnabled == 1 && st->tcx20Enabled == 0 ) - { - st->core = ACELP_CORE; - } - - if ( st->acelpEnabled == 0 && st->tcx20Enabled == 1 ) - { - st->core = TCX_20_CORE; - } - - st->prevTempFlatness = currFlatness; - - return; -} -#else void core_acelp_tcx20_switching( Encoder_State *st, /* i/o: encoder state structure */ float non_staX, /* i : unbound non-stationarity for sp/mu clas */ @@ -1344,7 +984,6 @@ void core_acelp_tcx20_switching( return; } -#endif /*-------------------------------------------------------------------* * BITS_ALLOC_ACELP_config_rf() @@ -1547,3 +1186,4 @@ static void BITS_ALLOC_TCX_config_rf( int16_t *rf_frame_type, int16_t *rf_target } return; } +#endif diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 72f9775f10cbf550ae94d4f77011756abccc6bc8..ba125469f1643fad4b32e0f025fc5ca2d757ccc7 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -274,8 +274,7 @@ void core_coder_mode_switch_ivas_fx( return; } -#endif - +#else void core_coder_mode_switch( Encoder_State *st, /* i/o: encoder state structure */ const int32_t last_total_brate, /* i : last bitrate */ @@ -431,3 +430,4 @@ void core_coder_mode_switch( return; } +#endif diff --git a/lib_enc/core_enc_updt.c b/lib_enc/core_enc_updt.c index b0bf893f4d86170700892d6ea54776040e017a2a..a388365f601d0c3da953e481684d19d62fca94e9 100644 --- a/lib_enc/core_enc_updt.c +++ b/lib_enc/core_enc_updt.c @@ -179,6 +179,7 @@ void core_encode_update_ivas_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * core_encode_update_cng() * @@ -279,3 +280,4 @@ void core_encode_update_cng( return; } +#endif diff --git a/lib_enc/enc_acelp_tcx_main.c b/lib_enc/enc_acelp_tcx_main.c index 5e0a1d004123271c84f988ba0d03e03449a1cc43..2b5acec573399fd65c5443424d0b4ef510c8c5c6 100644 --- a/lib_enc/enc_acelp_tcx_main.c +++ b/lib_enc/enc_acelp_tcx_main.c @@ -40,6 +40,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * enc_acelp_tcx_main() * @@ -129,3 +130,4 @@ void enc_acelp_tcx_main( pop_wmops(); return; } +#endif diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index a80c21c3a436a6503f3ddcf168ec148e817c005d..8c8557c0079dac0e70742f73cb243c6e0079060f 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -46,6 +46,8 @@ #include "prot_fx_enc.h" #endif + +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -56,7 +58,6 @@ static void writeFrameHeader( Encoder_State *st ); static void initFrameHeader( Encoder_State *st ); - /*-------------------------------------------------------------------* * evs_enc() * @@ -817,3 +818,4 @@ static void configure_core_coder( return; } +#endif diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index ee7c572c007f2ff86af1fc1530307bca09676481..f81c1a665ac8c04ddb93cd34cf049312b9899b55 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -6,11 +6,15 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ +#ifdef IVAS_FLOAT_FIXED +#include +#include +#endif /*-------------------------------------------------------------------* @@ -621,3 +625,779 @@ void core_signal_analysis_high_bitrate_fx( return; } + +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * core_signal_analysis_high_bitrate_ivas_fx() + * + * + *-------------------------------------------------------------------*/ + +void core_signal_analysis_high_bitrate_ivas_fx( + const Word16 *new_samples, /*i: Q0 */ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + Word16 lsp_new[], /* Q15 */ + Word16 lsp_mid[], /* Q15 */ + Encoder_State *st, + Word16 pTnsSize[], + Word16 pTnsBits[], + Word16 param_core[], + Word16 *ltpBits, + Word32 *windowed_samples, + const Word16 L_frame, + const Word16 L_frameTCX, + const Word16 last_element_mode, + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + Word32 **spectrum, + Word16 *spectrum_e, + Word16 *Q_new ) +{ + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + + const Word16 last_overlap = st->hTcxCfg->tcx_last_overlap_mode; + const Word16 curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode; + const Word16 minWindowLen = sub( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + Word16 i, frameno; + Word16 L_subframe; + Word16 left_overlap = -1, right_overlap = -1, folding_offset; + Word32 buf[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ + Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ + Word16 *pMdstWin; + Word16 lpc_left_overlap_mode, lpc_right_overlap_mode; + Word32 *powerSpec = buf; + Word16 powerSpec_e; + Word16 *tcx20Win = (Word16 *) buf; + Word32 *tcx20Win_32 = buf; + Word32 interleaveBuf[N_TCX10_MAX]; + Word16 *tcx5Win = (Word16 *) interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */ + Word16 nSubframes; + Word16 overlap_mode[3]; + Word16 *transform_type = hTcxEnc->transform_type; + Word32 r[M + 1]; + Word16 A[M + 1]; + Word16 r_h[NB_DIV][M + 1], r_l[NB_DIV][M + 1]; + Word16 *lsp[2]; + const Word16 tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 ); + const Word16 tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; + const Word16 tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 ); + Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1; + Word16 alw_voicing[2], alw_voicing_wc = -1; + Word16 disable_ltp = 0; + Word16 tmp, *tmpP16; + Word32 *tmpP32; + Word16 Q_exp; + Word32 L_tmpbuf[N_MAX + L_MDCT_OVLP_MAX]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + (void) vad_hover_flag; + powerSpec_e = 0; + move16(); + + Word16 *speech_ltp_fx = NULL; + Word16 *wspeech_fx = NULL; + Word16 *speech_fx = NULL; + Word16 q_out_wtda = 0; + move16(); + + if ( NE_16( last_element_mode, st->element_mode ) ) + { + disable_ltp = 1; /* disable TCX-LTP in stereo switching to avoid discontinuities in synthesis */ + move16(); + } + + /*--------------------------------------------------------------* + * Input Signal Processing: copy, HP filter, pre-emphasis + *---------------------------------------------------------------*/ + + /* Copy Samples */ + test(); + IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + Copy( new_samples, st->new_speech_enc, L_frame ); + Scale_sig( st->new_speech_enc, L_frame, 1 ); // Q1 + } + + /*--------------------------------------------------------------* + * TCX-LTP + *---------------------------------------------------------------*/ + + if ( st->element_mode == IVAS_CPE_DFT ) + { + if ( st->element_mode > EVS_MONO ) + { + wspeech_fx = st->buf_wspeech_enc + st->L_frame + L_SUBFR; + } + else + { + wspeech_fx = st->buf_wspeech_enc + st->L_frame + idiv1616( st->L_frame, st->nb_subfr ); + } + } + else if ( st->element_mode != IVAS_CPE_MDCT ) + { + speech_fx = st->buf_speech_enc + +st->encoderPastSamples_enc; + speech_ltp_fx = st->hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; + } + + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, wspeech_fx, NULL, wspeech_fx, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); + } + ELSE IF( st->element_mode != IVAS_CPE_MDCT ) + { + tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, speech_fx + st->encoderLookahead_enc, speech_ltp_fx + st->encoderLookahead_enc, speech_fx + st->encoderLookahead_enc, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); + } + + test(); + IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); + + Preemph_scaled( st->new_speech_enc_pe, Q_new, &( st->mem_preemph_enc ), + st->Q_max_enc, st->preemph_fac, 1, 0, 2, L_frame, st->coder_type_raw, 1 ); + } + + /* Rescale Memory */ + Q_exp = sub( *Q_new, st->prev_Q_new ); + move16(); + + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); // *Q_new + IF( Q_exp != 0 ) + { + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); // *Q_new + Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); // *Q_new + } + + IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) + { + Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + lsp[0] = lsp_new; + move16(); + lsp[1] = lsp_mid; + move16(); + } + + /*-------------------------------------------------------------------------* + * Decision matrix for the transform and overlap length + *--------------------------------------------------------------------------*/ + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + alw_pitch_lag_12k8[0] = st->pitch[0]; + move16(); + alw_pitch_lag_12k8[1] = st->pitch[1]; + move16(); + alw_voicing[0] = st->voicing_fx[0]; + move16(); + alw_voicing[1] = st->voicing_fx[1]; + move16(); + alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); + alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); + } + + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ + move16(); + + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + move16(); + transform_type[0] = TCX_20; + move16(); + transform_type[1] = TCX_20; + move16(); + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ + move16(); + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; + move16(); + alw_voicing[0] = alw_voicing_wc; + move16(); + } + } + ELSE + { + nSubframes = 2; + move16(); + IF( curr_overlap == FULL_OVERLAP ) + { + transform_type[0] = TCX_5; + move16(); + transform_type[1] = TCX_10; + move16(); + + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + move16(); + if ( EQ_16( last_overlap, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + move16(); + } + } + ELSE IF( last_overlap == FULL_OVERLAP ) + { + transform_type[0] = TCX_10; + move16(); + transform_type[1] = TCX_5; + move16(); + + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ + move16(); + if ( EQ_16( curr_overlap, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + move16(); + } + } + ELSE + { + transform_type[0] = transform_type[1] = TCX_5; + move16(); + move16(); + + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + move16(); + test(); + if ( EQ_16( last_overlap, HALF_OVERLAP ) && EQ_16( curr_overlap, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + move16(); + } + } + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ + move16(); + } + + test(); + IF( st->igf && NE_16( transform_type[0], TCX_20 ) ) + { + IGFEncResetTCX10BitCounter_fx( st->hIGFEnc ); + } + + /*-------------------------------------------------------------------------* + * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed + *--------------------------------------------------------------------------*/ + + FOR( frameno = 0; frameno < nSubframes; frameno++ ) + { + L_subframe = L_frameTCX; + move16(); + IF( NE_16( nSubframes, 1 ) ) + { + L_subframe = shr( L_frameTCX, 1 ); + } + + lpc_left_overlap_mode = overlap_mode[frameno]; + move16(); + lpc_right_overlap_mode = overlap_mode[frameno + 1]; + move16(); + if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) ) + { + lpc_left_overlap_mode = FULL_OVERLAP; + move16(); + } + if ( EQ_16( lpc_right_overlap_mode, ALDO_WINDOW ) ) + { + lpc_right_overlap_mode = FULL_OVERLAP; + move16(); + } + + test(); + IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + wtda_fx( hTcxEnc->new_speech_TCX, &q_out_wtda, tcx20Win_32, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX ); + + IF( windowed_samples != NULL ) /* store overlap data for later */ + { + assert( frameno == 0 ); + windowed_samples[0] = L_deposit_l( overlap_mode[frameno] ); + windowed_samples[1] = L_deposit_l( overlap_mode[frameno + 1] ); + } + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 1, 1 ); + } + } + ELSE + { + /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno], + overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], + &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1 ); + + IF( windowed_samples != NULL ) /* save windowed speech_TCX samples */ + { + assert( L_subframe + ( left_overlap + right_overlap ) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8 ); + windowed_samples[frameno * L_FRAME_MAX + 0] = L_deposit_l( overlap_mode[frameno] ); + windowed_samples[frameno * L_FRAME_MAX + 1] = L_deposit_l( overlap_mode[frameno + 1] ); + Copy_Scale_sig_16_32( tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2, 0 ); + } + } + + IF( EQ_16( transform_type[frameno], TCX_5 ) ) + { + folding_offset = shr( left_overlap, 1 ); + + /* Outter left folding */ + FOR( i = 0; i < folding_offset; i++ ) + { +#ifdef BASOP_NOGLOB + tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#else + tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); +#endif + move16(); + } + + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) ) + { + tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + Word32 L_tmp; + FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + tcx20Win[left_overlap + i] = sub( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + tcx20Win[left_overlap + i] = sub( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + } + + /* Outter right folding */ + tmp = shr( right_overlap, 1 ); + FOR( i = 0; i < tmp; i++ ) + { +#ifdef BASOP_NOGLOB + tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); +#else + tcx20Win[L_subframe + folding_offset - 1 - i] = add( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); +#endif + move16(); + } + + /* 2xTCX5 */ + L_subframe = tcx5SizeFB; + move16(); + + tmpP16 = tcx20Win; + tmpP32 = hTcxEnc->spectrum_fx[frameno]; + assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE ); + FOR( i = 0; i < 2; i++ ) + { + test(); + test(); + WindowSignal( st->hTcxCfg, + folding_offset, + mac_r( -( 1 << 16 ), 3 << 8, shl( i, 7 ) ), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + mac_r( 2 << 16, -( 3 << 8 ), shl( i, 7 ) ), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ + &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1 ); + + hTcxEnc->spectrum_e[frameno] = 16; + move16(); + TCX_MDCT( tcx5Win, + tmpP32, + &hTcxEnc->spectrum_e[frameno], + left_overlap, + sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), + right_overlap, st->element_mode ); + + tmpP16 += tcx5SizeFB; + tmpP32 += tcx5SizeFB; + + /* high-band gain control in case of BWS */ + IF( st->bwidth_sw_cnt > 0 ) + { + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( hTcxEnc->spectrum_fx[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), + factor, + hTcxEnc->spectrum_fx[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), + L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); + } + } + } + ELSE /* transform_type[frameno] != TCX_5 */ + { + assert( transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20 ); + + /* TCX20/TCX10 */ + hTcxEnc->spectrum_e[frameno] = 16; + move16(); + test(); + test(); + IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + /* DCT */ + Word16 Q; + + Q = q_out_wtda; + edct_fx( tcx20Win_32, hTcxEnc->spectrum_fx[frameno], L_subframe, &Q ); + hTcxEnc->spectrum_e[frameno] = sub( 31, Q ); + move16(); + + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( NORM_MDCT_FACTOR, L_subframe, &exp_diff ); + tmp = Sqrt16( tmp, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( hTcxEnc->spectrum_fx[frameno], factor, hTcxEnc->spectrum_fx[frameno], L_subframe ); + } + ELSE + { + test(); + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && frameno == 0 && EQ_16( transform_type[0], TCX_10 ) && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) ) + { + tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + Word32 L_tmp; + FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + tcx20Win[left_overlap + i] = sub( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + tcx20Win[left_overlap + i] = sub( tcx20Win[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + } + + TCX_MDCT( tcx20Win, hTcxEnc->spectrum_fx[frameno], &hTcxEnc->spectrum_e[frameno], left_overlap, sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); + } + + /* high-band gain control in case of BWS */ + IF( st->bwidth_sw_cnt > 0 ) + { + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( hTcxEnc->spectrum_fx[frameno] + L_FRAME16k / nSubframes, + factor, + hTcxEnc->spectrum_fx[frameno] + L_FRAME16k / nSubframes, + L_subframe - L_FRAME16k / nSubframes ); + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */ + test(); + test(); + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) && ( ( LT_32( st->total_brate, HQ_96k ) ) || st->igf ) ) + { + pMdstWin = tcx20Win; + test(); + if ( ( ( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) ) + { + pMdstWin = mdstWin; + } + + /* Compute noise-measure flags for spectrum filling and quantization */ + AnalyzePowerSpectrum_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ), + L_subframe, left_overlap, right_overlap, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_e[frameno], + pMdstWin, powerSpec, &powerSpec_e ); + } + } + } + + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + L_subframe = idiv1616( L_frameTCX, nSubframes ); + + test(); + IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) + { + wtda_ext_fx( hTcxEnc->new_speech_TCX, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3 ); + Scale_sig( mdstWin, L_frameTCX, 1 ); + } + ELSE + { + /* Windowing for the MDST */ + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1 ); + } + + IF( EQ_16( transform_type[frameno], TCX_5 ) ) + { + /* Outer left folding */ + FOR( i = 0; i < left_overlap / 2; i++ ) + { +#ifdef BASOP_NOGLOB + mdstWin[left_overlap / 2 + i] = add_sat( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); +#else + mdstWin[left_overlap / 2 + i] = add( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); +#endif + } + + test(); + test(); + IF( frameno == 0 && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) ) + { + tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + Word32 L_tmp; + FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + mdstWin[left_overlap + i] = add_sat( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + mdstWin[left_overlap + i] = add_sat( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + } + + /* Outer right folding */ + FOR( i = 0; i < right_overlap / 2; i++ ) + { +#ifdef BASOP_NOGLOB + mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub_sat( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); +#else + mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); +#endif + move16(); + } + + /* 2xTCX5 */ + L_subframe = tcx5SizeFB; + move16(); + folding_offset = shr( left_overlap, 1 ); + move16(); + + FOR( i = 0; i < 2; i++ ) + { + assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE ); + WindowSignal( st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1 ); + + spectrum_e[frameno] = 16; + move16(); + TCX_MDST( tcx5Win, spectrum[frameno] + i * tcx5SizeFB, &spectrum_e[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); + /* high-band gain control in case of BWS */ + IF( st->bwidth_sw_cnt > 0 ) + { + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), + factor, + spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ), + L_subframe - L_FRAME16k / ( 2 * nSubframes ) ); + } + } + } + ELSE /* transform_type[frameno] != TCX_5 */ + { + spectrum_e[frameno] = 16; + test(); + IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) + { + Word16 Q; + Copy_Scale_sig_16_32_no_sat( mdstWin, L_tmpbuf, N_MAX + L_MDCT_OVLP_MAX, 16 ); + + Q = 16; + move16(); + edst_fx( L_tmpbuf, spectrum[frameno], L_subframe, &Q ); + spectrum_e[frameno] = 31 - Q; + + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( NORM_MDCT_FACTOR, L_subframe, &exp_diff ); + tmp = Sqrt16( tmp, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( spectrum[frameno], factor, spectrum[frameno], L_subframe ); + } + ELSE + { + test(); + test(); + test(); + IF( frameno == 0 && EQ_16( transform_type[0], TCX_10 ) && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) ) + { + tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ); + Word32 L_tmp; + FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + mdstWin[left_overlap + i] = add_sat( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */ + { + L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (Q0, Q15) -> Q16 + L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re ); // (Q16, Q15) -> Q16 + L_tmp = L_shl( L_tmp, sub( 0, Q16 ) ); // Q0 +#ifdef BASOP_NOGLOB + mdstWin[left_overlap + i] = add_sat( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#else + mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) ); // Q0 +#endif + move32(); + } + } + + TCX_MDST( mdstWin, spectrum[frameno], &spectrum_e[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode ); + } + + /* high-band gain control in case of BWS */ + IF( st->bwidth_sw_cnt > 0 ) + { + Word16 exp_diff; + Word32 factor; + + tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff ); + factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31 + + v_multc_fixed( spectrum[frameno] + L_FRAME16k / nSubframes, factor, spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes ); + } + } + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + IF( ( frameno == 0 ) && ( st->last_core == ACELP_CORE ) ) + { + TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 1, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); + } + ELSE + { + TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 0, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); + } + + IF( st->hTcxCfg->fIsTNSAllowed ) + { + EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], + param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); + } + + IF( EQ_16( transform_type[frameno], TCX_5 ) ) + { + /* group sub-windows: interleave bins according to their frequencies */ + FOR( i = 0; i < tcx5SizeFB; i++ ) + { + interleaveBuf[2 * i] = hTcxEnc->spectrum_fx[frameno][i]; + move32(); + interleaveBuf[2 * i + 1] = hTcxEnc->spectrum_fx[frameno][tcx5SizeFB + i]; + move32(); + } + MVR2R_WORD32( interleaveBuf, hTcxEnc->spectrum_fx[frameno], tcx10SizeFB ); + } + + /*--------------------------------------------------------------* + * LPC analysis + *---------------------------------------------------------------*/ + + IF( st->tcxonly ) + { + HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size], + shr( L_frame, sub( nSubframes, 1 ) ), r, M ); + + FOR( i = 0; i <= M; i++ ) + { + r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] ); + move16(); + move16(); + } + + adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); + + E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, NULL, M, NULL ); + + E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); + } + + IF( st->igf ) + { + Word16 q_spectrum = sub( Q31, hTcxEnc->spectrum_e[frameno] ); + Word16 q_powerSpec = sub( Q31, powerSpec_e ); + ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); + } + } + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /* Copy memory */ + MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); + } + + return; +} +#endif diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index 7011112b4c16a6c5d56f306f5150264eff6a04ab..4a4e7f4f239da71a7a8ca21addb694b181983aa6 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -62,6 +62,7 @@ *-------------------------------------------------------------------*/ /*! r: maximum energy ratio */ +#ifndef IVAS_FLOAT_FIXED static float find_ener_decrease( const int16_t ind_deltaMax, /* i : index of the beginning of maximum energy search */ const float *pt_enr_ssf /* i : Pointer to the energy buffer */ @@ -102,6 +103,7 @@ static float find_ener_decrease( return dE2; } +#endif #ifdef IVAS_FLOAT_FIXED static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 */ const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search */ @@ -768,7 +770,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ * * Decision about coder type *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: coding type */ int16_t find_uv( Encoder_State *st, /* i/o: encoder state structure */ @@ -1150,3 +1152,4 @@ int16_t find_uv( return coder_type; } +#endif diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 1440ecb4bef1ec26c199eb9156529f4c6986a7aa..69a0d1f19f72c9ce537a5d96b1080f03b5a446e2 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -300,7 +300,7 @@ static Word16 IGF_getSFM_new_fx( tmp = BASOP_util_Pow2( L_add( numf, shl_sat( 1, sub( 14, numf_e ) ) ), add( 16, numf_e ), &tmp_e ); sfm = BASOP_Util_Divide3232_Scale( tmp, denom, &sfm_e ); sfm_e = add( sfm_e, sub( tmp_e, denom_e ) ); - sfm = shl_sat( extract_l( L_min( sfm, L_shl( 1, sub( 15, sfm_e ) ) ) ), sfm_e ); + sfm = shl_sat( extract_l( L_min( sfm, L_shl_sat( 1, sub( 15, sfm_e ) ) ) ), sfm_e ); } return sfm; @@ -1147,24 +1147,29 @@ static void IGF_CalculateEnvelope_ivas_fx( Word16 x1_e = BASOP_Util_Add_MantExp( tmp0, tmp0_e, tmp2, tmp2_e - 1, &x1 ); Word16 x2_e = BASOP_Util_Add_MantExp( tmp3, tmp3_e, tmp4, tmp4_e - 1, &x2 ); - hPrivateData->sfb_tb_e[sfb] = BASOP_Util_Add_MantExp( tmp_tb, tmp_tb_e, x1, x1_e, &hPrivateData->SFM_tb_fx[sfb] ); // hPrivateData->sfb_sb_e[sfb] - hPrivateData->SFM_tb_fx[sfb] = extract_l( L_min( L_shl( 22118 /*2.7f Q13*/, sub( 2, hPrivateData->sfb_tb_e[sfb] ) ), hPrivateData->SFM_tb_fx[sfb] ) ); - hPrivateData->sfb_sb_e[sfb] = BASOP_Util_Add_MantExp( tmp_sb, tmp_sb_e, x2, x2_e, &hPrivateData->SFM_sb_fx[sfb] ); // hPrivateData->sfb_tb_e[sfb] - IF( LT_16( hPrivateData->sfb_sb_e[sfb], 2 ) ) + move16(); + BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &tmp ); + + IF( tmp < 0 ) { - hPrivateData->SFM_sb_fx[sfb] = extract_l( L_min( 22118 /*2.7f Q13*/, L_shr( hPrivateData->SFM_sb_fx[sfb], sub( 2, hPrivateData->sfb_sb_e[sfb] ) ) ) ); - hPrivateData->sfb_sb_e[sfb] = 2; + hPrivateData->sfb_tb_e[sfb] = 2; + hPrivateData->SFM_tb_fx[sfb] = 22118; + move16(); move16(); } - ELSE + + hPrivateData->sfb_sb_e[sfb] = BASOP_Util_Add_MantExp( tmp_sb, tmp_sb_e, x2, x2_e, &hPrivateData->SFM_sb_fx[sfb] ); // hPrivateData->sfb_tb_e[sfb] + move16(); + BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_sb_fx[sfb] ), hPrivateData->sfb_sb_e[sfb], &tmp ); + + IF( tmp < 0 ) { - hPrivateData->SFM_sb_fx[sfb] = extract_l( L_min( L_shl( 22118 /*2.7f Q13*/, sub( 2, hPrivateData->sfb_sb_e[sfb] ) ), hPrivateData->SFM_sb_fx[sfb] ) ); + hPrivateData->sfb_sb_e[sfb] = 2; + hPrivateData->SFM_sb_fx[sfb] = 22118; + move16(); + move16(); } - move16(); - move16(); - move16(); - move16(); BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb], negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &diffSFM ); @@ -4470,4 +4475,43 @@ ivas_error IGF_Reconfig( return error; } +#else +ivas_error IGF_Reconfig( + IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word16 igf, /* i : IGF on/off */ + const Word16 reset, /* i : reset flag */ + const Word32 brate, /* i : bitrate for configuration */ + const Word16 bwidth, /* i : signal bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +) +{ + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + test(); + test(); + test(); + IF( igf && *hIGFEnc == NULL ) + { + IF( ( *hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); + } + IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); + } + ELSE IF( igf && reset ) + { + IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); + } + ELSE IF( !igf && *hIGFEnc != NULL ) + { + free( *hIGFEnc ); + *hIGFEnc = NULL; + } + + return error; +} #endif diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 5ea9b7b3c37e021efb8c4e21e1ffdc710c2ef73e..18335a91b1d22a89625434694cfc514404fec355 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -194,6 +194,9 @@ ivas_error init_encoder( /* adaptive lag window memory */ st->old_pitch_la = 0; +#ifdef IVAS_FLOAT_FIXED + st->prev_Q_new = 0; +#endif if ( st->input_Fs == 8000 ) { @@ -1052,35 +1055,60 @@ ivas_error init_encoder_ivas_fx( { st->last_core = -1; } + move16(); st->L_frame = L_FRAME; + move16(); st->last_coder_type = GENERIC; + move16(); st->coder_type = GENERIC; + move16(); st->last_total_brate = st->total_brate; + move32(); st->last_bits_frame_nominal = -1; + move16(); st->last_total_brate_cng = -1; + move16(); st->last_core_brate = st->total_brate; + move32(); st->dtx_sce_sba = 0; + move16(); st->extl = -1; + move16(); st->last_extl = -1; + move16(); st->last_L_frame = L_FRAME; + move16(); st->rate_switching_reset = 0; + move16(); st->rate_switching_reset_16kHz = 0; + move16(); st->clas = UNVOICED_CLAS; + move16(); st->low_rate_mode = 0; + move16(); st->ini_frame = 0; + move16(); st->inactive_coder_type_flag = 0; + move16(); st->sba_br_sw_while_no_data = 0; + move16(); st->coder_type_raw = VOICED; + move16(); st->last_coder_type_raw = st->coder_type_raw; + move16(); st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); + move16(); st->is_ism_format = 0; - IF( ism_mode != ISM_MODE_NONE ) + move16(); + + IF( NE_16( ism_mode, ISM_MODE_NONE ) ) { st->is_ism_format = 1; + move16(); } /*-----------------------------------------------------------------* @@ -1099,7 +1127,9 @@ ivas_error init_encoder_ivas_fx( st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; st->hBstr->nb_ind_tot = 0; + move16(); st->hBstr->nb_bits_tot = 0; + move16(); st->hBstr->st_ivas = st_ivas; } ELSE @@ -1115,11 +1145,24 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); +#if 1 // TODO: Float Initializations. To be removed later + mvr2r( GEWB_Ave, st->mem_AR, M ); + mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); + mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); + mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); + init_gp_clip( st->clip_var ); + set_zero( st->mem_MA, M ); + st->streaklimit = 1.0f; + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); +#endif st->next_force_safety_net = 0; + move16(); st->pstreaklen = 0; + move16(); st->streaklimit_fx = MAX_WORD16; + move16(); set16_fx( st->mem_MA_fx, 0, M ); init_gp_clip_fx( st->clip_var_fx ); @@ -1128,40 +1171,127 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. st->mem_preemph_fx = 0; + move16(); st->mem_preemph16k_fx = 0; + move16(); st->mem_preemph_enc = 0; + move16(); + +#if 1 // TODO: Float Initializations. To be removed later + set_f( st->old_wsp, 0, L_WSP_MEM ); + set_f( st->old_wsp2, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + st->mem_preemph = 0.0f; + st->mem_preemph16k = 0.0f; + st->mem_preemph_enc_flt = 0.0; + st->mem_preemp_preQ = 0.0f; + st->mem_deemp_preQ = 0.0f; + st->mem_wsp_enc_flt = 0.0; + st->mem_wsp = 0.0f; + set_f( st->mem_decim2, 0, 3 ); + set_f( st->Bin_E, 0, L_FFT ); + st->ee_old = 10.0f; + st->old_dE1 = 0.0f; + if ( st->Opt_AMR_WB ) + { + mvr2r( mean_isf_amr_wb, st->lsf_old, M ); + isf2isp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); + } + else + { + mvr2r( GEWB_Ave, st->lsf_old, M ); + lsf2lsp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); + } + mvr2r( st->lsf_old, st->lsf_old1, M ); + mvr2r( st->lsp_old1, st->lsp_old, M ); + mvr2r( st->lsp_old, st->lsp_old16k, M ); + mvr2r( st->lsp_old, st->lspold_enc, M ); + st->stab_fac = 0.0f; + set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); + st->mem_preemph_DFT = 0.0f; + set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + st->mem_preemph16k_DFT = 0.0f; + set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + mvr2r( st->lsp_old, st->lspold_s, M ); + set_f( st->old_Aq_12_8 + 1, 0, M ); + st->old_Aq_12_8[0] = 4096; + st->voicing0_sm = 0; + st->voicing_sm = 0; + st->LF_EnergyRatio_sm = 1; + st->diff_sm = 0; + st->energy_sm = 0; + set_f( st->voicing, 0.0f, 3 ); + st->lt_mean_NB = 0; + st->lt_mean_WB = 0; + st->lt_mean_SWB = 0; + st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ + st->lp_noise = 0.0f; + st->bckr_tilt_lt_flt = 0.f; + st->active_cnt = 0; + st->currEnergyLookAhead = 6.1e-5f; + st->old_hpfilt_in = 0.0f; + st->old_hpfilt_out = 0.0f; + st->EnergyLT = 0.0f; + st->Energy_Old = 0; + st->last_totalNoise = 0.f; + set_f( st->totalNoise_increase_hist, 0.f, TOTALNOISE_HIST_SIZE ); + st->min_alpha = 1; + st->prev_fmerit_flt = 0; + st->fmerit_dt_flt = 0; + st->pst_mem_deemp_err = 0.0f; + st->pst_lp_ener = 0.0f; + +#endif /* AVQ pre-quantizer memory */ st->mem_preemp_preQ_fx = 0; + move16(); st->mem_deemp_preQ_fx = 0; + move16(); st->last_nq_preQ = 0; + move16(); st->last_code_preq = 0; + move16(); st->use_acelp_preq = 0; + move16(); st->last_harm_flag_acelp = 0; + move16(); /* (Decimated) Weighted Speech Memory */ st->mem_wsp_enc = 0; + move16(); st->mem_wsp_fx = 0; + move16(); set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); st->ee_old_fx = 640; /*chk //10 in Q6 */ + move16(); st->Nb_ACELP_frames = 0; + move16(); st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ + move16(); /* adaptive lag window memory */ st->old_pitch_la = 0; + move16(); + + st->prev_Q_new = 0; + move16(); IF( EQ_32( st->input_Fs, 8000 ) ) { st->min_band = 1; + move16(); st->max_band = 16; + move16(); } ELSE { st->min_band = 0; + move16(); st->max_band = 19; + move16(); } IF( st->Opt_AMR_WB ) @@ -1181,37 +1311,55 @@ ivas_error init_encoder_ivas_fx( Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); st->stab_fac_fx = 0; + move16(); /* Bass post-filter memories - encoder side of MODE2 */ st->bpf_off = 0; + move16(); st->pst_mem_deemp_err_fx = 0; + move16(); st->pst_lp_ener_fx = 0; + move16(); /* TC coder type */ st->tc_cnt = 0; + move16(); /* find_uv() parameters */ st->old_dE1_fx = 0; + move16(); st->old_ind_deltaMax = 0; + move16(); set32_fx( st->old_enr_ssf_fx, 0, shl( NB_SSF, 1 ) ); st->spike_hyst = -1; + move16(); /* stereo switching memories */ st->mem_preemph_DFT_fx = 0; + move16(); set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); st->mem_preemph16k_DFT_fx = 0; + move16(); set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); st->sharpFlag = 0; /* Stationary noise UV modification */ st->ge_sm_fx = 10; /*chk //10 in Q6 */ + move16(); + st->ge_sm = 10; /*chk //10 in Q6 */ + move16(); st->uv_count = 0; + move16(); st->act_count = 3; + move16(); Copy( st->lsp_old_fx, st->lspold_s_fx, M ); st->noimix_seed = RANDOM_INITSEED; - st->min_alpha_fx = 1; + move16(); + st->min_alpha_fx = 32767; + move16(); st->exc_pe = 0; + move16(); #ifdef IVAS_FLOAT_FIXED st->exc_pe_fx = 0; move16(); @@ -1220,27 +1368,43 @@ ivas_error init_encoder_ivas_fx( #endif /* FEC */ st->last_clas = UNVOICED_CLAS; + move16(); st->prev_fmerit = 0; + move16(); st->fmerit_dt = 0; + move16(); st->Last_pulse_pos = 0; + move16(); FOR( i = 0; i < shl( NB_SUBFR16k, 1 ); i++ ) { +#if 1 // TODO: To be removed later st->old_pitch_buf[i] = L_SUBFR; +#endif + st->old_pitch_buf_fx[i] = L_SUBFR_Q6; + move16(); } /* mode1 core switching */ st->old_Es_pred = 0; + move16(); set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); - st->old_Aq_12_8_fx[0] = 1; + st->old_Aq_12_8_fx[0] = ONE_IN_Q12; + move16(); /* stable short pitch detection */ st->voicing0_sm_fx = 0; + move16(); st->voicing_sm_fx = 0; + move16(); st->LF_EnergyRatio_sm_fx = 1; + move16(); st->predecision_flag = 0; + move16(); st->diff_sm_fx = 0; + move32(); st->energy_sm_fx = 0; + move32(); set16_fx( st->pitch, L_SUBFR, 3 ); set16_fx( st->voicing_fx, 0, 3 ); @@ -1266,6 +1430,8 @@ ivas_error init_encoder_ivas_fx( st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; + set16_fx( st->hSignalBuf->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set16_fx( st->hSignalBuf->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); /* initializations */ set32_fx( st->Bin_E_old_fx, 0, shr( L_FFT, 2 ) ); set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); @@ -1274,19 +1440,52 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); st->input_buff_fx = st->hSignalBuf->input_buff; + st->input_buff32_fx = st->hSignalBuf->input_buff32; set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + set32_fx( st->input_buff32_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); st->old_input_signal_fx = st->input_buff_fx; /* st->input_Fs / FRAMES_PER_SEC */ Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { + st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); st->input_fx = st->input_buff_fx + add( frame_length, (Word16) NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); } ELSE { + st->input32_fx = st->input_buff32_fx + Mpy_32_32( st->input_Fs, 42949673 ) /* 1/50 in Q31*/; // st->input_Fs / FRAMES_PER_SEC st->input_fx = st->input_buff_fx + frame_length; } +#if 1 // TODO: To be removed later + st->Bin_E_old = st->hSignalBuf->Bin_E_old_flt; + st->mem_decim = st->hSignalBuf->mem_decim_flt; + st->mem_decim16k = st->hSignalBuf->mem_decim16k_flt; + st->old_inp_12k8 = st->hSignalBuf->old_inp_12k8_flt; + st->old_inp_16k = st->hSignalBuf->old_inp_16k_flt; + st->buf_speech_enc_pe_flt = st->hSignalBuf->buf_speech_enc_pe_flt; + st->buf_synth_flt = st->hSignalBuf->buf_synth_flt; + st->buf_speech_enc_flt = st->hSignalBuf->buf_speech_enc_flt; + st->buf_wspeech_enc_flt = st->hSignalBuf->buf_wspeech_enc_flt; + set_f( st->Bin_E_old, 0, L_FFT / 2 ); + set_f( st->mem_decim, 0, 2 * L_FILT_MAX ); + set_f( st->mem_decim16k, 0, 2 * L_FILT_MAX ); + set_f( st->old_inp_12k8, 0, L_INP_MEM ); + set_f( st->old_inp_16k, 0, L_INP_MEM ); + st->input_buff = st->hSignalBuf->input_buff_flt; + set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + st->old_input_signal = st->input_buff; + if ( st->element_mode == EVS_MONO ) + { + st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + } + else + { + st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; + } + set_f( st->hSignalBuf->buf_speech_enc_flt, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + set_f( st->hSignalBuf->buf_wspeech_enc_flt, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); +#endif } ELSE { @@ -1301,13 +1500,28 @@ ivas_error init_encoder_ivas_fx( st->buf_speech_enc = NULL; st->buf_wspeech_enc = NULL; st->input_buff_fx = NULL; +#if 1 + st->Bin_E_old = NULL; + st->mem_decim = NULL; + st->mem_decim16k = NULL; + st->old_inp_12k8 = NULL; + st->old_inp_16k = NULL; + st->buf_speech_enc_pe_flt = NULL; + st->buf_synth_flt = NULL; + st->buf_speech_enc_flt = NULL; + st->buf_wspeech_enc_flt = NULL; + st->input_buff = NULL; +#endif } /*-----------------------------------------------------------------* * Noise estimator *-----------------------------------------------------------------*/ - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) + test(); + test(); + test(); + IF( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || st->element_mode == EVS_MONO ) { IF( ( st->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) { @@ -1315,6 +1529,9 @@ ivas_error init_encoder_ivas_fx( } noise_est_init_ivas_fx( st->hNoiseEst ); +#if 1 + noise_est_init( st->hNoiseEst ); +#endif } ELSE { @@ -1326,9 +1543,11 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ st->vad_flag = 1; + move16(); st->localVAD = 0; + move16(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) && ( !vad_only_flag ) ) + IF( ( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || st->element_mode == EVS_MONO ) && ( !vad_only_flag ) ) { IF( ( st->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) { @@ -1336,12 +1555,16 @@ ivas_error init_encoder_ivas_fx( } wb_vad_init_ivas_fx( st->hVAD ); +#if 1 + wb_vad_init( st->hVAD ); +#endif } ELSE { st->hVAD = NULL; } st->Pos_relE_cnt = 20; + move16(); /* CLDFB-based VAD */ IF( st->element_mode == EVS_MONO ) @@ -1352,6 +1575,9 @@ ivas_error init_encoder_ivas_fx( } vad_init_ivas_fx( st->hVAD_CLDFB ); +#if 1 + vad_init( st->hVAD_CLDFB ); +#endif } ELSE { @@ -1362,7 +1588,7 @@ ivas_error init_encoder_ivas_fx( * Speech/music classifier *-----------------------------------------------------------------*/ - IF( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, EVS_MONO ) ) + IF( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) || st->element_mode == EVS_MONO ) { IF( ( st->hSpMusClas = (SP_MUS_CLAS_HANDLE) malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) { @@ -1370,10 +1596,15 @@ ivas_error init_encoder_ivas_fx( } speech_music_clas_init_fx( st->hSpMusClas ); - +#if 1 + speech_music_clas_init( st->hSpMusClas ); +#endif st->sp_aud_decision0 = 0; + move16(); st->sp_aud_decision1 = 0; + move16(); st->sp_aud_decision2 = 0; + move16(); } ELSE { @@ -1386,16 +1617,27 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ st->lt_mean_NB_fx = 0; + move16(); st->lt_mean_WB_fx = 0; + move16(); st->lt_mean_SWB_fx = 0; + move16(); st->count_WB = BWD_COUNT_MAX; + move16(); st->count_SWB = BWD_COUNT_MAX; + move16(); st->count_FB = BWD_COUNT_MAX; + move16(); st->bwidth = st->max_bwidth; + move16(); st->last_input_bwidth = st->bwidth; + move16(); st->last_bwidth = st->bwidth; + move16(); st->last_bwidth_cng = st->bwidth; + move16(); st->bwidth_sw_cnt = 0; + move16(); /*-----------------------------------------------------------------* @@ -1403,20 +1645,34 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + move16(); st->lp_noise_fx = 0; + move16(); st->flag_noisy_speech_snr = 0; + move16(); st->fd_cng_reset_flag = 0; + move16(); st->cng_type = -1; + move16(); st->bckr_tilt_lt = 0; + move16(); st->active_cnt = 0; + move16(); - IF( ( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON ) || EQ_16( st->element_mode, EVS_MONO ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + test(); + test(); + test(); + test(); + IF( ( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { IF( ( st->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); +#if 1 + dtx_enc_init( st, var_SID_rate_flag, interval_SID ); +#endif } ELSE { @@ -1449,9 +1705,13 @@ ivas_error init_encoder_ivas_fx( st->hTranDet = NULL; st->element_mode = IVAS_SCE; + move16(); st->idchan = 100; /* indicates hCoreCoderVAD */ + move16(); st->core = -1; + move16(); st->rf_mode = 0; + move16(); return error; } @@ -1460,7 +1720,12 @@ ivas_error init_encoder_ivas_fx( * LP-CNG *-----------------------------------------------------------------*/ - IF( ( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( ( idchan == 0 && st->Opt_DTX_ON && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || st->element_mode == EVS_MONO ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) { IF( ( st->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) { @@ -1468,6 +1733,9 @@ ivas_error init_encoder_ivas_fx( } td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); +#if 1 + td_cng_enc_init( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); +#endif } ELSE { @@ -1477,8 +1745,10 @@ ivas_error init_encoder_ivas_fx( /*-----------------------------------------------------------------* * CLDFB & resampling tools parameters *-----------------------------------------------------------------*/ - - IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { IF( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) { @@ -1490,13 +1760,17 @@ ivas_error init_encoder_ivas_fx( st->cldfbAnaEnc = NULL; } - st->currEnergyLookAhead = 130996; /* 6.1e-5f in Q31 */ + st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move32(); + st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move16(); /*-----------------------------------------------------------------* * SC-VBR parameters *-----------------------------------------------------------------*/ - IF( st->Opt_SC_VBR || EQ_16( st->element_mode, EVS_MONO ) ) + test(); + IF( st->Opt_SC_VBR || st->element_mode == EVS_MONO ) { IF( ( st->hSC_VBR = (SC_VBR_ENC_HANDLE) malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) { @@ -1504,6 +1778,9 @@ ivas_error init_encoder_ivas_fx( } sc_vbr_enc_init_fx( st->hSC_VBR ); +#if 1 + sc_vbr_enc_init( st->hSC_VBR ); +#endif } ELSE { @@ -1511,13 +1788,15 @@ ivas_error init_encoder_ivas_fx( } st->last_Opt_SC_VBR = 0; + move16(); /*-----------------------------------------------------------------* * AMR-WB IO initialization *-----------------------------------------------------------------*/ - IF( st->Opt_AMR_WB || EQ_16( st->element_mode, EVS_MONO ) ) + test(); + IF( st->Opt_AMR_WB || st->element_mode == EVS_MONO ) { IF( ( st->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) { @@ -1525,6 +1804,9 @@ ivas_error init_encoder_ivas_fx( } amr_wb_enc_init_fx( st->hAmrwb_IO ); +#if 1 + amr_wb_enc_init( st->hAmrwb_IO ); +#endif } ELSE { @@ -1535,7 +1817,9 @@ ivas_error init_encoder_ivas_fx( * ACELP LPDmem *-----------------------------------------------------------------*/ - IF( ( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + test(); + test(); + IF( ( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { IF( ( st->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) { @@ -1543,6 +1827,9 @@ ivas_error init_encoder_ivas_fx( } LPDmem_enc_init_fx( st->hLPDmem ); +#if 1 + LPDmem_enc_init( st->hLPDmem ); +#endif } ELSE { @@ -1554,9 +1841,13 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ st->GSC_noisy_speech = 0; + move16(); st->GSC_IVAS_mode = 0; + move16(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) + test(); + test(); + IF( ( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { IF( ( st->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) { @@ -1564,6 +1855,9 @@ ivas_error init_encoder_ivas_fx( } GSC_enc_init_fx( st->hGSCEnc ); +#if 1 + GSC_enc_init( st->hGSCEnc ); +#endif } ELSE { @@ -1574,7 +1868,8 @@ ivas_error init_encoder_ivas_fx( * TBE parameters *-----------------------------------------------------------------*/ - IF( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) { @@ -1588,6 +1883,10 @@ ivas_error init_encoder_ivas_fx( InitSWBencBuffer_fx( st ); ResetSHBbuffer_Enc_fx( st ); +#if 1 + InitSWBencBuffer( st->hBWE_TD ); + ResetSHBbuffer_Enc( st->hBWE_TD ); +#endif } ELSE { @@ -1599,7 +1898,8 @@ ivas_error init_encoder_ivas_fx( * SWB BWE parameters *-----------------------------------------------------------------*/ - IF( EQ_16( idchan, 0 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { @@ -1607,6 +1907,9 @@ ivas_error init_encoder_ivas_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); +#if 1 + fd_bwe_enc_init( st->hBWE_FD ); +#endif } ELSE { @@ -1617,7 +1920,7 @@ ivas_error init_encoder_ivas_fx( * HQ core parameters *-----------------------------------------------------------------*/ - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( idchan, 0 ) ) + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) { IF( ( st->hHQ_core = (HQ_ENC_HANDLE) malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) { @@ -1625,6 +1928,9 @@ ivas_error init_encoder_ivas_fx( } HQ_core_enc_init_fx( st->hHQ_core ); +#if 1 + HQ_core_enc_init( st->hHQ_core ); +#endif } ELSE { @@ -1633,27 +1939,40 @@ ivas_error init_encoder_ivas_fx( /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ st->old_hpfilt_in_fx = 0; + move16(); st->old_hpfilt_out_fx = 0; + move16(); st->EnergyLT_fx = 0; + move32(); st->Energy_Old_fx = 0; + move32(); st->TransientHangOver = 0; + move16(); + st->last_enerBuffer_exp = 0; + move16(); /*-----------------------------------------------------------------* * Channel-aware mode *-----------------------------------------------------------------*/ + test(); + test(); + test(); IF( !st->Opt_RF_ON || ( NE_16( st->bwidth, WB ) && NE_16( st->bwidth, SWB ) ) || NE_32( st->total_brate, ACELP_13k20 ) ) { st->rf_mode = 0; + move16(); } ELSE { st->rf_mode = st->Opt_RF_ON; + move16(); } st->rf_mode_last = st->rf_mode; + move16(); - IF( st->Opt_RF_ON || EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->Opt_RF_ON || st->element_mode == EVS_MONO ) { IF( ( st->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) { @@ -1662,6 +1981,9 @@ ivas_error init_encoder_ivas_fx( /* initialize RF indice buffers */ reset_rf_indices_fx( st ); +#if 1 + reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write ); +#endif } ELSE { @@ -1672,7 +1994,7 @@ ivas_error init_encoder_ivas_fx( * Temporal Envelope Coding *-----------------------------------------------------------------*/ - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { IF( ( st->hTECEnc = (TEC_ENC_HANDLE) malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) { @@ -1690,7 +2012,8 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel - IF( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) { @@ -1700,6 +2023,12 @@ ivas_error init_encoder_ivas_fx( /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; +#if 1 + set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); + st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; + st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; + set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); +#endif set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); @@ -1708,6 +2037,10 @@ ivas_error init_encoder_ivas_fx( /* MDCT classifier */ MDCT_classifier_reset_fx( st->hTcxEnc ); +#if 1 + MDCT_selector_reset( st->hTcxEnc ); + MDCT_classifier_reset( st->hTcxEnc ); +#endif IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -1725,6 +2058,15 @@ ivas_error init_encoder_ivas_fx( *-----------------------------------------------------------------*/ igf_brate = st->total_brate; + move32(); + + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) || EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) ) { igf_brate = L_sub( st->total_brate, i_mult( ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC ) ); @@ -1752,10 +2094,11 @@ ivas_error init_encoder_ivas_fx( igf_brate = ACELP_24k40; } } - ELSE IF( st->element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { igf_brate = element_brate; } + move32(); IF( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) { @@ -1765,8 +2108,12 @@ ivas_error init_encoder_ivas_fx( { st->igf = 0; } + move16(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) && ( st->igf || EQ_16( st->element_mode, EVS_MONO ) ) ) + test(); + test(); + test(); + IF( ( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) && ( st->igf || st->element_mode == EVS_MONO ) ) { IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { @@ -1782,11 +2129,12 @@ ivas_error init_encoder_ivas_fx( * Mode 2 initialization *-----------------------------------------------------------------*/ - st->last_sr_core = L_mult( st->last_L_frame, FRAMES_PER_SEC ); + st->last_sr_core = L_mult0( st->last_L_frame, FRAMES_PER_SEC ); + move32(); /* PLC encoder */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { IF( ( st->hPlcExt = (PLC_ENC_EVS_HANDLE) malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) { @@ -1800,30 +2148,41 @@ ivas_error init_encoder_ivas_fx( /* Init Mode 2 core coder */ st->last_totalNoise_fx = 0; + move16(); set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; + move16(); - init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /* initialization value */ ); + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ - IF( ( EQ_16( idchan, 0 ) && st->Opt_DTX_ON ) || EQ_16( st->element_mode, EVS_MONO ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) + test(); + test(); + test(); + test(); + IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { #if 0 - IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) - { - return error; - } + IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) + { + return error; + } #endif createFdCngEnc_fx( &st->hFdCngEnc ); initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); - +#if 1 + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); +#endif /* initialization for IVAS modes happens in first frame pre-processing */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); +#if 1 + configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); +#endif } } ELSE @@ -1852,14 +2211,29 @@ ivas_error init_encoder_ivas_fx( InitTransientDetection_ivas_fx( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } +#if 1 + if ( GT_16( st->element_mode, EVS_MONO ) ) + { + InitTransientDetection( frame_length, 0, st->hTranDet, 1 ); + } + else + { + InitTransientDetection( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + } +#endif + /*-----------------------------------------------------------------* * IVAS parameters *-----------------------------------------------------------------*/ st->tdm_LRTD_flag = 0; + move16(); st->cng_sba_flag = 0; + move16(); st->bits_frame_channel = 0; + move16(); st->side_bits_frame_channel = 0; + move16(); st->Q_syn2 = 0; move16(); st->Q_syn = 0; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index c3b4beaaedd61f6b043dc00f6686c40b9bb726f5..bff86bc97b6a0be75376db238fb9f01e1aa91ece 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -217,10 +217,38 @@ ivas_error ivas_core_enc( Word16 q_fft_buff; Word16 e_enerBuffer; + st->gamma = (Word16) floatToFixed( st->gamma_flt, Q15 ); + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); + + floatToFixed_arr16( st->lsp_old, st->lsp_old_fx, Q15, M ); + floatToFixed_arr16( st->lsp_old1, st->lsp_old1_fx, Q15, M ); + floatToFixed_arr16( st->lspold_enc, st->lspold_enc_fx, Q15, M ); + floatToFixed_arr16( st->voicing, st->voicing_fx, Q15, 3 ); + + IF( st->hTcxEnc ) + { + st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); + st->hTcxEnc->tcxltp_norm_corr_past = (Word16) floatToFixed( st->hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); + } + + IF( st->hTranDet ) + { + floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); + } + f2me( cor_map_sum[n], &cor_map_sum_fx, &exp_cor_map_sum ); - /*Decision_matrix enc*/ - q_fft_buff = Q_factor_arr( fft_buff[n], ( 2 * L_FFT ) ); + q_fft_buff = Q_factor_arrL( fft_buff[n], ( 2 * L_FFT ) ); + + if ( q_fft_buff <= 16 ) + { + q_fft_buff = 0; + } + else + { + q_fft_buff = q_fft_buff - 16; + } + if ( q_fft_buff >= 2 ) { q_fft_buff -= 3; @@ -229,6 +257,7 @@ ivas_error ivas_core_enc( { q_fft_buff -= 4; } + floatToFixed_arr( fft_buff[n], fft_buff_fx, q_fft_buff, ( 2 * L_FFT ) ); f2me_buf( enerBuffer[n], enerBuffer_fx, &e_enerBuffer, (Word32) CLDFB_NO_CHANNELS_MAX ); Word16 tmp_shift = find_guarded_bits_fx( 5 ); // Computing guraded bits necessary in the energyBuffer @@ -244,14 +273,6 @@ ivas_error ivas_core_enc( } } - /*setModeidx*/ - IF( st->envWeighted && !st->enableTcxLpc ) - { - /* Unweight the envelope */ - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q14 ); - } - /*setTcxmode*/ IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -264,17 +285,6 @@ ivas_error ivas_core_enc( move16(); move16(); move16(); - IF( st->hTranDet ) - { - floatToFixed_arr( st->hTranDet->subblockEnergies.subblockNrgChange_flt, st->hTranDet->subblockEnergies.subblockNrgChange, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); - } - IF( st->hTcxEnc ) - { - st->hTcxEnc->tfm_mem_fx = floatToFixed_32( st->hTcxEnc->tfm_mem, Q31 ); - move16(); - st->hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( st->hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); - move16(); - } } #endif if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], @@ -302,29 +312,31 @@ ivas_error ivas_core_enc( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*decison matrix*/ - if ( st->element_mode != IVAS_SCE && !st->low_rate_mode && !( st->total_brate > MAX_ACELP_BRATE ) && st->element_mode != IVAS_CPE_MDCT && st->coder_type != INACTIVE && st->sp_aud_decision1 != 0 && st->sp_aud_decision2 != 0 && st->sp_aud_decision1 != 1 && st->sp_aud_decision2 != 0 && !( st->element_mode == IVAS_CPE_TD || st->sp_aud_decision0 == 0 ) ) + st->gamma_flt = fixedToFloat_16( st->gamma, Q15 ); + st->preemph_fac_flt = fixedToFloat_16( st->preemph_fac, Q15 ); + + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); + fixedToFloat_arr( st->lsp_old1_fx, st->lsp_old1, Q15, M ); + fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); + fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); + + IF( st->hTcxEnc ) { - if ( st->hTcxEnc != NULL ) - { - st->hTcxEnc->clas_sec_old_flt = fix16_to_float( st->hTcxEnc->clas_sec_old_fx, Q13 ); - } + st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); + st->hTcxEnc->tcxltp_norm_corr_past_flt = fixedToFloat_16( st->hTcxEnc->tcxltp_norm_corr_past, Q15 ); } - /*setmode_index*/ - IF( st->envWeighted && !st->enableTcxLpc ) + IF( st->hTranDet ) { - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lsf_old_fx, st->lsf_old, Q15, M ); + fixedToFloat_arr( st->hTranDet->subblockEnergies.subblockNrgChange, st->hTranDet->subblockEnergies.subblockNrgChange_flt, Q15 - NRG_CHANGE_E, NSUBBLOCKS + MAX_TD_DELAY ); } - /*SetTCXModeInfo_ivas_fx*/ - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + /*decison matrix*/ + if ( st->element_mode != IVAS_SCE && !st->low_rate_mode && !( st->total_brate > MAX_ACELP_BRATE ) && st->element_mode != IVAS_CPE_MDCT && st->coder_type != INACTIVE && st->sp_aud_decision1 != 0 && st->sp_aud_decision2 != 0 && st->sp_aud_decision1 != 1 && st->sp_aud_decision2 != 0 && !( st->element_mode == IVAS_CPE_TD || st->sp_aud_decision0 == 0 ) ) { - if ( st->hTcxEnc ) + if ( st->hTcxEnc != NULL ) { - st->hTcxEnc->tfm_mem = fixedToFloat_32( st->hTcxEnc->tfm_mem_fx, Q31 ); - move16(); + st->hTcxEnc->clas_sec_old_flt = fix16_to_float( st->hTcxEnc->clas_sec_old_fx, Q13 ); } } #endif @@ -1365,7 +1377,95 @@ ivas_error ivas_core_enc( stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ ); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 shb_speech_fx32[L_FRAME16k]; + Word32 voice_factors_fx32[CPE_CHANNELS][NB_SUBFR16k]; + Word16 q_shb_speech_fx32 = Q_factor_arrL( shb_speech, L_FRAME16k ); + floatToFixed_arrL( shb_speech, shb_speech_fx32, q_shb_speech_fx32, L_FRAME16k ); + f2me_buf_16( hStereoICBWE->mixExc16k, hStereoICBWE->mixExc16k_fx, &hStereoICBWE->mixExc16k_e, L_FRAME16k ); + f2me_buf_16( hStereoICBWE->nlExc16k, hStereoICBWE->nlExc16k_fx, &hStereoICBWE->nlExc16k_e, L_FRAME16k ); + q_new_swb_speech_buffer = Q_factor_arrL( new_swb_speech_buffer, input_frame ); + floatToFixed_arrL( new_swb_speech_buffer, new_swb_speech_buffer_fx, q_new_swb_speech_buffer, input_frame ); + Copy_Scale_sig_16_32( voice_factors_fx[0], voice_factors_fx32[0], NB_SUBFR16k, 16 ); // Q31 + f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_nonref, hCPE->hStereoICBWE->mem_shb_speech_nonref_fx, &hCPE->hStereoICBWE->mem_shb_speech_nonref_e, L_LOOK_16k ); // shb_speech_ref_e + f2me_buf_16( hCPE->hStereoICBWE->mem_shb_speech_ref, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, &hCPE->hStereoICBWE->mem_shb_speech_ref_e, L_LOOK_16k ); // shb_speech_ref_e + f2me_buf_16( hCPE->hStereoICBWE->shbSynthRef, hCPE->hStereoICBWE->shbSynthRef_fx, &hCPE->hStereoICBWE->shbSynthRef_e, L_LOOK_16k ); // shb_speech_ref_e + + f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); + scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; + scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); + floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); + floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); + hCPE->hStereoICBWE->lpSHBRef_e = 31 - scale_factor; + +#endif + stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, 31 - q_shb_speech_fx32, new_swb_speech_buffer_fx, 31 - q_new_swb_speech_buffer, voice_factors_fx32[0] ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref, 15 - hStereoICBWE->mem_shb_speech_ref_e, LPC_SHB_ORDER ); + + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + hStereoICBWE->mem_nrg_L[0] = hCPE->hStereoDft->nrg_L[0]; + hStereoICBWE->mem_nrg_R[0] = hCPE->hStereoDft->nrg_R[0]; + hStereoICBWE->mem_nrg_DMX[0] = hCPE->hStereoDft->nrg_DMX[0]; + hStereoICBWE->mem_nrg_L[1] = hCPE->hStereoDft->nrg_L[1]; + hStereoICBWE->mem_nrg_R[1] = hCPE->hStereoDft->nrg_R[1]; + hStereoICBWE->mem_nrg_DMX[1] = hCPE->hStereoDft->nrg_DMX[1]; + hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, 31 ); + IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) + { + fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); + } + ELSE + { + me2f_buf_16( hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, hStereoICBWE->shbSynthRef, L_FRAME16k ); + } + + FOR( i = 0; i < 2; i++ ) + { + hStereoICBWE->memGsEnerMap[i] = me2f( hStereoICBWE->memGsEnerMap_fx[i], hStereoICBWE->memGsEnerMap_e ); + } + + hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, 0 ); + + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) + { + hStereoICBWE->prevSpecMapping = fixedToFloat( hStereoICBWE->prevSpecMapping_fx, Q31 ); + hStereoICBWE->memShbSpecMapping = fixedToFloat( hStereoICBWE->memShbSpecMapping_fx, 31 - hStereoICBWE->memShbSpecMapping_e ); + } + ELSE + { + hStereoICBWE->memShbSpecMapping = 0; + hStereoICBWE->prevSpecMapping = 0; + } + } + ELSE + { + hStereoICBWE->prevgsMapping = me2f( hStereoICBWE->prevgsMapping_fx, hStereoICBWE->prevgsMapping_e ); + hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + + IF( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) + { + + + me2f_buf( hStereoICBWE->memShbSpecXcorr_fx, hStereoICBWE->memShbSpecXcorr_e, hStereoICBWE->memShbSpecXcorr, 6 ); + hStereoICBWE->memShbSpecMapping = me2f( hStereoICBWE->memShbSpecMapping_fx, hStereoICBWE->memShbSpecMapping_e ); + } + + hStereoICBWE->prevRefEner = fixedToFloat( hStereoICBWE->prevRefEner_fx, 31 - hStereoICBWE->prevRefEner_e ); + hStereoICBWE->prevNonRefEner = fixedToFloat( hStereoICBWE->prevNonRefEner_fx, 31 - hStereoICBWE->prevNonRefEner_e ); + IF( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && st->flag_ACELP16k == 1 ) + { + fixedToFloat_arrL( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref, 31 - hStereoICBWE->mem_lpc_shbsynth_nonref_e, LPC_SHB_ORDER ); + } + hStereoICBWE->gDes_pastFrame = me2f( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e ); + } +#endif +#else stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] ); +#endif } /*---------------------------------------------------------------------* diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 46062b0dfad478d0c2fb95e504b76dd8e97d6117..e0dda8f53340e477af75d46e8ede3b3b1f13f037 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -107,6 +107,18 @@ ivas_error pre_proc_ivas( element_mode = st->element_mode; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )]; + Word16 lsp_new_fx[M]; + Word16 lsp_mid_fx[M]; + + floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); + floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); + floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); + floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); +#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS1 Word16 old_inp_16k_fx[L_INP_MEM]; Word16 exp_old_inp_16k = 0; @@ -114,7 +126,6 @@ ivas_error pre_proc_ivas( Word16 exp_old_inp_12k8 = 0; Word16 old_wsp_fx[L_WSP]; Word16 exp_old_wsp = 0; - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], exp_A = 0; Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], exp_Aw = 0; Word16 lsp_new_fx[M], exp_lsp_new = 0; Word16 lsp_mid_fx[M], exp_lsp_mid = 0; @@ -130,10 +141,6 @@ ivas_error pre_proc_ivas( f2me_buf_16( st->old_inp_16k, old_inp_16k_fx, &exp_old_inp_16k, L_INP_MEM ); f2me_buf_16( old_inp_12k8, old_inp_12k8_fx, &exp_old_inp_12k8, 496 ); f2me_buf_16( old_wsp, old_wsp_fx, &exp_old_wsp, L_WSP ); - f2me_buf_16( A, A_fx, &exp_A, NB_SUBFR16k * ( M + 1 ) ); - f2me_buf_16( Aw, Aw_fx, &exp_Aw, NB_SUBFR16k * ( M + 1 ) ); - f2me_buf_16( lsp_new, lsp_new_fx, &exp_lsp_new, M ); - f2me_buf_16( lsp_mid, lsp_mid_fx, &exp_lsp_mid, M ); f2me_buf_16( epsP, epsP_fx, &exp_epsP, M + 1 ); f2me( cor_map_sum, &cor_map_sum_fx, &exp_cor_map_sum ); #endif @@ -234,10 +241,6 @@ ivas_error pre_proc_ivas( IF( EQ_16( st->L_frame, L_FRAME ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->gamma_flt = GAMMA1_FLT; - st->preemph_fac_flt = PREEMPH_FAC_FLT; -#endif st->gamma = GAMMA1; st->preemph_fac = PREEMPH_FAC; move16(); @@ -246,10 +249,6 @@ ivas_error pre_proc_ivas( ELSE IF( EQ_16( st->L_frame, L_FRAME32k ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; -#endif st->gamma = GAMMA16k; st->preemph_fac = PREEMPH_FAC_SWB; move16(); @@ -257,10 +256,6 @@ ivas_error pre_proc_ivas( } ELSE { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->gamma_flt = GAMMA16k_FLT; - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; -#endif st->gamma = GAMMA16k; st->preemph_fac = PREEMPH_FAC_16k; move16(); @@ -508,10 +503,6 @@ ivas_error pre_proc_ivas( IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = PREEMPH_FAC_FLT; - st->gamma_flt = GAMMA1_FLT; -#endif st->preemph_fac = PREEMPH_FAC; st->gamma = GAMMA1; move16(); @@ -519,10 +510,6 @@ ivas_error pre_proc_ivas( } ELSE IF( EQ_32( st->sr_core, INT_FS_16k ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - st->gamma_flt = GAMMA16k_FLT; -#endif st->preemph_fac = PREEMPH_FAC_16k; st->gamma = GAMMA16k; move16(); @@ -530,10 +517,6 @@ ivas_error pre_proc_ivas( } ELSE /* st->sr_core >=25600 */ { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->preemph_fac_flt = PREEMPH_FAC_SWB_FLT; - st->gamma_flt = GAMMA16k_FLT; -#endif st->preemph_fac = PREEMPH_FAC_SWB; st->gamma = GAMMA16k; move16(); @@ -557,9 +540,6 @@ ivas_error pre_proc_ivas( } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->hTcxEnc->tfm_mem = 0.75f; -#endif st->hTcxEnc->tfm_mem_fx = 1610612736; /*0.75f in Q31*/ move32(); } @@ -966,7 +946,21 @@ ivas_error pre_proc_ivas( if ( !flag_16k_smc ) { - error = ivas_compute_core_buffers( st, &inp_16k, old_inp_16k, new_inp_resamp16k, input_frame, last_element_mode, sr_core_tmp, ener, A, Aw, epsP, lsp_new, lsp_mid ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#endif + error = ivas_compute_core_buffers( st, &inp_16k, old_inp_16k, new_inp_resamp16k, input_frame, last_element_mode, sr_core_tmp, ener, +#ifndef IVAS_FLOAT_FIXED + A, Aw, +#else + A_fx, Aw_fx, +#endif + epsP, +#ifndef IVAS_FLOAT_FIXED + lsp_new, lsp_mid +#else + lsp_new_fx, lsp_mid_fx +#endif + ); if ( error != IVAS_ERR_OK ) { return error; @@ -1064,6 +1058,13 @@ ivas_error pre_proc_ivas( } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( Aw_fx, Aw, Q14 - norm_s( Aw_fx[0] ), NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); + fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); +#endif + pop_wmops(); return error; } @@ -1076,19 +1077,29 @@ ivas_error pre_proc_ivas( *--------------------------------------------------------------------*/ ivas_error ivas_compute_core_buffers( - Encoder_State *st, /* i/o: encoder state structure */ - float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ - float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ - float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - const int16_t input_frame, /* i : frame length */ - const int16_t last_element_mode, /* i : last element mode */ - const int32_t sr_core, /* i : core-coder sampling rate */ - float *ener, /* o : residual energy from Levinson-Durbin */ + Encoder_State *st, /* i/o: encoder state structure */ + float **inp16k_out, /* o : ptr. to inp. signal in the current frame */ + float *old_inp_16k, /* i/o: buffer of old input signal @ 16kHz */ + float new_inp_resamp16k_out[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + const int16_t input_frame, /* i : frame length */ + const int16_t last_element_mode, /* i : last element mode */ + const int32_t sr_core, /* i : core-coder sampling rate */ + float *ener, /* o : residual energy from Levinson-Durbin */ +#ifndef IVAS_FLOAT_FIXED float A[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ float Aw[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ - float epsP[M + 1], /* i/o: LP prediction errors */ - float lsp_new[M], /* i/o: LSPs at the end of the frame */ - float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ +#else + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */ +#endif + float epsP[M + 1], /* i/o: LP prediction errors */ +#ifndef IVAS_FLOAT_FIXED + float lsp_new[M], /* i/o: LSPs at the end of the frame */ + float lsp_mid[M] /* i/o: LSPs in the middle of the frame */ +#else + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ + Word16 lsp_mid_fx[M] /* i/o: LSPs in the middle of the frame */ +#endif ) { float *inp_16k, *new_inp_16k; @@ -1780,21 +1791,19 @@ ivas_error ivas_compute_core_buffers( * LPC analysis *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED if ( st->last_L_frame == L_FRAME ) { /* this is just an approximation, but it is sufficient */ mvr2r( st->lsp_old1, st->lspold_enc, M ); } -#ifndef IVAS_FLOAT_FIXED analy_lp( inp_16k, L_FRAME16k, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lspold_enc, st->pitch, st->voicing, INT_FS_16k, 0 ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 *inp_16k_fx; - Word16 A_fx[NB_SUBFR16k * ( M + 1 )]; Word32 epsP_fx[M + 1]; Word16 epsP_h[M + 1], epsP_l[M + 1]; - Word16 lsp_new_fx[M], lsp_mid_fx[M]; Word16 e_esp; Word16 Q_r[2] = { 0 }; @@ -1833,22 +1842,18 @@ ivas_error ivas_compute_core_buffers( Word16 exp_ener; f2me_buf( ener, ener_fx, &exp_ener, CPE_CHANNELS ); - floatToFixed_arr( A, A_fx, Q14, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M ); - floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); - floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); #endif + IF( st->last_L_frame == L_FRAME ) + { + /* this is just an approximation, but it is sufficient */ + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); + } + analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_old_inp_16k, Q_r ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS me2f_buf_16( old_inp_16k_fx, exp_old_inp_16k, old_inp_16k, L_INP ); me2f_buf( ener_fx, exp_ener, ener, CPE_CHANNELS ); - fixedToFloat_arr( A_fx, A, Q14, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); - fixedToFloat_arr( st->lspold_enc_fx, st->lspold_enc, Q15, M ); - fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); for ( i = 0; i < M + 1; i++ ) { epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); @@ -1865,23 +1870,15 @@ ivas_error ivas_compute_core_buffers( find_wsp( L_FRAME16k, L_SUBFR, NB_SUBFR16k, A, Aw, st->speech_enc_pe_flt, PREEMPH_FAC_16k_FLT, st->wspeech_enc_flt, &st->mem_wsp_enc_flt, st->gamma_flt, L_LOOK_16k ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )]; - - floatToFixed_arr( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr( st->speech_enc_pe_flt - M, st->speech_enc_pe - M, Q9, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k - st->encoderPastSamples_enc + M ); floatToFixed_arr( st->wspeech_enc_flt, st->wspeech_enc, Q9, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k - st->L_frame - L_SUBFR ); st->mem_wsp_enc = (Word16) floatToFixed( st->mem_wsp_enc_flt, Q9 ); - st->gamma = (Word16) floatToFixed( st->gamma_flt, Q15 ); - #endif ivas_find_wsp( L_FRAME16k, L_SUBFR, NB_SUBFR16k, A_fx, Aw_fx, st->speech_enc_pe, PREEMPH_FAC_16k, st->wspeech_enc, &st->mem_wsp_enc, st->gamma, L_LOOK_16k ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( st->wspeech_enc, st->wspeech_enc_flt, Q9, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k - st->L_frame - L_SUBFR ); st->mem_wsp_enc_flt = fixedToFloat( st->mem_wsp_enc, Q9 ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 117bffd8e932002a7cbfbba8b4a00ccf09642fd6..72d95d33d97650ad5de5a0790ff37a9b9d464f89 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -984,7 +984,7 @@ ivas_error pre_proc_front_ivas_fx( Word32 non_staX_fx; float stab_fac; Word16 alw_pitch_lag_12k8[2]; - float alw_voicing[2]; + Word16 alw_voicing_fx[2]; Word16 last_core_orig; // float dummy; float S_map[L_FFT / 2]; @@ -1867,6 +1867,7 @@ ivas_error pre_proc_front_ivas_fx( st->last_totalNoise_fx = float_to_fix16( st->last_totalNoise, Q8 ); st->hNoiseEst->totalNoise_fx = float_to_fix16( st->hNoiseEst->totalNoise, Q8 ); + FOR( Word16 j = 0; j < TOTALNOISE_HIST_SIZE; j++ ) { st->totalNoise_increase_hist_fx[j] = float_to_fix16( st->totalNoise_increase_hist[j], Q8 ); @@ -2034,38 +2035,164 @@ ivas_error pre_proc_front_ivas_fx( if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { - AdjustFirstSID( st ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->hFdCngEnc->msPeriodog_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); + st->hFdCngEnc->msPeriodog_fx_exp_fft = st->hFdCngEnc->msPeriodog_fx_exp_cldfb = st->hFdCngEnc->msPeriodog_fx_exp; + st->hFdCngEnc->energy_ho_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->energy_ho, NPART ); + st->hFdCngEnc->msNoiseEst_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); + st->hFdCngEnc->msNoiseEst_old_fx_exp = 31 - Q_factor_arrL( st->hFdCngEnc->msNoiseEst_old, NPART ); + floatToFixed_arrL( st->hFdCngEnc->msPeriodog, st->hFdCngEnc->msPeriodog_fx, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); + floatToFixed_arrL( st->hFdCngEnc->energy_ho, st->hFdCngEnc->energy_ho_fx, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); + floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + floatToFixed_arrL( st->hFdCngEnc->msNoiseEst_old, st->hFdCngEnc->msNoiseEst_old_fx, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); +#endif + + AdjustFirstSID_fx( st->hFdCngEnc->hFdCngCom->npart, st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog_fx_exp, st->hFdCngEnc->energy_ho_fx, + &st->hFdCngEnc->energy_ho_fx_exp, st->hFdCngEnc->msNoiseEst_fx, &st->hFdCngEnc->msNoiseEst_fx_exp, st->hFdCngEnc->msNoiseEst_old_fx, + &st->hFdCngEnc->msNoiseEst_old_fx_exp, &( st->hFdCngEnc->hFdCngCom->active_frame_counter ), st ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( st->hFdCngEnc->msPeriodog_fx, st->hFdCngEnc->msPeriodog, 31 - st->hFdCngEnc->msPeriodog_fx_exp, NPART ); + fixedToFloat_arrL( st->hFdCngEnc->energy_ho_fx, st->hFdCngEnc->energy_ho, 31 - st->hFdCngEnc->energy_ho_fx_exp, NPART ); + fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_fx, st->hFdCngEnc->msNoiseEst, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); + fixedToFloat_arrL( st->hFdCngEnc->msNoiseEst_old_fx, st->hFdCngEnc->msNoiseEst_old, 31 - st->hFdCngEnc->msNoiseEst_old_fx_exp, NPART ); +#endif } /*----------------------------------------------------------------* * LP analysis *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 *old_inp_12k8_loc_fx = (Word16 *) malloc( L_INP_12k8 * sizeof( Word16 * ) ); + Word16 *inp_12k8_loc_fx, *new_inp_12k8_loc_fx; /* pointers to current frame and new data */ + new_inp_12k8_loc_fx = old_inp_12k8_loc_fx + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8_loc_fx = new_inp_12k8_loc_fx - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ + Word16 lsp_new_loc_fx[M]; + Word16 lsp_mid_loc_fx[M]; + Word16 lsf_new_16_loc_fx[M]; + Word16 stab_fac_fx; + Word16 Q_new_loc; + Word16 Q_r[2] = { 0 }; + Word16 A_loc_fx[NB_SUBFR16k * ( M + 1 )]; + Word16 epsP_l_loc[M + 1]; + Word16 epsP_h_loc[M + 1]; + Word32 ener_fx; + Q_new_loc = Q_factor_arrL( old_inp_12k8, L_INP_12k8 ); + Q_new_loc = 0; /* Dynamic Q_new used above causes overflow issues */ + for ( int k = 0; k < L_INP_12k8; k++ ) + { + if ( fabs( old_inp_12k8[k] ) > 32768.0f ) + { + Q_new_loc = -1; + break; + } + } + for ( int idx = 0; idx < L_INP_12k8; idx++ ) + { + old_inp_12k8_loc_fx[idx] = (Word16) ( old_inp_12k8[idx] * ( 1 << Q_new_loc ) ); + } + for ( int idx = 0; idx < M; idx++ ) + { + lsp_new_loc_fx[idx] = (Word16) ( lsp_new[idx] * 32767 ); + st->lsp_old1_fx[idx] = (Word16) ( st->lsp_old1[idx] * 32767 ); + st->lsf_old1_fx[idx] = (Word16) ( st->lsf_old1[idx] * 2.56 ); + } + for ( int idx = 0; idx < 3; idx++ ) + { + st->voicing_fx[idx] = (Word16) ( st->voicing[idx] * 32767 ); + } +#endif alw_pitch_lag_12k8[0] = st->old_pitch_la; + move16(); alw_pitch_lag_12k8[1] = st->old_pitch_la; - alw_voicing[0] = st->voicing[2]; - alw_voicing[1] = st->voicing[2]; + move16(); + alw_voicing_fx[0] = st->voicing_fx[2]; + move16(); + alw_voicing_fx[1] = st->voicing_fx[2]; + move16(); i = 0; - if ( element_mode == IVAS_CPE_TD && st->idchan == 1 && hCPE->hStereoTD->tdm_low_rate_mode == 1 ) + move16(); + + test(); + test(); + if ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && EQ_16( hCPE->hStereoTD->tdm_low_rate_mode, 1 ) ) { i = 1; + move16(); } - analy_lp( inp_12k8, L_FRAME, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, i ); + analy_lp_fx( inp_12k8_loc_fx, L_FRAME, L_look, &ener_fx, A_loc_fx, epsP_h_loc, epsP_l_loc, lsp_new_loc_fx, lsp_mid_loc_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, + INT_FS_12k8, i, Q_new_loc, Q_r ); - lsp2lsf( lsp_new, lsf_new, M, INT_FS_12k8 ); - stab_fac = lsf_stab( lsf_new, st->lsf_old1, 0, L_FRAME ); - mvr2r( lsf_new, st->lsf_old1, M ); + lsp2lsf_fx( lsp_new_loc_fx, lsf_new_16_loc_fx, M, INT_FS_12k8 ); + stab_fac_fx = lsf_stab_fx( lsf_new_16_loc_fx, st->lsf_old1_fx, 0, L_FRAME ); + + Copy( lsf_new_16_loc_fx, st->lsf_old1_fx, M ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + float power_2 = powf( 2.0, (float) ( Q_r[0] + 1 ) ); + float check_float; + for ( int idx = 0; idx < M + 1; idx++ ) + { + Word32 check = L_Comp( epsP_h_loc[idx], epsP_l_loc[idx] ); + check_float = (float) check / power_2; + epsP[idx] = check_float; + } + check_float = (float) ener_fx / power_2; + *ener = check_float; + + for ( int idx = 0; idx < M; idx++ ) + { + + lsp_new[idx] = (float) lsp_new_loc_fx[idx] / 32767.0f; + lsp_mid[idx] = (float) lsp_mid_loc_fx[idx] / 32767.0f; + st->lsp_old1[idx] = (float) ( (float) st->lsp_old1_fx[idx] / 32767.0f ); + st->lsf_old1[idx] = (float) ( (float) st->lsf_old1_fx[idx] / 2.56f ); + lsf_new[idx] = (float) ( (float) lsf_new_16_loc_fx[idx] / 2.56f ); + } + for ( int idx = 0; idx < NB_SUBFR16k * ( M + 1 ); idx++ ) + { + A[idx] = (float) ( (float) A_loc_fx[idx] / 16384.0f ); + } + + stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); +#endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { /*----------------------------------------------------------------* * Comparison of the LP coefficents to determine if it is possible * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + Word32 isp_PCh_fx[M]; + Word32 isp_SCh_fx[M]; + Word16 A_SCh_fx[M + 1]; + Word16 A_PCh_fx[M + 1]; + Word32 speech_buff[L_FRAME + M]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_speech = Q_factor_arrL( inp_12k8 - M, L_FRAME + M ); + Word16 gb1 = find_guarded_bits_fx( M ); + floatToFixed_arr32( inp_12k8 - M, speech_buff, Q_speech - gb1, L_FRAME + M ); + for ( i = 0; i < M + 1; i++ ) + { + A_PCh_fx[i] = (Word16) ( tdm_A_PCh[i] * ONE_IN_Q12 ); + A_SCh_fx[i] = (Word16) ( A[i] * ONE_IN_Q12 ); + } + for ( i = 0; i < M; i++ ) + { + isp_PCh_fx[i] = (Word32) ( tdm_lsp_new_PCh[i] * MAX_32 ); + isp_SCh_fx[i] = (Word32) ( lsp_new[i] * MAX_32 ); + } +#endif + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], A_PCh_fx, A_SCh_fx, M, isp_PCh_fx, isp_SCh_fx, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC, Q_speech ); +#else hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison( hCPE->hStereoTD, hCPE->hStereoClassif, st, inp_12k8, tdm_A_PCh, A, M, tdm_lsp_new_PCh, lsp_new, L_FRAME, element_brate - nb_bits_metadata * FRAMES_PER_SEC ); + +#endif } /*----------------------------------------------------------------* @@ -2082,10 +2209,8 @@ ivas_error pre_proc_front_ivas_fx( Word16 *inp_12k8_fx1 = &buf[M]; // this is done because find_wsp accesses inp from -16 index Word16 wsp_fx1[L_FRAME + L_LOOK_12k8] = { 0 }; - for ( i = 0; i < ( NB_SUBFR16k - 1 ) * ( M + 1 ); i++ ) - { - A_fx[i] = (Word16) floatToFixed( A[i], Q12 ); - } + floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); + Word16 e1, e2, q_inp_12k8; f2me_buf_16( inp_12k8 - M, inp_12k8_fx1, &e1, 368 + M ); f2me_buf_16( &st->mem_wsp, &st->mem_wsp_fx, &e2, 1 ); @@ -2209,7 +2334,6 @@ ivas_error pre_proc_front_ivas_fx( } } - floatToFixed_arr16( A, A_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); st->bckr_tilt_lt = float_to_fix( st->bckr_tilt_lt_flt, Q16 ); @@ -2458,13 +2582,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); st->bckr_tilt_lt_flt = fixedToFloat_32( st->bckr_tilt_lt, Q16 ); - if ( hStereoClassif != NULL ) - { - hStereoClassif->dE1_ch1 = fixedToFloat_32( hStereoClassif->dE1_ch1_fx, 31 - hStereoClassif->dE1_ch1_e ); - hStereoClassif->dE1_ch2 = fixedToFloat_32( hStereoClassif->dE1_ch2_fx, 31 - hStereoClassif->dE1_ch2_e ); - hStereoClassif->nchar_ch1 = fixedToFloat_32( hStereoClassif->nchar_ch1_fx, 31 - hStereoClassif->nchar_ch1_e ); - hStereoClassif->nchar_ch2 = fixedToFloat_32( hStereoClassif->nchar_ch2_fx, 31 - hStereoClassif->nchar_ch2_e ); - } fixedToFloat_arrL32( st->old_enr_ssf_fx, st->old_enr_ssf, 0, 2 * NB_SSF ); non_staX = fixedToFloat_16( non_staX16_fx, Q8 ); @@ -2674,32 +2791,14 @@ ivas_error pre_proc_front_ivas_fx( #if 1 #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 non_staX_e, sp_div_e, epsP_e, max_e_Etot; - hStereoClassif->relE_buf_e = 0; - f2me( hStereoClassif->ave_ener_L, &hStereoClassif->ave_ener_L_fx, &hStereoClassif->ave_ener_L_fx_e ); - f2me( hStereoClassif->ave_ener_R, &hStereoClassif->ave_ener_R_fx, &hStereoClassif->ave_ener_R_fx_e ); - f2me_buf( hStereoClassif->Etot_buf, hStereoClassif->Etot_buf_fx, &hStereoClassif->e_Etot_buf_fx, 3 ); - floatToFixed_arr32( hStereoClassif->relE_buf, hStereoClassif->relE_buf_fx, 31 - hStereoClassif->relE_buf_e, 3 ); - hStereoClassif->relE_0_1_LT_fx = float_to_fix( hStereoClassif->relE_0_1_LT, 31 - hStereoClassif->relE_buf_e ); - hStereoClassif->relE_0_1_fx = float_to_fix( hStereoClassif->relE_0_1, 31 - hStereoClassif->relE_buf_e ); - f2me( hStereoClassif->Etot_up, &hStereoClassif->Etot_up_fx, &hStereoClassif->Etot_up_e ); - f2me( hStereoClassif->Etot_dn, &hStereoClassif->Etot_dn_fx, &hStereoClassif->Etot_dn_e ); floatToFixed_arr32( lsf_new, lsf_new_fx, Q15, M ); f2me( hStereoClassif->ratio_L, &hStereoClassif->ratio_L_fx, &hStereoClassif->ratio_L_e ); - hStereoClassif->lepsP_ch1_fx = float_to_fix( hStereoClassif->lepsP_ch1, Q15 ); - floatToFixed_arr32( hStereoClassif->lsf_ch1, hStereoClassif->lsf_ch1_fx, Q15, M ); - floatToFixed_arr32( hStereoClassif->xtalk_fv, hStereoClassif->xtalk_fv_fx, Q15, 58 ); f2me_buf( hStereoClassif->voicing_ch1, hStereoClassif->voicing_ch1_fx, &hStereoClassif->voicing_ch1_e, 3 ); f2me_buf_16( st->voicing, st->voicing_fx, &st->voicing_e, 3 ); f2me( non_staX, &non_staX_fx, &non_staX_e ); - f2me( hStereoClassif->nchar_ch1, &hStereoClassif->nchar_ch1_fx, &hStereoClassif->nchar_ch1_e ); f2me_buf( epsP, epsP_fx, &epsP_e, 17 ); - f2me( hStereoClassif->cor_map_sum_ch1, &hStereoClassif->cor_map_sum_ch1_fx, &hStereoClassif->cor_map_sum_ch1_e ); f2me( hStereoClassif->non_sta_ch1, &hStereoClassif->non_sta_ch1_fx, &hStereoClassif->non_sta_ch1_e ); f2me( hStereoClassif->sp_div_ch1, &hStereoClassif->sp_div_ch1_fx, &hStereoClassif->sp_div_ch1_e ); - f2me( hStereoClassif->nchar_ch1, &hStereoClassif->nchar_ch1_fx, &hStereoClassif->nchar_ch1_e ); - f2me( hStereoClassif->nchar_ch2, &hStereoClassif->nchar_ch2_fx, &hStereoClassif->nchar_ch2_e ); - f2me( hStereoClassif->dE1_ch1, &hStereoClassif->dE1_ch1_fx, &hStereoClassif->dE1_ch1_e ); - f2me( hStereoClassif->dE1_ch2, &hStereoClassif->dE1_ch2_fx, &hStereoClassif->dE1_ch2_e ); f2me( hStereoClassif->ps_diff_ch1, &hStereoClassif->ps_diff_ch1_fx, &hStereoClassif->ps_diff_ch1_e ); f2me( hStereoClassif->ps_sta_ch1, &hStereoClassif->ps_sta_ch1_fx, &hStereoClassif->ps_sta_ch1_e ); f2me( hStereoClassif->ps_diff_ch2, &hStereoClassif->ps_diff_ch2_fx, &hStereoClassif->ps_diff_ch2_e ); @@ -2715,23 +2814,9 @@ ivas_error pre_proc_front_ivas_fx( st->pitch, st->voicing_fx, cor_map_sum_fx, non_staX_fx, sp_div_fx, st->clas, epsP_e, st->voicing_e, cor_map_sum_e, non_staX_e, sp_div_e ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - me2f_buf( hStereoClassif->Etot_buf_fx, hStereoClassif->e_Etot_buf_fx, hStereoClassif->Etot_buf, 3 ); - me2f_buf( hStereoClassif->relE_buf_fx, hStereoClassif->relE_buf_e, hStereoClassif->relE_buf, 10 ); - me2f_buf( hStereoClassif->lsf_ch1_fx, 16, hStereoClassif->lsf_ch1, 16 ); - me2f_buf( hStereoClassif->xtalk_fv_fx, 16, hStereoClassif->xtalk_fv, 58 ); me2f_buf( hStereoClassif->voicing_ch1_fx, hStereoClassif->voicing_ch1_e, hStereoClassif->voicing_ch1, 3 ); - hStereoClassif->lepsP_ch1 = me2f( hStereoClassif->lepsP_ch1_fx, 16 ); - hStereoClassif->Etot_up = me2f( hStereoClassif->Etot_up_fx, hStereoClassif->Etot_up_e ); - hStereoClassif->Etot_dn = me2f( hStereoClassif->Etot_dn_fx, hStereoClassif->Etot_dn_e ); - hStereoClassif->relE_0_1 = me2f( hStereoClassif->relE_0_1_fx, hStereoClassif->relE_buf_e ); - hStereoClassif->relE_0_1_LT = me2f( hStereoClassif->relE_0_1_LT_fx, hStereoClassif->relE_buf_e ); - hStereoClassif->cor_map_sum_ch1 = me2f( hStereoClassif->cor_map_sum_ch1_fx, hStereoClassif->cor_map_sum_ch1_e ); hStereoClassif->non_sta_ch1 = me2f( hStereoClassif->non_sta_ch1_fx, hStereoClassif->non_sta_ch1_e ); hStereoClassif->sp_div_ch1 = me2f( hStereoClassif->sp_div_ch1_fx, hStereoClassif->sp_div_ch1_e ); - hStereoClassif->nchar_ch1 = me2f( hStereoClassif->nchar_ch1_fx, hStereoClassif->nchar_ch1_e ); - hStereoClassif->nchar_ch2 = me2f( hStereoClassif->nchar_ch2_fx, hStereoClassif->nchar_ch2_e ); - hStereoClassif->dE1_ch1 = me2f( hStereoClassif->dE1_ch1_fx, hStereoClassif->dE1_ch1_e ); - hStereoClassif->dE1_ch2 = me2f( hStereoClassif->dE1_ch2_fx, hStereoClassif->dE1_ch2_e ); hStereoClassif->ps_diff_ch1 = me2f( hStereoClassif->ps_diff_ch1_fx, hStereoClassif->ps_diff_ch1_e ); hStereoClassif->ps_sta_ch1 = me2f( hStereoClassif->ps_sta_ch1_fx, hStereoClassif->ps_sta_ch1_e ); hStereoClassif->ps_diff_ch2 = me2f( hStereoClassif->ps_diff_ch2_fx, hStereoClassif->ps_diff_ch2_e ); @@ -2954,12 +3039,37 @@ ivas_error pre_proc_front_ivas_fx( if ( flag_16k_smc ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 lsp_mid_fx[M]; + + floatToFixed_arr16( Aw, Aw_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); + floatToFixed_arr16( lsp_new, lsp_new_fx, Q15, M ); + floatToFixed_arr16( lsp_mid, lsp_mid_fx, Q15, M ); +#endif + /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, A, Aw, epsP, lsp_new, lsp_mid ); + error = ivas_compute_core_buffers( st, NULL, old_inp_16k, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener, +#ifndef IVAS_FLOAT_FIXED + A, Aw, +#else + A_fx, Aw_fx, +#endif + epsP, +#ifndef IVAS_FLOAT_FIXED + lsp_new, lsp_mid +#else + lsp_new_fx, lsp_mid_fx +#endif + ); if ( error != IVAS_ERR_OK ) { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arr( Aw_fx, Aw, Q12, NB_SUBFR16k * ( M + 1 ) ); + fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); + fixedToFloat_arr( lsp_mid_fx, lsp_mid, Q15, M ); +#endif smc_dec = ivas_acelp_tcx20_switching( st, st->speech_enc_flt, st->wspeech_enc_flt, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); } @@ -2981,14 +3091,31 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_cor_map = Q_factor_arr( st->hNoiseEst->cor_map, L_FFT / 2 ); floatToFixed_arr( st->hNoiseEst->cor_map, st->hNoiseEst->cor_map_fx, Q_cor_map, L_FFT / 2 ); - Word16 q1 = Q_factor_arr( st->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); - Word16 q2 = Q_factor_arr( st->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.subblockNrg_flt, st->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); - floatToFixed_arrL( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; - st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + IF( EQ_16( element_mode, IVAS_SCE ) ) + { + Word16 q1 = Q_factor_arr( st->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); + Word16 q2 = Q_factor_arr( st->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); + + st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); + floatToFixed_arrL( st->hTranDet->subblockEnergies.subblockNrg_flt, st->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); + floatToFixed_arrL( st->hTranDet->subblockEnergies.accSubblockNrg_flt, st->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); + st->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; + st->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Word16 q1 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY ); + Word16 q2 = Q_factor_arr( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, NSUBBLOCKS + MAX_TD_DELAY + 1 ); + + hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg = float_to_fix16( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt, Q15 ); + floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, q1, NSUBBLOCKS + MAX_TD_DELAY ); + floatToFixed_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = 31 - q1; + hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - q2; + } + } #endif IF( EQ_16( element_mode, IVAS_SCE ) ) @@ -3014,9 +3141,21 @@ ivas_error pre_proc_front_ivas_fx( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( st->hNoiseEst->cor_map_fx, st->hNoiseEst->cor_map, Q_cor_map, L_FFT / 2 ); - fixedToFloat_arrL( st->hTranDet->subblockEnergies.subblockNrg, st->hTranDet->subblockEnergies.subblockNrg_flt, q1, NSUBBLOCKS + MAX_TD_DELAY ); - fixedToFloat_arrL( st->hTranDet->subblockEnergies.accSubblockNrg, st->hTranDet->subblockEnergies.accSubblockNrg_flt, q2, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); + IF( EQ_16( element_mode, IVAS_SCE ) ) + { + fixedToFloat_arrL( st->hTranDet->subblockEnergies.subblockNrg, st->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); + fixedToFloat_arrL( st->hTranDet->subblockEnergies.accSubblockNrg, st->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - st->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); + st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( st->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY ); + fixedToFloat_arrL( hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg, hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_flt, ( 31 - hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e ), NSUBBLOCKS + MAX_TD_DELAY + 1 ); + hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg_flt = fix16_to_float( hCPE->hCoreCoder[i]->hTranDet->transientDetector.pSubblockEnergies->facAccSubblockNrg, Q15 ); + } + } #endif #else if ( element_mode == IVAS_SCE ) @@ -3117,6 +3256,11 @@ ivas_error pre_proc_front_ivas_fx( mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 tmp = norm_s( A_fx[0] ); + fixedToFloat_arr( A_fx, A, Q14 - tmp, NB_SUBFR16k * ( M + 1 ) ); +#endif + #ifdef IVAS_FLOAT_FIXED free( enerBuffer_fx ); free( old_inp_16k_fx ); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index bad7375f5479a781feed11182c054ee8f1392cb7..a97541343a1a43b0b4b3a4475e2f7dc22d683024 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -35,6 +35,7 @@ #include "ivas_cnst.h" #include "prot.h" #include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_prot.h" #include "wmc_auto.h" @@ -44,6 +45,7 @@ * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_corecoder_enc_reconfig( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -500,3 +502,525 @@ ivas_error ivas_corecoder_enc_reconfig( return error; } +#else +/* Some float operations are still pending */ +ivas_error ivas_corecoder_enc_reconfig( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame */ + const Word16 nCPE_old, /* i : number of CPEs in previous frame */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ + const Word32 brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ +) +{ + Word16 n, sce_id, cpe_id; + Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; + float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + BSTR_ENC_HANDLE hBstr; + Word16 i, nb_bits; + Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST]; + Word16 nb_bits_tot; + Word16 nchan_transport_real, nchan_transport_old_real; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + hEncoderConfig = st_ivas->hEncoderConfig; + error = IVAS_ERR_OK; + + len_inp_memory = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); + IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) + { + len_inp_memory = add( len_inp_memory, NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ) ); + } + + nchan_transport_old_real = nchan_transport_old; + move16(); + nchan_transport_real = st_ivas->nchan_transport; + move16(); + + if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); + } + + /*-----------------------------------------------------------------* + * Switching between SCE(s)/CPE(s)/MCT + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( EQ_16( nchan_transport_real, nchan_transport_old_real ) && EQ_16( st_ivas->nSCE, nSCE_old ) && EQ_16( st_ivas->nCPE, nCPE_old ) ) /* in McMASA, nchan_transport may be the same, but nSCE/nCPE differs */ + { + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + move32(); + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + move32(); + + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + + Word16 tmp = 1; + move16(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + tmp = 0; + move16(); + } + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + // st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + } + + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + IF( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + + /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */ + test(); + IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) ) + { + nchan_transport_old_real = add( nSCE_old, i_mult( CPE_CHANNELS, nCPE_old ) ); + } + + test(); + IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + nchan_transport_real = add( st_ivas->nSCE, i_mult( CPE_CHANNELS, st_ivas->nCPE ) ); + } + + /* something in transport changes */ + hBstr = NULL; + + /* get the index list pointers */ + IF( nSCE_old ) + { + hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + } + ELSE IF( nCPE_old ) + { + hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + } + + /* save bitstream information */ + nb_bits_tot = hBstr->nb_bits_tot; + move16(); + i = 0; + move16(); + nb_bits = 0; + move16(); + + test(); + WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) + { + IF( hBstr->ind_list[i].nb_bits > 0 ) + { + temp_ind_list[i].id = hBstr->ind_list[i].id; + move16(); + temp_ind_list[i].value = hBstr->ind_list[i].value; + move16(); + temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits; + move16(); + hBstr->ind_list[i].nb_bits = -1; + move16(); + } + + hBstr->nb_bits_tot = 0; + move16(); + hBstr->nb_ind_tot = 0; + move16(); + + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + i = add( i, 1 ); + test(); + } + + FOR( ; i < MAX_NUM_IND_TEMP_LIST; i++ ) + { + /* reset nb_bits of all other indices to -1 */ + temp_ind_list[i].nb_bits = -1; + move16(); + } + + test(); + test(); + IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + /* within McMASA we can modify the transport signals when switching */ + /* copy earlier dmx buffers */ + IF( nSCE_old > 0 ) + { + set_zero( input_buff[0], len_inp_memory ); + mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + set_zero( input_buff[n + 1], len_inp_memory ); + IF( nCPE_old > 0 ) + { + mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + } + } + + ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + + n_CoreCoder_existing = 0; + move16(); + } + ELSE + { + n_CoreCoder_existing = s_min( nchan_transport_real, nchan_transport_old_real ); + } + + /* destroy superfluous core-coder elements */ + FOR( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + { + /* save input audio buffers */ + IF( GT_16( n_CoreCoder_existing, sce_id ) ) + { + mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + } + + destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); + st_ivas->hSCE[sce_id] = NULL; + } + + FOR( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + { + /* save input audio buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) + { + mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + } + } + + destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + test(); + IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) + { + ivas_mct_enc_close( &( st_ivas->hMCT ) ); + } + + /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ + IF( GT_16( st_ivas->nCPE, 1 ) && EQ_16( nCPE_old, 1 ) ) + { + free( st_ivas->hCPE[0]->hStereoMdct ); + st_ivas->hCPE[0]->hStereoMdct = NULL; + } + + /* create missing core coder elements and set element bitrates for already existing ones */ + IF( st_ivas->nSCE > 0 ) + { + nSCE_existing = s_min( nSCE_old, st_ivas->nSCE ); + + FOR( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + move32(); + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + + ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) ); + } + + FOR( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) + { + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* propagate input audio buffers */ + test(); + IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + + test(); + /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ + IF( sce_id > 0 || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_ind_tot ); + } + } + + IF( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL ) + { + IF( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + IF( st_ivas->nCPE > 0 ) + { + nCPE_existing = s_min( nCPE_old, st_ivas->nCPE ); + + FOR( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + move32(); + + /* allocate buffer of indices */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + + test(); + test(); + test(); + test(); + IF( ( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 ) || + ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->nSCE > 0 ) || + ( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 ) ) + { + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); + } + } + } + + FOR( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + test(); + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hMcMasa->separateChannelEnabled ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); + } + + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* propagate input audio buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) ) + { + mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory ); + } + } + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ + test(); + test(); + IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) + { + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); + } + + IF( hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); + } + } + } + } + + /* restore bitstream - IVAS format bits should be written in the first core channel of the first SCE/CPE */ + i = 0; + move16(); + nb_bits = 0; + move16(); + IF( st_ivas->nSCE > 0 ) + { + test(); + WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) + { + IF( temp_ind_list[i].nb_bits > 0 ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; + move16(); + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; + move16(); + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; + move16(); + } + + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + i = add( i, 1 ); + test(); + } + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; + move16(); + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + move16(); + } + ELSE IF( st_ivas->nCPE > 0 ) + { + WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) + { + IF( temp_ind_list[i].nb_bits > 0 ) + { + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; + move16(); + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value; + move16(); + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits; + move16(); + } + + nb_bits = add( nb_bits, temp_ind_list[i].nb_bits ); + i = add( i, 1 ); + } + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i; + move16(); + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + move16(); + } + + + IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + /* restore modified transport signal */ + IF( st_ivas->nSCE ) + { + mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + + IF( st_ivas->nCPE ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory ); + } + } + } + + test(); + test(); + IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) + { + IF( EQ_16( nCPE_old, 1 ) ) + { + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + move32(); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) /* 1/50 in Q31*/ ); + move16(); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + move16(); + + IF( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + IF( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) + { + IF( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* alllocate buffer for metadata indices */ + IF( st_ivas->nCPE > 0 ) + { + IF( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) + { + IF( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot ); + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) + { + ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) ); + } + } + + /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ + test(); + IF( EQ_16( st_ivas->nCPE, 1 ) && GT_16( nCPE_old, 1 ) ) + { + IF( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + move32(); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + move16(); + + IF( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* reset mct_chan_mode */ + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move16(); + } + + initMdctStereoEncData_fx( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); + + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = extract_l( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + move16(); + } + } + + return error; +} +#endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 668b9f71c094dcc62a2571bb9519a2b2d44d7b62..1f37cc90d96b1f72dbf806e92ab416526a6b41ff 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -212,7 +212,6 @@ ivas_error ivas_cpe_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS hCPE->hStereoClassif->is_speech_fx = floatToFixed_32( hCPE->hStereoClassif->is_speech, Q9 ); - hCPE->hStereoClassif->xtalk_wscore_fx = floatToFixed_32( hCPE->hStereoClassif->xtalk_wscore, Q31 ); hCPE->hCoreCoder[0]->hSpMusClas->past_dlp_fx[0] = float_to_fix16( hCPE->hCoreCoder[0]->hSpMusClas->past_dlp[0], Q9 ); hCPE->hCoreCoder[0]->hSpMusClas->wdlp_xtalk_fx = floatToFixed( hCPE->hCoreCoder[0]->hSpMusClas->wdlp_xtalk, Q19 ); #endif @@ -220,8 +219,6 @@ ivas_error ivas_cpe_enc( hCPE->element_mode = select_stereo_mode( hCPE, ivas_format ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( hCPE->hStereoClassif->unclr_fv_fx, hCPE->hStereoClassif->unclr_fv, Q15, SSC_MAX_NFEA ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_fv_fx, hCPE->hStereoClassif->xtalk_fv, Q15, SSC_MAX_NFEA ); hCPE->hStereoClassif->is_speech = fixedToFloat_32( hCPE->hStereoClassif->is_speech_fx, Q9 ); #endif #else @@ -234,7 +231,7 @@ ivas_error ivas_cpe_enc( stereo_mode_combined_format_enc( st_ivas, hCPE ); #endif #ifdef IVAS_FLOAT_FIXED - Word16 Q_inp = Q15; + Word16 Q_inp = 0; move16(); Word16 Q_buffer[2]; Word32 band_energies_LR_fx[2 * NB_BANDS]; @@ -266,19 +263,6 @@ ivas_error ivas_cpe_enc( } if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) { - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - - Q_inp = min( Q_inp, Q_factor_arr( sts[n]->input, L_FRAME48k ) ); - // floatToFixed_arr( sts[n]->input, st->input_fx, Q_inp, L_FRAME48k ); - } - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - - // Q_inp = L_min( Q_inp, Q_factor_arr( sts[n]->input, L_FRAME48k ) ); - floatToFixed_arr( sts[n]->input, sts[n]->input_fx, Q_inp, L_FRAME48k ); - } Word16 Qband = -1; move16(); Word16 Q_new_old = add( sub( Q_inp, Qband ), Q_add ); @@ -324,6 +308,7 @@ ivas_error ivas_cpe_enc( { return error; } + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( sts[0]->hFdCngEnc != NULL ) { @@ -557,16 +542,6 @@ ivas_error ivas_cpe_enc( currFlatness_fx[1] = float_to_fix16( currFlatness[1], Q7 ); #endif set_transient_stereo_fx( hCPE, currFlatness_fx ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( hCPE->hStereoDft ) - { - hCPE->hStereoDft->hItd->currFlatness = fix16_to_float( hCPE->hStereoDft->hItd->currFlatness_fx, Q7 ); - } - if ( hCPE->hStereoMdct ) - { - hCPE->hStereoMdct->hItd->currFlatness = fix16_to_float( hCPE->hStereoMdct->hItd->currFlatness_fx, Q7 ); - } -#endif #else set_transient_stereo( hCPE, currFlatness ); #endif @@ -738,29 +713,15 @@ ivas_error ivas_cpe_enc( f2me_buf( hCPE->hStereoDft->Spd_L_smooth, hCPE->hStereoDft->Spd_L_smooth_fx, &hCPE->hStereoDft->Spd_L_smooth_fx_e, STEREO_DFT_N_32k_ENC / 2 ); f2me_buf( hCPE->hStereoDft->Spd_R_smooth, hCPE->hStereoDft->Spd_R_smooth_fx, &hCPE->hStereoDft->Spd_R_smooth_fx_e, STEREO_DFT_N_32k_ENC / 2 ); floatToFixed_arrL( hCPE->hStereoDft->hItd->itd, hCPE->hStereoDft->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_fv, hCPE->hStereoClassif->xtalk_fv_fx, 15, SSC_MAX_NFEA ); floatToFixed_arrL( hCPE->hStereoClassif->unclr_fv, hCPE->hStereoClassif->unclr_fv_fx, 15, SSC_MAX_NFEA ); - f2me( hCPE->hStereoClassif->ave_ener_L, &hCPE->hStereoClassif->ave_ener_L_fx, &hCPE->hStereoClassif->ave_ener_L_fx_e ); - f2me( hCPE->hStereoClassif->ave_ener_R, &hCPE->hStereoClassif->ave_ener_R_fx, &hCPE->hStereoClassif->ave_ener_R_fx_e ); - if ( hCPE->hStereoMdct ) - { - hCPE->hStereoMdct->hItd->currFlatness_fx = float_to_fix16( hCPE->hStereoMdct->hItd->currFlatness, Q7 ); - } - #ifndef MSAN_FIX hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_score_buf, hCPE->hStereoClassif->xtalk_score_buf_fx, 31, XTALK_SCORE_BUF_LEN ); - hCPE->hStereoClassif->xtalk_wscore_fx = floatToFixed( hCPE->hStereoClassif->xtalk_wscore, 31 ); /*flt2fix: dft_compute_prm*/ floatToFixed_arrL( hCPE->hStereoDft->sidSideGain, hCPE->hStereoDft->sidSideGain_fx, Q31, STEREO_DFT_ERB4_BANDS ); hCPE->hStereoDft->sid_gipd_fx = floatToFixed( hCPE->hStereoDft->sid_gipd, Q13 ); - hCPE->hStereoClassif->relE_0_1_fx = floatToFixed( hCPE->hStereoClassif->relE_0_1, 31 ); - floatToFixed_arrL( hCPE->hStereoClassif->unclr_relE_0_1_LT, hCPE->hStereoClassif->unclr_relE_0_1_LT_fx, 31, UNCLR_RC_ORDER ); - hCPE->hStereoClassif->unclr_wscore_fx = floatToFixed( hCPE->hStereoClassif->unclr_wscore, 31 ); - for ( i = 0; i < 2; i++ ) { f2me( hCPE->hStereoDft->nrg_L[i], &hCPE->hStereoDft->nrg_L_fx[i], &hCPE->hStereoDft->nrg_L_fx_e[i] ); @@ -840,31 +801,6 @@ ivas_error ivas_cpe_enc( hCPE->hStereoTD->q_tdm_last_diff_lt_corr = Q31; hCPE->hStereoTD->tdm_last_diff_lt_corr_fx = floatToFixed_32( hCPE->hStereoTD->tdm_last_diff_lt_corr, hCPE->hStereoTD->q_tdm_last_diff_lt_corr ); floatToFixed_arrL( hCPE->hStereoClassif->unclr_fv, hCPE->hStereoClassif->unclr_fv_fx, Q15, 58 ); - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_fv, hCPE->hStereoClassif->xtalk_fv_fx, Q15, SSC_MAX_NFEA ); - floatToFixed_arrL( hCPE->hStereoClassif->unclr_relE_0_1_LT, hCPE->hStereoClassif->unclr_relE_0_1_LT_fx, Q31, UNCLR_RC_ORDER ); - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_score_buf, hCPE->hStereoClassif->xtalk_score_buf_fx, Q31, XTALK_SCORE_BUF_LEN ); - for ( int i = 0; i < XTALK_SCORE_BUF_LEN; i++ ) - { - Word64 temp = (Word64) ( hCPE->hStereoClassif->xtalk_score_buf[i] * ONE_IN_Q31 ); - if ( temp - 1 == MAX_32 ) - { - hCPE->hStereoClassif->xtalk_score_buf_fx[i] = MAX_32; - } - else if ( temp > MAX_32 || temp < MIN_32 ) - { - assert( 0 ); - } - else - { - hCPE->hStereoClassif->xtalk_score_buf_fx[i] = (Word32) temp; - } - } - hCPE->hStereoClassif->ratio_L_fx = floatToFixed_32( hCPE->hStereoClassif->ratio_L, Q31 ); - hCPE->hStereoClassif->relE_0_1_fx = floatToFixed_32( hCPE->hStereoClassif->relE_0_1, Q31 ); - hCPE->hStereoClassif->unclr_wscore_fx = floatToFixed_32( hCPE->hStereoClassif->unclr_wscore, Q31 ); - hCPE->hStereoClassif->xtalk_score_fx = floatToFixed_32( hCPE->hStereoClassif->xtalk_score, Q31 ); - hCPE->hStereoClassif->xtalk_wscore_fx = floatToFixed_32( hCPE->hStereoClassif->xtalk_wscore, Q31 ); - hCPE->hStereoClassif->xtalk_score_wrelE_fx = floatToFixed_32( hCPE->hStereoClassif->xtalk_score_wrelE, Q31 ); IF( hCPE->hStereoTD->tdm_last_SM_flag ) { IF( hCPE->hStereoTD->tdm_SM_reset_flag ) @@ -913,22 +849,11 @@ ivas_error ivas_cpe_enc( hCPE->hStereoTD->tdm_LT_es_em = fixedToFloat_32( hCPE->hStereoTD->tdm_LT_es_em_fx, Q21 ); sts[0]->hNoiseEst->Etot_last = fix16_to_float( sts[0]->hNoiseEst->Etot_last_fx, Q8 ); sts[1]->hNoiseEst->Etot_last = fix16_to_float( sts[1]->hNoiseEst->Etot_last_fx, Q8 ); - hCPE->hStereoClassif->xtalk_fv[E_diff_corrLM_corrRM] = fixedToFloat( hCPE->hStereoClassif->xtalk_fv_fx[E_diff_corrLM_corrRM], Q15 ); - hCPE->hStereoClassif->xtalk_fv[E_tdm_LT_es_em] = fixedToFloat( hCPE->hStereoClassif->xtalk_fv_fx[E_tdm_LT_es_em], Q15 ); hCPE->hStereoTD->tdm_lt_corr_LM = fixedToFloat_32( hCPE->hStereoTD->tdm_lt_corr_LM_fx, Q24 ); hCPE->hStereoTD->tdm_lt_corr_RM = fixedToFloat_32( hCPE->hStereoTD->tdm_lt_corr_RM_fx, Q24 ); hCPE->hStereoTD->tdm_last_diff_lt_corr = fixedToFloat_32( hCPE->hStereoTD->tdm_last_diff_lt_corr_fx, hCPE->hStereoTD->q_tdm_last_diff_lt_corr ); - hCPE->hStereoClassif->ratio_L = fixedToFloat_32( hCPE->hStereoClassif->ratio_L_fx, Q31 ); - hCPE->hStereoClassif->relE_0_1 = fixedToFloat_32( hCPE->hStereoClassif->relE_0_1_fx, Q31 ); - hCPE->hStereoClassif->unclr_wscore = fixedToFloat_32( hCPE->hStereoClassif->unclr_wscore_fx, Q31 ); fixedToFloat_arrL( hCPE->hStereoClassif->unclr_fv_fx, hCPE->hStereoClassif->unclr_fv, Q15, 58 ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_fv_fx, hCPE->hStereoClassif->xtalk_fv, Q15, SSC_MAX_NFEA ); - fixedToFloat_arrL( hCPE->hStereoClassif->unclr_relE_0_1_LT_fx, hCPE->hStereoClassif->unclr_relE_0_1_LT, Q31, UNCLR_RC_ORDER ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_score_buf_fx, hCPE->hStereoClassif->xtalk_score_buf, Q31, XTALK_SCORE_BUF_LEN ); - hCPE->hStereoClassif->xtalk_score = fixedToFloat_32( hCPE->hStereoClassif->xtalk_score_fx, Q31 ); - hCPE->hStereoClassif->xtalk_wscore = fixedToFloat_32( hCPE->hStereoClassif->xtalk_wscore_fx, Q31 ); - hCPE->hStereoClassif->xtalk_score_wrelE = fixedToFloat_32( hCPE->hStereoClassif->xtalk_score_wrelE_fx, Q31 ); if ( hCPE->hStereoTD->tdm_last_SM_flag ) { hCPE->hStereoTD->tdm_lt_rms_L_SM = fixedToFloat_32( hCPE->hStereoTD->tdm_lt_rms_L_SM_fx, Q16 ); @@ -944,7 +869,37 @@ ivas_error ivas_cpe_enc( #endif /* Compute the downmix signal based on the ratio index */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 input_fx[2][L_FRAME48k]; + floatToFixed_arr16( sts[1]->input, input_fx[0], 0, input_frame ); + floatToFixed_arr16( sts[0]->input, input_fx[1], 0, input_frame ); + hCPE->hStereoTD->tdm_last_ratio_fx = floatToFixed( hCPE->hStereoTD->tdm_last_ratio, Q31 ); + hCPE->hStereoTD->tdm_last_ratio_SM_fx = floatToFixed( hCPE->hStereoTD->tdm_last_ratio_SM, Q31 ); +#endif + Word16 tmp; + IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) + { + tmp = tdm_SM_or_LRTD_Pri; + move16(); + } + ELSE + { + tmp = 0; + move16(); + } + stereo_tdm_downmix_ivas_fx( hCPE->hStereoTD, input_fx[0], input_fx[1], input_frame, tdm_ratio_idx, tmp, tdm_ratio_idx_SM ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hCPE->hStereoTD->tdm_last_ratio = fixedToFloat( hCPE->hStereoTD->tdm_last_ratio_fx, Q31 ); + hCPE->hStereoTD->tdm_last_ratio_SM = fixedToFloat( hCPE->hStereoTD->tdm_last_ratio_SM_fx, Q31 ); + + fixedToFloat_arr( input_fx[0], sts[0]->input, 0, input_frame ); + fixedToFloat_arr( input_fx[1], sts[1]->input, 0, input_frame ); +#endif +#else stereo_tdm_downmix( hCPE->hStereoTD, sts[0]->input, sts[1]->input, input_frame, tdm_ratio_idx, ( ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) ? tdm_SM_or_LRTD_Pri : 0 ), tdm_ratio_idx_SM ); +#endif /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; @@ -973,17 +928,8 @@ ivas_error ivas_cpe_enc( } floatToFixed_arrL( hCPE->hStereoMdct->hItd->itd, hCPE->hStereoMdct->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); floatToFixed_arrL( hCPE->hStereoMdct->hItd->deltaItd, hCPE->hStereoMdct->hItd->deltaItd_fx, 16, STEREO_DFT_ENC_DFT_NB ); - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_fv, hCPE->hStereoClassif->xtalk_fv_fx, 15, SSC_MAX_NFEA ); floatToFixed_arrL( hCPE->hStereoClassif->unclr_fv, hCPE->hStereoClassif->unclr_fv_fx, 15, SSC_MAX_NFEA ); floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); - f2me( hCPE->hStereoClassif->ave_ener_L, &hCPE->hStereoClassif->ave_ener_L_fx, &hCPE->hStereoClassif->ave_ener_L_fx_e ); - f2me( hCPE->hStereoClassif->ave_ener_R, &hCPE->hStereoClassif->ave_ener_R_fx, &hCPE->hStereoClassif->ave_ener_R_fx_e ); - hCPE->hStereoMdct->hItd->currFlatness_fx = float_to_fix16( hCPE->hStereoMdct->hItd->currFlatness, Q7 ); - floatToFixed_arrL( hCPE->hStereoClassif->xtalk_score_buf, hCPE->hStereoClassif->xtalk_score_buf_fx, 31, XTALK_SCORE_BUF_LEN ); - hCPE->hStereoClassif->xtalk_wscore_fx = floatToFixed( hCPE->hStereoClassif->xtalk_wscore, 31 ); - hCPE->hStereoClassif->relE_0_1_fx = floatToFixed( hCPE->hStereoClassif->relE_0_1, 31 ); - floatToFixed_arrL( hCPE->hStereoClassif->unclr_relE_0_1_LT, hCPE->hStereoClassif->unclr_relE_0_1_LT_fx, 31, UNCLR_RC_ORDER ); - hCPE->hStereoClassif->unclr_wscore_fx = floatToFixed( hCPE->hStereoClassif->unclr_wscore, 31 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { floatToFixed_arr( sts[1]->old_inp_12k8, sts[1]->old_inp_12k8_fx, 0, L_INP_MEM ); @@ -995,20 +941,11 @@ ivas_error ivas_cpe_enc( if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { fixedToFloat_arrL( hCPE->hStereoMdct->hItd->itd_fx, hCPE->hStereoMdct->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_fv_fx, hCPE->hStereoClassif->xtalk_fv, 15, SSC_MAX_NFEA ); fixedToFloat_arrL( hCPE->hStereoClassif->unclr_fv_fx, hCPE->hStereoClassif->unclr_fv, 15, SSC_MAX_NFEA ); - hCPE->hStereoClassif->ave_ener_L = me2f( hCPE->hStereoClassif->ave_ener_L_fx, hCPE->hStereoClassif->ave_ener_L_fx_e ); - hCPE->hStereoClassif->ave_ener_R = me2f( hCPE->hStereoClassif->ave_ener_R_fx, hCPE->hStereoClassif->ave_ener_R_fx_e ); - hCPE->hStereoClassif->xtalk_score = fixedToFloat( hCPE->hStereoClassif->xtalk_score_fx, 31 ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_score_buf_fx, hCPE->hStereoClassif->xtalk_score_buf, 31, XTALK_SCORE_BUF_LEN ); - hCPE->hStereoClassif->xtalk_wscore = fixedToFloat( hCPE->hStereoClassif->xtalk_wscore_fx, 31 ); - // hCPE->hStereoClassif->prev_g_IPD = fixedToFloat( hCPE->hStereoClassif->prev_g_IPD_fx, 29 ); - // hCPE->hStereoClassif->prev_IPD = fixedToFloat( hCPE->hStereoClassif->prev_IPD_fx, 29 ); FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) { - // hCPE->q_input_mem[i] = Q_factor_arr( &hCPE->input_mem[i][0], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); - // floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); + fixedToFloat_arr( sts[i]->old_input_signal_fx, sts[i]->old_input_signal, sts[i]->q_inp, 1965 ); } } #endif @@ -1101,21 +1038,12 @@ ivas_error ivas_cpe_enc( me2f_buf( hCPE->hStereoDft->Spd_L_smooth_fx, hCPE->hStereoDft->Spd_L_smooth_fx_e, hCPE->hStereoDft->Spd_L_smooth, STEREO_DFT_N_32k_ENC / 2 ); me2f_buf( hCPE->hStereoDft->Spd_R_smooth_fx, hCPE->hStereoDft->Spd_R_smooth_fx_e, hCPE->hStereoDft->Spd_R_smooth, STEREO_DFT_N_32k_ENC / 2 ); fixedToFloat_arrL( hCPE->hStereoDft->hItd->itd_fx, hCPE->hStereoDft->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_fv_fx, hCPE->hStereoClassif->xtalk_fv, 15, SSC_MAX_NFEA ); fixedToFloat_arrL( hCPE->hStereoClassif->unclr_fv_fx, hCPE->hStereoClassif->unclr_fv, 15, SSC_MAX_NFEA ); - hCPE->hStereoClassif->ave_ener_L = me2f( hCPE->hStereoClassif->ave_ener_L_fx, hCPE->hStereoClassif->ave_ener_L_fx_e ); - hCPE->hStereoClassif->ave_ener_R = me2f( hCPE->hStereoClassif->ave_ener_R_fx, hCPE->hStereoClassif->ave_ener_R_fx_e ); - hCPE->hStereoClassif->xtalk_score = fixedToFloat( hCPE->hStereoClassif->xtalk_score_fx, 31 ); - fixedToFloat_arrL( hCPE->hStereoClassif->xtalk_score_buf_fx, hCPE->hStereoClassif->xtalk_score_buf, 31, XTALK_SCORE_BUF_LEN ); - hCPE->hStereoClassif->xtalk_wscore = fixedToFloat( hCPE->hStereoClassif->xtalk_wscore_fx, 31 ); fixedToFloat_arrL( hCPE->hStereoDft->sidSideGain_fx, hCPE->hStereoDft->sidSideGain, Q31, STEREO_DFT_ERB4_BANDS ); hCPE->hStereoDft->sid_gipd = fixedToFloat( hCPE->hStereoDft->sid_gipd_fx, Q13 ); /*local fix2flt*/ - fixedToFloat_arrL( hCPE->hStereoClassif->unclr_relE_0_1_LT_fx, hCPE->hStereoClassif->unclr_relE_0_1_LT, 31, UNCLR_RC_ORDER ); - hCPE->hStereoClassif->unclr_wscore = fixedToFloat( hCPE->hStereoClassif->unclr_wscore_fx, 31 ); - for ( i = 0; i < 2; i++ ) { hCPE->hStereoDft->nrg_L[i] = me2f( hCPE->hStereoDft->nrg_L_fx[i], hCPE->hStereoDft->nrg_L_fx_e[i] ); @@ -1379,10 +1307,6 @@ ivas_error ivas_cpe_enc( Etot_last_fx[1] = float_to_fix16( Etot_last[1], Q8 ); #endif tdm_configure_enc_fx( ivas_format, st_ivas->ism_mode, hCPE, Etot_last_fx, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - sts[0]->hSpMusClas->tdm_lt_Etot = fix16_to_float( sts[0]->hSpMusClas->tdm_lt_Etot_fx, Q8 ); - sts[1]->hSpMusClas->tdm_lt_Etot = fix16_to_float( sts[1]->hSpMusClas->tdm_lt_Etot_fx, Q8 ); -#endif #else tdm_configure_enc( ivas_format, st_ivas->ism_mode, hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); #endif @@ -2771,7 +2695,6 @@ ivas_error create_cpe_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } - set16_zero_fx( hCPE->input_mem_fx[n], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); } ELSE @@ -2781,6 +2704,26 @@ ivas_error create_cpe_enc_fx( } } + +#if 1 // TODO: To be removed later + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) + { + if ( ( hCPE->input_mem[n] = (float *) malloc( sizeof( float ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); + } + + set_zero( hCPE->input_mem[n], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); + } + else + { + hCPE->input_mem[n] = NULL; + } + } +#endif + /*-----------------------------------------------------------------* * stereo classifier: allocate and initialize *-----------------------------------------------------------------*/ @@ -2791,6 +2734,9 @@ ivas_error create_cpe_enc_fx( } stereo_classifier_init_fx( hCPE->hStereoClassif ); +#if 1 // TODO: To be removed later + stereo_classifier_init( hCPE->hStereoClassif ); +#endif /*-----------------------------------------------------------------* * Metadata: allocate and initialize diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index c3c181e12de42aca1b0175f94e1725861b68b133..1818b6fe59a8b1a1f929e913fc75ddea30efed6b 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -652,7 +652,17 @@ ivas_error front_vad_create_fx( set16_fx( hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples ); } +#if 1 hFrontVad->delay_buf = NULL; // Inorder to avoid issue in front_vad_distroy_fx call , Will have to be removed later + if ( hFrontVad->delay_samples > 0 ) + { + if ( ( hFrontVad->delay_buf = (float *) malloc( hFrontVad->delay_samples * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n" ) ); + } + set_f( hFrontVad->delay_buf, 0, hFrontVad->delay_samples ); + } +#endif *hFrontVad_out = hFrontVad; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index df29c2e7c6783670437d0fcb095c45f6bc987fdf..3c8a506ea7466c02e032cd395d3ebeadc6d8e874 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -501,26 +501,39 @@ void copy_encoder_config_fx( IF( flag_all ) { st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; + move32(); st_fx->last_codec_mode = st_ivas->last_codec_mode; + move16(); st_fx->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; + move32(); st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + move16(); st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + move16(); } st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; + move16(); st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + move16(); st_fx->codec_mode = st_ivas->codec_mode; + move16(); st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + move16(); st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; + move16(); st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; + move16(); st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + move16(); st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; + move16(); return; } @@ -2354,6 +2367,7 @@ void ivas_destroy_MD_bstr_enc( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ) { + test(); IF( hMetaData == NULL || *hMetaData == NULL ) { return; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index fbd42a4fa1b31b95944381ae29e715fad8e5bf7e..423bd5f98cbae4b2b9898cdbae6a77d7a487a177 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -1004,6 +1004,7 @@ return error; * - reconfigure the ISM format encoder *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_ism_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -1069,3 +1070,82 @@ ivas_error ivas_ism_enc_config( return error; } +#else +ivas_error ivas_ism_enc_config( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + ivas_error error; + ISM_MODE last_ism_mode; + Word16 nchan_transport_old; + Word16 nSCE_old, nCPE_old; + + error = IVAS_ERR_OK; + move32(); + last_ism_mode = st_ivas->ism_mode; + move16(); + + /* select ISM format mode */ + st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); + move16(); + + /* ISM bit-rate switching */ + test(); + IF( NE_16( st_ivas->ism_mode, last_ism_mode ) || NE_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + Word32 element_brate_tmp[MAX_NUM_OBJECTS]; + + nchan_transport_old = st_ivas->nchan_transport; + move16(); + + /* Reset and Initialize */ + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } + ELSE + { + st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp; + } + move16(); + + nCPE_old = st_ivas->nCPE; + move16(); + nSCE_old = st_ivas->nSCE; + move16(); + st_ivas->nSCE = st_ivas->nchan_transport; + move16(); + st_ivas->nCPE = 0; + move16(); + + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, imult3216( ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ), CPE_CHANNELS ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_16( last_ism_mode, ISM_MODE_DISC ) ) + { + /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */ + IF( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_16( last_ism_mode, ISM_MODE_PARAM ) ) + { + /* Deallocate the memory used by ParamISM when switch to Discrete ISM */ + ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); + } + } + + return error; +} +#endif diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index eed03579efa702d021df487882f8fba2c50d8ea4..94794884299e4949d6f9d2fff0ab8feeef8a12db 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -390,6 +390,7 @@ void ivas_param_ism_stereo_dmx( * Open Param ISM handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_param_ism_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -446,6 +447,68 @@ ivas_error ivas_param_ism_enc_open( return error; } +#else +ivas_error ivas_param_ism_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 i; + IVAS_FB_CFG *fb_cfg; + PARAM_ISM_CONFIG_HANDLE hParamIsm; + Word16 max_bins; + Word32 input_Fs; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + /* Assign memory to Param Object handle */ + if ( ( hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM\n" ) ); + } + + input_Fs = st_ivas->hEncoderConfig->input_Fs; + move32(); + + + /* set FB config. */ + IF( ( error = ivas_fb_set_cfg( &fb_cfg, ISM_FORMAT, st_ivas->hEncoderConfig->nchan_inp, 0, 0, input_Fs, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Allocate and initialize FB mixer handle */ + IF( ( error = ivas_FB_mixer_open_fx( &( hParamIsm->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_param_ism_config_fx( hParamIsm, st_ivas->hEncoderConfig->nchan_inp ); + + /* Assign memories for Band and Block grouping */ + hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; + move16(); + + max_bins = extract_l( Mpy_32_32( input_Fs, 10737418 ) ); // (int16_t) ( ( MDFT_FB_BANDS_240 * input_Fs ) / 48000 ); + FOR( i = 0; i < ( hParamIsm->nbands + 1 ); i++ ) + { + hParamIsm->band_grouping[i] = CLDFB_TO_MDFT_FAC * Param_ISM_band_grouping[i]; + move16(); + IF( GT_16( i_mult( Param_ISM_band_grouping[i], CLDFB_TO_MDFT_FAC ), max_bins ) ) + { + hParamIsm->band_grouping[i] = max_bins; + move16(); + } + } + + set16_fx( hParamIsm->noisy_speech_buffer, 0, PARAM_ISM_HYS_BUF_SIZE ); + + st_ivas->hParamIsm = hParamIsm; + + return error; +} +#endif /*-------------------------------------------------------------------------* @@ -454,6 +517,7 @@ ivas_error ivas_param_ism_enc_open( * Close Param ISM encoder handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_enc_close( PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ const int32_t input_Fs /* i : input sampling_rate */ @@ -471,6 +535,26 @@ void ivas_param_ism_enc_close( return; } +#else +void ivas_param_ism_enc_close( + PARAM_ISM_CONFIG_HANDLE *hParamIsm, /* i/o: ParamISM handle */ + const Word32 input_Fs /* i : input sampling_rate */ +) +{ + test(); + IF( hParamIsm == NULL || *hParamIsm == NULL ) + { + return; + } + + ivas_FB_mixer_close_fx( &( *hParamIsm )->hFbMixer, input_Fs, 0 ); + + free( ( *hParamIsm ) ); + ( *hParamIsm ) = NULL; + + return; +} +#endif /*-------------------------------------------------------------------------* diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 15bb49b783c4cdb031e90ff7cd7e64560532ea70..feef25497a36ecd48b17a9d87526365c6131c6f3 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -58,6 +58,7 @@ static ivas_error ivas_mc_enc_reconfig( Encoder_Struct *st_ivas, const int16_t l * Set hMCT handle parameters *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void set_mct_enc_params( MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -98,6 +99,53 @@ static void set_mct_enc_params( return; } +#else +static void set_mct_enc_params( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS_format */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ +) +{ + Word16 n; + + IF( b_nchan_change ) + { + hMCT->currBlockDataCnt = 0; + move16(); + + /*Initialize bits required to signal channel-pair index*/ + hMCT->bitsChannelPairIndex = s_max( 1, add( sub( 14, norm_s( sub( shr( i_mult( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 ) ) ), 1 ) ); + + set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + +#if 1 // TODO: To be removed later + for ( n = 0; n < MCT_MAX_CHANNELS; n++ ) + { + set_f( hMCT->lastxCorrMatrix[n], 0, MCT_MAX_CHANNELS ); + } +#endif + FOR( n = 0; n < MCT_MAX_CHANNELS; n++ ) + { + set32_fx( hMCT->lastxCorrMatrix_fx[n], 0, MCT_MAX_CHANNELS ); + } + hMCT->lastxCorrMatrix_e = 0; + move16(); + } + + hMCT->hbr_mct = 0; + move16(); + + test(); + IF( EQ_16( ivas_format, SBA_FORMAT ) && GE_32( ivas_total_brate, IVAS_256k ) ) + { + hMCT->hbr_mct = 1; + move16(); + } + + return; +} +#endif /*-------------------------------------------------------------------* * map_input_to_cpe_channels() @@ -628,6 +676,7 @@ ivas_error ivas_mct_enc( * Create, allocate and initialize IVAS encoder MCT handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error create_mct_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -746,6 +795,142 @@ ivas_error create_mct_enc( return IVAS_ERR_OK; } +#else +ivas_error create_mct_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + MCT_ENC_HANDLE hMCT; + Word16 n; + Word32 cp_bitrate; + Word16 max_blocks; + Word16 cpe_id; + IVAS_FORMAT ivas_format; + Word32 ivas_total_brate; + + ivas_format = st_ivas->hEncoderConfig->ivas_format; + move16(); + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + + /*-----------------------------------------------------------------* + * Allocate MCT handle + *-----------------------------------------------------------------*/ + + IF( ( hMCT = (MCT_ENC_HANDLE) malloc( sizeof( MCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT\n" ) ); + } + + /*-----------------------------------------------------------------* + * Allocate and initialize MCT BlockData handles + *-----------------------------------------------------------------*/ + + /* Determine active channels */ + test(); + test(); + test(); + test(); + IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + hMCT->nchan_out_woLFE = sub( st_ivas->hEncoderConfig->nchan_inp, 1 ); /* LFE channel is coded separately */ + move16(); + } + ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + { + hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); + move16(); + + test(); + IF( EQ_16( ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->hEncoderConfig->nchan_ism ); + move16(); + } + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup ); + move16(); + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + hMCT->nchan_out_woLFE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS - 1; + move16(); + } + + Word32 L_tmp; + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); + // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); + // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + } + + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + IF( hMCT->nchan_out_woLFE % 2 ) + { + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move16(); + } + + /*Initialize MCT block data */ + max_blocks = shr( hMCT->nchan_out_woLFE, 1 ); // hMCT->nchan_out_woLFE / CPE_CHANNELS + + FOR( n = 0; n < max_blocks; n++ ) + { + assert( st_ivas->hEncoderConfig->element_mode_init == IVAS_CPE_MDCT && "MCT is not supported for other stereo modes" ); + + IF( ( hMCT->hBlockData[n] = (MCT_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + } + + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->isActive = 0; + move16(); + hMCT->hBlockData[n]->ch1 = 0; + move16(); + hMCT->hBlockData[n]->ch2 = 0; + move16(); + + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 1 ); + } + + FOR( ; n < MCT_MAX_BLOCKS; n++ ) + { + hMCT->hBlockData[n] = NULL; + } + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + set_mct_enc_params( hMCT, ivas_total_brate, ivas_format, 1 ); + + st_ivas->hMCT = hMCT; + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- @@ -754,6 +939,7 @@ ivas_error create_mct_enc( * Reconfigure IVAS encoder MCT handle *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error mct_enc_reconfigure( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ @@ -942,6 +1128,186 @@ ivas_error mct_enc_reconfigure( return error; } +#else +ivas_error mct_enc_reconfigure( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ +) +{ + MCT_ENC_HANDLE hMCT; + Encoder_State *st; + Word16 n, cpe_id, max_blocks; + Word32 ivas_total_brate, cp_bitrate; + IVAS_FORMAT ivas_format; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + hMCT = st_ivas->hMCT; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + move16(); + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + + /*-----------------------------------------------------------------* + * Allocate and initialize MCT BlockData handles + *-----------------------------------------------------------------*/ + + IF( b_nchan_change ) + { + test(); + test(); + test(); + test(); + /* Determine active channels */ + IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + hMCT->nchan_out_woLFE = sub( st_ivas->hEncoderConfig->nchan_inp, 1 ); /* LFE channel is coded separately */ + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + hMCT->nchan_out_woLFE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS - 1; + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup ); + } + ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + move16(); + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->hEncoderConfig->nchan_ism ); + move16(); + } + } + } + + Word32 L_tmp; + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); + // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); + // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; + move32(); + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move16(); + } + } + + /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ + IF( hMCT->nchan_out_woLFE % 2 ) + { + st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move16(); + } + + /* set correct nominal bitrates and igf config already here, otherwise we + * run into a number of problems; only do it when the bitrate changes */ + IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; + + st->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + move32(); + + IF( NE_16( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[cpe_id]->element_brate, 42949673 ) /* 1/50 in Q31*/ ); + move16(); + st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_mode ); + move16(); + + IF( ( error = IGF_Reconfig( &st->hIGFEnc, st->igf, 1, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, st->rf_mode ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + } + + /* Initialize MCT block data */ + max_blocks = shr( hMCT->nchan_out_woLFE, 1 ); // hMCT->nchan_out_woLFE / CPE_CHANNELS + + FOR( n = 0; n < max_blocks; n++ ) + { + UWord16 mem_init = 0; + move16(); + assert( st_ivas->hEncoderConfig->element_mode_init == IVAS_CPE_MDCT && "MCT is not supported for other stereo modes" ); + + IF( b_nchan_change ) + { + IF( hMCT->hBlockData[n] == NULL ) + { + mem_init = 1; + move16(); + IF( ( hMCT->hBlockData[n] = (MCT_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); + } + + /*Initialize all parameters to zero*/ + hMCT->hBlockData[n]->isActive = 0; + move16(); + hMCT->hBlockData[n]->ch1 = 0; + move16(); + hMCT->hBlockData[n]->ch2 = 0; + move16(); + + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + } + } + + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, mem_init ); + } + + FOR( ; n < MCT_MAX_BLOCKS; n++ ) + { + /* deallocate no longer needed blocks */ + IF( hMCT->hBlockData[n] != NULL ) + { + IF( hMCT->hBlockData[n]->hStereoMdct != NULL ) + { + free( hMCT->hBlockData[n]->hStereoMdct ); + hMCT->hBlockData[n]->hStereoMdct = NULL; + } + + free( hMCT->hBlockData[n] ); + hMCT->hBlockData[n] = NULL; + } + } + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + set_mct_enc_params( hMCT, ivas_total_brate, ivas_format, b_nchan_change ); + + return error; +} +#endif /*------------------------------------------------------------------------- @@ -950,6 +1316,7 @@ ivas_error mct_enc_reconfigure( * Close MCT *-------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_mct_enc_close( MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ) @@ -983,6 +1350,42 @@ void ivas_mct_enc_close( return; } +#else +void ivas_mct_enc_close( + MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ +) +{ + Word16 n, maxBlocks; + + test(); + IF( hMCT == NULL || *hMCT == NULL ) + { + return; + } + + maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 ); + + FOR( n = 0; n < maxBlocks; n++ ) + { + IF( ( *hMCT )->hBlockData[n] != NULL ) + { + IF( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) + { + free( ( *hMCT )->hBlockData[n]->hStereoMdct ); + ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; + } + + free( ( *hMCT )->hBlockData[n] ); + ( *hMCT )->hBlockData[n] = NULL; + } + } + + free( ( *hMCT ) ); + ( *hMCT ) = NULL; + + return; +} +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 4aea681d7de27d21f42f8ab73c09c59aaaec8c5e..e148508b89374e0dd646a0c2abfc0732023c21be 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1652,6 +1652,12 @@ void ivas_mdct_core_whitening_enc( Word32 mdst_spectrum_long_fx[CPE_CHANNELS][2 * L_FRAME48k]; Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV]; #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_new; + Word16 new_samples_fx[CPE_CHANNELS][L_INP]; + Word32 *windowedSignal_fx[CPE_CHANNELS]; + Word32 L_tmpbuf[NB_DIV * L_FRAME48k + 4], L_tmpbuf1[NB_DIV * L_FRAME48k + 4]; +#endif push_wmops( "mdct_core_whitening" ); @@ -1702,6 +1708,10 @@ void ivas_mdct_core_whitening_enc( windowedSignal[0] = orig_spectrum_long[0]; /* NOTE temporarily available */ windowedSignal[1] = temp_buffer; /* orig_spectrum_long isn't long enough */ +#ifdef IVAS_FLOAT_FIXED + windowedSignal_fx[0] = L_tmpbuf; + windowedSignal_fx[1] = L_tmpbuf1; +#endif /*--------------------------------------------------------------* * TCX20/TCX10 switching decision @@ -1783,7 +1793,363 @@ void ivas_mdct_core_whitening_enc( #else tcx_ltp_encode( st, st->hTcxEnc->tcxMode, L_FRAME, old_wsp[ch] + L_WSP_MEM + L_LOOK_12k8, NULL, old_wsp[ch] + L_WSP_MEM + L_LOOK_12k8, T_op[ch], ¶m_core[ch][1 + NOISE_FILL_RANGES], <pBits[ch], NULL, 0, IVAS_CPE_MDCT ); #endif + +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( new_samples[ch], new_samples_fx[ch], 0, L_INP ); + Word16 leftOverlap = 0, rightOverlap = 0; + PWord16 const *left_win; + PWord16 const *right_win; + Word16 len_windowSignal; + Word16 overlap_mode[3]; + Word16 transform_type[2]; + overlap_mode[0] = st->hTcxCfg->tcx_last_overlap_mode; /* Overlap between the last and the current frame */ + IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) + { + nSubframes = 1; + transform_type[0] = TCX_20; + transform_type[1] = TCX_20; + overlap_mode[1] = st->hTcxCfg->tcx_curr_overlap_mode; /* Overlap between the current and the next frame */ + } + ELSE + { + nSubframes = 2; + IF( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) + { + transform_type[0] = TCX_5; + transform_type[1] = TCX_10; + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + if ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + } + } + ELSE IF( st->hTcxCfg->tcx_last_overlap_mode == FULL_OVERLAP ) + { + transform_type[0] = TCX_10; + transform_type[1] = TCX_5; + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ + if ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + } + } + ELSE + { + transform_type[0] = transform_type[1] = TCX_5; + overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ + if ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) && EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, HALF_OVERLAP ) ) + { + overlap_mode[1] = HALF_OVERLAP; + move16(); + } + } + overlap_mode[2] = st->hTcxCfg->tcx_curr_overlap_mode; /* Overlap between the current and the next frame */ + move16(); + } + + Word16 offset; + IF( ( EQ_16( transform_type[0], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + Word16 nl = (int16_t) ( (float) hTcxEnc->L_frameTCX * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); + floatToFixed_arr( &hTcxEnc->new_speech_TCX_flt[nl - hTcxEnc->L_frameTCX], + &hTcxEnc->new_speech_TCX[nl - hTcxEnc->L_frameTCX], + 0, + 2 * hTcxEnc->L_frameTCX ); + windowedSignal_fx[ch][0] = (Word16) windowedSignal[ch][0]; + windowedSignal_fx[ch][1] = (Word16) windowedSignal[ch][1]; + } + ELSE + { + tcx_get_windows( st->hTcxCfg, overlap_mode[0], overlap_mode[1], &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + len_windowSignal = ( st->hTcxEnc->L_frameTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; + offset = st->hTcxCfg->tcx_offsetFB; + IF( EQ_16( overlap_mode[0], TRANSITION_OVERLAP ) ) + { + len_windowSignal += st->hTcxCfg->tcx5SizeFB; + /* Increase frame size for 5ms */ + offset = negate( shr( st->hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); + } + floatToFixed_arr( &hTcxEnc->speech_TCX_flt[-( leftOverlap / 2 ) + offset], + &hTcxEnc->speech_TCX[-( leftOverlap / 2 ) + offset], + 0, + len_windowSignal ); + windowedSignal_fx[ch][0] = (Word16) windowedSignal[ch][0]; + windowedSignal_fx[ch][1] = (Word16) windowedSignal[ch][1]; + floatToFixed_arrL32( windowedSignal[ch] + 2, windowedSignal_fx[ch] + 2, 0, len_windowSignal ); + } + IF( NE_16( hTcxEnc->tcxMode, TCX_20 ) ) + { + IF( ( EQ_16( transform_type[1], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + Word16 nl = (int16_t) ( (float) hTcxEnc->L_frameTCX * N_ZERO_MDCT_NS / FRAME_SIZE_NS ); + floatToFixed_arr( &hTcxEnc->new_speech_TCX_flt[nl - hTcxEnc->L_frameTCX], + &hTcxEnc->new_speech_TCX[nl - hTcxEnc->L_frameTCX], + 0, + 2 * hTcxEnc->L_frameTCX ); + windowedSignal_fx[ch][L_FRAME48k + 0] = (Word16) windowedSignal[ch][L_FRAME_MAX + 0]; + windowedSignal_fx[ch][L_FRAME48k + 1] = (Word16) windowedSignal[ch][L_FRAME_MAX + 1]; + } + ELSE + { + tcx_get_windows( st->hTcxCfg, overlap_mode[1], overlap_mode[2], &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + len_windowSignal = ( st->hTcxEnc->L_frameTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; + offset = st->hTcxCfg->tcx_offsetFB; + IF( EQ_16( overlap_mode[1], TRANSITION_OVERLAP ) ) + { + len_windowSignal += st->hTcxCfg->tcx5SizeFB; + /* Increase frame size for 5ms */ + offset = negate( shr( st->hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) ); + } + floatToFixed_arr( &hTcxEnc->speech_TCX_flt[( 2 * st->hTcxCfg->tcx5SizeFB ) - ( leftOverlap / 2 ) + offset], + &hTcxEnc->speech_TCX[( 2 * st->hTcxCfg->tcx5SizeFB ) - ( leftOverlap / 2 ) + offset], + 0, + len_windowSignal ); + windowedSignal_fx[ch][L_FRAME48k + 0] = (Word16) windowedSignal[ch][L_FRAME_MAX + 0]; + windowedSignal_fx[ch][L_FRAME48k + 1] = (Word16) windowedSignal[ch][L_FRAME_MAX + 1]; + floatToFixed_arrL32( windowedSignal[ch] + L_FRAME48k + 2, windowedSignal_fx[ch] + L_FRAME48k + 2, 0, len_windowSignal ); + } + } + + if ( st->element_mode == IVAS_CPE_DFT ) + { + floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); + hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); + hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); + q_fac = Q_factor_arr( st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + floatToFixed_arr( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + st->exp_buf_wspeech_enc = 15 - q_fac; + } + else if ( st->element_mode != IVAS_CPE_MDCT ) + { + floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, Q7, NSUBBLOCKS + MAX_TD_DELAY ); + hTcxEnc->tcxltp_gain_past = float_to_fix16( hTcxEnc->tcxltp_gain_past_flt, Q15 ); + hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( hTcxEnc->tcxltp_norm_corr_past_flt, Q15 ); + q_fac = Q_factor_arr( st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + floatToFixed_arr( st->buf_speech_enc_flt, st->buf_speech_enc, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + st->exp_buf_speech_enc = 15 - q_fac; + floatToFixed_arr( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + st->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac; + } + + floatToFixed_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, 7, 24 ); + floatToFixed_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, 7, 24 ); + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) + { + if ( st->hIGFEnc ) + { + st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); + } + + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; + if ( st->hTdCngEnc != NULL ) + { + st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); + } + + float max_sb = 0; + float max_tb = 0; + Word16 max_sb_fx = 0; + Word16 max_tb_fx = 0; + + float max_fir_tb = 0; + float max_iir_tb = 0; + float max_fir_sb = 0; + float max_iir_sb = 0; + + Word16 max_fir_tb_fx = 0; + Word16 max_iir_tb_fx = 0; + Word16 max_fir_sb_fx = 0; + Word16 max_iir_sb_fx = 0; + FOR( Word16 sfb = 0; sfb < 23; sfb++ ) + { + f2me_16( hPrivateData->prevDampingFactor_IIR[sfb], &hPrivateData->prevDampingFactor_IIR_fx[sfb], &hPrivateData->prevDampingFactor_IIR_e[sfb] ); + + max_fir_tb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_TB[sfb] ), max_fir_tb ); + f2me_16( max_fir_tb, &max_fir_tb_fx, &hPrivateData->prevSFB_FIR_TB_e[sfb] ); + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_FIR_TB_e[sfb] ) ); + + max_iir_tb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_TB[sfb] ), max_iir_tb ); + f2me_16( max_iir_tb, &max_iir_tb_fx, &hPrivateData->prevSFB_IIR_TB_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_TB[sfb], sub( 15, hPrivateData->prevSFB_IIR_TB_e[sfb] ) ); + + max_fir_sb = fmaxf( fabsf( hPrivateData->prevSFM_FIR_SFB_SB[sfb] ), max_fir_sb ); + f2me_16( max_fir_sb, &max_fir_sb_fx, &hPrivateData->prevSFB_FIR_SB_e[sfb] ); + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_FIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_FIR_SB_e[sfb] ) ); + + max_iir_sb = fmaxf( fabsf( hPrivateData->prevSFM_IIR_SFB_SB[sfb] ), max_iir_sb ); + f2me_16( max_iir_sb, &max_iir_sb_fx, &hPrivateData->prevSFB_IIR_SB_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = float_to_fix16( hPrivateData->prevSFM_IIR_SFB_SB[sfb], sub( 15, hPrivateData->prevSFB_IIR_SB_e[sfb] ) ); + + max_tb = fmaxf( fabsf( hPrivateData->SFM_tb[sfb] ), max_tb ); + f2me_16( max_tb, &max_tb_fx, &hPrivateData->sfb_tb_e[sfb] ); + hPrivateData->SFM_tb_fx[sfb] = float_to_fix16( hPrivateData->SFM_tb[sfb], sub( 15, hPrivateData->sfb_tb_e[sfb] ) ); + + max_sb = fmaxf( fabsf( hPrivateData->SFM_sb[sfb] ), max_sb ); + f2me_16( max_sb, &max_sb_fx, &hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->SFM_sb_fx[sfb] = float_to_fix16( hPrivateData->SFM_sb[sfb], sub( 15, hPrivateData->sfb_sb_e[sfb] ) ); + } + + for ( i = 0; i < IGF_MAX_TILES; i++ ) + { + hPrivateData->prevSFM_FIR[i] = float_to_fix( hPrivateData->prevSFM_FIR_flt[i], 16 ); /*15Q16*/ + hPrivateData->prevSFM_IIR[i] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[i], 13 ); /*2Q13*/ + for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) + { + hPrivateData->igfPastSFM_fx[i][j] = float_to_fix16( hPrivateData->igfPastSFM[i][j], 13 ); + } + } + } + if ( st->hIGFEnc ) + { + Word16 q_spectrum; + q_spectrum = L_get_q_buf1( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); + floatToFixed_arrL32( st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->spec_be_igf, q_spectrum, st->hIGFEnc->infoStopLine - IGF_START_MN ); + st->hIGFEnc->spec_be_igf_e = 31 - q_spectrum; + } + Word16 q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[0], st->hTcxEnc->L_frameTCX / nSubframes ); + hTcxEnc->spectrum_e[0] = 31 - q_spectrum; + floatToFixed_arrL32( hTcxEnc->spectrum[0], hTcxEnc->spectrum_fx[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + q_spectrum = L_get_q_buf1( hTcxEnc->spectrum[1], st->hTcxEnc->L_frameTCX / nSubframes ); + hTcxEnc->spectrum_e[1] = 31 - q_spectrum; + floatToFixed_arrL32( hTcxEnc->spectrum[1], hTcxEnc->spectrum_fx[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + } + + Q_new = 0; +#endif + core_signal_analysis_high_bitrate_ivas_fx( new_samples_fx[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal_fx[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0, mdst_spectrum_fx[ch], mdst_spectrum_e[ch], &Q_new ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf ) + { + if ( st->hIGFEnc ) + { + st->hIGFEnc->tns_predictionGain_flt = fix16_to_float( st->hIGFEnc->tns_predictionGain, Q23 ); + me2f_buf( st->hIGFEnc->spec_be_igf, st->hIGFEnc->spec_be_igf_e, st->hIGFEnc->spec_be_igf_flt, st->hIGFEnc->infoStopLine - IGF_START_MN ); + } + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData = &st->hIGFEnc->igfData; + for ( Word16 sfb = 0; sfb < 23; sfb++ ) + { + hPrivateData->prevSFM_FIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_FIR_TB_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_TB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], hPrivateData->prevSFB_IIR_TB_e[sfb] ); + hPrivateData->prevSFM_FIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_FIR_SB_e[sfb] ); + hPrivateData->prevSFM_IIR_SFB_SB[sfb] = me2f_16( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], hPrivateData->prevSFB_IIR_SB_e[sfb] ); + hPrivateData->SFM_tb[sfb] = me2f_16( hPrivateData->SFM_tb_fx[sfb], hPrivateData->sfb_tb_e[sfb] ); + hPrivateData->SFM_sb[sfb] = me2f_16( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb] ); + hPrivateData->prevDampingFactor_IIR[sfb] = me2f_16( hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb] ); + } + + for ( i = 0; i < IGF_MAX_TILES; i++ ) + { + hPrivateData->prevSFM_FIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_FIR[i], 16 ); /*15Q16*/ + hPrivateData->prevSFM_IIR_flt[i] = fixedToFloat( hPrivateData->prevSFM_IIR[i], 13 ); /*2Q13*/ + for ( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) + { + hPrivateData->igfPastSFM[i][j] = fixedToFloat( hPrivateData->igfPastSFM_fx[i][j], 13 ); + } + } + + if ( st->hTdCngEnc != NULL ) + { + st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); + } + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + IF( st->hTcxEnc->fUseTns[0] || st->hTcxEnc->fUseTns[1] ) + { + if ( st->hTcxCfg->fIsTNSAllowed ) + { // conv params to float + // avgSqrCoef_flt = float(avgSqrCoef, Q 15) + hTcxEnc->tnsData[0].filter[0].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[0].avgSqrCoef, 15 ); + hTcxEnc->tnsData[0].filter[1].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[1].avgSqrCoef, 15 ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + hTcxEnc->tnsData[1].filter[0].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[0].avgSqrCoef, 15 ); + hTcxEnc->tnsData[1].filter[1].avgSqrCoef_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[1].avgSqrCoef, 15 ); + } + + // avgSqrCoef_flt = float(avgSqrCoef, Q 15) + hTcxEnc->tnsData[0].filter[0].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[0].predictionGain, 7 ); + hTcxEnc->tnsData[0].filter[1].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[0].filter[1].predictionGain, 7 ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + hTcxEnc->tnsData[1].filter[0].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[0].predictionGain, 7 ); + hTcxEnc->tnsData[1].filter[1].predictionGain_flt = fix16_to_float( hTcxEnc->tnsData[1].filter[1].predictionGain, 7 ); + } + // spectrum[]=float( (fix)spectrum_fx[]) , Q=q_factor_spectrum + // fixedToFloat_arrL( hTcxEnc->spectrum_long_fx, hTcxEnc->spectrum_long, q_factor_spectrum, N_MAX ); + + // subblockNrg_flt=(float)((fixed)subblockNrg) + fixedToFloat_arrL( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrg_flt, 7, 24 ); + + // subblockNrgChange_flt=(float)((fixed)subblockNrgChange) + fixedToFloat_arr( st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange, st->hTranDet->transientDetector.pSubblockEnergies->subblockNrgChange_flt, 7, 24 ); + } + } + } + + if ( st->element_mode == IVAS_CPE_DFT ) + { + hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); + hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); + hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); + fixedToFloat_arr( st->buf_wspeech_enc, st->buf_wspeech_enc_flt, q_fac, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + } + else if ( st->element_mode != IVAS_CPE_MDCT ) + { + hTcxEnc->tcxltp_gain_past_flt = fix16_to_float( hTcxEnc->tcxltp_gain_past, Q15 ); + hTcxEnc->tcxltp_gain_flt = fix16_to_float( hTcxEnc->tcxltp_gain, Q15 ); + hTcxEnc->tcxltp_norm_corr_past_flt = fix16_to_float( hTcxEnc->tcxltp_norm_corr_past, Q15 ); + fixedToFloat_arr( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, q_fac, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + } + + fixedToFloat_arrL32( hTcxEnc->spectrum_fx[0], hTcxEnc->spectrum[0], sub( Q31, hTcxEnc->spectrum_e[0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + fixedToFloat_arrL32( hTcxEnc->spectrum_fx[1], hTcxEnc->spectrum[1], sub( Q31, hTcxEnc->spectrum_e[1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + } + fixedToFloat_arrL32( mdst_spectrum_fx[ch][0], mdst_spectrum[ch][0], sub( Q31, mdst_spectrum_e[ch][0] ), st->hTcxEnc->L_frameTCX / nSubframes ); + IF( hTcxEnc->tcxMode != TCX_20 ) + { + fixedToFloat_arrL32( mdst_spectrum_fx[ch][1], mdst_spectrum[ch][1], sub( Q31, mdst_spectrum_e[ch][1] ), st->hTcxEnc->L_frameTCX / nSubframes ); + } + IF( ( EQ_16( transform_type[0], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + windowedSignal[ch][0] = (float) windowedSignal_fx[ch][0]; + windowedSignal[ch][1] = (float) windowedSignal_fx[ch][1]; + } + ELSE + { + tcx_get_windows( st->hTcxCfg, overlap_mode[0], overlap_mode[1], &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + len_windowSignal = ( st->hTcxEnc->L_frameTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; + windowedSignal[ch][0] = (float) windowedSignal_fx[ch][0]; + windowedSignal[ch][1] = (float) windowedSignal_fx[ch][1]; + fixedToFloat_arrL32( windowedSignal_fx[ch] + 2, windowedSignal[ch] + 2, 0, len_windowSignal ); + } + IF( NE_16( hTcxEnc->tcxMode, TCX_20 ) ) + { + IF( ( EQ_16( transform_type[1], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) + { + windowedSignal[ch][L_FRAME48k + 0] = (float) windowedSignal_fx[ch][L_FRAME_MAX + 0]; + windowedSignal[ch][L_FRAME48k + 1] = (float) windowedSignal_fx[ch][L_FRAME_MAX + 1]; + } + ELSE + { + tcx_get_windows( st->hTcxCfg, overlap_mode[1], overlap_mode[2], &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + len_windowSignal = ( st->hTcxEnc->L_frameTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; + windowedSignal[ch][L_FRAME48k + 0] = (float) windowedSignal_fx[ch][L_FRAME_MAX + 0]; + windowedSignal[ch][L_FRAME48k + 1] = (float) windowedSignal_fx[ch][L_FRAME_MAX + 1]; + fixedToFloat_arrL32( windowedSignal_fx[ch] + L_FRAME48k + 2, windowedSignal[ch] + L_FRAME48k + 2, 0, len_windowSignal ); + } + } +#endif +#else core_signal_analysis_high_bitrate( new_samples[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, mdst_spectrum[ch], tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0 ); +#endif /* BWD in MDCT domain */ if ( st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) @@ -1893,9 +2259,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 windowedSignal_fx[L_FRAME48k]; - set32_fx( windowedSignal_fx, 0, L_FRAME48k ); - q_com = L_get_q_buf1( hTcxEnc0->spectrum[n], hTcxEnc0->L_frameTCX / nSubframes ); q_com = s_min( q_com, L_get_q_buf1( mdst_spectrum[0][n], hTcxEnc0->L_frameTCX / nSubframes ) ); floatToFixed_arrL32( hTcxEnc0->spectrum[n], hTcxEnc0->spectrum_fx[n], q_com, hTcxEnc0->L_frameTCX / nSubframes ); @@ -1920,18 +2283,18 @@ void ivas_mdct_core_whitening_enc( PWord16 const *right_win; Word16 q_windowedSignal, len_windowSignal; - windowedSignal_fx[0] = ( Word16 ) * ( windowedSignal[0] + n * L_FRAME48k ); - windowedSignal_fx[1] = ( Word16 ) * ( windowedSignal[0] + n * L_FRAME48k + 1 ); - if ( ( hTcxEnc0->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEnc0->transform_type[n], TCX_20 ) && windowedSignal_fx[0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) + windowedSignal_fx[0][0] = ( Word16 ) * ( windowedSignal[0] + n * L_FRAME48k ); + windowedSignal_fx[0][1] = ( Word16 ) * ( windowedSignal[0] + n * L_FRAME48k + 1 ); + if ( ( hTcxEnc0->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEnc0->transform_type[n], TCX_20 ) && windowedSignal_fx[0][0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) { - tcx_get_windows( sts[0]->hTcxCfg, extract_l( windowedSignal_fx[0] ), extract_l( windowedSignal_fx[1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + tcx_get_windows( sts[0]->hTcxCfg, extract_l( windowedSignal_fx[0][0] ), extract_l( windowedSignal_fx[0][1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); len_windowSignal = ( L_subframeTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; q_windowedSignal = Q_factor_arrL( windowedSignal[0] + n * L_FRAME48k + 2, len_windowSignal ) - 1; - floatToFixed_arrL32( windowedSignal[0] + n * L_FRAME48k + 2, windowedSignal_fx + 2, q_windowedSignal, len_windowSignal ); + floatToFixed_arrL32( windowedSignal[0] + n * L_FRAME48k + 2, windowedSignal_fx[0] + n * L_FRAME48k + 2, q_windowedSignal, len_windowSignal ); } #endif kernel_switch_update_transforms_fx( hTcxEnc0->spectrum_fx[n], mdst_spectrum_fx[0][n], &q_com, hTcxEnc0->transform_type[n], sts[0]->hTcxCfg, sts[0]->bwidth_sw_cnt, hTcxEnc0->kernel_type[n], - hTcxEnc0->new_speech_TCX, ( n == 1 ? NULL : hTcxEnc0->speech_TCX ), windowedSignal_fx, &q_windowedSignal, L_subframeTCX / nSubframes ); + hTcxEnc0->new_speech_TCX, ( n == 1 ? NULL : hTcxEnc0->speech_TCX ), windowedSignal_fx[0] + n * L_FRAME48k, &q_windowedSignal, L_subframeTCX / nSubframes ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hTcxEnc0->spectrum_fx[n], hTcxEnc0->spectrum[n], q_com, hTcxEnc0->L_frameTCX / nSubframes ); fixedToFloat_arrL32( mdst_spectrum_fx[0][n], mdst_spectrum[0][n], q_com, hTcxEnc0->L_frameTCX / nSubframes ); @@ -1942,9 +2305,6 @@ void ivas_mdct_core_whitening_enc( #endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // Word32 windowedSignal_fx[L_FRAME48k]; - set32_fx( windowedSignal_fx, 0, L_FRAME48k ); - q_com = L_get_q_buf1( hTcxEnc1->spectrum[n], hTcxEnc1->L_frameTCX / nSubframes ); q_com = s_min( q_com, L_get_q_buf1( mdst_spectrum[1][n], hTcxEnc1->L_frameTCX / nSubframes ) ); floatToFixed_arrL32( hTcxEnc1->spectrum[n], hTcxEnc1->spectrum_fx[n], q_com, hTcxEnc1->L_frameTCX / nSubframes ); @@ -1964,18 +2324,18 @@ void ivas_mdct_core_whitening_enc( sts[1]->hTcxCfg->tcx_mdct_window_min_lengthFB ); } - windowedSignal_fx[0] = ( Word16 ) * ( windowedSignal[1] + n * L_FRAME48k ); - windowedSignal_fx[1] = ( Word16 ) * ( windowedSignal[1] + n * L_FRAME48k + 1 ); - if ( ( hTcxEnc1->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEnc1->transform_type[n], TCX_20 ) && windowedSignal_fx[0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[1]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) + windowedSignal_fx[1][0] = ( Word16 ) * ( windowedSignal[1] + n * L_FRAME48k ); + windowedSignal_fx[1][1] = ( Word16 ) * ( windowedSignal[1] + n * L_FRAME48k + 1 ); + if ( ( hTcxEnc1->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEnc1->transform_type[n], TCX_20 ) && windowedSignal_fx[1][0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[1]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) { - tcx_get_windows( sts[1]->hTcxCfg, extract_l( windowedSignal_fx[0] ), extract_l( windowedSignal_fx[1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + tcx_get_windows( sts[1]->hTcxCfg, extract_l( windowedSignal_fx[1][0] ), extract_l( windowedSignal_fx[1][1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); len_windowSignal = ( L_subframeTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; q_windowedSignal = Q_factor_arrL( windowedSignal[1] + n * L_FRAME48k + 2, len_windowSignal ) - 1; - floatToFixed_arrL32( windowedSignal[1] + n * L_FRAME48k + 2, windowedSignal_fx + 2, q_windowedSignal, len_windowSignal ); + floatToFixed_arrL32( windowedSignal[1] + n * L_FRAME48k + 2, windowedSignal_fx[1] + n * L_FRAME48k + 2, q_windowedSignal, len_windowSignal ); } #endif kernel_switch_update_transforms_fx( hTcxEnc1->spectrum_fx[n], mdst_spectrum_fx[1][n], &q_com, hTcxEnc1->transform_type[n], sts[1]->hTcxCfg, sts[1]->bwidth_sw_cnt, hTcxEnc1->kernel_type[n], - hTcxEnc1->new_speech_TCX, ( n == 1 ? NULL : hTcxEnc1->speech_TCX ), windowedSignal_fx, &q_windowedSignal, L_subframeTCX / nSubframes ); + hTcxEnc1->new_speech_TCX, ( n == 1 ? NULL : hTcxEnc1->speech_TCX ), windowedSignal_fx[1] + n * L_FRAME48k, &q_windowedSignal, L_subframeTCX / nSubframes ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hTcxEnc1->spectrum_fx[n], hTcxEnc1->spectrum[n], q_com, hTcxEnc1->L_frameTCX / nSubframes ); fixedToFloat_arrL32( mdst_spectrum_fx[1][n], mdst_spectrum[1][n], q_com, hTcxEnc1->L_frameTCX / nSubframes ); @@ -2119,9 +2479,6 @@ void ivas_mdct_core_whitening_enc( #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 windowedSignal_fx[L_FRAME48k]; - set32_fx( windowedSignal_fx, 0, L_FRAME48k ); - q_com = L_get_q_buf1( hTcxEncCh->spectrum[n], hTcxEncCh->L_frameTCX / nSubframes ); q_com = s_min( q_com, L_get_q_buf1( mdst_spectrum[ch][n], hTcxEncCh->L_frameTCX / nSubframes ) ); floatToFixed_arrL32( hTcxEncCh->spectrum[n], hTcxEncCh->spectrum_fx[n], q_com, hTcxEncCh->L_frameTCX / nSubframes ); @@ -2146,18 +2503,18 @@ void ivas_mdct_core_whitening_enc( PWord16 const *right_win; Word16 q_windowedSignal, len_windowSignal; - windowedSignal_fx[0] = ( Word16 ) * ( windowedSignal[ch] + n * L_FRAME48k ); - windowedSignal_fx[1] = ( Word16 ) * ( windowedSignal[ch] + n * L_FRAME48k + 1 ); - if ( ( hTcxEncCh->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEncCh->transform_type[n], TCX_20 ) && windowedSignal_fx[0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[ch]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) + windowedSignal_fx[ch][0] = ( Word16 ) * ( windowedSignal[ch] + n * L_FRAME48k ); + windowedSignal_fx[ch][1] = ( Word16 ) * ( windowedSignal[ch] + n * L_FRAME48k + 1 ); + if ( ( hTcxEncCh->transform_type[n] == TCX_5 ) || ( n == 0 /* speech_TCX != NULL*/ && NE_16( hTcxEncCh->transform_type[n], TCX_20 ) && windowedSignal_fx[ch][0] == FULL_OVERLAP && GT_16( sub( L_subframeTCX / nSubframes, leftOverlap ), sts[ch]->hTcxCfg->tcx_mdct_window_min_lengthFB - 1 ) ) ) { - tcx_get_windows( sts[ch]->hTcxCfg, extract_l( windowedSignal_fx[0] ), extract_l( windowedSignal_fx[1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); + tcx_get_windows( sts[ch]->hTcxCfg, extract_l( windowedSignal_fx[ch][0] ), extract_l( windowedSignal_fx[ch][1] ), &leftOverlap, &left_win, &rightOverlap, &right_win, 1 ); len_windowSignal = ( L_subframeTCX / nSubframes ) + ( leftOverlap + rightOverlap ) / 2; q_windowedSignal = Q_factor_arrL( windowedSignal[ch] + n * L_FRAME48k + 2, len_windowSignal ) - 1; - floatToFixed_arrL32( windowedSignal[ch] + n * L_FRAME48k + 2, windowedSignal_fx + 2, q_windowedSignal, len_windowSignal ); + floatToFixed_arrL32( windowedSignal[ch] + n * L_FRAME48k + 2, windowedSignal_fx[ch] + n * L_FRAME48k + 2, q_windowedSignal, len_windowSignal ); } #endif kernel_switch_update_transforms_fx( hTcxEncCh->spectrum_fx[n], mdst_spectrum_fx[ch][n], &q_com, hTcxEncCh->transform_type[n], sts[ch]->hTcxCfg, sts[ch]->bwidth_sw_cnt, hTcxEncCh->kernel_type[n], - hTcxEncCh->new_speech_TCX, ( n /*1*/ ? NULL : hTcxEncCh->speech_TCX ), windowedSignal_fx, &q_windowedSignal, L_subframeTCX / nSubframes ); + hTcxEncCh->new_speech_TCX, ( n /*1*/ ? NULL : hTcxEncCh->speech_TCX ), windowedSignal_fx[ch] + n * L_FRAME48k, &q_windowedSignal, L_subframeTCX / nSubframes ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arrL32( hTcxEncCh->spectrum_fx[n], hTcxEncCh->spectrum[n], q_com, hTcxEncCh->L_frameTCX / nSubframes ); fixedToFloat_arrL32( mdst_spectrum_fx[ch][n], mdst_spectrum[ch][n], q_com, hTcxEncCh->L_frameTCX / nSubframes ); @@ -2179,15 +2536,15 @@ void ivas_mdct_core_whitening_enc( { st = sts[ch]; hTcxEnc = st->hTcxEnc; - q_com = L_get_q_buf1( st->hTcxEnc->spectrum[0], N_MAX ); - st->hTcxEnc->spectrum_e[0] = Q31 - ( q_com - 4 ); - floatToFixed_arrL32( st->hTcxEnc->spectrum[0], st->hTcxEnc->spectrum_fx[0], ( Q31 - st->hTcxEnc->spectrum_e[0] ), N_MAX ); - nSubframes = ( hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; for ( k = 0; k < nSubframes; k++ ) { - q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], 2 * st->hTcxCfg->tcx5SizeFB ); - floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], 2 * st->hTcxCfg->tcx5SizeFB ); + q_com = L_get_q_buf1( st->hTcxEnc->spectrum[k], st->hTcxEnc->L_frameTCX / nSubframes ); + st->hTcxEnc->spectrum_e[k] = Q31 - ( q_com - 4 ); + floatToFixed_arrL32( st->hTcxEnc->spectrum[k], st->hTcxEnc->spectrum_fx[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); + + q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); + floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } hTcxEnc->tcxltp_gain = (Word16) ( hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); @@ -2201,13 +2558,11 @@ void ivas_mdct_core_whitening_enc( { st = sts[ch]; hTcxEnc = st->hTcxEnc; - fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[0], st->hTcxEnc->spectrum[0], ( Q31 - st->hTcxEnc->spectrum_e[0] ), N_MAX ); - nSubframes = ( hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for ( k = 0; k < nSubframes; k++ ) { - fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], 2 * st->hTcxCfg->tcx5SizeFB ); + fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); + fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } sts[ch]->hTcxEnc->tcxltp_gain_flt = fix16_to_float( sts[ch]->hTcxEnc->tcxltp_gain, Q15 ); } @@ -2497,17 +2852,17 @@ void ivas_mdct_core_whitening_enc( { st = sts[ch]; hTcxEnc = st->hTcxEnc; - q_com = L_get_q_buf1( st->hTcxEnc->spectrum[0], N_MAX ); - nSubframes = ( hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - st->hTcxEnc->spectrum_e[0] = Q31 - ( q_com - 4 ); - floatToFixed_arrL32( st->hTcxEnc->spectrum[0], st->hTcxEnc->spectrum_fx[0], ( Q31 - st->hTcxEnc->spectrum_e[0] ), N_MAX ); - for ( k = 0; k < nSubframes; k++ ) { - q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], st->hTcxCfg->tcx5SizeFB ); - floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], 2 * st->hTcxCfg->tcx5SizeFB ); + q_com = L_get_q_buf1( st->hTcxEnc->spectrum[k], st->hTcxEnc->L_frameTCX / nSubframes ); + st->hTcxEnc->spectrum_e[k] = Q31 - ( q_com - 4 ); + floatToFixed_arrL32( st->hTcxEnc->spectrum[k], st->hTcxEnc->spectrum_fx[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); + + q_temp[ch][k] = L_get_q_buf1( mdst_spectrum[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); + floatToFixed_arrL32( mdst_spectrum[ch][k], mdst_spectrum_fx[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } + hTcxEnc->tcxltp_gain = (Word16) ( hTcxEnc->tcxltp_gain_flt * ( 1 << Q15 ) ); } #endif @@ -2519,13 +2874,11 @@ void ivas_mdct_core_whitening_enc( { st = sts[ch]; hTcxEnc = st->hTcxEnc; - fixedToFloat_arrL( st->hTcxEnc->spectrum_fx[0], st->hTcxEnc->spectrum[0], ( Q31 - st->hTcxEnc->spectrum_e[0] ), N_MAX ); - nSubframes = ( hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; - for ( k = 0; k < nSubframes; k++ ) { - fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], 2 * st->hTcxCfg->tcx5SizeFB ); + fixedToFloat_arrL32( st->hTcxEnc->spectrum_fx[k], st->hTcxEnc->spectrum[k], ( Q31 - st->hTcxEnc->spectrum_e[k] ), st->hTcxEnc->L_frameTCX / nSubframes ); + fixedToFloat_arrL32( mdst_spectrum_fx[ch][k], mdst_spectrum[ch][k], q_temp[ch][k], st->hTcxEnc->L_frameTCX / nSubframes ); } sts[ch]->hTcxEnc->tcxltp_gain_flt = fix16_to_float( sts[ch]->hTcxEnc->tcxltp_gain, Q15 ); } @@ -3409,7 +3762,6 @@ void ivas_mdct_core_whitening_enc( pop_wmops(); return; } -#endif /*--------------------------------------------------------------* @@ -3560,6 +3912,7 @@ void ivas_mdct_quant_coder( pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED void ivas_mdct_quant_coder_fx( CPE_ENC_HANDLE hCPE, /* i/o: Encoder CPE handle */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 6d42df9331138e9bcf51673e4eff9267791dabbb..e62ae779241d7a466a78277fc0e996c8481e34d3 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -76,7 +76,9 @@ typedef struct stereo_itd_data_struct float prev_avg_max; Word32 prev_avg_max_fx; Word16 prev_avg_max_fx_e; +#ifndef IVAS_FLOAT_FIXED float currFlatness; +#endif Word16 currFlatness_fx; /* Xtalk classifier */ @@ -664,7 +666,7 @@ typedef struct stereo_icbwe_enc_data_structure Word16 memHPF_fx[8]; // Q -> q_dataChan_fx Word16 mem_decim_shb_ch0_fx[2 * L_FILT_MAX]; // Q0 Word16 mem_shb_speech_ref_fx[L_LOOK_16k]; - Word32 mem_shb_speech_nonref_fx[L_LOOK_16k]; + Word16 mem_shb_speech_nonref_fx[L_LOOK_16k]; Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; Word32 prevSpecMapping_fx; Word32 memShbSpecMapping_fx; @@ -692,6 +694,25 @@ typedef struct stereo_icbwe_enc_data_structure Word16 MSFlag; Word16 icbweRefEner_fx_e; + Word16 mem_shb_speech_ref_e; + Word16 mem_shb_speech_nonref_e; + Word16 mem_lpc_shbsynth_nonref_e; + Word16 memShbSpecMapping_e; + Word16 memShbSpecXcorr_e; + Word16 prevgsMapping_e; + Word16 prevRefEner_e; // Q31 + Word16 prevNonRefEner_e; // Q31 + Word16 memGsEnerMap_e; + Word16 mem_nrg_L_fx_e; + Word16 mem_nrg_R_fx_e; + Word16 mem_nrg_DMX_fx_e; + Word16 gDes_pastFrame_e; // Q31 + Word16 icbweRefEner_e; + Word16 shbSynthRef_e; + Word16 lpSHBRef_e; + Word16 nlExc16k_e; + Word16 mixExc16k_e; + } STEREO_ICBWE_ENC_DATA, *STEREO_ICBWE_ENC_HANDLE; @@ -705,11 +726,13 @@ typedef struct ivas_stereo_classifier_data_structure Word16 clas_ch1; Word16 pitch_ch1[3]; float voicing_ch1[3]; +#ifndef IVAS_FLOAT_FIXED float cor_map_sum_ch1; float lsf_ch1[M]; float lepsP_ch1; float dE1_ch1, dE1_ch2; float nchar_ch1, nchar_ch2; +#endif float non_sta_ch1; float sp_div_ch1; float ps_diff_ch1, ps_diff_ch2; @@ -724,6 +747,7 @@ typedef struct ivas_stereo_classifier_data_structure Word16 vad_relE; Word16 aEn_raw[CPE_CHANNELS]; /* raw aEn for local relative energy estimation */ +#ifndef IVAS_FLOAT_FIXED float ave_ener_L; /* average energy of the L channel */ float ave_ener_R; /* average energy of the R channel */ float Etot_dn; /* average energy in dB - lower bound */ @@ -732,21 +756,26 @@ typedef struct ivas_stereo_classifier_data_structure float Etot_buf[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ float relE_0_1; /* relative energy in the current frame normalized to (0,1) */ float relE_0_1_LT; +#endif Word16 unclr_sw_enable_cnt[CPE_CHANNELS]; /* UNCLR classifier - counter of frames suitable for UNCLR switching */ - +#ifndef IVAS_FLOAT_FIXED float unclr_relE_0_1_LT[UNCLR_RC_ORDER]; float unclr_wscore; +#endif Word16 unclr_decision; /* UNCLR stereo classifier decision (0/1) */ float unclr_fv[SSC_MAX_NFEA]; /* UNCLR - feature vector */ Word16 unclr_corrLagMax_prev; - +#ifndef IVAS_FLOAT_FIXED float xtalk_score_buf[XTALK_SCORE_BUF_LEN]; - Word16 xtalk_decision; /* xtalk stereo classifier decision (0/1) */ +#endif + Word16 xtalk_decision; /* xtalk stereo classifier decision (0/1) */ +#ifndef IVAS_FLOAT_FIXED float xtalk_fv[SSC_MAX_NFEA]; /* xtalk - feature vector */ float xtalk_wscore; float xtalk_score; float xtalk_score_wrelE; +#endif Word16 lrtd_mode; Word16 prev_lrtd_mode; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index adeeb1ff6ea1aaa3167d2207382fecac2da10f93..e4000c67b85726ccd9e0044492a5cfbe9354e317 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -95,9 +95,9 @@ static void edge_detect( const float *inp, const int16_t len, const float inp_mi #ifdef IVAS_FLOAT_FIXED static Word32 redge_detect_fx( const Word32 *inp, const Word16 len, const Word32 inp_min, const Word32 inp_max, Word16 *edge_min_e ); -#endif +#else static float redge_detect( const float *inp, const int16_t len, const float inp_min, const float inp_max ); - +#endif /*-------------------------------------------------------------------* * Function select_stereo_mode() @@ -422,6 +422,7 @@ void stereo_classifier_init( hStereoClassif->clas_ch1 = 0; set_s( hStereoClassif->pitch_ch1, 0, 3 ); set_f( hStereoClassif->voicing_ch1, 0.0f, 3 ); +#ifndef IVAS_FLOAT_FIXED hStereoClassif->cor_map_sum_ch1 = 0.0f; set_f( hStereoClassif->lsf_ch1, 0.0f, M ); hStereoClassif->lepsP_ch1 = 0.0f; @@ -429,6 +430,7 @@ void stereo_classifier_init( hStereoClassif->dE1_ch2 = 0.0f; hStereoClassif->nchar_ch1 = 0.0f; hStereoClassif->nchar_ch2 = 0.0f; +#endif hStereoClassif->non_sta_ch1 = 0.0f; hStereoClassif->sp_div_ch1 = 0.0f; @@ -446,38 +448,45 @@ void stereo_classifier_init( hStereoClassif->prev_g_IPD = 0.5f; hStereoClassif->prev_IPD = 0.0f; hStereoClassif->prev_ratio_m1_m2 = 0.0f; +#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->xtalk_score_buf, 0.0f, XTALK_SCORE_BUF_LEN ); +#endif hStereoClassif->ratio_L = 0.5f; hStereoClassif->vad_flag_glob = 0; hStereoClassif->vad_relE = 0; hStereoClassif->is_speech = 0.0f; set_s( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); - +#ifndef IVAS_FLOAT_FIXED hStereoClassif->Etot_dn = 0.0f; hStereoClassif->Etot_up = 0.0f; - set_f( hStereoClassif->relE_buf, 0.0f, UNCLR_L_RELE ); set_f( hStereoClassif->Etot_buf, 0.0f, UNCLR_L_ETOT ); +#endif +#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->unclr_relE_0_1_LT, 0.0f, UNCLR_RC_ORDER ); - +#endif hStereoClassif->unclr_sw_enable_cnt[0] = 0; hStereoClassif->unclr_sw_enable_cnt[1] = 0; hStereoClassif->unclr_decision = 0; +#ifndef IVAS_FLOAT_FIXED hStereoClassif->unclr_wscore = 0.0f; - +#endif set_f( hStereoClassif->unclr_fv, -1.0f, SSC_MAX_NFEA ); hStereoClassif->unclr_corrLagMax_prev = 0; +#ifndef IVAS_FLOAT_FIXED hStereoClassif->ave_ener_L = 0; hStereoClassif->ave_ener_R = 0; hStereoClassif->relE_0_1 = 0.01f; hStereoClassif->relE_0_1_LT = 0.01f; - +#endif +#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); hStereoClassif->xtalk_wscore = 0.0f; - hStereoClassif->xtalk_decision = 0; hStereoClassif->xtalk_score_wrelE = 0.0f; +#endif + hStereoClassif->xtalk_decision = 0; hStereoClassif->lrtd_mode = 0; hStereoClassif->prev_lrtd_mode = 0; @@ -549,11 +558,19 @@ void stereo_classifier_init_fx( hStereoClassif->Etot_dn_fx = 0; move32(); + hStereoClassif->Etot_dn_e = 0; + move16(); hStereoClassif->Etot_up_fx = 0; move32(); + hStereoClassif->Etot_up_e = 0; + move16(); set_zero_fx( hStereoClassif->relE_buf_fx, UNCLR_L_RELE ); + hStereoClassif->relE_buf_e = 0; + move16(); set_zero_fx( hStereoClassif->Etot_buf_fx, UNCLR_L_ETOT ); + hStereoClassif->e_Etot_buf_fx = 0; + move16(); set_zero_fx( hStereoClassif->unclr_relE_0_1_LT_fx, UNCLR_RC_ORDER ); hStereoClassif->unclr_sw_enable_cnt[0] = 0; @@ -812,7 +829,6 @@ void stereo_classifier_features_ivas_fx( { Copy32( lsf_new_fx, hStereoClassif->lsf_ch1_fx, M ); hStereoClassif->lepsP_ch1_fx = L_shr( L_sub( BASOP_Util_Loge( L_add( epsP_fx[13], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ), BASOP_Util_Loge( L_add( epsP_fx[0], L_shr( 21474 /*1e-5*2^31*/, epsP_e ) ), epsP_e ) ), 10 ); /*q15*/ - hStereoClassif->lepsP_ch1_e = 16; move32(); move16(); @@ -2078,6 +2094,7 @@ void xtalk_classifier_dft_fx( return; } #endif +#ifndef IVAS_FLOAT_FIXED void xtalk_classifier_dft( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const int16_t itd, /* i : ITD from DFT stereo - used as a feature */ @@ -2226,7 +2243,7 @@ void xtalk_classifier_dft( return; } - +#endif /*-------------------------------------------------------------------* * Function rc_filter() @@ -2616,7 +2633,7 @@ static Word32 redge_detect_fx( return edge_min; // Q31 } -#endif +#else /*! r: rising edge strength normalized to 0-1 */ static float redge_detect( const float *inp, /* i : input buffer (ordered from newest to oldest values)*/ @@ -2676,3 +2693,4 @@ static float redge_detect( return edge_min; } +#endif diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 30fd5303be753135d696e39bb219a7f50d7f8312..91799b60aca99cae00dbfa099f9593cd768314ec 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -830,12 +830,8 @@ void stereo_dft_cng_side_gain_fx( /* Use coarse band partitioning in inactive frames */ /* Rescale bands to the coarser partitioning taking the band size into account */ Copy( hStereoDft->band_limits, band_limits_full, STEREO_DFT_BAND_MAX + 1 ); -#ifndef IVAS_FLOAT_FIXED - hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->hConfig->band_res, min( STEREO_DFT_N_32k_ENC, NFFT_inner ), ENC ); -#else hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, s_min( STEREO_DFT_N_32k_ENC, NFFT_inner ), ENC ); move16(); -#endif IF( GT_16( nbands_full, add( hStereoDft->nbands, 1 ) ) ) { FOR( b = 0; b < hStereoDft->nbands; b++ ) diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index e6b1449b63b129ec14f001b94f453759f2c80989..c596fcbb532c6dbf8b12bc5b8c512742abb9c740 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1274,8 +1274,9 @@ void stereo_enc_itd_init( hItd->prev_max = 0.f; hItd->prev_index = 0; hItd->prev_avg_max = 0.f; +#ifndef IVAS_FLOAT_FIXED hItd->currFlatness = 0.f; - +#endif /* Xtalk classifier */ hItd->prev_m1 = 0; hItd->prev_m2 = 0; @@ -3427,17 +3428,6 @@ void stereo_dft_enc_process_fx( stereo_dft_enc_calculate_nrg_for_icbwe_fx( hStereoDft, DFT_L_e_tmp, DFT_R_e_tmp, DFT_DMX, DFT_DMX_e, input_Fs ); } -#if 0 // def IVAS_FLOAT_FIXED_CONVERSIONS - float DFT_DMX_flt[STEREO_DFT_N_MAX_ENC]; - float DFT_RES_flt[STEREO_DFT_N_8k_ENC]; - - for (i = 0; i < STEREO_DFT_N_MAX_ENC; i++) { - DFT_DMX_flt[i] = me2f(DFT_DMX[i], DFT_DMX_e[i]); - } - for (i = 0; i < STEREO_DFT_N_8k_ENC; i++) { - DFT_RES_flt[i] = me2f(DFT_RES[i], DFT_RES_e[i]); - } -#endif // making exp common Word16 max_exp = MIN_16; move16(); diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 5dd6f6dbe74ccac033355631895536c214422cbd..effd61ed8f0f58af6c8a86d8dd245cbd2a3d91a2 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -122,7 +122,7 @@ static void set_band_limits_fx( return; } -#endif +#else static void set_band_limits( int16_t *nbands, int16_t band_limits[STEREO_DFT_BAND_MAX + 1], @@ -139,7 +139,7 @@ static void set_band_limits( return; } - +#endif /*------------------------------------------------------------------------- * stereo_dft_hybrid_ITD_flag() @@ -213,7 +213,7 @@ static void stereo_dft_quantize_itd_fx( return; } -#endif +#else static void stereo_dft_quantize_itd( const int16_t in, float *out, @@ -239,7 +239,7 @@ static void stereo_dft_quantize_itd( return; } - +#endif /*------------------------------------------------------------------------- * itd_vad_ms_snr_calc() @@ -321,7 +321,7 @@ static Word32 itd_vad_ms_snr_calc_fx( return ( ms_snr ); } -#endif +#else static float itd_vad_ms_snr_calc( float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], float *Spd, @@ -360,7 +360,7 @@ static float itd_vad_ms_snr_calc( return ( ms_snr ); } - +#endif /*------------------------------------------------------------------------- * itd_vad_background_update() @@ -465,7 +465,7 @@ static void itd_vad_background_update_fx( return; } -#endif +#else static void itd_vad_background_update( float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], int16_t *vad_frm_cnt, @@ -511,7 +511,7 @@ static void itd_vad_background_update( return; } - +#endif /*------------------------------------------------------------------------- * stereo_dft_enc_itd_vad() * @@ -571,7 +571,7 @@ static Word16 stereo_dft_enc_itd_vad_fx( return ( vad_flag_itd ); } -#endif +#else static int16_t stereo_dft_enc_itd_vad( float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], int16_t *vad_frm_cnt, @@ -612,7 +612,7 @@ static int16_t stereo_dft_enc_itd_vad( return ( vad_flag_itd ); } - +#endif /*------------------------------------------------------------------------- * calc_mean_E_ratio() @@ -792,7 +792,7 @@ static Word32 calc_mean_E_ratio_fx( // return ( sum_Er * B_DENOM ); return Mpy_32_32( sum_Er, B_DENOM_Q31 ); } -#endif +#else static float calc_mean_E_ratio( ITD_DATA_HANDLE hItd, int16_t nbands, @@ -860,7 +860,7 @@ static float calc_mean_E_ratio( return ( sum_Er * B_DENOM ); } - +#endif /*------------------------------------------------------------------------- * resetEstimates() @@ -885,7 +885,7 @@ static void resetEstimates_fx( return; } -#endif +#else static void resetEstimates( ITD_DATA_HANDLE hItd ) { @@ -896,7 +896,7 @@ static void resetEstimates( return; } - +#endif /*------------------------------------------------------------------------- * td_sm_filter() * @@ -930,7 +930,7 @@ static void td_sm_filter_fx( return; } -#endif +#else static void td_sm_filter( float *x, float *y, @@ -954,7 +954,7 @@ static void td_sm_filter( return; } - +#endif /*------------------------------------------------------------------------- * peak_detect() * @@ -1176,7 +1176,7 @@ static Word32 peak_detect_fx( return Mpy_32_32( wfac, avg_max ); // 2+sum_max_e } } -#endif +#else static float peak_detect( float *xcorr_itd, float *max_max, @@ -1321,7 +1321,7 @@ static float peak_detect( return ( wfac * avg_max ); } } - +#endif /*------------------------------------------------------------------------- * Compute stereo parameter: ITD @@ -2952,6 +2952,7 @@ void stereo_dft_enc_compute_itd_fx( return; } #endif +#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_compute_itd( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ float *DFT_L, @@ -3716,3 +3717,4 @@ void stereo_dft_enc_compute_itd( return; } +#endif diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 1800950b7630bff2c6843b560593074a72594c2b..5c7b73a015153d7b22a90266cf773e68a218eb04 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -441,22 +441,23 @@ static void stereo_td_channel_extrapolate_fx( FOR( i = input_frame - itd_shift; i < input_frame; i++ ) { - shift_input[i] = add( mult( g_lpc, shift_input[i] ), mult( g, sts[leading_channel]->input_fx[i] ) ); + shift_input[i] = extract_h( L_mac0( L_mult0( g_lpc, shift_input[i] ), g, sts[leading_channel]->input_fx[i] ) ); // Q = 14 + q_shift - 16 + move16(); } - Word16 q_temp = 14 + q_shift - 15; + Word16 q_temp = sub( q_shift, 2 ); /* smooth transition (currently done by blending over linearly, could be replaced by something more elaborate.) */ - Word16 e_shift = 0, q_pre_ovl[1280]; - q_temp = q_shift - 1; + Word16 e_shift = 0; FOR( i = input_frame - itd_shift - pred_ovlp; i < input_frame - itd_shift; i++ ) { - Word32 temp1 = L_mult0( ( i - input_frame + itd_shift + pred_ovlp ), add( mult( g_lpc, shift_input[i] ), mult( g, sts[leading_channel]->input_fx[i] ) ) ); // 14 + q_shift - 15; + Word32 temp1 = L_mult0( ( i - input_frame + itd_shift + pred_ovlp ), add( mult( g_lpc, shift_input[i] ), mult( g, sts[leading_channel]->input_fx[i] ) ) ); // q_shift-1(14 + q_shift - 15); Word32 temp2 = L_mult0( ( input_frame - itd_shift - i ), shift_input[i] ); // q_shift temp2 = L_shr( temp2, 1 ); // q_shift-1 - temp1 = L_add( temp1, temp2 ); // Q_shift-1 - shift_input[i] = BASOP_Util_Divide3232_Scale( temp1, pred_ovlp, &e_shift ); - q_pre_ovl[i] = 15 - e_shift + q_shift - 1; - q_temp = s_min( q_pre_ovl[i], q_temp ); + temp1 = L_add( temp1, temp2 ); // q_shift-1 + shift_input[i] = BASOP_Util_Divide3232_Scale( temp1, pred_ovlp, &e_shift ); // Q=15-e_shift+q_shift-1 + move16(); + shift_input[i] = shr( shift_input[i], sub( add( sub( 15, e_shift ), sub( q_shift, 1 ) ), q_temp ) ); // q_temp + move16(); } // scaling whole buffer to q_temp// @@ -465,15 +466,6 @@ static void stereo_td_channel_extrapolate_fx( shift_input[i] = shr( shift_input[i], q_shift - q_temp ); } - FOR( i = input_frame - itd_shift; i < input_frame; i++ ) - { - shift_input[i] = shr( shift_input[i], q_shift - 1 - q_temp ); - } - - FOR( i = input_frame - itd_shift - pred_ovlp; i < input_frame - itd_shift; i++ ) - { - shift_input[i] = shr( shift_input[i], q_pre_ovl[i] - q_temp ); - } *q_new_shift = q_temp; return; } @@ -771,6 +763,7 @@ void stereo_td_itd_fx( ELSE { Copy( shift_mem, mdct_mem[ch], input_frame ); + Scale_sig( mdct_mem[ch], input_frame, sub( sts[ch]->q_inp, *q_input_mem ) ); } } } @@ -784,7 +777,7 @@ void stereo_td_itd_fx( * * Time-domain ITD in MDCT stereo * ---------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void stereo_td_itd_mdct_stereo( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder handle */ const int16_t vad_flag_dtx[], /* i : VAD dtx flags */ @@ -824,7 +817,7 @@ void stereo_td_itd_mdct_stereo( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void stereo_td_itd_mdct_stereo_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder handle */ diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index f35a9a3f876732994500bb04637e69476a451a74..9a85c984d7f01533a0335c23266086c74e8977c5 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -2309,7 +2309,6 @@ void stereo_tca_enc( floatToFixed_arrL32( bufChanL_DS, bufChanL_DS_fx, q_com, L_FRAME_DS + ADDED_MEM_DS ); floatToFixed_arrL32( bufChanR_DS, bufChanR_DS_fx, q_com, L_FRAME_DS + ADDED_MEM_DS ); - floatToFixed_arrL32( hCPE->hStereoClassif->xtalk_fv, hCPE->hStereoClassif->xtalk_fv_fx, Q15, SSC_MAX_NFEA ); floatToFixed_arrL32( hCPE->hStereoClassif->unclr_fv, hCPE->hStereoClassif->unclr_fv_fx, Q15, SSC_MAX_NFEA ); hStereoTCA->prevTargetGain_fx = floatToFixed_32( hStereoTCA->prevTargetGain, Q29 ); #endif @@ -2317,10 +2316,7 @@ void stereo_tca_enc( corrStatsEst_fx( hStereoTCA, bufChanL_DS_fx + ADDED_MEM_DS, bufChanR_DS_fx + ADDED_MEM_DS, q_com, ( L_FRAME_DS + L_XCORRMEM_DS ), dsFactor, hCPE->hCoreCoder[0]->vad_flag, hCPE->hCoreCoder[1]->vad_flag, hCPE->hStereoClassif ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( hCPE->hStereoClassif->xtalk_fv_fx, hCPE->hStereoClassif->xtalk_fv, Q15, SSC_MAX_NFEA ); fixedToFloat_arrL32( hCPE->hStereoClassif->unclr_fv_fx, hCPE->hStereoClassif->unclr_fv, Q15, SSC_MAX_NFEA ); - hCPE->hStereoClassif->ave_ener_L = me2f( hCPE->hStereoClassif->ave_ener_L_fx, hCPE->hStereoClassif->ave_ener_L_fx_e ); - hCPE->hStereoClassif->ave_ener_R = me2f( hCPE->hStereoClassif->ave_ener_R_fx, hCPE->hStereoClassif->ave_ener_R_fx_e ); hStereoTCA->corrStatsSmoothFac = me2f_16( hStereoTCA->corrStatsSmoothFac_fx, 0 ); #endif #else diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index bfdd2bf7c8b2212cd4fbb63d2213543709c00a07..676f60e540da994ad04d8434293619a5aed71be6 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -44,6 +44,7 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "ivas_rom_com_fx.h" #endif /*-------------------------------------------------------------------* @@ -74,6 +75,34 @@ static void ic_bwe_enc_reset( return; } +#ifdef IVAS_FLOAT_FIXED +static void ic_bwe_enc_reset_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo ICBWE handle */ +) +{ + /* unscaled & scaled SHB synthesis memory */ + set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); + + /* inter-channel BWE spectral shape adj. */ + hStereoICBWE->prevSpecMapping_fx = 0; + move32(); + hStereoICBWE->prevgsMapping_fx = ONE_IN_Q31; + move32(); + set32_fx( &( hStereoICBWE->memShbSpecMapping_fx ), 0, 1 ); + set32_fx( hStereoICBWE->memShbSpecXcorr_fx, 0, 6 ); + set32_fx( hStereoICBWE->memGsEnerMap_fx, ONE_IN_Q31, 2 ); + set32_fx( hStereoICBWE->mem_nrg_L_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_R_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_DMX_fx, 0, 2 ); + hStereoICBWE->gDes_pastFrame_fx = ONE_IN_Q31; + move32(); + hStereoICBWE->icbweRefEner_fx = 0; + move32(); + + return; +} +#endif + /*--------------------------------------------------------------------------* * ic_bwe_specMapping() * @@ -170,6 +199,218 @@ static int16_t ic_bwe_enc_specMapping( return idx; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +static Word16 ic_bwe_enc_specMapping_ivas_fx( + const Word32 *shb_frame_target_fx, /* i : target shb */ + Word16 shb_frame_target_e, + Word32 *shb_synth_nonref_fx, /* o : non-ref shb synth */ + Word16 shb_synth_nonref_e, + Word32 *specMapping_fx, /* i/o: current frame's mapping */ + Word32 *memShbSpecMapping_fx, /* i/o: current frame's mapping */ + Word32 *memShbSpecXcorr_fx, /* i/o: ic bwe spec mapping scorr memory */ + Word16 *memShbSpecXcorr_e ) +{ + Word16 idx; + + Word16 Txx1_fx = 0, Txx2_fx = 0, Txx3_fx = 0, T_desired_fx = 0; + Word16 Txx1_e = 0, Txx2_e = 0, Txx3_e = 0, T_desired_e = 0; + Word16 T_nonref_target_fx, temp_fx; + Word32 temp0_fx, temp1_fx, temp2_fx, temp3_fx; + Word16 a_fx, b_fx, c_fx, a_e, b_e, c_e; + Word16 u_fx, u1_fx, u2_fx, u_e = 0, u1_e, u2_e; + Word16 temp0_exp, temp1_exp, temp2_exp, temp3_exp, exp, T_nonref_target_e; + Word16 exp_buf[6]; + + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + /* Calculate rxx(1)/rxx(0) of the non ref target */ + + temp0_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx, shb_frame_target_e, L_FRAME16k - 1, &temp0_exp ); + temp1_fx = dotp_fixed_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx + 1, shb_frame_target_e, L_FRAME16k - 1, &temp1_exp ); + + /* Smoothing */ + temp0_fx = L_shr( temp0_fx, 1 ); + temp1_fx = L_shr( temp1_fx, 1 ); + + + memShbSpecXcorr_fx[0] = temp0_fx; // tem0_exp + memShbSpecXcorr_fx[1] = L_shr( temp1_fx, temp0_exp - temp1_exp ); // temp0_exp + exp = sub( temp0_exp, temp1_exp ); + exp_buf[0] = exp; + exp_buf[1] = exp; + move32(); + move32(); + move16(); + move16(); + + IF( temp0_fx != 0 ) + { + T_nonref_target_fx = BASOP_Util_Divide3232_Scale( temp1_fx, temp0_fx, &T_nonref_target_e ); // exp + } + ELSE + { + T_nonref_target_fx = 0; + T_nonref_target_e = 31; + move32(); + move16(); + } + + /* Calculate rxx(1)/rxx(0) of the non ref synth */ + temp0_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, L_FRAME16k - 3, &temp0_exp ); + temp1_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 1, shb_synth_nonref_e, L_FRAME16k - 3, &temp1_exp ); + temp2_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 2, shb_synth_nonref_e, L_FRAME16k - 3, &temp2_exp ); + temp3_fx = dotp_fixed_ivas_fx( shb_synth_nonref_fx, shb_synth_nonref_e, shb_synth_nonref_fx + 3, shb_synth_nonref_e, L_FRAME16k - 3, &temp3_exp ); + + /* Smoothing */ + temp0_fx = L_shr( temp0_fx, 1 ); + temp1_fx = L_shr( temp1_fx, 1 ); + temp2_fx = L_shr( temp2_fx, 1 ); + temp3_fx = L_shr( temp3_fx, 1 ); + + exp_buf[2] = temp0_exp; + exp_buf[3] = temp1_exp; + exp_buf[4] = temp2_exp; + exp_buf[5] = temp3_exp; + exp = exp_buf[0]; + move16(); + move16(); + move16(); + move16(); + move16(); + FOR( Word16 i = 0; i < 6; i++ ) + { + IF( LT_16( exp, exp_buf[i] ) ) + { + exp = exp_buf[i]; + move16(); + } + } + memShbSpecXcorr_fx[2] = L_shr( temp0_fx, sub( exp, temp0_exp ) ); + memShbSpecXcorr_fx[3] = L_shr( temp1_fx, sub( exp, temp1_exp ) ); + memShbSpecXcorr_fx[4] = L_shr( temp2_fx, sub( exp, temp2_exp ) ); + memShbSpecXcorr_fx[5] = L_shr( temp3_fx, sub( exp, temp3_exp ) ); + *memShbSpecXcorr_e = exp; + + move32(); + move32(); + move32(); + move32(); + move16(); + + + IF( temp0_fx != 0 ) + { + Txx1_fx = BASOP_Util_Divide3232_Scale( temp1_fx, temp0_fx, &Txx1_e ); + Txx2_fx = BASOP_Util_Divide3232_Scale( temp2_fx, temp0_fx, &Txx2_e ); + Txx3_fx = BASOP_Util_Divide3232_Scale( temp3_fx, temp0_fx, &Txx3_e ); + } + + T_desired_fx = T_nonref_target_fx; + T_desired_e = T_nonref_target_e; + move32(); + move16(); + + Word16 tmp, tmp1; + exp = BASOP_Util_Add_MantExp( Txx3_fx, Txx3_e, Txx1_fx, Txx1_e, &tmp ); + tmp1 = mult( Txx2_fx, T_desired_fx ); // Txx2_e + T_desired_e + a_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx2_e, T_desired_e ), 1 ), negate( tmp ), exp, &a_fx ); + + exp = BASOP_Util_Add_MantExp( Txx2_fx, Txx2_e, 32767, 1, &tmp ); + tmp1 = mult( Txx1_fx, T_desired_fx ); // Txx1_e + T_desired_e + b_e = BASOP_Util_Add_MantExp( tmp1, sub( add( Txx1_e, T_desired_e ), 1 ), negate( tmp ), exp, &b_fx ); + + c_e = BASOP_Util_Add_MantExp( T_desired_fx, T_desired_e, negate( Txx1_fx ), Txx1_e, &c_fx ); + + u_fx = extract_l( *specMapping_fx ); + + tmp = mult( b_fx, b_fx ); // b_e + b_e; + tmp1 = mult( a_fx, c_fx ); // a_e + c_e + 2 + + exp = BASOP_Util_Add_MantExp( tmp, add( b_e, b_e ), tmp1, add( a_e, add( c_e, 2 ) ), &temp_fx ); + test(); + IF( temp_fx >= 0 && a_fx != 0 ) + { + temp_fx = Sqrt16( temp_fx, &exp ); + exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, temp_fx, exp, &tmp ); + u1_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u1_fx ); + u1_e = add( u1_e, sub( exp, add( a_e, 1 ) ) ); + + exp = BASOP_Util_Add_MantExp( negate( b_fx ), b_e, negate( temp_fx ), exp, &tmp ); + u2_e = BASOP_Util_Divide1616_Scale( tmp, a_fx, &u2_fx ); + u2_e = add( u2_e, sub( exp, add( a_e, 1 ) ) ); + + test(); + IF( ( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( abs_s( u1_fx ) ), u1_e, 1, 31 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( abs_s( u2_fx ) ), u2_e, 1, 31 ) < 0 ) ) + { + IF( ( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( abs_s( u1_fx ) ), u1_e, L_deposit_h( abs_s( u2_fx ) ), u2_e ) < 0 ) ) + { + u_fx = u1_fx; + u_e = u1_e; + } + ELSE + { + u_fx = u2_fx; + u_e = u2_e; + } + move32(); + move16(); + } + ELSE IF( ( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( abs_s( u1_fx ) ), u1_e, 1, 31 ) < 0 ) ) + { + u_fx = u1_fx; + u_e = u1_e; + move32(); + move16(); + } + ELSE IF( ( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( abs_s( u2_fx ) ), u2_e, 1, 31 ) < 0 ) ) + { + u_fx = u2_fx; + u_e = u2_e; + move32(); + move16(); + } + } + + IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( u_fx ), u_e, 0, 0 ) > 0 ) + { + u_fx = 0; + u_e = 0; + move32(); + move16(); + } + + IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( u_fx ), u_e, -1288490188, 0 ) < 0 ) // -0.6 in Q31 + { + u_fx = -1288490188 >> 16; //-0.6 in Q31 -> Q15 + u_e = 0; + move32(); + move16(); + } + + + /* Quantize spec. mapping **/ + Word16 specMapping16; + idx = usquant_fx( shr( u_fx, sub( 0, u_e ) ), &specMapping16, -19660, 6553, 1 << STEREO_ICBWE_SPBITS ); // -0.6 in in Q15 -> -19660, 0.2 in Q15 -> 6553 + *specMapping_fx = L_deposit_h( specMapping16 ); + move32(); + + /* IC-BWE spec mapping */ + deemph_fx_32( 0, shb_synth_nonref_fx, extract_h( *specMapping_fx ), L_FRAME16k, memShbSpecMapping_fx ); + + return idx; +} + +#endif + + /*----------------------------------------------------------------------* * ic_bwe_gsMapping() * @@ -225,6 +466,100 @@ static int16_t ic_bwe_enc_gsMapping( return idx; } +/*----------------------------------------------------------------------* + * ic_bwe_gsMapping() + * + * Encode and apply the gain shape mapping of ref to the non-ref channel + *-----------------------------------------------------------------------*/ + +/*! r: return quant. index value */ +static Word16 ic_bwe_enc_gsMapping_ivas_fx( + const Word32 relG_targ_fx, /* i : gDes, rel gain target */ + Word16 relG_targ_e, + const Word16 *shbSynth_fx, /* i : ref synth signal */ + Word16 shbSynth_e, /* i : ref synth signal */ + Word32 *synthSHB_nonref_fx, /* i : nonref synth signal */ + Word16 *synthSHB_nonref_e, /* i : nonref synth signal */ + Word32 *gsMapping_fx, /* i/o: gs mapping */ + Word16 *gsMapping_e, /* i/o: gs mapping */ + Word32 *memEner_fx, /* */ + Word16 *memEner_e, + const Word16 element_mode /* i : element mode */ +) +{ + Word16 i; + Word16 idx = 0, temp1; + move16(); + Word32 temp1_fx32 = 0, temp2_fx32 = 0; + move32(); + move32(); + Word32 L_mult; + Word16 temp2_fx, gsMapping_fx16; + + /* rel gain of synth signals */ + Word16 exp1 = shbSynth_e, exp2 = *synthSHB_nonref_e, temp1_exp = 0, temp2_exp = 0, exp = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + temp1_fx32 = BASOP_Util_Add_Mant32Exp( temp1_fx32, temp1_exp, L_abs( L_deposit_h( shbSynth_fx[i] ) ), exp1, &temp1_exp ); + temp2_fx32 = BASOP_Util_Add_Mant32Exp( temp2_fx32, temp2_exp, L_abs( synthSHB_nonref_fx[i] ), exp2, &temp2_exp ); + } + + + memEner_fx[0] = temp1_fx32; + memEner_fx[1] = L_shr( temp2_fx32, abs_s( sub( temp1_exp, temp2_exp ) ) ); + move32(); + move32(); + *memEner_e = s_max( temp1_exp, temp2_exp ); + move16(); + + + IF( temp2_fx32 == 0 ) + { + *gsMapping_fx = *gsMapping_fx; + move32(); + } + ELSE + { + L_mult = Mpy_32_32( relG_targ_fx, temp1_fx32 ); // relG_targ_e + temp1_e + temp1 = BASOP_Util_Divide3232_Scale( L_mult, temp1_fx32, &exp ); // exp = exp - ( relG_targ_e + temp1_e + temp2_e ) + exp = add( exp, sub( add( relG_targ_e, temp1_exp ), temp2_exp ) ); + *gsMapping_fx = L_deposit_h( temp1 ); // exp + move32(); + } + + temp2_fx32 = BASOP_Util_Log10( *gsMapping_fx, exp ); /* no impact from prev_gsMapping */ // Q25 + /* quantize the IC-BWE GS mapping*/ + IF( EQ_16( element_mode, IVAS_CPE_TD ) ) + { + temp2_fx = extract_l( L_shr( temp2_fx32, Q10 ) ); // Q15 + gsMapping_fx16 = 0; + move16(); + idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMapping_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); // Q12 + // idx = squant_fx( temp2, gsMapping, icbwe_gsMapping_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); + } + ELSE + { + temp2_fx = extract_l( L_shr( temp2_fx32, Q10 ) ); // Q15 + gsMapping_fx16 = 0; + move16(); + idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMappingDFT_tbl_fx, 1 << STEREO_ICBWE_GSBITS ); // Q12 + } + *gsMapping_fx = L_deposit_h( gsMapping_fx16 ); // Q28 + move32(); + Word16 e; + L_mult = Mult_32_16( *gsMapping_fx, 27213 /*=log2(10)*2^13*/ ); // Q27 + Q13 - Q15 -> Q26 + *gsMapping_fx = BASOP_util_Pow2( L_mult, 5, &e ); + move32(); + + *gsMapping_e = e; // Q31 + move16(); + return idx; +} /*----------------------------------------------------------------------* * icbwe_dft_stereo_param() @@ -326,69 +661,230 @@ static void icbwe_dft_stereo_param( return; } - -/*-------------------------------------------------------------------* - * stereo_icBWE_enc() - * - * Encode the spatial mapping of reference to the non-reference channels in HB - *-------------------------------------------------------------------*/ - -void stereo_icBWE_enc( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const float shb_speech_ref[], /* i : SHB speech ref channel */ - float shb_speech_nonref[], /* i/o: SHB speech non-ref channel */ - const float *voice_factors /* i : voicing factors */ +#ifdef IVAS_FLOAT_FIXED +static void icbwe_dft_stereo_param_ivas_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: */ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i : */ + Encoder_State *st, /* i/o: */ + Word32 *shb_synth_nonref_fx, /* i/o: */ + Word16 shb_synth_nonref_e /* i/o: */ ) { - int16_t i, j, k, nbSubFr; - STEREO_DFT_ENC_DATA_HANDLE hStereoDft; - STEREO_ICBWE_ENC_HANDLE hStereoICBWE; - BSTR_ENC_HANDLE hBstr; - Encoder_State *st; - int16_t spIndx, gsIndx; - float shb_frame_ref[L_LOOK_16k + L_FRAME16k]; - float excSHB_nonref[L_FRAME16k]; - float shb_frame_nonref[L_LOOK_16k + L_FRAME16k]; - float shb_synth_nonref[L_FRAME16k]; + Word16 slopeILD_fx; + Word32 normFac_fx; + Word16 gsIndx, spIndx, gDes_fx; - float nlMixFac[NB_SUBFR16k]; - float temp1, temp2; - float gDes, gTarget; - int16_t nonRefMemLen, refMemLen; + Word32 *nrg_L_fx, *nrg_R_fx, *nrg_DMX_fx; + Word32 sum_nrg_L_fx, sum_nrg_R_fx, sum_nrg_DMX_fx; + const Word32 spec_table_fx[4] = { -1288490189, -858993459, -429496730, 0 }; // Q31 + const Word16 slope_table_fx16[4] = { -17788, -10577, -4822, 0 }; // Q13 - /* initialization */ - hStereoDft = hCPE->hStereoDft; - hStereoICBWE = hCPE->hStereoICBWE; - st = hCPE->hCoreCoder[0]; - hBstr = st->hBstr; + BSTR_ENC_HANDLE hBstr = st->hBstr; + normFac_fx = 1342177280; /* 1000 * (10/((14400+10400)/2 - (6400+10400)/2)) */ // Q29 + move32(); - gTarget = hCPE->hStereoTCA->targetGain; /* i : gain norm for target (or R) channel */ + nrg_L_fx = hStereoDft->nrg_L_fx; + nrg_R_fx = hStereoDft->nrg_R_fx; + nrg_DMX_fx = hStereoDft->nrg_DMX_fx; - nonRefMemLen = L_MEM_RECALC_TBE_16K + L_FILT16k; - if ( st->element_mode == IVAS_CPE_TD ) + hStereoICBWE->mem_nrg_L_fx[0] = nrg_L_fx[0]; // hStereoICBWE->nrg_L_fx_e[0] + hStereoICBWE->mem_nrg_R_fx[0] = nrg_R_fx[0]; // hStereoICBWE->nrg_R_fx_e[0] + hStereoICBWE->mem_nrg_DMX_fx[0] = nrg_DMX_fx[0]; // hStereoICBWE->nrg_DMX_fx_e[0] + hStereoICBWE->mem_nrg_L_fx[1] = L_shr( nrg_L_fx[1], abs_s( sub( hStereoDft->nrg_L_fx_e[0], hStereoDft->nrg_L_fx_e[1] ) ) ); // hStereoICBWE->nrg_L_fx_e[1] + hStereoICBWE->mem_nrg_R_fx[1] = L_shr( nrg_R_fx[1], abs_s( sub( hStereoDft->nrg_R_fx_e[0], hStereoDft->nrg_R_fx_e[1] ) ) ); // hStereoICBWE-> nrg_R_fx_e[1] + hStereoICBWE->mem_nrg_DMX_fx[1] = L_shr( nrg_DMX_fx[1], abs_s( sub( hStereoDft->nrg_DMX_fx_e[0], hStereoDft->nrg_DMX_fx_e[1] ) ) ); // hStereoICBWE->nrg_DMX_fx_e[1] + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + hStereoICBWE->mem_nrg_L_fx_e = s_max( hStereoDft->nrg_L_fx_e[0], hStereoDft->nrg_L_fx_e[1] ); + hStereoICBWE->mem_nrg_R_fx_e = s_max( hStereoDft->nrg_R_fx_e[0], hStereoDft->nrg_R_fx_e[1] ); + hStereoICBWE->mem_nrg_DMX_fx_e = s_max( hStereoDft->nrg_DMX_fx_e[0], hStereoDft->nrg_DMX_fx_e[1] ); + move16(); + move16(); + move16(); + + Word16 sum_nrg_L_e = hStereoICBWE->mem_nrg_L_fx_e, sum_nrg_R_e = hStereoICBWE->mem_nrg_R_fx_e, sum_nrg_DMX_e = hStereoICBWE->mem_nrg_DMX_fx_e; + sum_nrg_L_fx = sum_32_fx( hStereoICBWE->mem_nrg_L_fx, 2, &sum_nrg_L_e ); // hStereoICBWE->mem_nrg_L_fx_e + sum_nrg_R_fx = sum_32_fx( hStereoICBWE->mem_nrg_R_fx, 2, &sum_nrg_R_e ); // hStereoICBWE->mem_nrg_R_fx_e + sum_nrg_DMX_fx = sum_32_fx( hStereoICBWE->mem_nrg_DMX_fx, 2, &sum_nrg_DMX_e ); // hStereoICBWE->mem_nrg_DMX_fx_e + + /* refChanIndex_bwe refinement */ + + test(); + test(); + test(); + test(); + IF( ( ( BASOP_Util_Cmp_Mant32Exp( sum_nrg_R_fx, sum_nrg_R_e, Mpy_32_32( 1374389534, sum_nrg_L_fx ), sum_nrg_L_e ) < 0 ) && EQ_16( hStereoICBWE->refChanIndx_bwe, hStereoICBWE->prev_refChanIndx_bwe ) ) || ( BASOP_Util_Cmp_Mant32Exp( sum_nrg_R_fx, sum_nrg_R_e, Mpy_32_32( 773094113, sum_nrg_L_fx ), sum_nrg_L_e ) < 0 ) ) // 0.64 in Q31 -> 1374389534, 0.36 in Q31 -> 773094113 { - refMemLen = L_MEM_RECALC_TBE_16K + 20; + hStereoICBWE->refChanIndx_bwe = L_CH_INDX; + move16(); } - else if ( st->element_mode == IVAS_CPE_DFT && st->core_brate > SID_2k40 ) + ELSE IF( ( ( BASOP_Util_Cmp_Mant32Exp( sum_nrg_L_fx, sum_nrg_L_e, Mpy_32_32( 1374389534, sum_nrg_R_fx ), sum_nrg_R_e ) < 0 ) && EQ_16( hStereoICBWE->refChanIndx_bwe, hStereoICBWE->prev_refChanIndx_bwe ) ) || ( BASOP_Util_Cmp_Mant32Exp( sum_nrg_L_fx, sum_nrg_L_e, Mpy_32_32( 773094113, sum_nrg_R_fx ), sum_nrg_R_e ) < 0 ) ) // 0.64 in Q31 -> 1374389534, 0.36 in Q31 -> 773094113 { - refMemLen = 20; + hStereoICBWE->refChanIndx_bwe = R_CH_INDX; + move16(); } - else - { - ic_bwe_enc_reset( hStereoICBWE ); - return; - } + /* Initialization of spIndx */ + slopeILD_fx = 0; + move32(); - if ( st->element_mode == IVAS_CPE_DFT ) - { - /* memory resets */ - set_f( hStereoICBWE->mem_shb_speech_nonref, 0, L_LOOK_16k ); - set_f( shb_speech_nonref, 0, L_FRAME16k ); + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); - /* core switching reset */ - if ( st->last_core != ACELP_CORE || st->core != ACELP_CORE || st->bwidth < SWB || st->extl == -1 ) + test(); + test(); + test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) + { + /* Spec Mapping Estimate */ + Word16 tmp1, exp1; + Word32 L_tmp, L_tmp1; + L_tmp = Mpy_32_32( hStereoICBWE->mem_nrg_L_fx[1], hStereoICBWE->mem_nrg_R_fx[0] ); // hStereoICBWE->mem_nrg_L_fx_e[1] + hStereoICBWE->mem_nrg_R_fx_e[1] + L_tmp1 = Mpy_32_32( hStereoICBWE->mem_nrg_R_fx[1], hStereoICBWE->mem_nrg_L_fx[0] ); // hStereoICBWE->mem_nrg_L_fx_e[1] + hStereoICBWE->mem_nrg_R_fx_e[1] + tmp1 = BASOP_Util_Divide3232_Scale( L_tmp, L_tmp1, &exp1 ); + exp1 = add( exp1, sub( add( hStereoICBWE->mem_nrg_L_fx_e, hStereoICBWE->mem_nrg_R_fx_e ), add( hStereoICBWE->mem_nrg_L_fx_e, hStereoICBWE->mem_nrg_R_fx_e ) ) ); + L_tmp = BASOP_Util_Log10( L_deposit_h( tmp1 ), exp1 ); + L_tmp = Mpy_32_32( normFac_fx, L_tmp ); // // Q25 + Q29 - Q31 -> Q23 + slopeILD_fx = extract_l( L_shr( L_tmp, 16 ) ); // Q23 - Q16 -> Q7 + IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) + { + slopeILD_fx = negate( slopeILD_fx ); + } + ELSE + { + slopeILD_fx = slopeILD_fx; + move16(); + } + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); + IF( Mpy_32_32( spec_table_fx[spIndx], hStereoICBWE->prevSpecMapping_fx ) < 0 ) + { + slopeILD_fx = 0; + move32(); + spIndx = squant_fx( slopeILD_fx, &slopeILD_fx, slope_table_fx16, 1 << STEREO_ICBWE_SPBITS_DFT ); + } + + hStereoICBWE->prevSpecMapping_fx = spec_table_fx[spIndx]; // q31 + /* ic bwe spec mapping application */ + deemph_fx_32( 0, shb_synth_nonref_fx, extract_l( L_shr( hStereoICBWE->prevSpecMapping_fx, 16 ) ), L_FRAME16k, &hStereoICBWE->memShbSpecMapping_fx ); // shb_synth_nonref_e + } + ELSE + { + hStereoICBWE->memShbSpecMapping_fx = 0; + hStereoICBWE->prevSpecMapping_fx = 0; + move32(); + move32(); + } + + /* gsMapping estimate */ + + Word16 exp; + IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) + { + gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_R_fx, sum_nrg_DMX_fx, &exp ); + exp = add( exp, sub( sum_nrg_R_e, sum_nrg_DMX_e ) ); + } + ELSE + { + gDes_fx = BASOP_Util_Divide3232_Scale( sum_nrg_L_fx, sum_nrg_DMX_fx, &exp ); + exp = add( exp, sub( sum_nrg_L_e, sum_nrg_DMX_e ) ); + } + + gDes_fx = Sqrt16( gDes_fx, &exp ); + Word16 exp1 = hStereoICBWE->gDes_pastFrame_e, exp2, tmp; + Word32 tmp321 = 0, tmp322 = 0; + move32(); + move32(); + /* Geometric Mean */ + tmp321 = Sqrt32( hStereoICBWE->gDes_pastFrame_fx, &exp1 ); // exp1 + exp2 = exp; + move16(); + tmp = Sqrt16( gDes_fx, &exp2 ); + tmp322 = Mpy_32_32( tmp321, L_deposit_h( tmp ) ); // exp1 + exp2 + hStereoICBWE->gDes_pastFrame_fx = tmp322; + hStereoICBWE->gDes_pastFrame_e = add( exp1, exp2 ); + move32(); + move16(); + + gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); + + hStereoICBWE->gDes_pastFrame_fx = L_deposit_h( gDes_fx ); + hStereoICBWE->gDes_pastFrame_e = exp; + move32(); + move16(); + + push_indice( hBstr, IND_STEREO_ICBWE_REF, hStereoICBWE->refChanIndx_bwe, STEREO_ICBWE_REFBITS ); + IF( EQ_16( st->flag_ACELP16k, 1 ) ) + { + push_indice( hBstr, IND_STEREO_ICBWE_SP, spIndx, STEREO_ICBWE_SPBITS_DFT ); + } + + /* IC BWE GS mapping */ + push_indice( hBstr, IND_STEREO_ICBWE_GS, gsIndx, STEREO_ICBWE_GSBITS_DFT ); + + return; +} +#endif + +void stereo_icBWE_enc( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const float shb_speech_ref[], /* i : SHB speech ref channel */ + float shb_speech_nonref[], /* i/o: SHB speech non-ref channel */ + const float *voice_factors /* i : voicing factors */ +) +{ + int16_t i, j, k, nbSubFr; + STEREO_DFT_ENC_DATA_HANDLE hStereoDft; + STEREO_ICBWE_ENC_HANDLE hStereoICBWE; + BSTR_ENC_HANDLE hBstr; + Encoder_State *st; + int16_t spIndx, gsIndx; + float shb_frame_ref[L_LOOK_16k + L_FRAME16k]; + float excSHB_nonref[L_FRAME16k]; + float shb_frame_nonref[L_LOOK_16k + L_FRAME16k]; + float shb_synth_nonref[L_FRAME16k]; + + float nlMixFac[NB_SUBFR16k]; + float temp1, temp2; + float gDes, gTarget; + int16_t nonRefMemLen, refMemLen; + + /* initialization */ + hStereoDft = hCPE->hStereoDft; + hStereoICBWE = hCPE->hStereoICBWE; + st = hCPE->hCoreCoder[0]; + hBstr = st->hBstr; + + gTarget = hCPE->hStereoTCA->targetGain; /* i : gain norm for target (or R) channel */ + + nonRefMemLen = L_MEM_RECALC_TBE_16K + L_FILT16k; + + if ( st->element_mode == IVAS_CPE_TD ) + { + refMemLen = L_MEM_RECALC_TBE_16K + 20; + } + else if ( st->element_mode == IVAS_CPE_DFT && st->core_brate > SID_2k40 ) + { + refMemLen = 20; + } + else + { + ic_bwe_enc_reset( hStereoICBWE ); + + return; + } + + if ( st->element_mode == IVAS_CPE_DFT ) + { + /* memory resets */ + set_f( hStereoICBWE->mem_shb_speech_nonref, 0, L_LOOK_16k ); + set_f( shb_speech_nonref, 0, L_FRAME16k ); + + /* core switching reset */ + if ( st->last_core != ACELP_CORE || st->core != ACELP_CORE || st->bwidth < SWB || st->extl == -1 ) { ic_bwe_enc_reset( hStereoICBWE ); if ( st->core != ACELP_CORE || st->bwidth < SWB || st->input_Fs < 32000 || st->extl == -1 ) @@ -570,6 +1066,480 @@ void stereo_icBWE_enc( return; } + +void stereo_icBWE_enc_ivas_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel */ + const Word16 shb_speech_ref_e, /* i : SHB speech ref channel */ + Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel */ + Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ + const Word32 *voice_factors_fx /* i : voicing factors Q31 */ +) +{ + Word16 i, j, k, nbSubFr; + STEREO_DFT_ENC_DATA_HANDLE hStereoDft; + STEREO_ICBWE_ENC_HANDLE hStereoICBWE; + BSTR_ENC_HANDLE hBstr; + Encoder_State *st; + Word16 spIndx, gsIndx; + + Word16 nonRefMemLen, refMemLen; + Word16 shb_synth_nonref_e = 0, max_e; + move16(); + + Word32 nlMixFac_fx[NB_SUBFR16k]; + Word32 excSHB_nonref_fx[L_FRAME16k]; + set32_fx( excSHB_nonref_fx, 0, L_FRAME16k ); + Word32 shb_synth_nonref_fx[L_FRAME16k]; + Word32 shb_frame_nonref_fx[L_LOOK_16k + L_FRAME16k], gTarget_fx; + Word32 shb_frame_ref_fx[L_LOOK_16k + L_FRAME16k]; + Word32 gDes_fx; + Word32 temp1_fx, temp2_fx; + Word16 temp1_e, temp2_e, shb_frame_ref_e, shb_frame_nonref_e, gDes_e, tmp, exp; + + + /* initialization */ + hStereoDft = hCPE->hStereoDft; + hStereoICBWE = hCPE->hStereoICBWE; + st = hCPE->hCoreCoder[0]; + hBstr = st->hBstr; + + gTarget_fx = hCPE->hStereoTCA->targetGain_fx; /* i : gain norm for target (or R) channel */ // Q29 + move32(); + + nonRefMemLen = L_MEM_RECALC_TBE_16K + L_FILT16k; + move16(); + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + refMemLen = L_MEM_RECALC_TBE_16K + 20; + move16(); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GT_32( st->core_brate, SID_2k40 ) ) + { + refMemLen = 20; + move16(); + } + ELSE + { + ic_bwe_enc_reset_fx( hStereoICBWE ); + return; + } + + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + /* memory resets */ + set16_fx( hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k ); + set32_fx( shb_speech_nonref_fx, 0, L_FRAME16k ); + + /* core switching reset */ + test(); + test(); + test(); + IF( st->last_core != ACELP_CORE || st->core != ACELP_CORE || LT_16( st->bwidth, SWB ) || EQ_16( st->extl, -1 ) ) + { + + ic_bwe_enc_reset_fx( hStereoICBWE ); + test(); + test(); + test(); + IF( st->core != ACELP_CORE || LT_16( st->bwidth, SWB ) || LT_32( st->input_Fs, 32000 ) || EQ_16( st->extl, -1 ) ) + { + return; + } + } + + set32_fx( hStereoICBWE->memShbSpecXcorr_fx, 0, 6 ); + + hStereoICBWE->prevRefEner_fx = 0; + hStereoICBWE->prevNonRefEner_fx = 0; + move32(); + move32(); + + /* SHB frame buffer offsets for TBE processing << re-adjust check >>*/ + + max_e = s_max( hStereoICBWE->mem_shb_speech_ref_e, shb_speech_ref_e ); + Copy_Scale_sig( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) ); // mem_shb_speech_ref_e + + set32_fx( shb_frame_ref_fx, 0, L_LOOK_16k + L_FRAME16k ); + Copy_Scale_sig_16_32( hStereoICBWE->mem_shb_speech_ref_fx, shb_frame_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) + Q16 ); // mem_shb_speech_ref_e + + hStereoICBWE->mem_shb_speech_ref_e = max_e; + shb_frame_ref_e = max_e; + move16(); + move16(); + /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ + + shb_synth_nonref_e = max_e; + move16(); + + Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); + Copy_Scale_sig_32_16( shb_frame_ref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) - Q16 ); // mem_shb_speech_ref_e + + test(); + test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) + { + Copy32( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); // Q31 + /*if( gDes < 0.5f || gDes > 2.0f )*/ + test(); + IF( LT_32( gTarget_fx, 268435456 ) || GT_32( gTarget_fx, 1073741824 ) ) // 0.5 in Q29 or 2.0 in Q29 + { + v_multc_fixed( voice_factors_fx, 1073741824, nlMixFac_fx, NB_SUBFR16k ); // Q31, 0.5 in Q31 -> 1073741824 + } + + IF( st->flag_ACELP16k == 0 ) + { + nbSubFr = NB_SUBFR; + move16(); + } + ELSE + { + nbSubFr = NB_SUBFR16k; + move16(); + } + + Word16 exp_buf[L_FRAME16k]; + set16_fx( exp_buf, 0, L_FRAME16k ); + FOR( ( i = 0, k = 0 ); i < nbSubFr; i++ ) + { + test(); + IF( EQ_16( st->coder_type, UNVOICED ) || EQ_16( hStereoICBWE->MSFlag, 1 ) ) + { + temp1_fx = 0; + temp1_e = 0; + temp2_fx = ONE_IN_Q31; + temp2_e = 0; + move16(); + move32(); + move16(); + move32(); + } + ELSE + { + temp1_e = 0, temp2_e = 0; + move16(); + move32(); + temp1_fx = Sqrt32( nlMixFac_fx[i], &temp1_e ); + temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); + } + + tmp = BASOP_Util_Divide1616_Scale( L_FRAME16k, nbSubFr, &exp ); + tmp = shr( tmp, sub( Q15, exp ) ); + FOR( j = 0; j < tmp; ( j++, k++ ) ) + { + excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), add( temp1_e, hStereoICBWE->nlExc16k_e ), Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), add( temp2_e, hStereoICBWE->mixExc16k_e ), &exp_buf[k] ) ); + move32(); + } + } + + max_e = exp_buf[0]; + move16(); + FOR( j = 0; j < L_FRAME16k; j++ ) + { + IF( GT_16( exp_buf[j], max_e ) ) + { + max_e = exp_buf[j]; + move16(); + } + } + + FOR( j = 0; j < L_FRAME16k; j++ ) + { + excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); + move32(); + } + /* LP synthesis */ + Word16 tmp_e = s_max( hCPE->hStereoICBWE->lpSHBRef_e, max_e ); + + Word32 lpSHBRef_fx32[LPC_SHB_ORDER + 1]; + + Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); + Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); + // set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); + E_UTIL_synthesis_fx( 0, lpSHBRef_fx32, excSHB_nonref_fx, shb_synth_nonref_fx, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); + + shb_synth_nonref_e = tmp_e; + hStereoICBWE->mem_lpc_shbsynth_nonref_e = tmp_e; + move16(); + move16(); + } + ELSE + { + Copy_Scale_sig_32_16( shb_frame_ref_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k, -16 ); // max_e + hStereoICBWE->shbSynthRef_e = shb_frame_ref_e; + move16(); + Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); // max_e + shb_synth_nonref_e = shb_frame_ref_e; + move16(); + set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, 10 ); + } + + icbwe_dft_stereo_param_ivas_fx( hStereoICBWE, hStereoDft, st, shb_synth_nonref_fx, shb_synth_nonref_e ); + hStereoICBWE->memShbSpecMapping_e = shb_synth_nonref_e; + move16(); + } + ELSE + { + + max_e = s_max( hStereoICBWE->mem_shb_speech_nonref_e, shb_speech_nonref_e ); + Copy_Scale_sig( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) ); // mem_shb_speech_ref_e + + set32_fx( shb_frame_ref_fx, 0, L_LOOK_16k + L_FRAME16k ); + Copy_Scale_sig_16_32( hStereoICBWE->mem_shb_speech_ref_fx, shb_frame_ref_fx, L_LOOK_16k, add( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e + + hStereoICBWE->mem_shb_speech_ref_e = max_e; + shb_frame_ref_e = max_e; + move16(); + move16(); + /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ + + Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); + Copy_Scale_sig_32_16( shb_frame_ref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e + + set32_fx( shb_frame_nonref_fx, 0, L_LOOK_16k + L_FRAME16k ); + + max_e = s_max( hStereoICBWE->mem_shb_speech_nonref_e, shb_speech_nonref_e ); + Copy_Scale_sig( hStereoICBWE->mem_shb_speech_nonref_fx, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_nonref_e ) ) ); // mem_shb_speech_ref_e + + Copy_Scale_sig_16_32( hStereoICBWE->mem_shb_speech_nonref_fx, shb_frame_nonref_fx, L_LOOK_16k, add( negate( sub( max_e, hStereoICBWE->mem_shb_speech_nonref_e ) ), Q16 ) ); // mem_shb_speech_ref_e + + hStereoICBWE->mem_shb_speech_nonref_e = max_e; + shb_frame_nonref_e = max_e; + move16(); + move16(); + /* shb_frame_ref_ICBWE @ (8.75 - shb_speech_delay (=1.25) ms) after shb_speech */ + + Copy_Scale_sig32( shb_speech_nonref_fx, shb_frame_nonref_fx + L_LOOK_16k - nonRefMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_nonref_e ) ) ); + Copy_Scale_sig_32_16( shb_frame_nonref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_nonref_fx, L_LOOK_16k, sub( negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ), Q16 ) ); // mem_shb_speech_ref_e + + + /* core switching reset */ + test(); + test(); + test(); + test(); + IF( st->last_core != ACELP_CORE || st->core != ACELP_CORE || LT_16( st->bwidth, SWB ) || NE_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->extl, -1 ) ) + { + ic_bwe_enc_reset_fx( hStereoICBWE ); + test(); + test(); + test(); + test(); + IF( st->core != ACELP_CORE || LT_16( st->bwidth, SWB ) || LT_32( st->input_Fs, 32000 ) || NE_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->extl, -1 ) ) + { + return; + } + } + + /* resets done here. Need to move them to a separate function */ + test(); + test(); + IF( ( NE_16( hStereoICBWE->prev_refChanIndx_bwe, hStereoICBWE->refChanIndx_bwe ) ) || NE_16( st->last_extl, st->extl ) || NE_16( st->flag_ACELP16k, 1 ) ) + { + hStereoICBWE->prevSpecMapping_fx = 0; + hStereoICBWE->memShbSpecMapping_fx = 0; + move32(); + move32(); + set32_fx( hStereoICBWE->memShbSpecXcorr_fx, 0, 6 ); + } + + /* voice fac adjustment based on IC intensities */ + /*temp2 = (float)sqrt(sum2_f(shb_frame_ref + L_LOOK_16k - refMemLen, L_FRAME16k));*/ + + Word32 L_tmp, L_tmp1; + temp2_fx = hStereoICBWE->icbweRefEner_fx; + temp2_e = hStereoICBWE->icbweRefEner_e; + temp1_e = shb_frame_nonref_e; + move16(); + move32(); + move32(); + L_tmp = sum2_32_fx( shb_frame_nonref_fx + sub( L_LOOK_16k, refMemLen ), L_FRAME16k, &temp1_e ); + temp1_fx = Sqrt32( L_tmp, &temp1_e ); + + /*temp1 = 0.8f*hStereoICBWE->prevNonRefEner + 0.2f*temp1;*/ + /*temp2 = 0.8f*hStereoICBWE->prevRefEner + 0.2f*temp2;*/ + + IF( temp2_fx == 0 ) + { + gDes_fx = 1073741824; + gDes_e = 1; + move16(); + move32(); + } + ELSE + { + tmp = BASOP_Util_Divide3232_Scale( temp1_fx, temp2_fx, &exp ); + gDes_fx = L_deposit_h( tmp ); // exp + gDes_e = exp; + move16(); + } + tmp = gDes_e; + exp = hStereoICBWE->gDes_pastFrame_e; + move16(); + move16(); + L_tmp = Sqrt32( gDes_fx, &tmp ); + L_tmp1 = Sqrt32( hStereoICBWE->gDes_pastFrame_fx, &exp ); + + hStereoICBWE->gDes_pastFrame_fx = Mpy_32_32( L_tmp, L_tmp1 ); // tmp + exp + hStereoICBWE->gDes_pastFrame_e = add( tmp, exp ); + move32(); + move16(); + + hStereoICBWE->prevRefEner_fx = temp2_fx; + hStereoICBWE->prevRefEner_e = temp2_e; + hStereoICBWE->prevNonRefEner_fx = temp1_fx; + hStereoICBWE->prevNonRefEner_e = temp1_e; + move32(); + move32(); + move16(); + move16(); + + test(); + test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) + { + Copy32( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); // Q31 + + test(); + IF( LT_32( gTarget_fx, 268435456 ) || GT_32( gTarget_fx, 1073741824 ) ) // + { + v_multc_fixed( voice_factors_fx, 1073741824, nlMixFac_fx, NB_SUBFR16k ); + } + + IF( st->flag_ACELP16k == 0 ) + { + nbSubFr = NB_SUBFR; + move16(); + } + ELSE + { + nbSubFr = NB_SUBFR16k; + move16(); + } + + Word16 exp_buf[L_FRAME16k]; + set16_fx( exp_buf, 0, L_FRAME16k ); + FOR( ( i = 0, k = 0 ); i < nbSubFr; i++ ) + { + test(); + IF( EQ_16( st->coder_type, UNVOICED ) || EQ_16( hStereoICBWE->MSFlag, 1 ) ) + { + + temp1_fx = 0; + temp1_e = 0; + temp2_fx = ONE_IN_Q31; + temp2_e = 0; + move32(); + move32(); + move16(); + move16(); + } + ELSE + { + temp1_e = 0, temp2_e = 0; + temp1_fx = Sqrt32( nlMixFac_fx[i], &temp1_e ); + temp2_fx = Sqrt32( L_sub( ONE_IN_Q31, nlMixFac_fx[i] ), &temp2_e ); + move32(); + move16(); + } + + FOR( j = 0; j < ( L_FRAME16k / nbSubFr ); ( j++, k++ ) ) + { + excSHB_nonref_fx[k] = extract_l( BASOP_Util_Add_Mant32Exp( Mpy_32_32( temp1_fx, hStereoICBWE->nlExc16k_fx[k] ), temp1_e + hStereoICBWE->nlExc16k_e, Mpy_32_32( temp2_fx, hStereoICBWE->mixExc16k_fx[k] ), temp2_e + hStereoICBWE->mixExc16k_e, &exp_buf[k] ) ); + move32(); + } + } + + max_e = exp_buf[0]; + move16(); + FOR( j = 0; j < L_FRAME16k; j++ ) + { + IF( GT_16( exp_buf[j], max_e ) ) + { + max_e = exp_buf[j]; + move16(); + } + } + + FOR( j = 0; j < L_FRAME16k; j++ ) + { + excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); + move32(); + } + /* LP synthesis */ + + Word16 tmp_e = s_max( hCPE->hStereoICBWE->lpSHBRef_e, max_e ); + + Word32 lpSHBRef_fx32[LPC_SHB_ORDER + 1]; + + Copy_Scale_sig32( hCPE->hStereoICBWE->lpSHBRef_fx, lpSHBRef_fx32, LPC_SHB_ORDER + 1, negate( sub( tmp_e, hCPE->hStereoICBWE->lpSHBRef_e ) ) ); + Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, negate( sub( tmp_e, max_e ) ) ); + + E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); + shb_synth_nonref_e = sub( 31, tmp_e ); + hStereoICBWE->mem_lpc_shbsynth_nonref_e = shb_synth_nonref_e; + move16(); + } + ELSE + { + Copy_Scale_sig_32_16( shb_frame_ref_fx, hStereoICBWE->shbSynthRef_fx, L_FRAME16k, -16 ); // max_e + hStereoICBWE->shbSynthRef_e = shb_frame_ref_e; + move16(); + Copy32( shb_frame_ref_fx, shb_synth_nonref_fx, L_FRAME16k ); + shb_synth_nonref_e = shb_frame_ref_e; + move16(); + set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, 10 ); + } + + test(); + test(); + test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) + { + /* IC BWE spectral mapping */ + spIndx = ic_bwe_enc_specMapping_ivas_fx( shb_frame_nonref_fx, shb_frame_nonref_e, shb_synth_nonref_fx, shb_synth_nonref_e, &( hStereoICBWE->prevSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_fx ), hStereoICBWE->memShbSpecXcorr_fx, &( hStereoICBWE->memShbSpecXcorr_e ) ); + } + ELSE + { + spIndx = 3; + hStereoICBWE->prevSpecMapping_fx = 0; + move16(); + move32(); + } + + push_indice( hBstr, IND_STEREO_ICBWE_REF, hStereoICBWE->refChanIndx_bwe, STEREO_ICBWE_REFBITS ); + + IF( EQ_16( st->flag_ACELP16k, 1 ) ) + { + push_indice( hBstr, IND_STEREO_ICBWE_SP, spIndx, STEREO_ICBWE_SPBITS ); + } + ELSE + { + hStereoICBWE->prevSpecMapping_fx = -1288490188; // -0.6 in Q31 + move32(); + } + + /* IC BWE GS mapping */ + + gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); + + hStereoICBWE->gDes_pastFrame_fx = gDes_fx; + hStereoICBWE->gDes_pastFrame_e = gDes_e; + move32(); + move16(); + push_indice( hBstr, IND_STEREO_ICBWE_GS, gsIndx, STEREO_ICBWE_GSBITS ); + } + + /* IC-BWE updates */ + hStereoICBWE->prev_refChanIndx_bwe = hStereoICBWE->refChanIndx_bwe; + move16(); + + return; +} + + /*-------------------------------------------------------------------* * stereo_icBWE_init_enc() * @@ -627,6 +1597,23 @@ void stereo_icBWE_init_enc( hStereoICBWE->MSFlag = 0; +#ifdef IVAS_FLOAT_FIXED + set32_fx( hStereoICBWE->mem_nrg_L_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_R_fx, 0, 2 ); + set32_fx( hStereoICBWE->mem_nrg_DMX_fx, 0, 2 ); + hStereoICBWE->gDes_pastFrame_fx = MAX_32; // Q31 + hStereoICBWE->gDes_pastFrame_e = 0; // Q31 + hStereoICBWE->icbweRefEner_fx = 0; + hStereoICBWE->prevgsMapping_fx = MAX_32; + hStereoICBWE->prevgsMapping_e = 0; + move32(); + move32(); + move32(); + move16(); + move16(); + +#endif + return; } @@ -641,7 +1628,7 @@ void stereo_icBWE_init_enc_fx( set16_fx( hStereoICBWE->mem_shb_speech_ref_fx, 0, L_LOOK_16k ); /* SHB non-ref channel */ - set32_fx( hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k ); + set16_fx( hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k ); /* unscaled & scaled SHB synthesis memory */ set32_fx( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER ); diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 4345236c9a7a0a6fc5a813980253d48613d0b69d..c745013c2a1af347c6af52d3ac2fbf837f1851d8 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -111,20 +111,28 @@ #define B_ADAP 0.16f #endif -#define PC_LIMIT 64 -#define RATIO_PG_HR 0.94f -#define RATIO_PG 0.92f -#define PG2ND 3.0f -#define EUCLDST 0.04f -#define RATIO_PG2 0.86f -#define PG2ND2 3.0f -#define EUCLDST2 0.08f +#define PC_LIMIT 64 +#define RATIO_PG_HR 0.94f +#define RATIO_PG_HR_FX 2018634629 // 0.94f in Q31 +#define RATIO_PG 0.92f +#define RATIO_PG_FX 1975684956 // 0.92f in Q31 +#define PG2ND 3.0f +#define PG2ND_FX 6291456 // 3.0f in Q21 +#define EUCLDST 0.04f +#define EUCLDST_FX 85899346 // 0.04f in Q31 +#define RATIO_PG2 0.86f +#define RATIO_PG2_FX 1846835937 // 0.86f in Q31 +#define PG2ND2 3.0f +#define PG2ND2_FX 6291456 // 3.0f in Q21 +#define EUCLDST2 0.08f +#define EUCLDST2_FX 171798692 // 0.08f in Q31 #define RMS_THR 100 #ifdef IVAS_FLOAT_FIXED #define RMS_THR_Q16 ( 6553600 ) #endif -#define RATIO_PG_LRTD 0.96f +#define RATIO_PG_LRTD 0.96f +#define RATIO_PG_LRTD_FX 2061584302 // 0.96f in Q31 #define IVAS_BRATE_OMASA_STEREO_SW_THR 15000 @@ -2805,7 +2813,129 @@ static int16_t stereo_tdm_ener_analysis_SM( * * Perform the comparison of the 2 sets of LP coefficients *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*! r: replication decision; 1 = Use old LP */ +Word16 tdm_lp_comparison_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + Encoder_State *st, /* i/o: Encoder structure */ + Word32 *speech_buff, /* i : Current speech frame Q_speech */ + const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ + const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ + const Word16 m, /* i : filter length */ + const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ + const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 L_frame, /* i : frame length */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ + Word16 Q_speech ) +{ + Word32 ener_sig_fx, pred_gain_reuse_PCh_fx, log10_fx, predgain_SCh_fx; + Word16 LP_mode; + Word32 dist_fx, ftmp_fx; + Word16 i; + Word32 res_fx[L_FRAME16k]; + Word16 gb1 = find_guarded_bits_fx( M ); + + Word32 *speech_fx = &speech_buff[M]; + residu_ivas_fx( A_SCh_fx, Q12, m, speech_fx, res_fx, L_frame ); + /* Find prediction gain for current LP filter */ + // residu( A_SCh, m, speech, res, L_frame ); + + Word16 gb = find_guarded_bits_fx( L_frame ); + scale_sig32( speech_buff, L_FRAME + M, gb1 ); + Word16 exp = sub( 31, Q_speech ); + Word32 sum2_value = sum2_32_exp_fx( speech_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb + sum2_value = L_add( sum2_value, L_shl( 328, sub( sub( 31, exp ), 15 ) ) ); + Word32 temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); + ener_sig_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + // ener_sig = log10f( sum2_f( speech, L_frame ) + 0.01f ); + exp = sub( 31, sub( Q_speech, gb1 ) ); + sum2_value = sum2_32_exp_fx( res_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb + sum2_value = L_add( sum2_value, L_shl( 328, sub( sub( 31, exp ), 15 ) ) ); + temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); + log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + predgain_SCh_fx = Mpy_32_32( L_sub( ener_sig_fx, log10_fx ), 1342177280 ); // Q27+Q25-31 = Q21 + // pred_gain_reuse_PCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); + // predgain_SCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); + + /* Find prediction gain when resuing the Primary Channel LP filter */ + // residu( A_PCh, m, speech, res, L_frame ); + scale_sig32( speech_buff, L_FRAME + M, negate( gb1 ) ); + residu_ivas_fx( A_PCh_fx, Q12, m, speech_fx, res_fx, L_frame ); + exp = sub( 31, sub( Q_speech, gb1 ) ); + sum2_value = sum2_32_exp_fx( res_fx, L_frame, &exp, gb ); // 2*Q_speech -31-gb + sum2_value = L_add( sum2_value, L_shl( 328, sub( sub( 31, exp ), 15 ) ) ); + temp32_log = L_add( BASOP_Util_Log2( sum2_value ), L_shl( sub( Q31, sub( 31, exp ) ), Q25 ) ); + log10_fx = Mpy_32_32( temp32_log, 646456623 ); // Q25 + + pred_gain_reuse_PCh_fx = Mpy_32_32( L_sub( ener_sig_fx, log10_fx ), 1342177280 ); // Q27+Q25-31 = Q21 + // pred_gain_reuse_PCh = 10.0f * ( ener_sig - log10f( sum2_f( res, L_frame ) + 0.01f ) ); + + /* Find Euclidian distance between the 2 filters */ + dist_fx = 0; + move16(); + gb = find_guarded_bits_fx( M ); + FOR( i = 0; i < m; i++ ) + { + // ftmp = isp_SCh[i] - isp_PCh[i]; + ftmp_fx = L_sub( isp_SCh_fx[i], isp_PCh_fx[i] ); + // dist += ftmp * ftmp; + dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( ftmp_fx, ftmp_fx ), gb ) ); // Q31-gb + } + // ener_sig *= 10.0f; + ener_sig_fx = Mpy_32_32( ener_sig_fx, 1342177280 ); // Q27+Q25-31 = Q21 + + /* Verification of the filters similartiies and prediction gain obtained for each channel */ + /* Threshold are more relax if alpha is close to 0.5 (Valid if ICA is used ) */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb ) ) ) /* Prediction gain are close & Euclidian dist is small */ + || ( LT_32( predgain_SCh_fx, PG2ND_FX ) && LT_32( dist_fx, L_shr( EUCLDST2_FX, gb ) ) ) ) /* Prediction gain if the secondary channel is low & Euclidian dist is not too large */ + || ( GE_16( hStereoTD->tdm_last_ratio_idx, ( LRTD_STEREO_MID_IS_PRIM - 2 ) ) && LE_16( hStereoTD->tdm_last_ratio_idx, ( LRTD_STEREO_MID_IS_PRIM + 2 ) ) && /* ratio between 0.4 and 0.6 */ + ( ( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG2_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST2_FX, gb ) ) ) || LT_32( predgain_SCh_fx, PG2ND2_FX ) ) ) /* Prediction gain are not far & Euclidian dist is not too large or Prediction gain if the secondary channel is low */ + || LE_32( ener_sig_fx, 62914560 ) // 30.0f in Q21 + /* secondary channel has low energy */ + ) + { + LP_mode = 1; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + + if ( ( GE_32( element_brate_wo_meta, IVAS_48k ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb ) ) ) ) || + ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && LT_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_HR_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, add( gb, 1 ) ) ) ) ) || + ( EQ_16( hStereoClassif->lrtd_mode, 1 ) && GE_32( element_brate_wo_meta, IVAS_16k4 ) && !( GE_32( pred_gain_reuse_PCh_fx, Mpy_32_32( RATIO_PG_LRTD_FX, predgain_SCh_fx ) ) && LT_32( dist_fx, L_shr( EUCLDST_FX, gb + 2 ) ) ) ) || st->tc_cnt > 0 ) + { + LP_mode = 0; + move16(); + } + } + ELSE + { + /* Prediction or and filters are too different -> quantize the difference*/ + LP_mode = 0; + move16(); + } + + return LP_mode; +} +#else /*! r: replication decision; 1 = Use old LP */ int16_t tdm_lp_comparison( STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ @@ -2826,7 +2956,6 @@ int16_t tdm_lp_comparison( int16_t LP_mode; float dist, ftmp; int16_t i; - /* Find prediction gain for current LP filter */ residu( A_SCh, m, speech, res, L_frame ); ener_sig = log10f( sum2_f( speech, L_frame ) + 0.01f ); @@ -2871,7 +3000,7 @@ int16_t tdm_lp_comparison( return LP_mode; } - +#endif #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_ol_pitch_comparison() diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 1ff09e865d8acbb31c82c7caa7adebed559bf5c6..a701abb6fe3cff4a6176fe99e232b58a525f23d0 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -46,6 +46,7 @@ #include "prot_fx_enc.h" #include "ivas_prot_fx.h" #include "prot_fx.h" +#include "ivas_rom_com_fx.h" #endif @@ -630,7 +631,7 @@ void tdm_configure_enc_fx( test(); test(); test(); - IF( hCPE->hStereoClassif->lrtd_mode == 0 && ( ( sts[1]->hSpMusClas->tdm_lt_Etot < 0 && hCPE->hCoreCoder[1]->vad_flag == 0 ) /* very clean signal */ + IF( hCPE->hStereoClassif->lrtd_mode == 0 && ( ( sts[1]->hSpMusClas->tdm_lt_Etot_fx < 0 && hCPE->hCoreCoder[1]->vad_flag == 0 ) /* very clean signal */ || ( hCPE->hCoreCoder[1]->vad_flag == 0 || ( LT_16( Etot_last_fx[1], 7680 /*30.0f*/ ) && GT_16( sub( sts[0]->hSpMusClas->tdm_lt_Etot_fx, sts[1]->hSpMusClas->tdm_lt_Etot_fx ), 6656 /*26.0f*/ ) ) ) ) ) { sts[1]->coder_type = INACTIVE; @@ -1317,6 +1318,33 @@ static void tdm_downmix_plain( return; } + +#ifdef IVAS_FLOAT_FIXED +static void tdm_downmix_plain_ivas_fx( + Word16 FR_Y_fx[], /*Qx*/ + Word16 LR_X_fx[], /*Qx*/ + const Word16 Left_in_fx[], /*Qx*/ + const Word16 Right_in_fx[], /*Qx*/ + const Word32 ratio_L_fx, /* Q31 */ + const Word32 One_m_Ratio_fx, /* Q31 */ + const Word16 start_index, /* i : start index */ + const Word16 end_index /* i : end index */ +) +{ + Word16 i; + + FOR( i = start_index; i < end_index; i++ ) + { + FR_Y_fx[i] = add( mult( Right_in_fx[i], extract_h( One_m_Ratio_fx ) ), mult( Left_in_fx[i], extract_h( ratio_L_fx ) ) ); + LR_X_fx[i] = sub( mult( Left_in_fx[i], extract_h( One_m_Ratio_fx ) ), mult( Right_in_fx[i], extract_h( ratio_L_fx ) ) ); + move16(); + move16(); + } + + return; +} +#endif + /*-------------------------------------------------------------------* * Function tdm_downmix_fade() * @@ -1355,6 +1383,49 @@ static void tdm_downmix_fade( return; } +#ifdef IVAS_FLOAT_FIXED +static void tdm_downmix_fade_ivas_fx( + Word16 FR_Y_fx[], /* o : primary channel Qx */ + Word16 LR_X_fx[], /* o : secondary channel Qx */ + const Word16 Left_in_fx[], /* i : Left channel Qx */ + const Word16 Right_in_fx[], /* i : Right channel Qx */ + const Word32 ratio_L_fx, /* i : mixing ratio Q31 */ + const Word32 One_m_Ratio_fx, /* i : 1 - mixing ratio Q31 */ + const Word32 OldRatio_L_fx, /* i : old mixing ratio Q31 */ + const Word32 One_m_OldRatio_fx, /* i : 1 - old mixing ratio Q31 */ + const Word16 start_index, /* i : start index */ + const Word16 end_index /* i : end index */ +) +{ + Word16 i; + Word16 step_fx, fade_in_fx, fade_out_fx, scale; + + step_fx = BASOP_Util_Divide1616_Scale( 1, sub( end_index, start_index ), &scale ); + step_fx = shl( step_fx, scale ); // Q15 + fade_out_fx = 32767; + fade_in_fx = 0; + move16(); + move16(); + + FOR( i = start_index; i < end_index; i++ ) + { + FR_Y_fx[i] = add( mult( add( mult( Right_in_fx[i], extract_l( One_m_OldRatio_fx ) ), mult( Left_in_fx[i], extract_l( OldRatio_L_fx ) ) ), fade_out_fx ), mult( add( mult( Right_in_fx[i], extract_l( One_m_Ratio_fx ) ), mult( Left_in_fx[i], extract_l( ratio_L_fx ) ) ), fade_in_fx ) ); // Qx + LR_X_fx[i] = add( mult( sub( mult( Left_in_fx[i], extract_l( One_m_OldRatio_fx ) ), mult( Right_in_fx[i], extract_l( OldRatio_L_fx ) ) ), fade_out_fx ), + mult( sub( mult( Left_in_fx[i], extract_l( One_m_Ratio_fx ) ), mult( Right_in_fx[i], extract_l( ratio_L_fx ) ) ), + fade_in_fx ) ); // Qx + move16(); + move16(); + + + fade_in_fx = add( fade_in_fx, step_fx ); + fade_out_fx = sub( fade_out_fx, step_fx ); + } + + return; +} +#endif + + /*-------------------------------------------------------------------* * Function stereo_tdm_downmix() * @@ -1469,6 +1540,132 @@ void stereo_tdm_downmix( return; } + +#ifdef IVAS_FLOAT_FIXED +void stereo_tdm_downmix_ivas_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i : TD stereo IVAS encoder structure */ + Word16 *Left_in_fx, /* Qx */ + Word16 *Right_in_fx, /* Qx */ + const Word16 input_frame, /* i : Number of samples */ + const Word16 tdm_ratio_idx, /* i : TDM ratio index */ + const Word16 tdm_SM_flag, /* i : channel combination scheme flag */ + const Word16 tdm_ratio_idx_SM /* i : TDM ratio index for SM mode */ +) +{ + Word16 FR_Y_fx[L_FRAME48k], LR_X_fx[L_FRAME48k]; + Word16 i, tdm_n_OVA; + Word16 stereo_tdm_coder_type; + + tdm_n_OVA = NS2SA_FX2( L_mult0( input_frame, FRAMES_PER_SEC ), TDM_L_NOVA_NS ); + move16(); + + IF( hStereoTD->flag_skip_DMX ) + { + stereo_tdm_coder_type = 10; /* no DMX */ + move16(); + + Copy( Left_in_fx, FR_Y_fx, input_frame ); + Copy( Right_in_fx, LR_X_fx, input_frame ); + } + ELSE IF( EQ_16( tdm_SM_flag, 1 ) ) + { + IF( hStereoTD->tdm_last_SM_flag == 0 ) + { + stereo_tdm_coder_type = 0; /* mode 1 : Switching from YX scheme to SM scheme*/ + move16(); + } + ELSE + { + stereo_tdm_coder_type = 1; /* mode 2 : SM scheme*/ + move16(); + } + } + ELSE + { + IF( EQ_16( hStereoTD->tdm_last_SM_flag, 1 ) ) + { + stereo_tdm_coder_type = 2; /* mode 3 : Switching from SM scheme to YX scheme*/ + move16(); + } + ELSE + { + stereo_tdm_coder_type = 3; /* mode 4 : YX scheme*/ + move16(); + } + } + + SWITCH( stereo_tdm_coder_type ) + { + case ( 0 ): + { + /* Switching from YX scheme to SM scheme */ + tdm_downmix_fade_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx_SM], L_sub( tdm_ratio_tabl_fx[tdm_ratio_idx_SM], 2147483647 ), hStereoTD->tdm_last_ratio_fx, L_sub( 2147483647, hStereoTD->tdm_last_ratio_fx ), 0, tdm_n_OVA ); // 1.0 in Q31 -> 2147483647 + + /* Create new mixture of using the ratio computed above and formular for SM scheme */ + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx_SM], L_sub( tdm_ratio_tabl_fx[tdm_ratio_idx_SM], 2147483647 ), tdm_n_OVA, input_frame ); // 1.0 in Q31 -> 2147483647 + } + BREAK; + case ( 1 ): + { + /* Create new mixture of using the ratio computed above and formular for SM scheme */ + IF( EQ_32( tdm_ratio_tabl_fx[tdm_ratio_idx_SM], hStereoTD->tdm_last_ratio_SM_fx ) ) + { + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx_SM], L_sub( (Word32) tdm_ratio_tabl_fx[tdm_ratio_idx_SM], 2147483647 ), 0, input_frame ); // 1.0 in Q31 -> 2147483647 + } + ELSE + { + tdm_downmix_fade_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx_SM], L_sub( tdm_ratio_tabl_fx[tdm_ratio_idx_SM], 2147483647 ), hStereoTD->tdm_last_ratio_SM_fx, L_sub( hStereoTD->tdm_last_ratio_SM_fx, 2147483647 ), 0, tdm_n_OVA ); // 1.0 in Q31 -> 2147483647 + + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx_SM], L_sub( tdm_ratio_tabl_fx[tdm_ratio_idx_SM], 2147483647 ), tdm_n_OVA, input_frame ); // 1.0 in Q31 -> 2147483647 + } + } + BREAK; + case ( 2 ): + { + /* Switching from SM scheme to YX scheme */ + tdm_downmix_fade_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx], L_sub( 2147483647, tdm_ratio_tabl_fx[tdm_ratio_idx] ), hStereoTD->tdm_last_ratio_SM_fx, L_sub( hStereoTD->tdm_last_ratio_SM_fx, 2147483647 ), 0, tdm_n_OVA ); // 1.0 in Q31 -> 2147483647 + + /* Create new mixture of using the ratio computed above and formular for YX scheme */ + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx], L_sub( 2147483647, tdm_ratio_tabl_fx[tdm_ratio_idx] ), tdm_n_OVA, input_frame ); // 1.0 in Q31 -> 2147483647 + } + BREAK; + case ( 3 ): + { + /* Create new mixture of using the ratio computed above and formular for YX scheme */ + IF( EQ_32( tdm_ratio_tabl_fx[tdm_ratio_idx], + hStereoTD->tdm_last_ratio_fx ) ) + { + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx], L_sub( 2147483647, tdm_ratio_tabl_fx[tdm_ratio_idx] ), 0, input_frame ); // 1.0 in Q31 -> 2147483647 + } + ELSE + { + tdm_downmix_fade_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx], L_sub( 2147483647, tdm_ratio_tabl_fx[tdm_ratio_idx] ), hStereoTD->tdm_last_ratio_fx, L_sub( 2147483647, hStereoTD->tdm_last_ratio_fx ), 0, tdm_n_OVA ); // 1.0 in Q31 -> 2147483647 + + tdm_downmix_plain_ivas_fx( FR_Y_fx, LR_X_fx, Left_in_fx, Right_in_fx, tdm_ratio_tabl_fx[tdm_ratio_idx], L_sub( 2147483647, tdm_ratio_tabl_fx[tdm_ratio_idx] ), tdm_n_OVA, input_frame ); // 1.0 in Q31 -> 2147483647 + } + } + BREAK; + default: + BREAK; + } + + FOR( i = 0; i < input_frame; i++ ) + { + Left_in_fx[i] = FR_Y_fx[i]; // Qx + Right_in_fx[i] = LR_X_fx[i]; // Qx + move16(); + move16(); + } + + hStereoTD->tdm_last_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; // Q31 + hStereoTD->tdm_last_ratio_SM_fx = tdm_ratio_tabl_fx[tdm_ratio_idx_SM]; // Q31 + move32(); + move32(); + + return; +} +#endif + #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function stereo_tdm_prep_dwnmx() diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index a7e986843dc5a311fb48443992b503cee88174b8..bf22fb6011bdbe01a7d163374255bc8f9d1f51bc 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1731,11 +1731,13 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hEncoderConfig->Opt_AMR_WB ) { +#ifndef IVAS_FLOAT_FIXED IF( NE_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) { amr_wb_enc( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in[0], inputBufferSize ); } ELSE +#endif { amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); } diff --git a/lib_enc/nois_est.c b/lib_enc/nois_est.c index ac674a34abdedee2e8516a55d57ee95c4a7d9e4e..483c26a02398932711d43eea117294fb84d8c323 100644 --- a/lib_enc/nois_est.c +++ b/lib_enc/nois_est.c @@ -518,7 +518,7 @@ void noise_est( { ftemp2 /= ftemp; } - +#ifndef IVAS_FLOAT_FIXED if ( hStereoClassif != NULL ) { if ( st->idchan == 0 ) @@ -530,7 +530,7 @@ void noise_est( hStereoClassif->nchar_ch2 = ftemp2; } } - +#endif if ( ftemp2 > 10 ) { ftemp2 = 10; @@ -632,7 +632,7 @@ void noise_est( { if ( i >= START_BAND_SPMUS && i < NB_BANDS_SPMUS + START_BAND_SPMUS && st->hSpMusClas != NULL ) { - log_enr = (float) log( enr[i] ); + log_enr = (float) log( enr[i] + EPSILON ); if ( log_enr > st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS] ) { *non_staX += log_enr - st->hSpMusClas->past_log_enr[i - START_BAND_SPMUS]; diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index d0476a4129ede75409a8c6fe6250ba1a12064e64..355613596c392156684779732118fa8bb80ee262 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2174,6 +2174,7 @@ void noise_est_ivas_fx( Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden; Word16 e_ener, f_ener; Word32 Ltmp, Ltmp1, Lsum_num, Lsum_den, *pt1, *pt2, Ltmp2, Lnon_sta2; + Word64 w_sum_num, w_tmp; Word16 spec_div, noise_char; Word16 log_enr16; Word16 updt_step; /* Q15 */ @@ -2352,7 +2353,8 @@ void noise_est_ivas_fx( *-----------------------------------------------------------------*/ /* weighted sum of spectral changes per critical bands */ - Lsum_num = L_deposit_l( 0 ); + w_sum_num = 0; + move64(); Lsum_den = L_deposit_l( 0 ); /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */ @@ -2390,38 +2392,35 @@ void noise_est_ivas_fx( ExpDen = norm_l( Ltmpden ); den = extract_h( L_shl( Ltmpden, ExpDen ) ); num = div_s( num, den ); - Ltmp = L_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) ); - Lsum_num = L_add( Lsum_num, Ltmp ); + w_tmp = W_shr( num, add( sub( sub( shl( ExpNum, 1 ), ExpDen ), 15 + 1 ), tmpExp ) ); + w_sum_num = W_add( w_sum_num, w_tmp ); pt1++; pt2++; } Lsum_den = L_shr( Lsum_den, tmpExp ); + ExpNum = W_norm( w_sum_num ); + Lsum_num = W_extract_h( W_shl( w_sum_num, ExpNum ) ); + ExpNum = sub( ExpNum, 32 ); /* calculation of spectral diversity */ /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ spec_div = 0; move16(); - if ( GT_32( Mult_32_16( Lsum_num, 6554 ), Lsum_den ) ) /* Qx+Q15+1-16 ==> Qx */ + if ( GT_32( Mult_32_16( Lsum_num, 6554 ), L_shl_sat( Lsum_den, ExpNum ) ) ) /* Qx+Q15+1-16 ==> Qx */ { spec_div = 1; move16(); } /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */ - ExpNum = sub( norm_l( Lsum_num ), 1 ); - num = extract_h( L_shl( Lsum_num, ExpNum ) ); - Lsum_den = L_add( Lsum_den, 1 ); - - ExpDen = norm_l( Lsum_den ); - den = extract_h( L_shl( Lsum_den, ExpDen ) ); - - *sp_div = div_s( num, den ); + Word16 exp = 0; + *sp_div = BASOP_Util_Divide3232_Scale( Lsum_num, Lsum_den, &exp ); move16(); - *Q_sp_div = add( 15, sub( ExpNum, ExpDen ) ); + *Q_sp_div = add( sub( 15, exp ), ExpNum ); move16(); /*-----------------------------------------------------------------* diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c index f8f232b8913130d98ae8b93dbc7fafa278e915de..096aeb07c5d62643a4cd0803273afd4d35cbcce9 100644 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -47,6 +47,8 @@ #include "prot_fx_enc.h" #endif + +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * pre_proc() * @@ -1055,3 +1057,4 @@ void pre_proc( pop_wmops(); return; } +#endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 02fbc8e7d438fec491cd7c67611f82df745045be..6355d1ef9de46d8482979f9df15096197e6980c2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2188,6 +2188,27 @@ void core_signal_analysis_high_bitrate_fx( Word16 *spectrum_e, Word16 *Q_new ); +#ifdef IVAS_FLOAT_FIXED +void core_signal_analysis_high_bitrate_ivas_fx( + const Word16 *new_samples, /*i: Q0 */ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + Word16 lsp_new[], /* Q15 */ + Word16 lsp_mid[], /* Q15 */ + Encoder_State *st, + Word16 pTnsSize[], + Word16 pTnsBits[], + Word16 param_core[], + Word16 *ltpBits, + Word32 *windowed_samples, + const Word16 L_frame, + const Word16 L_frameTCX, + const Word16 last_element_mode, + const Word16 vad_hover_flag, /* i : VAD hangover flag */ + Word32 **spectrum, + Word16 *spectrum_e, + Word16 *Q_new ); +#endif + void ShapeSpectrum_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 A[], /* i : quantized coefficients NxAz_q[M+1] */ diff --git a/lib_enc/setmodeindex.c b/lib_enc/setmodeindex.c index 8077db8e8b8337934902fb41c3ca6b561a647807..7c9b89ab2f0d63d7958cb7851ce8c302a8a0c84f 100644 --- a/lib_enc/setmodeindex.c +++ b/lib_enc/setmodeindex.c @@ -52,6 +52,7 @@ ---------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void SetModeIndex( Encoder_State *st, /* i : Encoder state */ const int32_t last_total_brate, /* i : last total bitrate */ @@ -81,8 +82,7 @@ void SetModeIndex( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void SetModeIndex_ivas_fx( Encoder_State *st, /* i : Encoder state */ const Word32 last_total_brate, /* i : last total bitrate */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 82aaebc17793743eabeca9ef76f737ca7b0f47d1..a3e22d12db545009a2baac0661947784e438f9c5 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1018,8 +1018,9 @@ typedef struct sp_mus_clas_structure int16_t lt_hangover; float lowrate_pitchGain_flt; Word16 lowrate_pitchGain; - +#ifndef IVAS_FLOAT_FIXED float tdm_lt_Etot; +#endif Word16 tdm_lt_Etot_fx; // Q8 float var_cor_t[VAR_COR_LEN]; Word16 var_cor_t_fx[VAR_COR_LEN]; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index b00f385cf3a3b2248336b890f1957d5e83ea2129..4881d9f8baec0e8cb89deb35b3b33c4790fab825 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1260,7 +1260,7 @@ void wb_tbe_enc_ivas_fx( } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_fx, 0, 1 ); E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index edb92622ebcfc740f83c90f627f3d1dadd55a62a..bf7a5bc7a801ccd1b90459133cbc06c06c954306 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -836,5 +836,4 @@ void updt_enc_common_ivas_fx( return; } - #endif diff --git a/lib_enc/vad.c b/lib_enc/vad.c index e920caae56e3ae1d44c8252ba230e880d994baca..24f194ac86e19c83bfc0e3cdb2ba0ed105d9d67f 100644 --- a/lib_enc/vad.c +++ b/lib_enc/vad.c @@ -116,6 +116,10 @@ void wb_vad_init( hVAD->trigger_SID = 0; hVAD->snr_sum_vad = 0; +#ifdef IVAS_FLOAT_FIXED + hVAD->L_snr_sum_vad_fx = 0; +#endif + hVAD->hangover_terminate_flag = 0; return;