diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 375d4c2cf3dbf9bbc092a1ee3e0a523d3ea480f3..1642d1253ca44a9da38178f806a166ebfd151297 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -23,8 +23,8 @@ static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, Word16 Qnew ); void encod_audio_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12 */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ const Word16 *res, /* i : residual signal Q_new */ Word16 *synth, /* i/o: core synthesis Q-1 */ Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ @@ -32,10 +32,10 @@ void encod_audio_fx( Word16 *voice_factors, /* o : voicing factors Q15 */ Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + Word16 *lsf_new, /* i : current frame ISF vector Qx2.56 */ + Word16 *tmp_noise, /* o : noise energy Q2*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 Q_new, Word16 shift ) { @@ -43,9 +43,11 @@ void encod_audio_fx( Word16 i, i_subfr, nb_subfr, last_pit_bin; Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; Word16 tmp_nb_bits_tot = 0; + move16(); Word16 Es_pred; Word16 dct_res[L_FRAME16k], dct_epit[L_FRAME16k]; Word16 m_mean = 0; + move16(); Word16 saved_bit_pos; Word16 exc_wo_nf[L_FRAME16k]; Word32 Lm_mean; @@ -65,7 +67,7 @@ void encod_audio_fx( move16(); T0_frac_tmp = 0; move16(); - Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); + Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; move16(); Es_pred = 0; @@ -78,7 +80,7 @@ void encod_audio_fx( *---------------------------------------------------------------*/ #ifdef GSC_IVAS // TVB -->>>>>> test(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) + IF( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 ) { push_indice_fx( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); } @@ -99,6 +101,7 @@ void encod_audio_fx( test(); test(); test(); + test(); IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) { @@ -113,7 +116,7 @@ void encod_audio_fx( FOR( i = 0; i < 5; i++ ) { test(); - if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) + if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 /*6.0 in Q8*/ ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) { hGSCEnc->cor_strong_limit = 0; move16(); @@ -121,6 +124,9 @@ void encod_audio_fx( } } test(); + test(); + test(); + test(); IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) { nb_subfr = NB_SUBFR; @@ -166,10 +172,14 @@ void encod_audio_fx( nb_subfr_flag = 1; move16(); } + + test(); + test(); + test(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) { nb_subfr = shl( nb_subfr, 1 ); - nb_subfr_flag |= 0x2; + nb_subfr_flag = s_or( nb_subfr_flag, 0x2 ); logic16(); } @@ -194,14 +204,22 @@ void encod_audio_fx( * Compute adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); test(); IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) { - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode > EVS_MONO ) ) { nb_bits = 5; + move16(); } ELSE { @@ -235,17 +253,20 @@ void encod_audio_fx( { /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + move16(); } ELSE { /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + move16(); } IF( NE_16( st_fx->coder_type, INACTIVE ) ) { hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); - + move16(); hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); + move16(); } hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; @@ -253,6 +274,7 @@ void encod_audio_fx( IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP2; + move16(); IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { hGSCEnc->noise_lev = NOISE_LEVEL_SP0; @@ -267,12 +289,14 @@ void encod_audio_fx( ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); + move16(); push_indice_fx( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); } ELSE IF( st_fx->GSC_noisy_speech ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP3; move16(); + move16(); } ELSE { @@ -373,8 +397,8 @@ void encod_audio_fx( void encod_audio_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12 */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ const Word16 *res, /* i : residual signal Q_new */ Word16 *synth, /* i/o: core synthesis Q-1 */ Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ @@ -382,8 +406,8 @@ void encod_audio_ivas_fx( Word16 *voice_factors, /* o : voicing factors Q15 */ Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ + Word16 *lsf_new, /* i : current frame ISF vector Qx2.56 */ + Word16 *tmp_noise, /* o : noise energy Q8*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ Word16 Q_new, @@ -428,7 +452,7 @@ void encod_audio_ivas_fx( *---------------------------------------------------------------*/ test(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) + if ( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 ) { push_indice( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); } @@ -449,6 +473,7 @@ void encod_audio_ivas_fx( test(); test(); test(); + test(); IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) { @@ -471,6 +496,9 @@ void encod_audio_ivas_fx( } } test(); + test(); + test(); + test(); IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) { nb_subfr = NB_SUBFR; @@ -516,6 +544,10 @@ void encod_audio_ivas_fx( nb_subfr_flag = 1; move16(); } + + test(); + test(); + test(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) { nb_subfr = shl( nb_subfr, 1 ); @@ -523,6 +555,7 @@ void encod_audio_ivas_fx( logic16(); } + test(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); @@ -544,14 +577,22 @@ void encod_audio_ivas_fx( * Compute adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); test(); IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) { - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode > EVS_MONO ) ) { nb_bits = 5; + move16(); } ELSE { @@ -585,17 +626,20 @@ void encod_audio_ivas_fx( { /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + move16(); } ELSE { /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ + move16(); } IF( NE_16( st_fx->coder_type, INACTIVE ) ) { hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); - + move16(); hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); + move16(); } hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; @@ -603,6 +647,7 @@ void encod_audio_ivas_fx( IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP2; + move16(); IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { hGSCEnc->noise_lev = NOISE_LEVEL_SP0; @@ -708,7 +753,7 @@ void encod_audio_ivas_fx( * Synthesis *--------------------------------------------------------------------------------------*/ - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) { Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); @@ -721,7 +766,7 @@ void encod_audio_ivas_fx( hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ move16(); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_new */ return; } @@ -753,14 +798,14 @@ void encod_audio_ivas_fx( void gsc_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ - Word16 res_dct_in[], /* i : dct of residual signal */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + Word16 res_dct_in[], /* i : dct of residual signal Q_exc*/ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise, /* o : noise energy */ + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + Word16 *tmp_noise, /* o : noise energy Q2*/ Word16 Q_exc ) { Word16 y2_filt[L_FRAME16k]; @@ -794,6 +839,7 @@ void gsc_enc_fx( *--------------------------------------------------------------------------------------*/ bit = bits_used; + move16(); test(); test(); test(); @@ -841,10 +887,14 @@ void gsc_enc_fx( { IF( LE_32( st_fx->core_brate, brate_intermed_tbl[i] ) ) { - break; + BREAK; } i++; } + + test(); + test(); + test(); if ( GT_16( st_fx->element_mode, EVS_MONO ) && EQ_16( st_fx->coder_type, AUDIO ) && LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { @@ -854,6 +904,7 @@ void gsc_enc_fx( mean_gain = gsc_gainQ_fx( hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth /*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/ ); *tmp_noise = mult_r( 320, mean_gain ); /*10 in Q5 lp_gainc in Q3 */ + move16(); /*--------------------------------------------------------------------------------------* * Frequency encoder @@ -873,7 +924,7 @@ void gsc_enc_fx( { tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ bit = sub( bit, tmp ); } /* write unused bits */ @@ -974,11 +1025,11 @@ void gsc_enc_ivas_fx( const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ const Word16 bits_used, /* i : Number of bit used before frequency Q */ const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 *lsf_new_fx, + const Word16 *lsf_new_fx, /* Qx2.56 */ /* i : ISFs at the end of the frame */ // Q15 Word16 *exc_wo_nf_fx, /* o : excitation (in f domain) without noisefill */ // Q_exc - Word16 *tmp_noise_fx, /* o : long-term noise energy */ + Word16 *tmp_noise_fx, /* o : long-term noise energy Q8*/ Word16 *Q_exc ) { Word16 i; @@ -1031,7 +1082,7 @@ void gsc_enc_ivas_fx( * (non valuable temporal content present in exc_dct_in is already zeroed) *--------------------------------------------------------------------------------------*/ - v_sub_16( res_dct_in_fx, exc_dct_in_fx, exc_diff_fx, st->L_frame ); + v_sub_16( res_dct_in_fx, exc_dct_in_fx, exc_diff_fx, st->L_frame ); /* Q_exc */ exc_diff_fx[0] = 0; move16(); @@ -1064,18 +1115,18 @@ void gsc_enc_ivas_fx( { IF( LE_32( st->core_brate, brate_intermed_tbl[i] ) ) { - break; + BREAK; } - i = add( i, 1 ); + i++; } test(); test(); test(); - IF( st->element_mode > EVS_MONO && EQ_16( st->coder_type, AUDIO ) && - LE_32( st->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ + if ( st->element_mode > EVS_MONO && EQ_16( st->coder_type, AUDIO ) && + LE_32( st->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i = sub( i, 1 ); + i--; } mean_gain_fx = gsc_gainQ_ivas_fx( hBstr, st->element_mode, st->idchan, Ener_per_bd_iQ_fx, Ener_per_bd_iQ_fx, brate_intermed_tbl[i], st->coder_type, st->bwidth, st->L_frame, st->tdm_LRTD_flag, st->core_brate ); @@ -1129,18 +1180,18 @@ void gsc_enc_ivas_fx( j = emaximum_fx( Q12, concat_out_fx, shl( nb_subbands, 4 ), &L_tmp ); IF( LE_16( add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ), ONE_IN_Q12 ) ) { - max_eq = 32767; + max_eq = 32767; /* Q15 */ move16(); } ELSE { - max_eq = div_s( ONE_IN_Q12, add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ) ); + max_eq = div_s( ONE_IN_Q12, add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ) ); /* Q15 */ } } FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out_fx + i_mult( j, 16 ), exc_diffQ_fx + i_mult( max_ener_band[j], 16 ), 16 ); + Copy( concat_out_fx + i_mult( j, 16 ), exc_diffQ_fx + i_mult( max_ener_band[j], 16 ), 16 ); /* Q12 */ IF( GT_16( max_ener_band[j], last_bin ) ) { @@ -1209,7 +1260,7 @@ void gsc_enc_ivas_fx( { FOR( i = 64; i < st->L_frame; i++ ) { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); + exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ move16(); } } @@ -1217,7 +1268,7 @@ void gsc_enc_ivas_fx( { FOR( i = 0; i < L_FRAME; i++ ) { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); + exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ move16(); } } @@ -1229,13 +1280,13 @@ void gsc_enc_ivas_fx( Word16 Q_exc_new = s_min( *Q_exc, hGSCEnc->Q_last_exc_dct_in ); IF( NE_16( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ) { - Scale_sig( hGSCEnc->last_exc_dct_in_fx, st->L_frame, sub( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ); + Scale_sig( hGSCEnc->last_exc_dct_in_fx, st->L_frame, sub( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ); /* Q_exc_new */ hGSCEnc->Q_last_exc_dct_in = Q_exc_new; move16(); } ELSE { - Scale_sig( exc_dct_in_fx, st->L_frame, sub( Q_exc_new, *Q_exc ) ); + Scale_sig( exc_dct_in_fx, st->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ *Q_exc = Q_exc_new; move16(); } @@ -1275,7 +1326,7 @@ void gsc_enc_ivas_fx( /*=======================================================================*/ static Word16 edyn_fx( /* o : ratio of max to mean */ - const Word16 *vec, /* i : input vector */ + const Word16 *vec, /* i : input vector Qnew*/ const Word16 lvec, /* i : length of input vector */ Word16 Qnew ) { @@ -1286,6 +1337,7 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ Word16 scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif ener_mean = L_shl( 1, shl( Qnew, 1 ) ); /*2*Qnew*/ @@ -1323,10 +1375,10 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ } ELSE { - dyn = 1280; + dyn = 1280; /* 10.0f in Q7 */ move16(); } - return dyn; + return dyn; /* Q7 */ } @@ -1341,7 +1393,7 @@ void GSC_enc_init_fx( ) { /* AC mode */ - hGSCEnc->seed_tcx = 15687; + hGSCEnc->seed_tcx = 15687; /* Q0 */ move16(); hGSCEnc->cor_strong_limit = 1; move16(); @@ -1351,6 +1403,7 @@ void GSC_enc_init_fx( set16_fx( hGSCEnc->last_bitallocation_band, 0, 6 ); hGSCEnc->mem_last_pit_band = BAND1k2 + 1; + move16(); hGSCEnc->Last_frame_ener_fx = MAX_32; move32(); hGSCEnc->lt_gpitch_fx = 0; @@ -1363,8 +1416,8 @@ void GSC_enc_init_fx( move16(); set16_fx( hGSCEnc->mem_syn_tmp_fx, 0, M ); - hGSCEnc->mid_dyn_fx = 5120; - move16(); /*40 -> Q7 */ + hGSCEnc->mid_dyn_fx = 5120; /*40 -> Q7 */ + move16(); hGSCEnc->noise_lev = NOISE_LEVEL_SP0; move16(); hGSCEnc->past_dyn_dec = 0; diff --git a/lib_enc/guided_plc_enc_fx.c b/lib_enc/guided_plc_enc_fx.c index 9aa2ecb65550f4be98ba9615395e56d73888cd2b..60a3f8f50773d8e32359d71cc2ed14587e4d5a03 100644 --- a/lib_enc/guided_plc_enc_fx.c +++ b/lib_enc/guided_plc_enc_fx.c @@ -6,7 +6,6 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "stat_enc.h" @@ -19,8 +18,8 @@ * *-------------------------------------------------------------------*/ static void coderLookAheadInnovation( - Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ - Word16 *pT, /* out: pitch */ + Word16 A_3Q12[], /* input: coefficients NxAz[M+1] Q12*/ + Word16 *pT, /* out: pitch Q0*/ PLC_ENC_EVS_HANDLE st, /* i/o: coder memory state */ Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ @@ -41,13 +40,18 @@ static void coderLookAheadInnovation( Word32 max_ps, max_ps_tmp; Word16 max_ps_e; Word16 tmp_loop; + move32(); + move16(); + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Debug init (not instrumented) */ T0_fx = -3000; + move16(); subfr_len = shl( L_SUBFR, 1 ); /* 2*L_SUBFR */ if ( GT_16( L_FRAME16k, L_frame ) ) { @@ -59,10 +63,10 @@ static void coderLookAheadInnovation( * - BASOP specific initialization. * *------------------------------------------------------------------------*/ /* initialization */ - exc_Qx = exc_buf_Qx + L_EXC_MEM + 8; + exc_Qx = exc_buf_Qx + L_EXC_MEM + 8; /* Q(st->Qold) */ FOR( i = 0; i < L_EXC_MEM + 8; i++ ) { - exc_buf_Qx[i] = old_exc[i]; + exc_buf_Qx[i] = old_exc[i]; /* Q(st->Qold) */ move16(); } @@ -72,17 +76,17 @@ static void coderLookAheadInnovation( *------------------------------------------------------------------------*/ /* find LP residual signal for look-ahead part */ getLookAheadResSig( speechLookAhead_Qx, A_3Q12, exc_Qx, L_frame, 2 ); - Scale_sig( exc_Qx, subfr_len, 1 ); + Scale_sig( exc_Qx, subfr_len, 1 ); /* Q(st->Qold) + 1 */ /* find target signals */ - prev_pitch = st->T0_4th; + prev_pitch = st->T0_4th; /* Q0 */ move16(); /* find best candidate of pitch lag */ - T0_fx = st->T0_4th; + T0_fx = st->T0_4th; /* Q0 */ move16(); - mantissa_max = -0x7fffffffL; + mantissa_max = -0x7fffffffL; /* Q15 */ move32(); - max_ps = -0x7fffffffL; + max_ps = -0x7fffffffL; /* Q15 */ move32(); max_ps_e = 16; move16(); @@ -90,14 +94,14 @@ static void coderLookAheadInnovation( /*find maximum*/ exc_max = 0; move16(); - tmp_loop = s_min( -prev_pitch + search_range + subfr_len, 0 ); + tmp_loop = s_min( -prev_pitch + search_range + subfr_len, 0 ); /* Q0 */ FOR( i = -prev_pitch - search_range; i < tmp_loop; i++ ) { - exc_max = s_max( exc_Qx[i], exc_max ); + exc_max = s_max( exc_Qx[i], exc_max ); /* Q(st->Qold) + 1 */ } FOR( i = 0; i < subfr_len; i++ ) { - exc_max = s_max( exc_max, exc_Qx[i] ); + exc_max = s_max( exc_max, exc_Qx[i] ); /* Q(st->Qold) + 1 */ } /*calculate scaling factor for optimal precision and assure no overflow in dotproduct*/ exc_sh = sub( 15, norm_s( sub( subfr_len, 1 ) ) ); /*ceil(ld(subfr_len))*/ @@ -105,15 +109,15 @@ static void coderLookAheadInnovation( exc_sh = shr( add( exc_sh, 1 ), 1 ); /*scale buffer only where its needed*/ - tmp_loop = s_min( -prev_pitch + search_range + subfr_len, 0 ); + tmp_loop = s_min( -prev_pitch + search_range + subfr_len, 0 ); /* Q0 */ FOR( i = -prev_pitch - search_range; i < tmp_loop; i++ ) { - exc_Qx[i] = shr( exc_Qx[i], exc_sh ); + exc_Qx[i] = shr( exc_Qx[i], exc_sh ); /* Q(st->Qold) + 1 */ move16(); } FOR( i = 0; i < subfr_len; i++ ) { - exc_Qx[i] = shr( exc_Qx[i], exc_sh ); + exc_Qx[i] = shr( exc_Qx[i], exc_sh ); /* Q(st->Qold) + 1 */ move16(); } @@ -122,7 +126,7 @@ static void coderLookAheadInnovation( move16(); FOR( i = -prev_pitch - search_range; i < -prev_pitch + search_range + subfr_len; i++ ) { - alp_ini = L_mac( alp_ini, exc_Qx[i], exc_Qx[i] ); + alp_ini = L_mac( alp_ini, exc_Qx[i], exc_Qx[i] ); /* 2*(Q(st->Qold) + 1) + 1 */ } FOR( i = -search_range; i < search_range; i++ ) @@ -138,24 +142,24 @@ static void coderLookAheadInnovation( FOR( k = 0; k < subfr_len; k++ ) { - ps = L_mac( ps, exc_Qx[k], exc_Qx[k - prev_pitch - i] ); + ps = L_mac( ps, exc_Qx[k], exc_Qx[k - prev_pitch - i] ); /* 2*(Q(st->Qold) + 1) + 1 */ } /*calculate "small" dotproducts in order to subtract them from the "bigger" one*/ - FOR( k = negate( add( prev_pitch, search_range ) ); k < -prev_pitch - i; k++ ) + FOR( k = -( ( prev_pitch + search_range ) ); k < -prev_pitch - i; k++ ) { - alp_s1 = L_mac( alp_s1, exc_Qx[k], exc_Qx[k] ); + alp_s1 = L_mac( alp_s1, exc_Qx[k], exc_Qx[k] ); /* 2*(Q(st->Qold) + 1) + 1 */ } tmp_loop = sub( add( search_range, subfr_len ), prev_pitch ); FOR( k = +subfr_len - i - prev_pitch; k < tmp_loop; k++ ) { - alp_s2 = L_mac( alp_s2, exc_Qx[k], exc_Qx[k] ); + alp_s2 = L_mac( alp_s2, exc_Qx[k], exc_Qx[k] ); /* 2*(Q(st->Qold) + 1) + 1 */ } alp = L_sub( alp_ini, L_add( alp_s1, alp_s2 ) ); alp = L_max( alp, 1 ); /* alp must not be 0 */ alp_e = shl( exc_sh, 1 ); ps_e = shl( exc_sh, 1 ); - alp = ISqrt32( alp, &alp_e ); + alp = ISqrt32( alp, &alp_e ); /* Q31-alp_e */ ps = Mpy_32_16_1( ps, round_fx( alp ) ); /*alp_e+ps_e*/ ps_e = add( alp_e, ps_e ); @@ -173,7 +177,7 @@ static void coderLookAheadInnovation( T0_fx = add( prev_pitch, i ); } } - mantissa_max = max_ps; + mantissa_max = max_ps; /* Q31-ps_e */ move32(); if ( mantissa_max < 0 ) { @@ -239,9 +243,9 @@ void enc_prm_side_Info_fx( void encoderSideLossSimulation_fx( Encoder_State *st, PLC_ENC_EVS_HANDLE hPlc_Ext, - Word16 *lsf_q, /* Q1*1.28 */ - const Word16 stab_fac, /* Q15 */ - const Word16 calcOnlyISF, + Word16 *lsf_q, /* Qx2.56 */ + const Word16 stab_fac, /* Q15 */ + const Word16 calcOnlyISF, /* Q0 */ const Word16 L_frame ) { Word16 lspLocal_Q15[M]; @@ -251,11 +255,11 @@ void encoderSideLossSimulation_fx( /* Decoder State Update */ IF( EQ_16( L_frame, L_FRAME_16k ) ) { - lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_16k_FX ); + lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_16k_FX ); /* Q15 */ } ELSE { - lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_FX ); + lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_FX ); /* Q15 */ } @@ -263,8 +267,8 @@ void encoderSideLossSimulation_fx( st->narrowBand, st->sr_core ); - Copy( st->mem_MA_fx, hPlc_Ext->mem_MA_14Q1, M ); - Copy( st->mem_AR_fx, hPlc_Ext->mem_AR, M ); + Copy( st->mem_MA_fx, hPlc_Ext->mem_MA_14Q1, M ); /* Qx2.56 */ + Copy( st->mem_AR_fx, hPlc_Ext->mem_AR, M ); /* Qx2.56 */ /* ISF parameter processing for concealment */ @@ -272,15 +276,15 @@ void encoderSideLossSimulation_fx( hPlc_Ext->stab_fac_Q15 = stab_fac; move16(); - Copy( lsf_q, hPlc_Ext->lsfold_14Q1, M ); - Copy( lspLocal_Q15, hPlc_Ext->lspold_Q15, M ); + Copy( lsf_q, hPlc_Ext->lsfold_14Q1, M ); /* Qx2.56 */ + Copy( lspLocal_Q15, hPlc_Ext->lspold_Q15, M ); /* Q15 */ IF( calcOnlyISF != 0 ) { /* ISF concealment simulation */ getConcealedLSF( hPlc_Ext, xsfBase, st->clas, L_frame ); - hPlc_Ext->T0 = hPlc_Ext->T0_4th; + hPlc_Ext->T0 = hPlc_Ext->T0_4th; /* Q0 */ move16(); } ELSE @@ -300,9 +304,9 @@ void encoderSideLossSimulation_fx( getConcealedLP( hPlc_Ext, A_3Q12, xsfBase, st->clas, L_frame ); /* apply encoder side PLC simulation */ - hPlc_Ext->pit_min = st->pit_min; + hPlc_Ext->pit_min = st->pit_min; /* Q0 */ move16(); - hPlc_Ext->pit_max = st->pit_max; + hPlc_Ext->pit_max = st->pit_max; /* Q0 */ move16(); coderLookAheadInnovation( A_3Q12, &( hPlc_Ext->T0 ), hPlc_Ext, speechLookAhead_Qx, old_exc_Qx, L_frame ); } @@ -336,11 +340,11 @@ void GplcTcxEncSetup_fx( * *-------------------------------------------------------------------*/ Word16 encSideSpecPowDiffuseDetector_fx( - Word16 *lsf_ref, - Word16 *lsf_con, - const Word32 sr_core, - Word16 *prev_lsf4_mean, - const Word8 sw, + Word16 *lsf_ref, /* Qx2.56 */ + Word16 *lsf_con, /* Qx2.56 */ + const Word32 sr_core, /* Q0 */ + Word16 *prev_lsf4_mean, /* Qx2.56 */ + const Word8 sw, /* Q0 */ const Word16 coder_type ) { Word16 tmp; @@ -355,14 +359,14 @@ Word16 encSideSpecPowDiffuseDetector_fx( /* calculate the mean of the lowest 4 LSFs */ - L_tmp = L_mult( lsf_ref[0], 8192 /*1.0/4.0 Q15*/ ); - L_tmp = L_mac( L_tmp, lsf_ref[1], 8192 /*1.0/4.0 Q15*/ ); - L_tmp = L_mac( L_tmp, lsf_ref[2], 8192 /*1.0/4.0 Q15*/ ); - lsf4_mean = mac_r( L_tmp, lsf_ref[3], 8192 /*1.0/4.0 Q15*/ ); + L_tmp = L_mult( lsf_ref[0], 8192 /*1.0/4.0 Q15*/ ); /* Qx2.56 */ + L_tmp = L_mac( L_tmp, lsf_ref[1], 8192 /*1.0/4.0 Q15*/ ); /* Qx2.56 */ + L_tmp = L_mac( L_tmp, lsf_ref[2], 8192 /*1.0/4.0 Q15*/ ); /* Qx2.56 */ + lsf4_mean = mac_r( L_tmp, lsf_ref[3], 8192 /*1.0/4.0 Q15*/ ); /* Qx2.56 */ IF( sw ) { - Copy( lsf_con, lsf_mod, M ); + Copy( lsf_con, lsf_mod, M ); /* Qx2.56 */ modify_lsf( lsf_mod, M, sr_core, 1 ); @@ -372,28 +376,29 @@ Word16 encSideSpecPowDiffuseDetector_fx( cum_dist2 = 0; cnt_imprv = 0; + move16(); IF( EQ_32( sr_core, INT_FS_16k ) ) { - th = 2560; - move16(); /* LSF */ - th_dif = 288; - move16(); /* LSF */ + th = 2560; /* Qx2.56 */ + move16(); /* LSF */ + th_dif = 288; /* Qx2.56 */ + move16(); /* LSF */ } ELSE { - th = 2048; - move16(); /* LSF */ - th_dif = 230; - move16(); /* LSF */ + th = 2048; /* Qx2.56 */ + move16(); /* LSF */ + th_dif = 230; /* Qx2.56 */ + move16(); /* LSF */ } FOR( i = 0; i < M; i++ ) { tmp = sub( lsf_con[i], lsf_ref[i] ); - dist1 = L_mult( tmp, tmp ); + dist1 = L_mult( tmp, tmp ); /* 2*(Qx2.56)+1 */ tmp = sub( lsf_mod[i], lsf_ref[i] ); - dist2 = L_mult( tmp, tmp ); + dist2 = L_mult( tmp, tmp ); /* 2*(Qx2.56)+1 */ if ( GT_32( dist1, dist2 ) ) { @@ -409,6 +414,7 @@ Word16 encSideSpecPowDiffuseDetector_fx( test(); test(); test(); + test(); if ( GT_32( cum_dist1, L_add( cum_dist2, Mpy_32_16_1( cum_dist2, 4915 ) ) ) && GT_16( sub( lsf4_mean, *prev_lsf4_mean ), th_dif ) && LT_16( *prev_lsf4_mean, th ) && GT_16( cnt_imprv, 2 ) && EQ_16( coder_type, GENERIC ) ) { idx = 1; @@ -438,17 +444,19 @@ void updateSpecPowDiffuseIdx_fx( Word16 k; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move32(); move16(); - st->mean_gc[1] = st->gain_code[0]; - min_gp = st->bpf_gainT[0]; + st->mean_gc[1] = st->gain_code[0]; /* Q15 */ + min_gp = st->bpf_gainT[0]; /* Q15 */ FOR( k = 1; k < 4; k++ ) { st->mean_gc[1] = L_add_o( st->mean_gc[1], st->gain_code[k], &Overflow ); + move32(); min_gp = s_min( min_gp, st->bpf_gainT[k] ); } @@ -460,5 +468,5 @@ void updateSpecPowDiffuseIdx_fx( st->glr_idx[0] = 0; } move16(); - st->mean_gc[0] = st->mean_gc[1]; + st->mean_gc[0] = st->mean_gc[1]; /* Q15 */ } diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 3dc5f5b8aa066cacc554123f016a388638dbfe11..eabfe87b48124b8e97d483242005d0ceada58950 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -78,27 +78,27 @@ void stereo_tcx_init_enc_fx( move16(); } - st->hTcxCfg->coder_type = st->coder_type; + st->hTcxCfg->coder_type = st->coder_type; /* Q0 */ move16(); test(); test(); - IF( !st->tcxonly && !st->localVAD && EQ_16( st->hTcxCfg->coder_type, GENERIC ) ) + if ( !st->tcxonly && !st->localVAD && EQ_16( st->hTcxCfg->coder_type, GENERIC ) ) { st->hTcxCfg->coder_type = UNVOICED; move16(); } /*sampling rate*/ - total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); + total_brate = L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ); /* Q0 */ st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); move32(); st->fscale = sr2fscale_fx( st->sr_core ); move16(); /*frame size*/ - st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st->L_frame = extract_l( Mpy_32_32( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ move16(); - st->hTcxEnc->L_frameTCX = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st->hTcxEnc->L_frameTCX = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ move16(); test(); @@ -117,17 +117,17 @@ void stereo_tcx_init_enc_fx( } /*TCX tools*/ - st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_mode ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_mode ); /* Q0 */ move16(); - st->hTcxCfg->resq = getResq( total_brate ); + st->hTcxCfg->resq = getResq( total_brate ); /* Q0 */ move16(); - st->hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_mode, st->element_mode ); + st->hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_mode, st->element_mode ); /* Q0 */ move16(); - st->igf = getIgfPresent_fx( st->element_mode, total_brate, st->bwidth, st->rf_mode ); + st->igf = getIgfPresent_fx( st->element_mode, total_brate, st->bwidth, st->rf_mode ); /* Q0 */ move16(); prev_IsTNSAllowed = st->hTcxCfg->fIsTNSAllowed; move16(); - IF( NE_16( st->element_mode, EVS_MONO ) ) + if ( ( st->element_mode != EVS_MONO ) ) { st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); move16(); @@ -154,8 +154,8 @@ void stereo_tcx_init_enc_fx( void stereo_tcx_core_enc( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ - const Word16 new_samples_16k[], /* i : buffer of input signal @16 kHz */ + const Word16 new_samples_12k8[], /* i : buffer of input signal @12.8 kHz Q_new*/ + const Word16 new_samples_16k[], /* i : buffer of input signal @16 kHz Q_new*/ const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ Word16 lsp_new_fx[], /* i : LSPs at the end of the frame, Q15 */ Word16 lsp_mid_fx[], /* i : LSPs in the middle of the frame, Q15 */ @@ -242,14 +242,14 @@ void stereo_tcx_core_enc( *---------------------------------------------------------------*/ /* Subtract the bits of common header */ - st->bits_frame_core = extract_l( L_sub( Mpy_32_32( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), hBstr->nb_bits_tot ) ); + st->bits_frame_core = extract_l( L_sub( Mpy_32_32( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ), hBstr->nb_bits_tot ) ); /* Q0 */ move16(); /*Get Bits of TCX header*/ nbits_header = 3; /* Coder types (2) + last_core for bfi (1) */ move16(); - IF( st->tcxonly ) + if ( st->tcxonly ) { /* TCX20/10 flag */ nbits_header = add( nbits_header, 1 ); @@ -281,7 +281,7 @@ void stereo_tcx_core_enc( move16(); /* check minimum pitch for quantization */ - IF( LT_16( T_op[i], PIT_MIN_SHORTER ) ) + if ( LT_16( T_op[i], PIT_MIN_SHORTER ) ) { T_op[i] = shl( T_op[i], 1 ); move16(); @@ -302,11 +302,11 @@ void stereo_tcx_core_enc( IF( EQ_16( st->L_frame, L_FRAME ) ) { - p_new_samples = new_samples_12k8; + p_new_samples = new_samples_12k8; /* Q_new */ } ELSE { - p_new_samples = new_samples_16k; + p_new_samples = new_samples_16k; /* Q_new */ } /*--------------------------------------------------------------* @@ -351,7 +351,7 @@ void stereo_tcx_core_enc( q_ind_val = 0; move16(); test(); - IF( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) + if ( ( st->last_core != ACELP_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) { q_ind_val = 1; move16(); @@ -372,10 +372,9 @@ void stereo_tcx_core_enc( *---------------------------------------------------------------*/ /* TODO: integrate this. */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->prev_Q_new = 0; st->Q_old = 0; -#endif + Q_new = 0; move16(); input_frame = idiv1616U( extract_l( L_shr( st->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 ); @@ -389,27 +388,31 @@ void stereo_tcx_core_enc( core_signal_analysis_high_bitrate_ivas_fx( p_new_samples, T_op, lsp_new_fx, lsp_mid_fx, st, tnsSize, tnsBits, param_core, <pBits, NULL, st->L_frame, hTcxEnc->L_frameTCX, last_element_mode, vad_hover_flag, NULL, NULL, &Q_new, NULL ); bitsAvailable = sub( st->bits_frame_core, nbits_header ); - IF( st->igf ) + if ( st->igf ) { bitsAvailable = sub( bitsAvailable, st->hIGFEnc->infoTotalBitsWritten ); } - const Word16 Q_ener = Q_new + Q_SCALE - 2; // Q_new + Q_SCALE -2 + const Word16 Q_ener = add( Q_new, sub( Q_SCALE, 2 ) ); // Q_new + Q_SCALE -2 Q_exc = Q_new; st->prev_Q_new = Q_exc; + move16(); + move16(); + move16(); IF( st->hTdCngEnc ) { FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) { - Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); + Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); /* Q_exc */ st->hTdCngEnc->cng_Qexc_buf[ii] = Q_exc; + move16(); } } - Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); + Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); /* Q_exc */ st->hLPDmem->q_lpd_old_exc = Q_new; move16(); - Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); + Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); /* st->Q_syn */ st->hLPDmem->q_lpd_syn = st->Q_syn; move16(); @@ -432,8 +435,8 @@ void stereo_tcx_core_enc( IF( st->rate_switching_reset ) { - Copy( lsp_q_fx, st->lsp_old_fx, M ); - Copy( lsf_q_fx, st->lsf_old_fx, M ); + Copy( lsp_q_fx, st->lsp_old_fx, M ); /* Q15 */ + Copy( lsf_q_fx, st->lsf_old_fx, M ); /* Qx2.56 */ } } @@ -515,12 +518,12 @@ void stereo_tcx_core_enc( * Run TCX10/20 Core *---------------------------------------------------------------*/ - hTcxEnc->measuredBwRatio = ONE_IN_Q14; + hTcxEnc->measuredBwRatio = ONE_IN_Q14; /* Q14 */ move16(); FOR( n = 0; n < n_subframes; n++ ) { - target_bits[n] = sub( idiv1616( add( bitsAvailable, sub( sub( n_subframes, 1 ), n ) ), n_subframes ), tnsBits[n] ); + target_bits[n] = sub( idiv1616( add( bitsAvailable, sub( sub( n_subframes, 1 ), n ) ), n_subframes ), tnsBits[n] ); /* Q0 */ move16(); test(); @@ -541,7 +544,7 @@ void stereo_tcx_core_enc( { tmp1 = idiv1616( tmp1, n_subframes ); } - tmp2 = imult1616( n, NPRM_DIV ); + tmp2 = imult1616( n, NPRM_DIV ); /* Q0 */ QuantizeSpectrum_ivas_fx( st, A_q_fx, A_q_ind, gainlpc_fx[n], gainlpc_e[n], st->synth + tmp1, target_bits[n], tnsSize[n], param_core + tmp2, n, &hm_cfg[n], vad_hover_flag ); } @@ -557,8 +560,8 @@ void stereo_tcx_core_enc( s = s_min( s, norm_s( st->wspeech_enc[st->L_frame - 1] ) ); st->wspeech_enc[st->L_frame - 1] = shl( st->wspeech_enc[st->L_frame - 1], s ); } - Scale_sig( st->synth, st->L_frame, s ); - Scale_sig( st->hLPDmem->syn, M + 1, s ); + Scale_sig( st->synth, st->L_frame, s ); /* st->Q_syn + s */ + Scale_sig( st->hLPDmem->syn, M + 1, s ); /* st->Q_syn + s */ Q_new = add( Q_new, s ); move16(); move16(); @@ -578,8 +581,8 @@ void stereo_tcx_core_enc( IF( st->enableTcxLpc && st->core != ACELP_CORE ) { /* Update lsf / lsp memory */ - Copy( lsf_tcx_q_fx, st->lsf_old_fx, M ); - Copy( lsp_tcx_q_fx, st->lsp_old_fx, M ); + Copy( lsf_tcx_q_fx, st->lsf_old_fx, M ); /* Qx2.56 */ + Copy( lsp_tcx_q_fx, st->lsp_old_fx, M ); /* Q15 */ st->envWeighted = 1; move16(); @@ -592,12 +595,12 @@ void stereo_tcx_core_enc( /* check resonance for pitch clipping algorithm */ gp_clip_test_lsf_ivas_fx( st->element_mode, st->core_brate, st->lsf_old_fx, st->clip_var_fx, 0 ); - Copy( st->lsf_old_fx, st->mem_AR_fx, M ); + Copy( st->lsf_old_fx, st->mem_AR_fx, M ); /* Qx2.56 */ } ELSE { - Copy( lsf_q_fx, st->lsf_old_fx, M ); - Copy( lsp_q_fx, st->lsp_old_fx, M ); + Copy( lsf_q_fx, st->lsf_old_fx, M ); /* Qx2.56 */ + Copy( lsp_q_fx, st->lsp_old_fx, M ); /* Q15 */ } test(); @@ -607,7 +610,7 @@ void stereo_tcx_core_enc( /* update CNG parameters in active frames */ test(); test(); - IF( EQ_16( st->bwidth, NB ) && st->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + IF( EQ_16( st->bwidth, NB ) && st->enableTcxLpc && ( st->core != ACELP_CORE ) ) { Word16 buf_fx[L_LP], res_fx[L_FRAME], A_fx[M + 1], tmp_fx, lsptmp_fx[M]; Word32 A_fx32[M + 1], r_fx[M + 1]; @@ -615,7 +618,7 @@ void stereo_tcx_core_enc( assert( st->L_frame == L_FRAME ); - Copy( st->synth + L_FRAME - L_LP, buf_fx, L_LP ); + Copy( st->synth + L_FRAME - L_LP, buf_fx, L_LP ); /* st->Q_syn */ tmp_fx = st->synth[L_FRAME - L_LP - 1]; move16(); preemph_copy_fx( buf_fx, buf_fx, st->preemph_fac, L_LP, &tmp_fx ); @@ -624,7 +627,8 @@ void stereo_tcx_core_enc( lev_dur_fx( A_fx32, r_fx, M, NULL, Q12, Q_r ); FOR( Word16 j = 0; j < M; j++ ) { - A_fx[j] = extract_l( A_fx32[j] ); + A_fx[j] = extract_l( A_fx32[j] ); /* Q12 */ + move16(); } E_LPC_a_lsp_conversion( A_fx, lsptmp_fx, lsp_new_fx, M ); Residu3_fx( A_fx, buf_fx + L_LP - L_FRAME, res_fx, L_FRAME, 0 ); @@ -645,7 +649,7 @@ void stereo_tcx_core_enc( IF( EQ_16( st->L_frame, L_FRAME ) ) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); + Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); /* Q15 */ } /* Set 16k LSP flag for CNG buffer */ @@ -674,25 +678,25 @@ void stereo_tcx_core_enc( total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); - IF( NE_16( param_core[1 + NOISE_FILL_RANGES], 0 ) ) + IF( ( param_core[1 + NOISE_FILL_RANGES] != 0 ) ) { Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxEnc->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxEnc->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /* 15Q16 */ tcxltp_pitch_tmp = L_shr( tcxltp_pitch_tmp, 10 ); // Q6 - set16_fx( pitch_buf_fx, extract_l( tcxltp_pitch_tmp ), NB_SUBFR16k ); + set16_fx( pitch_buf_fx, extract_l( tcxltp_pitch_tmp ), NB_SUBFR16k ); /* Q6 */ } ELSE { - set16_fx( pitch_buf_fx, L_SUBFR * ONE_IN_Q6, NB_SUBFR16k ); + set16_fx( pitch_buf_fx, L_SUBFR * ONE_IN_Q6, NB_SUBFR16k ); /* Q6 */ } /* Memory scaling to keep everything in common q */ Word16 curr_q_syn = sub( shl( Q_new, 1 ), 1 ); - Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); - Scale_sig( st->hLPDmem->mem_syn, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); - Scale_sig( st->hLPDmem->mem_syn2, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); - st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( s_min( Q_new, st->hLPDmem->q_mem_syn ), Q_new ) ); + Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); /* s_min( curr_q_syn, st->hLPDmem->q_mem_syn ) */ + Scale_sig( st->hLPDmem->mem_syn, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); /* s_min( curr_q_syn, st->hLPDmem->q_mem_syn ) */ + Scale_sig( st->hLPDmem->mem_syn2, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), curr_q_syn ) ); /* s_min( curr_q_syn, st->hLPDmem->q_mem_syn ) */ + st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( s_min( Q_new, st->hLPDmem->q_mem_syn ), Q_new ) ); /* s_min( Q_new, st->hLPDmem->q_mem_syn ) */ move16(); - Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); - Scale_sig( st->hLPDmem->mem_syn3, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); + Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); /* s_min( curr_q_syn, st->hLPDmem->q_mem_syn ) */ + Scale_sig( st->hLPDmem->mem_syn3, M, sub( s_min( curr_q_syn, st->hLPDmem->q_mem_syn ), st->hLPDmem->q_mem_syn ) ); /* s_min( curr_q_syn, st->hLPDmem->q_mem_syn ) */ st->hLPDmem->q_mem_syn = s_min( curr_q_syn, st->hLPDmem->q_mem_syn ); move16(); st->hLPDmem->q_lpd_syn = Q_new; @@ -701,7 +705,7 @@ void stereo_tcx_core_enc( { FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) { - Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); + Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( Q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); /* Q_exc */ st->hTdCngEnc->cng_Qexc_buf[ii] = Q_exc; move16(); } @@ -710,6 +714,7 @@ void stereo_tcx_core_enc( IF( st->tcxonly == 0 ) { st->wspeech_enc[st->L_frame - 1] = shl( st->wspeech_enc[st->L_frame - 1], -st->Q_syn ); + move16(); } pop_wmops(); @@ -734,10 +739,10 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 *voicing_fr, /*Q15 i : fractional voicing values */ Word32 currFlatness, /*Q21 i : flatness */ Word16 lsp_mid[M], /*Q15 i : LSPs at the middle of the frame */ - Word16 stab_fac, /* i : LP filter stability */ + Word16 stab_fac, /* i : LP filter stability Q15*/ Word32 *res_cod_SNR_M, Word16 *res_cod_SNR_M_e, - const Word16 flag_16k_smc /* i : flag to compute parameters with 16kHz core */ + const Word16 flag_16k_smc /* i : flag to compute parameters with 16kHz core Q0*/ ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -799,7 +804,7 @@ Word16 ivas_acelp_tcx20_switching_fx( L_frame_tmp = L_frame; move16(); - x_fx = hTcxEnc->spectrum_long_fx; + x_fx = hTcxEnc->spectrum_long_fx; /* Q15 */ move32(); e_x = 31 - 15; move16(); @@ -808,16 +813,16 @@ Word16 ivas_acelp_tcx20_switching_fx( /* Check minimum pitch for quantization */ FOR( i = 0; i < 4; i++ ) { - pitch_fr_local[i] = pitch_fr[i]; + pitch_fr_local[i] = pitch_fr[i]; /* Q6 */ move16(); - voicing_fr_local[i] = voicing_fr[i]; + voicing_fr_local[i] = voicing_fr[i]; /* Q15 */ move16(); } E_LPC_f_lsp_a_conversion( lsp_mid, A_q_tcx_fx, M ); Q_A_q_tcx = sub( 14, norm_s( A_q_tcx_fx[0] ) ); scale_A = sub( Q12, Q_A_q_tcx ); - Copy_Scale_sig( A_q_tcx_fx, A_q_tcx_fx, M + 1, scale_A ); + Copy_Scale_sig( A_q_tcx_fx, A_q_tcx_fx, M + 1, scale_A ); /* Q12 */ /*--------------------------------------------------------------* * Estimate TCX SNR @@ -826,7 +831,7 @@ Word16 ivas_acelp_tcx20_switching_fx( target = L_add( 0x11A5D28, 0 ); /* 0x11A5D28 -> 850.f * log2(10)/10 (Q16) */ IF( flag_16k_smc ) { - tcx_offset = st->hTcxCfg->tcx_offset; + tcx_offset = st->hTcxCfg->tcx_offset; /* Q0 */ move16(); IF( st->last_core == ACELP_CORE ) @@ -890,9 +895,9 @@ Word16 ivas_acelp_tcx20_switching_fx( } } - Copy( inp_fx + sub( tcx_offset, shr( overlap, 1 ) ), xn_buf_fx, add( L_frame, overlap ) ); + Copy( inp_fx + sub( tcx_offset, shr( overlap, 1 ) ), xn_buf_fx, add( L_frame, overlap ) ); /* q_inp */ - L_frame_4 = shr( L_frame, 2 ); + L_frame_4 = shr( L_frame, 2 ); /* q0 */ IF( st->last_core == ACELP_CORE ) { test(); @@ -906,21 +911,21 @@ Word16 ivas_acelp_tcx20_switching_fx( { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = mult( xn_buf_fx[i], window_fx[i] ); + xn_buf_fx[i] = mult( xn_buf_fx[i], window_fx[i] ); /* q_inp */ move16(); } } FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[L_frame + i] = mult( xn_buf_fx[L_frame + i], window_fx[overlap - 1 - i] ); + xn_buf_fx[L_frame + i] = mult( xn_buf_fx[L_frame + i], window_fx[overlap - 1 - i] ); /* q_inp */ move16(); } e_x = sub( 16, q_inp ); /*exponent for xn_buf_fx*/ move16(); TCX_MDCT( xn_buf_fx, x_fx, &e_x, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); scale_A = getScaleFactor32( x_fx, L_frame ); - Copy_Scale_sig32( x_fx, x_fx, L_frame, scale_A ); + Copy_Scale_sig32( x_fx, x_fx, L_frame, scale_A ); /* Q31-e_x+scale_A */ e_x = sub( e_x, scale_A ); tmp16 = mult_r( shl( L_frame, 5 ), 29309 /*16*0.0559017 Q15*/ ); /* L_frame / sqrt(2*NORM_MDCT_FACTOR); Q9 */ @@ -941,7 +946,7 @@ Word16 ivas_acelp_tcx20_switching_fx( { com_gainlpc_e = s_max( com_gainlpc_e, gainlpc_e[i] ); } - Copy_Scale_sig32( x_fx, x_fx, L_frame, -com_gainlpc_e ); + Copy_Scale_sig32( x_fx, x_fx, L_frame, -com_gainlpc_e ); /* Q31-e_x-com_gainlpc_e */ e_x = add( e_x, com_gainlpc_e ); mdct_shaping( x_fx, L_frame, gainlpc_fx, gainlpc_e ); @@ -972,17 +977,17 @@ Word16 ivas_acelp_tcx20_switching_fx( /* calc quadruple energy */ ener = L_deposit_l( 1 ); - tmp16 = extract_h( L_shl( x_fx[0], s ) ); - ener = L_mac( ener, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( x_fx[0], s ) ); /* Q15-e_x+s */ + ener = L_mac( ener, tmp16, tmp16 ); /* 2*(Q15-e_x+s)+1 */ - tmp16 = extract_h( L_shl( x_fx[1], s ) ); - ener = L_mac( ener, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( x_fx[1], s ) ); /* Q15-e_x+s */ + ener = L_mac( ener, tmp16, tmp16 ); /* 2*(Q15-e_x+s)+1 */ - tmp16 = extract_h( L_shl( x_fx[2], s ) ); - ener = L_mac( ener, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( x_fx[2], s ) ); /* Q15-e_x+s */ + ener = L_mac( ener, tmp16, tmp16 ); /* 2*(Q15-e_x+s)+1 */ - tmp16 = extract_h( L_shl( x_fx[3], s ) ); - ener = L_mac( ener, tmp16, tmp16 ); + tmp16 = extract_h( L_shl( x_fx[3], s ) ); /* Q15-e_x+s */ + ener = L_mac( ener, tmp16, tmp16 ); /* 2*(Q15-e_x+s)+1 */ s = shl( sub( e_x, s ), 1 ); @@ -998,7 +1003,7 @@ Word16 ivas_acelp_tcx20_switching_fx( FOR( iter = 0; iter < 10; iter++ ) { - fac = L_shr( fac, 1 ); + fac = L_shr( fac, 1 ); /* q0 */ offset = L_sub( offset, fac ); ener = L_deposit_l( 0 ); @@ -1006,33 +1011,33 @@ Word16 ivas_acelp_tcx20_switching_fx( { tmp32 = L_sub( en[i], offset ); - IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 1], offset ); - IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 2], offset ); - IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 3], offset ); - IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } - IF( GT_32( ener, target ) ) + if ( GT_32( ener, target ) ) { offset = L_add( offset, fac ); BREAK; @@ -1086,7 +1091,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word16 temp_e, e_num, e_den, temp_ene_e; temp_ene_e = ener_e; move16(); - tmp32 = Sqrt32( ener, &temp_ene_e ); + tmp32 = Sqrt32( ener, &temp_ene_e ); /* Q31-temp_ene_e */ /*Approximate SNR of TCX*/ set32_fx( x_fx, tmp32, L_frame ); /* ener_e */ mdct_noiseShaping_ivas_fx( x_fx, &temp_ene_e, L_frame, gainlpc_noinv, gainlpc_noinv_e ); @@ -1113,10 +1118,10 @@ Word16 ivas_acelp_tcx20_switching_fx( FOR( i = bands[iter]; i < bands[iter + 1]; i++ ) { - nrg_s = BASOP_Util_Add_Mant32Exp( nrg_s, e_num, Mpy_32_32( y_fx[i], y_fx[i] ), shl( e_x, 1 ), &e_num ); - nrg_n = BASOP_Util_Add_Mant32Exp( nrg_n, e_den, Mpy_32_32( x_fx[i], x_fx[i] ), shl( temp_ene_e, 1 ), &e_den ); + nrg_s = BASOP_Util_Add_Mant32Exp( nrg_s, e_num, Mpy_32_32( y_fx[i], y_fx[i] ), shl( e_x, 1 ), &e_num ); /* Q31-e_num */ + nrg_n = BASOP_Util_Add_Mant32Exp( nrg_n, e_den, Mpy_32_32( x_fx[i], x_fx[i] ), shl( temp_ene_e, 1 ), &e_den ); /* Q31-e_den */ } - res_cod_SNR_M[iter] = BASOP_Util_Divide3232_Scale_cadence( nrg_s, nrg_n, &temp_e ); + res_cod_SNR_M[iter] = BASOP_Util_Divide3232_Scale_cadence( nrg_s, nrg_n, &temp_e ); /* Q31-res_cod_SNR_M_e[iter] */ move32(); res_cod_SNR_M_e[iter] = add( temp_e, sub( e_num, e_den ) ); move16(); @@ -1126,7 +1131,7 @@ Word16 ivas_acelp_tcx20_switching_fx( pt_ener_sfr = ener_sfr; tcx_snr = L_deposit_l( 0 ); - L_loop = L_frame; + L_loop = L_frame; /* Q0 */ move16(); if ( flag_16k_smc ) { @@ -1135,16 +1140,16 @@ Word16 ivas_acelp_tcx20_switching_fx( } Word16 temp32_e = 0; move16(); - Word32 temp_energy = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( ener_e ), 25 ) ); - temp_energy = L_add( temp_energy, 201326592 /* 6 in Q25*/ ); - temp_energy = L_shr( temp_energy, 9 ); /*temp_energy is log(( ener * L_SUBFR ))*/ + Word32 temp_energy = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( ener_e ), 25 ) ); /* Q25 */ + temp_energy = L_add( temp_energy, 201326592 /* 6 in Q25*/ ); /* Q25 */ + temp_energy = L_shr( temp_energy, 9 ); /*temp_energy is log(( ener * L_SUBFR ))*/ FOR( i = 0; i < L_loop; i += L_SUBFR ) { tmp32 = L_deposit_l( 0 ); FOR( j = 0; j < L_SUBFR; j++ ) { - tmp32 = BASOP_Util_Add_Mant32Exp( tmp32, temp32_e, L_mult0( wsp[i + j], wsp[i + j] ), sub( 31, add( q_inp, q_inp ) ), &temp32_e ); + tmp32 = BASOP_Util_Add_Mant32Exp( tmp32, temp32_e, L_mult0( wsp[i + j], wsp[i + j] ), sub( 31, add( q_inp, q_inp ) ), &temp32_e ); /* Q31-temp32_e */ } IF( tmp32 == 0 ) { @@ -1159,17 +1164,17 @@ Word16 ivas_acelp_tcx20_switching_fx( } ELSE { - tmp32 = L_add( BASOP_Util_Log2( tmp32 ), L_shl( L_deposit_l( temp32_e ), 25 ) ); - *pt_ener_sfr = tmp32; + tmp32 = L_add( BASOP_Util_Log2( tmp32 ), L_shl( L_deposit_l( temp32_e ), 25 ) ); /* Q25 */ + *pt_ener_sfr = tmp32; /* Q25 */ move32(); tmp32 = L_shr( tmp32, 9 ); /* 15Q16 */ } tcx_snr = L_sub( L_add( tcx_snr, tmp32 ), temp_energy ); /*15Q16*/ pt_ener_sfr++; } - tmp16 = BASOP_Util_Divide1616_Scale( L_SUBFR, L_loop, &temp32_e ); - tmp16 = shl( tmp16, temp32_e ); - tcx_snr = Mpy_32_16_1( tcx_snr, tmp16 ); + tmp16 = BASOP_Util_Divide1616_Scale( L_SUBFR, L_loop, &temp32_e ); /* Q15-temp32_e */ + tmp16 = shl( tmp16, temp32_e ); /* Q15 */ + tcx_snr = Mpy_32_16_1( tcx_snr, tmp16 ); /* Q16 */ tcx_snr = L_shl( Mpy_32_16_1( tcx_snr, 0x6054 /* 0x6054 -> 10/log2(10) (2Q13) */ ), 2 ); /* Q16*/ /*--------------------------------------------------------------* @@ -1213,7 +1218,7 @@ Word16 ivas_acelp_tcx20_switching_fx( T0 = shr( add( pitch_fr_local[i2], ( 1 << 5 ) ), 6 ); } - gain = get_gain2( wsp + i, wsp + sub( i, T0 ), L_SUBFR ); + gain = get_gain2( wsp + i, wsp + sub( i, T0 ), L_SUBFR ); /*Q16*/ noise = L_deposit_l( 1 ); noise_e = 0; diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 2daa9ed5035a5747a51d0cdd486d20fa0a1d7527..c959ef758f7f2b8e07fc3e98e8e4e5a8fa1d5188 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -51,17 +51,17 @@ void tdm_low_rate_enc( Encoder_State *st, /* i/o: State structure */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + Word16 *synth, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ // Q6 - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 attack_flag, /* i : GSC attack flag */ - const Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : long-term noise energy */ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + const Word16 attack_flag, /* i : GSC attack flag Q0*/ + const Word16 *lsf_new, /* i : current frame ISF vector Qx2.56*/ + Word16 *tmp_noise, /* o : long-term noise energy Q11*/ Word16 Q_new ) { const Word16 *p_Aq; @@ -88,7 +88,7 @@ void tdm_low_rate_enc( hLPDmem->tilt_code = 0; move16(); set16_fx( dct_epit_fx, 0, L_FRAME ); - set16_fx( pitch_buf, L_SUBFR_Q6, NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR_Q6, NB_SUBFR ); /* Q6 */ last_pit_bin = L_FRAME / 2; move16(); @@ -103,7 +103,7 @@ void tdm_low_rate_enc( *--------------------------------------------------------------------------------------*/ /* Find the current total number of bits used */ - tmp_nb_bits_tot = st->hBstr->nb_bits_tot; + tmp_nb_bits_tot = st->hBstr->nb_bits_tot; /* Q0 */ move16(); if ( st->extl_brate > 0 ) @@ -152,17 +152,17 @@ void tdm_low_rate_enc( * Synthesis *--------------------------------------------------------------------------------------*/ - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { - E_UTIL_synthesis( 0, p_Aq, &exc_wo_nf_fx[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1, M ); + E_UTIL_synthesis( 0, p_Aq, &exc_wo_nf_fx[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1, M ); /* Q_new */ p_Aq += ( M + 1 ); } /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc_wo_nf_fx, exc_fx, L_FRAME ); + Copy( exc_wo_nf_fx, exc_fx, L_FRAME ); /* Q_new */ return; } @@ -250,9 +250,9 @@ void encod_gen_2sbfr( coder_type = GENERIC; move16(); - p_Aw = Aw; - p_Aq = Aq; - pt_pitch = pitch_buf; + p_Aw = Aw; /* e(norm_s(Aw[0]+1) */ + p_Aq = Aq; /* e(norm_s(Aw[0]+1) */ + pt_pitch = pitch_buf; /*Q6*/ /*------------------------------------------------------------------* * ACELP subframe loop @@ -314,7 +314,7 @@ void encod_gen_2sbfr( lp_filt_exc_enc_ivas_fx( MODE1, coder_type, i_subfr, exc, h1, xn, y1, xn2, 2 * L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &st->acelp_cfg.ltf_mode ); #endif /* update long-term pitch gain for speech/music classifier */ - st->hSpMusClas->lowrate_pitchGain = add( mult( 29491, st->hSpMusClas->lowrate_pitchGain ), mult( 3277, gain_pit ) ); // Q14 + st->hSpMusClas->lowrate_pitchGain = add( mult( 29491, st->hSpMusClas->lowrate_pitchGain ), mult( 3277 /*Q15*/, gain_pit ) ); // Q14 move16(); /*-----------------------------------------------------------------* @@ -331,7 +331,7 @@ void encod_gen_2sbfr( IF( st->Opt_SC_VBR ) { - IF( EQ_16( st->hSC_VBR->last_ppp_mode, 1 ) ) + if ( EQ_16( st->hSC_VBR->last_ppp_mode, 1 ) ) { /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ st->clip_var_fx[1] = gain_pit; @@ -348,9 +348,9 @@ void encod_gen_2sbfr( #ifndef FIX_1320_LOWRATE_ACELP hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); #else - Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); /*Q0*/ - hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); /*Q0*/ + hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); /* Q15 */ #endif move16(); @@ -361,8 +361,8 @@ void encod_gen_2sbfr( #ifndef FIX_1320_LOWRATE_ACELP hLPDmem->mem_w0 = sub( sub( xn[2 * L_SUBFR - 1], mult_r( gain_pit, y1[2 * L_SUBFR - 1] ) ), mult_r( extract_h( gain_code ), y2[2 * L_SUBFR - 1] ) ); #else - Ltmp = L_mult0( gcode16, y2[2 * L_SUBFR - 1] ); /*Q10*/ - Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ + Ltmp = L_mult0( gcode16, y2[2 * L_SUBFR - 1] ); /*Q10*/ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ Ltmp = L_negate( Ltmp ); Ltmp = L_mac( Ltmp, xn[2 * L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ Ltmp = L_msu( Ltmp, y1[2 * L_SUBFR - 1], gain_pit /*Q14*/ ); /* Q_new-1+shift+14+1 */ @@ -388,11 +388,11 @@ void encod_gen_2sbfr( FOR( i = 0; i < 2 * L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - exc2[i + i_subfr] = shl_sat( mult( gain_pit, exc[i + i_subfr] ), 1 ); - Ltmp = L_mult( gcode16, code[i] ); /* Q10 */ - Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 */ - Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ + exc2[i + i_subfr] = shl_sat( mult( gain_pit, exc[i + i_subfr] ), 1 ); /* Q_new-1 */ + Ltmp = L_mult( gcode16, code[i] ); /* Q10 */ + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 */ + Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ exc[i + i_subfr] = round_fx_sat( Ltmp ); move16(); move16(); @@ -404,7 +404,7 @@ void encod_gen_2sbfr( prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); - voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; + voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; /* Q15 */ move16(); /*-----------------------------------------------------------------* @@ -428,8 +428,8 @@ void encod_gen_2sbfr( /* SC-VBR */ IF( st->Opt_SC_VBR ) { - st->hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; - st->hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + st->hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */ + st->hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); move16(); } diff --git a/lib_enc/lead_indexing_fx.c b/lib_enc/lead_indexing_fx.c index ff29330140ca4071d8d975ac14ce545a57050c97..70e0c4796ac2a53ea93ea8b1e7368999f4726e5c 100644 --- a/lib_enc/lead_indexing_fx.c +++ b/lib_enc/lead_indexing_fx.c @@ -22,8 +22,8 @@ static Word16 fcb_encode_pos_fx( const Word16 pos_vector[], const Word16 pulse_n *-------------------------------------------------------------------*/ void re8_compute_base_index_fx( const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ - const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ + const Word16 ka, /* i : Identifier of the absolute leader related to x Q0*/ + UWord16 *I /* o : index Q0*/ ) { Word16 i, j, k1, m; @@ -35,9 +35,9 @@ void re8_compute_base_index_fx( Word16 code_index; UWord16 offset; - a1 = vals_a[ka]; + a1 = vals_a[ka]; /* Q0 */ move16(); - a2 = vals_q[ka]; + a2 = vals_q[ka]; /* Q0 */ move16(); /* the sign process */ @@ -48,7 +48,7 @@ void re8_compute_base_index_fx( move16(); code_index = 0; move16(); - k1 = a2[0]; + k1 = a2[0]; /* Q0 */ move16(); test(); @@ -59,15 +59,15 @@ void re8_compute_base_index_fx( { IF( x[i] != 0 ) { - sign_8p = shl( sign_8p, 1 ); + sign_8p = shl( sign_8p, 1 ); /* Q0 */ setor_8p_temp[m] = i; move16(); - m = add( m, 1 ); + m++; } - IF( x[i] < 0 ) + if ( x[i] < 0 ) { - sign_8p = add( sign_8p, 1 ); + sign_8p = add( sign_8p, 1 ); /* Q0 */ } } @@ -78,33 +78,35 @@ void re8_compute_base_index_fx( move16(); *I = extract_l( L_add( offset, (Word32) code_index ) ); + move16(); } ELSE { FOR( i = 0; i < 8; i++ ) { - setor_8p[i] = abs_s( x[i] ); + setor_8p[i] = abs_s( x[i] ); /* Q0 */ + move16(); IF( x[i] != 0 ) { - sign_8p = shl( sign_8p, 1 ); - m = add( m, 1 ); + sign_8p = shl( sign_8p, 1 ); /* Q0 */ + m++; } - IF( x[i] < 0 ) + if ( x[i] < 0 ) { - sign_8p = add( sign_8p, 1 ); + sign_8p = add( sign_8p, 1 ); /* Q0 */ } } - IF( NE_16( k1, m ) ) + if ( NE_16( k1, m ) ) { - sign_8p = shr( sign_8p, 1 ); + sign_8p = shr( sign_8p, 1 ); /* Q0 */ } /* code level by level */ - code_level = sub( a2[1], 1 ); + code_level = sub( a2[1], 1 ); /* Q0 */ code_area = 8; move16(); @@ -119,15 +121,15 @@ void re8_compute_base_index_fx( { IF( NE_16( setor_8p[i], a1[j] ) ) { - setor_8p_temp[m] = i; + setor_8p_temp[m] = i; /* Q0 */ move16(); - setor_8p[m] = setor_8p[i]; + setor_8p[m] = setor_8p[i]; /* Q0 */ move16(); - m = add( m, 1 ); + m++; } } - code_index = extract_l( L_mult0( code_index, select_table22[m][code_area] ) ); - code_index = add( code_index, fcb_encode_pos_fx( setor_8p_temp, code_area, m ) ); + code_index = extract_l( L_mult0( code_index, select_table22[m][code_area] ) ); /* Q0 */ + code_index = add( code_index, fcb_encode_pos_fx( setor_8p_temp, code_area, m ) ); /* Q0 */ code_area = m; move16(); } @@ -136,18 +138,19 @@ void re8_compute_base_index_fx( { FOR( i = 0; i < code_area; i++ ) { - IF( EQ_16( setor_8p[i], a1[1] ) ) + if ( EQ_16( setor_8p[i], a1[1] ) ) { - code_index = add( code_index, i ); + code_index = add( code_index, i ); /* Q0 */ } } } code_index = add( shl( code_index, k1 ), sign_8p ); - offset = Is[ka]; + offset = Is[ka]; /* Q0 */ move16(); - *I = extract_l( L_add( offset, (Word32) code_index ) ); + *I = extract_l( L_add( offset, (Word32) code_index ) ); /* Q0 */ + move16(); } } @@ -156,10 +159,10 @@ void re8_compute_base_index_fx( * * Base function to compute base index for RE8 *-------------------------------------------------------------------*/ -static Word16 fcb_encode_pos_fx( /* o : Code index */ - const Word16 pos_vector[], /* i : Position vectort */ - const Word16 pulse_num, /* i : Pulse number */ - const Word16 pos_num /* i : Position number */ +static Word16 fcb_encode_pos_fx( /* o : Code index Q0*/ + const Word16 pos_vector[], /* i : Position vectort Q0*/ + const Word16 pulse_num, /* i : Pulse number Q0*/ + const Word16 pos_num /* i : Position number Q0*/ ) { Word16 i, j; @@ -171,10 +174,10 @@ static Word16 fcb_encode_pos_fx( /* o : Code index temp = sub( pulse_num, 1 ); - select_table23 = select_table22[pos_num]; + select_table23 = select_table22[pos_num]; /* Q0 */ move16(); - code_index = sub( select_table23[pulse_num], select_table23[sub( pulse_num, pos_vector[0] )] ); + code_index = sub( select_table23[pulse_num], select_table23[( pulse_num - pos_vector[0] )] ); /* Q0 */ j = 1; move16(); @@ -184,12 +187,12 @@ static Word16 fcb_encode_pos_fx( /* o : Code index { temp1 = sub( pos_num, j ); - select_table23 = select_table22[temp1]; + select_table23 = select_table22[temp1]; /* Q0 */ move16(); - code_index = add( code_index, sub( select_table23[sub( temp, pos_vector[i] )], select_table23[sub( pulse_num, pos_vector[j] )] ) ); + code_index = add( code_index, sub( select_table23[( temp - pos_vector[i] )], select_table23[( pulse_num - pos_vector[j] )] ) ); /* Q0 */ - j = add( j, 1 ); + j++; } return code_index; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 9093ffc402e7a3b2d578b8b76fea99b922f798ac..09e3efc84967a3f1de9618ca78c4c1c079fd4534 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -157,6 +157,7 @@ ivas_error IVAS_ENC_Open( st_ivas->mc_mode = MC_MODE_NONE; st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->sba_analysis_order = 0; + move16(); return IVAS_ERR_OK; } @@ -223,6 +224,7 @@ ivas_error IVAS_ENC_Open_fx( st_ivas->mc_mode = MC_MODE_NONE; st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->sba_analysis_order = 0; + move16(); return IVAS_ERR_OK; } @@ -237,18 +239,19 @@ void IVAS_ENC_Close( ) { /* Free all memory */ - if ( phIvasEnc == NULL || *phIvasEnc == NULL ) + test(); + IF( phIvasEnc == NULL || *phIvasEnc == NULL ) { return; } - if ( ( *phIvasEnc )->isConfigured ) + IF( ( *phIvasEnc )->isConfigured ) { ivas_destroy_enc_fx( ( *phIvasEnc )->st_ivas ); } - else + ELSE { - if ( ( *phIvasEnc )->st_ivas->hEncoderConfig ) + IF( ( *phIvasEnc )->st_ivas->hEncoderConfig ) { free( ( *phIvasEnc )->st_ivas->hEncoderConfig ); ( *phIvasEnc )->st_ivas->hEncoderConfig = NULL; @@ -289,17 +292,20 @@ ivas_error IVAS_ENC_ConfigureForMono( error = IVAS_ERR_OK; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } hIvasEnc->st_ivas->hEncoderConfig->ivas_format = MONO_FORMAT; hIvasEnc->st_ivas->hEncoderConfig->is_binaural = (Word16) is_binaural; + move16(); + move16(); if ( downmixFromStereo ) { hIvasEnc->st_ivas->hEncoderConfig->stereo_dmx_evs = 1; + move16(); } hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -334,7 +340,7 @@ ivas_error IVAS_ENC_ConfigureForStereo( ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -342,8 +348,11 @@ ivas_error IVAS_ENC_ConfigureForStereo( st_ivas = hIvasEnc->st_ivas; hEncoderConfig = st_ivas->hEncoderConfig; hEncoderConfig->nchan_inp = 2; + move16(); hEncoderConfig->ivas_format = STEREO_FORMAT; + move16(); hEncoderConfig->is_binaural = (Word16) is_binaural; + move16(); #ifdef DEBUGGING switch ( stereoMode ) @@ -412,7 +421,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( return error; } - IF( GT_16( numObjects, MAX_NUM_OBJECTS ) ) + IF( GT_32( numObjects, MAX_NUM_OBJECTS ) ) { return IVAS_ERR_TOO_MANY_INPUTS; } @@ -469,22 +478,27 @@ ivas_error IVAS_ENC_ConfigureForObjects( Encoder_Struct *st_ivas; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } - if ( numObjects > MAX_NUM_OBJECTS ) + IF( GT_32( numObjects, MAX_NUM_OBJECTS ) ) { return IVAS_ERR_TOO_MANY_INPUTS; } st_ivas = hIvasEnc->st_ivas; st_ivas->hEncoderConfig->ivas_format = ISM_FORMAT; + move16(); st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); st_ivas->hEncoderConfig->nchan_inp = numObjects; + move16(); st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); st_ivas->hEncoderConfig->ism_extended_metadata_flag = ism_extended_metadata; + move16(); hIvasEnc->extMetadataApi = ( ism_extended_metadata == 1 ); hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -510,17 +524,19 @@ ivas_error IVAS_ENC_FeedObjectMetadata( error = IVAS_ERR_OK; - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } - if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != ISM_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != SBA_ISM_FORMAT ) + test(); + test(); + IF( NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) && NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { return IVAS_ERR_METADATA_NOT_EXPECTED; } - if ( ismIndex > hIvasEnc->st_ivas->hEncoderConfig->nchan_inp ) + IF( GT_32( ismIndex, hIvasEnc->st_ivas->hEncoderConfig->nchan_inp ) ) { return IVAS_ERR_INVALID_INDEX; } @@ -531,7 +547,7 @@ ivas_error IVAS_ENC_FeedObjectMetadata( Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); - if ( error != IVAS_ERR_OK ) + IF( error != IVAS_ERR_OK ) { return error; } @@ -563,7 +579,7 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -574,12 +590,17 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; + move16(); + move16(); + move16(); /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + move16(); hEncoderConfig->Opt_PCA_ON = (Word16) Opt_PCA_ON; + move16(); hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -614,12 +635,17 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; + move16(); + move16(); + move16(); /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + move16(); hEncoderConfig->Opt_PCA_ON = (Word16) Opt_PCA_ON; + move16(); hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -790,7 +816,7 @@ ivas_error IVAS_ENC_ConfigureForMultichannel( ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -798,31 +824,34 @@ ivas_error IVAS_ENC_ConfigureForMultichannel( hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; hEncoderConfig->ivas_format = MC_FORMAT; + move16(); hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; /*just for initialization*/ + move16(); - switch ( mcLayout ) + SWITCH( mcLayout ) { case IVAS_ENC_MC_5_1: hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1; - break; + BREAK; case IVAS_ENC_MC_7_1: hEncoderConfig->mc_input_setup = MC_LS_SETUP_7_1; - break; + BREAK; case IVAS_ENC_MC_5_1_2: hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1_2; - break; + BREAK; case IVAS_ENC_MC_5_1_4: hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1_4; - break; + BREAK; case IVAS_ENC_MC_7_1_4: hEncoderConfig->mc_input_setup = MC_LS_SETUP_7_1_4; - break; + BREAK; default: return IVAS_ERR_INVALID_MC_LAYOUT; - break; + BREAK; } hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels_fx( hEncoderConfig->mc_input_setup ); + move16(); hIvasEnc->maxBandwidthUser = max_bwidth_user; @@ -860,7 +889,7 @@ static ivas_error configureEncoder( * Bandwidth limitation *-----------------------------------------------------------------*/ - if ( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) + IF( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) { return error; } @@ -869,32 +898,39 @@ static ivas_error configureEncoder( * DTX/CNG *-----------------------------------------------------------------*/ - if ( dtxConfig.enabled ) + IF( dtxConfig.enabled ) { hEncoderConfig->Opt_DTX_ON = 1; + move16(); - if ( dtxConfig.variable_SID_rate ) + IF( dtxConfig.variable_SID_rate ) { hEncoderConfig->var_SID_rate_flag = 1; hEncoderConfig->interval_SID = 0; + move16(); + move16(); } - else + ELSE { hEncoderConfig->var_SID_rate_flag = 0; + move16(); - if ( dtxConfig.SID_interval >= 3 && dtxConfig.SID_interval <= 100 ) + test(); + IF( GE_16( dtxConfig.SID_interval, 3 ) && LE_16( dtxConfig.SID_interval, 100 ) ) { hEncoderConfig->interval_SID = dtxConfig.SID_interval; + move16(); } - else + ELSE { return IVAS_ERR_INVALID_DTX_UPDATE_RATE; } } } - else + ELSE { hEncoderConfig->Opt_DTX_ON = 0; + move16(); } /*-----------------------------------------------------------------* @@ -902,36 +938,42 @@ static ivas_error configureEncoder( *-----------------------------------------------------------------*/ hEncoderConfig->ivas_total_brate = initBitrate; + move32(); /* SC-VBR at 5.90 kbps */ - if ( hEncoderConfig->ivas_total_brate == ACELP_5k90 ) + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_5k90 ) ) { hEncoderConfig->ivas_total_brate = ACELP_7k20; hEncoderConfig->Opt_SC_VBR = 1; hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR; + move32(); + move16(); + move16(); - if ( hEncoderConfig->max_bwidth != NB ) + if ( ( hEncoderConfig->max_bwidth != NB ) ) { hEncoderConfig->max_bwidth = WB; + move16(); } } /* check if the entered bitrate is supported */ - if ( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) /* IVAS */ + test(); + IF( NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* IVAS */ { - if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) + IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { - if ( hEncoderConfig->Opt_SC_VBR ) + IF( hEncoderConfig->Opt_SC_VBR ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", ACELP_5k90 ); } - else + ELSE { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", hEncoderConfig->ivas_total_brate ); } } - if ( hEncoderConfig->ivas_format == STEREO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) { #ifdef DEBUGGING if ( hIvasEnc->cmd_stereo ) @@ -942,57 +984,64 @@ static ivas_error configureEncoder( hEncoderConfig->stereo_mode_cmdl = 1; #endif - if ( hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO ) + if ( GE_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); #ifdef DEBUGGING hEncoderConfig->stereo_mode_cmdl = 0; #endif } } - if ( ( hEncoderConfig->element_mode_init == IVAS_CPE_TD || hEncoderConfig->element_mode_init == IVAS_CPE_DFT ) && hEncoderConfig->ivas_total_brate > IVAS_48k ) + test(); + test(); + IF( ( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_TD ) || EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_DFT ) ) && GT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - if ( hEncoderConfig->element_mode_init == IVAS_CPE_MDCT && hEncoderConfig->ivas_total_brate < IVAS_48k ) + test(); + IF( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_MDCT ) && LT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - if ( hEncoderConfig->ivas_total_brate > IVAS_256k ) + IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } } - else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + IF( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } } - else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) { /* nothing */ } - else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) ) { /* adapt element_mode according to the bitrate */ - if ( hEncoderConfig->nchan_inp == 2 && hEncoderConfig->element_mode_init != IVAS_SCE ) + test(); + IF( EQ_16( hEncoderConfig->nchan_inp, 2 ) && NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) ) { - if ( hEncoderConfig->ivas_total_brate >= IVAS_48k ) + IF( GE_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } - else if ( hEncoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + ELSE IF( LT_32( hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } } } - else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); move32(); @@ -1000,51 +1049,59 @@ static ivas_error configureEncoder( cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); /*adapt element_mode according to the bit-rate*/ - if ( hEncoderConfig->element_mode_init != IVAS_SCE ) + IF( NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) ) { - if ( cpe_brate >= IVAS_48k ) + if ( GE_32( cpe_brate, IVAS_48k ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } } } - else if ( hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->ism_mode = ISM_MODE_NONE; + move16(); } } - else /* EVS mono */ + ELSE /* EVS mono */ { hEncoderConfig->ivas_format = MONO_FORMAT; + move16(); hEncoderConfig->element_mode_init = EVS_MONO; + move16(); - if ( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) + IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate ); } - if ( hEncoderConfig->stereo_dmx_evs == 1 ) + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { hEncoderConfig->nchan_inp = 2; + move16(); } } /*-----------------------------------------------------------------* * Input sampling frequency *-----------------------------------------------------------------*/ - - if ( inputFs != 8000 && inputFs != 16000 && inputFs != 32000 && inputFs != 48000 ) + test(); + test(); + test(); + IF( NE_32( inputFs, 8000 ) && NE_32( inputFs, 16000 ) && NE_32( inputFs, 32000 ) && NE_32( inputFs, 48000 ) ) { return IVAS_ERR_INVALID_SAMPLING_RATE; } hEncoderConfig->input_Fs = inputFs; + move32(); /*-----------------------------------------------------------------* * Channel-aware mode *-----------------------------------------------------------------*/ - if ( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + IF( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1054,25 +1111,31 @@ static ivas_error configureEncoder( *-----------------------------------------------------------------*/ st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */ + move16(); - if ( hEncoderConfig->ivas_format == MONO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - if ( hEncoderConfig->Opt_AMR_WB ) + IF( hEncoderConfig->Opt_AMR_WB ) { st_ivas->codec_mode = MODE1; + move16(); } - else + ELSE { st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate ); + move16(); } } - if ( hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1 ) + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_13k2 ) && EQ_16( hEncoderConfig->Opt_RF_ON, 1 ) ) { st_ivas->codec_mode = MODE2; + move16(); } st_ivas->last_codec_mode = st_ivas->codec_mode; + move16(); /*-----------------------------------------------------------------* * Sanity checks @@ -1080,21 +1143,31 @@ static ivas_error configureEncoder( assert( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" ); - if ( ( hEncoderConfig->ivas_format != MONO_FORMAT || hEncoderConfig->stereo_dmx_evs ) && hEncoderConfig->input_Fs == 8000 ) + test(); + test(); + IF( ( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) || hEncoderConfig->stereo_dmx_evs ) && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS." ); } - if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_format != MONO_FORMAT && - ( ( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ) > 2 ) || - hEncoderConfig->ivas_format == MC_FORMAT || hEncoderConfig->ivas_format == MASA_ISM_FORMAT || hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && + ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_16( ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || + EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) ) { return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); } - + test(); + test(); + test(); #ifdef NONBE_FIX_708_OSBA_BR_SWITCHING_CRASH - if ( hEncoderConfig->Opt_PCA_ON && !( ( hEncoderConfig->ivas_format == SBA_FORMAT || hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == SBA_FOA_ORDER ) ) + IF( hEncoderConfig->Opt_PCA_ON && !( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) && EQ_32( hEncoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( hEncoderConfig->sba_order, SBA_FOA_ORDER ) ) ) #else if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == SBA_FOA_ORDER ) ) #endif @@ -1102,12 +1175,15 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } - if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } - if ( hEncoderConfig->is_binaural && !( ( hEncoderConfig->ivas_format == MONO_FORMAT && hEncoderConfig->stereo_dmx_evs ) || hEncoderConfig->ivas_format == STEREO_FORMAT ) ) + test(); + test(); + test(); + IF( hEncoderConfig->is_binaural && !( ( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && hEncoderConfig->stereo_dmx_evs ) || EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) ) { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'" ); } @@ -1116,22 +1192,24 @@ static ivas_error configureEncoder( * Finalize initialization *-----------------------------------------------------------------*/ - if ( ( error = ivas_init_encoder( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_init_encoder( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( hEncoderConfig->ivas_format == MONO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */ } - else + ELSE { hIvasEnc->hCoreCoder = NULL; } hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + move16(); + move16(); hIvasEnc->isConfigured = true; @@ -1171,19 +1249,24 @@ static ivas_error configureEncoder_fx( IF( dtxConfig.enabled ) { hEncoderConfig->Opt_DTX_ON = 1; + move16(); IF( dtxConfig.variable_SID_rate ) { hEncoderConfig->var_SID_rate_flag = 1; hEncoderConfig->interval_SID = 0; + move16(); + move16(); } ELSE { hEncoderConfig->var_SID_rate_flag = 0; - + move16(); + test(); IF( GE_16( dtxConfig.SID_interval, 3 ) && LE_16( dtxConfig.SID_interval, 100 ) ) { hEncoderConfig->interval_SID = dtxConfig.SID_interval; + move16(); } ELSE { @@ -1194,6 +1277,7 @@ static ivas_error configureEncoder_fx( ELSE { hEncoderConfig->Opt_DTX_ON = 0; + move16(); } /*-----------------------------------------------------------------* @@ -1201,21 +1285,27 @@ static ivas_error configureEncoder_fx( *-----------------------------------------------------------------*/ hEncoderConfig->ivas_total_brate = initBitrate; + move16(); /* SC-VBR at 5.90 kbps */ - IF( hEncoderConfig->ivas_total_brate == ACELP_5k90 ) + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_5k90 ) ) { hEncoderConfig->ivas_total_brate = ACELP_7k20; hEncoderConfig->Opt_SC_VBR = 1; hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR; + move32(); + move16(); + move16(); - IF( NE_16( hEncoderConfig->max_bwidth, NB ) ) + IF( ( hEncoderConfig->max_bwidth != NB ) ) { hEncoderConfig->max_bwidth = WB; + move16(); } } /* check if the entered bitrate is supported */ + test(); IF( NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* IVAS */ { IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) @@ -1230,26 +1320,32 @@ static ivas_error configureEncoder_fx( } } - IF( hEncoderConfig->ivas_format == STEREO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) { { hEncoderConfig->element_mode_init = IVAS_CPE_DFT; - IF( hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO ) + move16(); + IF( GE_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } } + test(); + test(); IF( ( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_TD ) || EQ_32( hEncoderConfig->element_mode_init, IVAS_CPE_DFT ) ) && GT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_MDCT ) && LT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); @@ -1269,15 +1365,18 @@ static ivas_error configureEncoder_fx( ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) ) { /* adapt element_mode according to the bitrate */ + test(); IF( EQ_16( hEncoderConfig->nchan_inp, 2 ) && NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) ) { IF( GE_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } ELSE IF( LT_32( hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } } } @@ -1293,6 +1392,7 @@ static ivas_error configureEncoder_fx( IF( GE_32( cpe_brate, IVAS_48k ) ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } } } @@ -1305,6 +1405,7 @@ static ivas_error configureEncoder_fx( { hEncoderConfig->ivas_format = MONO_FORMAT; hEncoderConfig->element_mode_init = EVS_MONO; + move16(); IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) { @@ -1314,19 +1415,23 @@ static ivas_error configureEncoder_fx( IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { hEncoderConfig->nchan_inp = 2; + move16(); } } /*-----------------------------------------------------------------* * Input sampling frequency *-----------------------------------------------------------------*/ - + test(); + test(); + test(); IF( NE_32( inputFs, 8000 ) && NE_32( inputFs, 16000 ) && NE_32( inputFs, 32000 ) && NE_32( inputFs, 48000 ) ) { return IVAS_ERR_INVALID_SAMPLING_RATE; } hEncoderConfig->input_Fs = inputFs; + move32(); /*-----------------------------------------------------------------* * Channel-aware mode @@ -1342,25 +1447,31 @@ static ivas_error configureEncoder_fx( *-----------------------------------------------------------------*/ st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */ + move16(); IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { IF( hEncoderConfig->Opt_AMR_WB ) { st_ivas->codec_mode = MODE1; + move16(); } ELSE { st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate ); + move16(); } } - IF( hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1 ) + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_13k2 ) && EQ_16( hEncoderConfig->Opt_RF_ON, 1 ) ) { st_ivas->codec_mode = MODE2; + move16(); } st_ivas->last_codec_mode = st_ivas->codec_mode; + move16(); /*-----------------------------------------------------------------* * Sanity checks @@ -1368,11 +1479,19 @@ static ivas_error configureEncoder_fx( assert( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" ); + test(); + test(); IF( ( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) || hEncoderConfig->stereo_dmx_evs ) && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS." ); } + test(); + test(); + test(); + test(); + test(); + test(); IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) ) @@ -1380,7 +1499,9 @@ static ivas_error configureEncoder_fx( return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); } - + test(); + test(); + test(); IF( hEncoderConfig->Opt_PCA_ON && !( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && EQ_32( hEncoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( hEncoderConfig->sba_order, SBA_FOA_ORDER ) ) ) { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); @@ -1391,6 +1512,9 @@ static ivas_error configureEncoder_fx( return error; } + test(); + test(); + test(); IF( hEncoderConfig->is_binaural && !( ( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && hEncoderConfig->stereo_dmx_evs ) || EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) ) { return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'" ); @@ -1416,6 +1540,8 @@ static ivas_error configureEncoder_fx( hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + move16(); + move16(); hIvasEnc->isConfigured = true; @@ -1429,7 +1555,7 @@ static ivas_error configureEncoder_fx( ivas_error IVAS_ENC_GetDelay( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ - Word16 *delay /* o : encoder delay */ + Word16 *delay /* o : encoder delay Q0*/ ) { ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -1446,10 +1572,10 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - *delay = NS2SA_FX2( hEncoderConfig->input_Fs, get_delay_fx( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL ) ); + *delay = NS2SA_FX2( hEncoderConfig->input_Fs, get_delay_fx( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL ) ); /*Q0*/ move16(); - *delay = imult1616( *delay, hEncoderConfig->nchan_inp ); + *delay = imult1616( *delay, hEncoderConfig->nchan_inp ); /*Q0*/ move16(); return IVAS_ERR_OK; @@ -1478,17 +1604,19 @@ ivas_error IVAS_ENC_GetNumInChannels( Word16 *numInChannels /* o : total number of samples expected in the input buffer for current encoder configuration */ ) { - if ( hIvasEnc == NULL || numInChannels == NULL ) + test(); + IF( hIvasEnc == NULL || numInChannels == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } *numInChannels = hIvasEnc->st_ivas->hEncoderConfig->nchan_inp; + move16(); return IVAS_ERR_OK; } @@ -1528,10 +1656,10 @@ ivas_error IVAS_ENC_GetInputBufferSize( *---------------------------------------------------------------------*/ ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - Word16 *inputBuffer, /* i : PCM input, Q0 */ - Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ - UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ - UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ + Word16 *inputBuffer, /* i : PCM input, Q0 Q0*/ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() Q0*/ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME Q0*/ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value Q0*/ ) { Encoder_Struct *st_ivas; @@ -1768,7 +1896,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } /* write indices into bitstream buffer */ - IF( EQ_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) + IF( hEncoderConfig->element_mode_init == EVS_MONO ) { test(); IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && ( hCoreCoder->element_mode == EVS_MONO ) ) @@ -1806,7 +1934,7 @@ ivas_error IVAS_ENC_SetBandwidth( ivas_error error; /* Do additional checks for user-facing function */ - if ( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1830,7 +1958,7 @@ ivas_error IVAS_ENC_SetBitrate( ivas_error error; /* Do additional checks for user-facing function */ - if ( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1855,7 +1983,7 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( ivas_error error; /* Do additional checks for user-facing function */ - if ( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1956,6 +2084,7 @@ IVAS_ENC_DTX_CONFIG IVAS_ENC_GetDefaultDtxConfig( void ) IVAS_ENC_DTX_CONFIG defaultDtxConfig; defaultDtxConfig.enabled = false; defaultDtxConfig.SID_interval = 0; + move16(); defaultDtxConfig.variable_SID_rate = false; return defaultDtxConfig; @@ -2022,11 +2151,11 @@ static ivas_error printConfigInfo_enc( * Print bitrate *-----------------------------------------------------------------*/ - if ( st_ivas->hEncoderConfig->Opt_SC_VBR ) + IF( st_ivas->hEncoderConfig->Opt_SC_VBR ) { fprintf( stdout, "Average bitrate: %.2f kbps\n", (float) ACELP_5k90 / 1000 ); } - else + ELSE { fprintf( stdout, "Bitrate: %.2f kbps\n", (float) hEncoderConfig->ivas_total_brate / 1000 ); } @@ -2035,18 +2164,18 @@ static ivas_error printConfigInfo_enc( * Print IVAS format *-----------------------------------------------------------------*/ - if ( hEncoderConfig->ivas_format == MONO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - if ( hEncoderConfig->stereo_dmx_evs ) + IF( hEncoderConfig->stereo_dmx_evs ) { fprintf( stdout, "IVAS format: stereo downmix to bit-exact EVS mono\n" ); } - else + ELSE { fprintf( stdout, "IVAS format: bit-exact EVS mono\n" ); } } - else if ( hEncoderConfig->ivas_format == STEREO_FORMAT ) + ELSE IF( hEncoderConfig->ivas_format == STEREO_FORMAT ) { #ifdef DEBUGGING if ( hEncoderConfig->stereo_mode_cmdl == 1 ) @@ -2076,64 +2205,65 @@ static ivas_error printConfigInfo_enc( } #endif } - else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - if ( hEncoderConfig->ivas_total_brate <= ACELP_32k && hEncoderConfig->nchan_inp > 2 ) + test(); + IF( LE_32( hEncoderConfig->ivas_total_brate, ACELP_32k ) && GT_16( hEncoderConfig->nchan_inp, 2 ) ) { fprintf( stdout, "IVAS format: Param-ISM (%i streams)\n", hEncoderConfig->nchan_inp ); } - else + ELSE { fprintf( stdout, "IVAS format: ISM (%i streams)\n", hEncoderConfig->nchan_inp ); } } - else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) ) { fprintf( stdout, "IVAS format: Scene Based Audio, Ambisonic order %i %s ", hEncoderConfig->sba_order, hEncoderConfig->sba_planar ? "(Planar)" : "" ); - if ( hEncoderConfig->Opt_PCA_ON ) + IF( hEncoderConfig->Opt_PCA_ON ) { fprintf( stdout, "- PCA configured with signal adaptive decision " ); } fprintf( stdout, "\n" ); } - else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) ) { fprintf( stdout, "IVAS format: MASA format\n" ); } - else if ( hEncoderConfig->ivas_format == MC_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) ) { - if ( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) + IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) { fprintf( stdout, "IVAS mode: Multi-Channel 5.1 \n" ); } - else if ( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 ) + ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 ) { fprintf( stdout, "IVAS mode: Multi-Channel 7.1 \n" ); } - else if ( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 ) + ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 ) { fprintf( stdout, "IVAS mode: Multi-Channel 5.1+2 \n" ); } - else if ( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 ) + ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 ) { fprintf( stdout, "IVAS mode: Multi-Channel 5.1+4\n" ); } - else if ( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1_4 ) + ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1_4 ) { fprintf( stdout, "IVAS mode: Multi-Channel 7.1+4\n" ); } } - else if ( hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { fprintf( stdout, "IVAS format: combined ISM and SBA (%i ISM stream(s))\n", hEncoderConfig->nchan_ism ); } - else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { fprintf( stdout, "IVAS format: combined ISM and MASA (%i ISM stream(s))\n", hEncoderConfig->nchan_ism ); } - if ( hEncoderConfig->is_binaural ) + IF( hEncoderConfig->is_binaural ) { fprintf( stdout, "Optional indication: binaural audio\n" ); } @@ -2142,13 +2272,13 @@ static ivas_error printConfigInfo_enc( * Print CNG update interval, if DTX is activated *-----------------------------------------------------------------*/ - if ( hEncoderConfig->Opt_DTX_ON ) + IF( hEncoderConfig->Opt_DTX_ON ) { - if ( hEncoderConfig->var_SID_rate_flag ) + IF( hEncoderConfig->var_SID_rate_flag ) { fprintf( stdout, "DTX: ON, variable CNG update interval\n" ); } - else + ELSE { fprintf( stdout, "DTX: ON, CNG update interval = %d frames\n", hEncoderConfig->interval_SID ); } @@ -2158,54 +2288,57 @@ static ivas_error printConfigInfo_enc( * Print potential limitation of audio bandwidth *-----------------------------------------------------------------*/ - if ( ( error = bandwidthApiToInternal( hIvasEnc->newBandwidthApi, &newBandwidthApi ) ) != IVAS_ERR_OK ) + IF( ( error = bandwidthApiToInternal( hIvasEnc->newBandwidthApi, &newBandwidthApi ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hEncoderConfig->Opt_SC_VBR && !hEncoderConfig->Opt_DTX_ON ) + test(); + IF( st_ivas->hEncoderConfig->Opt_SC_VBR && !hEncoderConfig->Opt_DTX_ON ) { return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "\nError: SC-VBR 5900 bps not supported without DTX\n\n" ); } - if ( hEncoderConfig->ivas_format == MONO_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - if ( newBandwidthApi != hEncoderConfig->max_bwidth ) + IF( NE_16( newBandwidthApi, hEncoderConfig->max_bwidth ) ) { - if ( newBandwidthApi == FB ) + IF( EQ_16( newBandwidthApi, FB ) ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f ); - if ( hEncoderConfig->max_bwidth == WB ) + IF( EQ_16( hEncoderConfig->max_bwidth, WB ) ) { fprintf( stdout, "Switching to WB.\n" ); } - else + ELSE { fprintf( stdout, "Switching to SWB.\n" ); } } - else if ( newBandwidthApi == SWB ) + ELSE IF( EQ_16( newBandwidthApi, SWB ) ) { fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.\n", ACELP_9k60 / 1000.f ); } } /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ - if ( ( newBandwidthApi == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) + test(); + test(); + IF( ( ( newBandwidthApi == NB ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) ) { fprintf( stdout, "\nError: Unsupported mode NB %d bps, NB mode supports rates 5900-24400 bps\n\n", hEncoderConfig->ivas_total_brate ); return IVAS_ERR_INVALID_BITRATE; } } - else + ELSE { - if ( newBandwidthApi != hEncoderConfig->max_bwidth ) + IF( NE_16( newBandwidthApi, hEncoderConfig->max_bwidth ) ) { - if ( hEncoderConfig->ivas_format == ISM_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps for %i objects. Switching to SWB.\n", hEncoderConfig->nchan_ism * MIN_BRATE_FB_ISM / 1000.f, hEncoderConfig->nchan_ism ); } - else + ELSE { fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f ); } @@ -2216,9 +2349,9 @@ static ivas_error printConfigInfo_enc( * Print Channel-aware limitation *-----------------------------------------------------------------*/ - if ( channelAwareModeEnabled ) + IF( channelAwareModeEnabled ) { - if ( hEncoderConfig->Opt_RF_ON == 0 ) + IF( hEncoderConfig->Opt_RF_ON == 0 ) { fprintf( stdout, "\nChannel-aware mode is supported at 13.2 kbps 32/48 kHz only. Switching to normal mode.\n" ); } @@ -2247,65 +2380,76 @@ static ivas_error setBitrate( hEncoderConfig->ivas_total_brate = totalBitrate; hIvasEnc->switchingActive = true; + move32(); /* channel-aware mode is supported only at 13.20 kbps */ - if ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->ivas_total_brate != ACELP_13k20 ) + test(); + IF( hEncoderConfig->Opt_RF_ON && NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) ) { assert( 0 && "\nChannel-aware mode is supported only at 13.20 kbps\n" ); hEncoderConfig->Opt_RF_ON = 0; + move16(); } - if ( hEncoderConfig->ivas_total_brate == ACELP_5k90 ) + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_5k90 ) ) { st_ivas->hEncoderConfig->Opt_SC_VBR = 1; hEncoderConfig->ivas_total_brate = ACELP_7k20; + move16(); + move32(); } - else + ELSE { st_ivas->hEncoderConfig->Opt_SC_VBR = 0; + move16(); } /* check if the entered bitrate is supported */ - if ( hEncoderConfig->element_mode_init > EVS_MONO ) + IF( hEncoderConfig->element_mode_init > EVS_MONO ) { - if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) + IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS: %d", hEncoderConfig->ivas_total_brate ); } } - else + ELSE { - if ( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) + IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate ); } /* in case of 8kHz signal, limit the total bitrate to 24.40 kbps */ - if ( hEncoderConfig->input_Fs == 8000 && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) + test(); + IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) ) { hEncoderConfig->ivas_total_brate = ACELP_24k40; + move32(); } } - if ( hEncoderConfig->ivas_format == ISM_FORMAT ) + IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + IF( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } } st_ivas->codec_mode = MODE1; + move16(); - if ( hEncoderConfig->element_mode_init == EVS_MONO ) + IF( hEncoderConfig->element_mode_init == EVS_MONO ) { - if ( hEncoderConfig->Opt_AMR_WB ) + IF( hEncoderConfig->Opt_AMR_WB ) { st_ivas->codec_mode = MODE1; + move16(); } - else + ELSE { st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate ); + move16(); } } @@ -2332,16 +2476,22 @@ static ivas_error setChannelAwareConfig_fx( hEncoderConfig = st_ivas->hEncoderConfig; /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ + test(); + test(); + test(); IF( ( caConfig.channelAwareModeEnabled && NE_32( st_ivas->hEncoderConfig->ivas_total_brate, ACELP_13k20 ) ) || ( hEncoderConfig->Opt_RF_ON && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) ) { hEncoderConfig->Opt_RF_ON = 0; + move16(); hEncoderConfig->rf_fec_offset = 0; + move16(); return IVAS_ERR_OK; } IF( caConfig.channelAwareModeEnabled ) { hEncoderConfig->Opt_RF_ON = 1; + move16(); /* Convert FEC indicator from API type */ IF( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK ) @@ -2350,14 +2500,21 @@ static ivas_error setChannelAwareConfig_fx( } /* Set new values only if they differ from current values */ + test(); IF( ( NE_16( newFecIndicator, hEncoderConfig->rf_fec_indicator ) || NE_16( caConfig.fec_offset, hEncoderConfig->rf_fec_offset ) ) ) { hEncoderConfig->rf_fec_indicator = newFecIndicator; + move16(); /* Check if new FEC offset has a valid value */ + test(); + test(); + test(); + test(); IF( EQ_16( caConfig.fec_offset, 0 ) || EQ_16( caConfig.fec_offset, 2 ) || EQ_16( caConfig.fec_offset, 3 ) || EQ_16( caConfig.fec_offset, 5 ) || EQ_16( caConfig.fec_offset, 7 ) ) { hEncoderConfig->rf_fec_offset = caConfig.fec_offset; + move16(); } ELSE { @@ -2369,10 +2526,12 @@ static ivas_error setChannelAwareConfig_fx( /* Save a copy of FEC offset value - needed during encoding */ hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + move16(); } ELSE { hEncoderConfig->Opt_RF_ON = 0; + move16(); } return IVAS_ERR_OK; @@ -2410,13 +2569,14 @@ static ivas_error doCommonConfigureChecks( static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ) { - if ( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) + test(); + IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } /* Currently settings can be changed only after configuration step */ - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } @@ -2442,25 +2602,34 @@ static ivas_error sanitizeBandwidth_fx( max_bwidth_tmp = hIvasEnc->newBandwidthApi; /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ - IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && GT_16( max_bwidth_tmp, NB ) ) + test(); + test(); + test(); + IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && ( max_bwidth_tmp > NB ) ) { max_bwidth_tmp = NB; + move16(); } ELSE IF( EQ_32( hEncoderConfig->input_Fs, 16000 ) && GT_16( max_bwidth_tmp, WB ) ) { max_bwidth_tmp = WB; + move16(); } ELSE IF( EQ_32( hEncoderConfig->input_Fs, 32000 ) && GT_16( max_bwidth_tmp, SWB ) ) { max_bwidth_tmp = SWB; + move16(); } /* NB coding not supported in IVAS. Switching to WB. */ - IF( EQ_16( max_bwidth_tmp, NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + test(); + test(); + IF( ( max_bwidth_tmp == NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { IF( GE_32( hEncoderConfig->input_Fs, 16000 ) ) { max_bwidth_tmp = WB; + move16(); } ELSE { @@ -2510,16 +2679,23 @@ static ivas_error sanitizeBandwidth_fx( { iDiv_and_mod_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism, &quo, &rem, 0 ); } + + test(); + test(); + test(); + test(); IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) || ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( quo, MIN_BRATE_FB_ISM ) ) ) ) { max_bwidth_tmp = SWB; + move16(); } } IF( NE_16( hEncoderConfig->max_bwidth, max_bwidth_tmp ) ) { hEncoderConfig->max_bwidth = max_bwidth_tmp; + move16(); hIvasEnc->switchingActive = true; } @@ -2535,31 +2711,37 @@ static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ) { + test(); IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_128k ) && EQ_16( hEncoderConfig->nchan_inp, 1 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_384k ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + test(); IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); @@ -2568,10 +2750,12 @@ static ivas_error sanitizeBitrateISM_fx( IF( extMetadataApi ) { hEncoderConfig->ism_extended_metadata_flag = (Word16) GE_32( hEncoderConfig->ivas_total_brate, ISM_EXTENDED_METADATA_BRATE ); + move16(); } ELSE { hEncoderConfig->ism_extended_metadata_flag = 0; + move16(); } return IVAS_ERR_OK; @@ -2601,15 +2785,19 @@ static ivas_error setBandwidth_fx( hIvasEnc->newBandwidthApi = newBandwidth; /* NB coding not supported in IVAS. Switching to WB. */ - IF( newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) + test(); + test(); + IF( ( newBandwidth == NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { newBandwidth = WB; + move16(); } IF( hEncoderConfig->max_bwidth != newBandwidth ) { hEncoderConfig->max_bwidth = newBandwidth; hIvasEnc->switchingActive = true; + move16(); } return IVAS_ERR_OK; @@ -2785,33 +2973,56 @@ static void init_encoder_config( ) { hEncoderConfig->ivas_total_brate = ACELP_12k65; + move32(); hEncoderConfig->max_bwidth = SWB; + move16(); hEncoderConfig->input_Fs = 16000; + move32(); hEncoderConfig->nchan_inp = 1; + move16(); hEncoderConfig->element_mode_init = EVS_MONO; + move16(); hEncoderConfig->ivas_format = UNDEFINED_FORMAT; + move16(); hEncoderConfig->is_binaural = 0; + move16(); hEncoderConfig->Opt_SC_VBR = 0; + move16(); hEncoderConfig->last_Opt_SC_VBR = 0; + move16(); hEncoderConfig->Opt_AMR_WB = 0; + move16(); hEncoderConfig->Opt_DTX_ON = 0; + move16(); hEncoderConfig->Opt_RF_ON = 0; + move16(); hEncoderConfig->rf_fec_offset = 0; + move16(); hEncoderConfig->rf_fec_indicator = 1; + move16(); hEncoderConfig->interval_SID = FIXED_SID_RATE; + move16(); hEncoderConfig->var_SID_rate_flag = 1; + move16(); hEncoderConfig->mc_input_setup = MC_LS_SETUP_INVALID; + move16(); hEncoderConfig->stereo_dmx_evs = 0; + move16(); hEncoderConfig->nchan_ism = 0; + move16(); hEncoderConfig->sba_order = 0; + move16(); hEncoderConfig->sba_planar = 0; + move16(); hEncoderConfig->ism_extended_metadata_flag = 0; + move16(); #ifdef DEBUGGING hEncoderConfig->stereo_mode_cmdl = 0; hEncoderConfig->force = -1; hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; #endif hEncoderConfig->Opt_PCA_ON = 0; + move16(); return; } diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index ab6c39c23c4da9b2ca62da54e672eaf5dbc61607..8cf6be1cd0e6ca1385d5c7ec3588583ea115ac20 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -169,8 +169,8 @@ ivas_error IVAS_ENC_Open_fx( /*! r: error code */ ivas_error IVAS_ENC_ConfigureForMono( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -182,8 +182,8 @@ ivas_error IVAS_ENC_ConfigureForMono( /*! r: error code */ ivas_error IVAS_ENC_ConfigureForStereo( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -197,8 +197,8 @@ ivas_error IVAS_ENC_ConfigureForStereo( /*! r: error code */ ivas_error IVAS_ENC_ConfigureForObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -209,8 +209,8 @@ ivas_error IVAS_ENC_ConfigureForObjects( /*! r: encoder error code */ ivas_error IVAS_ENC_ConfigureForMASAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const UWord16 numObjects, /* i : number of objects to be encoded */ @@ -220,8 +220,8 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( /*! r: encoder error code */ ivas_error IVAS_ENC_ConfigureForSBAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const UWord16 numObjects, /* i : number of objects to be encoded */ @@ -233,8 +233,8 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( /*! r: error code */ ivas_error IVAS_ENC_ConfigureForAmbisonics( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -245,8 +245,8 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -257,8 +257,8 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( /*! r: error code */ ivas_error IVAS_ENC_ConfigureForMasa( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -268,8 +268,8 @@ ivas_error IVAS_ENC_ConfigureForMasa( /*! r: encoder error code */ ivas_error IVAS_ENC_ConfigureForMultichannel( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 inputFs, /* i : input sampling frequency */ - const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ @@ -285,7 +285,7 @@ void IVAS_ENC_Close( /*! r: error code */ ivas_error IVAS_ENC_FeedObjectMetadata( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const UWord16 ismIndex, /* i : object index */ + const UWord16 ismIndex, /* i : object index */ const IVAS_ISM_METADATA metadata /* i : object metadata handle for current frame */ ); @@ -307,8 +307,8 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToCompact( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - Word16 *inputBuffer, /* i : PCM input */ - const Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + Word16 *inputBuffer, /* i : PCM input */ + const Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ UWord8 *outputBitStream, /* o : pointer to compact output bitstream. The array must already be allocated. */ UWord16 *numOutBits /* o : number of bits written to output bitstream */ ); @@ -324,7 +324,7 @@ ivas_error IVAS_ENC_SetBandwidth( /*! r: error code */ ivas_error IVAS_ENC_SetBitrate( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const Word32 totalBitrate /* i : requested bitrate of the output bitstream */ + const Word32 totalBitrate /* i : requested bitrate of the output bitstream */ ); /*! r: error code */ @@ -355,13 +355,13 @@ ivas_error IVAS_ENC_GetDelay( /*! r: encoder error code */ ivas_error IVAS_ENC_GetNumInChannels( const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - Word16 *numInChannels /* o : total number of samples expected in the input buffer for current encoder configuration */ + Word16 *numInChannels /* o : total number of samples expected in the input buffer for current encoder configuration */ ); /*! r: encoder error code */ ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ + Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ ); /* Utility functions */ diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index 5fe465f2946e037b8f2b92f9f2741c2c0432c308..af57edd3bd4629ef64c1c16842bc91d572fd67c7 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -18,11 +18,11 @@ void ivas_long_enr_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q8 */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag, /* i : sp/mus LPN flag */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover Q0*/ + Word16 high_lpn_flag, /* i : sp/mus LPN flag Q0*/ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ - const Word16 n_chan, /* i : number of channels */ - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover LR channels */ + const Word16 n_chan, /* i : number of channels Q0*/ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover LR channels Q0*/ const Word16 Etot_LR[] /* i : total channel energy LR channels Q8 */ ) @@ -42,13 +42,13 @@ void ivas_long_enr_fx( { FOR( n = 0; n < n_chan; n++ ) { - hFrontVad[n]->lp_noise_fx = hFrontVad[n]->hNoiseEst->totalNoise_fx; + hFrontVad[n]->lp_noise_fx = hFrontVad[n]->hNoiseEst->totalNoise_fx; /* Q8 */ move16(); - tmp = add( hFrontVad[n]->lp_noise_fx, 2560 ); + tmp = add( hFrontVad[n]->lp_noise_fx, 2560 ); /* Q8 */ - IF( LT_16( hFrontVad[n]->lp_speech_fx, tmp ) ) + if ( LT_16( hFrontVad[n]->lp_speech_fx, tmp ) ) { - hFrontVad[n]->lp_speech_fx = tmp; + hFrontVad[n]->lp_speech_fx = tmp; /* Q8 */ move16(); } } @@ -59,34 +59,34 @@ void ivas_long_enr_fx( IF( LT_16( hFrontVad[0]->ini_frame, 150 ) ) { - smooth_prev = 31130; - smooth_curr = 1638; + smooth_prev = 31130; /* 0.95f in Q15 */ + smooth_curr = 1638; /* 0.05f in Q15 */ move16(); move16(); } ELSE { - smooth_prev = 32113; - smooth_curr = 655; + smooth_prev = 32113; /* 0.98f in Q15 */ + smooth_curr = 655; /* 0.02f in Q15 */ move16(); move16(); } FOR( n = 0; n < n_chan; n++ ) { - hFrontVad[n]->lp_noise_fx = add( mult_r( smooth_prev, hFrontVad[n]->lp_noise_fx ), mult_r( smooth_curr, hFrontVad[n]->hNoiseEst->totalNoise_fx ) ); + hFrontVad[n]->lp_noise_fx = add( mult_r( smooth_prev, hFrontVad[n]->lp_noise_fx ), mult_r( smooth_curr, hFrontVad[n]->hNoiseEst->totalNoise_fx ) ); /* Q8 */ move16(); test(); IF( localVAD_HE_SAD_LR[n] && !high_lpn_flag ) { - IF( LT_16( sub( hFrontVad[n]->lp_speech_fx, Etot_LR[n] ), 2560 ) ) + IF( LT_16( sub( hFrontVad[n]->lp_speech_fx, Etot_LR[n] ), 2560 /*10.0f in Q8*/ ) ) { - hFrontVad[n]->lp_speech_fx = add( mult_r( 32113, hFrontVad[n]->lp_speech_fx ), mult_r( 655, Etot_LR[n] ) ); + hFrontVad[n]->lp_speech_fx = add( mult_r( 32113 /*0.98f in Q15*/, hFrontVad[n]->lp_speech_fx ), mult_r( 655 /*0.02f in Q15*/, Etot_LR[n] ) ); /* Q8 */ move16(); } ELSE { - hFrontVad[n]->lp_speech_fx = sub( hFrontVad[n]->lp_speech_fx, 13 ); + hFrontVad[n]->lp_speech_fx = sub( hFrontVad[n]->lp_speech_fx, 13 /*0.05f in Q8*/ ); /* Q8 */ move16(); } } @@ -94,7 +94,7 @@ void ivas_long_enr_fx( } FOR( n = 0; n < n_chan; n++ ) { - hFrontVad[n]->hNoiseEst->Etot_last_fx = Etot_LR[n]; + hFrontVad[n]->hNoiseEst->Etot_last_fx = Etot_LR[n]; /* Q8 */ move16(); } } @@ -102,7 +102,7 @@ void ivas_long_enr_fx( { IF( LT_16( st_fx->ini_frame, 4 ) ) { - st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; + st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ move16(); tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); @@ -115,8 +115,8 @@ void ivas_long_enr_fx( } else { st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; } */ - alpha = 655; - move16(); /* 0.02 Q15 */ + alpha = 655; /* 0.02 Q15 */ + move16(); if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ { alpha = 1638; @@ -141,7 +141,7 @@ void ivas_long_enr_fx( } } /* Update */ - st_fx->hNoiseEst->Etot_last_fx = Etot; + st_fx->hNoiseEst->Etot_last_fx = Etot; /* Q8 */ move16(); } @@ -154,9 +154,9 @@ void ivas_long_enr_fx( void long_enr_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag /* i : sp/mus LPN flag */ + const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q8*/ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover Q0*/ + Word16 high_lpn_flag /* i : sp/mus LPN flag Q0*/ ) { Word16 tmp; @@ -171,10 +171,11 @@ void long_enr_fx( { IF( LT_16( st_fx->ini_frame, 4 ) ) { - st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; + st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ + move16(); + tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ + st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); /* Q8 */ move16(); - tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); } ELSE { @@ -183,14 +184,15 @@ void long_enr_fx( } else { st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; } */ - alpha = 655; - move16(); /* 0.02 Q15 */ + alpha = 655; /* 0.02 Q15 */ + move16(); if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ { - alpha = 1638; - move16(); /* 0.05 Q15 */ + alpha = 1638; /* 0.05 Q15 */ + move16(); } st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ + move16(); test(); IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) @@ -199,10 +201,12 @@ void long_enr_fx( { /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ + move16(); } ELSE { st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + move16(); } } }