diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 058e962acc9f1dcd396ee7239f40bd6f79f81872..15826bdecc849dcca16c4368e237ef1300b3b5e0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -954,7 +954,7 @@ ivas_error ivas_jbm_dec_tc( float *data /* o : output synthesis signals */ ); #endif - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const uint16_t nSamplesAsked, /* i : number of samples wanted */ @@ -962,6 +962,7 @@ ivas_error ivas_jbm_dec_render( uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ int16_t *data /* o : output synthesis signal */ ); +#endif #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -7394,7 +7395,7 @@ void ivas_omasa_rearrange_channels( const int16_t nchan_transport_ism, /* i : number of ISM TCs */ const int16_t output_frame /* i : output frame length per channel */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_dirac_rend_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of samples requested */ @@ -7403,7 +7404,7 @@ void ivas_omasa_dirac_rend_jbm( const int16_t nchan_transport, /* i : number of transport channels */ float *output_f[] /* o : rendered time signal */ ); - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( Decoder_Struct *st_ivas, diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 10885e58b39a34117cb140982fa8f41294b3abc6..659ae5827e0155b9d92fbf0c65f808d4508e72be 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2096,11 +2096,8 @@ void td_bwe_dec_init_ivas_fx( ); void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#ifdef MSAN_FIX + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX const int16_t nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ); @@ -2111,7 +2108,7 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - float *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal */ ); void ivas_dirac_dec_read_BS_fx( @@ -2268,4 +2265,21 @@ void ivas_sba_get_spar_hoa_md_flag_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word16 *spar_hoa_md_flag, Word16 *spar_hoa_dirac2spar_md_flag ); + +void ivas_omasa_dirac_rend_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +); + +ivas_error ivas_jbm_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal */ +); #endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 78e7ae597ef6d54ba9fb0d983774afbd63bfc46a..12927bceb3449339952af06bf8fca169565281da 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -8149,7 +8149,7 @@ void IGFSCFDecoderDecode( ); // ari_dec_fx.c -Word16 ari_decode_overflow_fx( Tastat *s ); +Word32 ari_decode_overflow_fx( Tastat *s ); void ari_start_decoding_14bits_fx( Decoder_State *st, diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index b86c8ae815625adfb921630a5311bea27151b4b7..31af985cbddfb2e7b1c9e507c1243b315b2070e7 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -34,7 +34,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; Word16 d1m, ind1, fdelay, gapsize; Word32 cbrate; - Word16 synth_intFreq[2 * L_SUBFR]; + Word16 synth_intFreq[L_SUBFR * 2]; CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128 * 3]; Word16 old_exc[L_EXC_DEC], *exc; @@ -42,7 +42,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 hb_synth_tmp[NS2SA( 48000, 10000000 )]; const Word16 *hp_filter; Word16 Aq[2 * ( M + 1 )]; - Word16 bpf_error_signal[2 * L_SUBFR]; + Word16 bpf_error_signal[L_SUBFR * 2]; Word16 *pt1, *pt2; Word16 syn_fx_tmp[L_FRAME_16k]; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; @@ -72,12 +72,13 @@ ivas_error acelp_core_switch_dec_fx( Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); - set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 ); + set16_fx( mem_synth, 0, add( NS2SA( 16000, DELAY_CLDFB_NS ), 2 ) ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ /* set multiplication factor according to the sampling rate */ delta = 1; - if ( GT_16( output_frame, L_FRAME16k ) ) + move16(); + IF( GT_16( output_frame, L_FRAME16k ) ) { delta = shr( output_frame, 8 ); } @@ -97,7 +98,7 @@ ivas_error acelp_core_switch_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - if ( GT_32( cbrate, ACELP_24k40 ) ) + IF( GT_32( cbrate, ACELP_24k40 ) ) { cbrate = L_add( ACELP_24k40, 0 ); } @@ -138,7 +139,7 @@ ivas_error acelp_core_switch_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); - syn_12k8_fx( 2 * L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + syn_12k8_fx( shl( L_SUBFR, 1 ), Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) { @@ -149,20 +150,20 @@ ivas_error acelp_core_switch_dec_fx( pitch_buf_tmp[i] = L_SUBFR; move16(); } - nb_post_filt_fx( 2 * L_SUBFR, st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt_fx( shl( L_SUBFR, 1 ), st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); } IF( EQ_16( L_frame_for_cs, L_FRAME ) ) { - deemph_fx( synth_intFreq, PREEMPH_FAC, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC, shl( L_SUBFR, 1 ), &( st_fx->mem_deemph_fx ) ); } ELSE { - deemph_fx( synth_intFreq, PREEMPH_FAC_16k, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC_16k, shl( L_SUBFR, 1 ), &( st_fx->mem_deemph_fx ) ); } - unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, 2 * L_SUBFR ); - Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR ); + unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, shl( L_SUBFR, 1 ) ); + Copy( syn_fx_tmp + M, synth_intFreq, shl( L_SUBFR, 1 ) ); test(); IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) @@ -172,16 +173,16 @@ ivas_error acelp_core_switch_dec_fx( Residu3_fx( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); E_UTIL_synthesis( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); scale_st_fx( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( bpf_error_signal, synth_intFreq, L_SUBFR / 2 ); - blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 ); + Copy( bpf_error_signal, synth_intFreq, shr( L_SUBFR, 1 ) ); + blend_subfr2_fx( bpf_error_signal + shr( L_SUBFR, 1 ), synth_intFreq + shr( L_SUBFR, 1 ), synth_intFreq + shr( L_SUBFR, 1 ) ); } st_fx->hPFstat->on = 0; move16(); - IF( st_fx->flag_cna != 0 ) + IF( NE_16( st_fx->flag_cna, 0 ) ) { - generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0 ); + generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, shl( L_SUBFR, 1 ), 0 ); } /*----------------------------------------------------------------* @@ -189,11 +190,11 @@ ivas_error acelp_core_switch_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, 2 * L_SUBFR, NULL, + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, shl( L_SUBFR, 1 ), NULL, st_fx->bpf_off, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); - if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -206,13 +207,13 @@ ivas_error acelp_core_switch_dec_fx( move16(); /* CLDFB analysis and add the BPF error signal */ - if ( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) { return error; } i = 0; move16(); - if ( st_fx->bpf_off == 0 ) + IF( EQ_16( st_fx->bpf_off, 0 ) ) { i = CLDFB_NO_COL_MAX_SWITCH; move16(); @@ -223,8 +224,9 @@ ivas_error acelp_core_switch_dec_fx( /* CLDFB synthesis of the combined signal */ scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); - if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -233,7 +235,7 @@ ivas_error acelp_core_switch_dec_fx( *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq + NS2SA( L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) - 2, mem_synth, NS2SA( L_frame_for_cs * 50, DELAY_CLDFB_NS ) + 2, negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), L_sub( SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* * BWE decoding @@ -258,7 +260,7 @@ ivas_error acelp_core_switch_dec_fx( test(); IF( decode_bwe && !( ( EQ_16( output_frame, L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( output_frame, L_FRAME8k ) ) ) { - set16_fx( tmp_mem2, 0, 2 * L_FILT48k ); + set16_fx( tmp_mem2, 0, shl( L_FILT48k, 1 ) ); hp_filter = hp16000_48000_fx; fdelay = 48; @@ -297,7 +299,7 @@ ivas_error acelp_core_switch_dec_fx( /* safety check in case of bit errors */ i = MAX_D1M_16k; move16(); - if ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { i = MAX_D1M_12k8; move16(); @@ -312,7 +314,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); } - i = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ); + i = NS2SA_fx2( st_fx->output_Fs, L_sub( FRAME_SIZE_NS, L_add( ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS ) ) ); move16(); Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2( st_fx->output_Fs, 10000000L ) - i ); @@ -421,12 +423,12 @@ ivas_error acelp_core_switch_dec_bfi_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if ( st_fx->hBWE_TD != NULL ) + IF( st_fx->hBWE_TD != NULL ) { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); - bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, shl( PIT16k_MAX, 1 ) ); + bwe_exc = old_bwe_exc + shl( PIT16k_MAX, 1 ); } - else + ELSE { bwe_exc = NULL; } @@ -437,7 +439,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( move16(); /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -465,12 +467,14 @@ ivas_error acelp_core_switch_dec_bfi_fx( Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; + move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type ); st_fx->Q_exc = Q_exc; + move16(); } ELSE { @@ -516,6 +520,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); tmp_float32 = st_fx->enr_old_fx; + move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -558,11 +563,12 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST ); Copy( tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST ); hBPF->psf_att_fx = tmp_float7; + move16(); /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -571,9 +577,10 @@ ivas_error acelp_core_switch_dec_bfi_fx( cldfb_restore_memory( st_fx->cldfbAna ); scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); /* CLDFB synthesis of the combined signal */ - if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -662,12 +669,12 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if ( st_fx->hBWE_TD != NULL ) + IF( st_fx->hBWE_TD != NULL ) { Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } - else + ELSE { bwe_exc = NULL; } @@ -678,7 +685,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( move16(); /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -706,12 +713,14 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); st_fx->Q_exc = 0; + move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type ); st_fx->Q_exc = Q_exc; + move16(); } ELSE { @@ -757,6 +766,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); tmp_float32 = st_fx->enr_old_fx; + move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -803,9 +813,9 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = 11 - st_fx->Q_syn; + Qtmp = sub( 11, st_fx->Q_syn ); Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); - if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -817,7 +827,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( // scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -825,7 +835,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); - Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 11 - 5 - 1 ); + Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 5 ); /*11-5-1*/ // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); @@ -873,6 +883,7 @@ static void decod_gen_voic_core_switch_fx( hGSCDec = st_fx->hGSCDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif @@ -905,7 +916,7 @@ static void decod_gen_voic_core_switch_fx( * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[0], &exc[0], T0, T0_frac, add( L_SUBFR, 1 ), pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index ef751675e02287952d3a5aa36af579a1440a17f0..53d5fc20fc3ebcc0078b39054bad538d919d6ecb 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -52,6 +52,7 @@ ivas_error amr_wb_dec_fx( Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ Word16 tmp16; Word16 sid_bw = 0; + move16(); Word32 L_Ng_ener; Word16 exp2, ng_ener; @@ -138,7 +139,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 0; move16(); - if ( EQ_16( st_fx->last_core, HQ_CORE ) ) + IF( EQ_16( st_fx->last_core, HQ_CORE ) ) { st_fx->bpf_off = 1; move16(); @@ -150,10 +151,11 @@ ivas_error amr_wb_dec_fx( st_fx->sr_core = i_mult( st_fx->L_frame, 50 ); st_fx->fscale_old = st_fx->fscale; + move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ - IF( st_fx->ini_frame == 0 ) + IF( EQ_16( st_fx->ini_frame, 0 ) ) { st_fx->last_core = AMR_WB_CORE; move16(); @@ -168,7 +170,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ - if ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -186,12 +188,12 @@ ivas_error amr_wb_dec_fx( Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; /* reset post-filter in case of switching */ - if ( st_fx->hPFstat->on == 0 ) + IF( EQ_16( st_fx->hPFstat->on, 0 ) ) { st_fx->hPFstat->reset = 1; move16(); } - IF( st_fx->bfi > 0 ) + IF( GT_16( st_fx->bfi, 0 ) ) { st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } @@ -221,7 +223,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) + IF( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( NE_16( st_fx->last_core, 0 ) ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -240,7 +242,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 1; move16(); - if ( st_fx->hPFstat->on != 0 ) + IF( NE_16( st_fx->hPFstat->on, 0 ) ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -281,27 +283,30 @@ ivas_error amr_wb_dec_fx( { /* (float)12800/(float)32000; */ tmp16 = 13107; + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ tmp16 = 16384; + move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ tmp16 = 26214; + move16(); } - FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) + FOR( i = sub( NB_SUBFR16k, NB_SUBFR ); i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub( i, 1 )] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } - FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) + FOR( i = sub( shl( NB_SUBFR16k, 1 ), NB_SUBFR ); i < shl( NB_SUBFR16k, 1 ); i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub( i, 2 )] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } } @@ -313,16 +318,19 @@ ivas_error amr_wb_dec_fx( { /* (float)12800/(float)32000; */ tmp16 = 13107; + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ tmp16 = 16384; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ tmp16 = 26214; + move16(); } st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); st_fx->bfi_pitch_frame = L_FRAME; @@ -335,13 +343,13 @@ ivas_error amr_wb_dec_fx( { /* reset the unvoiced/audio signal improvement memories */ E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->hAmrwb_IO->old_Aq_fx, M ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + ( M + 1 ), M + 1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 2 * ( M + 1 ), M + 1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + 3 * ( M + 1 ), M + 1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + add( M, 1 ), add( M, 1 ) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 2, add( M, 1 ) ), add( M, 1 ) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 3, add( M, 1 ) ), add( M, 1 ) ); } /*End of _DIFF_FLOAT_FIX_*/ test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && st_fx->ini_frame != 0 ) + IF( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->ini_frame, 0 ) ) { st_fx->rate_switching_reset = 1; move16(); @@ -382,14 +390,14 @@ ivas_error amr_wb_dec_fx( delta_mem_scale = 3; move16(); - test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ + IF( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } i = st_fx->Q_exc; + move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, @@ -397,8 +405,8 @@ ivas_error amr_wb_dec_fx( Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ) ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ), L_FRAME ); /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -421,7 +429,7 @@ ivas_error amr_wb_dec_fx( st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ } /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub( L_FRAME, L_SYN_MEM_CLAS_ESTIM ), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /* Update music post processing values */ /* Filter energies update */ @@ -461,7 +469,7 @@ ivas_error amr_wb_dec_fx( st_fx->coder_type = GENERIC; move16(); - if ( vad_flag == 0 ) + IF( EQ_16( vad_flag, 0 ) ) { st_fx->coder_type = INACTIVE; move16(); @@ -523,7 +531,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 7 ) ) + IF( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) { tmp16 = 1; move16(); @@ -544,9 +552,9 @@ ivas_error amr_wb_dec_fx( 0, 0, 0, st_fx->last_core_brate, -1 ); /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ) ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub( DCT_L_POST, OFFSET2 ) ); IF( NE_16( output_frame, L_FRAME8k ) ) { @@ -560,12 +568,12 @@ ivas_error amr_wb_dec_fx( test(); test(); - IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) + IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) { tmp_coder_type = AUDIO; move16(); test(); - if ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) + IF( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -631,7 +639,7 @@ ivas_error amr_wb_dec_fx( { /* long burst frame erasures */ test(); - if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) + IF( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -664,7 +672,7 @@ ivas_error amr_wb_dec_fx( /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; i < MAX_LT; i++ ) { - hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; + hMusicPF->LDm_lt_diff_etot_fx[sub( i, 1 )] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } /* Filter energies update */ @@ -681,7 +689,7 @@ ivas_error amr_wb_dec_fx( syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub( L_FRAME, L_SYN_MEM_CLAS_ESTIM ), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); FOR( i = 0; i < NB_SUBFR; i++ ) @@ -734,7 +742,7 @@ ivas_error amr_wb_dec_fx( *-----------------------------------------------------------------*/ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); + Copy( syn_fx + sub( L_FRAME, L_SYN_MEM ), st_fx->mem_syn_r, L_SYN_MEM ); deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &( st_fx->mem_deemph_fx ) ); @@ -742,8 +750,8 @@ ivas_error amr_wb_dec_fx( Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + L_FRAME / 2, hTcxDec->old_syn_Overl, L_FRAME / 2, sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ - Copy_Scale_sig( syn_fx + L_FRAME - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ + Copy_Scale_sig( syn_fx + shr( L_FRAME, 1 ), hTcxDec->old_syn_Overl, shr( L_FRAME, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ + Copy_Scale_sig( syn_fx + sub( L_FRAME, add( M, 1 ) ), st_fx->syn, add( M, 1 ), sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter @@ -755,7 +763,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); + formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); } /*----------------------------------------------------------------* @@ -765,7 +773,7 @@ ivas_error amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( ( GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) || ( st_fx->coder_type == INACTIVE ) ) + IF( ( GE_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { /*VAD only for non inactive frame*/ test(); @@ -786,12 +794,13 @@ ivas_error amr_wb_dec_fx( ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); #endif st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; + move16(); /*Noisy speech detector*/ noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + IF( NE_16( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); @@ -800,7 +809,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); - IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) + IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) { flag_cna = 1; move16(); @@ -819,16 +828,16 @@ ivas_error amr_wb_dec_fx( } - IF( flag_cna == 0 ) + IF( EQ_16( flag_cna, 0 ) ) { test(); test(); test(); IF( EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < L_FRAME / 2; i++ ) + FOR( i = 0; i < shr( L_FRAME, 1 ); i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * L_FRAME / 4], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, shr( i_mult( 5, L_FRAME ), 2 ) )], -st_fx->Q_syn ) ); move16(); } } @@ -841,7 +850,7 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != L_FRAME ) + IF( NE_16( i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME ) ) { /* resample to ACELP internal sampling rate */ Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); @@ -849,7 +858,7 @@ ivas_error amr_wb_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); - if ( st_fx->ini_frame > 0 ) + IF( GT_16( st_fx->ini_frame, 0 ) ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } @@ -867,7 +876,7 @@ ivas_error amr_wb_dec_fx( /* CLDFB analysis and add the BPF error signal */ i = 0; move16(); - if ( st_fx->bpf_off == 0 ) + IF( EQ_16( st_fx->bpf_off, 0 ) ) { i = CLDFB_NO_COL_MAX; move16(); @@ -877,7 +886,7 @@ ivas_error amr_wb_dec_fx( st_fx->Q_syn2 = st_fx->Q_syn; move16(); - if ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) + IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); @@ -909,7 +918,7 @@ ivas_error amr_wb_dec_fx( tmp16 = norm_l( L_Ng_ener ); exp2 = Log2_norm_lc( L_shl( L_Ng_ener, tmp16 ) ); tmp16 = sub( 30, tmp16 ); - ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 8 + 2 ), exp2, 771 ); + ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 10 ), exp2, 771 ); /* st_fx->ng_ener_ST = 0.7f * st_fx->ng_ener_ST + 0.3f * ng_ener; */ st_fx->Ng_ener_ST_fx = mac_r( L_mult( st_fx->Ng_ener_ST_fx, 22938 ), ng_ener, 9830 ); move16(); @@ -938,7 +947,7 @@ ivas_error amr_wb_dec_fx( updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, 0, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ - Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * add( M, 1 ) ); test(); test(); @@ -948,7 +957,7 @@ ivas_error amr_wb_dec_fx( test(); test(); test(); - if ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -973,7 +982,7 @@ ivas_error amr_wb_dec_fx( move32(); st_fx->prev_Q_exc = st_fx->Q_exc; move16(); - if ( !st_fx->bfi ) + IF( !st_fx->bfi ) { st_fx->last_total_brate = st_fx->total_brate; move32(); @@ -991,10 +1000,10 @@ ivas_error amr_wb_dec_fx( * Overlap of ACELP synthesis with old MDCT memory *----------------------------------------------------------------*/ - if ( st_fx->bfi ) + IF( st_fx->bfi ) { /* calculate another loss frame to fill gap in case of switching frame loss */ - if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; } @@ -1049,17 +1058,19 @@ ivas_error amr_wb_dec_fx( /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_fx2( st_fx->output_Fs, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ); Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); delay_signal( synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); } - if ( waveadj_rec ) + IF( waveadj_rec ) { tmps = 0; + move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + move16(); } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx + tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, @@ -1073,11 +1084,12 @@ ivas_error amr_wb_dec_fx( hp20( synth_out_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); /* save synthesis for core switching */ - Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); + Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, L_add( ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS ) ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, L_sub( FRAME_SIZE_NS, L_add( ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS ) ) ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); { /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ Word16 delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + move16(); Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); @@ -1109,17 +1121,17 @@ void amr_wb_dec_init_fx( /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ hAmrwb_IO->UV_cnt_fx = 30; move16(); - hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); + hAmrwb_IO->LT_UV_cnt_fx = shl( 60, 6 ); move16(); set16_fx( hAmrwb_IO->lt_diff_etot_fx, 0, MAX_LT ); hAmrwb_IO->Last_ener_fx = 0; move16(); - set16_fx( hAmrwb_IO->old_Aq_fx, 0, NB_SUBFR * ( M + 1 ) ); + set16_fx( hAmrwb_IO->old_Aq_fx, 0, i_mult( NB_SUBFR, add( M, 1 ) ) ); hAmrwb_IO->old_Aq_fx[0] = 16384; - hAmrwb_IO->old_Aq_fx[M + 1] = 16384; - hAmrwb_IO->old_Aq_fx[2 * ( M + 1 )] = 16384; - hAmrwb_IO->old_Aq_fx[3 * ( M + 1 )] = 16384; + hAmrwb_IO->old_Aq_fx[add( M, 1 )] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult( 2, add( M, 1 ) )] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult( 3, add( M, 1 ) )] = 16384; move16(); move16(); move16(); diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 3fa319ad2f836720241ffcf55020e68a8413e77c..26390d6e0987048fc16d3ae410e083ded3d416e0 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -14,9 +14,9 @@ * Ari decode 14 bits routines -------------------------------------------------------------*/ -Word16 ari_decode_overflow_fx( Tastat *s ) +Word32 ari_decode_overflow_fx( Tastat *s ) { - return L_sub( L_sub( s->high, 1 ), s->low ) <= 0; + return LE_32( L_sub( L_sub( s->high, 1 ), s->low ), 0 ); } /** @@ -34,7 +34,7 @@ void ari_start_decoding_14bits_fx( val = L_and( L_deposit_l( get_next_indice( st, cbitsnew ) ), 0xffffL ); s->low = L_deposit_l( 0 ); - s->high = ari_q4new + 1; + s->high = L_add( ari_q4new, 1 ); move32(); s->value = val; move32(); @@ -56,13 +56,13 @@ Word16 ari_start_decoding_14bits_prm_fx( FOR( i = 0; i < cbitsnew; i++ ) { val = L_shl( val, 1 ); - if ( *( p + i ) ) + IF( *( p + i ) ) { val = L_add( val, 1 ); } } s->low = L_deposit_l( 0 ); - s->high = ari_q4new + 1; + s->high = L_add( ari_q4new, 1 ); move32(); s->value = val; move32(); @@ -90,20 +90,20 @@ static Word16 ari_lookup_s17_fx( range_h = extract_l( L_shr( range, 15 ) ); tmp = L_multi31x16_X2( range_h, range_l, p[8] ); - if ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 8; } tmp = L_multi31x16_X2( range_h, range_l, p[4] ); - if ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 4; } tmp = L_multi31x16_X2( range_h, range_l, p[2] ); - if ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 2; } @@ -115,7 +115,7 @@ static Word16 ari_lookup_s17_fx( tmp = L_multi31x16_X2( range_h, range_l, p[1] ); test(); - if ( ( (Word32) ( &cum_freq[15] - p ) == 0 ) && ( GT_32( tmp, cum ) ) ) + IF( EQ_32( (Word32) ( &cum_freq[15] - p ), 0 ) && ( GT_32( tmp, cum ) ) ) { p = p + 1; } @@ -156,12 +156,12 @@ static Word16 ari_lookup_s27_fx( move16(); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - if ( tmp <= 0 ) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -170,12 +170,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - if ( tmp <= 0 ) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -184,12 +184,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - if ( tmp <= 0 ) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -198,12 +198,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - if ( tmp <= 0 ) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -215,7 +215,7 @@ static Word16 ari_lookup_s27_fx( im = add( il, 1 ); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); @@ -237,12 +237,12 @@ static Word16 ari_lookup_bit_fx( range = L_shl( range, 13 ); /* L_multi31x16_X2(range_h, range_l, 8192) */ cum = L_sub( range, cum ); - if ( cum > 0 ) + IF( GT_32( cum, 0 ) ) { symbol = 1; move16(); } - if ( cum <= 0 ) + IF( LE_32( cum, 0 ) ) { symbol = 0; move16(); @@ -275,15 +275,16 @@ static Word16 ari_decode_14bits_ext_fx( range = L_sub( high, low ); cum = L_add( L_shl( L_sub( value, low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); - if ( cum < 0 ) + IF( LT_32( cum, 0 ) ) { cum = 0x7fffffff; + move32(); } symbol = lookup_fn( cum, range, cum_freq ); high = L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ); - low = L_add( low, mul_sbc_14bits( range, cum_freq[symbol + 1] ) ); + low = L_add( low, mul_sbc_14bits( range, cum_freq[add( symbol, 1 )] ) ); FOR( i = 0; i < 0x7FFF; i++ ) { @@ -296,8 +297,8 @@ static Word16 ari_decode_14bits_ext_fx( { BREAK; } - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC ) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB ) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); @@ -376,7 +377,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { highlim = testval; move16(); - pows[k] = mult_r( pows[k - 1], pows[k - 1] ); + pows[k] = mult_r( pows[sub( k, 1 )], pows[sub( k, 1 )] ); move16(); testval = mult_r( pows[k], base ); @@ -389,7 +390,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) BREAK; } } - assert( k < 12 ); /* maximum 2^10-1*/ + assert( LT_16( k, 12 ) ); /* maximum 2^10-1*/ /* narrow the range down */ FOR( k = sub( k, 2 ); k >= 0; k-- ) @@ -479,8 +480,8 @@ static Word16 ari_decode_14bits_notbl_fx( { BREAK; } - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC ) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB ) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index 0cf43fd5d2ca6daece1f506cc8129dbfd6155431..e2d5e8de7603ac33715507017bf83b26e7f332c2 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -92,9 +92,9 @@ DecodeIndex_fx( hTcxDec = st->hTcxDec; test(); - IF( ( hTcxDec->tcx_hm_LtpPitchLag > 0 ) && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) ) + IF( GT_16( hTcxDec->tcx_hm_LtpPitchLag, 0 ) && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) ) { - Word16 LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, 1 << ( 15 - kLtpHmFractionalResolution ) ), 2 ); + Word16 LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, shl( 1, sub( 15, kLtpHmFractionalResolution ) ) ), 2 ); *PeriodicityIndex = kLtpHmFlag; move16(); @@ -120,7 +120,7 @@ DecodeIndex_fx( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static int16_t tcx_hm_dequantize_gain( const int16_t coder_type, /* i : GC/VC coder type */ const int16_t gain_idx, /* i : quantization index */ @@ -133,14 +133,16 @@ static int16_t tcx_hm_dequantize_gain( if ( !( 0 <= gain_idx && gain_idx < ( 1 << kTcxHmNumGainBits ) ) ) { *gain = 0; + move16(); return 1; } *gain = qGains[coder_type][gain_idx]; + move16(); return 0; } - +#else static Word16 tcx_hm_dequantize_gain_fx( Word16 coder_type, /* i : coder type Q0 */ @@ -153,7 +155,7 @@ static Word16 tcx_hm_dequantize_gain_fx( /* safety check in case of bit errors */ test(); - IF( !( 0 <= gain_idx && LT_16( gain_idx, ( 1 << kTcxHmNumGainBits ) ) ) ) + IF( !( LE_16( 0, gain_idx ) && LT_16( gain_idx, shl( 1, kTcxHmNumGainBits ) ) ) ) { *gain = 0; return 1; @@ -164,14 +166,14 @@ static Word16 tcx_hm_dequantize_gain_fx( return 0; } - +#endif /*-------------------------------------------------------------------* * tcx_hm_decode_ivas() * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void tcx_hm_decode_ivas( const int16_t L_frame, /* i : number of spectral lines */ Word32 env[], /* i/o: envelope shape (Q16) */ @@ -228,7 +230,7 @@ void tcx_hm_decode_ivas( return; } - +#else void tcx_hm_decode( const Word16 L_frame, /* i : number of spectral lines */ Word32 env[], /* i/o: envelope shape (Q16) */ @@ -265,7 +267,7 @@ void tcx_hm_decode( NumTargetBits = add( NumTargetBits, targetBits ); - if ( EQ_16( coder_type, VOICED ) ) + IF( EQ_16( coder_type, VOICED ) ) { NumTargetBits = add( NumTargetBits, kTcxHmNumGainBits ); } @@ -294,6 +296,7 @@ void tcx_hm_decode( { /* A bit error was encountered */ *hm_bits = -1; + move16(); return; } @@ -302,3 +305,4 @@ void tcx_hm_decode( return; } +#endif diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index ee19c765d3089a70217717d259f4e8f431d13358..36710096533d9e2169e90de6382a096e74a37cb3 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -144,7 +144,7 @@ static Word16 tcx_arith_decode_ivas_fx( FOR( k = 0; k < L_frame; k++ ) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */ { set32_fx( q_spectrum, 0, L_frame ); return -1; @@ -157,7 +157,7 @@ static Word16 tcx_arith_decode_ivas_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); - IF( q != 0 ) + IF( NE_16( q, 0 ) ) { /* line is non-zero, decode sign */ bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); @@ -322,10 +322,16 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 gamma_w, gamma_uw; Word16 hm_bits; + test(); + test(); + test(); + test(); + test(); + test(); IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || - ( target_bits <= 0 ) ) + ( LE_16( target_bits, 0 ) ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -344,6 +350,7 @@ void tcx_arith_decode_envelope_ivas_fx( hTcxCfg = st->hTcxCfg; hTcxDec = st->hTcxDec; *signaling_bits = 0; + move16(); assert( hTcxDec->enableTcxLpc ); gamma_w = MAX16B; @@ -355,13 +362,13 @@ void tcx_arith_decode_envelope_ivas_fx( tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #undef WMC_TOOL_SKIP - IF( use_hm != 0 ) + IF( NE_16( use_hm, 0 ) ) { - IF( prm_hm[0] != 0 ) + IF( NE_16( prm_hm[0], 0 ) ) { tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF( hm_bits < 0 ) + IF( LT_16( hm_bits, 0 ) ) { st->BER_detect = 1; move16(); @@ -385,7 +392,7 @@ void tcx_arith_decode_envelope_ivas_fx( L_spec_core = L_spec; move16(); - if ( st->igf ) + IF( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -397,7 +404,7 @@ void tcx_arith_decode_envelope_ivas_fx( move16(); /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) + IF( LT_16( *arith_bits, 0 ) ) { st->BER_detect = 1; move16(); diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index b338cc3e0f39ca9d4185299df8e848e9b9e1d5af..ee9208b4e9ead5e9844b6d0f43fdee04a922f47e 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -30,7 +30,9 @@ static Word16 tcx_arith_decode_fx( Word32 L_tmp, Q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); Flag Carry = 0; + move32(); #endif @@ -40,7 +42,7 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_deposit_l( 0 ); FOR( k = 0; k < L_frame; k++ ) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */ { set32_fx( q_spectrum, 0, L_frame ); return -1; @@ -52,11 +54,11 @@ static Word16 tcx_arith_decode_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); - if ( q == 0 ) + IF( EQ_16( q, 0 ) ) { q_spectrum[k] = L_deposit_l( 0 ); } - IF( q != 0 ) /* line is non-zero, decode sign */ + IF( NE_16( q, 0 ) ) /* line is non-zero, decode sign */ { bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); @@ -66,16 +68,16 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_macNs( L_tmp, q, k ); #endif - Q = L_mult( q, -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); - if ( s == 0 ) - Q = L_mult( q, 1 << ( 30 - SPEC_EXP_DEC ) ); + Q = L_mult( q, negate( shl( 1, sub( 30, SPEC_EXP_DEC ) ) ) ); + IF( EQ_16( s, 0 ) ) + Q = L_mult( q, shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); q_spectrum[k] = Q; move32(); } IF( ari_decode_overflow_fx( &as ) ) { - if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ + IF( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); @@ -127,11 +129,15 @@ void tcx_arith_decode_envelope_fx( test(); test(); - + test(); + test(); + test(); + test(); + test(); IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || - ( target_bits <= 0 ) ) + LE_16( target_bits, 0 ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -159,13 +165,13 @@ void tcx_arith_decode_envelope_fx( tcx_arith_render_envelope( A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env ); - IF( use_hm != 0 ) + IF( NE_16( use_hm, 0 ) ) { - IF( prm_hm[0] != 0 ) + IF( NE_16( prm_hm[0], 0 ) ) { tcx_hm_decode( L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF( hm_bits < 0 ) + IF( LT_16( hm_bits, 0 ) ) { st->BER_detect = 1; move16(); @@ -193,7 +199,7 @@ void tcx_arith_decode_envelope_fx( L_spec_core = L_spec; move16(); - if ( st->igf ) + IF( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -205,7 +211,7 @@ void tcx_arith_decode_envelope_fx( move16(); /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) + IF( LT_16( *arith_bits, 0 ) ) { st->BER_detect = 1; move16(); diff --git a/lib_dec/avq_dec.c b/lib_dec/avq_dec.c index c92a899d91b391aecb72261d9c21dd9d0af5d51e..b0eef6b2fa04367a1be566bc834d3a98ca510339 100644 --- a/lib_dec/avq_dec.c +++ b/lib_dec/avq_dec.c @@ -285,7 +285,6 @@ void AVQ_demuxdec( return; } -#endif /*-----------------------------------------------------------------* * AVQ_dec_lpc_ivas() @@ -373,7 +372,7 @@ void AVQ_dec_lpc_ivas( * read codebook indices (rank I and event. Voronoi index kv) *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void read_cv( Decoder_State *st, /* i/o: decoder state structure */ uint16_t *I, /* o : rank I code book index */ diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index e768e1ffd80a993cd26970a8b9e04b5d34b3816a..68d3e9549cccd2b3915223db003c4b1448e80bf0 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -79,30 +79,42 @@ void AVQ_demuxdec_fx( { move16(); svOrder[i] = j; - i++; - j++; + i = add( 1, i ); + j = add( 1, j ); } FOR( i = 0; i < NSV_MAX; i++ ) { I[i] = (UWord16) -1; + move16(); } FOR( i = 0; i < Nsv; i++ ) { k = svOrder[i]; + move16(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( ( bits % 5 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, sub( Nsv, 1 ) ) ) { ordr_esti( Nsv - i, &trgtSvPos, &svOrder[i], Nsv ); k = svOrder[i]; + move16(); avq_bit_sFlag = 1; + move16(); } - + test(); IF( EQ_16( k, trgtSvPos ) && GT_16( avq_bit_sFlag, 0 ) ) { + test(); + test(); IF( EQ_16( sub( *nb_bits, bits ), 7 ) || LT_16( bits, BIT_SAVING_LOW_THR ) || GE_16( bits, BIT_SAVING_HIGH_THR ) ) { avq_bit_sFlag = 0; + move16(); } ELSE { @@ -110,15 +122,17 @@ void AVQ_demuxdec_fx( } } - nq[k] = 0; /* initialization and also forced if the budget is exceeded */ + nq[k] = 0; + move16(); /* initialization and also forced if the budget is exceeded */ IF( GT_16( bits, 8 ) ) { /* read the unary code including the stop bit for nq[i] */ nq[k] = -1; + move16(); DO { - ( nq[k] )++; + nq[k] = add( nq[k], 1 ); // IF ( 5 * nq[k] + 4 == bits ) IF( EQ_16( add( add( shl( nq[k], 2 ), nq[k] ), 4 ), bits ) ) @@ -164,49 +178,70 @@ void AVQ_demuxdec_fx( { i = svOrder[Nsv - 1]; nq[i] = 0; + move16(); bitsMod = bits % 5; IF( NE_16( i, sub( Nsv, 1 ) ) ) { nullVec = 0; - FOR( j = i; j < Nsv - 1; j++ ) + move16(); + FOR( j = i; j < sub( Nsv, 1 ); j++ ) { IF( EQ_16( nq[svOrder[j]], 0 ) ) { nullVec = add( nullVec, 1 ); } } - nq_est = bits / 5; - IF( ( GT_16( bitsMod, 0 ) || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), ( add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* dummy bits */ + nq_est = idiv1616( bits, 5 ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_16( bitsMod, 0 ) || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), ( add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) ) && EQ_16( nq[svOrder[sub( Nsv, 2 )]], 0 ) ) /* dummy bits */ { dummy_bits = sub( 5, bitsMod ); bits = add( bits, dummy_bits ); /* add dummy bits */ bitsMod = 0; + move16(); } - ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[sub( Nsv, 2 )]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ { underflow = 0; + move16(); IF( NE_16( ( add( bitsMod, nullVec ) % 5 ), 0 ) ) { underflow = 1; + move16(); } dummy_bits = add( nullVec, underflow ); bits = add( bits, dummy_bits ); /* add dummy bits */ bitsMod = 0; + move16(); } } underflow = 1; + move16(); IF( NE_16( bitsMod, 4 ) ) { underflow = 0; + move16(); bits = sub( bits, bitsMod ); } bits = add( bits, underflow ); /* read the unary code for unused bit*/ unused_bits_idx = -1; + move16(); DO { - ( unused_bits_idx )++; + unused_bits_idx = add( unused_bits_idx, 1 ); IF( EQ_16( add( add( shl( unused_bits_idx, 2 ), unused_bits_idx ), 4 ), sub( bits, 1 ) ) ) { BREAK; @@ -215,27 +250,42 @@ void AVQ_demuxdec_fx( WHILE( get_next_indice_1( st ) ); unusedbitsFlag = 0; + move16(); IF( EQ_16( dummy_bits, 0 ) ) { + test(); + test(); + test(); + test(); IF( EQ_16( unused_bits_idx, 0 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { unusedbitsFlag = 1; + move16(); } ELSE IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { unusedbitsFlag = -1; + move16(); } } /*Compute AVQ code book number from unused Bits */ tmp = (Word16) ( sub( bits, add( add( shl( add( unusedbitsFlag, unused_bits_idx ), 2 ), unusedbitsFlag ), unused_bits_idx ) ) ); - nq_est = tmp / 5; - nq_est = EQ_16( ( tmp % 5 ), 0 ) ? nq_est : add( nq_est, 1 ); - + nq_est = idiv1616( tmp, 5 ); + IF( EQ_16( ( tmp % 5 ), 0 ) ) + { + nq_est = nq_est; + move16(); + } + ELSE + { + nq_est = add( nq_est, 1 ); + } IF( EQ_16( nq_est, 1 ) ) { nq_est = 0; + move16(); } bits = sub( bits, underflow ); @@ -247,8 +297,9 @@ void AVQ_demuxdec_fx( } nq[i] = nq_est; + move16(); /* read codebook indices (rank I and event. Voronoi index kv) */ - read_cv_fx( st, &I[i], &kv[i * 8], nq[i], &bits ); + read_cv_fx( st, &I[i], &kv[shl( i, 3 )], nq[i], &bits ); bits = sub( bits, dummy_bits ); @@ -270,7 +321,7 @@ void AVQ_demuxdec_fx( xriq[add( shl( i, 3 ), j )] = code[j]; } } - + move16(); *nb_bits = bits; return; @@ -306,7 +357,7 @@ void AVQ_dec_lpc( /* decode all subvectors */ - FOR( l = Nsv - 1; l >= 0; l-- ) + FOR( l = sub( Nsv, 1 ); l >= 0; l-- ) { nq = indx[l]; /* quantizer number (0,2,3..n) */ move16(); @@ -361,7 +412,7 @@ void AVQ_dec_lpc( /* write decoded RE8 vector */ FOR( i = 0; i < 8; i++ ) { - nvecq[( l * 8 ) + i] = c[i]; + nvecq[add( shl( l, 3 ), i )] = c[i]; move16(); } } @@ -389,7 +440,7 @@ static void read_cv_fx( Word16 j, bits, order_v; bits = *nbits; - + move16(); /* read codebook indices (rank I and event. Voronoi index kv) */ IF( EQ_16( nq, 0 ) ) /* Q0 */ { @@ -397,13 +448,13 @@ static void read_cv_fx( } ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ { - *I = get_next_indice( st, 4 * nq ); + *I = get_next_indice( st, shl( nq, 2 ) ); bits = sub( bits, shl( nq, 2 ) ); } ELSE IF( EQ_16( s_and( nq, 1 ), 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 4 * 4 ); - bits = sub( bits, 4 * 4 ); + *I = get_next_indice( st, 16 ); + bits = sub( bits, 16 ); order_v = (Word16) sub( shr( nq, 1 ), 2 ); FOR( j = 0; j < 8; j++ ) @@ -414,8 +465,8 @@ static void read_cv_fx( } ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 4 * 3 ); - bits = sub( bits, 4 * 3 ); + *I = get_next_indice( st, 12 ); + bits = sub( bits, 12 ); order_v = (Word16) sub( shr( nq, 1 ), 1 ); FOR( j = 0; j < 8; j++ ) diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 48d136367c07a602ba3f7fd37a2af4bf646d4c23..b721487fbad77d166dfefe70d090fca0244ecb0b 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -538,11 +538,14 @@ void addBassPostFilter_ivas_fx( Word16 maxBand; const Word32 *weights_fx; Word16 nCol = cldfb->no_col; + move16(); Word16 nColToProcess = nCol; + move16(); Word16 nChan = cldfb->no_channels; + move16(); IF( GT_16( samplesToProcess, -1 ) ) { - nColToProcess = ( ( samplesToProcess + cldfb->no_channels - 1 ) / cldfb->no_channels ); + nColToProcess = idiv1616( sub( add( samplesToProcess, cldfb->no_channels ), 1 ), cldfb->no_channels ); move16(); } @@ -685,14 +688,20 @@ Word16 res_bpf_adapt_ivas_fx( IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) ) { i_start = 39; + move16(); i_end = 64; - bw_inv = 1311; /* 1/(64 - 39) in Q15 */ + move16(); + bw_inv = 1311; + move16(); /* 1/(64 - 39) in Q15 */ } ELSE { i_start = 28; + move16(); i_end = 40; - bw_inv = 2720; /* 1/(40 - 28) in Q15*/ + move16(); + bw_inv = 2720; + move16(); /* 1/(40 - 28) in Q15*/ } /* Measure energy of high frequency band in MDCT domain */ @@ -714,20 +723,33 @@ Word16 res_bpf_adapt_ivas_fx( res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; + move32(); /* Measure energy of discontinuities at subframe boundaries */ error_nrg = 0; + move32(); FOR( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k ) { tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx ); error_nrg = Madd_32_32( error_nrg, tmp, tmp ); - hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[i + STEREO_DFT_L_SUBFR_8k - 1]; + hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add( i, sub( STEREO_DFT_L_SUBFR_8k, 1 ) )]; + move32(); + } + error_nrg = L_shr( error_nrg, 1 ); // Q0 + error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */ + /* Form decision variable and apply limit */ + IF( LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) ) + { + bpf_error_ratio = (Word16) ( L_shl( ( L_shl( error_nrg, Q5 ) / res_hb_nrg ), Q8 ) ); + move16(); + } + ELSE + { + bpf_error_ratio = shl( ONE_IN_Q12, 1 ); } - error_nrg = L_shr( error_nrg, 1 ); // Q0 - error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */ - bpf_error_ratio = LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) ? (Word16) ( L_shl( ( L_shl( error_nrg, Q5 ) / res_hb_nrg ), Q8 ) ) : shl( ONE_IN_Q12, 1 ); /* Form decision variable and apply limit */ bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( sub( MAX_16, STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) ); hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; + move16(); res_bpf_flag = (Word16) LT_16( bpf_error_ratio, ONE_IN_Q13 ); @@ -791,51 +813,60 @@ void bpf_pitch_coherence_ivas_fx( { case 80: scaled_inv_L_frame = 26843545; + move32(); BREAK; case 160: scaled_inv_L_frame = 13421773; + move32(); BREAK; case 256: scaled_inv_L_frame = 8388608; + move32(); BREAK; case 320: scaled_inv_L_frame = 6710886; + move32(); BREAK; case 512: scaled_inv_L_frame = 4194304; + move32(); BREAK; case 640: scaled_inv_L_frame = 3355443; + move32(); BREAK; case 960: scaled_inv_L_frame = 2236962; + move32(); BREAK; default: scaled_inv_L_frame = 0; + move32(); } nb_subfr = shr( st->L_frame, 6 ); - + test(); IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->element_mode, EVS_MONO ) ) { - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add( nb_subfr, 3 )], st->old_pitch_buf_fx[add( nb_subfr, 2 )] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[add( nb_subfr, 1 )] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn1 = max( min( pcn1, 4096 ), 0 ); + pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( pitch_buf[sub( nb_subfr, 1 )], pitch_buf[sub( nb_subfr, 2 )] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn2 = max( min( pcn2, 4096 ), 0 ); + pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add( nb_subfr, 3 )], st->old_pitch_buf_fx[add( nb_subfr, 2 )] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn3 = max( min( pcn3, 4096 ), 0 ); + pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) { - st->hBPF->psf_att_fx = 13107; /*Q15*/ + st->hBPF->psf_att_fx = 13107; + move16(); /*Q15*/ // st->hBPF->psf_att = 0.4f; set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 0c70d5b788fff2cddc90e5f10b031a4d7df94ed4..c8287c00c3afa585800f3b2b1ea72f122d616f3e 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -46,6 +46,7 @@ void bass_psfilter_init_fx( set16_fx( hBPF->vibrato_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4*/ hBPF->psf_att_fx = 32767; + move16(); return; } @@ -157,7 +158,7 @@ void bass_psfilter_fx( { FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) { - hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[i - 1]; + hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[sub( i, 1 )]; move16(); /*Q6 */ } Ltmp = L_deposit_l( 0 ); @@ -168,7 +169,7 @@ void bass_psfilter_fx( tmp = round_fx( Ltmp ); /*Q4*/ /*tmp2 = div_s(1,nb_subfr); //Q15 */ tmp = mult_r( tmp, 8192 ); /*divide per 4 (when L_frame == L_FRAME) -> Q4*/ - if ( EQ_16( nb_subfr, 5 ) ) + IF( EQ_16( nb_subfr, 5 ) ) { tmp = mult_r( tmp, 26214 ); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ } @@ -181,7 +182,7 @@ void bass_psfilter_fx( dist_pit_diff = abs_s( sub( idx_pit_max, idx_pit_min ) ); diff_pit = sub( loc_pit_max, loc_pit_min ); /*Q4 */ test(); - if ( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) { diff_pit = mult_r( diff_pit, 26214 ); /*Q4 */ } @@ -189,7 +190,7 @@ void bass_psfilter_fx( test(); test(); test(); - if ( coder_type != INACTIVE && GE_16( diff_pit, 2 << 4 ) && LT_16( diff_pit, 10 << 4 ) && GE_16( dist_pit_diff, 3 ) ) + IF( NE_16( coder_type, INACTIVE ) && GE_16( diff_pit, shl( 2, 4 ) ) && LT_16( diff_pit, shl( 10, 4 ) ) && GE_16( dist_pit_diff, 3 ) ) { vibrato = 1; move16(); @@ -231,9 +232,10 @@ void bass_psfilter_fx( { /* do not use BPF for HQ core */ T_update = 80; - if ( EQ_16( L_frame, L_FRAME8k ) ) + IF( EQ_16( L_frame, L_FRAME8k ) ) { T_update = 40; + move16(); } move16(); set16_fx( T_sf, 0, 5 ); @@ -293,14 +295,14 @@ void bass_psfilter_fx( syn_fx = &syn_buf_fx[add( nbpsf_pit_max, i_subfr )]; syn2_fx = &syn2_buf_fx[i_subfr]; - IF( T != 0 ) + IF( NE_16( T, 0 ) ) { test(); IF( GE_16( T, PIT_MIN ) && Opt_AMR_WB ) { T = Pit_track_fx( syn_fx, T ); - if ( NE_16( T, T_sf[subfr_pos] ) ) + IF( NE_16( T, T_sf[subfr_pos] ) ) { Track_on = 1; move16(); @@ -364,14 +366,14 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - if ( Lcorr < 0 ) + IF( LT_32( Lcorr, 0 ) ) { gain = sub( 0, gain ); } @@ -414,7 +416,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -425,7 +427,7 @@ void bass_psfilter_fx( #else alpha = shr( div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ), exp2 ); /*Q15 */ #endif - if ( Lcorr < 0 ) + IF( LT_32( Lcorr, 0 ) ) { alpha = sub( 0, alpha ); } @@ -435,12 +437,14 @@ void bass_psfilter_fx( alpha = mult_r( alpha, hBPF->psf_att_fx ); test(); test(); + test(); + test(); IF( GT_16( alpha, 9830 ) && Track_on ) { alpha = 9830; move16(); } - ELSE if ( GT_16( alpha, 13107 ) && vibrato ) + ELSE IF( GT_16( alpha, 13107 ) && vibrato ) { alpha = 13107; move16(); @@ -495,14 +499,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = -1 - 2; + exp2 = sub( -1, 2 ); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + subfr_len / 2; - FOR( i = 0; i < subfr_len / 2; i++ ) + sigPtr = err + shr( subfr_len, 1 ); + FOR( i = 0; i < shr( subfr_len, 1 ); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -544,7 +548,7 @@ void bass_psfilter_fx( Track_on = 0; move16(); - if ( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ + IF( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ { Track_on = 1; move16(); @@ -597,14 +601,14 @@ void bass_psfilter_fx( exp2 = norm_l( Lener ); tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - if ( Lcorr < 0 ) + IF( LT_32( Lcorr, 0 ) ) { gain = sub( 0, gain ); } @@ -643,7 +647,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -680,14 +684,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = -1 - 2; + exp2 = sub( -1, 2 ); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + subfr_len / 2; - FOR( i = 0; i < subfr_len / 2; i++ ) + sigPtr = err + shr( subfr_len, 1 ); + FOR( i = 0; i < shr( subfr_len, 1 ); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -725,11 +729,11 @@ void bass_psfilter_fx( * update memory for next frame *-------------------------------------------------------*/ - FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) + FOR( i = sub( L_TRACK_HIST, 1 ); i > 0; i-- ) { - hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i - 1]; + hBPF->Track_on_hist[i] = hBPF->Track_on_hist[sub( i, 1 )]; move16(); - hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i - 1]; + hBPF->vibrato_hist[i] = hBPF->vibrato_hist[sub( i, 1 )]; move16(); } @@ -797,7 +801,7 @@ static Word16 Pit_track_fx( /* o : Pitch Lener0 = L_mult0( *v1, *v1 ); Ltmp0 = L_mult0( *v2, *v2 ); Lcorr0 = L_mult0( *v1++, *v2++ ); - FOR( i = 1; i < ( L_HALFR16k + NBPSF_L_EXTRA ) / 14; i++ ) + FOR( i = 1; i < idiv1616( add( L_HALFR16k, NBPSF_L_EXTRA ), 14 ); i++ ) { #ifdef BASOP_NOGLOB Lener0 = L_mac0_sat( Lener0, *v1, *v1 ); @@ -815,7 +819,7 @@ static Word16 Pit_track_fx( /* o : Pitch test(); IF( EQ_32( Lener0, 2147483647L ) || EQ_32( Ltmp0, 2147483647L ) || - EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, -2147483647 - 1L ) ) + EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, L_add( -2147483647, -1L ) ) ) { v1 -= i; move16(); @@ -860,7 +864,7 @@ static Word16 Pit_track_fx( /* o : Pitch /* Call the Integer Square Root (it will normalize again if req.) */ Ltmp = Isqrt( Ltmp ); /* We now do corr * 1 / sqrt(1/product) with high part of ratio only */ - exp1 = mac_r( ( 16 - 1 ) * 65536L - 0x8000L, exp1, 16384 ); + exp1 = mac_r( 950272, exp1, 16384 ); /*( 16 - 1 ) * 65536L - 0x8000L*/ exp2 = norm_l( Ltmp ); Ltmp = L_shl( Ltmp, exp2 ); exp1 = sub( exp1, exp2 ); @@ -875,7 +879,7 @@ static Word16 Pit_track_fx( /* o : Pitch Ltmp = L_shl( Ltmp, exp1 ); #endif /* cn = normalized correlation of pitch/2 */ - if ( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ + IF( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ { T = T2; move16(); @@ -943,7 +947,7 @@ void addBassPostFilter_fx( /* now do the subtraction */ - IF( nTimeSlots > 0 ) + IF( GT_16( nTimeSlots, 0 ) ) { /* Find common scale. */ b = s_max( cldfb_scale->lb_scale, scale.lb_scale ); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index d75b598f25867f53900ffe6475c01575ad2cc4e0..1c5628c8c4f6ad10fd74ca3967e9824e99db92e8 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -51,8 +51,10 @@ void CNG_dec_fx( Word16 weights, ptr, j, k; Word16 m1; Word16 m = 0; + move16(); Word16 tmp[HO_HIST_SIZE * M]; Word16 burst_ho_cnt = 0; + move16(); Word16 ll, s_ptr; Word32 L_enr, L_tmp1; Word16 tmp1, exp; @@ -93,16 +95,16 @@ void CNG_dec_fx( IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* de-quantize the LSF vector */ - IF( st_fx->Opt_AMR_WB != 0 ) + IF( NE_16( st_fx->Opt_AMR_WB, 0 ) ) { /* Flt function */ isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); - /* check if ISPs may trigger too much synthesis energy */ + /* check IF ISPs may trigger too much synthesis energy */ E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( Aq_tmp, shl( L_SUBFR, 1 ) ); - IF( ( shr( enr_new, 14 ) > 0 ) ) + IF( GT_16( shr( enr_new, 14 ), 0 ) ) { /* Use old LSP vector */ Copy( st_fx->lsp_old_fx, lsp_new, M ); @@ -117,12 +119,12 @@ void CNG_dec_fx( NULL #endif ); - /* check if LSPs may trigger too much synthesis energy */ + /* check IF LSPs may trigger too much synthesis energy */ E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( Aq_tmp, shl( L_SUBFR, 1 ) ); - IF( shr( enr_new, 14 ) > 0 ) + IF( GT_16( shr( enr_new, 14 ), 0 ) ) { /* Use old LSP vector */ Copy( st_fx->lsp_old_fx, lsp_new, M ); @@ -138,7 +140,7 @@ void CNG_dec_fx( } /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG == 0 ) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); } @@ -154,7 +156,7 @@ void CNG_dec_fx( { istep = ISTEP_AMR_WB_SID_FX; move16(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { istep = ISTEP_SID_FX; move16(); @@ -163,7 +165,7 @@ void CNG_dec_fx( /* initialize the energy quantization parameters */ num_bits = 6; move16(); - if ( st_fx->Opt_AMR_WB == 0 ) + IF( EQ_16( st_fx->Opt_AMR_WB, 0 ) ) { num_bits = 7; move16(); @@ -180,12 +182,12 @@ void CNG_dec_fx( { tmp1 = add( hTdCngDec->old_enr_index, 40 ); } - IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ + IF( GT_16( L_enr_index, tmp1 ) && GE_16( hTdCngDec->old_enr_index, 0 ) ) /* Likely bit error and not startup */ { L_enr_index = tmp1; move16(); L_enr_index = s_min( L_enr_index, 127 ); - if ( st_fx->Opt_AMR_WB != 0 ) + IF( NE_16( st_fx->Opt_AMR_WB, 0 ) ) { L_enr_index = s_min( L_enr_index, 63 ); } @@ -195,8 +197,8 @@ void CNG_dec_fx( test(); test(); IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && - st_fx->first_CNG != 0 && - hTdCngDec->old_enr_index >= 0 && + NE_16( st_fx->first_CNG, 0 ) && + GE_16( hTdCngDec->old_enr_index, 0 ) && GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) { *allow_cn_step = 1; @@ -205,7 +207,7 @@ void CNG_dec_fx( hTdCngDec->old_enr_index = L_enr_index; move16(); - if ( L_enr_index == 0 ) + IF( EQ_16( L_enr_index, 0 ) ) { L_enr_index = -5; move16(); @@ -226,7 +228,7 @@ void CNG_dec_fx( burst_ho_cnt = get_next_indice( st_fx, 3 ); /* 3bit */ *sid_bw = get_next_indice( st_fx, 1 ); - IF( *sid_bw == 0 ) + IF( EQ_16( *sid_bw, 0 ) ) { env_idx[0] = get_next_indice( st_fx, 6 ); move16(); @@ -238,10 +240,10 @@ void CNG_dec_fx( } } } - /* Reset CNG history if CNG frame length is changed */ + /* Reset CNG history IF CNG frame length is changed */ test(); test(); - IF( EQ_16( st_fx->bwidth, WB ) && st_fx->first_CNG != 0 && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) + IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) { hTdCngDec->ho_hist_size = 0; move16(); @@ -255,29 +257,29 @@ void CNG_dec_fx( test(); test(); test(); - IF( st_fx->last_core_brate <= SID_2k40 ) + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) { - /* Reset hangover counter if not first SID period */ - if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + /* Reset hangover counter IF not first SID period */ + IF( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) { hTdCngDec->num_ho = 0; move16(); } - /* Update LSPs if last SID energy not outliers or insufficient number of hangover frames */ + /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ test(); IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) { FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 3277, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } } ELSE { - /* Update CNG_mode if allowed */ + /* Update CNG_mode IF allowed */ test(); test(); test(); @@ -301,7 +303,7 @@ void CNG_dec_fx( move16(); s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); move16(); - if ( s_ptr < 0 ) + IF( LT_16( s_ptr, 0 ) ) { s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); } @@ -309,7 +311,7 @@ void CNG_dec_fx( FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -322,31 +324,31 @@ void CNG_dec_fx( IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), st_fx->L_frame, 0 ); } /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); + Copy( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), &( hTdCngDec->ho_lsp_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, M )] ), M ); Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); + Copy32( &( hTdCngDec->ho_env_circ_fx[i_mult( s_ptr, NUM_ENV_CNG )] ), &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); } s_ptr = add( s_ptr, 1 ); - if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) + IF( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) { s_ptr = 0; move16(); } } - IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + IF( GT_16( hTdCngDec->ho_hist_size, 0 ) ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ { /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); @@ -354,7 +356,7 @@ void CNG_dec_fx( test(); test(); - if ( ( L_tmp1 > 0 && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF( ( GT_32( L_tmp1, 0 ) && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); } @@ -365,17 +367,17 @@ void CNG_dec_fx( move16(); } test(); - IF( *allow_cn_step == 0 && hTdCngDec->ho_hist_size > 0 ) + IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) { /* Use average of energies below last energy */ ptr = hTdCngDec->ho_hist_ptr; move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); + Copy( &( hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )] ), tmp, M ); m1 = 0; move16(); - IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ), 0 ) ) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } @@ -388,9 +390,9 @@ void CNG_dec_fx( FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) { ptr = sub( ptr, 1 ); - if ( ptr < 0 ) + IF( LT_16( ptr, 0 ) ) { - ptr = HO_HIST_SIZE - 1; + ptr = sub( HO_HIST_SIZE, 1 ); move16(); } @@ -405,10 +407,10 @@ void CNG_dec_fx( /*weights += W_DTX_HO[k];*/ weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); - IF( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ) == 0 ) + Copy( &hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )], &tmp[i_mult( m, M )], M ); + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], &tmp_env[i_mult( m1, NUM_ENV_CNG )], NUM_ENV_CNG ); m1 = add( m1, 1 ); } m = add( m, 1 ); @@ -419,7 +421,7 @@ void CNG_dec_fx( exp = norm_s( weights ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl( L_tmp1, exp + 1 ); /* Q6 */ + L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ st_fx->lp_ener_fx = L_enr; /* Q6 */ @@ -430,27 +432,27 @@ void CNG_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[sub( M, 1 )], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } ELSE { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); + lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_16k_FX ); ftmp_fx = 1205; - move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[sub( M, 1 )], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - FOR( j = 0; j < M - 1; j++ ) + FOR( j = 0; j < sub( M, 1 ); j++ ) { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + tmpv = sub( sub( lsf_tmp[add( j, 1 )], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ } C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ @@ -487,10 +489,10 @@ void CNG_dec_fx( L_tmp1 = 0; FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); } - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ) ); tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ @@ -501,20 +503,23 @@ void CNG_dec_fx( FOR( i = 0; i < M; i++ ) { L_tmp1 = 0; + move32(); FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); } - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ), L_deposit_l( tmp[add( i_mult( max_idx[1], M ), i )] ) ) ); /*Q15*/ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ } } - dist = 0; /*Q15*/ - max_dev = 0; /*Q15*/ + dist = 0; + move16(); /*Q15*/ + max_dev = 0; + move16(); /*Q15*/ FOR( i = 0; i < M; i++ ) { dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ @@ -523,7 +528,7 @@ void CNG_dec_fx( #else dist = add( dist, dev ); /*Q15*/ #endif - if ( GT_16( dev, max_dev ) ) + IF( GT_16( dev, max_dev ) ) { max_dev = dev; move16(); @@ -547,7 +552,7 @@ void CNG_dec_fx( st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); } } - IF( m1 > 0 ) + IF( GT_16( m1, 0 ) ) { FOR( i = 0; i < NUM_ENV_CNG; i++ ) { @@ -600,14 +605,14 @@ void CNG_dec_fx( /* Update hangover memory during CNG */ test(); #ifdef BASOP_NOGLOB - IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) + IF( EQ_16( *allow_cn_step, 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #else IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #endif { /* update the pointer to circular buffer of old LSP vectors */ hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -620,7 +625,7 @@ void CNG_dec_fx( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; move32(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && *sid_bw == 0 ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( *sid_bw, 0 ) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ exp = norm_l( hTdCngDec->Enew_fx ); @@ -653,16 +658,16 @@ void CNG_dec_fx( move32(); } hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[( hTdCngDec->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); } - ELSE IF( *sid_bw != 0 ) + ELSE IF( NE_16( *sid_bw, 0 ) ) { hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); } hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); @@ -672,7 +677,7 @@ void CNG_dec_fx( st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -681,8 +686,9 @@ void CNG_dec_fx( /* Update the frame length memory */ st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -700,7 +706,7 @@ void CNG_dec_fx( tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ { - Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); + Copy( Aq, &Aq[i_mult( i, add( M, 1 ) )], add( M, 1 ) ); } return; @@ -723,11 +729,11 @@ void swb_CNG_dec_fx( ) { test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -741,7 +747,7 @@ void swb_CNG_dec_fx( st_fx->last_vad_fx = 1; move16(); st_fx->hTdCngDec->burst_cnt = add( st_fx->hTdCngDec->burst_cnt, 1 ); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) + IF( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) { st_fx->hTdCngDec->burst_cnt = 0; move16(); @@ -763,11 +769,11 @@ void swb_CNG_dec_ivas_fx( ) { test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -833,14 +839,14 @@ static void shb_CNG_decod_fx( TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - IF( st_fx->bfi == 0 ) + IF( EQ_16( st_fx->bfi, 0 ) ) { test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { idx_ener_fx = get_next_indice( st_fx, 4 ); - if ( idx_ener_fx == 0 ) + IF( EQ_16( idx_ener_fx, 0 ) ) { idx_ener_fx = -15; move16(); @@ -881,7 +887,7 @@ static void shb_CNG_decod_fx( IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - if ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) + IF( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) { st_fx->shb_dtx_count_fx = add( st_fx->shb_dtx_count_fx, 1 ); } @@ -889,7 +895,7 @@ static void shb_CNG_decod_fx( E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, add( LPC_SHB_ORDER, 1 ), sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ #ifdef IVAS_CODE_CNG // mvr2r(shb_lpcCNG, st->hTdCngDec->shb_lpcCNG, LPC_SHB_ORDER + 1); @@ -905,12 +911,12 @@ static void shb_CNG_decod_fx( exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - if ( st_fx->first_CNG == 0 ) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { st_fx->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } - if ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) + IF( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); @@ -929,12 +935,12 @@ static void shb_CNG_decod_fx( } test(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st_fx->bfi == 0 ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st_fx->bfi, 0 ) ) { st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; move16(); - if ( st_fx->first_CNG == 0 ) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { st_fx->shb_cng_ener_fx = st_fx->last_shb_cng_ener_fx; move16(); @@ -942,7 +948,7 @@ static void shb_CNG_decod_fx( } gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /*8 */ - if ( GT_16( gain_fx, 15 ) ) + IF( GT_16( gain_fx, 15 ) ) { gain_fx = 15; move16(); @@ -970,20 +976,21 @@ static void shb_CNG_decod_fx( /* synthesis signal gain shaping */ L_tmp = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ } q = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q ); - q = q - 32; + q = sub( q, 32 ); ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ IF( EQ_16( st_fx->last_vad_fx, 1 ) ) { st_fx->trans_cnt_fx = 0; move16(); test(); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) + IF( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) { st_fx->trans_cnt_fx = 5; move16(); @@ -992,7 +999,7 @@ static void shb_CNG_decod_fx( ener_fx = st_fx->shb_cng_ener_fx; move16(); /*Q8 */ - IF( st_fx->trans_cnt_fx > 0 ) + IF( GT_16( st_fx->trans_cnt_fx, 0 ) ) { i = extract_l( L_mult0( st_fx->trans_cnt_fx, 17 ) ); /*Q0 */ #ifdef BASOP_NOGLOB @@ -1007,7 +1014,7 @@ static void shb_CNG_decod_fx( L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ L_tmp = L_add( L_tmp, 10 << 16 ); - if ( L_tmp < 0 ) + IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; move32(); @@ -1019,7 +1026,7 @@ static void shb_CNG_decod_fx( L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ #endif L_tmp = L_shr( L_tmp, 10 ); - if ( L_tmp == 0 ) + IF( EQ_32( L_tmp, 0 ) ) { L_tmp = 1; /*Q5 */ } @@ -1058,7 +1065,7 @@ static void shb_CNG_decod_fx( move32(); } - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < shl( ALLPASSSECTIONS_STEEP, 1 ); i++ ) { hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2 ); } @@ -1202,12 +1209,12 @@ static void shb_CNG_decod_ivas_fx( } test(); test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st->bfi == 0 ) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) { st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; move32(); - IF( st->first_CNG == 0 ) + IF( EQ_16( st->first_CNG, 0 ) ) { st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; move32(); @@ -1243,6 +1250,7 @@ static void shb_CNG_decod_ivas_fx( /* synthesis signal gain shaping */ L_tmp = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ @@ -1277,12 +1285,12 @@ static void shb_CNG_decod_ivas_fx( } tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ - IF( tmp > 32767 ) + IF( GT_32( tmp, 32767 ) ) abort(); Word16 tmp_16 = (Word16) tmp; L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, 10 << 16 ); + L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; @@ -1291,9 +1299,10 @@ static void shb_CNG_decod_ivas_fx( fra = L_Extract_lc( L_tmp, &exp ); L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ L_tmp = L_shr( L_tmp, 10 ); - IF( L_tmp == 0 ) + IF( EQ_32( L_tmp, 0 ) ) { - L_tmp = 1; /*Q5 */ + L_tmp = 1; + move32(); /*Q5 */ } exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); /*Q31*/ @@ -1420,7 +1429,7 @@ void td_cng_dec_init_fx( // st->CNG_mode = -1; // for (i = 0; i < LPC_SHB_ORDER; i++) //{ - // if (st->element_mode != EVS_MONO) + // IF (st->element_mode != EVS_MONO) // { // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); // } @@ -1520,7 +1529,7 @@ void td_cng_dec_init_ivas_fx( { IF( NE_16( st->element_mode, EVS_MONO ) ) { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i + 1, 1 ), LPC_SHB_ORDER + 1 ); + hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( add( i, 1 ), 1 ), LPC_SHB_ORDER + 1 ); } ELSE { diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index b043eab46b57a0966be7ade7cdea8377f9598d2c..d8c00803e354bee1203f80f1c33751fa38228da4 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -773,12 +773,16 @@ void reset_tcx_overl_buf_fx( { set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_old_syn_Overl = 0; + move16(); set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_syn_Overl_TDAC = 0; + move16(); set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_syn_Overl = 0; + move16(); set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_syn_Overl_TDACFB = 0; + move16(); return; } #endif diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 835220694790d3f1e585e3429197c688c4103414..7acc450f9b4f9586521c0fccfbb4a8fce5547c19 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -71,7 +71,7 @@ void open_decoder_LPD_fx( #ifndef NEW_IVAS_OPEN_DEC hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); #endif - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); @@ -85,7 +85,7 @@ void open_decoder_LPD_fx( IF( st->hTcxDec != NULL ) { hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->L_frameTCX_past = st->hTcxDec->L_frameTCX; } @@ -112,9 +112,9 @@ void open_decoder_LPD_fx( test(); test(); - if ( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || - ( st->tcxonly != 0 && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) + IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || + ( NE_16( st->tcxonly, 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; move16(); @@ -130,7 +130,7 @@ void open_decoder_LPD_fx( st->TcxBandwidth = getTcxBandwidth( bwidth ); st->narrowBand = 0; move16(); - if ( EQ_16( bwidth, NB ) ) + IF( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -162,7 +162,7 @@ void open_decoder_LPD_fx( hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); } } - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->pit_res_max_past = st->pit_res_max; } @@ -170,12 +170,12 @@ void open_decoder_LPD_fx( /*Preemphasis param*/ st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + IF( LT_16( st->fscale, 640 ) ) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE if ( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); @@ -185,6 +185,8 @@ void open_decoder_LPD_fx( move16(); st->inv_gamma = GAMMA1_INV; move16(); + test(); + test(); IF( EQ_32( st->sr_core, INT_FS_16k ) || ( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { @@ -198,14 +200,14 @@ void open_decoder_LPD_fx( st->lpcQuantization = 0; move16(); test(); - if ( st->tcxonly == 0 && LE_32( st->sr_core, INT_FS_16k ) ) + IF( EQ_16( st->tcxonly, 0 ) && LE_32( st->sr_core, INT_FS_16k ) ) { st->lpcQuantization = 1; } st->numlpc = 2; move16(); - if ( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { st->numlpc = 1; move16(); @@ -213,11 +215,11 @@ void open_decoder_LPD_fx( /* Initialize TBE */ st->prev_coder_type = GENERIC; - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub( LPC_SHB_ORDER, 2 ) ); hBWE_TD->prev_tilt_para_fx = 0; - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add( M, 1 ) ); } /*TCX config*/ @@ -227,7 +229,7 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -254,23 +256,23 @@ void open_decoder_LPD_fx( InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - if ( 1 ) // st->element_mode == EVS_MONO) + IF( 1 ) // st->element_mode == EVS_MONO) { - if ( st->hTECDec == NULL ) + IF( st->hTECDec == NULL ) { - if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) { // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); assert( 0 ); } } } - else + ELSE { st->hTECDec = NULL; } @@ -278,10 +280,9 @@ void open_decoder_LPD_fx( #else - if ( st->hIGFDec != NULL ) - { + IF( st->hIGFDec != NULL ){ PMT( "To be done" ) - // if (!is_init || st->element_mode != IVAS_CPE_MDCT) + // IF (!is_init || st->element_mode != IVAS_CPE_MDCT) //{ // init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); // } @@ -292,11 +293,11 @@ void open_decoder_LPD_fx( // } } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly == 0 ) + IF( st->tcxonly == 0 ) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - // if (st->tecDec_fx != NULL) + // IF (st->tecDec_fx != NULL) { resetTecDec_Fx( &( st->tecDec_fx ) ); } @@ -312,7 +313,7 @@ void open_decoder_LPD_fx( st->flag_cna = 0; move16(); } - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->flag_cna = 0; st->last_flag_cna = 0; @@ -320,7 +321,7 @@ void open_decoder_LPD_fx( } /* Static vectors to zero */ - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->last_is_cng = 0; @@ -330,26 +331,30 @@ void open_decoder_LPD_fx( move16(); IF( hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); - set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); - set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); + set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); - set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); + set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); hTcxDec->q_synth_history_fx = 0; + move16(); } - set16_fx( st->syn, 0, M + 1 ); + set16_fx( st->syn, 0, add( M, 1 ) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + move16(); mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + move16(); st->con_tcx = 0; + move16(); } ELSE { @@ -409,7 +414,7 @@ void open_decoder_LPD_fx( /*PLC*/ #ifndef NEW_IVAS_OPEN_DEC - IF( st->prev_bfi != 0 ) + IF( NE_16( st->prev_bfi, 0 ) ) { PWord16 const *w; Word16 W1, W2, nz, delay_comp; @@ -418,9 +423,12 @@ void open_decoder_LPD_fx( move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + move16(); nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + move16(); delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + move16(); Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); @@ -428,25 +436,28 @@ void open_decoder_LPD_fx( /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ hHQ_core->Q_old_wtda = -1; + move16(); set16_fx( hHQ_core->old_out_fx, 0, nz ); Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/ FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); + hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, nz )] ) ); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); + hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_fx[add( i, nz )] ) ); } - set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz ); + set16_fx( &hHQ_core->old_out_fx[add( W1, nz )], 0, nz ); lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); + move16(); Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; + move16(); } #else PMT( "acelp_plc_mdct_transition is missing" ) @@ -488,17 +499,17 @@ void open_decoder_LPD_fx( set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ - if ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ #if 0 PMT("to be moved to reset_tcx_overl_buf") #endif } - if ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); @@ -508,16 +519,17 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; } /*OLA for MDCT-LB always reset in codec switching cases*/ - if ( st->hHQ_core != NULL ) + IF( st->hHQ_core != NULL ) { set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } move16(); st->last_core_bfi = TCX_20_CORE; - if ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { st->hPFstat->on = 0; + move16(); } move16(); /* reset CLDFB memories */ @@ -528,7 +540,7 @@ void open_decoder_LPD_fx( #if 0 PMT("cldfbSynHB is missing ") #endif - // if (st->cldfbSynHB != NULL) + // IF (st->cldfbSynHB != NULL) //{ // cldfb_reset_memory(st->cldfbSynHB); // } @@ -540,7 +552,7 @@ void open_decoder_LPD_fx( /* convert quantized LSP vector */ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); - IF( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); } @@ -565,19 +577,21 @@ void open_decoder_LPD_fx( { /*Partial reset of ACELP memories*/ st->rate_switching_reset = 1; + move16(); /*reset partly some memories*/ st->tilt_code_fx = TILT_CODE; + move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, add( M, 1 ) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub( L_SYN_MEM, M ), st->mem_syn2_fx, M ); /*Untouched memories : st->syn */ } @@ -589,7 +603,7 @@ void open_decoder_LPD_fx( test(); test(); - if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) + IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) { st->rate_switching_reset = 1; move16(); @@ -602,37 +616,38 @@ void open_decoder_LPD_fx( /* bass pf reset */ st->bpf_gain_param = 0; move16(); - if ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); } /* Formant postfilter */ - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { /*do nothing*/ } ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) ) { - IF( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { - IF( st->hPFstat->on != 0 ) + IF( NE_16( st->hPFstat->on, 0 ) ) { - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM ); set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); st->hPFstat->reset = 1; + move16(); st->hPFstat->gain_prec = 16384; move16(); } } - ELSE IF( st->hPFstat->on != 0 ) + ELSE IF( NE_16( st->hPFstat->on, 0 ) ) { - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -641,43 +656,45 @@ void open_decoder_LPD_fx( /*reset post-filter except for Narrowband*/ IF( NE_32( st->output_Fs, 8000 ) ) { - if ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { st->hPFstat->reset = 1; - if ( st->hPFstat->on != 0 ) + move16(); + IF( NE_16( st->hPFstat->on, 0 ) ) { st->hPFstat->reset = 0; + move16(); Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } } ELSE { - if ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ } /*feed last value old_synth as it is used for pre-emphasis mem*/ - if ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { - hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; + hTcxDec->old_synth[sub( hTcxDec->old_synth_len, 1 )] = st->syn[M]; } move16(); - if ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { - hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + hBPF->pst_old_syn_fx[sub( NBPSF_PIT_MAX, 1 )] = st->syn[M]; } move16(); } } /* lsf and lsp initialization */ - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); @@ -702,31 +719,31 @@ void open_decoder_LPD_fx( Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768 / 2; + st->last_gain_syn_deemph = 16384; move16(); st->last_gain_syn_deemph_e = 1; move16(); test(); - IF( EQ_16( st->last_codec_mode, MODE1 ) || st->ini_frame == 0 ) + IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16( st->ini_frame, 0 ) ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768 / 2; + st->last_concealed_gain_syn_deemph = 16384; move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); - if ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { - hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/ + hTcxDec->conceal_eof_gain = 16384; /*Q14*/ move16(); } } /* Post processing */ - set16_fx( st->mem_Aq, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, add( M, 1 ) ) ); st->lp_ener_FER_fx = 15360; move16(); /*60 in Q8*/ - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->prev_bfi = 0; move16(); @@ -775,11 +792,11 @@ void open_decoder_LPD_fx( st->prev_widow_left_rect = 0; move16(); - if ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT /* Todo: should be considered for other stereo modes as well */ - if ( is_init || MCT_flag || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) ) + IF( is_init || MCT_flag || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) ) { PMT( "Fixed point to be done" ) st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; @@ -793,8 +810,7 @@ void open_decoder_LPD_fx( #else hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; - move16(); + hTcxDec->conNoiseLevelIndex = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); hTcxDec->conCurrLevelIndex = 0; move16(); hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ @@ -802,7 +818,9 @@ void open_decoder_LPD_fx( set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/ set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); hTcxDec->conLastFrameLevel_e = 0; + move16(); hTcxDec->conCngLevelBackgroundTrace_e = -6; + move16(); hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; #endif @@ -811,14 +829,15 @@ void open_decoder_LPD_fx( st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ + move16(); } @@ -842,14 +861,15 @@ void open_decoder_LPD_fx( move16(); /* TCX-LTP */ - if ( hTcxLtpDec != NULL ) + IF( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); } move16(); test(); - IF( hTcxLtpDec != NULL && ( st->ini_frame == 0 || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) + test(); + IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) { #if 0 PMT("TO be verify, update seems to differ from float") @@ -858,12 +878,12 @@ void open_decoder_LPD_fx( move16(); hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - if ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcxltp_last_gain_unmodified = 0; } move16(); - IF( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); @@ -879,14 +899,15 @@ void open_decoder_LPD_fx( } /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - if ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ } - else + ELSE { st->lp_error_ener = 0; + move16(); } st->mem_error = L_deposit_l( 0 ); st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); @@ -898,7 +919,7 @@ void open_decoder_LPD_fx( st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ move16(); - if ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); @@ -907,7 +928,7 @@ void open_decoder_LPD_fx( move16(); st->p_bpf_noise_buf = NULL; - if ( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { st->p_bpf_noise_buf = st->bpf_noise_buf; } @@ -916,8 +937,8 @@ void open_decoder_LPD_fx( move16(); test(); test(); - if ( EQ_16( bwidth, SWB ) && - ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( EQ_16( bwidth, SWB ) && + ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->tec_tfa = 1; move16(); @@ -950,7 +971,7 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( st->ini_frame == 0 || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( EQ_16( st->ini_frame, 0 ) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { concealment_init_x( hTcxDec->L_frameTCX, &st->plcInfo ); } @@ -961,7 +982,7 @@ void open_decoder_LPD_fx( PMT("handle to tonalMDCTconceal is missing") #endif //#ifdef ADD_IVAS_HTONALMDCTCONC - if ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->tonalMDCTconceal.nScaleFactors = 0; move16(); @@ -980,12 +1001,12 @@ void open_decoder_LPD_fx( st->second_last_tns_active = 0; st->second_last_core = -1; #ifdef NEW_IVAS_OPEN_DEC - if ( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) + IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf ); } #endif - if ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move16(); @@ -997,31 +1018,42 @@ void open_decoder_LPD_fx( test(); test(); test(); - if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) - - if ( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || - ( EQ_32( st->total_brate, 24400 ) ) ) && - st->element_mode == EVS_MONO ) + IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + { + test(); + test(); + test(); + IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || + ( EQ_32( st->total_brate, 24400 ) ) ) && + EQ_16( st->element_mode, EVS_MONO ) ) { move16(); st->dec_glr = 1; } + } move16(); st->dec_glr_idx = 0; - if ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->enableTcxLpc = 1; + move16(); st->VAD = 0; + move16(); hTcxDec->old_gaintcx_bfi = 0; + move16(); hTcxDec->old_gaintcx_bfi_e = 0; + move16(); hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); } #ifndef NEW_IVAS_OPEN_DEC st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); #endif - if ( hTcxLtpDec != NULL ) + IF( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp_gain = 0; + move16(); } return; } @@ -1036,24 +1068,32 @@ void tcxltp_dec_init_fx( const Word32 sr_core ) { hTcxLtpDec->tcxltp_gain = 0; + move16(); hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); - - IF( ini_frame == 0 || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) + test(); + test(); + IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) { hTcxLtpDec->tcxltp_pitch_int = pit_max; + move16(); hTcxLtpDec->tcxltp_pitch_fr = 0; + move16(); - IF( ini_frame == 0 ) + IF( EQ_16( ini_frame, 0 ) ) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; + move16(); hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; + move16(); hTcxLtpDec->tcxltp_gain_post_prev = 0; + move16(); hTcxLtpDec->tcxltp_filt_idx_prev = -1; + move16(); } } @@ -1071,7 +1111,8 @@ void acelp_plc_mdct_transition_fx( Word16 i; /*PLC*/ - IF( st->prev_bfi != 0 && st->hTcxCfg != NULL ) + test(); + IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL ) { W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); @@ -1079,29 +1120,33 @@ void acelp_plc_mdct_transition_fx( w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + move16(); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); + move16(); /*CLDFB delay*/ Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ st->hHQ_core->Q_old_wtda = -1; + move16(); set16_fx( st->hHQ_core->old_out_fx, 0, nz ); // Q_old_out is 0 Copy_Scale_sig( st->hHQ_core->fer_samples_fx + delay_comp, st->hHQ_core->old_out_fx + nz, W1, st->hHQ_core->Q_old_wtda ); /*Q-1*/ FOR( i = 0; i < W2; i++ ) { - st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[add( i, nz )] ) ); } FOR( ; i < W1; i++ ) { - st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), st->hHQ_core->old_out_fx[add( i, nz )] ) ); } - set16_fx( &st->hHQ_core->old_out_fx[W1 + nz], 0, nz ); + set16_fx( &st->hHQ_core->old_out_fx[add( W1, nz )], 0, nz ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX ); Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + move16(); Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; } @@ -1147,6 +1192,7 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/ { st->fscale_old = st->fscale; + move16(); } st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); @@ -1159,15 +1205,16 @@ void open_decoder_LPD_ivas_fx( { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); - move16(); } IF( st->hTcxDec != NULL ) { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); IF( EQ_16( st->ini_frame, 0 ) ) { st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + move16(); } } @@ -1175,15 +1222,26 @@ void open_decoder_LPD_ivas_fx( move16(); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( NE_16( st->tcxonly, 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; + move16(); } ELSE { st->nb_subfr = NB_SUBFR; + move16(); } st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ // assert(FSCALE_DENOM == 512); @@ -1191,9 +1249,11 @@ void open_decoder_LPD_ivas_fx( // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f)); st->TcxBandwidth = getTcxBandwidth( bwidth ); st->narrowBand = 0; + move16(); IF( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; + move16(); } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1220,15 +1280,16 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { st->pit_res_max_past = st->pit_res_max; + move16(); } /*Preemphasis param*/ - IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) /*To be replaced with basops*/ + IF( LT_16( st->fscale, 640 ) ) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE IF( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); @@ -1236,11 +1297,13 @@ void open_decoder_LPD_ivas_fx( ELSE { st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ + move16(); } // gamma_float to be removed later st->inv_gamma = GAMMA1_INV; move16(); + test(); IF( EQ_32( st->sr_core, INT_FS_16k ) ) { st->gamma = GAMMA16k; @@ -1262,35 +1325,43 @@ void open_decoder_LPD_ivas_fx( } /* LPC quantization */ + test(); IF( LE_32( st->sr_core, INT_FS_16k ) && EQ_16( st->tcxonly, 0 ) ) { st->lpcQuantization = 1; + move16(); } ELSE { st->lpcQuantization = 0; + move16(); } IF( EQ_16( st->tcxonly, 0 ) ) { st->numlpc = 1; + move16(); } ELSE { st->numlpc = 2; + move16(); } /* Initialize TBE */ st->prev_coder_type = GENERIC; + move16(); IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub( LPC_SHB_ORDER, 2 ) ); hBWE_TD->prev_tilt_para_fx = 0; - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + move16(); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add( M, 1 ) ); } IF( st->hIGFDec != NULL ) { + test(); IF( !is_init || NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { init_tcx_cfg_fx( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag, fscaleFB ); @@ -1298,7 +1369,10 @@ void open_decoder_LPD_ivas_fx( ELSE { st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + move16(); + move16(); st->hTcxCfg->last_aldo = 1; + move16(); } } IF( st->hTECDec != NULL ) @@ -1321,6 +1395,7 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { st->flag_cna = 0; + move16(); st->last_flag_cna = 0; move16(); } @@ -1337,18 +1412,22 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { reset_tcx_overl_buf_fx( st->hTcxDec ); - set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); + set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); + set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); hTcxDec->q_synth_history_fx = 0; + move16(); } - set16_fx( st->syn, 0, M + 1 ); + set16_fx( st->syn, 0, add( M, 1 ) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + move16(); mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + move16(); st->con_tcx = 0; + move16(); } ELSE { @@ -1381,6 +1460,7 @@ void open_decoder_LPD_ivas_fx( } /*Mode 1/2 switching*/ + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); @@ -1408,15 +1488,21 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL ) { acelp_plc_mdct_transition_fx( st ); - *Q_syn_Overl_TDAC = *Q_fer_samples - 1; + *Q_syn_Overl_TDAC = sub( *Q_fer_samples, 1 ); *Q_syn_Overl = *Q_fer_samples; - *Q_syn_Overl_TDACFB = *Q_fer_samples - 1; + move16(); + *Q_syn_Overl_TDACFB = sub( *Q_fer_samples, 1 ); *Q_syn_OverlFB = *Q_fer_samples; - *Q_old_out = *Q_fer_samples - 1; - *Q_old_outLB = *Q_fer_samples - 1; + move16(); + *Q_old_out = sub( *Q_fer_samples, 1 ); + *Q_old_outLB = sub( *Q_fer_samples, 1 ); } } - + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_codec_mode, MODE2 ) && NE_16( st->L_frame, st->last_L_frame ) && ( ( EQ_16( st->m_frame_type, SID_FRAME ) && GT_16( st->last_core, ACELP_CORE ) ) || ( GT_16( st->last_core, ACELP_CORE ) && GT_16( st->core, ACELP_CORE ) ) || st->prev_bfi ) ) @@ -1425,16 +1511,23 @@ void open_decoder_LPD_ivas_fx( } /* Rate switching */ + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { /* Switching from MDCT */ /*Reset of ACELP memories*/ st->rate_switching_reset = 1; + move16(); // To be removed later st->tilt_code_fx = TILT_CODE; + move16(); set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); - set16_fx( st->syn, 0, 1 + M ); + set16_fx( st->syn, 0, add( 1, M ) ); set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ @@ -1446,10 +1539,14 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxCfg != NULL ) { hHQ_core->Q_old_wtda = -1; /*To be removed later when hHQ_core->Q_old_wtda vaue is updated*/ + move16(); Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); *Q_syn_OverlFB = *Q_old_out; + move16(); st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + move16(); st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + move16(); } /*OLA for Mode 2 TCX always reset in Mode switching cases*/ @@ -1459,10 +1556,12 @@ void open_decoder_LPD_ivas_fx( } st->last_core_bfi = TCX_20_CORE; + move16(); IF( st->hPFstat != NULL ) { st->hPFstat->on = 0; + move16(); } /* reset CLDFB memories */ @@ -1492,6 +1591,7 @@ void open_decoder_LPD_ivas_fx( Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); *Q_old_Aq_12_8 = 14; + move16(); IF( !st->last_con_tcx ) { ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC, st->Q_syn ); @@ -1503,19 +1603,21 @@ void open_decoder_LPD_ivas_fx( { /*Partial reset of ACELP memories*/ st->rate_switching_reset = 1; + move16(); /*reset partly some memories*/ st->tilt_code_fx = TILT_CODE; + move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, add( M, 1 ) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub( L_SYN_MEM, M ), st->mem_syn2_fx, M ); } /* update of lsf_old only needed in BASOP */ /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1523,7 +1625,8 @@ void open_decoder_LPD_ivas_fx( /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ /* } */ } - + test(); + test(); IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && NE_16( st->ini_frame, 0 ) ) { st->rate_switching_reset = 1; @@ -1538,6 +1641,7 @@ void open_decoder_LPD_ivas_fx( /* bass pf reset */ st->bpf_gain_param = 0; + move16(); IF( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); @@ -1554,8 +1658,8 @@ void open_decoder_LPD_ivas_fx( { IF( st->hPFstat->on ) { - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { @@ -1568,8 +1672,8 @@ void open_decoder_LPD_ivas_fx( } ELSE IF( st->hPFstat->on ) { - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -1577,20 +1681,22 @@ void open_decoder_LPD_ivas_fx( /*codec mode switching*/ /*reset post-filter except for Narrowband*/ - IF( NE_32( st->output_Fs, L_FRAME8k * FRAMES_PER_SEC ) ) + IF( NE_32( st->output_Fs, i_mult( L_FRAME8k, FRAMES_PER_SEC ) ) ) { IF( st->hPFstat != NULL ) { st->hPFstat->reset = 1; - IF( st->hPFstat->on != 0 ) + move16(); + IF( NE_16( st->hPFstat->on, 0 ) ) { st->hPFstat->reset = 0; + move16(); //-------------Present in EVS // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ //-------------- - lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } } @@ -1607,11 +1713,11 @@ void open_decoder_LPD_ivas_fx( /*feed last value old_synth as it is used for pre-emphasis mem*/ IF( st->hTcxDec != NULL ) { - st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; + st->hTcxDec->old_synth[sub( st->hTcxDec->old_synth_len, 1 )] = st->syn[M]; } IF( st->hBPF != NULL ) { - st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + st->hBPF->pst_old_syn_fx[sub( NBPSF_PIT_MAX, 1 )] = st->syn[M]; } } } @@ -1634,45 +1740,54 @@ void open_decoder_LPD_ivas_fx( E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M ); E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); st->plcBackgroundNoiseUpdated = 0; + move16(); Copy( st->lsf_old_fx, st->lsf_q_cng, M ); Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); Copy( st->lsp_old_fx, st->lsp_q_cng, M ); Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/ - + st->last_gain_syn_deemph = 16384; /* 1.f Q14*/ + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16( st->ini_frame, 0 ) ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768 / 2; - move16(); + st->last_concealed_gain_syn_deemph = 16384; st->last_concealed_gain_syn_deemph_e = 1; move16(); IF( hTcxDec != NULL ) { - hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/ + hTcxDec->conceal_eof_gain = 16384; /*Q14*/ } } /* Post processing */ - set16_fx( st->mem_Aq, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, add( M, 1 ) ) ); st->lp_ener_FER_fx = 15360; /*60.0f Q8*/ + move16(); IF( EQ_16( st->ini_frame, 0 ) ) { st->prev_bfi = 0; + move16(); st->last_core_bfi = -1; + move16(); IF( st->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 0; + move16(); } } st->prev_old_bfi = 0; + move16(); IF( st->hTcxDec != NULL ) { st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; + move16(); + move16(); st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; + move16(); + move16(); set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); } @@ -1681,10 +1796,12 @@ void open_decoder_LPD_ivas_fx( Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); st->clas_dec = UNVOICED_CLAS; + move16(); IF( !st->last_con_tcx ) { - st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + st->old_enr_LP = 0; + move16(); /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } IF( st->prev_bfi ) @@ -1693,12 +1810,14 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) ) { st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } } ELSE { - st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + st->last_good = UNVOICED_CLAS; + move16(); /* last good received frame for concealment */ st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ } st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -1709,10 +1828,13 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { st->hTcxDec->prev_widow_left_rect = 0; - + move16(); + test(); + test(); + test(); IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) ) { - st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; + st->hTcxDec->NoiseLevelIndex_bfi = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); @@ -1722,7 +1844,7 @@ void open_decoder_LPD_ivas_fx( hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + hTcxDec->conNoiseLevelIndex = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); move16(); hTcxDec->conCurrLevelIndex = 0; move16(); @@ -1731,26 +1853,33 @@ void open_decoder_LPD_ivas_fx( set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/ set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); hTcxDec->conLastFrameLevel_e = 0; + move16(); hTcxDec->conCngLevelBackgroundTrace_e = -6; + move16(); hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; + move16(); } } st->cummulative_damping = 32767 /*1.0f Q15*/; + move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { - st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; + move16(); /*Q14*/ } st->old_fpitch = L_deposit_h( st->pit_min ); st->rate_switching_init = 1; + move16(); st->reset_mem_AR = 0; + move16(); /* For phase dispersion */ st->dm_fx.prev_gain_code = L_deposit_l( 0 ); @@ -1769,26 +1898,31 @@ void open_decoder_LPD_ivas_fx( IF( hTcxDec != NULL ) { st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX ); - + test(); + test(); IF( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) { hTcxDec->tcxltp_last_gain_unmodified = 0; + move16(); } /* TCX */ hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); hTcxDec->envWeighted = 0; + move16(); } IF( st->hBPF != NULL ) { st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ hBPF->pst_mem_deemp_err_fx = 0; + move16(); } ELSE { st->lp_error_ener = 0; + move32(); } st->mem_error = L_deposit_l( 0 ); IF( st->tcxonly ) @@ -1799,31 +1933,47 @@ void open_decoder_LPD_ivas_fx( ELSE { st->p_bpf_noise_buf = st->bpf_noise_buf; + move32(); st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; + move32(); } + test(); + test(); + test(); IF( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->tec_tfa = 1; + move16(); } ELSE { st->tec_tfa = 0; + move16(); } st->tec_flag = 0; + move16(); st->tfa_flag = 0; + move16(); /* needed in decoder to read the bitstream */ st->enableGplc = 0; + move16(); st->flagGuidedAcelp = 0; + move16(); st->tonal_mdct_plc_active = 0; + move16(); st->T0_4th = L_SUBFR; + move16(); st->guidedT0 = st->T0_4th; - + move16(); + test(); + test(); IF( st->hPlcInfo != NULL && GE_32( total_brate, HQ_48k ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->enablePlcWaveadjust = 1; + move16(); IF( st->hTcxDec != NULL && ( EQ_16( st->ini_frame, 0 ) || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) ) { @@ -1833,22 +1983,34 @@ void open_decoder_LPD_ivas_fx( ELSE { st->enablePlcWaveadjust = 0; + move16(); } /* PLC: [TCX: Tonal Concealment] */ + test(); + test(); + test(); IF( st->hTonalMDCTConc != NULL && !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->hTonalMDCTConc->nScaleFactors = 0; + move16(); st->hTonalMDCTConc->nSamples = 0; + move16(); st->hTonalMDCTConc->lastPcmOut = 0x0; + move16(); st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; + move16(); st->hTonalMDCTConc->lastBlockData.nSamples = 0; + move16(); TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } st->last_tns_active = 0; + move16(); st->second_last_tns_active = 0; + move16(); st->second_last_core = -1; + move16(); IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { @@ -1861,31 +2023,43 @@ void open_decoder_LPD_ivas_fx( hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; move16(); } - + test(); + test(); + test(); + test(); IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_32( st->element_mode, EVS_MONO ) ) { st->dec_glr = 1; + move16(); } ELSE { st->dec_glr = 0; + move16(); } st->dec_glr_idx = 0; + move16(); st->VAD = 0; + move16(); IF( hTcxDec != NULL ) { hTcxDec->enableTcxLpc = 1; + move16(); hTcxDec->old_gaintcx_bfi = 0; + move16(); hTcxDec->old_gaintcx_bfi_e = 0; + move16(); hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); } IF( st->hTcxCfg != NULL ) { st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); } return; diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index bb2f4c404498c995a51df295695b9b27384c93d7..5682809484e7700f131eb4c1c3bb02c6649e6e13 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -27,6 +27,7 @@ void reconfig_decoder_LPD_ivas_fx( Word32 lowrate_tcxlpc_max_br; move16(); st->bits_frame = bits_frame; + move16(); IF( EQ_16( bwidth, NB ) ) { @@ -43,14 +44,23 @@ void reconfig_decoder_LPD_ivas_fx( /*Configuration of partial copy*/ st->acelp_cfg_rf.mode_index = 1; + move16(); st->acelp_cfg_rf.midLpc = 0; + move16(); st->acelp_cfg_rf.midLpc_enable = 0; + move16(); st->acelp_cfg_rf.pre_emphasis = 0; + move16(); st->acelp_cfg_rf.formant_enh = 1; + move16(); st->acelp_cfg_rf.formant_tilt = 1; + move16(); st->acelp_cfg_rf.voice_tilt = 1; + move16(); st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + move16(); st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) { @@ -82,7 +92,7 @@ void reconfig_decoder_LPD_ivas_fx( { IF( st->rf_flag ) { - i--; + i = sub( i, 1 ); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -142,10 +152,12 @@ void reconfig_decoder_LPD_ivas_fx( { oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLen = L_SYN_MEM_CLAS_ESTIM; + move16(); } ELSE { oldLen = L_SYN_MEM_CLAS_ESTIM; + move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } lerp( &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, oldLen )], &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, newLen )], newLen, oldLen ); @@ -172,6 +184,7 @@ void reconfig_decoder_LPD_ivas_fx( { hTcxDec->envWeighted = 0; move16(); + move16(); } return; @@ -205,7 +218,7 @@ void reconfig_decoder_LPD_fx( move16(); st->narrowBand = 1; } - ELSE if ( GT_16( bwidth, NB ) ) + ELSE IF( GT_16( bwidth, NB ) ) { move16(); st->narrowBand = 0; @@ -215,14 +228,23 @@ void reconfig_decoder_LPD_fx( /*Configuration of partial copy*/ st->acelp_cfg_rf.mode_index = 1; + move16(); st->acelp_cfg_rf.midLpc = 0; + move16(); st->acelp_cfg_rf.midLpc_enable = 0; + move16(); st->acelp_cfg_rf.pre_emphasis = 0; + move16(); st->acelp_cfg_rf.formant_enh = 1; + move16(); st->acelp_cfg_rf.formant_tilt = 1; + move16(); st->acelp_cfg_rf.voice_tilt = 1; + move16(); st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + move16(); st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) @@ -238,7 +260,7 @@ void reconfig_decoder_LPD_fx( } move16(); - if ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { Word16 i; @@ -247,7 +269,7 @@ void reconfig_decoder_LPD_fx( test(); IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) ) { - Word16 scaleTableSize = sizeof( scaleTcxTable ) / sizeof( scaleTcxTable[0] ); /* is a constant */ + Word16 scaleTableSize = idiv1616( sizeof( scaleTcxTable ), sizeof( scaleTcxTable[0] ) ); /* is a constant */ FOR( i = 0; i < scaleTableSize; i++ ) { @@ -257,9 +279,9 @@ void reconfig_decoder_LPD_fx( ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - if ( st->rf_flag ) + IF( st->rf_flag ) { - i--; + i = sub( i, 1 ); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -270,7 +292,7 @@ void reconfig_decoder_LPD_fx( } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF( st->ini_frame != 0 ) + IF( NE_16( st->ini_frame, 0 ) ) { test(); test(); @@ -320,10 +342,12 @@ void reconfig_decoder_LPD_fx( oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLen = L_SYN_MEM_CLAS_ESTIM; move16(); + move16(); } ELSE { oldLen = L_SYN_MEM_CLAS_ESTIM; + move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } lerp( &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, oldLen )], &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, newLen )], newLen, oldLen ); @@ -345,9 +369,10 @@ void reconfig_decoder_LPD_fx( IF( GT_16( st->element_mode, IVAS_SCE ) ) { lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; + move16(); } hTcxDec->enableTcxLpc = EQ_16( st->numlpc, 1 ) && EQ_16( st->lpcQuantization, 1 ) && ( LE_32( total_brate, lowrate_tcxlpc_max_br ) /*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag ); - if ( st->ini_frame == 0 ) + IF( EQ_16( st->ini_frame, 0 ) ) { hTcxDec->envWeighted = 0; move16(); diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 5241b42e07381ee107bdbc1cc38a22d21e6d0926..2316e9c096a242e91f89b3700f40f46aadab2afa 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -47,7 +47,7 @@ void mode_switch_decoder_LPD_fx( bSwitchFromAmrwbIO = 0; move16(); - if ( EQ_16( st->last_core, AMR_WB_CORE ) ) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; move16(); @@ -62,12 +62,12 @@ void mode_switch_decoder_LPD_fx( st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); test(); test(); - IF( ( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, ( FSCALE_DENOM * 16000 ) / 12800 ) ) && ( EQ_16( fscale, st->fscale ) ) ) ) + IF( ( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, 640 ) ) && ( EQ_16( fscale, st->fscale ) ) ) ) { test(); test(); test(); - if ( ( ( GT_32( total_brate, 32000 ) ) && ( st->tcxonly == 0 ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( st->tcxonly != 0 ) ) ) + IF( ( ( GT_32( total_brate, 32000 ) ) && ( EQ_16( st->tcxonly, 0 ) ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( NE_16( st->tcxonly, 0 ) ) ) ) { switchWB = 1; move16(); @@ -75,7 +75,7 @@ void mode_switch_decoder_LPD_fx( } test(); - if ( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) + IF( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) { switchWB = 1; move16(); @@ -100,7 +100,7 @@ void mode_switch_decoder_LPD_fx( test(); test(); test(); - IF( NE_16( fscale, st->fscale ) || switchWB != 0 || bSwitchFromAmrwbIO != 0 || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( NE_16( fscale, st->fscale ) || NE_16( switchWB, 0 ) || NE_16( bSwitchFromAmrwbIO, 0 ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT open_decoder_LPD_fx( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); @@ -136,7 +136,7 @@ void mode_switch_decoder_LPD_fx( st->narrowBand = 0; move16(); - if ( EQ_16( bwidth, NB ) ) + IF( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -149,7 +149,7 @@ void mode_switch_decoder_LPD_fx( st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); move16(); - IF( st->hTcxCfg->fIsTNSAllowed != 0 && st->hIGFDec != NULL ) + IF( NE_16( st->hTcxCfg->fIsTNSAllowed, 0 ) && st->hIGFDec != NULL ) { InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); #ifdef IVAS_CODE @@ -165,7 +165,7 @@ void mode_switch_decoder_LPD_fx( reconfig_decoder_LPD_fx( st, frame_size, bwidth, total_brate, st->last_L_frame ); test(); - IF( hTcxDec->envWeighted != 0 && hTcxDec->enableTcxLpc == 0 ) + IF( NE_16( hTcxDec->envWeighted, 0 ) && EQ_16( hTcxDec->enableTcxLpc, 0 ) ) { Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); @@ -174,7 +174,7 @@ void mode_switch_decoder_LPD_fx( } /* update PLC LSF memories */ - IF( st->tcxonly == 0 ) + IF( EQ_16( st->tcxonly, 0 ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l( st->sr_core ) ); } @@ -185,7 +185,7 @@ void mode_switch_decoder_LPD_fx( Copy( st->lsfoldbfi1_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx, M ); - IF( st->igf != 0 && hBWE_TD != NULL ) + IF( NE_16( st->igf, 0 ) && hBWE_TD != NULL ) { test(); test(); @@ -217,7 +217,7 @@ void mode_switch_decoder_LPD_fx( test(); IF( ( EQ_16( bwidth, SWB ) ) && ( EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { - IF( st->tec_tfa == 0 ) + IF( EQ_16( st->tec_tfa, 0 ) ) { set16_fx( st->hTECDec->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); } @@ -304,12 +304,12 @@ void mode_switch_decoder_LPD_ivas_fx( test(); test(); - IF( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, ( FSCALE_DENOM * 16000 ) / 12800 ) ) && ( EQ_16( fscale, st->fscale ) ) ) + IF( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, 640 ) ) && ( EQ_16( fscale, st->fscale ) ) ) { test(); test(); test(); - IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( st->tcxonly == 0 ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) + IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( EQ_16( st->tcxonly, 0 ) ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) { switchWB = 1; move16(); @@ -328,12 +328,13 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hIGFDec != NULL ) { st->hIGFDec->infoIGFStopFreq = -1; + move16(); } move16(); test(); test(); - IF( st->igf && ( st->idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) + IF( st->igf && ( EQ_16( st->idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ IGFDecSetMode_ivas_fx( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); @@ -360,6 +361,7 @@ void mode_switch_decoder_LPD_ivas_fx( { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); } IF( st->hTcxCfg != NULL ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 148c40a3cd4afcb239d8e9f1017256148bd6afeb..afaa9d78abf31a62210c7b9f6716e57d12452751 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3219,32 +3219,21 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - float *output_f[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal */ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; UWord16 slot_size, n_samples_sf, ch, nchan_intern; Word16 temp = 0; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - float *output_f_local[MAX_OUTPUT_CHANNELS]; -#ifdef MSAN_FIX - float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV -#else - float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV -#endif - Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV - Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; + Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); FOR( ch = 0; ch < nchan_intern; ch++ ) { - output_f_local[ch] = output_f_local_buff[ch]; - set_zero( output_f_local_buff[ch], nSamplesAsked ); - output_f_local_fx[ch] = output_f_local_buff_fx[ch]; set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); } @@ -3271,7 +3260,7 @@ void ivas_dirac_dec_render_fx( FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { #ifdef MSAN_FIX - ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, output_f_local_fx, nchan_transport, NULL, NULL ); + ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local_fx, nchan_transport, NULL, NULL ); #else ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, nchan_transport, NULL, NULL ); #endif // MSAN_FIX @@ -3280,7 +3269,6 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { - output_f_local[ch] += n_samples_sf; output_f_local_fx[ch] += n_samples_sf; } @@ -3292,7 +3280,6 @@ void ivas_dirac_dec_render_fx( { IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) { - mvr2r( output_f_local_buff[ch], output_f[ch], *nSamplesRendered ); Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); } } @@ -3405,11 +3392,8 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#ifdef MSAN_FIX + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX const Word16 nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) @@ -4993,7 +4977,6 @@ void ivas_dirac_dec_render_sf_fx( { scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; - fixedToFloat_arrL( output_buf_fx[i], output_f[i], Q11, index_slot * hSpatParamRendCom->num_freq_bands + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] ); } } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -5054,44 +5037,15 @@ void ivas_dirac_dec_render_sf_fx( Word16 tmp_lfe_idx = 0; for ( ch = 0; ch < outchannels; ch++ ) { - // fixedToFloat_arrL(output_buf_fx[i], output_f[i], Q11, index_slot * hSpatParamRendCom->num_freq_bands + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]); IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) ) { - IF( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled ) - { - // Fixed to float - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands + index_slot * hSpatParamRendCom->num_freq_bands ); - } - ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA && hDirACRend->hOutSetup.separateChannelEnabled ) - { - /* LFE has been synthesized in the time domain, do nothing. */ - } - ELSE - { - // Float to fixed. - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands + index_slot * hSpatParamRendCom->num_freq_bands ); - } IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { tmp_lfe_idx = add( tmp_lfe_idx, 1 ); } } - ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) - { - /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated - * channel is combined with the synthesized channels here. */ - } - ELSE - { - // Fixed to float - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands ); - } } } - else - { - /* NOTE: according to line coverage report this part is not being hit by any test case. Not adding fixed to float conversion here. */ - } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5b5fcfb55c21b5e2a4df246bc21bb96bdd9821f2..9d528f8df45ee6c4ca1d8b02a8a9c9711e4f4e41 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -4638,9 +4638,6 @@ void ivas_destroy_dec( } ELSE IF( st_ivas->hHrtfTD != NULL ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); -#endif BSplineModelEvalDealloc_fx( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD ); } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 7002b0453461b0fd000626557bed47dd9b002856..bb7d374a9c72d6e3948cbb4ec80da393c28f7963 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2566,26 +2566,22 @@ void ivas_jbm_dec_feed_tc_to_renderer( * Principal IVAS JBM rendering routine *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const uint16_t nSamplesAsked, /* i : number of samples wanted */ - uint16_t *nSamplesRendered, /* o : number of samples rendered */ - uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - int16_t *data /* o : output synthesis signal */ +ivas_error ivas_jbm_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal */ ) { - int16_t n, nchan_out; - int16_t nchan_transport; - int16_t nchan_remapped; - int32_t output_Fs; + Word16 n, nchan_out; + Word16 nchan_transport; + Word16 nchan_remapped; + Word32 output_Fs; AUDIO_CONFIG output_config; - int16_t nSamplesAskedLocal; + Word16 nSamplesAskedLocal; ivas_error error; - float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; - // float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 tmp_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; - Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; Word16 subframe_len, gd_bits, exp, nchan_in, i, j; const Word16 output_q_factor = Q11; @@ -2598,35 +2594,35 @@ ivas_error ivas_jbm_dec_render( hSpatParamRendCom = st_ivas->hSpatParamRendCom; output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); nchan_out = st_ivas->hDecoderConfig->nchan_out; + move16(); nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm; + move16(); output_config = st_ivas->hDecoderConfig->output_config; + move32(); nSamplesAskedLocal = nSamplesAsked + st_ivas->hTcBuffer->n_samples_discard; + move16(); - for ( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { - p_output[n] = st_ivas->p_output_f[n]; p_output_fx[n] = st_ivas->p_output_fx[n]; } - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - p_temp_fx[i] = tmp_buffer_fx[i]; - } - if ( !st_ivas->hDecoderConfig->Opt_tsm ) + IF( !st_ivas->hDecoderConfig->Opt_tsm ) { - for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) + FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) { p_tc_fx[n] = p_output_fx[n]; } - for ( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; } } - else + ELSE { - for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) + FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) { p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered]; } @@ -2634,15 +2630,16 @@ ivas_error ivas_jbm_dec_render( #ifdef MSAN_FIX st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full; + move16(); #endif // MSAN_FIX /*----------------------------------------------------------------* * Update combined orientation access index *----------------------------------------------------------------*/ - if ( st_ivas->hCombinedOrientationData != NULL ) + IF( st_ivas->hCombinedOrientationData != NULL ) { /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */ - st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start -= st_ivas->hTcBuffer->n_samples_discard; + st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard ); ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); } @@ -2650,184 +2647,81 @@ ivas_error ivas_jbm_dec_render( /*----------------------------------------------------------------* * Rendering *----------------------------------------------------------------*/ - - if ( st_ivas->ivas_format == UNDEFINED_FORMAT ) + test(); + IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) { assert( 0 ); } - else if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER ) + ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) { Word16 slot_size, tmp, e; slot_size = st_ivas->hTcBuffer->n_samples_granularity; + move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); tmp = shr( tmp, sub( 15, e ) ); - // slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); - FOR( Word16 ind = 0; ind < st_ivas->hTcBuffer->nchan_transport_jbm; ind++ ) - { - floatToFixed_arrL( p_output[ind], p_output_fx[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); - } ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); - - FOR( Word16 ind = 0; ind < st_ivas->hTcBuffer->nchan_transport_jbm; ind++ ) - { - fixedToFloat_arrL( p_output_fx[ind], p_output[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); - } } - else if ( st_ivas->ivas_format == STEREO_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_MC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - Word16 q; - q = 11; + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { /* Rendering */ - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output_fx[0][lp] = (Word32) ( p_output[0][lp] * ( 1u << 11 ) ); - p_output_fx[1][lp] = (Word32) ( p_output[1][lp] * ( 1u << 11 ) ); - } + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output[0][lp] = (float) p_output_fx[0][lp] / ( 1u << 11 ); - p_output[1][lp] = (float) p_output_fx[1][lp] / ( 1u << 11 ); - } } - else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { - Word32 output_fx_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word16 ch; - Word32 *p_output_fx_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - FOR( Word16 lp = 0; lp < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; lp++ ) - { - p_output_fx_tmp[lp] = &output_fx_tmp[lp][0]; - } - - Word16 Q_p_output_buf = Q11; - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx_tmp[i], Q_p_output_buf, L_FRAME48k ); - } - /*-------------------------------------------flt 2 fix----------------------------------------------------------*/ - /*-----following buffers and values are getting used in the function and hence are in the intermediate conv-----*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin-------------------------------------norm-Q-*/ - /*i/o : st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old---------------------------------norm-Q-*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->interpolator------------------------------------------Q14----*/ - /*i/o : st_ivas->hParamIsmDec->azimuth_values------------------------------------------------------------Q22----*/ - /*i/o : st_ivas->hParamIsmDec->elevation_values----------------------------------------------------------Q22----*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc-----------------------------------norm-Q-*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc-----------------------------------norm-Q-*/ - /*i/o : st_ivas->cldfbSynDec[ch]->cldfb_state------------------------------------------------------------Q11----*/ - /*--------------------------------------------------------------------------------------------------------------*/ - - Word16 n_out; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) - { - n_out = st_ivas->nchan_ism; - } - else - { - n_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; - } - - /*-------------------------------------flt 2 fix----------------------------------------------------------*/ - - ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx_tmp ); - - /*-----------------------------------------fix 2 flt--------------------------------------------*/ - for ( ch = 0; ch < n_out; ch++ ) - { - fixedToFloat_arrL( p_output_fx_tmp[ch], p_output[ch], Q11, L_FRAME48k ); - } - /*-----------------------------------------fix 2 flt--------------------------------------------*/ + ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { /* Convert CICP19 -> Ambisonics */ -#if 1 - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered ); - } -#endif ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } } } - else /* ISM_MODE_DISC */ + ELSE /* ISM_MODE_DISC */ { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + test(); + test(); /* Loudspeaker or Ambisonics rendering */ - if ( st_ivas->renderer_type == RENDERER_TD_PANNING || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - Word16 q = 11; ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } } - else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output_fx[0][lp] = (Word32) ( p_output[0][lp] * ( 1u << 11 ) ); - p_output_fx[1][lp] = (Word32) ( p_output[1][lp] * ( 1u << 11 ) ); - } Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output[0][lp] = (float) p_output_fx[0][lp] / ( 1u << 11 ); - p_output[1][lp] = (float) p_output_fx[1][lp] / ( 1u << 11 ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */ #ifdef MSAN_FIX @@ -2835,8 +2729,10 @@ ivas_error ivas_jbm_dec_render( { FOR( j = 0; j < 16; j++ ) { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); } } #else @@ -2849,21 +2745,23 @@ ivas_error ivas_jbm_dec_render( } } #endif - Word16 Q_buffer_in = 11; ivas_ism2sba_sf_fx( st_ivas->hTcBuffer->tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order ); Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); FOR( j = 0; j < sba_num_chans; j++ ) { - fixedToFloat_arrL( p_output_fx[j], p_output[j], Q_buffer_in + 29 - 31, *nSamplesRendered ); + scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); } + #ifdef MSAN_FIX FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { FOR( j = 0; j < 16; j++ ) { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); } } #else @@ -2879,566 +2777,315 @@ ivas_error ivas_jbm_dec_render( } /* Binaural rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output_fx[i][j] = floatToFixed( p_output[i][j], Q11 ); - } - } IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } - - // Fixed to float - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); gd_bits = find_guarded_bits_fx( subframe_len ); exp = 13; + move16(); nchan_in = 12; + move16(); nchan_out = 2; - exp -= gd_bits; + move16(); + exp = sub( exp, gd_bits ); *st_ivas->hCrendWrapper->p_io_qfactor = exp; - for ( i = 0; i < nchan_in; i++ ) + move16(); + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - - p_temp_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); } - if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < nchan_out; i++ ) + FOR( i = 0; i < nchan_out; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - - p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); } } } } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { nchan_remapped = nchan_transport; - + move16(); + test(); + test(); /* Loudspeakers, Ambisonics or Binaural rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - for ( n = 0; n < nchan_remapped; n++ ) + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + FOR( n = 0; n < nchan_remapped; n++ ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); -#endif } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } -#if 1 // To Be removed - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif -#else - if ( ( error = ivas_sba_linear_renderer( p_output, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); } } - else + ELSE { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif } } - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nchan_remapped = st_ivas->nchan_transport; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + move16(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( error = ivas_omasa_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ) ) != IVAS_ERR_OK ) - { - return error; - } -#else IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ) != IVAS_ERR_OK ) { return error; } - - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } } - else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - ivas_omasa_dirac_rend_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); + ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); } } - else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { nchan_remapped = nchan_transport; - + move16(); /* Loudspeakers, Ambisonics or Binaural rendering */ - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // IF( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, output_q_factor, 960 ) ) != IVAS_ERR_OK ) { return error; } - -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - -#if 1 /*TODO: remove fixed to float conversions */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_OSBA_STEREO ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + test(); /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/ - if ( st_ivas->nchan_ism == 1 && st_ivas->hDecoderConfig->Opt_tsm == 0 ) + IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) { -#ifdef IVAS_FLOAT_FIXED Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered ); Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered ); p_tc_fx[1] = p_output_fx[2]; p_tc_fx[2] = p_output_fx[3]; - - fixedToFloat_arrL( p_output_fx[2], p_output[2], 11, *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[3], p_output[3], 11, *nSamplesRendered ); -#else - mvr2r( p_tc[2], p_output[3], *nSamplesRendered ); - mvr2r( p_tc[1], p_output[2], *nSamplesRendered ); - p_tc[1] = p_output[2]; - p_tc[2] = p_output[3]; -#endif } /* render objects */ - Word16 q = 11; ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } /* add already rendered SBA part */ - for ( n = 0; n < nchan_out; n++ ) + FOR( n = 0; n < nchan_out; n++ ) { -#ifdef IVAS_FLOAT_FIXED v_add_fixed( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered, 0 ); - - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, *nSamplesRendered ); -#else - v_add( p_output[n], p_tc[n + st_ivas->nchan_ism], p_output[n], *nSamplesRendered ); -#endif } } - else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - Word16 q = 11; IF( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ) != IVAS_ERR_OK ) { return error; } - q = Q11; - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } } - else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); -#endif } } - else + ELSE { - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); - } -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else + ELSE { - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) { - mvr2r( p_output[n], p_output[n + st_ivas->nchan_ism], *nSamplesRendered ); + Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); } - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - set_zero( p_output[n], *nSamplesRendered ); + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } } } } - else if ( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { - int16_t crendInPlaceRotation = FALSE; - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - if ( st_ivas->transport_config != st_ivas->intern_config && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) ) + Word16 crendInPlaceRotation = FALSE; + move16(); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + + test(); + test(); + test(); + IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { - if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ) + IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) { crendInPlaceRotation = TRUE; -#ifdef IVAS_FLOAT_FIXED + move16(); + ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); -#if 1 - FOR( i = 0; i < ( st_ivas->hIntSetup.ambisonics_order + 1 ) * ( st_ivas->hIntSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hTransSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE ); -#endif // IVAS_FLOAT_FIXED } } + test(); /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); gd_bits = find_guarded_bits_fx( subframe_len ); exp = 13; - if ( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ) != IVAS_ERR_OK ) + move16(); + IF( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) { return error; } - exp -= gd_bits; + exp = sub( exp, gd_bits ); *st_ivas->hCrendWrapper->p_io_qfactor = exp; - for ( i = 0; i < nchan_in; i++ ) + move16(); + + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); } - if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) - - + IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - for ( i = 0; i < nchan_in; i++ ) + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output[i][j] = fixed_to_float( p_output_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); } } - else if ( st_ivas->renderer_type == RENDERER_MC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - Word16 q = 11; + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { -#if 1 /* TODO: remove float to fix conversions: */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output_fx[i][j] = floatToFixed( p_output[i][j], output_q_factor ); - } - } -#endif IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /* TODO: remove Fixed to float */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } -#endif - - Word16 q = 11; - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - - FOR( i = 0; i < st_ivas->nchan_transport; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) - { - if ( p_output[i] != NULL ) - { - // fixedToFloat_arrL(p_output_fx[i], p_output[i], 11, 960); - floatToFixed_arrL( p_output[i], p_output_fx[i], 11, 960 ); - } - } - ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) - { - if ( p_output[i] != NULL ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], 11, 960 ); - } - } - + test(); + test(); /* Rendering */ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) { - { - Word16 q = 11; - - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); - - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } - } + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); } - else if ( st_ivas->renderer_type == RENDERER_MC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - Word16 q = 11; - ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx ); - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { -#ifdef IVAS_FLOAT_FIXED - // Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - // Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; #ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); - p_output_fx[i] = p_output_fx[i]; - } - - Word16 num_subframes = (int16_t) ( ( *nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); - for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + Word16 num_subframes = (Word16) ( ( *nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); + FOR( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { Word16 idx = subframe_idx; Word16 pos_q = Q25; @@ -3452,40 +3099,18 @@ ivas_error ivas_jbm_dec_render( } } #endif - if ( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); - } -#endif - -#else - if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#endif - - Word16 q = 11; ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); - - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { -#ifdef IVAS_FLOAT_FIXED #if 1 // ftf changes - int16_t channel_active_fx[MAX_OUTPUT_CHANNELS]; - // uint16_t nchan_out_init; + Word16 channel_active_fx[MAX_OUTPUT_CHANNELS]; Word16 nchan_out_cov; Word16 nchan_out_cldfb = 0; @@ -3493,34 +3118,39 @@ ivas_error ivas_jbm_dec_render( Word16 nchan_transport_tmp = st_ivas->nchan_transport; output_Fs = st_ivas->hDecoderConfig->output_Fs; Word16 nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - // nchan_out_init = nchan_out_transport; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { nchan_out_cldfb = BINAURAL_CHANNELS; + move16(); set_s( channel_active_fx, 1, BINAURAL_CHANNELS ); - nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); } - else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) { nchan_out_cov = nchan_out_transport; - nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + move16(); + nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } - else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); nchan_out_cldfb = nchan_out_cov; + move16(); set_s( channel_active_fx, 1, nchan_out_cov ); } - else + ELSE { nchan_out_cov = nchan_out_transport; + move16(); nchan_out_cldfb = nchan_out_transport; + move16(); set_s( channel_active_fx, 1, nchan_out_cov ); } // ftf for ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx // ftf changes - if ( st_ivas->hParamMC->max_band_decorr > 0 ) + IF( GT_16( st_ivas->hParamMC->max_band_decorr, 0 ) ) { // ftf for param_mc_protoSignalComputation_fx FOR( Word16 x = 0; x < st_ivas->hParamMC->diff_proto_info->num_protos_diff; x++ ) @@ -3537,22 +3167,25 @@ ivas_error ivas_jbm_dec_render( scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; } - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { Word16 Q_hoa_encoder = 31; + move16(); floatToFixed_arrL( st_ivas->hParamMC->hoa_encoder, st_ivas->hParamMC->hoa_encoder_fx, Q_hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } - // ftf for ivas_binRenderer_fx /* CLDFB synthesis */ - for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) + FOR( Word16 ch = 0; ch < nchan_out_cldfb; ch++ ) { - if ( st_ivas->cldfbSynDec[ch] ) + IF( st_ivas->cldfbSynDec[ch] ) { scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; + move16(); } } @@ -3572,139 +3205,90 @@ ivas_error ivas_jbm_dec_render( } #endif ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); -#if 1 // ftf changes - for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) + FOR( int ch = 0; ch < nchan_out_cldfb; ch++ ) { - if ( st_ivas->cldfbSynDec[ch] ) + IF( st_ivas->cldfbSynDec[ch] ) { scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, Q5 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - fixedToFloat_arrL( p_output_fx[ch], p_output[ch], Q11, *nSamplesRendered ); - } - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) - { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } } - if ( st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots ) + IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) ) { FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) { - IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { -#ifdef IVAS_FLOAT_FIXED mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; move16(); -#else - mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); -#endif } -#ifdef IVAS_FLOAT_FIXED mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; move16(); -#else - mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); -#endif } } -#endif - -#else - ivas_param_mc_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); -#endif } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - int16_t offset = hSpatParamRendCom->slots_rendered * hSpatParamRendCom->slot_size; + Word16 offset = imult1616( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->slot_size ); nchan_remapped = st_ivas->nchan_transport; + move16(); - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) /* rendering to CICPxx and Ambisonics */ + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */ { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { /* we still need to copy the separate channel if available */ - if ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } -#ifdef IVAS_FLOAT_FIXED - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered ); - } ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_5_1 && ( output_config == IVAS_AUDIO_CONFIG_5_1_2 || output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1 ) ) + ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; n++ ) + FOR( n = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); n < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); n++ ) { - set_zero( p_output[n], *nSamplesRendered ); + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } } } /* copy discrete C and TD LFE from internal TC to output */ - if ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { - if ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 || - output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 || - output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL] + offset, p_output_fx[LFE_CHANNEL], *nSamplesRendered ); Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[LFE_CHANNEL], p_output[LFE_CHANNEL], Q11, *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL] + offset, p_output[LFE_CHANNEL], *nSamplesRendered ); - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } - else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( st_ivas->hOutSetup.num_lfe, 0 ) ) { /* Delay the separated channel to sync with the DirAC rendering */ -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } } } @@ -3716,69 +3300,36 @@ ivas_error ivas_jbm_dec_render( * - float to integer conversion *----------------------------------------------------------------*/ - st_ivas->hTcBuffer->n_samples_available -= *nSamplesRendered; - st_ivas->hTcBuffer->n_samples_rendered += *nSamplesRendered; + st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered ); + st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered ); /* update global combined orientation start index */ ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); - if ( st_ivas->hTcBuffer->n_samples_discard > 0 ) + IF( GT_16( st_ivas->hTcBuffer->n_samples_discard, 0 ) ) { - for ( n = 0; n < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) + FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) { - p_output[n] += st_ivas->hTcBuffer->n_samples_discard; + p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard; } - *nSamplesRendered -= st_ivas->hTcBuffer->n_samples_discard; + *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard ); st_ivas->hTcBuffer->n_samples_discard = 0; + move16(); } { - if ( st_ivas->ivas_format != MONO_FORMAT ) + IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) ) { #ifndef DISABLE_LIMITER - Word16 ch_idx; - exp = 16; - for ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) - { - - p_output_fx[ch_idx] = tmp_buffer_fx[ch_idx]; - } - for ( ch_idx = 0; ch_idx < nchan_out; ch_idx++ ) - { - exp = s_min( exp, Q_factor_arrL( p_output[ch_idx], *nSamplesRendered ) ); - } - exp -= 2; - exp = 11; - for ( ch_idx = 0; ch_idx < nchan_out; ch_idx++ ) - { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output_fx[ch_idx][j] = (Word32) ( p_output[ch_idx][j] * ( 1 << exp ) ); - } - } - ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp ); - for ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ ) - { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output[ch_idx][j] = ( (float) p_output_fx[ch_idx][j] / ( 1 << exp ) ); - } - } + ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor ); #endif } } - Word16 q_p_output = Q11; - FOR( i = 0; i < nchan_out; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], q_p_output, *nSamplesRendered ); - } - - ivas_syn_output_fx( p_output_fx, q_p_output, *nSamplesRendered, nchan_out, data ); - FOR( i = 0; i < nchan_out; i++ ){} + ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out, data ); - - *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + move16(); pop_wmops(); return IVAS_ERR_OK; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index be58073f452e3dfeb54c0fa2547ceeaf6ae96c23..0e709625dae461c7d0a6c1b3bab79dab3d5ed02b 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1145,6 +1145,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * ivas_omasa_dirac_rend_jbm() * @@ -1180,88 +1181,75 @@ void ivas_omasa_dirac_rend_jbm( subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_render_fx( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); -#else ivas_dirac_dec_render( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); -#endif -#ifdef IVAS_FLOAT_FIXED - Word16 q_output = 31; - Word32 **output_fx, data_separated_objects_fx[4][960]; - q_output = Q11; -#ifdef MSAN_FIX /*Can be removed when dependency on data_separated_objects is removed*/ - Word16 no_channels; - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - no_channels = 1; - } - ELSE - { - no_channels = st_ivas->nchan_ism; - } - FOR( Word16 ind = 0; ind < no_channels; ind++ ) - { + ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); + + return; +} #else - FOR( Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++ ) +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_rend_jbm_fx() + * + * Rendering in OMASA format for JBM + *--------------------------------------------------------------------------*/ + +void ivas_omasa_dirac_rend_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +) +{ + Word16 subframes_rendered; + Word16 slots_rendered; + Word16 n; + Word32 data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#endif // MSAN_FIX - FOR( Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++ ) - { - // data_separated_objects_fx[ind][ind2] = (Word32)(data_separated_objects[ind][ind2] * (1<hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ); - FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) + ELSE { - output_fx[ind] = (Word32 *) malloc( sizeof( Word32 ) * 960 ); - FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - // output_fx[ind][ind2] =(Word32)(output_f[ind][ind2] * (1<hSpatParamRendCom->subframes_rendered; + move16(); + slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + move16(); + + ivas_dirac_dec_render_fx( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); + #ifdef MSAN_FIX FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) #else FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) #endif // MSAN_FIX { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q30 -> Q29 - } + scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, -1 ); // Q30 -> Q29 } - ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects_fx, output_fx, subframes_rendered, slots_rendered ); + ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); - FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) - { - FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) - { - output_f[ind][ind2] = fixedToFloat( output_fx[ind][ind2], q_output ); - } - free( output_fx[ind] ); - } - free( output_fx ); #ifdef MSAN_FIX FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) #else FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) #endif // MSAN_FIX { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q29 -> Q30 - } + scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, 1 ); // Q29 -> Q30 } - // dbgwrite2_txt(output_f[1],960,"../omasa_soutput_f.txt"); -#else - ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); -#endif + return; } +#endif #ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 09757dbf863a978870042ad483aa4666f0fa9d89..acb58e751be63381833405538f6ee7933558b1f0 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -2821,14 +2821,9 @@ void ivas_spar_dec_upmixer_sf_fx( const Word16 nchan_internal, /* i : number of internal channels */ Word16 out_len ) { - /*TODO: To be removed later--------------------------------------------------------*/ - float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - float *p_output[MAX_OUTPUT_CHANNELS]; - /*---------------------------------------------------------------------------*/ Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - // Word32 output_fx[16][960]; Word16 i, b, ts, out_ch, in_ch; Word16 num_spar_bands, spar_band, nchan_transport; Word16 num_in_ingest, split_band; @@ -3069,16 +3064,7 @@ void ivas_spar_dec_upmixer_sf_fx( IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) - { - fixedToFloat_arrL( output_fx[ch], output[ch], Q11, out_len ); - p_output[ch] = output[ch]; - } -#ifdef MSAN_FIX - ivas_dirac_dec_render_sf_fx( st_ivas, p_output, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); -#else - ivas_dirac_dec_render_sf_fx( st_ivas, p_output, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); -#endif // MSAN_FIX + ivas_dirac_dec_render_sf_fx( st_ivas, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); } /*------------------------------------------------------------------ends*/ IF( st_ivas->hDirAC != NULL ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 63830ac1572f24bfc6cfb0d391ccfb8b40ac0586..8e036270b3016cb82fd4f9a1c20d47256d5b8795 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1613,7 +1613,7 @@ static ivas_error IVAS_DEC_GetRenderedSamples( st_ivas = hIvasDec->st_ivas; /* run the main IVAS decoding routine */ - error = ivas_jbm_dec_render( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); + error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); return error; } diff --git a/lib_dec/vlpc_2st_dec.c b/lib_dec/vlpc_2st_dec.c index ddeb78dc87f8b31203d4040dcbb9de5719ba8d6a..ac22f990a8038eb08159e9cdfd779080b7fec1da 100644 --- a/lib_dec/vlpc_2st_dec.c +++ b/lib_dec/vlpc_2st_dec.c @@ -44,7 +44,7 @@ * * *------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void vlpc_2st_dec_flt( float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ int16_t *indx, /* i : index[] (4 bits per words) */ @@ -75,3 +75,4 @@ void vlpc_2st_dec_flt( return; } +#endif diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index b0ef34b2474860cd124670b0c0f4276cb77e0ac9..5f888df99b4e1284ec7fd15c9034de10ab1f082e 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -1151,8 +1151,7 @@ void BSplineModelEvalDealloc_fx( } return; } -#endif // IVAS_FLOAT_FIXED - +#else void BSplineModelEvalDealloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ @@ -1171,15 +1170,14 @@ void BSplineModelEvalDealloc( free( model->azimKSeq ); if ( modelEval != NULL ) { -#ifndef IVAS_FLOAT_FIXED free( modelEval->hrfModL ); free( modelEval->hrfModR ); -#endif } } return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 4d652a0c3cd03dc319ecb766c2d5c1dbd972ebec..e333a56b1db47b8567e23e8ab640a5b45ee654e8 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -216,9 +216,6 @@ void TDREND_MIX_Dealloc_fx( { IF( EQ_16( hBinRendererTd->HrFiltSet_p->FilterMethod, TDREND_HRFILT_Method_BSplineModel ) ) { -#if 0 /*IVAS_FLOAT_FIXED_TO_BE_REMOVED*/ - BSplineModelEvalDealloc( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); -#endif BSplineModelEvalDealloc_fx( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } ELSE diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 66555279dc547b3e64ea8b77676cb4b3d9ea8e82..0df7c7b7bfe266157d1612988347ab7742cb65a6 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1316,12 +1316,12 @@ void BSplineModelEvalDealloc_fx( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ ); -#endif // IVAS_FLOAT_FIXED - +#else void BSplineModelEvalDealloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ ); +#endif // IVAS_FLOAT_FIXED /* ----- Object renderer - hrfilt ----- */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 3ee653b70b4dac8f5aa54e25b958e324230ad0bd..6b7afe97f9667dde784dfceeccf862daaa199bdf 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -2143,7 +2143,7 @@ static void set_reverb_acoustic_data_fx( tmp_exp = add( exp_argument_e, 1 ); L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp ); L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] ); - tmp_exp = add( tmp_exp, pDsr_e[bin_idx] ); + tmp_exp = add( pow_exp, pDsr_e[bin_idx] ); pDsr_fx[bin_idx] = L_tmp; move32(); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 0cf951fadd915b42e3b5e553af550da7d0f9bed9..3158cc8de05722e13a5aeed7683a44f3aa50f715 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1602,7 +1602,6 @@ typedef struct const int16_t *azimShapeIdx; const int16_t *azimShapeSampFactor; - const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ const Word32 *elevBsShape_fx; @@ -1616,24 +1615,29 @@ typedef struct Word16 EL_e; const Word32 *ER_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ Word16 ER_e; -#endif // IVAS_FLOAT_FIXED - const float *AlphaL; /* Array, size AlphaN x K */ - const float *AlphaR; /* Array, size AlphaN x K */ +#else + const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ + const float *AlphaL; /* Array, size AlphaN x K */ + const float *AlphaR; /* Array, size AlphaN x K */ const float *elevBsShape; float **azimKSeq; /* Array, length azimDim3+1 */ const float **azimBsShape; +#endif // IVAS_FLOAT_FIXED int16_t azimDim3Max; int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ - const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ - const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ - +#ifndef IVAS_FLOAT_FIXED + const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ +#endif /* Pointers for allocation of dynamic memory */ +#ifndef IVAS_FLOAT_FIXED float *AlphaL_dyn; float *AlphaR_dyn; float *EL_dyn; float *ER_dyn; +#endif #ifdef IVAS_FLOAT_FIXED Word32 *AlphaL_dyn_fx; Word32 *AlphaR_dyn_fx; @@ -1644,11 +1648,12 @@ typedef struct Word32 *ER_dyn_fx; Word16 ER_dyn_e; #endif - float *elevBsShape_dyn; - float *elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevBsShape_dyn_fx; Word32 *elevKSeq_dyn_fx; +#else + float *elevKSeq_dyn; + float *elevBsShape_dyn; #endif int16_t *azimDim2_dyn; int16_t *azimDim3_dyn; @@ -1656,9 +1661,10 @@ typedef struct int16_t *azimSegSamples_dyn; int16_t *azimShapeIdx_dyn; int16_t *azimShapeSampFactor_dyn; - float **azimBsShape_dyn; #ifdef IVAS_FLOAT_FIXED Word32 **azimBsShape_dyn_fx; +#else + float **azimBsShape_dyn; #endif } ModelParams_t; @@ -1669,20 +1675,28 @@ typedef struct int16_t elevDim2; int16_t elevDim3; +#ifndef IVAS_FLOAT_FIXED const float *elevKSeq; /* Array, length elevDim3-2 */ +#endif int16_t azimDim2; int16_t azimDim3; +#ifndef IVAS_FLOAT_FIXED const float *azimKSeq; /* Array, length azimDim3-2 */ const float *W; /* Array, size (elevDim3*azimDim3) x K */ +#endif int16_t azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; int16_t azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; +#ifndef IVAS_FLOAT_FIXED const float *azimBsShape; +#endif int16_t azimSegSamples; int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; +#ifndef IVAS_FLOAT_FIXED const float *elevBsShape; +#endif int16_t elevSegSamples; #ifndef IVAS_FLOAT_FIXED float resamp_factor; @@ -1699,22 +1713,24 @@ typedef struct #endif // IVAS_FLOAT_FIXED /* Pointers for allocation of dynamic memory */ - float *elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevKSeq_dyn_fx; Word32 *azimKSeq_dyn_fx; -#endif +#else + float *elevKSeq_dyn; float *azimKSeq_dyn; float *W_dyn; float *azimBsShape_dyn; +#endif #ifdef IVAS_FLOAT_FIXED Word32 *W_dyn_fx; Word16 W_dyn_e; Word32 *azimBsShape_dyn_fx; #endif - float *elevBsShape_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevBsShape_dyn_fx; +#else + float *elevBsShape_dyn; #endif } ModelParamsITD_t; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 048a86470e28ca3531f6310cfd401eaa8de6cdfb..b00de3950dcdf93661b5c90743eda678376252cd 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -247,7 +247,90 @@ static ivas_error read_hrtf_binary_header( * * Loads the B Spline HR filter model ITD data from file. --------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void LoadBSplineBinaryITD( + ModelParamsITD_t *modelITD, /* i/o: ITD model parameter structure */ + FILE *f_hrtf /* i : HR filter data file handle */ +) +{ + Word16 tmp; + fread( &modelITD->N, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->elevDim2, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->elevDim3, sizeof( Word16 ), 1, f_hrtf ); + + float *elevKSeq_dyn_local = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); + + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + FOR( int i = 0; i < modelITD->elevDim3 - 2; i++ ) + { + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); + } + + fread( &modelITD->azimDim2, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf ); + + float *azimKSeq_dyn_local = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( azimKSeq_dyn_local, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); + modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + FOR( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) + { + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 ); + } + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( W_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); + + /* azimuth */ + fread( modelITD->azimBsLen, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + fread( modelITD->azimBsStart, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + + float *azimBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + FOR( int i = 0; i < tmp; i++ ) + { + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 ); + } + + fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf ); + + /* elevation */ + fread( modelITD->elevBsLen, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + fread( modelITD->elevBsStart, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + FOR( int i = 0; i < tmp; i++ ) + { + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); + } + + fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); + modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; + + modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; + modelITD->W_fx = modelITD->W_dyn_fx; + modelITD->W_e = modelITD->W_dyn_e; + move16(); + modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; + modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; + + return; +} +#else static void LoadBSplineBinaryITD( ModelParamsITD_t *modelITD, /* i/o: ITD model parameter structure */ FILE *f_hrtf /* i : HR filter data file handle */ @@ -257,34 +340,45 @@ static void LoadBSplineBinaryITD( fread( &modelITD->N, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->elevDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->elevDim3, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); - fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevKSeq_dyn_local = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } +#else + modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #endif fread( &modelITD->azimDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->azimDim3, sizeof( int16_t ), 1, f_hrtf ); - modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *azimKSeq_dyn_local = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( azimKSeq_dyn_local, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 ); } +#else + modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #endif fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->W_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->W_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( W_dyn_local, sizeof( float ), tmp, f_hrtf ); + modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - f2me_buf( modelITD->W_dyn, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); + f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); +#else + modelITD->W_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->W_dyn, sizeof( float ), tmp, f_hrtf ); #endif /* azimuth */ @@ -293,14 +387,18 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *azimBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( int i = 0; i < tmp; i++ ) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 ); } +#else + modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &modelITD->azimSegSamples, sizeof( int16_t ), 1, f_hrtf ); @@ -311,42 +409,50 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( int i = 0; i < tmp; i++ ) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } +#else + modelITD->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &modelITD->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevKSeq = (const float *) modelITD->elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; +#else + modelITD->elevKSeq = (const float *) modelITD->elevKSeq_dyn; #endif - modelITD->azimKSeq = (const float *) modelITD->azimKSeq_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; +#else + modelITD->azimKSeq = (const float *) modelITD->azimKSeq_dyn; #endif - modelITD->W = (const float *) modelITD->W_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->W_fx = modelITD->W_dyn_fx; modelITD->W_e = modelITD->W_dyn_e; move16(); +#else + modelITD->W = (const float *) modelITD->W_dyn; #endif - modelITD->azimBsShape = (const float *) modelITD->azimBsShape_dyn; - modelITD->elevBsShape = (const float *) modelITD->elevBsShape_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; +#else + modelITD->elevBsShape = (const float *) modelITD->elevBsShape_dyn; + modelITD->azimBsShape = (const float *) modelITD->azimBsShape_dyn; #endif return; } - +#endif /*-------------------------------------------------------------------* * LoadBSplineBinary() @@ -426,73 +532,93 @@ static ivas_error LoadBSplineBinary( fread( &model->elevDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &model->elevDim3, sizeof( int16_t ), 1, f_hrtf ); - model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); - fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevKSeq_dyn_local = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), model->elevDim3 - 2, f_hrtf ); model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) { - model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); + model->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } +#else + model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); + fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #endif model->azimDim2_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); model->azimDim3_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); model->azim_start_idx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); - model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); #ifdef IVAS_FLOAT_FIXED + float **azimKSeq_local = (float **) malloc( model->elevDim3 * sizeof( float * ) ); model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ); +#else + model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); #endif for ( i = 0; i < model->elevDim3; i++ ) { fread( &model->azimDim2_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azimDim3_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( int16_t ), 1, f_hrtf ); - model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); - fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED + azimKSeq_local[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); + fread( azimKSeq_local[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) { - model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); + model->azimKSeq_fx[i][j] = float_to_fix( azimKSeq_local[i][j], Q22 ); } +#else + model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); + fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #endif } fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf ); +#ifdef IVAS_FLOAT_FIXED + float *AlphaL_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( AlphaL_dyn_local, sizeof( float ), model->AlphaN * model->K, f_hrtf ); + model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); + f2me_buf( AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); +#else model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaL_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); -#ifdef IVAS_FLOAT_FIXED - model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf( model->AlphaL_dyn, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); #endif - model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); - fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *AlphaR_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( AlphaR_dyn_local, sizeof( float ), model->AlphaN * model->K, f_hrtf ); + model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf( model->AlphaR_dyn, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); + f2me_buf( AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); +#else + model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); #endif /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( int16_t ), 1, f_hrtf ); - model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); - model->azimBsShape_dyn = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); model->azimBsShape_dyn_fx = (Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); + float **azimBsShape_dyn_local = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); +#else + model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); + model->azimBsShape_dyn = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); #endif model->azimSegSamples_dyn = (int16_t *) malloc( model->num_unique_azim_splines * sizeof( int16_t ) ); for ( i = 0; i < model->num_unique_azim_splines; i++ ) { fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); - fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + azimBsShape_dyn_local[i] = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local[i], sizeof( float ), tmp, f_hrtf ); model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( int j = 0; j < tmp; j++ ) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); + model->azimBsShape_dyn_fx[i][j] = float_to_fix( azimBsShape_dyn_local[i][j], Q30 ); } +#else + model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); + fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); } @@ -506,23 +632,22 @@ static ivas_error LoadBSplineBinary( fread( model->elevBsLen, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( model->elevBsStart, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); + model->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } +#else + model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &model->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); /* Set const pointers */ - model->AlphaL = (const float *) model->AlphaL_dyn; - model->AlphaR = (const float *) model->AlphaR_dyn; - model->EL = (const float *) model->EL_dyn; - model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED model->AlphaL_fx = model->AlphaL_dyn_fx; model->AlphaL_e = model->AlphaL_dyn_e; @@ -536,12 +661,18 @@ static ivas_error LoadBSplineBinary( model->ER_fx = model->ER_dyn_fx; model->ER_e = model->ER_dyn_e; move16(); +#else + model->AlphaL = (const float *) model->AlphaL_dyn; + model->AlphaR = (const float *) model->AlphaR_dyn; + model->EL = (const float *) model->EL_dyn; + model->ER = (const float *) model->ER_dyn; #endif - model->elevBsShape = (const float *) model->elevBsShape_dyn; - model->elevKSeq = (const float *) model->elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED model->elevBsShape_fx = (const Word32 *) model->elevBsShape_dyn_fx; model->elevKSeq_fx = (const Word32 *) model->elevKSeq_dyn_fx; +#else + model->elevBsShape = (const float *) model->elevBsShape_dyn; + model->elevKSeq = (const float *) model->elevKSeq_dyn; #endif model->azimDim2 = (const int16_t *) model->azimDim2_dyn; model->azimDim3 = (const int16_t *) model->azimDim3_dyn; @@ -552,9 +683,10 @@ static ivas_error LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { - model->azimBsShape[i] = (const float *) model->azimBsShape_dyn[i]; #ifdef IVAS_FLOAT_FIXED model->azimBsShape_fx[i] = (const Word32 *) model->azimBsShape_dyn_fx[i]; +#else + model->azimBsShape[i] = (const float *) model->azimBsShape_dyn[i]; #endif } @@ -728,12 +860,13 @@ static void HRTF_energy_sections_precalc( ) { int16_t i, k, j; +#ifndef IVAS_FLOAT_FIXED float *pEL; float *pER; const float *pAlphaL; const float *pAlphaR; float tmp; -#ifdef IVAS_FLOAT_FIXED +#else Word32 *pEL_fx; Word32 *pER_fx; const Word32 *pAlphaL_fx; @@ -747,45 +880,42 @@ static void HRTF_energy_sections_precalc( AlphaN = model->AlphaN; /* Precalculated energies for each section and each row of the alpha matrices */ - model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); - model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); - pEL = model->EL_dyn; - pER = model->ER_dyn; #ifdef IVAS_FLOAT_FIXED model->EL_dyn_fx = (Word32 *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( Word32 ) ); model->ER_dyn_fx = (Word32 *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( Word32 ) ); pEL_fx = model->EL_dyn_fx; pER_fx = model->ER_dyn_fx; +#else + model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + pEL = model->EL_dyn; + pER = model->ER_dyn; #endif for ( i = 0; i < HRTF_MODEL_N_SECTIONS; i++ ) { for ( j = 0; j < AlphaN; j++ ) /* rows of Alpha matrices */ { - *pEL = 0.0f; - *pER = 0.0f; #ifdef IVAS_FLOAT_FIXED *pEL_fx = 0; move32(); *pER_fx = 0; move32(); +#else + *pEL = 0.0f; + *pER = 0.0f; #endif - pAlphaL = &model->AlphaL[model->iSecFirst[i] * AlphaN + j]; - pAlphaR = &model->AlphaR[model->iSecFirst[i] * AlphaN + j]; #ifdef IVAS_FLOAT_FIXED pAlphaL_fx = &model->AlphaL_fx[model->iSecFirst[i] * AlphaN + j]; pAlphaR_fx = &model->AlphaR_fx[model->iSecFirst[i] * AlphaN + j]; +#else + pAlphaR = &model->AlphaR[model->iSecFirst[i] * AlphaN + j]; + pAlphaL = &model->AlphaL[model->iSecFirst[i] * AlphaN + j]; #endif for ( k = model->iSecFirst[i]; k < model->iSecLast[i]; k++ ) /* k within the sections */ { /* Energy calculation */ - tmp = *pAlphaL; - *pEL += tmp * tmp; - tmp = *pAlphaR; - *pER += tmp * tmp; - pAlphaL += AlphaN; - pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ @@ -793,18 +923,24 @@ static void HRTF_energy_sections_precalc( *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; +#else + tmp = *pAlphaL; + *pEL += tmp * tmp; + tmp = *pAlphaR; + *pER += tmp * tmp; + pAlphaL += AlphaN; + pAlphaR += AlphaN; #endif } - pEL++; - pER++; #ifdef IVAS_FLOAT_FIXED pEL_fx++; pER_fx++; +#else + pEL++; + pER++; #endif } } - model->EL = (const float *) model->EL_dyn; - model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) @@ -815,6 +951,9 @@ static void HRTF_energy_sections_precalc( model->ER_fx = model->ER_dyn_fx; model->ER_e = model->ER_dyn_e; move16(); +#else + model->EL = (const float *) model->EL_dyn; + model->ER = (const float *) model->ER_dyn; #endif } @@ -845,58 +984,64 @@ ivas_error dealloc_HRTF_binary( { if ( hHrtf->ModelParams.UseItdModel ) { - free( hHrtf->ModelParamsITD.elevKSeq_dyn ); - free( hHrtf->ModelParamsITD.azimKSeq_dyn ); - free( hHrtf->ModelParamsITD.W_dyn ); - free( hHrtf->ModelParamsITD.azimBsShape_dyn ); - free( hHrtf->ModelParamsITD.elevBsShape_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParamsITD.elevKSeq_dyn_fx ); free( hHrtf->ModelParamsITD.azimKSeq_dyn_fx ); free( hHrtf->ModelParamsITD.W_dyn_fx ); free( hHrtf->ModelParamsITD.azimBsShape_dyn_fx ); free( hHrtf->ModelParamsITD.elevBsShape_dyn_fx ); +#else + free( hHrtf->ModelParamsITD.azimKSeq_dyn ); + free( hHrtf->ModelParamsITD.elevBsShape_dyn ); + free( hHrtf->ModelParamsITD.elevKSeq_dyn ); + free( hHrtf->ModelParamsITD.W_dyn ); + free( hHrtf->ModelParamsITD.azimBsShape_dyn ); #endif } - free( hHrtf->ModelParams.elevKSeq_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.elevKSeq_dyn_fx ); +#else + free( hHrtf->ModelParams.elevKSeq_dyn ); #endif free( hHrtf->ModelParams.azim_start_idx_dyn ); free( hHrtf->ModelParams.azimDim2_dyn ); free( hHrtf->ModelParams.azimDim3_dyn ); - free( hHrtf->ModelParams.AlphaL_dyn ); - free( hHrtf->ModelParams.AlphaR_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.AlphaL_dyn_fx ); free( hHrtf->ModelParams.AlphaR_dyn_fx ); +#else + free( hHrtf->ModelParams.AlphaL_dyn ); + free( hHrtf->ModelParams.AlphaR_dyn ); #endif free( hHrtf->ModelParams.azimSegSamples_dyn ); free( hHrtf->ModelParams.azimShapeIdx_dyn ); free( hHrtf->ModelParams.azimShapeSampFactor_dyn ); - free( hHrtf->ModelParams.elevBsShape_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.elevBsShape_dyn_fx ); +#else + free( hHrtf->ModelParams.elevBsShape_dyn ); #endif for ( i = 0; i < hHrtf->ModelParams.num_unique_azim_splines; i++ ) { - free( hHrtf->ModelParams.azimBsShape_dyn[i] ); - free( &hHrtf->ModelParams.azimBsShape_dyn[i] ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.azimBsShape_dyn_fx[i] ); free( &hHrtf->ModelParams.azimBsShape_dyn_fx[i] ); +#else + free( hHrtf->ModelParams.azimBsShape_dyn[i] ); + free( &hHrtf->ModelParams.azimBsShape_dyn[i] ); #endif } +#ifndef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ for ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq[i] ); } free( hHrtf->ModelParams.azimKSeq ); -#ifdef IVAS_FLOAT_FIXED +#else free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { @@ -905,16 +1050,14 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq_fx ); #endif - free( hHrtf->ModelParams.EL_dyn ); - free( hHrtf->ModelParams.ER_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.EL_dyn_fx ); free( hHrtf->ModelParams.ER_dyn_fx ); -#endif -#ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelEval.hrfModL_fx ); free( hHrtf->ModelEval.hrfModR_fx ); #else + free( hHrtf->ModelParams.EL_dyn ); + free( hHrtf->ModelParams.ER_dyn ); free( hHrtf->ModelEval.hrfModL ); free( hHrtf->ModelEval.hrfModR ); #endif