diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 9353570790ea131d84ab75dabd26dec3365c8295..327d14f91b93683f803f65efef68959d3b018923 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1043,6 +1043,15 @@ typedef enum #define DIRAC_MONO_MIN_THRESH 1e2f #define DIRAC_MONO_FRAME_THRESH 15 /* 30ms */ + +#define DIRAC_MONO_THRESH_SILENCE_FX (Word32)3e4 +#define DIRAC_MONO_NORM_FACTOR_FX (Word64)1e13 +#define DIRAC_MONO_ONE_ON_NORM_FACTOR_FX (Word64)1/1e13 +#define DIRAC_MONO_MAX_THRESH_FX (Word32)1e6 +#define DIRAC_MONO_MIN_THRESH_FX (Word32)1e2 +#define DIRAC_MONO_NORM_FACTOR_M 1220703104 +#define DIRAC_MONO_NORM_FACTOR_E 44 + typedef enum { DIRAC_OPEN, /* initialize to default value */ @@ -1304,6 +1313,7 @@ enum #define MASA_RATIO_THRESHOLD 0.1f #define MASA_ANGLE_TOLERANCE 0.5f #ifdef IVAS_FLOAT_FIXED +#define MASA_RATIO_THRESHOLD_FX 214748365 // 0.1 in Q31 #define MASA_RATIO_TOLERANCE_FX 419430/*0.1 Q22*/ #define MASA_ANGLE_TOLERANCE_FX ONE_IN_Q21/*0.5f q22*/ #endif diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 1c6a82a99ff789726a253103bc76250c86f96ac6..9d54f3f0a8e4c3ce482af3b6c5af1bf5a620b698 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -714,17 +714,6 @@ 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" ); @@ -757,12 +746,6 @@ 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_prot.h b/lib_com/ivas_prot.h index 924a554d664c5808e74ad00dc120a3327a982041..49ae9424ab32fa10d6f98b4d65ac9829e3a9c79a 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3773,7 +3773,7 @@ void stereo_cng_compute_PScorr( void stereo_cng_dec_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const int32_t ivas_total_brate /* i : IVAS total bitrate Q0*/ ); void stereo_cna_update_params( @@ -3784,9 +3784,9 @@ void stereo_cna_update_params( ); void stereo_cna_update_params_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ); void dtx_enc_init( Encoder_State *st, /* i : Encoder state handle */ @@ -6875,6 +6875,7 @@ void ivas_spar_arith_coeffs_com_init( const Word16 table_idx, const Word16 enc_dec); +#ifndef IVAS_FLOAT_FIXED int16_t ivas_arith_encode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, @@ -6887,6 +6888,7 @@ int16_t ivas_arith_encode_cmplx_cell_array( const int16_t any_diff , const int16_t wc_strat_arith ); +#endif ivas_error ivas_huffman_decode( ivas_huffman_cfg_t *huff_cfg, diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a8d7e76597acb3cfb1b32264f57fed5e1be71c35..0a94203298d3464b396d3db25b57371aa0d359fe 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3288,6 +3288,23 @@ void computeReferencePower_enc_fx( Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ const Word16 nchan_ana /* i : number of analysis channels */ ); + +void computeReferencePower_enc_fx_dirac( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ + Word32 *reference_power, /* o : Estimated power */ + Word16 *e_reference, /* o : exponent of reference_power */ + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + const IVAS_FORMAT ivas_format, /* i : ivas_format */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count, /* i/o: Mono Frame Count */ + Word16 *dirac_mono_flag /* i/o: Mono Flag */ +); + void ivas_omasa_enc_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ @@ -3412,4 +3429,16 @@ ivas_error ivas_param_mc_enc_open_fx( ivas_error ivas_param_mc_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + +Word16 ivas_arith_encode_cmplx_cell_array( + ivas_arith_t *pArith_re, + ivas_arith_t *pArith_re_diff, + const Word16 *pDo_diff, + const Word16 nB, + Word16 *pSymbol_re, + Word16 *pSymbol_old_re, + ivas_cell_dim_t *pCell_dims, + BSTR_ENC_HANDLE hMetaData, + const Word16 any_diff, + const Word16 wc_strat_arith ); #endif diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index facff366706fbb0c1b0b67a329e6020327185200..9c1a3063084721a327fd779ec1eec309bdf9f0c4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1551,7 +1551,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl( 1, q_dm_fv_re ); + tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); move32(); max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fea8657eb912f754b6953d7bebd71882bf0e1f9f..8fac54f5e3fb963330b74dd2e0509d9f70276664 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9413,15 +9413,15 @@ void fft_cldfb_fx( ); void stereo_dft_dec_analyze_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal */ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t chan, /* i : channel number */ - const int16_t input_frame, /* i : input frame size */ - const int16_t output_frame, /* i : output frame size */ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const int16_t k_offset, /* i : offset of DFT */ - const int16_t delay, /* i : delay in samples for input signal */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_DFT ); diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index 730014f0de6a7a3765cec2cf4ec7b1004cd50e5c..90140911d4ab7d15fe9d5e96ed5534391204c22e 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -17,11 +17,11 @@ *-------------------------------------------------------------------*/ void FEC_lsf2lsp_interp( - Decoder_State *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ + Decoder_State *st, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *Aq, /* o : calculated A(z) for 4 subframes Q12 */ + Word16 *lsf, /* o : estimated LSF vector Qlog2(2.56)*/ + Word16 *lsp /* o : estimated LSP vector Q15* */ ) { diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 36fec6a4a69dfa380edb2b5d2f7d450a285f6276..012057a9ddb8c8af6f6a2038876943048be9257c 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -41,9 +41,9 @@ void FEC_pitch_estim_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 clas, /* i : current frame classification */ const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ + const Word16 pitch_buf[], /* i : Floating pitch for each subframe Q6 */ const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC Q6*/ Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ Word16 *upd_cnt /* i/o: update counter */ , diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index e99d8b028886eca4d82bfa94d83dd33c9308d7a2..b9789ab84e0436f67b66106e5cbd4015063bc857 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -39,13 +39,13 @@ ivas_error acelp_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ + Word16 synth_out[], /* o : synthesis Q_syn2-1*/ Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0*/ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE Q_syn2-1*/ Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits */ Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ @@ -74,7 +74,7 @@ ivas_error acelp_core_dec_fx( Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /*Q12*/ Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer */ + Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer Q_exc*/ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 *bwe_exc_fx; Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ @@ -136,8 +136,11 @@ ivas_error acelp_core_dec_fx( hBWE_FD = st_fx->hBWE_FD; hTcxDec = st_fx->hTcxDec; error = IVAS_ERR_OK; - + move32(); // IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) + test(); + test(); + test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) { /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ @@ -236,32 +239,35 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st_fx->bpf_off = 1; move16(); /* in case of core switching, reset post-filter memories */ - IF( st_fx->hPFstat != NULL ) + if ( st_fx->hPFstat != NULL ) { st_fx->hPFstat->on = 0; + move16(); } - move16(); + /* reset the GSC pre echo energy threshold in case of switching */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } - move32(); } - if ( st_fx->prev_bfi > 0 ) + IF( st_fx->prev_bfi > 0 ) { /* reset the GSC pre echo energy threshold in case of FEC */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } - move32(); } #ifdef IVAS_CODE #ifdef NON_BE_FIX_807_MASA_DTX_BRSW @@ -277,14 +283,14 @@ ivas_error acelp_core_dec_fx( st_fx->clas_dec = st_fx->last_good; move16(); enr_q_fx = 0; - move16(); + move32(); Es_pred_fx = 0; move16(); tmp_noise_fx = 0; - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - exc_fx = old_exc_fx + L_EXC_MEM_DEC; move16(); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc + exc_fx = old_exc_fx + L_EXC_MEM_DEC; + IF( st_fx->hWIDec != NULL ) { Copy( st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); @@ -296,7 +302,7 @@ ivas_error acelp_core_dec_fx( exc2_fx = old_exc2_fx + L_EXC_MEM; IF( st_fx->hBWE_TD != NULL ) { - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } ELSE @@ -304,7 +310,6 @@ ivas_error acelp_core_dec_fx( bwe_exc_fx = NULL; } - move16(); last_pulse_pos = 0; move16(); do_WI_fx = 0; @@ -367,14 +372,14 @@ ivas_error acelp_core_dec_fx( move16(); move16(); } - else + ELSE { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; move16(); move16(); test(); - IF( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) + if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); @@ -384,16 +389,15 @@ ivas_error acelp_core_dec_fx( p_tdm_Pri_pitch_buf = NULL; #endif move16(); - move16(); } /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ test(); test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) + IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - if ( st_fx->hPFstat->on != 0 ) + IF( st_fx->hPFstat->on != 0 ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -404,22 +408,23 @@ ivas_error acelp_core_dec_fx( } /* convert quantized LSP vector */ st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); + move16(); /* convert old quantized LSF vector */ lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); // Qlog2(2.56) + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); // Qlog2(2.56) + Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); // Qlog2(2.56) /* Reset LPC mem */ IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) } ELSE { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) } set16_fx( st_fx->mem_MA_fx, 0, M ); #if 1 // def IVAS_CODE @@ -436,7 +441,7 @@ ivas_error acelp_core_dec_fx( #else synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); #endif - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); @@ -447,57 +452,63 @@ ivas_error acelp_core_dec_fx( /* update buffer of old subframe pitch values */ IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - move16(); + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - k = 13107; + k = 13107; // Q15 + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ - k = 16384; + k = 16384; // Q15 + move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - k = 26214; + k = 26214; // Q15 + move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); + st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q(15+15+1-16) move32(); } FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); + st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q15 move32(); } } ELSE { - move16(); + IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ - k = -16384; + k = -16384; // -0.5 in Q15 + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ - k = -12288; + k = -12288; //-0.375 in Q15 + move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ { /* tmpF = (float)16000/(float)12800; */ - k = 8192; + k = 8192; //.25 in Q15 + move16(); } FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); + st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 move32(); } st_fx->old_pitch_buf_fx[NB_SUBFR + 1] = st_fx->old_pitch_buf_fx[NB_SUBFR + 2]; @@ -505,7 +516,7 @@ ivas_error acelp_core_dec_fx( FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); + st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 move32(); } st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; @@ -517,45 +528,53 @@ ivas_error acelp_core_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - move16(); + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - k = 13107; + k = 13107; // Q15 + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ - k = 16384; + k = 16384; // Q15 + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - k = 26214; + k = 26214; // Q15 + move16(); } st_fx->bfi_pitch_fx = mult_r( k, st_fx->bfi_pitch_fx ); + move16(); st_fx->bfi_pitch_frame = L_FRAME; move16(); } ELSE { - move16(); + IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)16000/(float)32000; */ - k = -16384; + k = -16384; //-0.5 in Q15 + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* tmpF = (float)16000/(float)25600; */ - k = -12288; + k = -12288; // -0.375 in Q15 + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { /* tmpF = (float)16000/(float)12800; */ - k = 8192; + k = 8192; // .25 in Q15 + move16(); } st_fx->bfi_pitch_fx = add( st_fx->bfi_pitch_fx, mult_r( st_fx->bfi_pitch_fx, k ) ); + move16(); st_fx->bfi_pitch_frame = L_FRAME16k; move16(); } @@ -582,21 +601,28 @@ ivas_error acelp_core_dec_fx( tc_subfr_fx = -1; move16(); - if ( EQ_16( st_fx->coder_type, TRANSITION ) ) + IF( EQ_16( st_fx->coder_type, TRANSITION ) ) { tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame ); - move16(); } #if 1 // def IVAS_CODE /*----------------------------------------------------------------* * Decoding of GSC IVAS mode *----------------------------------------------------------------*/ st_fx->GSC_IVAS_mode = 0; - IF( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 && !( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + move16(); + test(); + test(); + test(); + test(); + IF( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 && !( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { - IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + test(); + test(); + IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { st_fx->GSC_IVAS_mode = get_next_indice( st_fx, 2 ); + move16(); } } #endif @@ -607,7 +633,7 @@ ivas_error acelp_core_dec_fx( IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF( EQ_16( st_fx->cng_type, LP_CNG ) ) + IF( st_fx->cng_type == LP_CNG ) { CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); @@ -624,12 +650,13 @@ ivas_error acelp_core_dec_fx( CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, &st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); -#if 1 // def IVAS_CODE - Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); +#if 1 // def IVAS_CODE + Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); // Q12 #endif } ELSE { + test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { FdCng_decodeSID_fx( st_fx->hFdCngDec->hFdCngCom, st_fx ); @@ -672,17 +699,18 @@ ivas_error acelp_core_dec_fx( delta_mem_scale = 3; move16(); test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) && EQ_16( st_fx->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st_fx->lp_ener_fx, 40 ) && ( st_fx->cng_type == LP_CNG ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st_fx->Q_exc; + move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); - Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); + Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); // Q_exc /* update past excitation signals for LD music post-filter */ IF( hMusicPF != NULL ) @@ -695,6 +723,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } } /* synthesis at 12.8kHz sampling rate */ @@ -712,7 +741,7 @@ ivas_error acelp_core_dec_fx( /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); + Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); // Q_syn -> Q(-1) IF( hBWE_FD != NULL ) { save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); @@ -741,13 +770,13 @@ ivas_error acelp_core_dec_fx( tc_subfr_tmp = tc_subfr_fx; move16(); - IF( LT_16( tc_subfr_tmp, L_SUBFR ) ) + if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) { tc_subfr_tmp = 0; move16(); } - IF( EQ_16( tc_subfr_fx, TC_0_192 ) ) + if ( EQ_16( tc_subfr_fx, TC_0_192 ) ) { nb_bits = -1; move16(); @@ -755,7 +784,7 @@ ivas_error acelp_core_dec_fx( config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - test(); + test(); test(); IF( EQ_16( st_fx->coder_type, TRANSITION ) && LT_16( tc_subfr_fx, L_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -772,7 +801,7 @@ ivas_error acelp_core_dec_fx( test(); IF( st_fx->hTdCngDec != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); + Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs ); } @@ -894,7 +923,7 @@ ivas_error acelp_core_dec_fx( /* decode the last glottal pulse position */ T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits ); - move16(); + test(); test(); @@ -906,10 +935,12 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); IF( EQ_16( st_fx->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st_fx->prev_bfi, 1 ) ) { st_fx->Q_exc = FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); + move16(); } ELSE IF( ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st_fx->old_bfi_cnt, 1 ) && EQ_16( output_frame, L_FRAME16k ) && st_fx->hWIDec != NULL ) { @@ -926,6 +957,8 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16( st_fx->clas_dec, VOICED_CLAS ) && NE_16( st_fx->clas_dec, ONSET ) && st_fx->relax_prev_lsf_interp == 0 && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) ) { @@ -945,7 +978,7 @@ ivas_error acelp_core_dec_fx( /*------------------------------------------------------------* * Decode excitation according to coding type *------------------------------------------------------------*/ - test(); + test(); test(); #ifdef ADD_LRTD @@ -971,7 +1004,7 @@ ivas_error acelp_core_dec_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); @@ -985,8 +1018,9 @@ ivas_error acelp_core_dec_fx( } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; + move16(); /* SC-VBR - PPP frames */ IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) { @@ -999,7 +1033,7 @@ ivas_error acelp_core_dec_fx( { decod_tran_fx( st_fx, st_fx->L_frame, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); } - ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf #ifdef ADD_LRTD @@ -1041,6 +1075,7 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( st_fx->nelp_mode_dec, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); @@ -1059,17 +1094,25 @@ ivas_error acelp_core_dec_fx( Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); } test(); - IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && EQ_16( st_fx->GSC_noisy_speech, 0 ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) + test(); + test(); + test(); + IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) { Word16 last_coder_type = st_fx->last_coder_type; - + move16(); + test(); + test(); + test(); if ( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && st_fx->GSC_noisy_speech == 0 ) ) { last_coder_type = AUDIO; + move16(); } /* Extrapolation of the last future part, windowing and high resolution DCT transform */ qdct = 0; + move16(); #ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); @@ -1091,7 +1134,7 @@ ivas_error acelp_core_dec_fx( /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) ) + if ( st_fx->coder_type == INACTIVE ) { i = 0; move16(); @@ -1101,7 +1144,7 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1109,7 +1152,7 @@ ivas_error acelp_core_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); IF( hMusicPF != NULL ) @@ -1118,6 +1161,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } } } @@ -1155,15 +1199,18 @@ ivas_error acelp_core_dec_fx( move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + test(); + test(); + test(); test(); IF( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && LE_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { @@ -1201,10 +1248,10 @@ ivas_error acelp_core_dec_fx( FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - IF( st_fx->nelp_mode_dec == 1 ) + IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); @@ -1252,6 +1299,7 @@ ivas_error acelp_core_dec_fx( { /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; i < MAX_LT; i++ ) @@ -1266,7 +1314,7 @@ ivas_error acelp_core_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1275,9 +1323,10 @@ ivas_error acelp_core_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); - if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + test(); + IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn } syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -1288,20 +1337,22 @@ ivas_error acelp_core_dec_fx( Copy( syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM ); } st_fx->prev_Q_exc_fr = st_fx->Q_exc; + move16(); st_fx->prev_Q_syn_fr = st_fx->Q_syn; + move16(); Copy( syn_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - if ( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + test(); + IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) { k = 0; move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } /*------------------------------------------------------------* @@ -1328,16 +1379,17 @@ ivas_error acelp_core_dec_fx( /* SC-VBR */ st_fx->hSC_VBR->FadeScale_fx = mult( st_fx->hSC_VBR->FadeScale_fx, 24576 ); /*24576 in Q15*/ + move16(); } IF( hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } ELSE { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); + Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 } } /*--------------------------------------------------------* @@ -1350,9 +1402,9 @@ ivas_error acelp_core_dec_fx( move16(); FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); + pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) move16(); - k++; + k = add( k, 1 ); } IF( EQ_16( st_fx->bwidth, NB ) ) @@ -1371,6 +1423,7 @@ ivas_error acelp_core_dec_fx( ELSE { st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); + move16(); } /*------------------------------------------------------------------* @@ -1386,7 +1439,7 @@ ivas_error acelp_core_dec_fx( /* Update MODE2 memories*/ IF( hTcxDec != NULL ) { - Copy_Scale_sig( syn_fx + st_fx->L_frame / 2, hTcxDec->old_syn_Overl, st_fx->L_frame / 2, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ + Copy_Scale_sig( syn_fx + shr( st_fx->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st_fx->L_frame, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q-1*/ } Copy_Scale_sig( syn_fx + st_fx->L_frame - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ @@ -1399,7 +1452,7 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) + IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || ( st_fx->element_mode > EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) { Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); st_fx->hPFstat->on = 1; @@ -1408,7 +1461,7 @@ ivas_error acelp_core_dec_fx( } ELSE IF( GE_16( st_fx->last_bwidth, WB ) ) { - if ( st_fx->hPFstat->on ) + IF( st_fx->hPFstat->on ) { Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf, M ); Copy( syn_fx, temp_buf + M, L_SUBFR ); @@ -1426,18 +1479,26 @@ ivas_error acelp_core_dec_fx( * Comfort noise addition *----------------------------------------------------------------*/ - test(); - test(); test(); test(); IF( ( st_fx->hFdCngDec != NULL || EQ_16( st_fx->idchan, 1 ) ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( ( st_fx->cng_type == LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ test(); st_fx->VAD = st_fx->VAD && ( st_fx->coder_type != INACTIVE ); - + move16(); + test(); + test(); + test(); + test(); + test(); IF( st_fx->idchan == 0 && ( st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) ) { @@ -1445,20 +1506,19 @@ ivas_error acelp_core_dec_fx( noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + move16(); IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } } - IF( st_fx->idchan == 0 ) + if ( st_fx->idchan == 0 ) { st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; move32(); } /*Noise estimate*/ - test(); - test(); IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) /* && !st->cng_ism_flag IVAS_CODE */ ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -1469,10 +1529,7 @@ ivas_error acelp_core_dec_fx( #endif } /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - test(); - test(); - test(); - test(); + #ifdef IVAS_CODE if ( !st->cna_dirac_flag ) { @@ -1569,11 +1626,15 @@ ivas_error acelp_core_dec_fx( } } #else + test(); + test(); + test(); + test(); IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) { generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); } - ELSE IF( st_fx->flag_cna && st_fx->coder_type == AUDIO && st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) + ELSE IF( st_fx->flag_cna && EQ_16( st_fx->coder_type, AUDIO ) && st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) { FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) { @@ -1584,11 +1645,16 @@ ivas_error acelp_core_dec_fx( #endif #ifndef IVAS_CODE - IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && st_fx->last_flag_cna == 1 && ( ( st_fx->last_core == ACELP_CORE && st_fx->last_coder_type != AUDIO ) || st_fx->last_core == AMR_WB_CORE ) ) + test(); + test(); + test(); + test(); + test(); + IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], negate( st_fx->Q_syn ) ) ); move16(); } } @@ -1614,15 +1680,17 @@ ivas_error acelp_core_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); - if ( st_fx->ini_frame > 0 ) + IF( st_fx->ini_frame > 0 ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + move16(); } } #ifdef ADD_LRTD /* analyze pitch coherence for bass post-filter */ bpf_pitch_coherence( st, pitch_buf ); #endif + test(); IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) ) { test(); @@ -1680,31 +1748,36 @@ ivas_error acelp_core_dec_fx( { /* set NB mask for upsampling */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); + move16(); } ELSE IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + move16(); } /*WB/SWB-FD_CNG*/ scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); - test(); - test(); + test(); IF( !st_fx->cng_sba_flag || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) + test(); + test(); + test(); + IF( ( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) { generate_comfort_noise_dec_hf_fx( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); st_fx->cldfbSyn->bandsToZero = 0; move16(); - if ( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) + IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); + move16(); } st_fx->cldfbSyn->lsb = st_fx->cldfbAna->no_channels; move16(); @@ -1832,13 +1905,20 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); + test(); + test(); IF( ( !st_fx->bfi && ( st_fx->prev_bfi ) ) || ( ( EQ_16( st_fx->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st_fx->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && !st_fx->tdm_LRTD_flag ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - + test(); + test(); + test(); + test(); + test(); IF( !st_fx->ppp_mode_dec && ( st_fx->idchan == 0 || NE_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) ) { non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, @@ -1846,9 +1926,10 @@ ivas_error acelp_core_dec_fx( } test(); - IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); } } /*----------------------------------------------------------------------* @@ -1857,6 +1938,8 @@ ivas_error acelp_core_dec_fx( updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); + test(); + test(); IF( GT_32( st_fx->core_brate, SID_2k40 ) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index e18d369f46df393119862027b01d9649946e1b9c..9718c710697f78c23c349379cd3fb7f2969afa3c 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -55,7 +55,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( const Word16 nchan_transport_old, /* i : last number of transport channels */ const ISM_MODE last_ism_mode, /* i : last ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { ivas_error error; @@ -100,7 +100,13 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) ) + /* st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport */ + Word16 tmp, tmp_e; + Word32 tmp_32; + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + tmp_32 = L_deposit_l( tmp ); + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, tmp_32, L_shl( tmp_32, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -115,7 +121,9 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; + move32(); hIntSetupOld = st_ivas->hIntSetup; + move32(); tc_granularity_new = 1; move16(); renderer_type_old = st_ivas->renderer_type; @@ -705,7 +713,7 @@ ivas_error ivas_ism_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { Word32 ivas_total_brate; @@ -729,7 +737,7 @@ ivas_error ivas_ism_dec_config_fx( test(); test(); test(); - IF( !st_ivas->bfi && NE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) ) + IF( !st_ivas->bfi && NE_32( ivas_total_brate, IVAS_SID_5k2 ) && ( ivas_total_brate != FRAME_NO_DATA ) ) { /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->nchan_ism, ivas_total_brate ); @@ -773,7 +781,7 @@ ivas_error ivas_ism_dec_config_fx( { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; move16(); - IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { st_ivas->hDecoderConfig->nchan_out = st_ivas->nchan_ism; move16(); diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index d33c88eed8085bc5a6902ba786477221d2ecf692..9f7af820fb1b57de72495bd13ee27a4628a4a1fe 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -86,7 +86,7 @@ void ivas_ism_dtx_dec_fx( test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { - IF( st_ivas->hParamIsmDec != NULL ) + if ( st_ivas->hParamIsmDec != NULL ) { st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech = flag_noisy_speech; move16(); @@ -102,8 +102,8 @@ void ivas_ism_dtx_dec_fx( { FOR( ch = 0; ch < nchan_ism; ch++ ) { - st_ivas->hParamIsmDec->azimuth_values_fx[ch] = st_ivas->hIsmMetaData[ch]->azimuth_fx; - st_ivas->hParamIsmDec->elevation_values_fx[ch] = st_ivas->hIsmMetaData[ch]->elevation_fx; + st_ivas->hParamIsmDec->azimuth_values_fx[ch] = st_ivas->hIsmMetaData[ch]->azimuth_fx; // Q22 + st_ivas->hParamIsmDec->elevation_values_fx[ch] = st_ivas->hIsmMetaData[ch]->elevation_fx; // Q22 move32(); move32(); } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 37c0f6d7baf5cc35971f772d99e6c81ad4ef7376..633459a2a3ec4b489ecc9b6775a5f0372e3bbec4 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -157,7 +157,7 @@ static void ism_metadata_smooth_fx( IF( GT_32( diff_fx, ISM_AZIMUTH_MAX_FX ) ) { diff_fx = L_sub( diff_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); - hIsmMetaData->last_azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); + hIsmMetaData->last_azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); // Q22 move32(); } ELSE IF( LT_32( diff_fx, ISM_AZIMUTH_MIN_FX ) ) @@ -755,8 +755,8 @@ ivas_error ivas_ism_metadata_dec_fx( Word32 element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; Word16 ism_extmeta_bitstream; Word16 non_diegetic_flag_global; - Word32 yaw_fx, pitch_fx; - Word16 radius_fx; + Word32 yaw_fx, pitch_fx; // Q22 + Word16 radius_fx; // Q9 Word16 flag_abs_radius; Word16 flag_abs_orientation; Word16 flag_abs_position; @@ -799,7 +799,7 @@ ivas_error ivas_ism_metadata_dec_fx( /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_ISM_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st0->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st0->bit_stream[last_bit_pos - i]; move16(); } st0->bit_stream = bstr_meta; @@ -825,7 +825,6 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); ism_mode = ivas_ism_mode_select( nchan_ism, ism_total_brate ); - move16(); } IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) @@ -954,7 +953,7 @@ ivas_error ivas_ism_metadata_dec_fx( lowrate_metadata_flag[ch] = hIsmMeta[ch]->ism_md_lowrate_flag; move16(); - IF( null_metadata_flag[ch] == 0 ) + if ( null_metadata_flag[ch] == 0 ) { ism_metadata_flag_global = s_or( ism_metadata_flag_global, lowrate_metadata_flag[ch] ); } @@ -1003,7 +1002,7 @@ ivas_error ivas_ism_metadata_dec_fx( test(); test(); test(); - IF( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { nb_bits_start = st0->next_bit_pos; move16(); @@ -1039,7 +1038,7 @@ ivas_error ivas_ism_metadata_dec_fx( idx_angle2 = shl( 1, ( ISM_ELEVATION_NBITS - 1 ) ); /* Panning gain dequantization */ - hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); hIsmMetaData->elevation_fx = 0; move32(); move32(); @@ -1068,8 +1067,8 @@ ivas_error ivas_ism_metadata_dec_fx( } ELSE /* ISM_MODE_DISC */ { - hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); - hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_ELEVATION_NBITS ) ); + hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_ELEVATION_NBITS ) ); move32(); move32(); @@ -1081,8 +1080,8 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); idx_angle2 = hIsmMetaData->orientation_angle.last_angle2_idx; move16(); - yaw_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_AZIMUTH_NBITS ) ); - pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, shl( 1, ISM_ELEVATION_NBITS ) ); + yaw_fx = ism_dequant_meta_fx( idx_angle1, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); + pitch_fx = ism_dequant_meta_fx( idx_angle2, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, ( 1 << ISM_AZIMUTH_NBITS ) ); idx_radius = decode_radius_fx( st0, &hIsmMetaData->last_radius_idx, &flag_abs_radius ); radius_fx = usdequant_fx( idx_radius, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8 ); @@ -1130,6 +1129,7 @@ ivas_error ivas_ism_metadata_dec_fx( IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) { hParamIsm->flag_noisy_speech = get_next_indice_fx( st0, 1 ); + move16(); /* Loop over multiwave to read the object indices from bitstream */ FOR( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) @@ -1158,7 +1158,11 @@ ivas_error ivas_ism_metadata_dec_fx( total_bits_metadata = sub( st0->next_bit_pos, nb_bits_start ); /* bits per ISM*/ - bits_metadata_ism = extract_l( total_bits_metadata / *nchan_transport ); + + // total_bits_metadata / *nchan_transport + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( total_bits_metadata, *nchan_transport, &tmp_e ); + bits_metadata_ism = shr( tmp, sub( 15, tmp_e ) ); // Q0 nb_bits_objcod_read = 0; move16(); @@ -1197,9 +1201,9 @@ ivas_error ivas_ism_metadata_dec_fx( { FOR( ch = 0; ch < nchan_ism; ch++ ) { - hParamIsm->azi_index[ch] = add( hParamIsm->azi_index[ch], i_mult2( hParamIsm->last_az_sgn[ch], hParamIsm->last_az_diff[ch] ) ); + hParamIsm->azi_index[ch] = add( hParamIsm->azi_index[ch], i_mult2( hParamIsm->last_az_sgn[ch], hParamIsm->last_az_diff[ch] ) ); // Q0 move16(); - hParamIsm->ele_index[ch] = add( hParamIsm->ele_index[ch], i_mult2( hParamIsm->last_el_sgn[ch], hParamIsm->last_el_diff[ch] ) ); + hParamIsm->ele_index[ch] = add( hParamIsm->ele_index[ch], i_mult2( hParamIsm->last_el_sgn[ch], hParamIsm->last_el_diff[ch] ) ); // Q0 move16(); hIsmMeta[ch]->position_angle.last_angle1_idx = hParamIsm->azi_index[ch]; move16(); @@ -1234,7 +1238,7 @@ ivas_error ivas_ism_metadata_dec_fx( } test(); - IF( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { ism_metadata_flag_global = 1; move16(); @@ -1261,7 +1265,7 @@ ivas_error ivas_ism_metadata_dec_fx( } } - IF( ( error = ivas_ism_config_fx( ism_total_brate, *nchan_transport, nchan_ism, hIsmMeta, ism_extmeta_bitstream, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, masa_ism_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( ism_total_brate, *nchan_transport, nchan_ism, hIsmMeta, ism_extmeta_bitstream, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, masa_ism_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -1281,8 +1285,8 @@ ivas_error ivas_ism_metadata_dec_fx( test(); test(); test(); - IF( EQ_16( ism_imp[ch], ISM_NO_META ) && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || - ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) + if ( ism_imp[ch] == ISM_NO_META && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || + ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; move16(); @@ -1290,7 +1294,7 @@ ivas_error ivas_ism_metadata_dec_fx( } test(); - IF( NE_32( ism_mode, ISM_MASA_MODE_DISC ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + if ( NE_32( ism_mode, ISM_MASA_MODE_DISC ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { hSCE[ch]->element_brate = element_brate[ch]; move32(); @@ -1328,7 +1332,7 @@ ivas_error ivas_ism_metadata_dec_fx( /* set bitstream pointers for each ISM */ FOR( ch = 1; ch < *nchan_transport; ch++ ) { - hSCE[ch]->hCoreCoder[0]->bit_stream = hSCE[ch - 1]->hCoreCoder[0]->bit_stream + ( hSCE[ch - 1]->hCoreCoder[0]->total_brate / FRAMES_PER_SEC ); + hSCE[ch]->hCoreCoder[0]->bit_stream = ( hSCE[ch - 1]->hCoreCoder[0]->bit_stream + extract_l( Mpy_32_32( hSCE[ch - 1]->hCoreCoder[0]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } /*----------------------------------------------------------------* @@ -1410,7 +1414,7 @@ ivas_error ivas_ism_metadata_dec_create_fx( IF( element_brate_tmp != NULL ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1518,7 +1522,7 @@ static void decode_angle_indices_fx( nbits_diff_angle1 = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1527,13 +1531,13 @@ static void decode_angle_indices_fx( nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( nbits_diff_angle1 < ( ISM_AZIMUTH_NBITS - 1 ) && get_next_indice_fx( st0, 1 ) == 1 ) { diff = add( diff, 1 ); nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); } - IF( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) ) + if ( LT_16( nbits_diff_angle1, ( ISM_AZIMUTH_NBITS - 1 ) ) ) { /* count stop bit */ nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); @@ -1543,17 +1547,17 @@ static void decode_angle_indices_fx( } /* azimuth/yaw is on a circle - check for diff coding for -180° -> 180° and vice versa changes */ - IF( GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + IF( GT_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { - idx_angle1 = sub( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* +180° -> -180° */ + idx_angle1 = sub( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); /* +180° -> -180° */ } ELSE IF( idx_angle1 < 0 ) { - idx_angle1 = add( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* -180° -> +180° */ + idx_angle1 = add( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); /* -180° -> +180° */ } /* +180° == -180° */ - IF( EQ_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + if ( EQ_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { idx_angle1 = 0; move16(); @@ -1561,7 +1565,7 @@ static void decode_angle_indices_fx( /* sanity check in case of FER or BER */ test(); - IF( ( idx_angle1 < 0 ) || GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + if ( ( idx_angle1 < 0 ) || GT_16( idx_angle1, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) ) { idx_angle1 = angle->last_angle1_idx; move16(); @@ -1596,7 +1600,7 @@ static void decode_angle_indices_fx( nbits_diff_angle2 = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1605,25 +1609,25 @@ static void decode_angle_indices_fx( nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( ( nbits_diff_angle2 < ISM_ELEVATION_NBITS ) && ( get_next_indice_fx( st0, 1 ) == 1 ) ) { diff = add( diff, 1 ); nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); } - IF( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) + if ( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) { /* count stop bit */ nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); } } - idx_angle2 = add( angle->last_angle2_idx, sgn * diff ); + idx_angle2 = add( angle->last_angle2_idx, i_mult( sgn, diff ) ); } /* sanity check in case of FER or BER */ test(); - IF( ( idx_angle2 < 0 ) || GT_16( idx_angle2, sub( shl( 1, ISM_ELEVATION_NBITS ), 1 ) ) ) + if ( ( idx_angle2 < 0 ) || GT_16( idx_angle2, ( ( 1 << ISM_ELEVATION_NBITS ) - 1 ) ) ) { idx_angle2 = angle->last_angle2_idx; move16(); @@ -1835,7 +1839,7 @@ static Word16 decode_radius_fx( nbits_diff_radius = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ + if ( EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* negative sign */ { sgn = -1; move16(); @@ -1844,7 +1848,7 @@ static Word16 decode_radius_fx( nbits_diff_radius = add( nbits_diff_radius, 1 ); /* read until the stop bit */ - WHILE( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) + WHILE( ( nbits_diff_radius < ISM_RADIUS_NBITS ) && ( get_next_indice_fx( st0, 1 ) == 1 ) ) { diff = add( diff, 1 ); nbits_diff_radius = add( nbits_diff_radius, 1 ); @@ -1861,7 +1865,7 @@ static Word16 decode_radius_fx( /* sanity check in case of FER or BER */ test(); - IF( ( idx_radius < 0 ) || GT_16( idx_radius, sub( shl( 1, ISM_RADIUS_NBITS ), 1 ) ) ) + if ( ( idx_radius < 0 ) || GT_16( idx_radius, ( 1 << ISM_RADIUS_NBITS ) - 1 ) ) { idx_radius = *last_radius_idx; move16(); @@ -2133,7 +2137,7 @@ void ivas_ism_metadata_sid_dec_fx( Word16 next_bit_pos_orig; UWord16 bstr_meta[IVAS_SID_5k2 / FRAMES_PER_SEC], *bstr_orig; - IF( EQ_32( ism_total_brate, FRAME_NO_DATA ) ) + IF( ism_total_brate == FRAME_NO_DATA ) { ism_metadata_smooth_fx( hIsmMeta, ism_total_brate, nchan_ism ); @@ -2143,7 +2147,7 @@ void ivas_ism_metadata_sid_dec_fx( /* initialization */ st0 = hSCE[0]->hCoreCoder[0]; - last_bit_pos = extract_l( L_sub( ism_total_brate / FRAMES_PER_SEC, L_add( 1, SID_FORMAT_NBITS ) ) ); + last_bit_pos = extract_l( L_sub( Mpy_32_32( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), L_add( 1, SID_FORMAT_NBITS ) ) ); bstr_orig = st0->bit_stream; next_bit_pos_orig = st0->next_bit_pos; move16(); @@ -2169,7 +2173,7 @@ void ivas_ism_metadata_sid_dec_fx( /* number of objects was already read in ivas_ism_get_dtx_dec() */ /* update the position in the bitstream */ st0->next_bit_pos = add( st0->next_bit_pos, nchan_ism ); - + move16(); /* read SID metadata flag( one per object ) */ FOR( ch = 0; ch < nchan_ism; ch++ ) { @@ -2203,6 +2207,7 @@ void ivas_ism_metadata_sid_dec_fx( { /* read noisy speech flag */ *flag_noisy_speech = get_next_indice_fx( st0, 1 ); + move16(); nBits_sce_id = 1; move16(); } @@ -2212,24 +2217,24 @@ void ivas_ism_metadata_sid_dec_fx( { /* read sce id */ *sce_id_dtx = get_next_indice_fx( st0, nBits_sce_id ); - + move16(); /* decode the coherence */ FOR( ch = 0; ch < nchan_transport; ch++ ) { IF( EQ_16( ch, *sce_id_dtx ) ) { - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = 32767; + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = 32767; // 1.0f in Q15 move16(); CONTINUE; } idx = get_next_indice_fx( st0, nBits_coh ); - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); // Q15 move16(); } } - IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) + if ( EQ_32( ism_mode, ISM_MODE_PARAM ) ) { hSCE[*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = hSCE[!*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx; move16(); @@ -2247,21 +2252,25 @@ void ivas_ism_metadata_sid_dec_fx( /* Azimuth decoding */ idx_azimuth = get_next_indice_fx( st0, nBits_azimuth ); hIsmMetaData->azimuth_fx = ism_dequant_meta_fx( idx_azimuth, ism_azimuth_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_azimuth ); - + move32(); /* Elevation decoding */ idx_elevation = get_next_indice_fx( st0, nBits_elevation ); hIsmMetaData->elevation_fx = ism_dequant_meta_fx( idx_elevation, ism_elevation_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_elevation ); - + move32(); /* update last indexes to correspond to active frames coding */ IF( GT_16( nBits_azimuth, ISM_AZIMUTH_NBITS ) ) { hIsmMetaData->position_angle.last_angle1_idx = shr( idx_azimuth, sub( nBits_azimuth, ISM_AZIMUTH_NBITS ) ); + move16(); hIsmMetaData->position_angle.last_angle2_idx = shr( idx_elevation, sub( nBits_elevation, ISM_ELEVATION_NBITS ) ); + move16(); } ELSE { hIsmMetaData->position_angle.last_angle1_idx = shl( idx_azimuth, sub( ISM_AZIMUTH_NBITS, nBits_azimuth ) ); + move16(); hIsmMetaData->position_angle.last_angle2_idx = shl( idx_elevation, sub( ISM_ELEVATION_NBITS, nBits_elevation ) ); + move16(); } /* save for smoothing metadata evolution */ @@ -2274,7 +2283,7 @@ void ivas_ism_metadata_sid_dec_fx( /* take into account padding bits as metadata bits to keep later bitrate checks valid */ Word32 res_dec, res_frac; - iDiv_and_mod_32( sub( IVAS_SID_5k2, SID_2k40 ), FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + iDiv_and_mod_32( IVAS_SID_5k2 - SID_2k40, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); nb_bits_metadata[*sce_id_dtx] = (Word16) res_dec; move16(); diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 16b818327819f04df311caeb9280800284c5d20f..2c72c6b48c23ef5ab407e3953a1721f56bc6605c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -67,9 +67,9 @@ static void ivas_param_ism_dec_dequant_DOA_fx( /* Get the azimuth and elevation values */ FOR( i = 0; i < nchan_ism; i++ ) { - hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); // Q22 move16(); - hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); // Q22 move16(); } @@ -113,9 +113,9 @@ static void ivas_param_ism_dec_dequant_powrat_fx( { FOR( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) { - hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 ); /* Q15 */ + hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 /*.5f in Q15 */ ); /* Q15 */ move16(); - hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); + hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); // Q15 , 32767= (1.0f in Q15) -1 move16(); } } @@ -149,7 +149,8 @@ static void ivas_param_ism_dec_dequant_powrat( #ifdef IVAS_FLOAT_FIXED static void ivas_ism_get_interpolator_fx( const Word16 subframe_nbslots, - Word16 *interpolator ) + Word16 *interpolator /*Q15*/ +) { Word16 interp_idx, q_tmp, tmp; @@ -183,7 +184,8 @@ static void ivas_ism_get_interpolator( static void ivas_ism_get_proto_matrix_fx( IVAS_OUTPUT_SETUP hOutSetup, const Word16 nchan_transport, - Word16 *proto_matrix ) + Word16 *proto_matrix /*Q15*/ +) { Word16 idx; @@ -198,16 +200,16 @@ static void ivas_ism_get_proto_matrix_fx( { IF( hOutSetup.ls_azimuth_fx[idx] > 0 ) { - proto_matrix[idx] = shl_sat( ONE_IN_Q14, 1 ); + proto_matrix[idx] = 32767; /* 1.0f in Q15 */ move16(); - proto_matrix[add( idx, hOutSetup.nchan_out_woLFE )] = 0; + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0; move16(); } ELSE IF( hOutSetup.ls_azimuth_fx[idx] < 0 ) { proto_matrix[idx] = 0; move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = shl_sat( ONE_IN_Q14, 1 ); + proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 32767; /* 1.0f in Q15 */ move16(); } ELSE @@ -284,14 +286,14 @@ static void ivas_ism_get_proto_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_collect_slot_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ - Word32 *Cldfb_RealBuffer_in_fx, + Word32 *Cldfb_RealBuffer_in_fx, /*Q(31-exp_real)*/ Word16 exp_real, - Word32 *Cldfb_ImagBuffer_in_fx, + Word32 *Cldfb_ImagBuffer_in_fx, /*Q(31-exp_imag)*/ Word16 exp_imag, const Word16 ch, - Word32 ref_power_fx[], + Word32 ref_power_fx[], /*Q(31-exp_ref_power)*/ Word16 *exp_ref_power, - Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], + Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-exp_cx_diag)*/ Word16 *exp_cx_diag ) { Word16 band_idx, bin_idx; @@ -320,9 +322,9 @@ static void ivas_param_ism_collect_slot_fx( tmp_fx = 0; move32(); exp_tmp = 0; - move32(); - Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // 2 * exp_real - Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // 2 * exp_imag + move16(); + Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_real) + Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // Q(31-2 * exp_imag) tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var1, add( exp_real, exp_real ), &exp_tmp ); tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var2, add( exp_imag, exp_imag ), &exp_tmp ); @@ -330,9 +332,9 @@ static void ivas_param_ism_collect_slot_fx( move16(); move16(); cx_diag_fx[bin_idx][ch] = BASOP_Util_Add_Mant32Exp( cx_diag_fx[bin_idx][ch], exp_cx_diag_buf[bin_idx][ch], tmp_fx, exp_tmp, &exp_cx_diag_new ); - move16(); + move32(); ref_power_fx[bin_idx] = BASOP_Util_Add_Mant32Exp( ref_power_fx[bin_idx], exp_ref_power_buf[bin_idx], tmp_fx, exp_tmp, &exp_ref_power_new ); - move16(); + move32(); exp_cx_diag_buf[bin_idx][ch] = exp_cx_diag_new; move16(); exp_ref_power_buf[bin_idx] = exp_ref_power_new; @@ -357,10 +359,10 @@ static void ivas_param_ism_collect_slot_fx( { FOR( j = 0; j < PARAM_ISM_MAX_DMX; j++ ) { - cx_diag_fx[i][j] = L_shr_r( cx_diag_fx[i][j], sub( max_exp_cx_diag, exp_cx_diag_buf[i][j] ) ); - move16(); + cx_diag_fx[i][j] = L_shr_r( cx_diag_fx[i][j], sub( max_exp_cx_diag, exp_cx_diag_buf[i][j] ) ); // Q(31-max_exp_cx_diag) + move32(); } - ref_power_fx[i] = L_shr_r( ref_power_fx[i], sub( max_exp_ref_power, exp_ref_power_buf[i] ) ); + ref_power_fx[i] = L_shr_r( ref_power_fx[i], sub( max_exp_ref_power, exp_ref_power_buf[i] ) ); // Q(31-max_exp_ref_power) move16(); } @@ -407,17 +409,17 @@ static void ivas_param_ism_collect_slot( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_compute_mixing_matrix_fx( - const int16_t nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_ism, /* i : number of ISM channels */ PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */ ISM_DTX_DATA_DEC hISMDTX, /* i : ISM DTX handle */ Word32 direct_response_fx[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN], // Q30 const Word16 nchan_transport, const Word16 nchan_out_woLFE, - Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], + Word32 cx_diag_fx[][PARAM_ISM_MAX_DMX], /*Q(31-cx_diag_e)*/ Word16 cx_diag_e, - Word32 ref_power_fx[], + Word32 ref_power_fx[], /*Q(31-ref_power_e)*/ Word16 ref_power_e, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_e)*/ Word16 mixing_matrix_e[CLDFB_NO_CHANNELS_MAX] ) { Word16 band_idx, bin_idx; @@ -502,7 +504,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( move32(); BREAK; case 3: - direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], 24576 ); + direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], 10923 ); // 10923 = 1/3f in Q15 move32(); BREAK; case 4: @@ -513,7 +515,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } ELSE { - direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], hParamIsmDec->power_ratios_fx[band_idx][0][w] ); + direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], hParamIsmDec->power_ratios_fx[band_idx][0][w] ); // Q(31-ref_power_e) move32(); } direct_power_e = ref_power_e; @@ -539,7 +541,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } FOR( i = 0; i < nchan_out_woLFE; i++ ) { - cy_diag_fx[i] = L_shr_r( cy_diag_fx[i], sub( cy_diag_e, cy_diag_e_arr[i] ) ); + cy_diag_fx[i] = L_shr_r( cy_diag_fx[i], sub( cy_diag_e, cy_diag_e_arr[i] ) ); // cy_diag_e move32(); } @@ -551,7 +553,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } FOR( w = 0; w < num_wave; w++ ) { - direct_power_fx[w] = L_shr_r( direct_power_fx[w], sub( direct_power_e, temp_e[w] ) ); + direct_power_fx[w] = L_shr_r( direct_power_fx[w], sub( direct_power_e, temp_e[w] ) ); // diract_power_e move32(); } @@ -665,13 +667,13 @@ static void ivas_param_ism_compute_mixing_matrix( static void ivas_param_ism_render_slot_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, - Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX], - Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX], - Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_RealBuffer_tc_exp)*/ + Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX], /*Q11 (31-Cldfb_ImagBuffer_tc_exp)*/ + Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_real)*/ + Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q(31-exp_imag)*/ Word16 *exp_real, Word16 *exp_imag, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-exp_mixing_matrix_lin_fx)*/ const Word16 interpolator_idx, const Word16 out_slot_idx, const Word16 num_ch_LS, @@ -717,8 +719,8 @@ static void ivas_param_ism_render_slot_fx( Word32 tmp_3 = Mpy_32_32( L_sub( ONE_IN_Q31, tmp_1_fx ), hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx][outchIdx + inchIdx * num_ch_LS] ); // 1 + hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old mixing_matrix_smooth_fx = BASOP_Util_Add_Mant32Exp( tmp_2, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_fx[bin_idx], tmp_3, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx[bin_idx], &res_exp ); - Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp - Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp + Word32 tmp_4 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_RealBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp)) + Word32 tmp_5 = Mpy_32_32( mixing_matrix_smooth_fx, Cldfb_ImagBuffer_in_fx[inchIdx][bin_idx] ); // Q(31-(res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp)) Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], real_buf_exp, tmp_4, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp, &real_buf_exp ); @@ -752,9 +754,9 @@ static void ivas_param_ism_render_slot_fx( { FOR( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) { - Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); + Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_RealBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_real, exp_buf_real[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_real)) move32(); - Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); + Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = L_shr( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], sub( max_exp_imag, exp_buf_imag[outchIdx][out_slot_idx][bin_idx] ) ); // Q(31-(max_exp_imag)) move32(); } } @@ -932,7 +934,7 @@ static ivas_error ivas_param_ism_rendering_init( #ifdef IVAS_FLOAT_FIXED static void ivas_param_ism_update_mixing_matrix_fx( PARAM_ISM_DEC_HANDLE hParamIsmDec, - Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], + Word32 mixing_matrix_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], /*Q(31-mixing_matrix_exp)*/ Word16 mixing_matrix_exp[CLDFB_NO_CHANNELS_MAX], const Word16 nchan_in, const Word16 nchan_out ) @@ -1107,14 +1109,14 @@ ivas_error ivas_param_ism_dec_open_fx( /* Initialize Param ISM Rendering handle */ IF( st_ivas->hDecoderConfig->Opt_tsm ) { - IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - IF( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ), IVAS_ERR_OK ) ) { return error; } @@ -1130,7 +1132,7 @@ ivas_error ivas_param_ism_dec_open_fx( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Initialize efap handle */ - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1152,12 +1154,12 @@ ivas_error ivas_param_ism_dec_open_fx( test(); IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1870,7 +1872,7 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || - ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_16( st_ivas->hDecoderConfig->Opt_Headrotation, 0 ) ) ) + ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) { Word16 i, num_objects; Word32 azimuth_fx, elevation_fx; @@ -1909,7 +1911,7 @@ void ivas_ism_dec_digest_tc_fx( } ELSE { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); + ivas_jbm_dec_get_adapted_linear_interpolator_fx( extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); move16(); } @@ -1924,16 +1926,16 @@ void ivas_ism_dec_digest_tc_fx( { Word16 gains_fx[2]; ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] ); - st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); - move16(); - st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); - move16(); + st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); // Q31 -> Q30 + move32(); + st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); // Q31 -> Q30 + move32(); } ELSE { // TODO tmu review when #215 is resolved - azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); - elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); + azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->azimuth_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 + elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->elevation_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 test(); test(); @@ -1954,8 +1956,8 @@ void ivas_ism_dec_digest_tc_fx( IF( st_ivas->hEFAPdata != NULL ) { - azimuth_fx = L_shl( azimuth_fx, Q22 ); - elevation_fx = L_shl( elevation_fx, Q22 ); + azimuth_fx = L_shl( azimuth_fx, Q22 ); // Q22 + elevation_fx = L_shl( elevation_fx, Q22 ); // Q22 efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); } } @@ -1964,8 +1966,8 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /*get HOA gets for direction (ACN/SN3D)*/ - Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); - Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); + Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); // Q0 + Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); // Q0 ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order, Q30 ); } } @@ -2078,7 +2080,7 @@ void ivas_ism_dec_digest_tc( void ivas_param_ism_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output */ + Word32 *transport_channels[], /* i : synthesized core-coder transport channels/DirAC output q_tc_in*/ Word16 q_tc_in ) { Word16 exp_ref_power = 31, exp_cx_diag = 31; @@ -2200,27 +2202,27 @@ void ivas_param_ism_dec_digest_tc_fx( FOR( j = 0; j < nchan_out_woLFE; j++ ) { - IF( GT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) + IF( hParamIsmDec->azimuth_values_fx[j] > 0 ) { - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; // (1.0f in Q15) - 1 move16(); hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 0; move16(); } ELSE { - IF( LT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) + IF( hParamIsmDec->azimuth_values_fx[j] < 0 ) { hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 0; move16(); - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; // (1.0f in Q15) - 1 move16(); } ELSE /* == 0.0f */ { - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; // Q15 move16(); - hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; + hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; // Q15 move16(); } } @@ -2235,7 +2237,7 @@ void ivas_param_ism_dec_digest_tc_fx( { FOR( i = 0; i < 2; i++ ) { - scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); + scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); // q_tc_in } q_tc = q_tc_in; move16(); @@ -2257,7 +2259,9 @@ void ivas_param_ism_dec_digest_tc_fx( Copy32( RealBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); Copy32( ImagBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = sub( 31, q_tc ); + move16(); hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = sub( 31, q_tc ); + move16(); } Word16 scale_factor_real, scale_factor_imag; Word16 current_idx; @@ -2268,8 +2272,8 @@ void ivas_param_ism_dec_digest_tc_fx( current_idx = add( imult1616( imult1616( slot_idx, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) ); scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); // Q(31-(exp_real_tmp-scale_factor_real)) + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); // Q(31-(exp_imag_tmp-scale_factor_imag)) exp_real_tmp = sub( exp_real_tmp, scale_factor_real ); exp_imag_tmp = sub( exp_imag_tmp, scale_factor_imag ); ivas_param_ism_collect_slot_fx( hParamIsmDec, @@ -2282,8 +2286,8 @@ void ivas_param_ism_dec_digest_tc_fx( exp_real_tmp = add( exp_real_tmp, scale_factor_real ); exp_imag_tmp = add( exp_imag_tmp, scale_factor_imag ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); // Q(31-(exp_real_tmp)) + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); // Q(31-(exp_imag_tmp)) } } /* Obtain Mixing Matrix on a frame-level */ @@ -2582,13 +2586,13 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( L_tmp1 = BASOP_Util_Add_Mant32Exp( ch0, ch0_e, ch1, ch1_e, &tmp_e1 ); /*L + R*/ - L_tmp1 = Mpy_32_32( L_tmp1, L_tmp1 ); /*(L + R)*(L + R)*/ + L_tmp1 = Mpy_32_32( L_tmp1, L_tmp1 ); // Q(31-(tmp_e1+tmp_e1 /*(L + R)*(L + R)*/ tmp_e1 = add( tmp_e1, tmp_e1 ); ene_sum_fx = BASOP_Util_Add_Mant32Exp( ene_sum_fx, ene_sum_e, L_tmp1, tmp_e1, &ene_sum_e ); } - IF( NE_32( ene_sum_fx, 0 ) ) + IF( ene_sum_fx != 0 ) { gain_fx = BASOP_Util_Divide3232_Scale( ene_tc_fx, ene_sum_fx, &tmp_e1 ); } @@ -2605,7 +2609,7 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( { /*handling denominator equals to zero*/ gain_fx = 1; move16(); - tmp_e1 = -32767; + tmp_e1 = -32767; //(-1.0f in Q15) + 1 move16(); } } @@ -2617,41 +2621,41 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( IF( GT_16( tmp_e2, tmp_e1 ) ) { - gain_fx = shr( gain_fx, tmp_e2 - tmp_e1 ); + gain_fx = shr( gain_fx, sub( tmp_e2, tmp_e1 ) ); // Q(15-tmp_e2) tmp_e1 = tmp_e2; move16(); } ELSE { - last_gain_fx = shr( last_gain_fx, tmp_e1 - tmp_e2 ); + last_gain_fx = shr( last_gain_fx, sub( tmp_e1, tmp_e2 ) ); // Q(15-tmp_e1) } IF( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 ) { /* Smoothing */ - gain_fx = add( mult_r( 24574, gain_fx ), mult_r( 8192, last_gain_fx ) ); + gain_fx = add( mult_r( 24574, gain_fx ), mult_r( 8192, last_gain_fx ) ); // 24574 =.75f in Q15 , 8192=.25f in Q15 /* 10ms ramp */ /* slope between two consecutive gains, 480 samples length */ - invFade = div_s( 1, nFadeLength ); + invFade = div_s( 1, nFadeLength ); // Q15 tmp = 0; move16(); FOR( i = 0; i < ( nFadeLength ); i++ ) { /* tmp2 = ( last_gain_fx + i * grad_fx )*/ - tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); + tmp2 = add( mult_r( sub( 32767, tmp ), last_gain_fx ), mult_r( tmp, gain_fx ) ); // 32767= 1.0f in Q15, - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], tmp2 ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], tmp2 ); // Q(Q_tc-tmp_e1) move32(); tmp = add( tmp, invFade ); } FOR( ; i < nSamples; i++ ) { - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); } } @@ -2659,9 +2663,9 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( { FOR( i = 0; i < nSamples; i++ ) { - transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); + transport_channels_f[0][i] = Mpy_32_16_1( transport_channels_f[0][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); - transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); + transport_channels_f[1][i] = Mpy_32_16_1( transport_channels_f[1][i], gain_fx ); // Q(Q_tc-tmp_e1) move32(); } } @@ -2689,15 +2693,15 @@ static void ivas_ism_param_dec_render_sf_fx( const int16_t nchan_transport, const int16_t nchan_out, const int16_t nchan_out_woLFE, - Word32 *output_f_fx[], + Word32 *output_f_fx[], /*Q_output*/ Word16 Q_output[] ) { Word16 ch, slot_idx, i, index_slot; /* CLDFB Output Buffers */ - Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX]; - Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX]; + Word32 Cldfb_RealBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-real_exp) + Word32 Cldfb_ImagBuffer_fx[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; // Q(31-imag_exp) + Word32 *Cldfb_RealBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11 + Word32 *Cldfb_ImagBuffer_in_fx[PARAM_ISM_MAX_DMX]; // Q11 PARAM_ISM_DEC_HANDLE hParamIsmDec; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word16 slot_idx_start; @@ -2726,8 +2730,8 @@ static void ivas_ism_param_dec_render_sf_fx( Word16 imag_exp[JBM_CLDFB_SLOTS_IN_SUBFRAME]; FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - index_slot = slot_idx_start + slot_idx; - move16(); + index_slot = add( slot_idx_start, slot_idx ); + FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -2787,15 +2791,15 @@ static void ivas_ism_param_dec_render_sf_fx( FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); - Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); + Scale_sig32( RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), real_exp[i] ) ); // Q_real + Scale_sig32( ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, add( sub( Q_real, 31 ), imag_exp[i] ) ); // Q_real } - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); // Q_real-1 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q_real, 1 ); move16(); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); - Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); + Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); // Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); @@ -2808,13 +2812,12 @@ static void ivas_ism_param_dec_render_sf_fx( Word32 res_dec, res_frac; iDiv_and_mod_32( sub( add( samplesProcessed, st_ivas->cldfbSynDec[ch]->no_channels ), 1 ), st_ivas->cldfbSynDec[ch]->no_channels, &res_dec, &res_frac, 0 ); no_col_cldfb = s_min( no_col_cldfb, extract_l( res_dec ) ); - move16(); } size_cldfb = imult1616( st_ivas->cldfbSynDec[ch]->no_channels, no_col_cldfb ); - Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); + Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); // Q11 - Q_output[ch] = sub( Q_real, 1 ); + Q_output[ch] = 11; move16(); idx_in = add( idx_in, 1 ); } @@ -2930,7 +2933,8 @@ void ivas_param_ism_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[] ) + Word32 *output_f_fx[] /*Q11*/ +) { Word16 ch, slots_to_render, first_sf, last_sf, subframe_idx; @@ -2967,7 +2971,7 @@ void ivas_param_ism_dec_render_fx( move16(); } slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - move16(); + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ Word32 res_dec, res_frac; iDiv_and_mod_32( nSamplesAsked, slot_size, &res_dec, &res_frac, 0 ); @@ -2995,7 +2999,7 @@ void ivas_param_ism_dec_render_fx( { ivas_ism_param_dec_render_sf_fx( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local_fx, Q_output ); - n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); FOR( ch = 0; ch < nchan_out; ch++ ) { output_f_local_fx[ch] += n_samples_sf; @@ -3149,7 +3153,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( move32(); test(); - IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) + IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || ivas_total_brate == FRAME_NO_DATA ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); @@ -3171,9 +3175,9 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ); + azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ) ); // Q0 move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) @@ -3204,15 +3208,15 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; move16(); - azimuth[0] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + azimuth[0] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); power_ratio_fx[0] = hParamIsmDec->power_ratios_fx[band_idx][0][0]; move16(); - azimuth[1] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + azimuth[1] = extract_l( L_shr( L_add( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); - elevation[1] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + elevation[1] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); power_ratio_fx[1] = hParamIsmDec->power_ratios_fx[band_idx][0][1]; move16(); @@ -3225,13 +3229,13 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( move16(); hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; move16(); - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); // Q30 move32(); hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; move16(); hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; move16(); - hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); + hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); // Q30 move32(); } } @@ -3255,9 +3259,9 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); + azimuth[0] = extract_l( L_shr( ( L_add( hParamIsmDec->azimuth_values_fx[0], ( 1 << 21 ) ) ), 22 ) ); // Q0 move16(); - elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ), 22 ); + elevation[0] = extract_l( L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ( 1 << 21 ) ), 22 ) ); // Q0 move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 8177b4567830a3e929e0b2147cd1449bc19a683b..7737a251d1f18a8c1dece2108e2ec370cb02a2f1 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -677,16 +677,16 @@ static void stereo_dft_generate_comfort_noise( *-------------------------------------------------------------------*/ static void stereo_dft_generate_comfort_noise_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 last_element_mode, /* i : last element mode */ - Decoder_State *st, /* i/o: Core coder decoder state */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ - const Word16 targetGain, /* i : ICA target gain Q13 */ - const Word16 chan, /* i : channel number */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q of DFT */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + Decoder_State *st, /* i/o: Core coder decoder state */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ + Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ + const Word16 targetGain, /* i : ICA target gain Q13*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q of DFT */ ) { Word16 i, j, k; @@ -755,17 +755,17 @@ static void stereo_dft_generate_comfort_noise_fx( IF( chan == 0 ) { - pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; + pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; /* Q31 */ FOR( b = 0; b < hStereoDft->nbands; b++ ) { IF( hStereoCng->xfade_frame_counter == 0 ) { - hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); + hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); /* Q15 */ move16(); } ELSE { - hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); + hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); /* Q15 */ move16(); } @@ -774,12 +774,12 @@ static void stereo_dft_generate_comfort_noise_fx( { IF( hStereoCng->first_SID_after_TD ) { - hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); /* Q15 */ move16(); } ELSE { - hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; + hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; /* Q15 */ move16(); } } @@ -787,18 +787,18 @@ static void stereo_dft_generate_comfort_noise_fx( { IF( GT_16( hStereoCng->nr_corr_frames, CORR_INIT ) ) { - hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); + hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); /* Q15 */ move16(); } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ move16(); } } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); + hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ move16(); } } @@ -878,25 +878,25 @@ static void stereo_dft_generate_comfort_noise_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - pTrigo = hStereoDft->dft_trigo_12k8_fx; + pTrigo = hStereoDft->dft_trigo_12k8_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); } ELSE { - pTrigo = hStereoDft->dft_trigo_16k_fx; + pTrigo = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); } - FOR( i = 0; i < shr( st->L_frame, 2 ); i++ ) + FOR( i = 0; i < st->L_frame / 4; i++ ) { - trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( st->L_frame / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[st->L_frame / 2 - i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[st->L_frame / 4] = pTrigo[i_mult( st->L_frame / 4, trigo_step )]; + trigo_dec[st->L_frame / 4] = pTrigo[st->L_frame / 4 * trigo_step]; /* Q15 */ move16(); Word16 rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), getScaleFactor32( cngNoiseLevel_upd, st->L_frame ) ); @@ -918,14 +918,14 @@ static void stereo_dft_generate_comfort_noise_fx( // lp_ener_fx will be in Q6 at this point. // So applying appropriate left shift on the denominator. - factor = L_shr( BASOP_Util_Divide3232_Scale_cadence( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ + factor = L_shr( BASOP_Util_Divide3232_Scale_cadence( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ /* q_div */ factor = Sqrt32( factor, &q_div ); q_div = add( q_div, 1 ); Word16 q_tmp; - FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) + FOR( i = 0; i < st->L_frame / 2 - 1; i++ ) { - ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); /* q_cngNoiseLevel_upd */ assert( ftmp > 0 ); q_sqrt = sub( 62, shl( q_cngNoiseLevel_upd, 1 ) ); IF( ftmp == 0 ) @@ -937,13 +937,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp = ISqrt32( ftmp, &q_sqrt ); e_norm_temp[i] = sub( 31, add( q_sqrt, q_div ) ); move16(); - *ptr0++ = Mpy_32_32( factor, tmp ); + *ptr0++ = Mpy_32_32( factor, tmp ); /* 2 * q_div + q_sqrt - 31 */ move32(); ptr1 += 2; ptr2 += 2; } - FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) + FOR( i = 0; i < st->L_frame / 2 - 1; i++ ) { q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, add( e_norm_temp[i], norm_l( cngNoiseLevel_upd[i] ) ) ); } @@ -961,18 +961,18 @@ static void stereo_dft_generate_comfort_noise_fx( IF( NE_16( st->L_frame, L_FRAME16k ) ) { - pTrigo = hStereoDft->dft_trigo_16k_fx; + pTrigo = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); - trigo_dec[sub( L_FRAME16k / 2, i )] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[L_FRAME16k / 2 - i] = pTrigo[i * trigo_step]; /* Q15 */ move16(); } - trigo_dec[L_FRAME16k / 4] = pTrigo[i_mult( L_FRAME16k / 4, trigo_step )]; + trigo_dec[L_FRAME16k / 4] = pTrigo[L_FRAME16k / 4 * trigo_step]; /* Q15 */ move16(); } @@ -983,11 +983,11 @@ static void stereo_dft_generate_comfort_noise_fx( rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); shift = sub( getScaleFactor32( shb_shape, L_FRAME16k ), 1 ); - scale_sig32( shb_shape, L_FRAME16k, shift ); + scale_sig32( shb_shape, L_FRAME16k, shift ); /* q_shb_shape + shift */ q_shb_shape = add( q_shb_shape, shift ); /* Compute 1/|A| */ - enr = Madd_32_32( Mpy_32_32( shb_shape[0], shb_shape[0] ), shb_shape[1], shb_shape[1] ); + enr = Madd_32_32( Mpy_32_32( shb_shape[0], shb_shape[0] ), shb_shape[1], shb_shape[1] ); /* 62 - 2*q_shb_shape */ q_enr = sub( 62, shl( q_shb_shape, 1 ) ); ptr0 = shb_shape; ptr1 = ptr0 + 2; @@ -996,20 +996,20 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) { - ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); /* 2*q_shape - 31 */ q_tmp = sub( shl( q_shb_shape, 1 ), 31 ); assert( ftmp > 0 ); q_div = 0; move16(); - ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); + ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); /* q_div */ /* in float: both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. in BASOP: sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ - enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); - tmp32_1 = Sqrt32( ftmp, &q_div ); + enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); /* q_enr */ + tmp32_1 = Sqrt32( ftmp, &q_div ); /* q_div */ *ptr0++ = tmp32_1; move32(); e_norm_temp[i] = sub( 31, q_div ); @@ -1026,19 +1026,19 @@ static void stereo_dft_generate_comfort_noise_fx( } FOR( i = 0; i < L_FRAME16k; i++ ) { - shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); + shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); /* q_shb_shape */ move32(); } } /* Update CNG noise level from MS noise estimation */ - Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); + Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* exp(bandNoiseShape_exp)*/ ptr_cng = cngNoiseLevel_hist; - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { tmp = L_shr( *( cngNoiseLevel_hist + shl( i, 1 ) ), 1 ); move32(); - tmp = L_add( tmp, L_shr( *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ), 1 ) ); + tmp = L_add( tmp, L_shr( *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ), 1 ) ); /* exp(bandNoiseShape_exp)*/ *ptr_cng++ = tmp; move32(); } @@ -1052,11 +1052,11 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; Word32 temppp; Word16 shift_g = shr( find_guarded_bits_fx( shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ) ), 1 ); - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { - E0 = W_add( E0, *ptr_cng++ ); + E0 = W_add( E0, *ptr_cng++ ); /* exp(bandNoiseShape_exp - E0_e) */ temppp = L_shr( ( *ptr_tmp ), shift_g ); - E1 = W_mac_32_32( E1, temppp, temppp ); + E1 = W_mac_32_32( E1, temppp, temppp ); /* 2*(q_cngNoiseLevel_upd - shift_g) + 1*/ ptr_tmp++; } E0_e = W_norm( E0 ); @@ -1068,20 +1068,20 @@ static void stereo_dft_generate_comfort_noise_fx( IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( E0 ), E0_e, W_extract_h( E1 ), E1_e ) < 0 ) { - tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E0 ), W_extract_h( E1 ), &q_div ); + tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E0 ), W_extract_h( E1 ), &q_div ); /* q_div + E0_e - E1_e */ q_div = add( q_div, sub( E0_e, E1_e ) ); tmp_16 = Sqrt16( tmp_16, &q_div ); tmp_16 = shl( tmp_16, q_div ); - hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); /* Q0 */ move16(); } ELSE { - tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E1 ), W_extract_h( E0 ), &q_div ); + tmp_16 = BASOP_Util_Divide3232_Scale( W_extract_h( E1 ), W_extract_h( E0 ), &q_div ); /* q_div + E0_e - E1_e */ q_div = add( q_div, sub( E1_e, E0_e ) ); tmp_16 = Sqrt16( tmp_16, &q_div ); tmp_16 = shl( tmp_16, q_div ); - hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); + hStereoCng->xfade_length = sub( MAX_XFADE_FX, extract_l( L_shr( imult3216( MAX_XFADE_FX, tmp_16 ), Q15 ) ) ); /* Q0 */ move16(); } } @@ -1090,15 +1090,15 @@ static void stereo_dft_generate_comfort_noise_fx( { ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) { q_sqrt = st->hFdCngDec->bandNoiseShape_exp; move16(); - tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); + tmp_16 = BASOP_Util_Divide1616_Scale( hStereoCng->xfade_frame_counter, hStereoCng->xfade_length, &q_div ); /* Q0 */ tmp_16 = shl( tmp_16, q_div ); tmp = Sqrt32( *ptr_cng++, &q_sqrt ); tmp = L_shl( tmp, sub( add( q_cngNoiseLevel_upd, q_sqrt ), 31 ) ); - *ptr_tmp = L_add( Mpy_32_16_1( *ptr_tmp, tmp_16 ), Mpy_32_16_1( Mpy_32_16_1( tmp, sub( MAX_16, tmp_16 ) ), hStereoDft->scale_fx ) ); + *ptr_tmp = L_add( Mpy_32_16_1( *ptr_tmp, tmp_16 ), Mpy_32_16_1( Mpy_32_16_1( tmp, sub( MAX_16, tmp_16 ) ), hStereoDft->scale_fx ) ); /* q_cngNoiseLevel_upd + q_div */ move32(); ptr_tmp++; } @@ -1112,7 +1112,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_i = ptr_r + 1; scale = shr( output_frame, 1 ); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); @@ -1125,13 +1125,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp32_1 = L_shl( tmp32_1, q_shift ); q_shift = sub( sub( 46, q_cngNoiseLevel_upd ), q_shift ); - ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); /* q_dft */ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft */ move32(); ptr_i += 2; ptr_level++; @@ -1163,8 +1163,8 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_shb = shb_shape + ( L_FRAME16k / 2 - 1 ); /* Averaging for Nyquist frequency */ Word16 q1, q2; - tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); - tmp32_2 = *( ptr_shb - 1 ); + tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1], inv_scale ); /* q_cngNoiseLevel_upd + 1 - q_res */ + tmp32_2 = *( ptr_shb - 1 ); /* q_shb_shape */ move32(); q1 = sub( add( q_cngNoiseLevel_upd, 1 ), q_res ); q2 = q_shb_shape; @@ -1174,19 +1174,19 @@ static void stereo_dft_generate_comfort_noise_fx( q_tmp = sub( q_tmp, 1 ); IF( LT_16( sub( Q31, q_tmp ), q_shb_shape ) ) { - scale_sig32( shb_shape, L_FRAME16k, sub( sub( Q31, q_tmp ), q_shb_shape ) ); + scale_sig32( shb_shape, L_FRAME16k, sub( sub( Q31, q_tmp ), q_shb_shape ) ); /* Q31 - q_tmp */ q_shb_shape = sub( Q31, q_tmp ); } - *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); + *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); /* Q31 - q_tmp */ move32(); // *ptr_shb = 0.5f * ( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1] / scale + *( ptr_shb - 1 ) ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */ ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); @@ -1205,7 +1205,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); ptr_i += 2; ptr_shb--; @@ -1221,13 +1221,13 @@ static void stereo_dft_generate_comfort_noise_fx( tmp32_1 = L_shl( tmp32_1, q_shift ); q_shift = sub( add( Q16, q_div ), q_shift ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* q_dft */ ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { - ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); - ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); /* q_dft + q_shift */ move32(); ptr_r += 2; ptr_i += 2; @@ -1240,17 +1240,17 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); lp_noise_e = 0; move16(); - ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, add( hFdCngCom->startBand, 1 ) ); - ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); + ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, add( hFdCngCom->startBand, 1 ) ); /* q_cngNoiseLevel */ + ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); /* q_cngNoiseLevel_upd */ q_tmp = s_max( hFdCngCom->cngNoiseLevelExp, shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ) ); - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); /* q_tmp */ hFdCngCom->cngNoiseLevelExp = q_tmp; move16(); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { - *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); + *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); /* q_cngNoiseLevel */ move32(); ptr_tmp--; *ptr_level = *( ptr_level + 1 ); @@ -1270,9 +1270,9 @@ static void stereo_dft_generate_comfort_noise_fx( /* Fade MS -> SID/MS */ j = 0; move16(); - FOR( k = 0; k < sub( hFdCngCom->nFFTpart, 2 ); k++ ) + FOR( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) { - factor = BASOP_Util_Divide3232_Scale_cadence( L_add( hFdCngCom->sidNoiseEstLp[k], DELTA_FX ), L_add( st->hFdCngDec->partNoiseShape[k], DELTA_FX ), &q_div ); + factor = BASOP_Util_Divide3232_Scale_cadence( L_add( hFdCngCom->sidNoiseEstLp[k], DELTA_FX ), L_add( st->hFdCngDec->partNoiseShape[k], DELTA_FX ), &q_div ); /* q_div */ q_div = add( q_div, sub( hFdCngCom->sidNoiseEstExp, st->hFdCngDec->partNoiseShape_exp ) ); IF( q_div < 0 ) { @@ -1280,10 +1280,10 @@ static void stereo_dft_generate_comfort_noise_fx( q_div = 0; move16(); } - factor = L_min( L_add( L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ), W_extract_l( W_mult0_32_32( Mpy_32_16_1( L_sub( factor, L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ) ), ONE_BY_MAX_K ), hStereoCng->xfade_frame_counter ) ) ), factor ); + factor = L_min( L_add( L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ), W_extract_l( W_mult0_32_32( Mpy_32_16_1( L_sub( factor, L_shl( hStereoDft->scale_fx, sub( 16, q_div ) ) ), ONE_BY_MAX_K ), hStereoCng->xfade_frame_counter ) ) ), factor ); /* q_div */ FOR( ; j <= hFdCngCom->part[k]; j++ ) { - hFdCngCom->cngNoiseLevel[j] = L_shl( Mpy_32_32( st->hFdCngDec->bandNoiseShape[j], factor ), q_div ); + hFdCngCom->cngNoiseLevel[j] = L_shl( Mpy_32_32( st->hFdCngDec->bandNoiseShape[j], factor ), q_div ); /* exp(st->hFdCngDec->bandNoiseShape_exp) */ move32(); } } @@ -1296,10 +1296,10 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { ptr_level = hFdCngCom->cngNoiseLevel; - ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* qDFT */ ptr_i = ptr_r + 1; q_cngNoiseLevel = sub( Q31, hFdCngCom->cngNoiseLevelExp ); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { /* Real part in FFT bins */ tmp = L_shr( *ptr_level++, 1 ); @@ -1307,19 +1307,19 @@ static void stereo_dft_generate_comfort_noise_fx( rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); q_sqrt = sub( Q31, q_cngNoiseLevel ); tmp = Sqrt32( tmp, &q_sqrt ); - *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); + *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); /* qDFT */ move32(); - ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); + ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); /* qDFT */ move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = L_shl( imult3216( Mpy_32_32( ( *ptr_i ), tmp ), scale ), q_sqrt ); + ( *ptr_i ) = L_shl( imult3216( Mpy_32_32( ( *ptr_i ), tmp ), scale ), q_sqrt ); /* qDFT */ move32(); ptr_i += 2; } ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); /* qDFT */ ptr_i = ptr_r + 1; FOR( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) { @@ -1336,7 +1336,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = Mpy_32_32( *ptr_i, tmp ); + ( *ptr_i ) = Mpy_32_32( *ptr_i, tmp ); // q_dft + 15 + q_sqrt - 31 ( *ptr_i ) = L_shl_sat( ( *ptr_i ), add( 15, q_sqrt ) ); move32(); ptr_i += 2; @@ -1351,7 +1351,7 @@ static void stereo_dft_generate_comfort_noise_fx( lp_noise_e = 0; move16(); ptr_level = hFdCngCom->cngNoiseLevel; - FOR( i = 0; i < sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); i++ ) + FOR( i = 0; i < hFdCngCom->stopFFTbin - hFdCngCom->startBand; i++ ) { // lp_noise = L_add( lp_noise, *ptr_level++ ); lp_noise = BASOP_Util_Add_Mant32Exp( lp_noise, lp_noise_e, *ptr_level++, hFdCngCom->cngNoiseLevelExp, &lp_noise_e ); @@ -1361,31 +1361,31 @@ static void stereo_dft_generate_comfort_noise_fx( test(); IF( EQ_16( hStereoCng->last_act_element_mode, IVAS_CPE_TD ) && ( chan > 0 ) ) { - Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); + Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 - log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); - st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); + log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); /* Q23 */ + st1->lp_noise = L_add( Mpy_32_16_1( st1->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); /* Q23 */ move32(); } ELSE IF( ( chan == 0 ) ) { Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. move16(); - Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); + Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 // Hence the 16-bit constant log10(2) will be stored in Q13 - log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); - st->hFdCngDec->lp_noise = L_add( Mpy_32_16_1( st->hFdCngDec->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); + log_lp_noise = Mpy_32_16_1( log_lp_noise, 2466 /* log10(2) in Q13 */ ); /* Q23 */ + st->hFdCngDec->lp_noise = L_add( Mpy_32_16_1( st->hFdCngDec->lp_noise, 29491 /* 0.9f in Q15 */ ), log_lp_noise ); /* Q23 */ move32(); - st->lp_noise = st->hFdCngDec->lp_noise; + st->lp_noise = st->hFdCngDec->lp_noise; /* Q23 */ move32(); - st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); + st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ move16(); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ move32(); } @@ -1398,16 +1398,16 @@ static void stereo_dft_generate_comfort_noise_fx( min_q = sub( s_min( add( q_shift_1, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ), add( q_shift_2, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ), 1 /* Guard bit */ ); - scale_sig32( st->hFdCngDec->smoothed_psd_fx, L_FRAME16k, sub( min_q, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ) ); + scale_sig32( st->hFdCngDec->smoothed_psd_fx, L_FRAME16k, sub( min_q, sub( Q31, st->hFdCngDec->smoothed_psd_exp ) ) ); /* Q31 - st->hFdCngDec->smoothed_psd_exp */ st->hFdCngDec->smoothed_psd_exp = sub( Q31, min_q ); move16(); - scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( min_q, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( min_q, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ); /* Q31 - hFdCngCom->cngNoiseLevelExp */ hFdCngCom->cngNoiseLevelExp = st->hFdCngDec->smoothed_psd_exp; move16(); FOR( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) { - ftmp = hFdCngCom->cngNoiseLevel[sub( i, hFdCngCom->startBand )]; + ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; move32(); IF( !st->hFdCngDec->first_cna_noise_updated ) { @@ -1423,7 +1423,7 @@ static void stereo_dft_generate_comfort_noise_fx( IF( ( st->hFdCngDec->smoothed_psd_fx[i] > 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), st->hFdCngDec->smoothed_psd_fx[i] ) ) { /* prevent abrupt upward update steps */ - ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 1 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); + ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 1 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); /* st->hFdCngDec->smoothed_psd_exp */ move16(); } ELSE IF( LT_32( ftmp, st->hFdCngDec->smoothed_psd_fx[i] ) ) @@ -1435,7 +1435,7 @@ static void stereo_dft_generate_comfort_noise_fx( } /* smoothing */ - st->hFdCngDec->smoothed_psd_fx[i] = L_add( Mpy_32_16_1( st->hFdCngDec->smoothed_psd_fx[i], alpha ), Mpy_32_16_1( ftmp, sub( MAX_16, alpha ) ) ); + st->hFdCngDec->smoothed_psd_fx[i] = L_add( Mpy_32_16_1( st->hFdCngDec->smoothed_psd_fx[i], alpha ), Mpy_32_16_1( ftmp, sub( MAX_16, alpha ) ) ); /* st->hFdCngDec->smoothed_psd_exp */ move32(); } @@ -1447,15 +1447,15 @@ static void stereo_dft_generate_comfort_noise_fx( IF( max_l ) { q_shift = sub( norm_l( max_l ), 2 ); - scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, q_shift ); + scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, q_shift ); /* st->hFdCngDec->msNoiseEst_exp - q_shift */ st->hFdCngDec->msNoiseEst_exp = sub( st->hFdCngDec->msNoiseEst_exp, q_shift ); move16(); } st->hFdCngDec->first_cna_noise_updated = 1; move16(); - Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); + Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); /* st->hFdCngDec->msNoiseEst_exp - q_shift */ st->hFdCngDec->msPeriodog_ST_exp = st->hFdCngDec->msNoiseEst_exp; - st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; + st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; /* Q0 */ move16(); } @@ -1507,11 +1507,11 @@ void stereo_dtf_cng( } #else void stereo_dtf_cng_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - const Word16 output_frame, /* i : output frame size */ - Word16 q_dft /* i : Q factor of the DFT data */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q factor of the DFT data */ ) { Decoder_State **sts; @@ -1523,7 +1523,7 @@ void stereo_dtf_cng_fx( { IF( LT_16( hCPE->hStereoCng->nr_dft_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_dft_frames = add( hCPE->hStereoCng->nr_dft_frames, 1 ); + hCPE->hStereoCng->nr_dft_frames = add( hCPE->hStereoCng->nr_dft_frames, 1 ); /* Q0 */ move16(); } @@ -1532,7 +1532,7 @@ void stereo_dtf_cng_fx( test(); IF( LT_16( hCPE->hStereoCng->nr_sid_frames, SID_INIT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - hCPE->hStereoCng->nr_sid_frames = add( hCPE->hStereoCng->nr_sid_frames, 1 ); + hCPE->hStereoCng->nr_sid_frames = add( hCPE->hStereoCng->nr_sid_frames, 1 ); /* Q0 */ move16(); } @@ -1555,8 +1555,8 @@ void stereo_dtf_cng_fx( *-------------------------------------------------------------------*/ void stereo_cng_dec_update( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { IF( GT_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) ) @@ -1572,7 +1572,7 @@ void stereo_cng_dec_update( } IF( LT_16( hCPE->hStereoCng->active_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->active_frame_counter = add( hCPE->hStereoCng->active_frame_counter, 1 ); + hCPE->hStereoCng->active_frame_counter = add( hCPE->hStereoCng->active_frame_counter, 1 ); /* Q0 */ move16(); } } @@ -1582,7 +1582,7 @@ void stereo_cng_dec_update( move16(); IF( LT_16( hCPE->hStereoCng->xfade_frame_counter, MAX_FRAME_COUNTER ) ) { - hCPE->hStereoCng->xfade_frame_counter = add( hCPE->hStereoCng->xfade_frame_counter, 1 ); + hCPE->hStereoCng->xfade_frame_counter = add( hCPE->hStereoCng->xfade_frame_counter, 1 ); /* Q0 */ move16(); } } @@ -1602,7 +1602,7 @@ void stereo_cng_dec_update( } } - hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->active_frame_counter = hCPE->hStereoCng->active_frame_counter; + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->active_frame_counter = hCPE->hStereoCng->active_frame_counter; /* Q0 */ move16(); return; @@ -1621,8 +1621,8 @@ void stereo_cng_compute_PScorr_fx( Word16 *output_Q, Word32 *c_PS_LT_fx, Word16 Q_c_PS_LT_fx, - const Word16 L_frame_0, /* i : L_frame channel 0 */ - const Word16 L_frame_1 /* i : L_frame channel 1 */ + const Word16 L_frame_0, /* i : L_frame channel 0 Q0*/ + const Word16 L_frame_1 /* i : L_frame channel 1 Q0*/ ) { Word16 i; @@ -1840,10 +1840,10 @@ static void stereo_cng_compute_LRcorr( } #else static void stereo_cng_compute_LRcorr_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -1874,9 +1874,9 @@ static void stereo_cng_compute_LRcorr_fx( FOR( i = 0; i < output_frame; i++ ) { - enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); - enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); - dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); /* 2 * OUTPUT_Q */ + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ } dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); if ( dotLR_fx < 0 ) @@ -1917,7 +1917,7 @@ static void stereo_cng_compute_LRcorr_fx( temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &enrL_inv_q ); temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &enrR_inv_q ); - energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* enrL_inv_q + enrR_inv_q - 31 */ res_q = add( enrL_inv_q, enrR_inv_q ); headroom_left_dotLR = W_norm( dotLR_fx ); dotLR_q = OUTPUT_Q * 2; @@ -1935,13 +1935,13 @@ static void stereo_cng_compute_LRcorr_fx( Word16 div_q = 0; move16(); - c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &div_q ); + c_fx = BASOP_Util_Divide3232_Scale( W_extract_l( enrL_fx ), W_extract_l( enrR_fx ), &div_q ); /* div_q */ c_q = add( sub( 15, div_q ), sub( enrR_q, enrL_q ) ); hCPE->hStereoTD->c_LR_LT_fx = L_add( Mpy_32_32( STEREO_TD_PS_CORR_FILT_FX, hCPE->hStereoTD->c_LR_LT_fx ), - Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( extract_l( c_LR_fx ) ) ) ); + Mpy_32_32( L_sub( ONE_IN_Q31, STEREO_TD_PS_CORR_FILT_FX ), L_deposit_h( extract_l( c_LR_fx ) ) ) ); /* Q31 */ move32(); - hCPE->hStereoCng->c_LR_LT_fx = hCPE->hStereoTD->c_LR_LT_fx; + hCPE->hStereoCng->c_LR_LT_fx = hCPE->hStereoTD->c_LR_LT_fx; /* Q31 */ move32(); Word16 sqrt_q = sub( 31, c_q ); @@ -1951,8 +1951,8 @@ static void stereo_cng_compute_LRcorr_fx( tmp_fx = Mpy_32_32( tmp_fx, sqrt_res ); Word16 tmp_q = sub( sub( 31, sqrt_q ), 1 ); // *2 handled with q reduction - beta_sqr = Mpy_32_32( beta_fx, beta_fx ); - one_minus_beta_sqr = Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), L_sub( ONE_IN_Q31, beta_fx ) ); + beta_sqr = Mpy_32_32( beta_fx, beta_fx ); /* Q31 */ + one_minus_beta_sqr = Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), L_sub( ONE_IN_Q31, beta_fx ) ); /* Q31 */ numer_1 = Mpy_32_16_1( one_minus_beta_sqr, extract_l( c_fx ) ); // c_q+31-15 numer_1_q = add( c_q, 31 - 15 ); @@ -1992,8 +1992,8 @@ static void stereo_cng_compute_LRcorr_fx( denom_q = s_min( denom_q, denom_3_q ); - num = L_add( L_add( L_shr( numer_1, sub( numer_1_q, num_q ) ), L_sub( L_shr( numer_2, sub( numer_2_q, num_q ) ), L_shr( numer_3, sub( numer_3_q, num_q ) ) ) ), DELTA_FX ); - denom = L_add( L_add( L_shr( denom_1, sub( denom_1_q, denom_q ) ), L_add( L_shr( denom_2, sub( denom_2_q, denom_q ) ), L_shr( denom_3, sub( denom_3_q, denom_q ) ) ) ), DELTA_FX ); + num = L_add( L_add( L_shr( numer_1, sub( numer_1_q, num_q ) ), L_sub( L_shr( numer_2, sub( numer_2_q, num_q ) ), L_shr( numer_3, sub( numer_3_q, num_q ) ) ) ), DELTA_FX ); /* num_q */ + denom = L_add( L_add( L_shr( denom_1, sub( denom_1_q, denom_q ) ), L_add( L_shr( denom_2, sub( denom_2_q, denom_q ) ), L_shr( denom_3, sub( denom_3_q, denom_q ) ) ) ), DELTA_FX ); /* denom_q */ Word16 q = 0; move16(); sc_fx = BASOP_Util_Divide3232_Scale( num, denom, &q ); @@ -2018,12 +2018,12 @@ static void stereo_cng_compute_LRcorr_fx( move16(); } hCPE->hStereoTD->SP_ratio_LT_fx = L_add_sat( Mpy_32_32( 1932735283, hCPE->hStereoTD->SP_ratio_LT_fx ), - L_shl_sat( Mpy_32_32( 214748364, sqrt_res ), sqrt_q ) ); + L_shl_sat( Mpy_32_32( 214748364, sqrt_res ), sqrt_q ) ); /* sqrt_q */ move32(); IF( LT_16( hCPE->hStereoCng->nr_corr_frames, CM_INIT ) ) { - hCPE->hStereoCng->nr_corr_frames = add( hCPE->hStereoCng->nr_corr_frames, 1 ); + hCPE->hStereoCng->nr_corr_frames = add( hCPE->hStereoCng->nr_corr_frames, 1 ); /* Q0 */ move16(); } @@ -2075,10 +2075,10 @@ static void FindEmEs( #else static void FindEmEs_fx( - const Word32 *ch1_fx, /* i : Left channel */ - const Word32 *ch2_fx, /* i : right channel */ - const Word16 len, /* i : length */ - Word32 *lt_es_em_fx /* i/o: LT energy ratio */ + const Word32 *ch1_fx, /* i : Left channel OUTPUT_Q*/ + const Word32 *ch2_fx, /* i : right channel OUTPUT_Q*/ + const Word16 len, /* i : length Q0*/ + Word32 *lt_es_em_fx /* i/o: LT energy ratio Q24*/ ) { Word16 i; @@ -2098,16 +2098,16 @@ static void FindEmEs_fx( FOR( i = 0; i < len; i++ ) { mono_i_fx = L_add( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_fx = W_add( ener_fx, W_mult0_32_32( mono_i_fx, mono_i_fx ) ); + ener_fx = W_add( ener_fx, W_mult0_32_32( mono_i_fx, mono_i_fx ) ); /* 2 * OUTPUT_Q */ side_i_fx = L_sub( L_shr( ch1_fx[i], 1 ), L_shr( ch2_fx[i], 1 ) ); - ener_side_fx = W_add( ener_side_fx, W_mult0_32_32( side_i_fx, side_i_fx ) ); + ener_side_fx = W_add( ener_side_fx, W_mult0_32_32( side_i_fx, side_i_fx ) ); /* 2 * OUTPUT_Q */ } headroom_left_ener_fx = W_norm( ener_fx ); headroom_left_ener_side_fx = W_norm( ener_side_fx ); IF( LT_16( headroom_left_ener_fx, 32 ) ) { - ener_fx = W_shr( ener_fx, sub( 32, headroom_left_ener_fx ) ); + ener_fx = W_shr( ener_fx, sub( 32, headroom_left_ener_fx ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_ener_fx */ ener_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_fx ) ); } ELSE @@ -2117,7 +2117,7 @@ static void FindEmEs_fx( } IF( LT_16( headroom_left_ener_side_fx, 32 ) ) { - ener_side_fx = W_shr( ener_side_fx, sub( 32, headroom_left_ener_side_fx ) ); + ener_side_fx = W_shr( ener_side_fx, sub( 32, headroom_left_ener_side_fx ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_ener_fx */ ener_side_q = sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_ener_side_fx ) ); } ELSE @@ -2129,7 +2129,7 @@ static void FindEmEs_fx( /**es_em = 10 * ( log10( sqrt( ener_side / len ) ) - log10( sqrt( ener / len ) ) ); */ division_res = BASOP_Util_Divide3232_Scale( W_extract_l( ener_side_fx ), W_extract_l( ener_fx ), &temp_q ); temp_q = sub( temp_q, sub( ener_side_q, ener_q ) ); - square_res = Sqrt32( L_deposit_h( extract_l( division_res ) ), &temp_q ); + square_res = Sqrt32( L_deposit_h( extract_l( division_res ) ), &temp_q ); /* temp_q */ IF( temp_q < 0 ) { square_res = L_shr( square_res, ( -temp_q ) ); @@ -2137,9 +2137,9 @@ static void FindEmEs_fx( move16(); } log_res = BASOP_Util_Log2( square_res ); - es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30 + es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30-31 /* long-term estimate */ - *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); + *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); /* Q24 */ move32(); return; } @@ -2264,10 +2264,10 @@ void stereo_cna_update_params( } #else void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal */ - const Word16 output_frame, /* i : Output frame length */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -2303,7 +2303,7 @@ void stereo_cna_update_params_fx( FindEmEs_fx( output_fx[0], output_fx[1], output_frame, &hCPE->lt_es_em_fx ); - hCPE->hStereoCng->first_SID_after_TD = 1; + hCPE->hStereoCng->first_SID_after_TD = 1; /* Q0 */ move16(); stereo_cng_compute_LRcorr_fx( hCPE, output_fx, output_frame, tdm_ratio_idx ); } @@ -2335,9 +2335,9 @@ void stereo_cna_update_params_fx( { FOR( i = 0; i < output_frame; i++ ) { - enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); - enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); - dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); + enrL_fx = W_add( enrL_fx, W_mult0_32_32( output_fx[0][i], output_fx[0][i] ) ); /* 2 * OUTPUT_Q */ + enrR_fx = W_add( enrR_fx, W_mult0_32_32( output_fx[1][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ + dotLR_fx = W_add( dotLR_fx, W_mult0_32_32( output_fx[0][i], output_fx[1][i] ) ); /* 2 * OUTPUT_Q */ } dotLR_fx = W_add( dotLR_fx, EPSILON_FX_SMALL ); if ( dotLR_fx < 0 ) @@ -2351,7 +2351,7 @@ void stereo_cna_update_params_fx( IF( LT_16( headroom_left_x, 32 ) ) { - enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_x ) ); + enrL_fx = W_shr( enrL_fx, sub( 32, headroom_left_x ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_x */ x_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ); } ELSE @@ -2360,7 +2360,7 @@ void stereo_cna_update_params_fx( } IF( LT_16( headroom_left_y, 32 ) ) { - enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_y ) ); + enrR_fx = W_shr( enrR_fx, sub( 32, headroom_left_y ) ); /* 2 * OUTPUT_Q - 32 * headroom_left_x */ y_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_y ) ) ); } ELSE @@ -2375,21 +2375,21 @@ void stereo_cna_update_params_fx( temp_x_inv = ISqrt32( W_extract_l( enrL_fx ), &x_inv_q ); temp_y_inv = ISqrt32( W_extract_l( enrR_fx ), &y_inv_q ); - energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* x_inv_q + y_inv_q */ temp_res_q = add( x_inv_q, y_inv_q ); headroom_left_dotLR_fx = W_norm( dotLR_fx ); dotLR_fx_q = OUTPUT_Q * 2; move16(); IF( LT_16( headroom_left_dotLR_fx, 32 ) ) { - dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR_fx ) ); + dotLR_fx = W_shr( dotLR_fx, sub( 32, headroom_left_dotLR_fx ) ); /* dotLR_fx_q - (32 * headroom_left_dotLR_fx) */ dotLR_fx_q = sub( dotLR_fx_q, sub( 32, headroom_left_dotLR_fx ) ); } - dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); + dotLR_fx = Mpy_32_32( W_extract_l( dotLR_fx ), energy_xy_fx ); /* dotLR_fx_q + ((31 - temp_res_q) - 31)) */ dotLR_fx_q = add( dotLR_fx_q, sub( sub( 31, temp_res_q ), 31 ) ); - dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); + dotLR_fx = W_deposit32_l( L_shl_sat( W_extract_l( dotLR_fx ), sub( 31, dotLR_fx_q ) ) ); /* Q31 */ /* estimate L/R correlation factor and ILD in time domain */ - c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); + c_LR_fx = extract_h( W_extract_l( dotLR_fx ) ); /* Q15 */ temp_res_q = 0; move16(); @@ -2401,7 +2401,7 @@ void stereo_cna_update_params_fx( { c_q = 31; move16(); - c_fx = L_shr_sat( c_fx, sub( c_q, 31 ) ); + c_fx = L_shr_sat( c_fx, sub( c_q, 31 ) ); /* Q31 */ one_in_c_q = ONE_IN_Q31; move32(); } @@ -2418,7 +2418,7 @@ void stereo_cna_update_params_fx( move16(); temp_res_q = 0; move16(); - c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); + c_ILD_fx = BASOP_Util_Divide3232_Scale( L_shl_sat( num_c_fx, min_headroom_left ), L_shl_sat( denom_c_fx, min_headroom_left ), &temp_res_q ); /* temp_res_q */ IF( temp_res_q < 0 ) { c_ILD_fx = L_shr( c_ILD_fx, negate( temp_res_q ) ); @@ -2436,11 +2436,11 @@ void stereo_cna_update_params_fx( ELSE { hFdCngDec->cna_LR_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_LR_CORR_LT_FILT_FX, hFdCngDec->cna_LR_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_LR_CORR_LT_FILT_FX ), extract_l( c_LR_fx ) ) ) ); /* Q31 */ move16(); hFdCngDec->cna_ILD_LT_fx = extract_h( L_add_sat( Mpy_32_16_1( STEREO_CNA_ILD_LT_FILT_FX, hFdCngDec->cna_ILD_LT_fx ), - Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), extract_l( c_ILD_fx ) ) ) ); + Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_CNA_ILD_LT_FILT_FX ), extract_l( c_ILD_fx ) ) ) ); /* Q31 */ move16(); } @@ -2463,19 +2463,19 @@ void stereo_cna_update_params_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { /* quickly decrease in TD stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); + hFdCngDec->cna_act_fact_fx = extract_h( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ) ); /* Q15 */ move16(); } ELSE IF( GT_32( L_mult0( sts[0]->VAD, MAX_WORD16 ), hFdCngDec->cna_act_fact_fx ) ) // VAD is one bit { /* quickly increase during active frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ), ( 644245094 * sts[0]->VAD ) ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 1503238553, hFdCngDec->cna_act_fact_fx ), ( 644245094 * sts[0]->VAD ) ) ); /* Q15 */ move16(); } ELSE { /* slowly decrease during inactive frames in DFT stereo mode */ - hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ), ( 107374184 * sts[0]->VAD ) ) ); + hFdCngDec->cna_act_fact_fx = extract_h( L_add( Mpy_32_16_1( 2040109440, hFdCngDec->cna_act_fact_fx ), ( 107374184 * sts[0]->VAD ) ) ); /* Q15 */ move16(); } } @@ -2521,8 +2521,8 @@ void stereo_cng_init_dec( } #else void stereo_cng_init_dec_fx( - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ - const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 Q0*/ ) { hStereoCng->prev_sid_nodata = 0; diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 4e65044dabe4661b4b7f2fac2df736b199dc4bb4..3d4adac216f7951f58f5211566bcadd6639405a0 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -663,14 +663,14 @@ void stereo_dft_dec_destroy( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_analyze_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal */ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 chan, /* i : channel number */ - const Word16 input_frame, /* i : input frame size */ - const Word16 output_frame, /* i : output frame size */ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const Word16 k_offset, /* i : offset of DFT */ - const Word16 delay, /* i : delay in samples FOR input signal */ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_out_DFT ) { @@ -704,86 +704,86 @@ void stereo_dft_dec_analyze_fx( IF( EQ_16( input_frame, output_frame ) ) { trigo_fx = hStereoDft->dft_trigo_fx; - trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); - win_right_fx = hStereoDft->win32ms_fx; - win_left_fx = hStereoDft->win32ms_fx; - win2_fx = hStereoDft->win232ms_fx; + trigo_step = i_mult( hStereoDft->dft_trigo_step, STEREO_DFT_TRIGO_DEC_STEP ); /* Q0 */ + win_right_fx = hStereoDft->win32ms_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME ) ) { - trigo_fx = hStereoDft->dft_trigo_12k8_fx; + trigo_fx = hStereoDft->dft_trigo_12k8_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_12k8_fx; - win_left_fx = hStereoDft->win32ms_12k8_fx; - win2_fx = hStereoDft->win232ms_12k8_fx; + win_right_fx = hStereoDft->win32ms_12k8_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_12k8_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_12k8_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { assert( ( chan == 1 ) && "12.8kHz sampling rate only FOR second channel, i.e. residual coding or allpass signal" ); - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME16k ) ) { - trigo_fx = hStereoDft->dft_trigo_16k_fx; + trigo_fx = hStereoDft->dft_trigo_16k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_16k_fx; - win_left_fx = hStereoDft->win32ms_16k_fx; - win2_fx = hStereoDft->win232ms_16k_fx; + win_right_fx = hStereoDft->win32ms_16k_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_16k_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_16k_fx; /* Q15 */ test(); IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { assert( ( chan == 0 ) && "DFT stereo: BPF memory only FOR M channel" ); - mem_fx = hCPE->input_mem_BPF_fx[chan]; + mem_fx = hCPE->input_mem_BPF_fx[chan]; /* Q11 */ } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB_ADD ) ) { - mem_fx = hCPE->input_mem_LB_fx[chan]; + mem_fx = hCPE->input_mem_LB_fx[chan]; /* Q11 */ } ELSE { assert( ( chan == 1 ) && ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) && "16kHz sampling rate only FOR second channel with allpass signal" ); - mem_fx = hCPE->input_mem_fx[chan]; + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } } ELSE IF( EQ_16( input_frame, L_FRAME8k ) ) { assert( ( chan == 1 ) && "DFT stereo: 8kHz analysis only FOR residual coding" ); - trigo_fx = hStereoDft->dft_trigo_8k_fx; + trigo_fx = hStereoDft->dft_trigo_8k_fx; /* Q15 */ trigo_step = STEREO_DFT_TRIGO_SRATE_8k_STEP * STEREO_DFT_TRIGO_DEC_STEP; move16(); - win_right_fx = hStereoDft->win32ms_8k_fx; - win_left_fx = hStereoDft->win32ms_8k_fx; - win2_fx = hStereoDft->win232ms_8k_fx; - mem_fx = hCPE->input_mem_fx[chan]; + win_right_fx = hStereoDft->win32ms_8k_fx; /* Q15 */ + win_left_fx = hStereoDft->win32ms_8k_fx; /* Q15 */ + win2_fx = hStereoDft->win232ms_8k_fx; /* Q15 */ + mem_fx = hCPE->input_mem_fx[chan]; /* Q11 */ } ELSE { @@ -797,7 +797,7 @@ void stereo_dft_dec_analyze_fx( win2_fx = NULL; /* to avoid compilation warning */ } - inputFs = L_mult0( input_frame, FRAMES_PER_SEC ); + inputFs = L_mult0( input_frame, FRAMES_PER_SEC ); /* Q0 */ delay_dec = NS2SA_FX2( inputFs, STEREO_DFT32MS_OVL_NS ); move16(); zp = NS2SA_FX2( inputFs, STEREO_DFT32MS_ZP_NS ); @@ -806,7 +806,7 @@ void stereo_dft_dec_analyze_fx( move16(); NFFT = NS2SA_FX2( inputFs, STEREO_DFT32MS_N_NS ); Word16 qfac_fx; - fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); + fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); /* qfac_fx */ qfac_fx = sub( 31, qfac_fx ); ovl2 = NS2SA_FX2( inputFs, STEREO_DFT32MS_OVL2_NS ); move16(); @@ -816,10 +816,10 @@ void stereo_dft_dec_analyze_fx( mem_size = add( delay_dec, delay ); /* Update buffers */ - Copy32( mem_fx, input_buff_fx, mem_size ); - Copy32( input_fx, input_buff_fx + mem_size, input_frame ); - Copy32( input_buff_fx + input_frame, mem_fx, mem_size ); - pInput_buff_fx = input_buff_fx; + Copy32( mem_fx, input_buff_fx, mem_size ); /* Q11 */ + Copy32( input_fx, input_buff_fx + mem_size, input_frame ); /* q */ + Copy32( input_buff_fx + input_frame, mem_fx, mem_size ); /* q */ + pInput_buff_fx = input_buff_fx; /* q */ test(); IF( EQ_16( hCPE->nchan_out, 1 ) && ( hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) @@ -835,17 +835,17 @@ void stereo_dft_dec_analyze_fx( assert( ( k_offset <= STEREO_DFT_NBDIV ) ); - FOR( i = 0; i < shr( NFFT, 2 ); i++ ) + FOR( i = 0; i < NFFT / 4; i++ ) { - trigo_dec_fx[i] = trigo_fx[i_mult( i, trigo_step )]; + trigo_dec_fx[i] = trigo_fx[i * trigo_step]; move16(); - trigo_dec_fx[sub( NFFT / 2, i )] = trigo_fx[i_mult( i, trigo_step )]; + trigo_dec_fx[NFFT / 2 - i] = trigo_fx[i * trigo_step]; move16(); } - trigo_dec_fx[NFFT / 4] = trigo_fx[i_mult( NFFT / 4, trigo_step )]; + trigo_dec_fx[NFFT / 4] = trigo_fx[NFFT / 4 * trigo_step]; move16(); - FOR( k = 0; k < sub( STEREO_DFT_NBDIV, k_offset ); k++ ) + FOR( k = 0; k < STEREO_DFT_NBDIV - k_offset; k++ ) { set32_fx( DFT_fx, 0, STEREO_DFT32MS_N_MAX ); IF( k == 0 ) @@ -860,24 +860,24 @@ void stereo_dft_dec_analyze_fx( move16(); } - pInput_fx = pInput_buff_fx + offset; - pDFT_out_fx = out_DFT_fx[chan] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pInput_fx = pInput_buff_fx + offset; /* q */ + pDFT_out_fx = out_DFT_fx[chan] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* q_out_DFT */ /*Forwards FFT: L and R*/ /* Zero Padding & Flat Portion */ - Copy32( pInput_fx, DFT_fx + zp, sub( NFFT, i_mult( 2, zp ) ) ); + Copy32( pInput_fx, DFT_fx + zp, sub( NFFT, i_mult( 2, zp ) ) ); /* q */ /* Overlapping portions */ IF( k == 0 ) { FOR( i = 0; i < ovl; i++ ) { - DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win_left_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win_left_fx[STEREO_DFT32MS_STEP * i] ); /* q */ move32(); } FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), 1 ), i )], win2_fx[i] ); + DFT_fx[NFFT - zp - 1 - i] = Mpy_32_16_1( DFT_fx[NFFT - zp - 1 - i], win2_fx[i] ); /* q */ move32(); } } @@ -885,12 +885,12 @@ void stereo_dft_dec_analyze_fx( { FOR( i = 0; i < ovl2; i++ ) { - DFT_fx[add( i, zp )] = Mpy_32_16_1( DFT_fx[add( i, zp )], win2_fx[i] ); + DFT_fx[i + zp] = Mpy_32_16_1( DFT_fx[i + zp], win2_fx[i] ); /* q */ move32(); } FOR( i = 0; i < ovl; i++ ) { - DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )] = Mpy_32_16_1( DFT_fx[sub( sub( sub( NFFT, zp ), i ), 1 )], win_right_fx[i_mult( STEREO_DFT32MS_STEP, i )] ); + DFT_fx[NFFT - zp - i - 1] = Mpy_32_16_1( DFT_fx[NFFT - zp - i - 1], win_right_fx[STEREO_DFT32MS_STEP * i] ); /* q */ move32(); } } @@ -902,7 +902,7 @@ void stereo_dft_dec_analyze_fx( FOR( Word16 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); /* q + q_shift*/ move32(); } @@ -913,7 +913,7 @@ void stereo_dft_dec_analyze_fx( q_shift = sub( L_norm_arr( DFT_fx, NFFT ), sub( 31, qfac_fx ) ); FOR( Word16 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); + DFT_fx[j] = L_shl( DFT_fx[j], q_shift ); /* q + q_shift */ move32(); } q_DFT = add( q_DFT, q_shift ); @@ -921,7 +921,7 @@ void stereo_dft_dec_analyze_fx( { FOR( Word32 j = 0; j < NFFT; j++ ) { - out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], sub( q_out_DFT[chan], q_DFT ) ); + out_DFT_fx[chan][j] = L_shr( out_DFT_fx[chan][j], sub( q_out_DFT[chan], q_DFT ) ); /* q_DFT */ move32(); } q_out_DFT[chan] = q_DFT; @@ -931,7 +931,7 @@ void stereo_dft_dec_analyze_fx( { FOR( Word32 j = 0; j < NFFT; j++ ) { - DFT_fx[j] = L_shr( DFT_fx[j], sub( q_DFT, q_out_DFT[chan] ) ); + DFT_fx[j] = L_shr( DFT_fx[j], sub( q_DFT, q_out_DFT[chan] ) ); /* q_DFT */ move32(); } q_DFT = q_out_DFT[chan]; @@ -943,11 +943,11 @@ void stereo_dft_dec_analyze_fx( test(); IF( ( ana_type == DFT_STEREO_DEC_ANA_FB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_LB ) || EQ_32( ana_type, DFT_STEREO_DEC_ANA_NOCORE ) ) { - pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ); /*DC*/ + pDFT_out_fx[0] = L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ); /*DC*/ /* qDFT */ move32(); IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ); + pDFT_out_fx[1] = L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ); /* qDFT */ move32(); } ELSE @@ -957,51 +957,51 @@ void stereo_dft_dec_analyze_fx( } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ); + pDFT_out_fx[i] = L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ); /* qDFT */ move32(); } FOR( i = NFFT; i < hStereoDft->NFFT; i++ ) { - pDFT_out_fx[i] = 0; + pDFT_out_fx[i] = 0; /* qDFT */ move32(); } } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_BPF ) ) { - pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[0] = L_sub( pDFT_out_fx[0], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[0], fac_fx ), dft_bpf_weights_fx[0] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); FOR( i = 1; i < STEREO_DFT_BPF_SIZE; i++ ) { - pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[2 * i] = L_sub( pDFT_out_fx[2 * i], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); - pDFT_out_fx[add( 2 * i, 1 )] = L_sub( pDFT_out_fx[add( 2 * i, 1 )], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[add( 2 * i, 1 )], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); + pDFT_out_fx[2 * i + 1] = L_sub( pDFT_out_fx[2 * i + 1], L_shl( Mpy_32_32( Mpy_32_32( DFT_fx[2 * i + 1], fac_fx ), dft_bpf_weights_fx[i] ), sub( 32, qfac_fx ) ) ); /* qDFT */ move32(); } } ELSE IF( EQ_32( ana_type, DFT_STEREO_DEC_ANA_HB_ADD ) ) { - NFFT_core = NS2SA_FX2( L_mult0( hCPE->hCoreCoder[0]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_N_NS ); + NFFT_core = NS2SA_FX2( L_mult0( hCPE->hCoreCoder[0]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_N_NS ); /* Q0 */ move16(); FOR( i = NFFT_core; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); /* qDFT */ move32(); } } ELSE { - pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ) ); /*DC*/ + pDFT_out_fx[0] = L_add( pDFT_out_fx[0], L_shl( Mpy_32_32( DFT_fx[0], fac_fx ), sub( 31, qfac_fx ) ) ); /*DC*/ /* qDFT */ move32(); IF( EQ_16( NFFT, hStereoDft->NFFT ) ) /*Nyquist*/ { - pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[1] ); + pDFT_out_fx[1] = L_add( L_shl( Mpy_32_32( DFT_fx[1], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[1] ); /* qDFT */ move32(); } FOR( i = 2; i < NFFT; i++ ) { - pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); + pDFT_out_fx[i] = L_add( L_shl( Mpy_32_32( DFT_fx[i], fac_fx ), sub( 31, qfac_fx ) ), pDFT_out_fx[i] ); /* qDFT */ move32(); } } diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index f1b7055e4a536de275a31390c4f7db84f1c7e428..2613f09d08444294b0ad0a974cd762049515a7f5 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -72,9 +72,9 @@ void stereo_dft_dmx_out_reset_fx( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ ) { - hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - hStereoDftDmx->prevTargetGain_fx = ONE_IN_Q29; + hStereoDftDmx->prevTargetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); set32_fx( hStereoDftDmx->memOutHB_fx, 0, NS2SA_FX2( 48000, STEREO_DFT32MS_OVL_NS ) ); @@ -94,11 +94,11 @@ void stereo_dft_dmx_out_reset_fx( #ifdef IVAS_FLOAT_FIXED void stereo_dft_unify_dmx_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - const Word16 prev_sid_nodata /* i : Previous SID/No data indicator */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers hStereoDft->qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis Q11*/ + const Word16 prev_sid_nodata /* i : Previous SID/No data indicator Q0*/ ) { Word16 i, k, b, N_div; @@ -122,11 +122,11 @@ void stereo_dft_unify_dmx_fx( Word16 num_plocs; Word32 plocsi[STEREO_DFT_RES_N_PEAKS_MAX]; - output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ samp_ratio = BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio ); samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) ); - prev_bfi = st0->prev_old_bfi; + prev_bfi = st0->prev_old_bfi; /* Q0 */ move32(); /* Initialization */ @@ -158,7 +158,7 @@ void stereo_dft_unify_dmx_fx( test(); test(); hStereoDft->trans = (Word16) ( ( EQ_16( st0->clas_dec, ONSET ) || EQ_16( st0->clas_dec, SIN_ONSET ) || EQ_16( st0->clas_dec, UNVOICED_CLAS ) || EQ_16( st0->clas_dec, UNVOICED_TRANSITION ) ) || LE_16( st0->stab_fac_fx, (Word16) 0x2000 ) ) || - ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); + ( ( EQ_16( st0->core, TCX_20_CORE ) && ( EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) || EQ_16( st0->hTcxCfg->tcx_last_overlap_mode, HALF_OVERLAP ) ) ) || EQ_16( st0->core, TCX_10_CORE ) ); /* Q0 */ move16(); /* Smoothing for the current frame */ @@ -166,15 +166,15 @@ void stereo_dft_unify_dmx_fx( FOR( k = 0; k < N_div; k++ ) { - pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); - pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); + pDFT_DMX = DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ + pDFT_RES = DFT[1] + i_mult( k, STEREO_DFT32MS_N_MAX ); /* qDFT */ assert( hStereoDft->hConfig->dmx_active ); /*Apply Stereo*/ g = MAX_16; move16(); /* since delay is just 3.125ms, the parameters received are used for the second window */ - pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pSideGain = hStereoDft->side_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ /* Stereo residual PLC */ IF( hStereoDft->res_cod_band_max > 0 ) @@ -183,7 +183,7 @@ void stereo_dft_unify_dmx_fx( { IF( EQ_16( k, 1 ) ) { - Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); + Copy32( pDFT_RES, hStereoDft->res_mem_fx, shl( hStereoDft->band_limits[hStereoDft->res_cod_band_max], 1 ) ); /* qDFT */ hStereoDft->q_res_mem = hStereoDft->q_dft; move16(); hStereoDft->time_offs = 0; @@ -194,7 +194,7 @@ void stereo_dft_unify_dmx_fx( { hStereoDft->nbands = hStereoDft->res_cod_band_max; /* Limit nbands since residual PLC only needs the low frequency range of the stereo filling */ move16(); - pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); + pPredGain = hStereoDft->res_pred_gain_fx + i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ); /* Q31 */ hStereoDft->past_DMX_pos = ( sub( add( hStereoDft->past_DMX_pos, STEREO_DFT_PAST_MAX ), 1 ) ) % STEREO_DFT_PAST_MAX; move16(); stereo_dft_generate_res_pred_fx( hStereoDft, samp_ratio, pDFT_DMX, DFT_PRED_RES, pPredGain, k, DFT[1] + k * STEREO_DFT32MS_N_MAX, &stop, st0->bfi ); @@ -206,7 +206,7 @@ void stereo_dft_unify_dmx_fx( /* Apply active DMX */ - DFT_L[0] = pDFT_DMX[0]; + DFT_L[0] = pDFT_DMX[0]; /* qDFT */ move32(); DFT_R[0] = pDFT_DMX[0]; move32(); @@ -214,23 +214,23 @@ void stereo_dft_unify_dmx_fx( /* upmix residual part */ FOR( b = 0; b < hStereoDft->res_cod_band_max; b++ ) { - g = extract_h( pSideGain[b] ); + g = extract_h( pSideGain[b] ); /* Q15 */ move16(); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); + tmp = Madd_32_16( pDFT_RES[2 * i], pDFT_DMX[2 * i], g ); /* qDFT */ - DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); + DFT_L[2 * i] = L_add( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); - DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); + DFT_R[2 * i] = L_sub( pDFT_DMX[2 * i], tmp ); /* qDFT */ move32(); tmp = Madd_32_16( pDFT_RES[2 * i + 1], pDFT_DMX[2 * i + 1], g ); - DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); + DFT_L[2 * i + 1] = L_add( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); - DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); + DFT_R[2 * i + 1] = L_sub( pDFT_DMX[2 * i + 1], tmp ); /* qDFT */ move32(); } } @@ -253,11 +253,11 @@ void stereo_dft_unify_dmx_fx( FOR( j = hStereoDft->band_limits[b]; j < hStereoDft->band_limits[b + 1]; j++ ) { - sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( DFT_L[2 * j], DFT_L[2 * j] ), W_mult_32_32( DFT_L[add( shl( j, 1 ), 1 )], DFT_L[add( shl( j, 1 ), 1 )] ) ) ); - sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( DFT_R[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_R[add( shl( j, 1 ), 1 )], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); + sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( DFT_L[2 * j], DFT_L[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_L[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ + sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( DFT_R[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_R[2 * j + 1], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ - dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); - dot_prod_img = W_add( dot_prod_img, W_sub( W_mult_32_32( DFT_L[add( shl( j, 1 ), 1 )], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j], DFT_R[add( shl( j, 1 ), 1 )] ) ) ); + dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j + 1], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ + dot_prod_img = W_add( dot_prod_img, W_sub( W_mult_32_32( DFT_L[2 * j + 1], DFT_R[2 * j] ), W_mult_32_32( DFT_L[2 * j], DFT_R[2 * j + 1] ) ) ); /* 2 * q_dft + 1 */ } norm_sum_nrg_L = W_norm( sum_nrg_L ); @@ -281,7 +281,7 @@ void stereo_dft_unify_dmx_fx( exp_dot_prod_abs = sub( 31, sub( shl( q_dot_prod_real, 1 ), 31 ) ); exp_sum_nrg_Mid = sub( 31, q_sum_nrg_L ); - sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); + sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); /* q_sum_nrg_L */ Word32 tmp_nrg_L = Sqrt32( sum_nrg_L_32, &exp_sum_nrg_l ); Word32 tmp_nrg_R = Sqrt32( sum_nrg_R_32, &exp_sum_nrg_R ); @@ -296,7 +296,7 @@ void stereo_dft_unify_dmx_fx( exp_sum_abs = add( exp_sum_abs, 1 ); sum_abs = L_add( L_shr( tmp_nrg_L, sub( exp_sum_abs, exp_sum_nrg_l ) ), L_shr( tmp_nrg_R, sub( exp_sum_abs, exp_sum_nrg_R ) ) ); dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_img_32, dot_prod_img_32 ) ), &exp_dot_prod_abs ); - Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, sub( sub( 31, exp_dot_prod_abs ), q_sum_nrg_L ) ) ); + Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, sub( sub( 31, exp_dot_prod_abs ), q_sum_nrg_L ) ) ); /* q_sum_nrg_L */ Word16 E_num = sub( 31, q_sum_nrg_L ); Word32 num_sqrt = Sqrt32( num, &E_num ); Word16 exp_wR = exp_sum_abs; @@ -322,7 +322,7 @@ void stereo_dft_unify_dmx_fx( } ELSE { - wR_temp = shr( divide3232( L_shr( num_sqrt, sub( exp_wR, E_num ) ), L_shr( sum_abs, sub( exp_wR, exp_sum_abs ) ) ), 2 ); + wR_temp = shr( divide3232( L_shr( num_sqrt, sub( exp_wR, E_num ) ), L_shr( sum_abs, sub( exp_wR, exp_sum_abs ) ) ), 2 ); /* Q13 */ } Word32 sum_nrg_Mid_sqrt = Sqrt32( sum_nrg_Mid, &exp_sum_nrg_Mid ); @@ -339,12 +339,12 @@ void stereo_dft_unify_dmx_fx( test(); IF( sum_nrg_Mid_sqrt == 0 && sum_abs == 0 ) { - wL_temp = 6364; + wL_temp = 6364; /* Q13 */ move16(); } ELSE IF( sum_nrg_Mid_sqrt == 0 && sum_abs != 0 ) { - wL_temp = 5793; + wL_temp = 5793; /* Q13 */ move16(); } ELSE @@ -365,12 +365,12 @@ void stereo_dft_unify_dmx_fx( move32(); } } - Copy32( pDFT_DMX, DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ), hStereoDft->NFFT ); + Copy32( pDFT_DMX, DFT[0] + i_mult( k, STEREO_DFT32MS_N_MAX ), hStereoDft->NFFT ); /* hStereoDft->q_dft */ /* Update DFT_past_DMX, needed for stereo filling used by stereo residual PLC */ - hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX; + hStereoDft->past_DMX_pos = ( hStereoDft->past_DMX_pos + 1 ) % STEREO_DFT_PAST_MAX; /* Q0 */ move16(); - Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); + Copy32( pDFT_DMX, hStereoDft->DFT_past_DMX_fx[hStereoDft->past_DMX_pos], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ) ); /* hStereoDft->q_dft */ hStereoDft->q_DFT_past_DMX_fx[hStereoDft->past_DMX_pos] = hStereoDft->q_dft; move16(); test(); @@ -387,7 +387,7 @@ void stereo_dft_unify_dmx_fx( q_shift1 = sub( hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[idx_k1] ); /*dmx energy memory*/ - hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); + hStereoDft->past_dmx_nrg_fx = stereo_dft_dmx_swb_nrg_fx( hStereoDft->DFT_past_DMX_fx[idx_k0], hStereoDft->DFT_past_DMX_fx[idx_k1], s_min( hStereoDft->NFFT, STEREO_DFT32MS_N_32k ), q_shift0, q_shift1 ); /* 2 * q_dft */ move32(); } } @@ -665,11 +665,11 @@ void add_HB_to_mono_dmx( } #else void add_HB_to_mono_dmx_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output[L_FRAME48k], /* i/o: output synthesis */ - Word32 outputHB[L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output[L_FRAME48k], /* i/o: output synthesis Qx*/ + Word32 outputHB[L_FRAME48k], /* i : HB synthesis Q11*/ + const Word16 last_core, /* i : last core, primary channel Q0*/ + const Word16 output_frame /* i : frame length Q0*/ ) { Word16 i, j, decoderDelay, icbweOLASize, dftOvlLen, memOffset; @@ -682,10 +682,10 @@ void add_HB_to_mono_dmx_fx( Word32 output_Fs; Word32 *memOutHB_fx, *memTransitionHB_fx; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; - memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; + memOutHB_fx = hCPE->hStereoDftDmx->memOutHB_fx; /* Q11 */ + memTransitionHB_fx = hCPE->hStereoDftDmx->memTransitionHB_fx; /* Q11 */ memOffset = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); move16(); @@ -729,24 +729,24 @@ void add_HB_to_mono_dmx_fx( } alpha_fx = winSlope_fx; // Q30 move32(); - FOR( ; i < add( decoderDelay, icbweOLASize ); i++ ) + FOR( ; i < decoderDelay + icbweOLASize; i++ ) { - temp_fx[i] = L_shl( Mpy_32_32( temp_fx[i], alpha_fx ), 1 ); + temp_fx[i] = L_shl( Mpy_32_32( temp_fx[i], alpha_fx ), 1 ); // Q30 move32(); - alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); + alpha_fx = L_add_sat( alpha_fx, winSlope_fx ); /* Q30 */ } } ELSE { - Copy32( memOutHB_fx, temp_fx, memOffset ); + Copy32( memOutHB_fx, temp_fx, memOffset ); /* Q11 */ } v_add_32( temp_fx, output, output, output_frame ); - Copy32( outputHB + sub( output_frame, memOffset ), memOutHB_fx, memOffset ); + Copy32( outputHB + sub( output_frame, memOffset ), memOutHB_fx, memOffset ); /* Q11 */ - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ @@ -754,16 +754,16 @@ void add_HB_to_mono_dmx_fx( move16(); FOR( i = 0; i < memOffset; i++ ) { - memTransitionHB_fx[i] = Mpy_32_16_1( memOutHB_fx[i], win_dft_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) )] ); + memTransitionHB_fx[i] = Mpy_32_16_1( memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); /* Q11 */ move32(); - j = add( j, 1 ); + j++; } FOR( i = 0; j < dftOvlLen; i++ ) { - memTransitionHB_fx[add( memOffset, i )] = Mpy_32_16_1( outputHB[sub( output_frame, i ) - 1], win_dft_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) )] ); + memTransitionHB_fx[memOffset + i] = Mpy_32_16_1( outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * ( dftOvlLen - 1 - j )] ); /* Q11 */ move32(); - j = add( j, 1 ); + j++; } } ELSE diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 77b055e3231c27841e491221b6c5e7e658f4235d..f5e997e626d273132f2ac241ff4aa7b13cde8c18 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -80,65 +80,6 @@ void init_coder_ace_plus_ivas_fx( Word16 L_frame_old; /*keep old frame size for switching */ Word16 L_subfr; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hTcxEnc != NULL ) - { - hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ - move16(); - - IF( st->ini_frame == 0 ) - { - set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); - hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; - hTcxEnc->tcx_target_bits_fac_flt = 1.0f; - } - } - - IF( st->hBWE_TD != NULL ) - { - set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); - } - - st->currEnergyHF = 0; - - IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - - /* Initialize TCX */ - IF( hTcxEnc != NULL ) - { - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); - } - - /* Initialize Signal Buffers */ - f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); - f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); - f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); - f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); - f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); - - /* Initialize ACELP */ - if ( st->lspold_enc != NULL ) - { - floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); - } - if ( st->lsp_old1 != NULL ) - { - floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); - } - if ( st->lsp_old != NULL ) - { - floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); - } - - /* Adaptive BPF */ - set_zero( st->mem_bpf, 2 * L_FILT16k ); - set_zero( st->mem_error_bpf, 2 * L_FILT16k ); -#endif - /* Bitrate */ st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); move16(); @@ -261,9 +202,6 @@ void init_coder_ace_plus_ivas_fx( test(); IF( st->igf && st->hIGFEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); -#endif IGFEncSetMode_ivas_fx( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); } ELSE IF( st->hIGFEnc != NULL ) @@ -275,11 +213,9 @@ void init_coder_ace_plus_ivas_fx( } /* Initialize Core Signal Analysis Module */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_core_sig_ana( st ); -#endif init_core_sig_ana_ivas_fx( st ); + /* Initialize TCX */ IF( hTcxEnc != NULL ) { @@ -295,9 +231,6 @@ void init_coder_ace_plus_ivas_fx( init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate ); #endif /* Initialize ACELP */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_acelp( st, L_frame_old, st->total_brate, last_total_brate ); -#endif init_acelp_ivas_fx( st, L_frame_old, 0 ); @@ -349,9 +282,6 @@ void init_coder_ace_plus_ivas_fx( move16(); /* Initialize ACELP/TCX Modes */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_modes( st, last_total_brate ); -#endif init_modes_ivas_fx( st, last_total_brate ); /* Adaptive BPF */ @@ -786,6 +716,7 @@ static void init_tcx( #ifdef IVAS_FLOAT_FIXED hTcxEnc->spectrum_fx[0] = hTcxEnc->spectrum_long_fx; hTcxEnc->spectrum_fx[1] = hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); #endif init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, @@ -1621,7 +1552,8 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); move16(); - + hLPDmem->e_old_exc = 0; + move16(); /*Resamp others memories*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 4b11e2b8d69397362307d4898a1cd80b84e144c2..e3cd4c6016ab020165c041b25a8a354bce33e960 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -200,7 +200,77 @@ void core_coder_mode_switch_ivas_fx( { st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( hTcxEnc != NULL ) + { + hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ + move16(); + + IF( st->ini_frame == 0 ) + { + set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); + hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; + hTcxEnc->tcx_target_bits_fac_flt = 1.0f; + } + } + + IF( st->hBWE_TD != NULL ) + { + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); + } + + st->currEnergyHF = 0; + + IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) + { + set_f( st->mem_MA, 0.0f, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + /* Initialize TCX */ + IF( hTcxEnc != NULL ) + { + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); + } + + /* Initialize Signal Buffers */ + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); + f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); + f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); + f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); + + /* Initialize ACELP */ + if ( st->lspold_enc != NULL ) + { + floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); + } + if ( st->lsp_old1 != NULL ) + { + floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); + } + if ( st->lsp_old != NULL ) + { + floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); + } + + /* Adaptive BPF */ + set_zero( st->mem_bpf, 2 * L_FILT16k ); + set_zero( st->mem_error_bpf, 2 * L_FILT16k ); +#endif init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + IF( st->hLPDmem != NULL ) + { + me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + } + IF( st->igf && st->hIGFEnc != NULL ) + { + 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, N_MAX_TCX - IGF_START_MN ); + } +#endif } test(); diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c index e7688dfbaef1ece0033ed624d3d4ff2a3d31f678..90c1855e87321f283131ab640eb310c1db6314c7 100644 --- a/lib_enc/ext_sig_ana.c +++ b/lib_enc/ext_sig_ana.c @@ -580,58 +580,6 @@ void core_signal_analysis_high_bitrate( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } #endif ProcessIGF_ivas_fx( st, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_fx[frameno], &q_spectrum, powerSpec_fx, &q_powerSpec, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 4acf05384a5be334a797d10739b11ef43609ab16..c38ed7c92b07198ba9d93c7944bb0378f80f9bf2 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -3883,8 +3883,14 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_SB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_FIR_TB_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_FIR_SB_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_IIR_SFB_SB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_IIR_SB_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_TB_fx, 0, IGF_MAX_SFB ); + set16_fx( hPrivateData->prevSFB_IIR_TB_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->sfb_tb_e, 15, IGF_MAX_SFB ); + set16_fx( hPrivateData->sfb_sb_e, 15, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_IIR_SFB_TB_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->prevDampingFactor_IIR_fx, -( ONE_IN_Q15 ), IGF_MAX_SFB ); set16_fx( hPrivateData->prevDampingFactor_IIR_e, 0, IGF_MAX_SFB ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 0e63098c69230f976e9a51489fc5800c860984c5..abbdba3126c166749da3e8ab7ac3d5da2a1e3b37 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -2188,9 +2188,78 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; + IF( hTcxEnc != NULL ) + { + hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ + move16(); - init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); + IF( st->ini_frame == 0 ) + { + set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 ); + hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2; + hTcxEnc->tcx_target_bits_fac_flt = 1.0f; + } + } + + IF( st->hBWE_TD != NULL ) + { + set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); + } + + st->currEnergyHF = 0; + + IF( ( NE_16( st->last_L_frame, st->L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || ( EQ_16( st->last_core, HQ_CORE ) ) ) + { + set_f( st->mem_MA, 0.0f, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + + /* Initialize TCX */ + IF( hTcxEnc != NULL ) + { + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_flt, Q15 ); + } + /* Initialize Signal Buffers */ + f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, st->L_frame ); + f2me_buf_16( st->old_wsp, st->old_wsp_fx, &st->exp_old_wsp, L_WSP_MEM ); + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, L_INP_MEM ); + f2me_buf_16( st->old_inp_16k, st->old_inp_16k_fx, &st->exp_old_inp_16k, L_INP_MEM ); + f2me_buf_16( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc + st->L_frame + L_SUBFR - L_WSP_MEM, &st->exp_old_inp_16k, L_WSP_MEM ); + + /* Initialize ACELP */ + if ( st->lspold_enc != NULL ) + { + floatToFixed_arr16( st->lspold_enc, &st->lspold_enc_fx[0], Q15, M ); + } + if ( st->lsp_old1 != NULL ) + { + floatToFixed_arr16( st->lsp_old1, &st->lsp_old1_fx[0], Q15, M ); + } + if ( st->lsp_old != NULL ) + { + floatToFixed_arr16( st->lsp_old, &st->lsp_old_fx[0], Q15, M ); + } + + /* Adaptive BPF */ + set_zero( st->mem_bpf, 2 * L_FILT16k ); + set_zero( st->mem_error_bpf, 2 * L_FILT16k ); +#endif + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st->preemph_fac_flt = fix16_to_float( st->preemph_fac, Q15 ); + IF( st->hLPDmem != NULL ) + { + me2f_buf_16( st->hLPDmem->old_exc, st->hLPDmem->e_old_exc, st->hLPDmem->old_exc_flt, L_EXC_MEM ); + } + IF( st->igf && st->hIGFEnc != NULL ) + { + 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, N_MAX_TCX - IGF_START_MN ); + } +#endif /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 3206e7ea9e697f23c496f397d03a727ec14c220e..efa570ee96628e893dd9a36041d25c5241e33071 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -46,9 +46,17 @@ /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +static void computeIntensityVector_enc_fx( + const DIRAC_ENC_HANDLE hDirAC, + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ); +#else static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], const int16_t enc_param_start_band, const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ); - +#endif /*------------------------------------------------------------------------- * ivas_dirac_enc_open() @@ -154,6 +162,29 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); +#ifdef IVAS_FLOAT_FIXED + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + IF( ( hDirAC->buffer_intensity_real_fx[i] = (Word32 **) malloc( hDirAC->no_col_avg_diff * sizeof( Word32 * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( ( hDirAC->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->buffer_intensity_real_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } + } + + IF( ( hDirAC->buffer_energy_fx = (Word32 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); +#endif if ( st_ivas->hQMetaData->useLowerRes ) { @@ -409,6 +440,20 @@ void ivas_dirac_enc_close( free( hDirAC->buffer_intensity_real[i] ); hDirAC->buffer_intensity_real[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) + { + free( hDirAC->buffer_intensity_real_fx[i][j] ); + hDirAC->buffer_intensity_real_fx[i][j] = NULL; + } + } + + free( hDirAC->buffer_intensity_real_fx[i] ); + hDirAC->buffer_intensity_real_fx[i] = NULL; +#endif + free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; } @@ -779,6 +824,193 @@ ivas_error ivas_dirac_enc( * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_dirac_get_mono_flag_fx( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count ) /* i/o: current number of mono frames count */ +{ + Word16 brange[2]; + Word16 i, j, ch_idx; + Word32 other_ch_band_power; + Word32 W_band_power; + Word16 any_mc_band = 0; + Word16 any_mono_band = 0; + Word16 local_mono_flag = 0; + Word32 W_band_power_norm; + Word32 threshold = 0; + Word16 W_band_power_e = 0; + Word16 other_ch_band_power_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move32(); + + /* Banded Power Calculations */ + FOR( i = 0; i < DIRAC_MAX_NBANDS; i++ ) + { + W_band_power = 0; + other_ch_band_power = 0; + move32(); + move32(); + + brange[0] = band_grouping[i]; + brange[1] = band_grouping[i + 1]; + move16(); + move16(); + + Word64 acc = 0, acc1 = 0; + move64(); + move64(); + + Word16 shift1 = 0; + Word16 shift2 = 0; + move16(); + move16(); + + /* Loop over the W channel bins to calculate the power in the band */ + FOR( j = brange[0]; j < brange[1]; j++ ) + { + acc = W_mac_32_32( acc, Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); + acc = W_mac_32_32( acc, Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); + shift1 = W_norm( acc ); + W_band_power = W_extract_h( W_shl( acc, shift1 ) ); + W_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift1 ); + } + + /* Loop over the other channels and bins to calculate the power in the band */ + FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) + { + /* abs()^2 */ + FOR( j = brange[0]; j < brange[1]; j++ ) + { + acc1 = W_mac_32_32( acc1, Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); + acc1 = W_mac_32_32( acc1, Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); + shift2 = W_norm( acc1 ); + other_ch_band_power = W_extract_h( W_shl( acc1, shift2 ) ); + other_ch_band_power_e = sub( imult1616( (Word16) 2, e_Cldfb ), shift2 ); + } + } + IF( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, EPSILON_FX_M, EPSILON_FX_E ) < 0 ) + { + if ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) + { + any_mono_band = 1; + move16(); + } + } + ELSE + { + test(); + IF( ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) || ( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) ) + { + Word16 tmp_div_e = 0; + move16(); + Word16 tmp_div = BASOP_Util_Divide3232_Scale( W_band_power, DIRAC_MONO_NORM_FACTOR_M, &tmp_div_e ); + tmp_div_e = add( tmp_div_e, sub( W_band_power_e, DIRAC_MONO_NORM_FACTOR_E ) ); + Word16 W_band_power_norm_e = 0; + move16(); + Word16 flag = BASOP_Util_Cmp_Mant32Exp( tmp_div, tmp_div_e, ONE_IN_Q14, 1 ); + IF( EQ_16( flag, 1 ) ) + { + W_band_power_norm = 1; + move16(); + W_band_power_norm_e = 31; + move16(); + } + ELSE + { + W_band_power_norm = L_deposit_h( tmp_div ); + W_band_power_norm_e = tmp_div_e; + move16(); + } + Word32 tmp_2 = Mpy_32_32( W_band_power_norm, DIRAC_MONO_MAX_THRESH_FX ); // W_band_power_norm_e+31 + Word32 tmp_3 = W_extract_h( W_shl( DIRAC_MONO_MIN_THRESH_FX, sub( 31, add( W_band_power_norm_e, 31 ) ) ) ); + tmp_3 = DIRAC_MONO_MIN_THRESH_FX; // exp31 + move32(); + Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( tmp_2, add( W_band_power_norm_e, 31 ), tmp_3, 31 ); + + Word16 threshold_e = 0; + move16(); + IF( EQ_16( flag2, 1 ) ) + { + threshold = tmp_2; + move32(); + threshold_e = add( W_band_power_norm_e, 31 ); + } + ELSE + { + threshold = DIRAC_MONO_MIN_THRESH_FX; + threshold_e = 31; + move32(); + move16(); + } + + IF( BASOP_Util_Cmp_Mant32Exp( divide3232( W_band_power, other_ch_band_power ), 31, threshold, threshold_e ) == 0 ) + { + any_mono_band = 1; + move16(); + } + ELSE + { + any_mc_band = 1; + move16(); + } + } + } + } + + /* If any band contains multi-channel content it's not mono */ + IF( any_mc_band ) + { + local_mono_flag = 0; + move16(); + } + ELSE + { + /* If any band contains mono content the frame is mono. */ + if ( any_mono_band ) + { + local_mono_flag = 1; + move16(); + } + } + + /* Hysteresis - only after DIRAC_MONO_FRAME_THRESH frames on mono will the actual mono flag be set */ + IF( local_mono_flag ) + { + IF( LT_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) ) + { + *mono_frame_count = add( *mono_frame_count, 1 ); + move16(); + } + } + ELSE + { + /* Instantaneously disable actual mono flag if multi-channel content is observed */ + if ( any_mc_band ) + { + *mono_frame_count = 0; + move16(); + } + } + + /* Final check if there has been mono for DIRAC_MONO_FRAME_THRESH number of frames than the content is declared mono */ + IF( EQ_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) ) + { + return 1; + } + ELSE + { + return 0; + } +} + static int16_t ivas_dirac_get_mono_flag( const int16_t *band_grouping, /* i : Band grouping for estimation */ float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -886,7 +1118,7 @@ static int16_t ivas_dirac_get_mono_flag( return 0; } } - +#endif /*------------------------------------------------------------------------- * computeReferencePower_enc() @@ -959,6 +1191,114 @@ void computeReferencePower_enc( * * *-------------------------------------------------------------------------*/ + +void computeReferencePower_enc_fx_dirac( + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ + Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ + Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ + Word32 *reference_power, /* o : Estimated power */ + Word16 *e_reference, /* o : exponent of reference_power */ + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + const IVAS_FORMAT ivas_format, /* i : ivas_format */ + Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ + const Word16 nchan_ana, /* i : number of analysis channels */ + Word16 *mono_frame_count, /* i/o: Mono Frame Count */ + Word16 *dirac_mono_flag /* i/o: Mono Flag */ +) +{ + Word16 brange[2]; + Word16 ch_idx, i, j; + Word64 reference_power_temp[DIRAC_MAX_NBANDS]; + Word64 reference_power_W[DIRAC_MAX_NBANDS]; + Word16 e_reference_W = 0, e_reference_temp = 0; + Word16 min_norm; + move16(); + move16(); + + IF( dirac_mono_flag != NULL ) + { + *dirac_mono_flag = ivas_dirac_get_mono_flag_fx( band_grouping, Cldfb_RealBuffer, Cldfb_ImagBuffer, e_Cldfb, nchan_ana, mono_frame_count ); + move16(); + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = band_grouping[i + enc_param_start_band]; + brange[1] = band_grouping[i + enc_param_start_band + 1]; + move16(); + move16(); + + reference_power_temp[i] = 0; + move64(); + + reference_power_W[i] = 0; + move64(); + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ); + reference_power_W[i] = W_mac_32_32( reference_power_W[i], Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ); + move64(); + move64(); + + e_reference_W = imult1616( (Word16) 2, e_Cldfb ); + } + reference_power_temp[i] = W_add( reference_power_temp[i], reference_power_W[i] ); + move64(); + + FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) + { + /* abs()^2 */ + FOR( j = brange[0]; j < brange[1]; j++ ) + { + reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ); + reference_power_temp[i] = W_mac_32_32( reference_power_temp[i], Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ); + move64(); + move64(); + + e_reference_temp = imult1616( (Word16) 2, e_Cldfb ); + } + } + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power_temp[i] = W_shr( reference_power_temp[i], 1 ); + move64(); + } + + test(); + IF( EQ_16( ivas_format, SBA_FORMAT ) && EQ_16( ref_power_w, 1 ) ) + { + FOR( i = 0; i < num_freq_bands; i++ ) + { + IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( reference_power_temp[i] ), e_reference_temp, W_extract_h( reference_power_W[i] ), e_reference_W ) < 0 ) + { + reference_power_temp[i] = reference_power_W[i]; + move64(); + } + } + } + + min_norm = W_norm( reference_power_temp[0] ); + FOR( i = 0; i < num_freq_bands; i++ ) + { + min_norm = s_min( min_norm, W_norm( reference_power_temp[i] ) ); // Finding minimum norm for the right shifting of entire buffer + } + + FOR( i = 0; i < num_freq_bands; i++ ) + { + reference_power[i] = W_extract_h( W_shl( reference_power_temp[i], min_norm ) ); // Right shift with min_norm and extract high bits + move32(); + } + *e_reference = sub( e_reference_temp, min_norm ); + move16(); + + return; +} + void computeReferencePower_enc_fx( const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -1097,12 +1437,19 @@ void ivas_dirac_param_est_enc( Word16 i, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED_ +#ifdef IVAS_FLOAT_FIXED Word32 dir_v_fx[DIRAC_NUM_DIMS]; #endif float *pcm_in[DIRAC_MAX_ANA_CHANS]; float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) + { + set_zero( Cldfb_RealBuffer[i], DIRAC_NO_FB_BANDS_MAX ); + set_zero( Cldfb_ImagBuffer[i], DIRAC_NO_FB_BANDS_MAX ); + } +#endif float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; @@ -1112,6 +1459,17 @@ void ivas_dirac_param_est_enc( Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + Word16 intensity_real_q = 0; + Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + Word16 direction_vector_q = 0; + Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q = 0; + move16(); + move16(); + move16(); +#endif float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; float diffuseness_vector[DIRAC_MAX_NBANDS]; float renormalization_factor[DIRAC_MAX_NBANDS]; @@ -1349,6 +1707,7 @@ void ivas_dirac_param_est_enc( #endif } +#ifndef IVAS_FLOAT_FIXED computeReferencePower_enc( hDirAC->band_grouping, Cldfb_RealBuffer, @@ -1361,7 +1720,84 @@ void ivas_dirac_param_est_enc( FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 Q_Cldfb = 31; + FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) + { + FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) + { + Q_Cldfb = s_min( Q_Cldfb, Q_factor_L( Cldfb_RealBuffer[x][k] ) ); + } + } + Word16 guard = find_guarded_bits_fx( 16 ) / 2; // Guard bits to avoid the precision loss for the reference_power + Word16 e_reference; + + FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) + { + floatToFixed_arrL( Cldfb_RealBuffer[k], Cldfb_RealBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); + } + + FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) + { + floatToFixed_arrL( Cldfb_ImagBuffer[k], Cldfb_ImagBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); + } + + FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) + { + FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) + { + Cldfb_RealBuffer_fx[x][k] = L_shr( Cldfb_RealBuffer_fx[x][k], guard ); + Cldfb_ImagBuffer_fx[x][k] = L_shr( Cldfb_ImagBuffer_fx[x][k], guard ); + } + } + Q_Cldfb = sub( Q_Cldfb, guard ); + + Word16 hodirac_flag_temp = 1; + IF( hodirac_flag ) + { + hodirac_flag_temp = 0; + } +#endif + computeReferencePower_enc_fx_dirac( + hDirAC->band_grouping, + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + sub( 31, Q_Cldfb ), + reference_power_fx[ts], + &e_reference, + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + ivas_format, + hodirac_flag_temp, + FOA_CHANNELS, + mono_frame_count, + dirac_mono_flag ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( reference_power_fx[ts], reference_power[ts], 31 - e_reference, DIRAC_NO_FB_BANDS_MAX ); +#endif +#endif +#ifdef IVAS_FLOAT_FIXED + computeIntensityVector_enc_fx( + hDirAC, + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + intensity_real_fx ); + + // intensity_real_q = 2 * Q_Cldfb + 1 - 32; + intensity_real_q = sub( shl( Q_Cldfb, 1 ), 31 ); + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + fixedToFloat_arrL( intensity_real_fx[i], intensity_real[i], intensity_real_q, num_freq_bands ); + } +#endif +#else computeIntensityVector_enc( hDirAC, Cldfb_RealBuffer, @@ -1369,9 +1805,31 @@ void ivas_dirac_param_est_enc( hDirAC->hConfig->enc_param_start_band, num_freq_bands, intensity_real ); +#endif if ( !hodirac_flag ) { +#ifdef IVAS_FLOAT_FIXED + computeDirectionVectors_fixed( + intensity_real_fx[0], + intensity_real_fx[1], + intensity_real_fx[2], + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + direction_vector_fx[0], + direction_vector_fx[1], + direction_vector_fx[2], + sub( 31, intensity_real_q ) ); + + direction_vector_q = Q30; + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + fixedToFloat_arrL( direction_vector_fx[i], direction_vector[i], direction_vector_q, num_freq_bands ); + } +#endif +#else computeDirectionVectors( intensity_real[0], intensity_real[1], @@ -1381,6 +1839,7 @@ void ivas_dirac_param_est_enc( direction_vector[0], direction_vector[1], direction_vector[2] ); +#endif } #ifdef IVAS_FLOAT_FIXED @@ -1388,7 +1847,6 @@ void ivas_dirac_param_est_enc( #define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; max_val = 0; Word32 tmp32; for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -1439,7 +1897,58 @@ void ivas_dirac_param_est_enc( mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); #endif + +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 buffer_intensity_real_q = 0; + float max_buffer_intensity_real_val = 0; + for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + { + for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + { + for ( int k = 0; k < num_freq_bands; k++ ) + { + max_buffer_intensity_real_val = max( max_buffer_intensity_real_val, (float) fabs( hDirAC->buffer_intensity_real[j][i][k] ) ); + } + } + } + + Word32 tmp_var = 0; + Word16 buffer_intensity_real_buff_e = 0; + f2me( (float) fabs( max_buffer_intensity_real_val ), &tmp_var, &buffer_intensity_real_buff_e ); + buffer_intensity_real_q = sub( 31, buffer_intensity_real_buff_e ); + for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + { + for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + { + floatToFixed_arrL( hDirAC->buffer_intensity_real[j][i], hDirAC->buffer_intensity_real_fx[j][i], buffer_intensity_real_q, num_freq_bands ); + } + } + + Word16 buffer_energy_e = 0; + Word16 buffer_energy_q = 0; + move16(); + move16(); + f2me_buf( hDirAC->buffer_energy, hDirAC->buffer_energy_fx, &buffer_energy_e, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + buffer_energy_q = sub( 31, buffer_energy_e ); +#endif + Word16 *buffer_energy_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); + Word16 *buffer_intensity_real_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); + set16_fx( buffer_energy_buff_q, buffer_energy_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + set16_fx( buffer_intensity_real_buff_q, buffer_intensity_real_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, buffer_intensity_real_buff_q, buffer_energy_buff_q, &diffuseness_vector_q ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( diffuseness_vector_fx, diffuseness_vector, diffuseness_vector_q, num_freq_bands ); +#endif + free( buffer_energy_buff_q ); + buffer_energy_buff_q = NULL; + free( buffer_intensity_real_buff_q ); + buffer_intensity_real_buff_q = NULL; +#else computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); +#endif if ( hodirac_flag ) { @@ -1512,12 +2021,12 @@ void ivas_dirac_param_est_enc( dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; } -#ifdef IVAS_FLOAT_FIXED_ - /*==========================================flt-2-fix======================================================*/ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 q_dir_e = 0; f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ +#endif ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, @@ -1525,10 +2034,10 @@ void ivas_dirac_param_est_enc( &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - /*==========================================fix-2-flt======================================================*/ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); - /*==========================================fix-2-flt======================================================*/ +#endif #else ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, @@ -1891,7 +2400,62 @@ void ivas_dirac_param_est_enc( * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void computeIntensityVector_enc_fx( + const DIRAC_ENC_HANDLE hDirAC, + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], + const Word16 enc_param_start_band, /* i : first band to process */ + const Word16 num_frequency_bands, + Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] ) +{ + /* Reminder + * X = a + ib; Y = c + id + * X*Y = ac - bd + i(ad +bc) + */ + Word16 i, j; + Word32 real, img; + Word16 brange[2]; + + FOR( i = 0; i < num_frequency_bands; i++ ) + { + brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; + move16(); + brange[1] = hDirAC->band_grouping[i + enc_param_start_band + 1]; + move16(); + + intensity_real[0][i] = 0; + move32(); + intensity_real[1][i] = 0; + move32(); + intensity_real[2][i] = 0; + move32(); + + Word64 tmp_1 = 0, tmp_2 = 0, tmp_3 = 0; + move64(); + move64(); + move64(); + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + real = Cldfb_RealBuffer[0][j]; + move32(); + img = Cldfb_ImagBuffer[0][j]; + move32(); + /* Intensity is XYZ order, audio is WYZX order. */ + tmp_1 = W_add( tmp_1, W_add( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), W_mult_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); + tmp_2 = W_add( tmp_2, W_add( W_mult_32_32( Cldfb_RealBuffer[1][j], real ), W_mult_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); + tmp_3 = W_add( tmp_3, W_add( W_mult_32_32( Cldfb_RealBuffer[2][j], real ), W_mult_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); + } + + intensity_real[0][i] = W_extract_h( tmp_1 ); // output Q= 2* input_q + 1 - 32 + intensity_real[1][i] = W_extract_h( tmp_2 ); // output Q= 2* input_q + 1 - 32 + intensity_real[2][i] = W_extract_h( tmp_3 ); // output Q= 2* input_q + 1 - 32 + } + return; +} +#else static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -1929,7 +2493,7 @@ static void computeIntensityVector_enc( return; } - +#endif /*------------------------------------------------------------------------- * computeDiffuseness_mdft() diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 900f0bb49b0850738f755240febb8c93c0f38e41..d296a4f01c5a3e1c2178d74ad98549011981814f 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -401,9 +401,10 @@ static Word16 arith_encode_cell_array_diff( Word16 arith_result; total_symbol_len = 0; + move16(); FOR( i = 0; i < nB; i++ ) { - total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + total_symbol_len = add( total_symbol_len, ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ) ); } assert( LE_16( total_symbol_len, ( IVAS_MAX_INPUT_LEN ) ) ); @@ -451,35 +452,50 @@ Word16 ivas_arith_encode_cmplx_cell_array( Word16 arith_result; idx1 = 0; + move16(); IF( EQ_16( any_diff, 1 ) ) { idx = 0; total_len = 0; + move16(); + move16(); FOR( i = 0; i < nB; i++ ) { - len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + len = ( imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); + move16(); IF( NE_16( pDo_diff[i], 0 ) ) { FOR( j = 0; j < len; j++ ) { input_old[idx] = pSymbol_old_re[total_len + j]; input_new[idx++] = pSymbol_re[total_len + j]; + move16(); + move16(); } cell_dim_diff[i].dim1 = pCell_dims[i].dim1; cell_dim_diff[i].dim2 = pCell_dims[i].dim2; cell_dim[i].dim1 = 0; cell_dim[i].dim2 = 0; + move16(); + move16(); + move16(); + move16(); } ELSE { FOR( j = 0; j < len; j++ ) { input[idx1++] = pSymbol_re[total_len + j]; + move16(); } cell_dim_diff[i].dim1 = 0; cell_dim_diff[i].dim2 = 0; cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim2 = pCell_dims[i].dim2; + move16(); + move16(); + move16(); + move16(); } total_len = add( total_len, len ); } @@ -491,6 +507,7 @@ Word16 ivas_arith_encode_cmplx_cell_array( } arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); + move16(); IF( LT_16( arith_result, 0 ) ) { return -1; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a7eb2b719b423fcb99b4b5c6b3c53f4eeeacf59c..e3028474e193ddec8b7e8000d0188cbf5bc1bb81 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -68,7 +68,16 @@ static void find_n_largest( const float *input, int16_t *largestIndices, const i static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); #endif +#ifdef IVAS_FLOAT_FIXED +static void detect_metadata_composition_fx( + const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ + UWord8 *joinedSubframes, /* o : Result of subframe composition */ + UWord8 *coherencePresent, /* o : Result of coherence presence */ + UWord8 *isTwoDir /* o : Result of two direction check */ +); +#else static void detect_metadata_composition( const MASA_ENCODER_HANDLE hMasa, uint8_t *joinedSubframes, uint8_t *coherencePresent, uint8_t *isTwoDir ); +#endif #ifdef IVAS_FLOAT_FIXED static void compensate_energy_ratios_fx( MASA_ENCODER_HANDLE hMasa ); @@ -89,7 +98,16 @@ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_H static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif +#ifdef IVAS_FLOAT_FIXED +static void average_masa_metadata_fx( + MASA_METADATA_FRAME *hMeta, + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const SPHERICAL_GRID_DATA *Sph_Grid16, + const UWord8 useSphGrid ); +#else static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const SPHERICAL_GRID_DATA *sphGrid, const uint8_t useSphGrid ); +#endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED static void copy_masa_metadata_subframe_fx( @@ -115,8 +133,9 @@ static UWord8 are_masa_subframes_similar_fx( const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ const UWord8 sf2_idx /* i : index of the subframe of frame2 to inspect */ ); -#endif +#else static uint8_t are_masa_subframes_similar( const MASA_METADATA_HANDLE frame1, const uint8_t sf1_idx, const MASA_METADATA_HANDLE frame2, const uint8_t sf2_idx ); +#endif #ifdef IVAS_FLOAT_FIXED static void detect_framing_async_fx( @@ -1861,6 +1880,7 @@ ivas_error ivas_masa_enc_config( previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); } + f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); current_meta->common_meta.surround_coherence_fx[i][j] = float_to_fix16( current_meta->common_meta.surround_coherence[i][j], Q15 ); current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = float_to_fix( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); @@ -1871,6 +1891,15 @@ ivas_error ivas_masa_enc_config( } #endif // IVAS_FLOAT_FIXED_CONVERSIONS detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ + if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) + { + /* average over sub-frames */ + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), ivas_total_brate == IVAS_512k ? TRUE : FALSE ); + } + + + /* Inspect metadata for parameter changes that affect coding. */ + detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { @@ -1896,15 +1925,6 @@ ivas_error ivas_masa_enc_config( } } #endif // IVAS_FLOAT_FIXED_CONVERSIONS - - if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) - { - /* average over sub-frames */ - average_masa_metadata( &( hMasa->masaMetadata ), hMasa->data.energy, &( hMasa->data.Sph_Grid16 ), ivas_total_brate == IVAS_512k ? TRUE : FALSE ); - } - - /* Inspect metadata for parameter changes that affect coding. */ - detect_metadata_composition( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); hMasa->config.joinedSubframes = joinedSubframes; hMasa->config.coherencePresent = coherencePresent; hMasa->config.numberOfDirections = ( hMasa->masaMetadata.descriptive_meta.numberOfDirections + 1 ) == 2 && isActualTwoDir ? 2 : 1; @@ -3381,6 +3401,195 @@ static void move_metadata_to_qmetadata_fx( /* This function studies parametric MASA metadata to provide information for codec configuration */ +#ifdef IVAS_FLOAT_FIXED +static void detect_metadata_composition_fx( + const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ + UWord8 *joinedSubframes, /* o : Result of subframe composition */ + UWord8 *coherencePresent, /* o : Result of coherence presence */ + UWord8 *isTwoDir /* o : Result of two direction check */ +) +{ + MASA_METADATA_FRAME *hMeta; + Word8 sf, band, dir, numDir; + Word16 nSubFrames; + UWord8 dirValid[2] = { FALSE, FALSE }; + UWord8 cohPresent = FALSE; + UWord8 sfDiffer = FALSE; + UWord8 sfSimilar; + move16(); /*dirValid[0]*/ + move16(); /*dirValid[1]*/ + move16(); /*cohPresent*/ + move16(); /*sfDiffer*/ + + hMeta = &( hMasa->masaMetadata ); + numDir = (Word8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + move16(); + + *isTwoDir = FALSE; + move16(); + + /* First check for valid two directions */ + IF( EQ_16( numDir, 1 ) ) + { + dirValid[0] = TRUE; + move16(); + } + ELSE + { + /* Default assumption */ + *isTwoDir = TRUE; + move16(); + + /* Check for direct-to-total ratio values */ + FOR( dir = 0; dir < numDir; dir++ ) + { + sf = 0; + move16(); + WHILE( !dirValid[dir] && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + test(); + band = 0; + move16(); + WHILE( !dirValid[dir] && LT_16( band, MASA_FREQUENCY_BANDS ) ) + { + test(); + IF( GE_32( hMeta->directional_meta[dir].energy_ratio_fx[sf][band] /*q30*/, MASA_RATIO_THRESHOLD_FX >> 1 /*q30*/ ) ) + { + dirValid[dir] = TRUE; + move16(); + } + band = (Word8) add( band, 1 ); + } + sf = (Word8) add( sf, 1 ); + } + } + + test(); + IF( dirValid[1] == FALSE ) + { + /* This handles also case where both are false. Then we just use first dir metadata. */ + *isTwoDir = FALSE; + move16(); + } + ELSE IF( dirValid[0] == FALSE && EQ_16( dirValid[1], TRUE ) ) + { + *isTwoDir = FALSE; + move16(); + /* Copy data to first direction */ + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hMeta->directional_meta[0].azimuth_fx[sf][band] = hMeta->directional_meta[1].azimuth_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].elevation_fx[sf][band] = hMeta->directional_meta[1].elevation_fx[sf][band]; /*q22*/ + hMeta->directional_meta[0].energy_ratio_fx[sf][band] = hMeta->directional_meta[1].energy_ratio_fx[sf][band]; /*q30*/ + hMeta->directional_meta[0].spread_coherence_fx[sf][band] = hMeta->directional_meta[1].spread_coherence_fx[sf][band]; /*q15*/ + move32(); + move16(); + move16(); + move16(); + } + } + } + + IF( *isTwoDir == FALSE ) + { + /* Further checks will be done with just one direction */ + numDir = 1; + move16(); + } + } + + /* Check if data over subframes is identical. Check is done by comparing to first subframe. */ + sfSimilar = TRUE; + sf = 1; + move16(); + move16(); + WHILE( EQ_16( sfSimilar, TRUE ) && LT_16( sf, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + test(); + sfSimilar = are_masa_subframes_similar_fx( hMeta, 0, hMeta, sf ); + sf = (Word8) add( sf, 1 ); + move16(); + } + IF( sfSimilar == TRUE ) + sfDiffer = FALSE; + ELSE + sfDiffer = TRUE; + move16(); + + /* Further checks can be done with just one subframe if they are identical */ + IF( EQ_16( sfDiffer, TRUE ) ) + nSubFrames = MAX_PARAM_SPATIAL_SUBFRAMES; + ELSE + nSubFrames = 1; + move16(); + + /* Check spread coherence */ + dir = 0; + move16(); + WHILE( cohPresent == FALSE && LT_16( dir, numDir ) ) + { + test(); + sf = 0; + move16(); + WHILE( cohPresent == FALSE && LT_16( sf, nSubFrames ) ) + { + test(); + band = 0; + move16(); + WHILE( cohPresent == FALSE /*has value zero*/ && LT_16( band, MASA_FREQUENCY_BANDS ) ) + { + test(); + /* Check coherences for presence of coherence */ + IF( GT_16( hMeta->directional_meta[dir].spread_coherence_fx[sf][band] /*Q15*/, MASA_COHERENCE_THRESHOLD_FX >> 16 ) ) /*Q15*/ + { + cohPresent = TRUE; + move16(); + } + band = (Word8) add( band, 1 ); + move16(); + } + sf = (Word8) add( sf, 1 ); + move16(); + } + dir = (Word8) add( dir, 1 ); + move16(); + } + + /* Check surround coherence separately if we do not have already knowledge of coherence */ + IF( cohPresent == FALSE ) + { + Word32 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 diffuse_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 i, j; + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + surround_coherence_fx[i][j] = L_deposit_h( hMeta->common_meta.surround_coherence_fx[i][j] ); /*q31*/ + diffuse_to_total_ratio_fx[i][j] = L_shl_sat( hMeta->common_meta.diffuse_to_total_ratio_fx[i][j], 1 ); /*q31*/ + } + } + cohPresent = ivas_masa_surrcoh_signicant_fx( surround_coherence_fx, diffuse_to_total_ratio_fx, nSubFrames, MASA_FREQUENCY_BANDS ); + } + + /* Set output flags */ + IF( EQ_16( sfDiffer, TRUE ) ) + { + *joinedSubframes = FALSE; + } + ELSE + { + *joinedSubframes = TRUE; + } + move16(); + *coherencePresent = cohPresent; + move16(); + + return; +} +#else static void detect_metadata_composition( const MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder data */ uint8_t *joinedSubframes, /* o : Result of subframe composition */ @@ -3505,6 +3714,7 @@ static void detect_metadata_composition( return; } +#endif // IVAS_FLOAT_FIXED /* Check and compensate energy ratios. This function verifies that energy ratios follow the principle of summing to one. @@ -4643,6 +4853,163 @@ void ivas_masa_enc_reconfigure( * * Average MASA metadata frame subframe contents: applies aggregation over time *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void average_masa_metadata_fx( + MASA_METADATA_FRAME *hMeta, + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i*/ + Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i:stores exponent values for energy_e*/ + const SPHERICAL_GRID_DATA *Sph_Grid16, + const UWord8 useSphGrid ) +{ + Word16 i, j, k; + Word16 azi_rad_fx, ele_rad_fx; + UWord8 numDirections; + + /* use the nominal values without data-adaptivity */ + numDirections = (UWord8) add( hMeta->descriptive_meta.numberOfDirections, 1 ); + move16(); + + /* azi/ele/nrg into vectors for each sub-frame and band */ + FOR( i = 0; i < numDirections; i++ ) + { + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + Word32 x_sum_fx, y_sum_fx, z_sum_fx, energy_sum_fx, vec_len_fx, spread_coh_sum_fx, surr_coh_sum_fx, temp1, temp2; + Word16 vec_len_e, x_sum_e, y_sum_e, z_sum_e, energy_sum_e, spread_coh_sum_e, surr_coh_sum_e, temp1_e, temp2_e; + x_sum_fx = 0; + y_sum_fx = 0; + z_sum_fx = 0; + energy_sum_fx = 0; + spread_coh_sum_fx = 0; + surr_coh_sum_fx = 0; + x_sum_e = 0; /*exponent for x_sum_fx*/ + y_sum_e = 0; /*exponent for y_sum_fx*/ + z_sum_e = 0; /*exponent for z_sum_fx*/ + energy_sum_e = 0; /*exponent for energy_sum_fx*/ + spread_coh_sum_e = 0; /*exponent for spread_coh_sum_fx*/ + surr_coh_sum_e = 0; /*exponent for surr_coh_sum_fx*/ + temp1 = 0; /* to store temporary computations*/ + temp2 = 0; /* to store temporary computations*/ + temp1_e = 0; /*to store temporary exponents*/ + temp2_e = 0; /*to store temporary exponents*/ + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + vec_len_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ) ); /*exponent=energy_e+1*/ + vec_len_e = add( energy_e[j][k], 1 ); + + /* energy-weighted sum over subframes */ + x_sum_fx = BASOP_Util_Add_Mant32Exp( x_sum_fx, x_sum_e, Mpy_32_32( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ) /*q31*/, vec_len_fx ), vec_len_e, &x_sum_e ); /*x_sum_e*/ + y_sum_fx = BASOP_Util_Add_Mant32Exp( y_sum_fx, y_sum_e, Mpy_32_32( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ) /*q31*/, vec_len_fx ), vec_len_e, &y_sum_e ); /*y_sum_e*/ + z_sum_fx = BASOP_Util_Add_Mant32Exp( z_sum_fx, z_sum_e, Mpy_32_16_1( vec_len_fx, getSineWord16R2( ele_rad_fx ) /*q15*/ ), vec_len_e, &z_sum_e ); /*z_sum_e*/ + + energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, energy_sum_e, energy[j][k], energy_e[j][k], &energy_sum_e ); /*energy_sum_e*/ + + spread_coh_sum_fx = BASOP_Util_Add_Mant32Exp( spread_coh_sum_fx, spread_coh_sum_e, Mpy_32_16_1( energy[j][k], hMeta->directional_meta[i].spread_coherence_fx[j][k] ), energy_e[j][k], &spread_coh_sum_e ); /*spread_coh_sum_e*/ + IF( i == 0 ) + { + /* this is in common metadata and not in each direction */ + surr_coh_sum_fx = BASOP_Util_Add_Mant32Exp( surr_coh_sum_fx, surr_coh_sum_e, Mpy_32_16_1( energy[j][k], hMeta->common_meta.surround_coherence_fx[j][k] ), energy_e[j][k], &surr_coh_sum_e ); /*surr_coh_sum_e*/ + } + } + + /* the data from the combined sub-frames is written into the first sub-frame band */ + j = 0; + move16(); + hMeta->directional_meta[i].azimuth_fx[j][k] = Mpy_32_16_1( 961263669 /*(1/ EVS_PI * 180.0f) in Q24*/, BASOP_util_atan2( y_sum_fx, x_sum_fx, sub( y_sum_e, x_sum_e ) ) /*q13*/ ); /*24+13-15=22*/ + move32(); + temp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( x_sum_fx, x_sum_fx ), shl( x_sum_e, 1 ), Mpy_32_32( y_sum_fx, y_sum_fx ), shl( y_sum_e, 1 ), &temp1_e ); /*temp1_e*/ + temp2_e = temp1_e; + temp2 = Sqrt32( temp1, &temp2_e ); /*temp2_e*/ + hMeta->directional_meta[i].elevation_fx[j][k] = Mpy_32_16_1( 961263669 /*(1/ EVS_PI * 180.0f) in Q24*/, BASOP_util_atan2( z_sum_fx, temp2, sub( z_sum_e, temp2_e ) ) /*q13*/ ); /*24+13-15=22*/ + move32(); + IF( EQ_16( useSphGrid, TRUE ) ) + { + + hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16_fx( &( hMeta->directional_meta[i].elevation_fx[j][k] ), + &( hMeta->directional_meta[i].azimuth_fx[j][k] ), Sph_Grid16 ); + move16(); + } + vec_len_fx = BASOP_Util_Add_Mant32Exp( temp1, temp1_e, Mpy_32_32( z_sum_fx, z_sum_fx ), shl( z_sum_e, 1 ), &vec_len_e ); /*vec_len_e*/ /*x_sum * x_sum + y_sum * y_sum + z_sum * z_sum*/ + vec_len_fx = Sqrt32( vec_len_fx, &vec_len_e ); /*vec_len_e*/ + hMeta->directional_meta[i].energy_ratio_fx[j][k] = BASOP_Util_Divide3232_Scale( vec_len_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); /*temp2_e*/ + move32(); + temp2_e = add( temp2_e, sub( vec_len_e, energy_sum_e ) ); + hMeta->directional_meta[i].energy_ratio_fx[j][k] = L_shl( hMeta->directional_meta[i].energy_ratio_fx[j][k], add( temp2_e, 15 ) ); /*changing q from 15-temp2_e to q30*/ + move32(); + hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spread_coh_sum_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); + move16(); + temp2_e = add( temp2_e, sub( spread_coh_sum_e, energy_sum_e ) ); + hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ + move16(); + IF( i == 0 ) + { + hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surr_coh_sum_fx, L_add( energy_sum_fx, EPSILON_FX ), &temp2_e ); + move16(); + temp2_e = add( temp2_e, sub( surr_coh_sum_e, energy_sum_e ) ); + hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], temp2_e ); /*changing q from 15-temp2_e to q15*/ + move16(); + } + + /* copy the same value to all subframes */ + FOR( j = 1; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + hMeta->directional_meta[i].azimuth_fx[j][k] = hMeta->directional_meta[i].azimuth_fx[0][k]; /*q22*/ + hMeta->directional_meta[i].elevation_fx[j][k] = hMeta->directional_meta[i].elevation_fx[0][k]; /*q22*/ + hMeta->directional_meta[i].energy_ratio_fx[j][k] = hMeta->directional_meta[i].energy_ratio_fx[0][k]; /*q30*/ + hMeta->directional_meta[i].spread_coherence_fx[j][k] = hMeta->directional_meta[i].spread_coherence_fx[0][k]; /*q15*/ + move32(); + move32(); + move32(); + move16(); + IF( i == 0 ) + { + hMeta->common_meta.surround_coherence_fx[j][k] = hMeta->common_meta.surround_coherence_fx[0][k]; /*q15*/ + move16(); + } + } + } + } + + FOR( k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( EQ_16( numDirections, 2 ) ) + { + hMeta->common_meta.diffuse_to_total_ratio_fx[j][k] = L_max( 0, L_sub( L_sub( ONE_IN_Q30, hMeta->directional_meta[1].energy_ratio_fx[j][k] ), hMeta->directional_meta[0].energy_ratio_fx[j][k] ) ); /*q30*/ + } + ELSE + { + hMeta->common_meta.diffuse_to_total_ratio_fx[j][k] = L_max( 0, L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][k] ) ); /*q30*/ + } + move32(); + hMeta->common_meta.remainder_to_total_ratio_fx[j][k] = 0; /*q30*/ + move32(); + } + } + + return; +} +#else static void average_masa_metadata( MASA_METADATA_FRAME *hMeta, @@ -4753,6 +5120,7 @@ static void average_masa_metadata( return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -5004,7 +5372,7 @@ static UWord8 are_masa_subframes_similar_fx( return TRUE; } } -#endif +#else static uint8_t are_masa_subframes_similar( const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ const uint8_t sf1_idx, /* i : index of the subframe of frame1 to inspect */ @@ -5092,6 +5460,7 @@ static uint8_t are_masa_subframes_similar( return TRUE; } } +#endif /*-------------------------------------------------------------------* * detect_framing_async() diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 4c3ce7706b545a6aee1bfa132bccfefd49997f57..3b0c84b66709c7a472a43606f03a0d777a6d22a1 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -652,88 +652,6 @@ ivas_error ivas_mct_enc( FOR( int b = 0; b < hMCT->nchan_out_woLFE; b++ ) { st = sts_tmp[b]; - - if ( st->hIGFEnc ) - { - ch = 0; - hIGFEnc[ch] = st->hIGFEnc; - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 igfGridIdx; - IF( st->last_core == ACELP_CORE && EQ_16( st->core, TCX_20_CORE ) ) - { - igfGridIdx = IGF_GRID_LB_TRAN; - } - ELSE IF( EQ_16( st->core, TCX_20_CORE ) ) - { - igfGridIdx = IGF_GRID_LB_NORM; - } - ELSE - { - /* It is short block */ - igfGridIdx = IGF_GRID_LB_SHORT; - } - hPrivateData = &hIGFEnc[ch]->igfData; - hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; - if ( hIGFEnc[ch] ) - { - hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); - } - - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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( int k = 0; k < IGF_MAX_TILES; k++ ) - { - hPrivateData->prevSFM_FIR[k] = float_to_fix( hPrivateData->prevSFM_FIR_flt[k], 16 ); /*15Q16*/ - hPrivateData->prevSFM_IIR[k] = float_to_fix16( hPrivateData->prevSFM_IIR_flt[k], 13 ); /*2Q13*/ - FOR( int j = 0; j < IGF_PAST_SFM_LEN; j++ ) - { - hPrivateData->igfPastSFM_fx[k][j] = float_to_fix16( hPrivateData->igfPastSFM[k][j], 13 ); - } - } - floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); - } - if ( st->hTdCngEnc != NULL ) { st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 ); diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 53177f642789a497cd10eba479ad06e8869e77d0..3c97580fc8848ef42955763774a882a891c169e4 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -82,23 +82,43 @@ static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], #else static void ivas_band_mixer_fx( Word32 *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 num_ch, Word16 *num_bands, Word16 red_band_fact ); #endif + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_huffman_coded_bs_fx( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const Word16 nB, const Word16 qsi, const Word16 bands_bw ); +#else static int16_t ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t bands_bw ); +#endif + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_arith_coded_bs_fx( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const Word16 *pDo_diff, const Word16 bands_bw, const Word16 nB, const Word16 qsi, const Word16 strat, const Word32 ivas_total_brate ); +#else static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t strat, const int32_t ivas_total_brate ); +#endif + static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); #ifdef IVAS_FLOAT_FIXED static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word16 *max_freq_per_chan, const Word16 nchan_transport, Word32 *pFC, const Word16 nchan_inp ); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void ivas_select_next_strat_fx( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const Word16 dmx_switch, const Word16 dtx_vad ); +#else static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); +#endif #ifdef IVAS_FLOAT_FIXED static void ivas_store_prior_coeffs_fx( ivas_spar_md_enc_state_t *hMdEnc, const Word16 num_bands, const Word16 strat, const Word16 dtx_vad, const Word16 qsi ); #else static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); #endif + +#ifdef IVAS_FLOAT_FIXED +static void ivas_write_spar_md_bitstream_fx( ivas_spar_md_enc_state_t *hMdEnc, const Word16 nB, const Word16 bands_bw, BSTR_ENC_HANDLE hMetaData, const Word32 ivas_total_brate, const Word16 strat, const Word16 qsi ); +#else static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi ); +#endif #ifndef IVAS_FLOAT_FIXED @@ -108,7 +128,7 @@ static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, con static void ivas_spar_quant_pred_coeffs_dtx_fx( ivas_spar_md_t *pSpar_md, const Word32 *pValues, const Word16 ndm, Word16 *pIndex, const Word16 dim1, Word32 *pQuant ); static void ivas_quant_p_per_band_dtx_fx( Word32 *pP_mat, const Word16 num_dec, const Word16 num_dmx, Word16 *ppIdx_pd, Word32 *pP_out, const Word16 num_ch ); #endif -static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); +static void ivas_write_parameter_bitstream_dtx_fx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, Word16 *num_dmx, Word16 *num_dec, const Word16 num_bands ); #ifndef IVAS_FLOAT_FIXED static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); @@ -169,20 +189,19 @@ ivas_error ivas_spar_md_enc_open( } } } - - if ( ( hMdEnc->mixer_mat_local = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + FOR( i = 0; i < num_channels; i++ ) { - if ( ( hMdEnc->mixer_mat_local[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + FOR( j = 0; j < num_channels; j++ ) { - if ( ( hMdEnc->mixer_mat_local[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + IF( ( hMdEnc->mixer_mat_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } @@ -239,25 +258,6 @@ ivas_error ivas_spar_md_enc_open_fx( num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - IF( ( hMdEnc->mixer_mat_local_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - FOR( i = 0; i < num_channels; i++ ) - { - IF( ( hMdEnc->mixer_mat_local_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - FOR( j = 0; j < num_channels; j++ ) - { - IF( ( hMdEnc->mixer_mat_local_fx[i][j] = (Word32 *) malloc( IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - } - } - IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -326,20 +326,6 @@ void ivas_spar_md_enc_close( free( hMdEnc->mixer_mat ); } - if ( hMdEnc->mixer_mat_local != NULL ) - { - for ( i = 0; i < num_channels; i++ ) - { - - for ( j = 0; j < num_channels; j++ ) - { - free( hMdEnc->mixer_mat_local[i][j] ); - } - free( hMdEnc->mixer_mat_local[i] ); - } - free( hMdEnc->mixer_mat_local ); - } - free( *hMdEnc_in ); *hMdEnc_in = NULL; @@ -595,23 +581,25 @@ static void ivas_spar_set_enc_config_fx( * Band limit downmix matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_band_limit_dmx_matrix( +static void ivas_band_limit_dmx_matrix_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, - const int16_t num_bands, - const int16_t bands_bw ) + const Word16 num_ch, + const Word16 num_bands, + const Word16 bands_bw ) { - int16_t i, j, b, ndm; + Word16 i, j, b, ndm; - for ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + move16(); - for ( i = ndm; i < num_ch; i++ ) + FOR( i = ndm; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - hMdEnc->mixer_mat[i][j][b] = 0; + hMdEnc->mixer_mat_fx[i][j][b] = 0; + move32(); } } } @@ -626,32 +614,34 @@ static void ivas_band_limit_dmx_matrix( * Band mixing downmix matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_band_mixing( +static void ivas_band_mixing_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, - const int16_t num_bands, - const int16_t nchan_transport, - const int16_t upmixed_bands ) + const Word16 num_ch, + const Word16 num_bands, + const Word16 nchan_transport, + const Word16 upmixed_bands ) { - int16_t i, j, k, b; - int16_t red_band_fact; + Word16 i, j, k, b; + Word16 red_band_fact; - red_band_fact = upmixed_bands / num_bands; + red_band_fact = idiv1616( upmixed_bands, num_bands ); - for ( i = 0; i < nchan_transport; i++ ) + FOR( i = 0; i < nchan_transport; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - for ( k = num_bands - 1; k >= 0; k-- ) + FOR( k = num_bands - 1; k >= 0; k-- ) { - for ( b = red_band_fact - 1; b >= 0; b-- ) + FOR( b = red_band_fact - 1; b >= 0; b-- ) { - hMdEnc->mixer_mat[i][j][red_band_fact * k + b] = hMdEnc->mixer_mat[i][j][k]; + hMdEnc->mixer_mat_fx[i][j][red_band_fact * k + b] = hMdEnc->mixer_mat_fx[i][j][k]; + move32(); } } - for ( k = red_band_fact * num_bands; k < upmixed_bands; k++ ) + FOR( k = red_band_fact * num_bands; k < upmixed_bands; k++ ) { - hMdEnc->mixer_mat[i][j][k] = hMdEnc->mixer_mat[i][j][( red_band_fact * num_bands ) - 1]; + hMdEnc->mixer_mat_fx[i][j][k] = hMdEnc->mixer_mat_fx[i][j][( red_band_fact * num_bands ) - 1]; + move32(); } } } @@ -716,10 +706,11 @@ ivas_error ivas_spar_md_enc_process_fx( const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ) { - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 i, j, b, qsi, ndm, ndec, num_ch, num_quant_strats; - float pred_coeffs_re_local[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 pred_coeffs_re_local_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; Word16 active_w, nchan_transport, dmx_switch, strat; Word16 nB, bands_bw, packed_ok = 0; @@ -845,6 +836,16 @@ ivas_error ivas_spar_md_enc_process_fx( bands_bw = 1; move16(); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( b = 0; b < num_bands; b++ ) + { + for ( int ii = 0; ii < num_ch - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); + } + } +#endif test(); IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { @@ -852,7 +853,8 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { - pred_coeffs_re_local[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re[i]; + pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + move32(); } } } @@ -871,49 +873,57 @@ ivas_error ivas_spar_md_enc_process_fx( #endif ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); - - if ( dirac_mono_flag ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( b = 0; b < num_bands; b++ ) { - int16_t i_ts; - int16_t num_md_sub_frames = 1; + for ( int ii = 0; ii < num_ch - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); + } + } +#endif + IF( dirac_mono_flag ) + { + Word16 i_ts; + Word16 num_md_sub_frames = 1; + move16(); ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[0]; + move16(); - for ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) + FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( j = 0; j < ndm + ndec - 1; j++ ) + FOR( j = 0; j < ndm + ndec - 1; j++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = 0; + move32(); } - for ( j = 0; j < ndec; j++ ) + FOR( j = 0; j < ndec; j++ ) { - for ( k = 0; k < ndm - 1; k++ ) + FOR( k = 0; k < ndm - 1; k++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = 0; + move32(); } } - for ( j = 0; j < ndec; j++ ) + FOR( j = 0; j < ndec; j++ ) { hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = 0.0f; + hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = 0; + move32(); } } } } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( b = 0; b < num_bands; b++ ) - { - hMdEnc->mixer_mat_local[i][j][b] = hMdEnc->mixer_mat[i][j][b]; - } - } - } code_strat = 0; move16(); FOR( qsi = 0; qsi < num_quant_strats; qsi++ ) @@ -923,14 +933,6 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max, Q28 ); hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min, Q28 ); hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max, Q28 ); - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } #endif FOR( b = 0; b < num_bands; b++ ) { @@ -1021,53 +1023,93 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); } } -#endif + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; + f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); for ( i = 0; i < num_ch - 1; i++ ) { - for ( b = 0; b < num_bands; b++ ) + dm_fv_re_q = s_min( dm_fv_re_q, Q_factor_arrL( dm_fv_re[i], num_bands ) ); + } + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) { - pred_coeffs_re[i][b] = Wscale[b] * hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i]; + mixer_q = s_min( mixer_q, Q_factor_arrL( hMdEnc->mixer_mat[i][j], num_bands ) ); + } + } + mixer_q = mixer_q - Wscale_e; // Important + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + floatToFixed_arrL32( hMdEnc->mixer_mat[i][j], hMdEnc->mixer_mat_fx[i][j], mixer_q, num_bands ); + } + } + for ( i = 0; i < num_ch - 1; i++ ) + { + floatToFixed_arrL32( dm_fv_re[i], dm_fv_re_fx[i], dm_fv_re_q, num_bands ); + } +#endif + FOR( i = 0; i < num_ch - 1; i++ ) + { + FOR( b = 0; b < num_bands; b++ ) + { + pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), Wscale_e ); + move32(); } } - if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { - for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) + FOR( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ ) { - for ( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) + FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { /* Use the prediction coeffs computed based on DirAC MD to generate mixer matrix */ - pred_coeffs_re[i][b] = pred_coeffs_re_local[i][b]; - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; + pred_coeffs_re_fx[i][b] = pred_coeffs_re_local_fx[i][b]; + move32(); + hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = 0; + hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0.0f; + move32(); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = 0; + move16(); } } } - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, dm_fv_re_q, hMdEnc->mixer_mat_fx, &mixer_q, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); - for ( b = 0; b < num_bands; b++ ) + FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + move16(); ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; + move16(); - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - hMdEnc->mixer_mat[0][i][b] *= Wscale[b]; + hMdEnc->mixer_mat_fx[0][i][b] = L_shl( Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ), Wscale_e ); + move32(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMdEnc->mixer_mat[0][i][b] = fix_to_float( hMdEnc->mixer_mat_fx[0][i][b], mixer_q ); +#endif } - if ( ( ndm != num_ch ) && ( ndm != 1 ) ) + IF( NE_16( ndm, num_ch ) && NE_16( ndm, 1 ) ) { ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); - if ( dirac_mono_flag ) + IF( dirac_mono_flag ) { ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[0]; + move16(); ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[0]; - for ( j = 0; j < ndec; j++ ) + move16(); + FOR( j = 0; j < ndec; j++ ) { - for ( k = 0; k < ndm - 1; k++ ) + FOR( k = 0; k < ndm - 1; k++ ) { hMdEnc->spar_md.band_coeffs[b].C_re[j][k] = 0.0f; } @@ -1080,21 +1122,38 @@ ivas_error ivas_spar_md_enc_process_fx( } /* band limit downmix matrix */ - ivas_band_limit_dmx_matrix( hMdEnc, num_ch, num_bands, bands_bw ); + ivas_band_limit_dmx_matrix_fx( hMdEnc, num_ch, num_bands, bands_bw ); /* band mixing */ - if ( bands_bw > 1 ) + IF( GT_16( bands_bw, 1 ) ) { - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); + ivas_band_mixing_fx( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } +#endif - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - ivas_write_parameter_bitstream_dtx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); - break; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMdEnc->spar_md.min_max_fx[0] = float_to_fix( hMdEnc->spar_md.min_max[0], Q28 ); + hMdEnc->spar_md.min_max_fx[1] = float_to_fix( hMdEnc->spar_md.min_max[1], Q28 ); +#endif + ivas_write_parameter_bitstream_dtx_fx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); + BREAK; } +#ifdef IVAS_FLOAT_FIXED + ivas_select_next_strat_fx( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); +#else ivas_select_next_strat( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); +#endif for ( i = 0; i < MAX_CODING_STRATS; i++ ) { @@ -1103,7 +1162,11 @@ ivas_error ivas_spar_md_enc_process_fx( { reset_indices_enc( &hMetaData_tmp, md_indices_allocated ); +#ifdef IVAS_FLOAT_FIXED + ivas_write_spar_md_bitstream_fx( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); +#else ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); +#endif /*write to main buffer if its a valid bitstream*/ if ( hMetaData_tmp.nb_bits_tot > 0 ) @@ -1685,142 +1748,353 @@ static void ivas_band_mixer( * * Write MD parameters into bitstream *-----------------------------------------------------------------------------------------*/ - -static void ivas_write_spar_md_bitstream( +#ifdef IVAS_FLOAT_FIXED +static void ivas_write_spar_md_bitstream_fx( ivas_spar_md_enc_state_t *hMdEnc, - const int16_t nB, - const int16_t bands_bw, + const Word16 nB, + const Word16 bands_bw, BSTR_ENC_HANDLE hMetaData, - const int32_t ivas_total_brate, - const int16_t strat, - const int16_t qsi ) + const Word32 ivas_total_brate, + const Word16 strat, + const Word16 qsi ) { - int16_t no_ec, i; - int16_t do_diff[IVAS_MAX_NUM_BANDS]; - int16_t entropy_coding_result; + Word16 no_ec, i; + Word16 do_diff[IVAS_MAX_NUM_BANDS]; + Word16 entropy_coding_result; - if ( strat == NO_STRAT ) + IF( EQ_16( strat, NO_STRAT ) ) { return; } /* write quant strat */ - if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) + IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { - push_next_indice( hMetaData, qsi >> 1, hMdEnc->spar_md_cfg.quant_strat_bits - 1 ); + push_next_indice( hMetaData, shr( qsi, 1 ), sub( hMdEnc->spar_md_cfg.quant_strat_bits, 1 ) ); } - else + ELSE { push_next_indice( hMetaData, qsi, hMdEnc->spar_md_cfg.quant_strat_bits ); } no_ec = 0; + move16(); - if ( ivas_total_brate < IVAS_24k4 ) + IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { - switch ( strat ) + SWITCH( strat ) { case BASE: - push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); - break; + push_next_indice( hMetaData, sub( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + BREAK; case BASE_NOEC: - push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); + push_next_indice( hMetaData, add( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); no_ec = 1; - break; + move16(); + BREAK; case FOUR_A: case FOUR_C: case FOUR_B: case FOUR_D: push_next_indice( hMetaData, strat, SPAR_NUM_CODING_STRAT_BITS ); - break; + BREAK; } /* for LBR SBA 40MS MD never do time diff */ - for ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { do_diff[i] = 0; + move16(); } } - else + ELSE { - switch ( strat ) + SWITCH( strat ) { case BASE: - push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + push_next_indice( hMetaData, sub( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) { do_diff[i] = 0; + move16(); } - break; + BREAK; case BASE_NOEC: - push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + push_next_indice( hMetaData, add( bands_bw, 1 ), SPAR_NUM_CODING_STRAT_BITS ); + FOR( i = 0; i < nB; i++ ) { do_diff[i] = 0; + move16(); } no_ec = 1; - break; + move16(); + BREAK; case FOUR_A: push_next_indice( hMetaData, 4, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 0 ); + do_diff[i] = ( ( s_and( ( add( i, 1 ) ), 3 ) ) != 0 ); + move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; + BREAK; case FOUR_B: push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 1 ); + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 1 ) ); + move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; + BREAK; case FOUR_C: push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 2 ); + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 2 ) ); + move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; + BREAK; case FOUR_D: push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); - for ( i = 0; i < nB; i++ ) + FOR( i = 0; i < nB; i++ ) { - do_diff[i] = ( ( ( i + 1 ) & 3 ) != 3 ); + do_diff[i] = (Word16) ( NE_16( ( s_and( ( add( i, 1 ) ), 3 ) ), 3 ) ); + move16(); } ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); - break; + BREAK; } } - if ( no_ec == 1 ) + IF( EQ_16( no_ec, 1 ) ) { entropy_coding_result = - ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, - bands_bw ); + ivas_get_huffman_coded_bs_fx( hMdEnc, hMetaData, nB, qsi, + bands_bw ); + move16(); } - else + ELSE { entropy_coding_result = - ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, - strat, ivas_total_brate ); + ivas_get_arith_coded_bs_fx( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, + strat, ivas_total_brate ); + move16(); } if ( entropy_coding_result < 0 ) { hMetaData->nb_bits_tot = 0; + move16(); } return; } - - -/*-----------------------------------------------------------------------------------------* +#else +static void ivas_write_spar_md_bitstream( + ivas_spar_md_enc_state_t *hMdEnc, + const int16_t nB, + const int16_t bands_bw, + BSTR_ENC_HANDLE hMetaData, + const int32_t ivas_total_brate, + const int16_t strat, + const int16_t qsi ) +{ + int16_t no_ec, i; + int16_t do_diff[IVAS_MAX_NUM_BANDS]; + int16_t entropy_coding_result; + + if ( strat == NO_STRAT ) + { + return; + } + + /* write quant strat */ + if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) + { + push_next_indice( hMetaData, qsi >> 1, hMdEnc->spar_md_cfg.quant_strat_bits - 1 ); + } + else + { + push_next_indice( hMetaData, qsi, hMdEnc->spar_md_cfg.quant_strat_bits ); + } + + no_ec = 0; + + if ( ivas_total_brate < IVAS_24k4 ) + { + switch ( strat ) + { + case BASE: + push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); + break; + case BASE_NOEC: + push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); + no_ec = 1; + break; + case FOUR_A: + case FOUR_C: + case FOUR_B: + case FOUR_D: + push_next_indice( hMetaData, strat, SPAR_NUM_CODING_STRAT_BITS ); + break; + } + /* for LBR SBA 40MS MD never do time diff */ + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + } + else + { + switch ( strat ) + { + case BASE: + push_next_indice( hMetaData, bands_bw - 1, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + break; + case BASE_NOEC: + push_next_indice( hMetaData, bands_bw + 1, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = 0; + } + no_ec = 1; + break; + case FOUR_A: + push_next_indice( hMetaData, 4, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 0 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_B: + push_next_indice( hMetaData, 5, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 1 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_C: + push_next_indice( hMetaData, 6, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 2 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + case FOUR_D: + push_next_indice( hMetaData, 7, SPAR_NUM_CODING_STRAT_BITS ); + for ( i = 0; i < nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != 3 ); + } + ivas_map_prior_coeffs_quant( &hMdEnc->spar_md_prior, &hMdEnc->spar_md_cfg, qsi, nB ); + break; + } + } + + if ( no_ec == 1 ) + { + entropy_coding_result = + ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, + bands_bw ); + } + else + { + entropy_coding_result = + ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, + strat, ivas_total_brate ); + } + + if ( entropy_coding_result < 0 ) + { + hMetaData->nb_bits_tot = 0; + } + + return; +} +#endif + + +/*-----------------------------------------------------------------------------------------* * Function ivas_get_huffman_coded_bs() * * Generate huffman coded bitstream *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_huffman_coded_bs_fx( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const Word16 nB, + const Word16 qsi, + const Word16 bands_bw ) +{ + Word16 i, j; + Word16 pred_coeff_dim, pred_offset; + + FOR( i = 0; i < nB; i++ ) + { + Word16 code, len; + Word16 ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i * bands_bw]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i * bands_bw]; + move16(); + move16(); + + pred_coeff_dim = sub( add( ndm, ndec ), 1 ); + pred_offset = 0; + move16(); + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + if ( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + pred_offset = DIRAC_TO_SPAR_HBR_PRED_CHS; + move16(); + } + } + + FOR( j = pred_offset; j < pred_coeff_dim; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + + Word16 n = imult1616( ndec, sub( ndm, 1 ) ); + FOR( j = 0; j < n; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + + FOR( j = 0; j < ndec; j++ ) + { + ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len ); + IF( GT_16( ( add( hMetaData->nb_bits_tot, len ) ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) + { + return -1; + } + push_next_indice( hMetaData, code, len ); + } + } + + return 0; +} +#else static int16_t ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, @@ -1881,6 +2155,7 @@ static int16_t ivas_get_huffman_coded_bs( return 0; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1888,6 +2163,203 @@ static int16_t ivas_get_huffman_coded_bs( * * Generate arithmetic coded bitstream *-----------------------------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_get_arith_coded_bs_fx( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const Word16 *pDo_diff, + const Word16 bands_bw, + const Word16 nB, + const Word16 qsi, + const Word16 strat, + const Word32 ivas_total_brate ) +{ + Word16 i, any_diff; + Word16 j; + ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t drct_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t decd_cell_dims[IVAS_MAX_NUM_BANDS]; + ivas_cell_dim_t decx_cell_dims[IVAS_MAX_NUM_BANDS]; + Word16 symbol_arr_re[IVAS_MAX_INPUT_LEN]; + Word16 symbol_arr_old_re[IVAS_MAX_INPUT_LEN]; + Word16 arith_result; + + FOR( i = 0; i < nB; i++ ) + { + Word16 ndm, ndec; + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[bands_bw * i]; + move16(); + move16(); + + test(); + test(); + test(); + test(); + test(); + IF( ( LT_32( ivas_total_brate, IVAS_24k4 ) ) && ( GT_16( strat, 3 ) ) && ( ( ( EQ_16( i % 2, 1 ) ) && ( strat % 2 == 0 ) ) || ( ( i % 2 == 0 ) && ( EQ_16( strat % 2, 1 ) ) ) ) ) + { + pred_cell_dims[i].dim1 = 0; + pred_cell_dims[i].dim2 = 0; + drct_cell_dims[i].dim1 = 0; + drct_cell_dims[i].dim2 = 0; + decd_cell_dims[i].dim1 = 0; + decd_cell_dims[i].dim2 = 0; + decx_cell_dims[i].dim1 = 0; + decx_cell_dims[i].dim2 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + pred_cell_dims[i].dim1 = sub( add( ndm, ndec ), 1 ); + move16(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + pred_cell_dims[i].dim1 = sub( pred_cell_dims[i].dim1, ( FOA_CHANNELS - 1 ) ); + move16(); + } + } + pred_cell_dims[i].dim2 = 1; + drct_cell_dims[i].dim1 = ndec; + drct_cell_dims[i].dim2 = sub( ndm, 1 ); + decd_cell_dims[i].dim1 = ndec; + decd_cell_dims[i].dim2 = 1; + decx_cell_dims[i].dim1 = shr( ( imult1616( ndec, sub( ndec, 1 ) ) ), 1 ); + decx_cell_dims[i].dim2 = 1; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + } + + any_diff = 0; + move16(); + FOR( i = 0; i < nB; i++ ) + { + IF( pDo_diff[i] != 0 ) + { + any_diff = 1; + move16(); + BREAK; + } + } + + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + FOR( i = 0; i < nB; i++ ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + FOR( j = 0; j < pred_cell_dims[i].dim1; j++ ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] = + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS]; + move16(); + IF( EQ_16( any_diff, 1 ) ) + { + hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j] = + hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS]; + move16(); + } + } + } + } + } + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, pred_cell_dims, PRED_COEFF ); + } + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + IF( arith_result < 0 ) + { + return -1; + } + + test(); + IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) + { + FOR( i = 0; i < nB; i++ ) + { + IF( GE_16( i, SPAR_DIRAC_SPLIT_START_BAND ) ) + { + FOR( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + DIRAC_TO_SPAR_HBR_PRED_CHS] = + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j]; + move16(); + } + FOR( j = 0; j < DIRAC_TO_SPAR_HBR_PRED_CHS; j++ ) + { + hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] = 0; + move16(); + } + } + } + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, drct_cell_dims, DRCT_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, drct_cell_dims, DRCT_COEFF ); + } + + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + + IF( arith_result < 0 ) + { + return -1; + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decd_cell_dims, DECD_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decd_cell_dims, DECD_COEFF ); + } + + arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB, + symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); + move16(); + + IF( arith_result < 0 ) + { + return -1; + } + + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decx_cell_dims, DECX_COEFF ); + + IF( EQ_16( any_diff, 1 ) ) + { + ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decx_cell_dims, DECX_COEFF ); + } + + return 0; +} +#else static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, @@ -2045,6 +2517,7 @@ static int16_t ivas_get_arith_coded_bs( return 0; } +#endif /*-----------------------------------------------------------------------------------------* @@ -2052,7 +2525,63 @@ static int16_t ivas_get_arith_coded_bs( * * Select next strategy *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_select_next_strat_fx( + ivas_strats_t prior_strat, + ivas_strats_t cs[MAX_QUANT_STRATS], + const Word16 dmx_switch, + const Word16 dtx_vad ) +{ + cs[0] = BASE; + move16(); + cs[1] = BASE_NOEC; + move16(); + + test(); + IF( dmx_switch == 0 && dtx_vad ) + { + SWITCH( prior_strat ) + { + case START: + cs[2] = NO_STRAT; + move16(); + BREAK; + case BASE: + cs[2] = FOUR_A; + move16(); + BREAK; + case BASE_DIFF: + cs[2] = FOUR_A; + move16(); + BREAK; + case BASE_NOEC: + cs[2] = FOUR_A; + move16(); + BREAK; + case FOUR_A: + cs[2] = FOUR_B; + move16(); + BREAK; + case FOUR_B: + cs[2] = FOUR_C; + move16(); + BREAK; + case FOUR_C: + cs[2] = FOUR_D; + move16(); + BREAK; + case FOUR_D: + cs[2] = FOUR_A; + move16(); + BREAK; + default: + assert( !"bad value of prior_strat" ); + } + } + return; +} +#else static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], @@ -2096,7 +2625,7 @@ static void ivas_select_next_strat( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_store_prior_coeffs() @@ -2330,85 +2859,105 @@ static void ivas_quant_p_per_band_dtx_fx( * Write MD DTX parameters into bitstream *-----------------------------------------------------------------------------------------*/ -static void ivas_write_parameter_bitstream_dtx( +static void ivas_write_parameter_bitstream_dtx_fx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, - int16_t *num_dmx, - int16_t *num_dec, - const int16_t num_bands ) + Word16 *num_dmx, + Word16 *num_dec, + const Word16 num_bands ) { int16_t i, j; - float val; - int16_t idx; - float pr_min_max[2]; - int16_t zero_pad_bits, sid_bits_len; + Word32 val; + Word16 idx; + Word32 pr_min_max[2]; + Word16 zero_pad_bits, sid_bits_len; sid_bits_len = hMetaData->nb_bits_tot; - pr_min_max[0] = pSpar_md->min_max[0]; - pr_min_max[1] = pSpar_md->min_max[1]; + move16(); + pr_min_max[0] = pSpar_md->min_max_fx[0]; + move32(); + pr_min_max[1] = pSpar_md->min_max_fx[1]; + move32(); - for ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { - int16_t ndm = num_dmx[i]; - int16_t ndec = num_dec[i]; + Word16 ndm = num_dmx[i]; + move16(); + Word16 ndec = num_dec[i]; + move16(); - for ( j = 0; j < FOA_CHANNELS - 1; j++ ) + FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) { - int16_t pr, pd; - int16_t pr_q_lvls, pd_q_lvls, pr_pd_bits; - int16_t pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; - uint16_t value; + Word16 pr, pd; + Word16 pr_q_lvls, pd_q_lvls, pr_pd_bits; + Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; + UWord16 value; pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + move16(); pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + move16(); pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + move16(); pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + move16(); - if ( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) + test(); + test(); + test(); + IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + move16(); pr = pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1]; + move16(); - if ( ( j + 1 ) > ndec ) + IF( GT_16( add( j, 1 ), ndec ) ) { pd_q_lvls = 1; + move16(); pd = 0; + move16(); } - else + ELSE { pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + move16(); pd = pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1]; + move16(); } - val = dtx_pd_real_min_max[0]; - ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 ); + val = dtx_pd_real_min_max_fx[0]; + move32(); + ivas_quantise_real_values_enc_fx( &val, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val, 1 ); - pd -= idx; + pd = sub( pd, idx ); val = pr_min_max[0]; - ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); + move32(); + ivas_quantise_real_values_enc_fx( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 ); - pr -= idx; - pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); + pr = sub( pr, idx ); + pr_pd_bits = ivas_get_bits_to_encode( i_mult( pd_q_lvls, pr_q_lvls ) ); - value = (uint16_t) ( pr * pd_q_lvls + pd ); + value = (UWord16) ( add( i_mult( pr, pd_q_lvls ), pd ) ); push_next_indice( hMetaData, value, pr_pd_bits ); } } } - sid_bits_len = hMetaData->nb_bits_tot - sid_bits_len; - zero_pad_bits = ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - sid_bits_len; + sid_bits_len = sub( hMetaData->nb_bits_tot, sid_bits_len ); + zero_pad_bits = sub( i_mult( SPAR_DTX_BANDS, SPAR_SID_BITS_TAR_PER_BAND ), sid_bits_len ); assert( zero_pad_bits >= 0 ); - if ( num_dmx[0] == 2 ) + IF( EQ_16( num_dmx[0], 2 ) ) { - zero_pad_bits -= 1; + zero_pad_bits = sub( zero_pad_bits, 1 ); } - while ( zero_pad_bits > 0 ) + WHILE( GT_16( zero_pad_bits, 0 ) ) { - j = min( zero_pad_bits, 16 ); + j = s_min( zero_pad_bits, 16 ); push_next_indice( hMetaData, 0, j ); - zero_pad_bits -= j; + zero_pad_bits = sub( zero_pad_bits, j ); } return; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 4f3b805cf7e72db6ee0a7152204327f0db21c7a1..ad0f7f379a2d89d93b2c40d4df95949b2976d020 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -949,6 +949,10 @@ typedef struct ivas_dirac_enc_data_structure int16_t no_col_avg_diff; float **buffer_intensity_real[DIRAC_NUM_DIMS]; float *buffer_energy; +#ifdef IVAS_FLOAT_FIXED + Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word32 *buffer_energy_fx; +#endif /* Frame count for detecting mono */ int16_t mono_frame_count; @@ -1020,7 +1024,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 num_decorr; float ***mixer_mat; - float ***mixer_mat_local; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 4bd59385850c79bf00a1030d0ee954c48c602e50..82f334783c1f5227fb64e7d8a7ef0782d92d2926 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1226,7 +1226,7 @@ void stereo_mdct_core_enc( hPrivateData = &hIGFEnc[ch]->igfData; hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; swb_offset = hGrid->swb_offset; - hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); + // hIGFEnc[ch]->tns_predictionGain = float_to_fix16( hIGFEnc[ch]->tns_predictionGain_flt, Q23 ); sts[ch]->hTcxEnc->spectrum_e[n] = 31 - Q_factor_arrL( sts[ch]->hTcxEnc->spectrum[n], hGrid->infoGranuleLen ); sts[ch]->hTcxEnc->spectrum_e[n] = s_max( sts[ch]->hTcxEnc->spectrum_e[n], 31 - Q_factor_arrL( &p_powerSpec[ch][0], hGrid->infoGranuleLen ) ); sts[ch]->hTcxEnc->spectrum_e[n] = s_max( sts[ch]->hTcxEnc->spectrum_e[n], 31 - Q_factor_arrL( inv_spectrum[ch][n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ) ); @@ -1235,57 +1235,6 @@ void stereo_mdct_core_enc( floatToFixed_arr32( &p_powerSpec[ch][0], &p_powerSpec_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[n], hGrid->infoGranuleLen ); floatToFixed_arr32( inv_spectrum[ch][n], inv_spectrum_fx[ch][n], 31 - sts[ch]->hTcxEnc->spectrum_e[n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); floatToFixed_arr32( powerSpecMsInv[ch][0], powerSpecMsInv_fx[ch][0], 31 - sts[ch]->hTcxEnc->spectrum_e[n], swb_offset[hGrid->sfbWrap[hGrid->nTiles]] ); - 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } - floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); } #endif /**********************************flt to fix ends here*******************************************************/ hIGFEnc[0]->spec_be_igf_e = p_orig_spectrum_e[0]; @@ -1345,59 +1294,6 @@ void stereo_mdct_core_enc( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } - int igfGridIdx; if ( st->last_core == ACELP_CORE && st->core == TCX_20_CORE ) { @@ -1433,11 +1329,7 @@ void stereo_mdct_core_enc( q_powerSpec = L_get_q_buf1( &powerSpec[ch][n * L_subframeTCX], hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); floatToFixed_arrL32( &powerSpec[ch][n * L_subframeTCX], &powerSpec_fx[ch][n * L_subframeTCX], q_powerSpec, hPrivateData->igfInfo.grid[igfGridIdx].infoGranuleLen ); - if ( st->hIGFEnc ) - { - st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); - } - floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); + #endif ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powerSpec, st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -1508,58 +1400,6 @@ void stereo_mdct_core_enc( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 = max( 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 ); - } - } int igfGridIdx; if ( st->last_core == ACELP_CORE && st->core == TCX_20_CORE ) @@ -1600,7 +1440,7 @@ void stereo_mdct_core_enc( { st->hIGFEnc->tns_predictionGain = float_to_fix16( st->hIGFEnc->tns_predictionGain_flt, Q23 ); } - floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); + // floatToFixed_arr16( &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold_flt[0][0], &hPrivateData->igfInfo.grid[igfGridIdx].whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); #endif ProcessIGF_ivas_fx( st, st->hTcxEnc->spectrum_fx[n], orig_spectrum_fx[ch][n], &q_spectrum, &powerSpec_fx[ch][n * L_subframeTCX], &q_powerSpec, st->core == TCX_20_CORE, n, hCPE->hCoreCoder[0]->sp_aud_decision0, 0 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS