From 3c39f43f91f2a76e890e1e6c802c04ff58d7fe6b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 18 Oct 2024 18:21:14 +0530 Subject: [PATCH 1/2] MSAN error fixed, LTV crash fixes and Q-info update for decoder files --- lib_com/prot_fx.h | 4 +- lib_com/tools_fx.c | 2 + lib_dec/ACcontextMapping_dec_fx.c | 33 ++- lib_dec/acelp_core_dec_ivas_fx.c | 217 +++++++-------- lib_dec/acelp_core_switch_dec_fx.c | 70 ++--- lib_dec/hf_synth_fx.c | 8 +- lib_dec/ivas_ism_renderer.c | 52 ++-- lib_dec/ivas_jbm_dec.c | 395 +++++++++++++++------------- lib_dec/ivas_pca_dec_fx.c | 95 +++---- lib_dec/ivas_post_proc.c | 184 ++++++------- lib_dec/ivas_qspherical_dec.c | 22 +- lib_dec/ivas_range_uni_dec.c | 146 +++++----- lib_enc/acelp_core_enc.c | 14 + lib_enc/cod_tcx.c | 81 +++++- lib_enc/init_enc.c | 4 + lib_enc/ivas_core_enc.c | 7 + lib_enc/ivas_core_pre_proc.c | 2 + lib_enc/ivas_cpe_enc.c | 6 + lib_enc/ivas_dirac_enc.c | 3 + lib_enc/ivas_front_vad.c | 2 + lib_enc/ivas_masa_enc.c | 3 + lib_enc/ivas_mdct_core_enc.c | 11 + lib_enc/ivas_sns_enc.c | 9 + lib_enc/ivas_stereo_mdct_core_enc.c | 3 + lib_enc/transient_detection_fx.c | 4 + 25 files changed, 764 insertions(+), 613 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c0a3b61a4..6befe335c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8162,8 +8162,8 @@ void decod_amr_wb_fx( // rst_dec_fx.c void CNG_reset_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Word16 *pitch_buf, /* o : floating pitch for each subframe Q6*/ + Word16 *voice_factors /* o : voicing factors Q15*/ ); // voiced_dec_fx.c diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 5c733b1df..3580e632e 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -93,6 +93,8 @@ Word16 float_to_fix16( float number, Word16 Q ) return 0; if ( number == 1.0f && Q == Q15 ) return MAX16B; + if ( number == -1.0f && Q == Q15 ) + return MIN16B; assert( fabs( number ) < pow( 2, 15 - Q ) ); Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); return ret; diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index 89a7e1890..df1ae4cc8 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -22,7 +22,7 @@ #ifdef IVAS_FLOAT_FIXED Word16 ACcontextMapping_decode2_no_mem_s17_LC( Decoder_State *st, /* i/o: decoder state */ - Word16 *x, /* o: decoded spectrum */ + Word16 *x, /* o: decoded spectrum Q0*/ Word16 nt, /* i: size of spectrum */ Word16 nbbits, /* i: bit budget */ Word16 resQMaxBits, /* i: residual coding maximum bits*/ @@ -40,6 +40,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( Word16 resQBits; Word16 rest_bits, rest_bits_overflow; Word16 tmp = 0; /* initialize just to avoid compiler warning */ + move16(); Word16 nt_half; Word16 c[2], *ctx; Word16 p1, p2; @@ -59,7 +60,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /* Rate flag */ rateFlag = 0; move16(); - IF( GT_16( nbbits, 400 ) ) + if ( GT_16( nbbits, 400 ) ) { rateFlag = 2 << NBITS_CONTEXT; move16(); @@ -86,7 +87,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); lastnz = shl( n, 1 ); - + test(); IF( GT_16( lastnz, nt ) || st->BER_detect ) { st->BER_detect = 1; @@ -118,7 +119,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); get_next_coeff = get_next_coeff_mapped; - move16(); } ELSE /* unmapped domain */ { @@ -130,7 +130,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( move16(); get_next_coeff = get_next_coeff_unmapped; - move16(); } /* Start Decoding */ @@ -174,10 +173,10 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( La = L_deposit_l( 0 ); Lb = L_deposit_l( 0 ); /* MSBs decoding */ - test(); + FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++ ) { - test(); + esc_nb = s_min( lev, 3 ); tmp = add( t, Tab_esc_nb[esc_nb] ); assert( tmp >= 0 && tmp < 4096 ); @@ -217,11 +216,11 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*lsbs bits sign bits*/ rest_bits = add( rest_bits, shl( lev, 1 ) ); - IF( a > 0 ) + if ( a > 0 ) { rest_bits = add( rest_bits, 1 ); } - IF( b > 0 ) + if ( b > 0 ) { rest_bits = add( rest_bits, 1 ); } @@ -293,12 +292,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } /*Decode signs*/ - IF( hm_cfg ) + if ( hm_cfg ) { tmp = nt; move16(); } - IF( !hm_cfg ) + if ( !hm_cfg ) { tmp = lastnz; move16(); @@ -344,7 +343,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( /*! r: resQBits */ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( Decoder_State *st, /* i/o: decoder state */ - Word16 *x, /* o : decoded spectrum */ + Word16 *x, /* o : decoded spectrum Q0*/ const Word16 nt, /* i : size of spectrum */ const Word16 nbbits, /* i : bit budget */ const Word16 resQMaxBits, /* i : residual coding maximum bits */ @@ -376,7 +375,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( k = 1; move16(); nt_half = shr( nt, 1 ); - WHILE( LT_16( k, nt_half ) ) + WHILE( k < nt_half ) { n = add( n, 1 ); k = shl( k, 1 ); @@ -390,7 +389,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( move16(); lastnz = shl( n, 1 ); - if ( GT_16( lastnz, nt ) ) + IF( GT_16( lastnz, nt ) ) { st->BER_detect = 1; move16(); @@ -463,7 +462,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( t = add( *ctx, rateFlag ); IF( LT_16( nt_half, idx ) ) { - t = add( t, shl( 1, NBITS_CONTEXT ) ); + t = add( t, ( 1 << NBITS_CONTEXT ) ); } esc_nb = 0; @@ -486,7 +485,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { esc_nb = s_min( lev, 3 ); - pki = ari_lookup_s17_LC[add( t, Tab_esc_nb[esc_nb] )]; + pki = ari_lookup_s17_LC[t + Tab_esc_nb[esc_nb]]; move16(); r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ @@ -645,7 +644,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { esc_nb = s_min( lev, 3 ); - pki = ari_lookup_s17_LC[add( t, add( shl( ( rateQ ), NBITS_CONTEXT ), Tab_esc_nb[esc_nb] ) )]; + pki = ari_lookup_s17_LC[t + ( ( rateQ << NBITS_CONTEXT ) + Tab_esc_nb[esc_nb] )]; move16(); r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 362a3ff8c..8b2313360 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -55,18 +55,18 @@ static void rescale_fdCngDec( HANDLE_FD_CNG_DEC hFdCngDec, Word16 old_NoiseExp ); ivas_error acelp_core_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs */ - Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ + Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 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 */ - const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle Qlog2(2.56)*/ + const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel Q15*/ const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const Word16 last_element_mode, /* i : last element mode */ @@ -209,11 +209,11 @@ ivas_error acelp_core_dec_ivas_fx( /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); - Copy( Aq_fx, st->Aq_cng, M + 1 ); + Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/ /* update old LSP and LSF vector */ - Copy( lsf_new_fx, st->lsf_old_fx, M ); - Copy( lsp_new_fx, st->lsp_old_fx, M ); + Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/ + Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ } set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ @@ -235,9 +235,7 @@ ivas_error acelp_core_dec_ivas_fx( set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer_fx[i] = realBufferTmp_fx[i]; - move32(); imagBuffer_fx[i] = imagBufferTmp_fx[i]; - move32(); } /*----------------------------------------------------------------* * Initialization @@ -282,7 +280,7 @@ ivas_error acelp_core_dec_ivas_fx( } test(); - IF( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) + if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ st->hGSCDec->Last_frame_ener_fx = MAX_32; @@ -310,7 +308,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); tmp_noise_fx = 0; move16(); - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ exc_fx = old_exc_fx + L_EXC_MEM_DEC; IF( st->hWIDec != NULL ) @@ -325,7 +323,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( st->hBWE_TD != NULL ) { - Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( st->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 @@ -423,8 +421,8 @@ ivas_error acelp_core_dec_ivas_fx( IF( ( st->hPFstat->on != 0 ) ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; - mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); - mem_syn_r_size_new = mult_r( 2048, st->L_frame ); + mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/ + mem_syn_r_size_new = mult_r( 2048, st->L_frame ); /* 1.25/20.f = 2048 (Q15)*/ lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } @@ -437,18 +435,18 @@ ivas_error acelp_core_dec_ivas_fx( lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs ); /* FEC - update adaptive LSF mean vector */ - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/ /* Reset LPC mem */ IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } set16_fx( st->mem_MA_fx, 0, M ); @@ -465,9 +463,9 @@ ivas_error acelp_core_dec_ivas_fx( #else ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); #endif - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ - Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); + Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ } /* update buffer of old subframe pitch values */ @@ -477,29 +475,29 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - tmpF_fx = 13107; + tmpF_fx = 13107; // Q15 move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { - tmpF_fx = 26214; + tmpF_fx = 26214; // Q15 move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); + st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); + st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } } @@ -509,12 +507,12 @@ ivas_error acelp_core_dec_ivas_fx( move16(); IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - tmpF_fx = 20480; + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ @@ -526,7 +524,7 @@ ivas_error acelp_core_dec_ivas_fx( } FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); + st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2]; @@ -534,7 +532,7 @@ ivas_error acelp_core_dec_ivas_fx( FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); + st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1]; @@ -548,17 +546,17 @@ ivas_error acelp_core_dec_ivas_fx( { IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - tmpF_fx = 13107; + tmpF_fx = 13107; // Q15 move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { - tmpF_fx = 26214; + tmpF_fx = 26214; // Q15 move16(); } st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); @@ -572,12 +570,12 @@ ivas_error acelp_core_dec_ivas_fx( move16(); IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - tmpF_fx = 16384; + tmpF_fx = 16384; // Q15 move16(); } ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - tmpF_fx = 20480; + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ @@ -626,7 +624,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( GT_16( st->element_mode, EVS_MONO ) && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { test(); test(); @@ -649,8 +647,8 @@ ivas_error acelp_core_dec_ivas_fx( CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); @@ -676,7 +674,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FdCng_decodeSID_ivas_fx( st ); rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx *sid_bw = 0; move16(); } @@ -703,13 +701,13 @@ ivas_error acelp_core_dec_ivas_fx( ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); Word16 new_sidNoiseEstExp = 31 - Q4; move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; move16(); Word16 new_cngNoiseLevelExp = 31 - Q4; move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp ); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; move16(); @@ -718,7 +716,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; move16(); } @@ -728,9 +726,9 @@ ivas_error acelp_core_dec_ivas_fx( { Word32 noise_lvl_highest_fx; - noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[sub( sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ), 1 )]; + noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1]; move32(); - FOR( Word16 b = sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) + FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; move32(); @@ -747,7 +745,7 @@ ivas_error acelp_core_dec_ivas_fx( Word16 delta_mem_scale = 3; move16(); test(); - if ( LT_32( st->lp_ener_fx, 40 ) && EQ_16( st->cng_type, LP_CNG ) ) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); @@ -770,7 +768,7 @@ ivas_error acelp_core_dec_ivas_fx( Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL ); } - Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); + Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc /* update past excitation signals for LD music post-filter */ IF( st->hMusicPF != NULL ) @@ -782,7 +780,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { - st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15, 9830 =.3f in Q15, 22937=.7f in Q15 move16(); } } @@ -801,13 +799,13 @@ ivas_error acelp_core_dec_ivas_fx( CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); /* update st->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); + Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1) /* update old synthesis for classification */ Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); + Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn IF( st->hBWE_FD != NULL ) { save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); @@ -862,12 +860,12 @@ ivas_error acelp_core_dec_ivas_fx( /*-----------------------------------------------------------------* * After CNG period, use the most up-to-date LSPs *-----------------------------------------------------------------*/ - test(); + test(); test(); IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { - Copy( st->lspCNG_fx, st->lsp_old_fx, M ); + Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/ lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); } @@ -947,8 +945,8 @@ ivas_error acelp_core_dec_ivas_fx( FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); // Q(x-2) + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } test(); @@ -957,7 +955,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Prepare ACB memory from last HQ frame */ old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ); tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = shl_sat( old_exc_s_fx[sub( st->L_frame, 1 )], st->Q_syn ); /* Q0 -> Q_syn */ + st->mem_deemph_fx = shl_sat( old_exc_s_fx[ st->L_frame- 1], st->Q_syn ); /* Q0 -> Q_syn */ move16(); PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); @@ -1062,7 +1060,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( st->nelp_mode_dec ) { /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); /* SC-VBR - NELP frames */ @@ -1077,7 +1075,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE IF( st->ppp_mode_dec ) { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); /* SC-VBR - PPP frames */ @@ -1092,7 +1090,7 @@ ivas_error acelp_core_dec_ivas_fx( { decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); } - ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx @@ -1106,7 +1104,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1182,7 +1180,7 @@ ivas_error acelp_core_dec_ivas_fx( LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); @@ -1192,6 +1190,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); + test(); #ifdef FIX_843_LOW_RATE_BWE if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO ) #else @@ -1215,7 +1214,7 @@ ivas_error acelp_core_dec_ivas_fx( Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); IF( st->hMusicPF != NULL ) @@ -1257,8 +1256,8 @@ ivas_error acelp_core_dec_ivas_fx( * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - move16(); - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); // Q0 FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); @@ -1269,7 +1268,7 @@ ivas_error acelp_core_dec_ivas_fx( /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); } } @@ -1306,14 +1305,14 @@ ivas_error acelp_core_dec_ivas_fx( FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif { - Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, M + 1 )] ), Q2 ) ); - Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + imult3216( nsf, ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[nsf * ( M + 1 )] ), Q2 ) ); // Qx->Q(x-2) + Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; move16(); } IF( EQ_16( st->nelp_mode_dec, 1 ) ) { /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 st->Q_exc = 0; move16(); @@ -1410,7 +1409,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); // Q0 FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, @@ -1445,10 +1444,10 @@ ivas_error acelp_core_dec_ivas_fx( * Apply NB postfilter in case of 8kHz output *--------------------------------------------------------*/ test(); - IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) + IF( st->last_bwidth == NB && st->hPFstat != NULL ) { Copy( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k ); - IF( EQ_16( st->bwidth, NB ) ) + IF( st->bwidth == NB ) { st->hPFstat->on = 1; move16(); @@ -1533,7 +1532,9 @@ ivas_error acelp_core_dec_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ + test(); st->VAD = st->VAD && st->coder_type != INACTIVE; + move16(); test(); test(); test(); @@ -1594,6 +1595,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { + test(); IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { /* Clear memory for secondary channel CNA */ @@ -1617,6 +1619,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) { + test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); @@ -1625,16 +1628,16 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) ); move16(); } } } ELSE { - if ( hStereoCng != NULL ) + IF( hStereoCng != NULL ) { hStereoCng->flag_cna_fade = 1; move16(); @@ -1668,9 +1671,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } @@ -1714,7 +1717,7 @@ ivas_error acelp_core_dec_ivas_fx( Word32 pitch_buf_fx_q20[12]; - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) Word16 lim = shr( st->L_frame, 6 ); FOR( Word16 lp = 0; lp < lim; lp++ ) { @@ -1722,7 +1725,7 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) @@ -1768,7 +1771,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 #endif Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 } #ifdef MSAN_FIX @@ -1818,7 +1821,7 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); /* set output mask for upsampling */ @@ -1889,8 +1892,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); // Q_imag } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) @@ -1899,7 +1902,7 @@ ivas_error acelp_core_dec_ivas_fx( #endif st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); + Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); // Q_real-1 FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { @@ -1921,7 +1924,7 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( save_hb_synth_fx, L_FRAME48k, negate( ( sub( Q_real, 1 ) ) ) ); // Q0 Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; move16(); @@ -1940,7 +1943,7 @@ ivas_error acelp_core_dec_ivas_fx( st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); + Scale_sig32( synth_fx, L_FRAME48k, negate( sub( Q_real, 1 ) ) ); // Q0 Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; move16(); @@ -1972,8 +1975,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) @@ -1988,7 +1991,7 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); + scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif @@ -2002,7 +2005,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE { - Word16 nSamples = NS2SA_FX2( st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX @@ -2051,7 +2054,7 @@ ivas_error acelp_core_dec_ivas_fx( addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ @@ -2079,8 +2082,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real } #ifdef FIX_882_LOW_LEVEL_DISCONTINUITIES scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) @@ -2094,11 +2097,11 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); + Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; move16(); IF( st->p_bpf_noise_buf_32 ) @@ -2106,7 +2109,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 } set32_fx( synth_fx, 0, output_frame ); @@ -2116,11 +2119,11 @@ ivas_error acelp_core_dec_ivas_fx( #ifndef MSAN_FIX Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); #else - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 #endif IF( st->element_mode > EVS_MONO ) { - Copy( psyn_fx, output_fx, st->L_frame ); + Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ } st->Q_syn2 = 0; @@ -2137,7 +2140,7 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && + IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { #ifndef FIX_774_ENERGY_BURST @@ -2145,7 +2148,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); #endif #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif @@ -2221,9 +2224,9 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { - Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc } test(); if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) @@ -2260,10 +2263,10 @@ ivas_error acelp_core_dec_ivas_fx( { IF( save_hb_synth_fx16 ) { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0 } #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 #else Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 81f58bd27..bedc88438 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -27,7 +27,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ const Word16 output_frame, /* i : input frame length */ const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ + Word16 *mem_synth, /* o : synthesis to overlap Q0 */ Word16 *Q_syn ) { Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; @@ -58,9 +58,7 @@ ivas_error acelp_core_switch_dec_fx( set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer[i] = realBufferTmp[i]; - move32(); imagBuffer[i] = imagBufferTmp[i]; - move32(); } /* initializations */ @@ -69,8 +67,8 @@ ivas_error acelp_core_switch_dec_fx( gain = 0; move16(); - Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); + Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); // Q12 + Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); // Q12 set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ @@ -93,14 +91,15 @@ ivas_error acelp_core_switch_dec_fx( IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( ( ( st_fx->last_core == ACELP_CORE ) ) || ( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) ) { exc = old_exc + L_EXC_MEM_DEC; - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame*/ + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame Q_exc*/ IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - IF( GT_32( cbrate, ACELP_24k40 ) ) + if ( GT_32( cbrate, ACELP_24k40 ) ) { - cbrate = L_add( ACELP_24k40, 0 ); + cbrate = ACELP_24k40; + move32(); } L_frame_for_cs = L_FRAME; @@ -110,11 +109,13 @@ ivas_error acelp_core_switch_dec_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - cbrate = L_add( ACELP_8k00, 0 ); + cbrate = ACELP_8k00; + move32(); } ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) { - cbrate = L_add( ACELP_14k80, 0 ); + cbrate = ACELP_14k80; + move32(); } ELSE { @@ -141,10 +142,12 @@ ivas_error acelp_core_switch_dec_fx( syn_12k8_fx( 2 * L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) + test(); + IF( st_fx->hPFstat->on && ( st_fx->last_bwidth == NB ) ) { Word16 tmp_noise, pitch_buf_tmp[2]; tmp_noise = 0; + move16(); FOR( i = 0; i < 2; i++ ) { pitch_buf_tmp[i] = L_SUBFR; @@ -166,7 +169,7 @@ ivas_error acelp_core_switch_dec_fx( Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR ); test(); - IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) + IF( st_fx->hPFstat->on && ( st_fx->last_bwidth != NB ) ) { Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, bpf_error_signal, M ); Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR ); @@ -177,7 +180,6 @@ ivas_error acelp_core_switch_dec_fx( blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 ); } st_fx->hPFstat->on = 0; - move16(); IF( st_fx->flag_cna ) @@ -235,7 +237,7 @@ ivas_error acelp_core_switch_dec_fx( *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), L_sub( SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), ( SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* * BWE decoding @@ -252,7 +254,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); ind1 = (Word16) get_next_indice_fx( st_fx, NOOFGAINBITS1 ); move16(); - gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr( DELTAOFFIRSTGAIN_FX, 3 ) ); /*Q13*/ + gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, DELTAOFFIRSTGAIN_FX >> 3 ); /*Q13*/ decode_bwe = 1; move16(); } @@ -416,7 +418,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( tmp_noise = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc exc = old_exc + L_EXC_MEM_DEC; IF( st_fx->hWIDec != NULL ) { @@ -429,7 +431,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( exc2 = old_exc2 + L_EXC_MEM; IF( st_fx->hBWE_TD != NULL ) { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); // Q_exc bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } ELSE @@ -469,7 +471,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); /* SC-VBR */ @@ -592,7 +594,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); /* output to Q0 */ - Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 cldfb_restore_memory( st_fx->cldfbSyn ); @@ -663,7 +665,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( tmp_noise = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc exc = old_exc + L_EXC_MEM_DEC; IF( st_fx->hWIDec != NULL ) { @@ -716,7 +718,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { Word16 gain_buf[NB_SUBFR16k]; - Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); + Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 st_fx->Q_exc = 0; move16(); /* SC-VBR */ @@ -771,7 +773,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Rescale_mem( 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, 0, NULL ); #ifdef FIX_907_MEM_UPDATE_ISSUE - Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); + Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn #endif Copy( st_fx->mem_syn2_fx, tmp1, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn ); @@ -820,12 +822,13 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( tmp5, hBPF->Track_on_hist, L_TRACK_HIST ); Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST ); hBPF->psf_att_fx = tmp7; + move16(); /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ Qtmp = sub( 11, st_fx->Q_syn ); - Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); + Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) { return error; @@ -842,16 +845,17 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( } /*cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ - Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); // Q_cldfb_state+1 st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); move16(); Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 5 ); /*11-5-1*/ // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); - Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); + Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); // Q_cldfb_state-1 st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 ); - Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); + move16(); + Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); // 11-5-1 -> 11 // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); @@ -871,19 +875,19 @@ static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient */ - Word16 *exc, /* i/o: adapt. excitation exc */ + const Word16 *Aq, /* i : LP filter coefficient Q_12 */ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ const Word32 core_brate, /* i : switching frame bit-rate */ Word16 *Q_exc ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ Word16 gain_pit, gain_code16; /* pitch gain */ Word32 gain_code, L_tmp; /* gain/normalized gain of the algebraic excitation */ - Word32 norm_gain_code; /* normalized gain of the algebraic excitation */ - Word16 gain_inov; /* Innovation gain */ - Word16 voice_fac; /* voicing factor */ - Word16 code[L_SUBFR]; /* algebraic codevector */ - Word16 pitch; /* pointer to floating pitch */ + Word32 norm_gain_code; /* normalized gain of the algebraic excitation Q16 */ + Word16 gain_inov; /* Innovation gain Q12 */ + Word16 voice_fac; /* voicing factor Q15*/ + Word16 code[L_SUBFR]; /* algebraic codevector Q9*/ + Word16 pitch; /* pointer to floating pitch Q6*/ Word16 i; /* tmp variables */ Word16 pitch_limit_flag; Word16 *pt1; diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 626796be2..21989d052 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -93,10 +93,10 @@ void hf_synth_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ const Word32 core_brate, /* i : core bitrate */ const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ + const Word16 *Aq, /* i : quantized Az Q12 */ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc */ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2 */ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2 */ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index b910052d8..68998a30e 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -178,7 +178,7 @@ ivas_error ivas_ism_renderer_open_fx( st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); move16(); } - st_ivas->hIsmRendererData->interpolator_fx[sub( interpolator_length, 1 )] = 32767; + st_ivas->hIsmRendererData->interpolator_fx[interpolator_length - 1] = 32767; // (1.0f in Q15 )- 1 move16(); return IVAS_ERR_OK; @@ -218,7 +218,7 @@ void ivas_ism_renderer_close( ) { test(); - if ( hIsmRendererData == NULL || *hIsmRendererData == NULL ) + IF( hIsmRendererData == NULL || *hIsmRendererData == NULL ) { return; } @@ -374,7 +374,7 @@ void ivas_ism_render_sf( #else void ivas_ism_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: core-coder transport channels/object output */ + Word32 *output_fx[], /* i/o: core-coder transport channels/object output Q11*/ const Word16 n_samples_to_render /* i : output frame length per channel */ ) { @@ -409,7 +409,7 @@ void ivas_ism_render_sf_fx( { FOR( i = 0; i < num_objects; i++ ) { - p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; + p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; // Q11 } } ELSE @@ -440,9 +440,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { - rotateAziEle_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); - move16(); - move16(); + rotateAziEle_fx( extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ) ), extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ) ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); IF( st_ivas->hEFAPdata != NULL ) { @@ -480,8 +478,8 @@ void ivas_ism_render_sf_fx( tc_fx = p_tc_fx[i]; FOR( k = 0; k < n_samples_to_render; k++ ) { - g2_fx = sub( 32767, *g1_fx ); - output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); + g2_fx = sub( 32767, *g1_fx ); // 32767 = (1.0f in Q15) - 1 + output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); // Q11( (30+15+1-16) + 11 -31 +1) move16(); } } @@ -490,7 +488,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; // Q30 move32(); } } @@ -512,10 +510,10 @@ void ivas_ism_render_sf_fx( #ifdef IVAS_FLOAT_FIXED void ivas_ism_get_stereo_gains_fx( - const Word16 aziDeg, /* i : object azimuth */ - const Word16 eleDeg, /* i : object elevation */ - Word16 *left_gain_fx, /* o : left channel gain */ - Word16 *right_gain_fx /* o : right channel gain */ + const Word16 aziDeg, /* i : object azimuth Q0*/ + const Word16 eleDeg, /* i : object elevation Q0*/ + Word16 *left_gain_fx, /* o : left channel gain Q15*/ + Word16 *right_gain_fx /* o : right channel gain Q15*/ ) { /* Convert azi and ele to an azi value of the cone of confusion */ @@ -525,27 +523,27 @@ void ivas_ism_get_stereo_gains_fx( const Word16 *ptr_sin_az = ivas_sin_az_fx; - WHILE( GT_16( azAddEl, 180 ) ) + WHILE( azAddEl > 180 ) { azAddEl = sub( azAddEl, 360 ); } - WHILE( LT_16( azAddEl, -180 ) ) + WHILE( azAddEl < -180 ) { azAddEl = add( azAddEl, 360 ); } - WHILE( GT_16( azSubEl, 180 ) ) + WHILE( azSubEl > 180 ) { azSubEl = sub( azSubEl, 360 ); } - WHILE( LT_16( azSubEl, -180 ) ) + WHILE( azSubEl < -180 ) { azSubEl = add( azSubEl, 360 ); } Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) - { /* Left side */ - gains[0] = (Word16) 0x7fff; + { /* Left side */ + gains[0] = (Word16) 0x7fff; // 1.0f in Q15 move16(); gains[1] = 0; move16(); @@ -554,7 +552,7 @@ void ivas_ism_get_stereo_gains_fx( { /* Right side */ gains[0] = 0; move16(); - gains[1] = (Word16) 0x7fff; + gains[1] = (Word16) 0x7fff; // 1.0f in Q15 move16(); } ELSE /* Tangent panning law */ @@ -984,8 +982,8 @@ void ivas_omasa_separate_object_render_jbm( void ivas_omasa_separate_object_render_jbm_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesRendered, /* i : number of samples rendered */ - Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal Q11*/ + Word32 *output_fx[], /* o : rendered time signal Q11*/ const Word16 subframes_rendered, /* i : number of subframes rendered */ const Word16 slots_rendered /* i : number of CLDFB slots rendered */ ) @@ -1038,7 +1036,7 @@ void ivas_omasa_separate_object_render_jbm_fx( offsetSamples = i_mult( slots_rendered, hSpatParamRendCom->slot_size ); - FOR( j = 0; j < add( nchan_out_woLFE, num_lfe ); j++ ) + FOR( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) { output_fx_local[j] = output_fx[j]; } @@ -1137,7 +1135,7 @@ void ivas_omasa_separate_object_render_jbm_fx( { IF( hDirACRend->hOutSetup.num_lfe > 0 ) { - j2 = add( j, (Word16) GE_16( j, lfe_index ) ); + j2 = add( j, extract_l( GE_16( j, lfe_index ) ) ); } ELSE { @@ -1152,9 +1150,9 @@ void ivas_omasa_separate_object_render_jbm_fx( { g1_fx = hRendererData->interpolator_fx[k]; move16(); - g2_fx = sub( 32767, g1_fx ); + g2_fx = sub( 32767, g1_fx ); // 32767 = 1.0f in Q15 - output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][add( k, offsetSamples )], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][add( k, offsetSamples )], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); + output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][k + offsetSamples], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); // Q11( (30+15+1-16) + 11 -31 +1) move32(); } } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 14101fcd0..dcbd10839 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -97,11 +97,12 @@ static Word16 ceil_fx16( Word16 inp, Word16 Q ) #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx ) + Word32 *data_fx /*Q11*/ +) { Word16 n, output_frame, nchan_out, i; Decoder_State *st; /* used for bitstream handling */ - Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */ + Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */ Word16 nchan_remapped; Word16 nb_bits_metadata[MAX_SCE + 1]; Word32 output_Fs, ivas_total_brate; @@ -132,6 +133,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ ) { p_output_fx[n] = st_ivas->p_output_fx[n]; + IF( p_output_fx[n] != NULL ) { set32_fx( p_output_fx[n], 0, L_FRAME48k ); @@ -188,8 +190,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 } /* HP filtering */ @@ -206,12 +208,12 @@ ivas_error ivas_jbm_dec_tc_fx( s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, s ); + Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) } ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 } } } @@ -239,7 +241,7 @@ ivas_error ivas_jbm_dec_tc_fx( { shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) ) st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); move16(); @@ -298,7 +300,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } } @@ -322,7 +324,7 @@ ivas_error ivas_jbm_dec_tc_fx( st = st_ivas->hCPE[0]->hCoreCoder[0]; } - IF( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -334,7 +336,7 @@ ivas_error ivas_jbm_dec_tc_fx( } ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) { return error; } @@ -369,7 +371,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -377,8 +379,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) @@ -407,7 +409,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 } SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 nchan_transport; @@ -437,7 +439,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); move16(); @@ -450,16 +452,16 @@ ivas_error ivas_jbm_dec_tc_fx( } q = hCPE->hStereoDft->q_dft; move16(); - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } @@ -484,15 +486,15 @@ ivas_error ivas_jbm_dec_tc_fx( test(); test(); test(); - IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ + IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ { IF( !st->tcxonly ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } } } @@ -508,7 +510,7 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } } } @@ -516,30 +518,30 @@ ivas_error ivas_jbm_dec_tc_fx( #else scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); #endif - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); // q_prev_synth_fx } #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); @@ -554,7 +556,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifdef MSAN_FIX FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), 11 - hCPE->q_prev_synth_fx ); + Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 } #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); @@ -563,14 +565,14 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB } IF( hCPE->hStereoDft != NULL ) { @@ -595,13 +597,13 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ { IF( !st->tcxonly ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } } } @@ -617,21 +619,24 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } } } } #else - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 #endif - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; test(); } + + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + move16(); FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -641,7 +646,6 @@ ivas_error ivas_jbm_dec_tc_fx( { nchan_remapped = 1; /* Only one channel transported */ move16(); - test(); } /* HP filtering */ @@ -681,13 +685,13 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( ch = 0; ch < nchan_transport; ch++ ) { - Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); + Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output) } ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { - Scale_sig32( p_output_fx[c], output_frame, 11 ); + Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11 } } ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) @@ -699,7 +703,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < size; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 } ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame ); @@ -725,7 +729,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } } @@ -782,7 +786,7 @@ ivas_error ivas_jbm_dec_tc_fx( } /* MASA metadata decoding */ - IF( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -792,7 +796,7 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - IF( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -809,7 +813,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -846,7 +850,7 @@ ivas_error ivas_jbm_dec_tc_fx( ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* sanity check in case of bitrate switching */ - IF( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } @@ -862,7 +866,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ ) { - Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); + Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11 } } } @@ -912,7 +916,7 @@ ivas_error ivas_jbm_dec_tc_fx( { set32_fx( p_output_fx[0], 0, L_FRAME48k ); - IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -923,7 +927,7 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -931,13 +935,13 @@ ivas_error ivas_jbm_dec_tc_fx( IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -947,7 +951,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { - Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); + Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14 } SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; Word16 nchan_transport; @@ -974,7 +978,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); move16(); @@ -991,42 +995,42 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), hCPE->q_prev_synth_fx - 11 ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -1038,35 +1042,35 @@ ivas_error ivas_jbm_dec_tc_fx( #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -1097,7 +1101,7 @@ ivas_error ivas_jbm_dec_tc_fx( move16(); FOR( ch = 0; ch < nchan_transport; ch++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, sub( Q_p_output, Q11 ) ); + Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, sub( Q_p_output, Q11 ) ); // Q_p_output } hSpar->hMdDec->Q_mixer_mat = 31; move16(); @@ -1105,7 +1109,7 @@ ivas_error ivas_jbm_dec_tc_fx( ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { - Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); + Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11 } } ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 ) @@ -1118,7 +1122,7 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = sba_ch_idx; i < size; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, sub( Q14, Q11 ) ); + Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14 } ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame ); @@ -1133,14 +1137,14 @@ ivas_error ivas_jbm_dec_tc_fx( FOR( i = 0; i < nchan_remapped; i++ ) { - Scale_sig32( p_output_fx[i], output_frame, 1 ); + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q } } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame ); - Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); + Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11 /* add W */ FOR( n = 0; n < nchan_out; n++ ) @@ -1167,8 +1171,8 @@ ivas_error ivas_jbm_dec_tc_fx( /* LFE channel decoder */ ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); - IF( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ) != IVAS_ERR_OK ) + Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1186,7 +1190,7 @@ ivas_error ivas_jbm_dec_tc_fx( test(); IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { - IF( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ) + IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) { ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); } @@ -1203,12 +1207,12 @@ ivas_error ivas_jbm_dec_tc_fx( s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, s ); + Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) } ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 } } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) @@ -1222,7 +1226,7 @@ ivas_error ivas_jbm_dec_tc_fx( /* LFE channel decoder */ ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); + Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); @@ -1283,15 +1287,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) @@ -1349,15 +1353,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */ @@ -1368,7 +1372,7 @@ ivas_error ivas_jbm_dec_tc_fx( set32_fx( p_output_fx[n], 0, L_FRAME48k ); - IF( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1411,15 +1415,15 @@ ivas_error ivas_jbm_dec_tc_fx( #ifndef FIX_826_PRECISION_LOST_AND_COMPL IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0], &q_output ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) #endif { return error; } IF( NE_16( q_output, Q11 ) ) { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); + Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 + Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 } } } @@ -1437,7 +1441,7 @@ ivas_error ivas_jbm_dec_tc_fx( } FOR( i = 0; i < 2; i++ ) { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); + Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) } hCPE->hStereoDft->q_dft = add( Q11, s ); @@ -1457,21 +1461,21 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; move16(); } @@ -1483,22 +1487,22 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hSCE != NULL ) { - Scale_sig32( &hSCE->save_hb_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; move16(); - Scale_sig32( &hSCE->save_synth_fx[0], (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; move16(); } FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); // q_dft hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; move16(); } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, 11 ) ); // q_prev_synth_fx #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), hCPE->q_prev_synth_fx - 11 ); #endif @@ -1509,7 +1513,7 @@ ivas_error ivas_jbm_dec_tc_fx( } #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); + Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 #else Scale_sig32( &hCPE->prev_synth_fx[0][0], sizeof( hCPE->prev_synth_fx ) / sizeof( hCPE->prev_synth_fx[0][0] ), 11 - hCPE->q_prev_synth_fx ); #endif // MSAN_FIX @@ -1517,19 +1521,19 @@ ivas_error ivas_jbm_dec_tc_fx( scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); FOR( i = 0; i < CPE_CHANNELS; ++i ) { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 } IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; move16(); } @@ -1537,7 +1541,7 @@ ivas_error ivas_jbm_dec_tc_fx( { FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ ) { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[ii] = Q11; move16(); } @@ -1581,10 +1585,15 @@ ivas_error ivas_jbm_dec_tc_fx( st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; move32(); IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) - st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + { + st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + move32(); + } ELSE + { st_ivas->last_active_ivas_total_brate = ivas_total_brate; - move32(); + move32(); + } } test(); @@ -2282,7 +2291,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - Word32 *data_fx /* i : transport channels */ + Word32 *data_fx /* i : transport channels Q11*/ ) { Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* Word32 buffer for transport channels that will be directly converted with the CLDFB */ @@ -2363,11 +2372,11 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( IF( st_ivas->hSCE[0] ) { Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2413,7 +2422,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2430,7 +2439,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); } ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -2451,7 +2460,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); move16(); } @@ -2500,24 +2509,24 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( move16(); } - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1) st_ivas->hParamMC->proto_matrix_int_e = 1; move16(); ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 ); - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1) Word16 shift; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ), shift ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift) st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift ); move16(); shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov, shift ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift) st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift ); move16(); } @@ -2531,7 +2540,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( { shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); move16(); } @@ -2697,7 +2706,7 @@ ivas_error ivas_jbm_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of samples wanted */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { Word16 n, nchan_out; @@ -2728,7 +2737,7 @@ ivas_error ivas_jbm_dec_render_fx( move16(); output_config = st_ivas->hDecoderConfig->output_config; move32(); - nSamplesAskedLocal = add( (Word16) nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); + nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); move16(); FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) @@ -2878,7 +2887,7 @@ ivas_error ivas_jbm_dec_render_fx( Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); FOR( j = 0; j < sba_num_chans; j++ ) { - scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); + scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11 } @@ -2908,7 +2917,7 @@ ivas_error ivas_jbm_dec_render_fx( /* Binaural rendering */ IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) { return error; } @@ -2929,15 +2938,15 @@ ivas_error ivas_jbm_dec_render_fx( move16(); FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 } - IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } FOR( i = 0; i < nchan_out; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 } } } @@ -2963,7 +2972,7 @@ ivas_error ivas_jbm_dec_render_fx( { Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); } - IF( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) ) { return error; } @@ -2975,7 +2984,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2992,7 +3001,7 @@ ivas_error ivas_jbm_dec_render_fx( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { - IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -3023,7 +3032,7 @@ ivas_error ivas_jbm_dec_render_fx( hSpar->hMdDec->Q_mixer_mat = 30; move16(); - IF( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3054,14 +3063,14 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE IF( 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_BINAURAL_FASTCONV_ROOM ) ) { - IF( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3073,7 +3082,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3085,14 +3094,14 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE { - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ), IVAS_ERR_OK ) ) { return error; } IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - FOR( n = sub( st_ivas->hIntSetup.nchan_out_woLFE, 1 ); n >= 0; n-- ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) { Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); } @@ -3149,10 +3158,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 IF( st_ivas->hDecoderConfig->Opt_tsm ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 } } IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, @@ -3167,7 +3176,7 @@ ivas_error ivas_jbm_dec_render_fx( { FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, -Q2 ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, -Q2 ); // Q(11-2) } } @@ -3175,10 +3184,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 IF( st_ivas->hDecoderConfig->Opt_tsm ) { - scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 } } } @@ -3279,7 +3288,7 @@ ivas_error ivas_jbm_dec_render_fx( { Word16 tmp; tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp) st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); move16(); } @@ -3288,7 +3297,7 @@ ivas_error ivas_jbm_dec_render_fx( { IF( st_ivas->cldfbSynDec[ch] ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); } @@ -3298,14 +3307,14 @@ ivas_error ivas_jbm_dec_render_fx( FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); move16(); IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); move16(); } @@ -3315,7 +3324,7 @@ ivas_error ivas_jbm_dec_render_fx( { IF( st_ivas->cldfbSynDec[ch] ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } @@ -3368,7 +3377,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) { - FOR( n = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); n < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); n++ ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ ) { set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } @@ -3933,7 +3942,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( const MC_MODE mc_mode_old, /* i : old MC mode */ const ISM_MODE ism_mode_old, /* i : old ISM mode */ UWord16 *nSamplesRendered, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0*/ ) { ivas_error error; @@ -3955,7 +3964,11 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( /* get number of possible slots in new granularity */ n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); - n_slots_still_available = n_samples_still_available / tc_granularity_new; + + // n_slots_still_available = n_samples_still_available / tc_granularity_new; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e ); + n_slots_still_available = shr( tmp, sub( 15, tmp_e ) ); *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new ); n_samples_to_render = *nSamplesRendered; move16(); @@ -4024,7 +4037,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( { /*TODO :To be tested : no stream entering---------------------------------------*/ /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); + set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15 ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); @@ -4126,8 +4139,8 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( Word16 last_dirac_md_idx; UWord16 nSamplesAvailableNext; - last_spar_md_idx = st_ivas->hSpar->render_to_md_map[sub( st_ivas->hSpar->slots_rendered, 1 )]; - last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[sub( st_ivas->hSpatParamRendCom->slots_rendered, 1 )]; + last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1]; + last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; move16(); move16(); /* copy from ISM delay buffer to the correct place in tcs */ @@ -4454,13 +4467,13 @@ ivas_error ivas_jbm_dec_set_discard_samples( temp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e ); temp = shr( temp, sub( 15, temp_e ) ); nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e ); - nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); - nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[sub( st_ivas->hTcBuffer->nb_subframes, 1 )] ); + nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); // Q0 + nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); IF( nSlotsInFirstSubframe > 0 ) { st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity ); /* set last subframes number to max to ensure correct continuation */ - st_ivas->hTcBuffer->subframe_nbslots[sub( st_ivas->hTcBuffer->nb_subframes, 1 )] = nMaxSlotsPerSubframe; + st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe; move16(); move16(); } @@ -4530,7 +4543,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator( void ivas_jbm_dec_get_adapted_linear_interpolator_fx( const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ const Word16 interp_length, /* i : length of the interpolator to be created */ - Word16 *interpolator_fx /* o : the interpolator */ + Word16 *interpolator_fx /* o : the interpolator Q15 */ ) { Word16 jbm_segment_len, idx; @@ -4540,7 +4553,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator_fx( jbm_segment_len = shr( default_interp_length, 1 ); dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/ - interpolator_fx[interp_length - 1] = 32767; + interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */ move16(); interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision move16(); @@ -4553,7 +4566,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator_fx( IF( interpolator_fx[idx + 1] > 0 ) { dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e ); - dec_fx = shr( dec_fx, sub( 15, dec_e ) ); + dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0 FOR( ; idx >= 0; idx-- ) { interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx ); @@ -4599,7 +4612,7 @@ void ivas_jbm_dec_get_adapted_subframes( } temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e ); - *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); + *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0 move16(); nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; move16(); @@ -4682,10 +4695,10 @@ void ivas_jbm_dec_get_md_map( Word16 temp; jbm_segment_len = shr( default_len, 1 ); - FOR( ( map_idx = sub( len, 1 ), src_idx = sub( default_len, 1 ) ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) + FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) { temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 src_idx_map = s_max( 0, temp ); map[map_idx] = add( offset, src_idx_map ) % buf_len; move16(); @@ -4701,10 +4714,10 @@ void ivas_jbm_dec_get_md_map( FOR( ; map_idx >= 0; map_idx-- ) { temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 src_idx = s_max( 0, temp ); map[map_idx] = add( offset, src_idx ) % buf_len; - src_idx_fx -= dec_fx; + src_idx_fx = L_sub( src_idx_fx, dec_fx ); } } ELSE @@ -4794,8 +4807,8 @@ void ivas_jbm_dec_get_md_map_even_spacing( Word32 temp; Word16 temp_e; temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e ); - temp = L_shr( temp, sub( 15, temp_e ) ); - decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); + temp = L_shr( temp, sub( 15, temp_e ) ); // Q16 + decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16 decimal_sum_fx = decimal_fx; eps_fx = 65; @@ -5139,13 +5152,14 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( } ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - test(); - test(); + + if ( st_ivas->sba_dirac_stereo_flag ) { num_tc = CPE_CHANNELS; move16(); } + test(); test(); if ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) ) @@ -5207,9 +5221,9 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( test(); test(); test(); - IF( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) + if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) { /* LFE is synthesized in TD with the TCs*/ num_tc = add( num_tc, 1 ); @@ -5237,8 +5251,8 @@ static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of samples to digest */ Word16 *nSamplesResidual, /* o : number of samples that will be left for the next frame */ - Word32 *data, /* i : (interleaved) transport channel samples */ - Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) */ + Word32 *data, /* i : (interleaved) transport channel samples data_q*/ + Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) data_q*/ Word16 data_q ) { Word16 ch; @@ -5276,7 +5290,7 @@ static void ivas_jbm_dec_copy_tc( Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available ); FOR( m = 0; m < nSamplesForRendering; m++ ) { - tc_digest_f[ch][add( n_samples_still_available, m )] = data[add( imult1616( m, st_ivas->hTcBuffer->nchan_transport_jbm ), ch )]; + tc_digest_f[ch][n_samples_still_available + m] = data[( m * st_ivas->hTcBuffer->nchan_transport_jbm ) + ch]; // data_q move32(); } Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual ); @@ -5387,7 +5401,7 @@ Word16 ivas_jbm_dec_get_render_granularity( const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ - const Word32 output_Fs /* i : sampling rate */ + const Word32 output_Fs /* i : sampling rate Q0*/ ) { Word16 render_granularity; @@ -5600,7 +5614,7 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( nsamp_to_allocate = 0; move16(); - tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); + tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0 tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e ); nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0 @@ -5824,7 +5838,7 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( { Word16 nMaxSlotsPerSubframeNew; - nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); + nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // Q0 /* if samples were flushed, take that into account here */ test(); IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 ) @@ -5980,7 +5994,8 @@ static void ivas_jbm_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, - Word32 *output_fx[] ) + Word32 *output_fx[] /*Q11*/ +) { Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e; @@ -5989,9 +6004,9 @@ static void ivas_jbm_dec_tc_buffer_playout_fx( /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); - tmp = shr( tmp, sub( 15, e ) ); + tmp = shr( tmp, sub( 15, e ) ); // Q0 slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp ); - st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); + st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0 *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size ); first_sf = st_ivas->hTcBuffer->subframes_rendered; last_sf = first_sf; @@ -6096,11 +6111,11 @@ void ivas_jbm_dec_td_renderers_adapt_subframes( /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */ tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); + nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // Q0 /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */ tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - nSlotsAvailable = shr( tmp, sub( 15, exp ) ); + nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // Q0 st_ivas->hTcBuffer->num_slots = nSlotsAvailable; move16(); diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 7dd2e334c..9765facd6 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -47,22 +47,24 @@ static Word32 ivas_bitstream_read_int32_fx( Decoder_State *st0, - const Word16 bits ) + const Word16 bits /*Q0*/ +) { Word32 val; /* MSB */ - val = L_shl( get_next_indice_fx( st0, sub( bits, 16 ) ), 16 ); + val = L_shl( get_next_indice_fx( st0, sub( bits, 16 ) ), 16 ); /*Q0*/ /* + LSB */ - val = L_add( val, get_next_indice_fx( st0, 16 ) ); + val = L_add( val, get_next_indice_fx( st0, 16 ) ); /*Q0*/ return val; } static void pca_dec_reset_dquat_fx( - Word16 *ql_fx, - Word16 *qr_fx ) + Word16 *ql_fx, /*Q15*/ + Word16 *qr_fx /*Q15*/ +) { set16_fx( ql_fx, 0, IVAS_PCA_INTERP ); ql_fx[0] = MAX_16; @@ -79,9 +81,9 @@ static void pca_dec_reset_mem_eigvec_fx( { Word16 i; - FOR( i = 0; i < shr( IVAS_PCA_LEN_INTERP_EIG_DEC, 4 ); i++ ) + FOR( i = 0; i < ( IVAS_PCA_LEN_INTERP_EIG_DEC >> 4 ); i++ ) { - eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[i_mult( 16, i )], FOA_CHANNELS, MAX_16 ); + eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[( 16 * i )], FOA_CHANNELS, MAX_16 ); } return; @@ -89,11 +91,12 @@ static void pca_dec_reset_mem_eigvec_fx( static void pca_inv_transform_sub_fx( - Word16 *eigVec, - Word32 *transformed_data[], /* i : input/transformed audio channels */ - const Word16 start, - const Word16 len, - const Word16 n_channels ) + Word16 *eigVec, /*Q15*/ + Word32 *transformed_data[], /* i : input/transformed audio channels Q11*/ + const Word16 start, /*Q0*/ + const Word16 len, /*Q0*/ + const Word16 n_channels /*Q0*/ +) { Word16 i, j, k; Word32 temp, temp2; @@ -103,7 +106,7 @@ static void pca_inv_transform_sub_fx( { FOR( k = 0; k < n_channels; k++ ) { - buffer_data[k] = transformed_data[k][add( j, start )]; + buffer_data[k] = transformed_data[k][( j + start )]; /*Q11*/ move32(); } @@ -113,10 +116,10 @@ static void pca_inv_transform_sub_fx( move32(); FOR( i = 0; i < n_channels; i++ ) { - temp2 = Mpy_32_16_1( buffer_data[i], eigVec[add( k * IVAS_PCA_INTERP, i )] ); + temp2 = Mpy_32_16_1( buffer_data[i], eigVec[( k * IVAS_PCA_INTERP + i )] ); /*Q11*/ temp = L_add( temp, temp2 ); } - transformed_data[k][add( j, start )] = temp; + transformed_data[k][( j + start )] = temp; /*Q11*/ move32(); } } @@ -127,11 +130,12 @@ static void pca_inv_transform_sub_fx( static void pca_dec_inv_transform_fx( PCA_DEC_STATE *hPCA, - Word16 *ql_fx, - Word16 *qr_fx, - const Word16 n_samples, - const Word16 n_channels, - Word32 *decoded_data[] ) + Word16 *ql_fx, /*Q15*/ + Word16 *qr_fx, /*Q15*/ + const Word16 n_samples, /*Q0*/ + const Word16 n_channels, /*Q0*/ + Word32 *decoded_data[] /*Q11*/ +) { Word16 j; Word16 slot_len; @@ -141,12 +145,12 @@ static void pca_dec_inv_transform_fx( pca_interp_preproc_fx( hPCA->prev_ql_fx, hPCA->prev_qr_fx, ql_fx, qr_fx, IVAS_PCA_N_SLOTS, ql_interp_fx, qr_interp_fx ); - slot_len = idiv1616( n_samples, IVAS_PCA_N_SLOTS ); + slot_len = idiv1616( n_samples, IVAS_PCA_N_SLOTS ); /*Q0*/ FOR( j = 0; j < IVAS_PCA_N_SLOTS; j++ ) { /* convert from double quaternion to 4D matrix */ - dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[add( 16 * j, IVAS_PCA_DELAY_CMP * 16 )] ); + dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[( 16 * j + IVAS_PCA_DELAY_CMP * 16 )] ); pca_inv_transform_sub_fx( &hPCA->mem_eigVec_interp_fx[16 * j], decoded_data, slot_len * j, slot_len, n_channels ); } @@ -156,12 +160,13 @@ static void pca_dec_inv_transform_fx( static void pca_dec_update_dquat_fx( PCA_DEC_STATE *hPCA, - const Word16 *ql_fx, - const Word16 *qr_fx ) + const Word16 *ql_fx, /*Q15*/ + const Word16 *qr_fx /*Q15*/ +) { /* update state for next frame */ - Copy( qr_fx, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); - Copy( ql_fx, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); + Copy( qr_fx, hPCA->prev_qr_fx, IVAS_PCA_INTERP ); /*Q15*/ + Copy( ql_fx, hPCA->prev_ql_fx, IVAS_PCA_INTERP ); /*Q15*/ return; } @@ -197,16 +202,16 @@ void ivas_pca_read_bits_fx( PCA_DEC_STATE *hPCA ) { /*first bit in the PCA payload (first bit after 3 header bits) signals bypass/active*/ - hPCA->pca_bypass = get_next_indice_fx( st0, 1 ); + hPCA->pca_bypass = get_next_indice_fx( st0, 1 ); /*Q0*/ move16(); IF( EQ_16( hPCA->pca_bypass, PCA_MODE_INACTIVE ) ) { return; } - hPCA->index[0] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS - 1 ); + hPCA->index[0] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS - 1 ); /*Q0*/ move32(); - hPCA->index[1] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS ); + hPCA->index[1] = ivas_bitstream_read_int32_fx( st0, IVAS_PCA_QBITS ); /*Q0*/ move32(); return; @@ -220,18 +225,18 @@ void ivas_pca_read_bits_fx( void ivas_pca_dec_fx( PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ - const Word16 output_frame, /* i : output frame length */ - const Word16 n_channels, /* i : number of channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ - const Word16 bfi, /* i : bad frame indicator */ - Word32 *pcm_out_fx[] /* o : output audio channels */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 n_channels, /* i : number of channels Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word16 bfi, /* i : bad frame indicator Q0*/ + Word32 *pcm_out_fx[] /* o : output audio channels Q11*/ ) { - Word16 ql_fx[IVAS_PCA_INTERP], qr_fx[IVAS_PCA_INTERP]; + Word16 ql_fx[IVAS_PCA_INTERP], qr_fx[IVAS_PCA_INTERP]; /*Q15*/ Word16 pca_bypass; // todo : check if mem_eigVec_interp_fx values are being updated / add loop to update - Copy( &hPCA->mem_eigVec_interp_fx[IVAS_PCA_N_SLOTS * 16], hPCA->mem_eigVec_interp_fx, IVAS_PCA_DELAY_CMP * 16 ); + Copy( &hPCA->mem_eigVec_interp_fx[IVAS_PCA_N_SLOTS * 16], hPCA->mem_eigVec_interp_fx, IVAS_PCA_DELAY_CMP * 16 ); /*Q15*/ /* @@@TODO: check how ivas_total_brate is set if bfi == 1 */ // ToDo: and what happens in DTX where "ivas_total_brate" can be close to zero? @@ -255,12 +260,12 @@ void ivas_pca_dec_fx( } pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); /*Q0*/ move16(); if ( GT_16( hPCA->prev_pca_bypass, 2 ) ) { - hPCA->prev_pca_bypass = 2; + hPCA->prev_pca_bypass = 2; /*Q0*/ move16(); } @@ -270,12 +275,12 @@ void ivas_pca_dec_fx( IF( bfi == 0 ) { /* set PCA by-pass mode indicator */ - pca_bypass = hPCA->pca_bypass; + pca_bypass = hPCA->pca_bypass; /*Q0*/ move16(); } ELSE { - pca_bypass = hPCA->prev_pca_bypass; + pca_bypass = hPCA->prev_pca_bypass; /*Q0*/ move16(); } @@ -295,9 +300,9 @@ void ivas_pca_dec_fx( pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); - hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); + hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); /*Q0*/ move16(); - hPCA->prev_pca_bypass = s_min( hPCA->prev_pca_bypass, 2 ); + hPCA->prev_pca_bypass = s_min( hPCA->prev_pca_bypass, 2 ); /*Q0*/ move16(); return; // exit happens here } @@ -311,8 +316,8 @@ void ivas_pca_dec_fx( { /* freeze */ // todo : check if update of prev_ql_fx is required - Copy( hPCA->prev_ql_fx, ql_fx, IVAS_PCA_INTERP ); - Copy( hPCA->prev_qr_fx, qr_fx, IVAS_PCA_INTERP ); + Copy( hPCA->prev_ql_fx, ql_fx, IVAS_PCA_INTERP ); /*Q15*/ + Copy( hPCA->prev_qr_fx, qr_fx, IVAS_PCA_INTERP ); /*Q15*/ } pca_dec_inv_transform_fx( hPCA, ql_fx, qr_fx, output_frame, n_channels, pcm_out_fx ); diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index 912c94193..b98b5a6b9 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -153,11 +153,11 @@ void ivas_post_proc( void ivas_post_proc_fx( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 synth[], /* i/o: output synthesis signal */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 n, /* i : channel number Q0*/ + Word32 synth[], /* i/o: output synthesis signal Q11*/ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal output_q*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ Word16 output_q ) { Word16 k; @@ -198,7 +198,7 @@ void ivas_post_proc_fx( ELSE { /* set delay */ - delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); /*Q0*/ move16(); test(); @@ -207,13 +207,13 @@ void ivas_post_proc_fx( test(); IF( EQ_16( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ), 0 ) && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { - Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); + Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } ELSE IF( sba_dirac_stereo_flag && EQ_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { - Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); + Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); - Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); + Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32, output_q ); @@ -224,7 +224,7 @@ void ivas_post_proc_fx( { Word16 pit_res_max_past_tmp; - pit_res_max_past_tmp = sts[0]->pit_res_max_past; + pit_res_max_past_tmp = sts[0]->pit_res_max_past; /*Q0*/ move16(); FOR( k = 0; k < hCPE->nchan_out; k++ ) { @@ -236,16 +236,16 @@ void ivas_post_proc_fx( { hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec; /* copy LTP side-info of downmix channel also to right channel struct */ - hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; + hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; /*Q0*/ move16(); - hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; + hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; /*Q15*/ move16(); - hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; + hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; /*Q0*/ move16(); - hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; + hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; /*Q0*/ move16(); /* revert update of pit_res_max_past to have correct value also in right channel */ - sts[0]->pit_res_max_past = pit_res_max_past_tmp; + sts[0]->pit_res_max_past = pit_res_max_past_tmp; /*Q0*/ move16(); } @@ -277,13 +277,13 @@ void ivas_post_proc_fx( #ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_core_switching_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 output_frame, /* i : output frame length */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo */ - const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo */ + Word32 output_fx[], /* i/o: synthesis @internal Fs q*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs q*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis q*/ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_DFT*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB FOR DFT Stereo Q0*/ + const Word16 sba_dirac_stereo_dtx_flag, /* i : DTX indicator FOR SBA DirAC stereo Q0*/ Word16 *q, Word16 *q_DFT ) { @@ -301,31 +301,31 @@ void stereo_dft_dec_core_switching_fx( Word32 synth_tmp_fx[L_FRAME48k]; - st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ - output_Fs = st->output_Fs; + st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ + output_Fs = st->output_Fs; /*Q0*/ move32(); - L_frameTCX = st->hTcxDec->L_frameTCX; + L_frameTCX = st->hTcxDec->L_frameTCX; /*Q0*/ move16(); /*TBE*/ - delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); + delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ move16(); - delay_dft_dec = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); + delay_dft_dec = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/ move16(); - delay_dft_dec_lb = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); + delay_dft_dec_lb = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/ move16(); /* TCX/ACELP/HQ-CORE->TCX */ - tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ + tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ /*Q0*/ move16(); - delay_comp = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ + delay_comp = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ /*Q0*/ move16(); calc_inv = W_shl( 1, 31 ); // Memory Tables ////////////////////////////////////////////////////////////////////////////// - Word32 mem_len_inv_tbl[] = { 85899345, 42949672, 28633115, 21474836, 17179869, 14316557 }; - Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; + Word32 mem_len_inv_tbl[] = { 85899345, 42949672, 28633115, 21474836, 17179869, 14316557 }; /*Q31*/ + Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; /*Q31*/ /////////////////////////////////////////////////////////////////////////////////////////////// test(); @@ -338,7 +338,7 @@ void stereo_dft_dec_core_switching_fx( test(); test(); - if ( ( st->prev_bfi != 0 ) && EQ_16( ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) ) + IF( ( st->prev_bfi != 0 ) && EQ_16( ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) ) { /* last_core needed FOR correctly decoding ACELP->TCX/HQ switching frames in ivas_core_dec(). In the following steps the decoder needs to consider IF the core was changed due to a lost frame to apply the correct transition */ @@ -369,7 +369,7 @@ void stereo_dft_dec_core_switching_fx( IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( sba_dirac_stereo_dtx_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { /* In case of a TCX to ACELP switch next frame */ - Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/ /* BPF */ test(); @@ -377,7 +377,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 && NE_16( st->core, HQ_CORE ) ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0, q, q_DFT ); } @@ -395,25 +395,25 @@ void stereo_dft_dec_core_switching_fx( test(); IF( LE_32( st->last_core_brate, SID_2k40 ) && LE_16( st->element_mode, IVAS_SCE ) ) { - Word16 mem_len = NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + Word16 mem_len = NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/ move16(); - Word32 mem_len_inv = mem_len_inv_tbl[idiv1616( mem_len, 25 )]; + Word32 mem_len_inv = mem_len_inv_tbl[( mem_len / 25 )]; move32(); Word16 qmem_len = norm_l( mem_len ); Word32 mem_len_fx = L_shl( mem_len, qmem_len ); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/ move32(); - hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/ move32(); } /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = - L_add( hCPE->input_mem_fx[0][NS2SA_FX2( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = + L_add( hCPE->input_mem_fx[0][NS2SA_FX2( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); /*Q11*/ move32(); } } @@ -422,21 +422,21 @@ void stereo_dft_dec_core_switching_fx( /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = hb_synth_fx[i]; + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = hb_synth_fx[i]; /*Q11*/ move32(); } } /* cross-fading between (delayed) TBE and FB-TCX over 2.3125ms */ - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ Word16 qtmps = norm_l( tmps ); Word32 tmps_fx = L_shl( tmps, qtmps ); Word32 tmps_inv = (Word32) ( calc_inv / tmps ); FOR( i = 0; i < tmps; i++ ) { - synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[add( i, delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); + synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[( i + delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); /*q + qtmps - 31*/ move32(); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); /*q*/ move32(); } @@ -447,25 +447,25 @@ void stereo_dft_dec_core_switching_fx( { IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) { - Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); + Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); /*q*/ } /* fading-out LB-TCX/ACELP */ Word16 qdelay_comp = norm_l( delay_comp ); - Word32 delay_comp_inv = delay_comp_inv_tbl[idiv1616( delay_comp, 7 )]; + Word32 delay_comp_inv = delay_comp_inv_tbl[( delay_comp / 7 )]; /*Q31*/ move32(); Word32 delay_comp_fx = L_shl( delay_comp, qdelay_comp ); FOR( i = 0; i < delay_comp; i++ ) { - output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); + output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); /*q + qdelay_comp - 31*/ move32(); - output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); + output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); /*q*/ move32(); } /* In case of TCX frames, output LB TCX is zeroed out until the end but in case of an TCX->ACELP switch, this memory is needed, hence it is backed up */ /* Unlike the case when DFT32MS is disabled, there is only 1 DFT analysis window, hence in the TCX frame we don't want to do a DFT analysis FOR LB TCX but in a potential ACELP frame, we want the memories of the LB TCX FOR the last OLA samples so that HB analysis can be skipped */ - Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/ /*zero the rest FOR avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/ IF( GT_32( st->last_core_brate, SID_2k40 ) ) @@ -510,16 +510,16 @@ void stereo_dft_dec_core_switching_fx( IF( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { Word16 nZeros; - nZeros = (Word16) ( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); + nZeros = (Word16) ( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); - delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ move16(); - Copy32( &st->hHQ_core->oldOut_fx[sub( nZeros, add( delay_comp, NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( &st->hHQ_core->oldOut_fx[( nZeros - ( delay_comp + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/ + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ Word16 mem_len; - mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/ move16(); Word16 qmem_len = norm_l( mem_len ); @@ -528,9 +528,9 @@ void stereo_dft_dec_core_switching_fx( move32(); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/ move32(); - hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/ move32(); } set32_fx( output_fx, 0, st->L_frame ); @@ -541,7 +541,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } @@ -559,11 +559,11 @@ void stereo_dft_dec_core_switching_fx( Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb ); FOR( i = 0; i < delay_dft_dec_lb; i++ ) { - hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = - Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], L_shl( i, qdelay_dft_dec_lb ) ); + hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] = + Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], L_shl( i, qdelay_dft_dec_lb ) ); /*Q11 + qdelay_dft_dec_lb -31*/ move32(); - hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = - L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); + hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] = + L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); /*Q11*/ move32(); } stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT ); @@ -572,13 +572,13 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } /* Fading-in TD-BWE, Fading-out FB-TCX*/ - Copy32( synth_fx, synth_tmp_fx, output_frame ); + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { Word16 qdelay_dft_dec = norm_l( delay_dft_dec ); @@ -586,20 +586,20 @@ void stereo_dft_dec_core_switching_fx( Word32 delay_dft_dec_fx = L_shl( delay_dft_dec, qdelay_dft_dec ); FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */ { - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_add( - Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_shl( i, qdelay_dft_dec ) ), - Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_add( + Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_shl( i, qdelay_dft_dec ) ), + Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); /*Q11 + qdelay_dft_dec - 31*/ move32(); - hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_shl( - Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], delay_dft_dec_inv ), - sub( Q31, qdelay_dft_dec ) ); + hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_shl( + Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], delay_dft_dec_inv ), + sub( Q31, qdelay_dft_dec ) ); /*Q11*/ move32(); } FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade out. ICBWE fade in performed in time domain here */ { - synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); + synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); /*q + qdelay_dft_dec - 31*/ move32(); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); /*q*/ move32(); } @@ -649,7 +649,7 @@ void stereo_dft_dec_core_switching_fx( IF( st->p_bpf_noise_buf_32 ) { #ifdef MSAN_FIX - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/ #endif stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT ); } @@ -680,14 +680,14 @@ void stereo_dft_dec_core_switching_fx( { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8; move16(); - ap_fade_len_inv = 67108864; + ap_fade_len_inv = 67108864; /*1/32 in Q31*/ move32(); } ELSE { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k; move16(); - ap_fade_len_inv = 53687091; + ap_fade_len_inv = 53687091; /*1/40 in Q31*/ move32(); } @@ -701,10 +701,10 @@ void stereo_dft_dec_core_switching_fx( test(); IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) { - Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); + Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); /*Q0*/ Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; - Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); + Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; move16(); @@ -715,45 +715,45 @@ void stereo_dft_dec_core_switching_fx( test(); IF( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) && !st->tcxonly ) { - Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); + Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); /*q*/ } ELSE { - Copy32( output_fx, pAp_input_fx, st->L_frame ); + Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/ } IF( EQ_16( st->last_core, ACELP_CORE ) && EQ_16( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */ { - Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); + Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); /*q*/ FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), - Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } } ELSE { - Copy32( output_fx, pAp_input_fx, st->L_frame ); - IF( NE_16( st->last_core, ACELP_CORE ) ) /* TCX/HQ-Core -> ACELP */ + Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/ + IF( NE_16( st->last_core, ACELP_CORE ) ) /* TCX/HQ-Core -> ACELP */ { Word16 shift = sub( hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0] ); FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), - Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } } - predelay = NS2SA_FX2( st->sr_core, DELAY_BWE_TOTAL_NS ); + predelay = NS2SA_FX2( st->sr_core, DELAY_BWE_TOTAL_NS ); /*Q0*/ move16(); /* apply predelay to have same overall filter delay FOR all cases */ @@ -771,9 +771,9 @@ void stereo_dft_dec_core_switching_fx( { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } } @@ -785,9 +785,9 @@ void stereo_dft_dec_core_switching_fx( { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); /*q + qap_fade_len - 31*/ move32(); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/ move32(); } hCPE->hStereoDft->ap_wasTransient = 0; @@ -818,7 +818,7 @@ void stereo_dft_dec_core_switching_fx( test(); IF( !use_cldfb_for_dft || ( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && EQ_16( st->cng_type, LP_CNG ) && EQ_16( st->extl, SWB_CNG ) && EQ_16( hCPE->nchan_out, 1 ) ) ) { - v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ + v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ /*q*/ } } diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 993f01c52..3f50f3816 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -103,14 +103,14 @@ float deindex_elevation( #ifdef IVAS_FLOAT_FIXED Word32 deindex_elevation_fx( - UWord16 *id_th, /* i : input index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ + UWord16 *id_th, /* i : input index Q0*/ + const Word16 no_bits, /* i : number of bits for the spherical grid Q0*/ const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { Word32 theta_hat_fx; Word16 q_id_th = sub( norm_l( *id_th ), 1 ); - Word32 id_th_fx = L_shl( *id_th, q_id_th ); + Word32 id_th_fx = L_shl( *id_th, q_id_th ); /*q_id_th*/ IF( EQ_32( *id_th, MASA_NO_INDEX ) ) { @@ -121,7 +121,7 @@ Word32 deindex_elevation_fx( { IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); + theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ); /*Q22*/ IF( GT_32( theta_hat_fx, L_shl( 90, Q22 ) ) ) { theta_hat_fx = 90 * ONE_IN_Q22; @@ -133,10 +133,10 @@ Word32 deindex_elevation_fx( IF( L_and( *id_th, 1 ) == 0 ) { /* theta is negative */ - *id_th = (UWord16) L_shr( *id_th, 1 ); + *id_th = (UWord16) L_shr( *id_th, 1 ); /* *id_th / 2 */ /*Q0*/ move16(); - id_th_fx = L_shr( id_th_fx, 1 ); - theta_hat_fx = L_negate( L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ) ); + id_th_fx = L_shr( id_th_fx, 1 ); /*q_id_th*/ + theta_hat_fx = L_negate( L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ) ); /*Q22*/ IF( LT_32( theta_hat_fx, -90 * ONE_IN_Q22 ) ) { theta_hat_fx = -90 * ONE_IN_Q22; @@ -145,10 +145,10 @@ Word32 deindex_elevation_fx( } ELSE { - *id_th = (UWord16) L_shr( L_add( *id_th, 1 ), 1 ); + *id_th = (UWord16) L_shr( L_add( *id_th, 1 ), 1 ); /* ( *id_th + 1 ) / 2 */ /*Q0*/ move16(); - id_th_fx = L_shr( L_add( id_th_fx, L_shl( 1, q_id_th ) ), 1 ); - theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); + id_th_fx = L_shr( L_add( id_th_fx, L_shl( 1, q_id_th ) ), 1 ); /*q_id_th*/ + theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[( no_bits - 3 )] ), sub( 31, q_id_th ) ); /*Q22*/ IF( GT_32( theta_hat_fx, 90 * ONE_IN_Q22 ) ) { theta_hat_fx = 90 * ONE_IN_Q22; @@ -158,6 +158,6 @@ Word32 deindex_elevation_fx( } } - return theta_hat_fx; + return theta_hat_fx; /*Q22*/ } #endif diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 380e4da21..8a82dabd2 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -102,8 +102,8 @@ void rc_uni_dec_init( #endif void rc_uni_dec_init_fx( RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ - UWord16 *bit_buffer, /* i : Bit buffer */ - const Word16 max_available_bits /* i : Total maximum bits available */ + UWord16 *bit_buffer, /* i : Bit buffer Q0*/ + const Word16 max_available_bits /* i : Total maximum bits available Q0*/ ) { Word16 i; @@ -111,17 +111,17 @@ void rc_uni_dec_init_fx( rc_st_dec->rc_low = 0; rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->bit_buffer = bit_buffer; + rc_st_dec->bit_buffer = bit_buffer; /*Q0*/ rc_st_dec->bit_count = 0; /* the renormalization procedure reads at most 32 - 2 extra bits than available */ - rc_st_dec->max_allowable_bit_count = add( max_available_bits, 30 ); + rc_st_dec->max_allowable_bit_count = add( max_available_bits, 30 ); /*Q0*/ rc_st_dec->bit_error_detected = 0; FOR( i = 0; i < 4; i++ ) { // Not adding basops becuase the resultant value greater than Word32 - rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); + rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec ); /*Q0*/ } return; @@ -211,10 +211,10 @@ uint16_t rc_uni_dec_read_symbol_fastS( #endif UWord16 rc_uni_dec_read_symbol_fastS_fx( RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ - const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ - const UWord16 sym_freq_table[], /* i : Symbol frequency */ - const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ + const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol Q0*/ + const UWord16 sym_freq_table[], /* i : Symbol frequency Q0*/ + const UWord16 alphabet_size, /* i : Number of symbols in the alphabet Q0*/ + const UWord16 tot_shift /* i : Total frequency as a power of 2 Q0*/ ) { UWord16 sym_begin; @@ -226,11 +226,11 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( UWord16 step; UWord32 reversed_low; - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, tot_shift ); + range = UL_lshr( range, tot_shift ); /*range >>= tot_shift*/ /* the cumulative value is val = low / range */ /* the condition val >= level is equivalent with low >= range * level */ @@ -246,7 +246,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -256,28 +256,28 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* do a binary search to find the symbol read */ sym_begin = 0; move16(); - sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} */ + sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} Q0*/ move16(); /* ceil(log2(x)) = 1 + floor(log2(x - 1)), for any x >= 2 */ /* floor(log2(y)) = 31 - norm_ul_float(y) = 30 - norm_l(y), for any 1 <= y <= 2 ^ 31 - 1 */ ceil_log2_alphabet_size = sub( 31, norm_l( UL_subNsD( alphabet_size, 1 ) ) ); /* completely equivalent with 32 - norm_ul_float(alphabet_size - 1), but norm_l is faster */ - reversed_low = UL_subNsD( UL_lshl( range, tot_shift ), low ); + reversed_low = UL_subNsD( UL_lshl( range, tot_shift ), low ); /*( range << tot_shift ) - low*/ /* at most ceil_log2_alphabet_size steps are needed so that sym_end - sym_begin == 1 */ FOR( step = 0; step < ceil_log2_alphabet_size; step++ ) { - sym_middle = shr( add( sym_begin, sym_end ), 1 ); + sym_middle = shr( add( sym_begin, sym_end ), 1 ); /*( sym_begin + sym_end ) >> 1 Q0*/ /* completely equvalent with low >= range * ((1 << tot_shift) - table[sym_middle]) */ IF( range * L_sub( L_shl( 1, tot_shift ), cum_freq_table[sym_middle] ) >= reversed_low ) { - sym_begin = sym_middle; + sym_begin = sym_middle; /*Q0*/ move16(); } ELSE { - sym_end = sym_middle; + sym_end = sym_middle; /*Q0*/ move16(); } } @@ -285,7 +285,7 @@ UWord16 rc_uni_dec_read_symbol_fastS_fx( /* sym_begin contains the symbol read */ /* low was not modified */ - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); rc_uni_dec_update_fx( rc_st_dec, cum_freq_table[sym_begin], sym_freq_table[sym_begin] ); @@ -327,26 +327,26 @@ static void rc_uni_dec_update( static void rc_uni_dec_update_fx( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const UWord16 cum_freq, /* i : Cumulative frequency */ - const UWord16 sym_freq /* i : Symbol frequency */ + const UWord16 cum_freq, /* i : Cumulative frequency Q0*/ + const UWord16 sym_freq /* i : Symbol frequency Q0*/ ) { - rc_st_dec->rc_low = UL_subNsD( rc_st_dec->rc_low, UL_Mpy_32_32( cum_freq, rc_st_dec->rc_range ) ); - rc_st_dec->rc_range = UL_Mpy_32_32( rc_st_dec->rc_range, sym_freq ); + rc_st_dec->rc_low = UL_subNsD( rc_st_dec->rc_low, UL_Mpy_32_32( cum_freq, rc_st_dec->rc_range ) ); /*Q0*/ + rc_st_dec->rc_range = UL_Mpy_32_32( rc_st_dec->rc_range, sym_freq ); /*Q0*/ move32(); move32(); /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ IF( LT_64( rc_st_dec->rc_range, 0x01000000 ) ) { - rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); /*Q0*/ move32(); move32(); IF( LT_64( rc_st_dec->rc_range, 0x01000000 ) ) { - rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); + rc_st_dec->rc_low = UL_addNsD( UL_lshl( rc_st_dec->rc_low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + rc_st_dec->rc_range = UL_lshl( rc_st_dec->rc_range, 8 ); /*Q0*/ move32(); move32(); } @@ -370,12 +370,12 @@ UWord16 rc_uni_dec_read_bit( UWord32 low; /* local copy (1 to 5 uses) */ UWord32 range; /* local copy (3 to 6 uses) */ - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, 1 ); + range = UL_lshr( range, 1 ); /*range >>= 1*/ /* in case of bitstream errors it is possible that rc_low >= (rc_range << 1) */ val = 0; @@ -383,8 +383,8 @@ UWord16 rc_uni_dec_read_bit( /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( GE_64( low, range ) ) { - val = UL_addNsD( val, 1 ); - low = UL_subNsD( low, range ); + val = UL_addNsD( val, 1 ); /*Q0*/ + low = UL_subNsD( low, range ); /*Q0*/ /* rc_range was already subtracted once from rc_low */ IF( GE_64( low, range ) ) @@ -396,7 +396,7 @@ UWord16 rc_uni_dec_read_bit( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -408,13 +408,13 @@ UWord16 rc_uni_dec_read_bit( /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ range = UL_lshl( range, 8 ); } - rc_st_dec->rc_low = low; + rc_st_dec->rc_low = low; /*Q0*/ move32(); - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); return (UWord16) val; @@ -480,20 +480,20 @@ uint16_t rc_uni_dec_read_bit( #ifdef IVAS_FLOAT_FIXED UWord16 rc_uni_dec_read_bit_prob_fast( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const Word16 freq0, /* i : Frequency for symbol 0 */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ + const Word16 freq0, /* i : Frequency for symbol 0 Q0*/ + const UWord16 tot_shift /* i : Total frequency as a power of 2 Q0*/ ) { UWord32 val; UWord32 low; /* local copy (2 to 7 uses) */ UWord32 range; /* local copy (5 to 9 uses) */ - low = rc_st_dec->rc_low; + low = rc_st_dec->rc_low; /*Q0*/ move32(); - range = rc_st_dec->rc_range; + range = rc_st_dec->rc_range; /*Q0*/ move32(); - range = UL_lshr( range, tot_shift ); + range = UL_lshr( range, tot_shift ); /*range >>= tot_shift*/ /* in case of bitstream errors it is possible that low >= (1 << tot_shift) * range */ /*basop comment : unsigned integers are getting compared hence basops are not used*/ @@ -506,7 +506,7 @@ UWord16 rc_uni_dec_read_bit_prob_fast( /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; move32(); - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); /* the current value and all the following values are very likely incorrect */ @@ -518,34 +518,34 @@ UWord16 rc_uni_dec_read_bit_prob_fast( /*basop comment : unsigned comparision and multiplication of unsigned and signed hence basops are not used*/ IF( low >= range * freq0 ) { - val = UL_addNsD( val, 1 ); + val = UL_addNsD( val, 1 ); /*Q0*/ - low = UL_subNsD( low, UL_Mpy_32_32( range, freq0 ) ); + low = UL_subNsD( low, UL_Mpy_32_32( range, freq0 ) ); /*Q0*/ /*basop comment : multiplication of two unsigned integers and result is stored in unsigned hence basops are not used*/ - range = UL_Mpy_32_32( range, UL_subNsD( UL_lshl( 1, tot_shift ), freq0 ) ); /* freq1 = (1 << tot_shift) - freq0 */ + range = UL_Mpy_32_32( range, UL_subNsD( UL_lshl( 1, tot_shift ), freq0 ) ); /* freq1 = (1 << tot_shift) - freq0 Q0*/ } ELSE { /* basop comment : multiplication of two unsigned integers and result is stored in unsigned integer hence basops are not used*/ - range = UL_Mpy_32_32( range, freq0 ); + range = UL_Mpy_32_32( range, freq0 ); /*Q0*/ } /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ /*basop comment : comparision of unsigned integers hence basops are not used*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - range = UL_lshl( range, 8 ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = UL_lshl( range, 8 ); /*range <<= 8*/ IF( LT_64( range, 0x01000000 ) ) { - low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); - range = UL_lshl( range, 8 ); + low = UL_addNsD( UL_lshl( low, 8 ), (UWord32) rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = UL_lshl( range, 8 ); /*range <<= 8*/ } } - rc_st_dec->rc_low = low; + rc_st_dec->rc_low = low; /*Q0*/ move32(); - rc_st_dec->rc_range = range; + rc_st_dec->rc_range = range; /*Q0*/ move32(); return (UWord16) val; @@ -623,7 +623,7 @@ uint16_t rc_uni_dec_read_bit_prob_fast( #ifdef IVAS_FLOAT_FIXED UWord16 rc_uni_dec_read_bits( RangeUniDecState *rc_st_dec, /* i/o: RC State handle */ - const Word16 bits /* i : Number of bits */ + const Word16 bits /* i : Number of bits Q0*/ ) { UWord32 val; @@ -634,18 +634,18 @@ UWord16 rc_uni_dec_read_bits( #ifdef FIX851_RANGE_DEC_PRECISION Word16 exp_temp1; #endif - low = rc_st_dec->rc_low; - range = rc_st_dec->rc_range; + low = rc_st_dec->rc_low; /*Q0*/ + range = rc_st_dec->rc_range; /*Q0*/ move32(); move32(); - range = (UWord32) W_shr( range, bits ); + range = (UWord32) W_shr( range, bits ); /*range >>= bits*/ #ifdef FIX851_RANGE_DEC_PRECISION exp_temp1 = sub( W_norm( low ), 31 + 1 ); - temp1 = (UWord32) W_shl( low, exp_temp1 ); + temp1 = (UWord32) W_shl( low, exp_temp1 ); /*Q : W_norm( low ) - 32*/ norm_range = sub( W_norm( range ), 31 ); - temp2 = (UWord32) W_shl( range, norm_range ); - val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); + temp2 = (UWord32) W_shl( range, norm_range ); /*Q : W_norm( range ) - 31*/ + val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); /*Q0*/ #else temp1 = (UWord32) W_shr( low, 1 ); norm_range = sub( W_norm( range ), 31 ); @@ -662,7 +662,7 @@ UWord16 rc_uni_dec_read_bits( /* for valid bitstreams, always low < range, therefore setting low = range */ /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ move32(); move32(); @@ -670,26 +670,26 @@ UWord16 rc_uni_dec_read_bits( return 0; /* return the minimum valid value for the output */ } - low = (UWord32) W_sub( low, W_mult0_32_32( val, range ) ); + low = (UWord32) W_sub( low, W_mult0_32_32( val, range ) ); /*Q0*/ /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */ IF( LT_64( range, 0x01000000 ) ) { - low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); - range = (UWord32) W_shl( range, 8 ); + low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = (UWord32) W_shl( range, 8 ); /*range <<= 8*/ if ( LT_64( range, 0x01000000 ) ) { - low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); - range = (UWord32) W_shl( range, 8 ); + low = (UWord32) W_add( W_shl( low, 8 ), rc_uni_dec_read_fx( rc_st_dec ) ); /*Q0*/ + range = (UWord32) W_shl( range, 8 ); /*range <<= 8*/ } } - rc_st_dec->rc_low = low; - rc_st_dec->rc_range = range; + rc_st_dec->rc_low = low; /*Q0*/ + rc_st_dec->rc_range = range; /*Q0*/ move32(); move32(); - return (UWord16) val; + return (UWord16) val; /*Q0*/ } #else uint16_t rc_uni_dec_read_bits( @@ -793,7 +793,7 @@ Word16 rc_uni_dec_virtual_finish_fx( { /* the function is completely equivalent with rc_uni_dec_finish */ // Not adding basop because value of rc_st_dec->rc_range exceeds Word32 - return add( rc_st_dec->bit_count, sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); + return add( rc_st_dec->bit_count, sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) ); /*Q0*/ } #else @@ -850,8 +850,8 @@ static Word16 rc_uni_dec_read_fx( Word16 byte_read; UWord16 *shifted_bit_buffer; - shifted_bit_buffer = rc_st_dec->bit_buffer + rc_st_dec->bit_count; - rc_st_dec->bit_count = add( rc_st_dec->bit_count, 8 ); + shifted_bit_buffer = rc_st_dec->bit_buffer + rc_st_dec->bit_count; /*Q0*/ + rc_st_dec->bit_count = add( rc_st_dec->bit_count, 8 ); /*Q0*/ /* * In case of bitstream errors the number the bits read may be larger than the total @@ -865,7 +865,7 @@ static Word16 rc_uni_dec_read_fx( /* for valid bitstreams, always low < range, therefore setting low = range */ /* will always reach the bitstream error condition branch on the next call */ rc_st_dec->rc_range = 0xFFFFFFFF; - rc_st_dec->rc_low = rc_st_dec->rc_range; + rc_st_dec->rc_low = rc_st_dec->rc_range; /*Q0*/ return 0; /* reading the 8 bits would trigger an out-of-bounds array access */ } @@ -877,5 +877,5 @@ static Word16 rc_uni_dec_read_fx( s_or( shl( shifted_bit_buffer[4], 3 ), s_or( shl( shifted_bit_buffer[5], 2 ), s_or( shl( shifted_bit_buffer[6], 1 ), shifted_bit_buffer[7] ) ) ) ) ) ) ); - return byte_read; + return byte_read; /*Q0*/ } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 5e967443d..b80450511 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -1305,7 +1305,11 @@ ivas_error acelp_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // conv params from float to fix Q_exc2 = Q_factor_arr( exc2, L_FRAME ); +#ifndef MSAN_FIX floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME16k ); +#else + floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); +#endif floatToFixed_arr( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); floatToFixed_arr( st->lspold_s, st->lspold_s_fx, 15, 16 ); st->min_alpha_fx = float_to_fix16( st->min_alpha, 15 ); @@ -1341,9 +1345,19 @@ ivas_error acelp_core_enc( *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS + +#ifndef MSAN_FIX Word16 q_syn = Q_factor_arr( syn, L_FRAME16k ); +#else + Word16 q_syn = Q_factor_arr( syn, L_FRAME ); +#endif q_syn = min( q_syn, Q_factor_arr( res, L_FRAME16k ) ); + +#ifndef MSAN_FIX floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME16k ); +#else + floatToFixed_arr16( syn, syn_fx, q_syn, L_FRAME ); +#endif floatToFixed_arr( pitch_buf, pitch_buf_fx, Q6, NB_SUBFR16k ); // Saturation Conversion used as last values have garbage values even in float floatToFixed_arr16( res, res_fx, q_syn, L_FRAME16k ); #endif diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 0656104d6..502b22aed 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -309,11 +309,29 @@ void TNSAnalysisStereo_fx( IF( sts[0]->hTcxEnc->tnsData[k].nFilters > 0 || sts[1]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( meanLtpGain_fx, 19660 /* 0.6 in Q15*/ ) ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; - pFilter[0]->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter[0]->order != 0 ) + { + pFilter[0]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[0]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } ++sts[1]->hTcxEnc->tnsData[k].nFilters; - pFilter[1]->filterType = TNS_FILTER_ON; - move16(); + IF( pFilter[1]->order != 0 ) + { + pFilter[1]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[1]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -323,11 +341,29 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters[0]->minEnergyChange ) ) { ++sts[0]->hTcxEnc->tnsData[k].nFilters; - pFilter[0]->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter[0]->order != 0 ) + { + pFilter[0]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[0]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } ++sts[1]->hTcxEnc->tnsData[k].nFilters; - pFilter[1]->filterType = TNS_FILTER_ON; - move16(); + IF( pFilter[1]->order != 0 ) + { + pFilter[1]->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter[1]->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -540,8 +576,18 @@ void TNSAnalysisStereo_fx( IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 || isTCX10 || LT_16( sts[ch]->hTcxEnc->tcxltp_gain, 19660 ) ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; - pFilter->filterType = TNS_FILTER_ON; - move16(); + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter->order != 0 ) + { + pFilter->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { @@ -550,13 +596,24 @@ void TNSAnalysisStereo_fx( IF( GE_16( maxEnergyChange_fx, pTnsParameters->minEnergyChange ) ) { ++sts[ch]->hTcxEnc->tnsData[k].nFilters; - pFilter->filterType = TNS_FILTER_ON; + /* When order parameter is evaluated as 0 and change in precision causes the flow to reach here, + this may result in crash later. Changing the filter type here so the order is taken here in further section */ + IF( pFilter->order != 0 ) + { + pFilter->filterType = TNS_FILTER_ON; + move16(); + } + ELSE + { + pFilter->filterType = TNS_FILTER_ON_ZERO; + move16(); + } } ELSE { pFilter->filterType = TNS_FILTER_OFF; + move16(); } - move16(); } } ELSE IF( sts[ch]->hTcxEnc->tnsData[k].nFilters > 0 ) /* If a previous filter is turned on */ diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index bd75d6636..703aa2014 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -457,7 +457,11 @@ ivas_error init_encoder( #ifndef IVAS_FLOAT_FIXED wb_vad_init( st->hVAD ); #else +#ifndef MSAN_FIX wb_vad_init_fx( st->hVAD ); +#else + wb_vad_init_ivas_fx( st->hVAD ); +#endif #endif } else diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index baaf780da..45704ed04 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -140,6 +140,13 @@ ivas_error ivas_core_enc( Word16 i; #endif +#ifdef MSAN_FIX + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set_zero( bwe_exc_extended[i], L_FRAME32k + NL_BUFF_OFFSET ); + } +#endif + push_wmops( "ivas_core_enc" ); error = IVAS_ERR_OK; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 598a5094b..336b51ca6 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1159,7 +1159,9 @@ ivas_error ivas_compute_core_buffers( floatToFixed_arr16( old_inp_16k, old_inp_16k_fx, Q_old_inp_16k, L_INP ); floatToFixed_arr16( signal_in, signal_in_fx, Q_old_inp_16k, 960 ); +#ifndef MSAN_FIX floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); +#endif floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c95570a07..97f13701f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -173,6 +173,12 @@ ivas_error ivas_cpe_enc( set16_fx( voicing_fr_fx[0], 0, NB_SUBFR ); set16_fx( voicing_fr_fx[1], 0, NB_SUBFR ); +#ifdef MSAN_FIX + FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + { + set_zero( fft_buff[i], 2 * L_FFT ); + } +#endif /*------------------------------------------------------------------* * CPE initialization - core coder *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 58746812a..14125546c 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -538,8 +538,10 @@ ivas_error ivas_dirac_enc( floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif } } #endif @@ -685,6 +687,7 @@ ivas_error ivas_dirac_enc( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } } + pop_wmops(); return IVAS_ERR_OK; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index db5e9816b..86dd71446 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -888,7 +888,9 @@ ivas_error front_vad_spar( floatToFixed_arrL( hFrontVad->hNoiseEst->bckr, hFrontVad->hNoiseEst->bckr_fx, Q_new_old + QSCALE + 2, 20 ); floatToFixed_arrL( hFrontVad->hNoiseEst->enrO, hFrontVad->hNoiseEst->enrO_fx, Q_new_old + QSCALE + 2, 20 ); st->flag_noisy_speech_snr_fx = (Word8) st->flag_noisy_speech_snr; +#ifndef MSAN_FIX floatToFixed_arrL( &band_energies[0], &band_energies_fx[0], Q_new_old + QSCALE + 2, 40 ); +#endif #endif if ( ( error = front_vad_fx( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands_fx, Etot_fx, lf_E_fx, localVAD_HE_SAD, vad_hover_flag, band_energies_fx, &PS_fx[0], &st->lgBin_E_fx[0], Q_inp, &Q_buffer, Q_add, &front_create_flag ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index f5f0cbdbe..4c02123a9 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -986,8 +986,11 @@ ivas_error ivas_masa_encode( floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + +#ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif } } #endif diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 10768a52c..fe7220da6 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1661,6 +1661,14 @@ void ivas_mdct_core_whitening_enc( push_wmops( "mdct_core_whitening" ); +#ifdef MSAN_FIX + FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + set_zero( A_q[ch][0], M + 1 ); + set_zero( A_q[ch][1], M + 1 ); + } +#endif + /*--------------------------------------------------------------* * Initialization *---------------------------------------------------------------*/ @@ -1703,6 +1711,9 @@ void ivas_mdct_core_whitening_enc( mdst_spectrum_fx[ch][1] = mdst_spectrum_long_fx[ch] + N_TCX10_MAX; set_f( scf[ch][0], 0.0, M ); set_f( scf[ch][1], 0.0, M ); +#ifdef MSAN_FIX + set_f( temp_buffer, 0.0, 15 * L_FRAME48k / 8 ); +#endif #endif } diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index 5419544c2..a6cc6f225 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -1017,15 +1017,24 @@ Word16 quantize_sns_fx( /* Re-Scaling Buffers*/ *sns_e = sns_e_tmp[0][0]; move16(); + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { *sns_e = s_max( *sns_e, sns_e_tmp[ch][0] ); *sns_e = s_max( *sns_e, sns_e_tmp[ch][1] ); } + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef MSAN_FIX + FOR( k = 0; k < nSubframes; k++ ) + { + scale_sig32( snsQ_out_fx[ch][k], M, sub( sns_e_tmp[ch][k], *sns_e ) ); + } +#else scale_sig32( snsQ_out_fx[ch][0], M, sub( sns_e_tmp[ch][0], *sns_e ) ); scale_sig32( snsQ_out_fx[ch][1], M, sub( sns_e_tmp[ch][1], *sns_e ) ); +#endif } /* get back to L/F representation */ test(); diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 3552cb9ae..23cc63ccb 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -745,6 +745,9 @@ void stereo_mdct_core_enc( set_f( quantized_spectrum_long[ch], 0.0, N_MAX ); set_f( mdst_spectrum_long[ch], 0.0, N_MAX ); set_f( powerSpec[ch], 0.0, N_MAX ); +#ifdef MSAN_FIX + set_f( orig_spectrum_long[ch], 0.0, N_MAX ); +#endif } /*--------------------------------------------------------------* diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 7000b6fbe..1300d421f 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -558,7 +558,11 @@ void RunTransientDetection_ivas_fx( /* Update subblock energies. */ +#ifdef MSAN_FIX + Scale_sig( filteredInput_fx, length, 8 ); +#else Scale_sig( filteredInput_fx, L_FRAME_MAX, 8 ); +#endif Scale_sig32( pSubblockEnergies->subblockNrg, NSUBBLOCKS + MAX_TD_DELAY, 3 ); Scale_sig32( pSubblockEnergies->accSubblockNrg, NSUBBLOCKS + MAX_TD_DELAY + 1, 3 ); Scale_sig( pSubblockEnergies->subblockNrgChange, NSUBBLOCKS + MAX_TD_DELAY, 3 ); -- GitLab From 41ed0d3e911d659a8db0dc265d34e61ebe106b6d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 18 Oct 2024 18:28:04 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_dec/acelp_core_dec_ivas_fx.c | 2 +- lib_enc/ivas_mdct_core_enc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 8b2313360..a16878a55 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -955,7 +955,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Prepare ACB memory from last HQ frame */ old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ); tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = shl_sat( old_exc_s_fx[ st->L_frame- 1], st->Q_syn ); /* Q0 -> Q_syn */ + st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */ move16(); PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index fe7220da6..a597110c5 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1662,7 +1662,7 @@ void ivas_mdct_core_whitening_enc( push_wmops( "mdct_core_whitening" ); #ifdef MSAN_FIX - FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { set_zero( A_q[ch][0], M + 1 ); set_zero( A_q[ch][1], M + 1 ); -- GitLab